61
61
offsetof(SQL_CONFIG,deletestalesessions), NULL, "yes"},
62
62
{"num_sql_socks", PW_TYPE_INTEGER,
63
63
offsetof(SQL_CONFIG,num_sql_socks), NULL, "5"},
64
{"lifetime", PW_TYPE_INTEGER,
65
offsetof(SQL_CONFIG,lifetime), NULL, "0"},
66
{"max_queries", PW_TYPE_INTEGER,
67
offsetof(SQL_CONFIG,max_queries), NULL, "0"},
64
68
{"sql_user_name", PW_TYPE_STRING_PTR,
65
69
offsetof(SQL_CONFIG,query_user), NULL, ""},
66
70
{"default_user_profile", PW_TYPE_STRING_PTR,
70
74
{"authorize_check_query", PW_TYPE_STRING_PTR,
71
75
offsetof(SQL_CONFIG,authorize_check_query), NULL, ""},
72
76
{"authorize_reply_query", PW_TYPE_STRING_PTR,
73
offsetof(SQL_CONFIG,authorize_reply_query), NULL, ""},
77
offsetof(SQL_CONFIG,authorize_reply_query), NULL, NULL},
74
78
{"authorize_group_check_query", PW_TYPE_STRING_PTR,
75
79
offsetof(SQL_CONFIG,authorize_group_check_query), NULL, ""},
76
80
{"authorize_group_reply_query", PW_TYPE_STRING_PTR,
103
107
offsetof(SQL_CONFIG,allowed_chars), NULL,
104
108
"@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_: /"},
111
* This only works for a few drivers.
113
{"query_timeout", PW_TYPE_INTEGER,
114
offsetof(SQL_CONFIG,query_timeout), NULL, NULL},
106
116
{NULL, -1, 0, NULL, NULL}
129
139
* sql xlat function. Right now only SELECTs are supported. Only
130
140
* the first element of the SELECT result will be used.
142
* For other statements (insert, update, delete, etc.), the
143
* number of affected rows will be returned.
132
145
static int sql_xlat(void *instance, REQUEST *request,
133
146
char *fmt, char *out, size_t freespace,
160
174
sqlsocket = sql_get_socket(inst);
161
175
if (sqlsocket == NULL)
179
* If the query starts with any of the following prefixes,
180
* then return the number of rows affected
182
if ((strncasecmp(querystr, "insert", 6) == 0) ||
183
(strncasecmp(querystr, "update", 6) == 0) ||
184
(strncasecmp(querystr, "delete", 6) == 0)) {
186
char buffer[21]; /* 64bit max is 20 decimal chars + null byte */
188
if (rlm_sql_query(sqlsocket,inst,querystr)) {
189
radlog(L_ERR, "rlm_sql (%s): database query error, %s: %s",
190
inst->config->xlat_name, querystr,
191
(inst->module->sql_error)(sqlsocket,
193
sql_release_socket(inst,sqlsocket);
197
numaffected = (inst->module->sql_affected_rows)(sqlsocket,
199
if (numaffected < 1) {
200
RDEBUG("rlm_sql (%s): SQL query affected no rows",
201
inst->config->xlat_name);
205
* Don't chop the returned number if freespace is
206
* too small. This hack is necessary because
207
* some implementations of snprintf return the
208
* size of the written data, and others return
209
* the size of the data they *would* have written
210
* if the output buffer was large enough.
212
snprintf(buffer, sizeof(buffer), "%d", numaffected);
213
ret = strlen(buffer);
214
if (ret >= freespace){
215
RDEBUG("rlm_sql (%s): Can't write result, insufficient string space",
216
inst->config->xlat_name);
217
(inst->module->sql_finish_query)(sqlsocket,
219
sql_release_socket(inst,sqlsocket);
223
memcpy(out, buffer, ret + 1); /* we did bounds checking above */
225
(inst->module->sql_finish_query)(sqlsocket, inst->config);
226
sql_release_socket(inst,sqlsocket);
228
} /* else it's a SELECT statement */
163
230
if (rlm_sql_select_query(sqlsocket,inst,querystr)){
164
231
radlog(L_ERR, "rlm_sql (%s): database query error, %s: %s",
165
232
inst->config->xlat_name,querystr,
171
238
ret = rlm_sql_fetch_row(sqlsocket, inst);
174
DEBUG("rlm_sql (%s): SQL query did not succeed",
175
inst->config->xlat_name);
241
RDEBUG("SQL query did not succeed");
176
242
(inst->module->sql_finish_select_query)(sqlsocket, inst->config);
177
243
sql_release_socket(inst,sqlsocket);
181
247
row = sqlsocket->row;
182
248
if (row == NULL) {
183
DEBUG("rlm_sql (%s): SQL query did not return any results",
184
inst->config->xlat_name);
249
RDEBUG("SQL query did not return any results");
185
250
(inst->module->sql_finish_select_query)(sqlsocket, inst->config);
186
251
sql_release_socket(inst,sqlsocket);
190
255
if (row[0] == NULL){
191
DEBUG("rlm_sql (%s): row[0] returned NULL",
192
inst->config->xlat_name);
256
RDEBUG("row[0] returned NULL");
193
257
(inst->module->sql_finish_select_query)(sqlsocket, inst->config);
194
258
sql_release_socket(inst,sqlsocket);
197
261
ret = strlen(row[0]);
198
262
if (ret >= freespace){
199
DEBUG("rlm_sql (%s): sql_xlat:: Insufficient string space",
200
inst->config->xlat_name);
263
RDEBUG("Insufficient string space");
201
264
(inst->module->sql_finish_select_query)(sqlsocket, inst->config);
202
265
sql_release_socket(inst,sqlsocket);
206
269
strlcpy(out,row[0],freespace);
208
DEBUG("rlm_sql (%s): - sql_xlat finished",
209
inst->config->xlat_name);
271
RDEBUG("sql_xlat finished");
211
273
(inst->module->sql_finish_select_query)(sqlsocket, inst->config);
212
274
sql_release_socket(inst,sqlsocket);
431
497
strlcpy(sqlusername, tmpuser, MAX_STRING_LEN);
432
DEBUG2("rlm_sql (%s): sql_set_user escaped user --> '%s'",
433
inst->config->xlat_name, sqlusername);
434
vp = pairmake("SQL-User-Name", sqlusername, 0);
436
radlog(L_ERR, "%s", librad_errstr);
498
RDEBUG2("sql_set_user escaped user --> '%s'", sqlusername);
499
vp = radius_pairmake(request, &request->packet->vps,
500
"SQL-User-Name", NULL, 0);
502
radlog(L_ERR, "%s", fr_strerror());
440
pairadd(&request->packet->vps, vp);
506
strlcpy(vp->vp_strvalue, tmpuser, sizeof(vp->vp_strvalue));
507
vp->length = strlen(vp->vp_strvalue);
473
541
if (!radius_xlat(querystr, sizeof(querystr), inst->config->groupmemb_query, request, sql_escape_func)) {
474
radlog(L_ERR, "rlm_sql (%s): xlat failed.",
475
inst->config->xlat_name);
542
radlog_request(L_ERR, 0, request, "xlat \"%s\" failed.",
543
inst->config->groupmemb_query);
479
547
if (rlm_sql_select_query(sqlsocket, inst, querystr) < 0) {
480
radlog(L_ERR, "rlm_sql (%s): database query error, %s: %s",
481
inst->config->xlat_name,querystr,
548
radlog_request(L_ERR, 0, request,
549
"database query error, %s: %s",
482
551
(inst->module->sql_error)(sqlsocket,inst->config));
517
586
* username will then be checked with the passed check string.
520
static int sql_groupcmp(void *instance, REQUEST *req, VALUE_PAIR *request, VALUE_PAIR *check,
589
static int sql_groupcmp(void *instance, REQUEST *request, VALUE_PAIR *request_vp, VALUE_PAIR *check,
521
590
VALUE_PAIR *check_pairs, VALUE_PAIR **reply_pairs)
523
592
SQLSOCK *sqlsocket;
528
597
check_pairs = check_pairs;
529
598
reply_pairs = reply_pairs;
599
request_vp = request_vp;
532
DEBUG("rlm_sql (%s): - sql_groupcmp", inst->config->xlat_name);
601
RDEBUG("sql_groupcmp");
533
602
if (!check || !check->vp_strvalue || !check->length){
534
DEBUG("rlm_sql (%s): sql_groupcmp: Illegal group name",
535
inst->config->xlat_name);
603
RDEBUG("sql_groupcmp: Illegal group name");
539
DEBUG("rlm_sql (%s): sql_groupcmp: NULL request",
540
inst->config->xlat_name);
607
RDEBUG("sql_groupcmp: NULL request");
544
611
* Set, escape, and check the user attr here
546
if (sql_set_user(inst, req, sqlusername, NULL) < 0)
613
if (sql_set_user(inst, request, sqlusername, NULL) < 0)
552
619
sqlsocket = sql_get_socket(inst);
553
620
if (sqlsocket == NULL) {
554
621
/* Remove the username we (maybe) added above */
555
pairdelete(&req->packet->vps, PW_SQL_USER_NAME);
622
pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
560
627
* Get the list of groups this user is a member of
562
if (sql_get_grouplist(inst, sqlsocket, req, &group_list) < 0) {
563
radlog(L_ERR, "rlm_sql (%s): Error getting group membership",
564
inst->config->xlat_name);
629
if (sql_get_grouplist(inst, sqlsocket, request, &group_list) < 0) {
630
radlog_request(L_ERR, 0, request,
631
"Error getting group membership");
565
632
/* Remove the username we (maybe) added above */
566
pairdelete(&req->packet->vps, PW_SQL_USER_NAME);
633
pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
567
634
sql_release_socket(inst, sqlsocket);
571
638
for (group_list_tmp = group_list; group_list_tmp != NULL; group_list_tmp = group_list_tmp->next) {
572
639
if (strcmp(group_list_tmp->groupname, check->vp_strvalue) == 0){
573
DEBUG("rlm_sql (%s): - sql_groupcmp finished: User is a member of group %s",
574
inst->config->xlat_name,
575
(char *)check->vp_strvalue);
640
RDEBUG("sql_groupcmp finished: User is a member of group %s",
576
642
/* Free the grouplist */
577
643
sql_grouplist_free(&group_list);
578
644
/* Remove the username we (maybe) added above */
579
pairdelete(&req->packet->vps, PW_SQL_USER_NAME);
645
pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
580
646
sql_release_socket(inst, sqlsocket);
585
651
/* Free the grouplist */
586
652
sql_grouplist_free(&group_list);
587
653
/* Remove the username we (maybe) added above */
588
pairdelete(&req->packet->vps, PW_SQL_USER_NAME);
654
pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
589
655
sql_release_socket(inst,sqlsocket);
591
DEBUG("rlm_sql (%s): - sql_groupcmp finished: User is NOT a member of group %s",
592
inst->config->xlat_name, (char *)check->vp_strvalue);
657
RDEBUG("sql_groupcmp finished: User is NOT a member of group %s",
610
676
* Get the list of groups this user is a member of
612
678
if (sql_get_grouplist(inst, sqlsocket, request, &group_list) < 0) {
613
radlog(L_ERR, "rlm_sql (%s): Error retrieving group list",
614
inst->config->xlat_name);
679
radlog_request(L_ERR, 0, request, "Error retrieving group list");
623
688
sql_group = pairmake("Sql-Group", group_list_tmp->groupname, T_OP_EQ);
624
689
if (!sql_group) {
625
radlog(L_ERR, "rlm_sql (%s): Error creating Sql-Group attribute",
626
inst->config->xlat_name);
690
radlog_request(L_ERR, 0, request,
691
"Error creating Sql-Group attribute");
629
694
pairadd(&request->packet->vps, sql_group);
630
695
if (!radius_xlat(querystr, sizeof(querystr), inst->config->authorize_group_check_query, request, sql_escape_func)) {
631
radlog(L_ERR, "rlm_sql (%s): Error generating query; rejecting user",
632
inst->config->xlat_name);
696
radlog_request(L_ERR, 0, request,
697
"Error generating query; rejecting user");
633
698
/* Remove the grouup we added above */
634
699
pairdelete(&request->packet->vps, PW_SQL_GROUP);
637
702
rows = sql_getvpdata(inst, sqlsocket, &check_tmp, querystr);
639
radlog(L_ERR, "rlm_sql (%s): Error retrieving check pairs for group %s",
640
inst->config->xlat_name, group_list_tmp->groupname);
704
radlog_request(L_ERR, 0, request, "Error retrieving check pairs for group %s",
705
group_list_tmp->groupname);
641
706
/* Remove the grouup we added above */
642
707
pairdelete(&request->packet->vps, PW_SQL_GROUP);
643
708
pairfree(&check_tmp);
649
714
if (paircompare(request, request->packet->vps, check_tmp, &request->reply->vps) == 0) {
651
DEBUG2("rlm_sql (%s): User found in group %s",
652
inst->config->xlat_name, group_list_tmp->groupname);
716
RDEBUG2("User found in group %s",
717
group_list_tmp->groupname);
654
719
* Now get the reply pairs since the paircompare matched
656
721
if (!radius_xlat(querystr, sizeof(querystr), inst->config->authorize_group_reply_query, request, sql_escape_func)) {
657
radlog(L_ERR, "rlm_sql (%s): Error generating query; rejecting user",
658
inst->config->xlat_name);
722
radlog_request(L_ERR, 0, request, "Error generating query; rejecting user");
659
723
/* Remove the grouup we added above */
660
724
pairdelete(&request->packet->vps, PW_SQL_GROUP);
661
725
pairfree(&check_tmp);
664
728
if (sql_getvpdata(inst, sqlsocket, &reply_tmp, querystr) < 0) {
665
radlog(L_ERR, "rlm_sql (%s): Error retrieving reply pairs for group %s",
666
inst->config->xlat_name, group_list_tmp->groupname);
729
radlog_request(L_ERR, 0, request, "Error retrieving reply pairs for group %s",
730
group_list_tmp->groupname);
667
731
/* Remove the grouup we added above */
668
732
pairdelete(&request->packet->vps, PW_SQL_GROUP);
669
733
pairfree(&check_tmp);
682
746
* match expected behavior
685
DEBUG2("rlm_sql (%s): User found in group %s",
686
inst->config->xlat_name, group_list_tmp->groupname);
749
RDEBUG2("User found in group %s",
750
group_list_tmp->groupname);
688
752
* Now get the reply pairs since the paircompare matched
690
754
if (!radius_xlat(querystr, sizeof(querystr), inst->config->authorize_group_reply_query, request, sql_escape_func)) {
691
radlog(L_ERR, "rlm_sql (%s): Error generating query; rejecting user",
692
inst->config->xlat_name);
755
radlog_request(L_ERR, 0, request, "Error generating query; rejecting user");
693
756
/* Remove the grouup we added above */
694
757
pairdelete(&request->packet->vps, PW_SQL_GROUP);
695
758
pairfree(&check_tmp);
698
761
if (sql_getvpdata(inst, sqlsocket, &reply_tmp, querystr) < 0) {
699
radlog(L_ERR, "rlm_sql (%s): Error retrieving reply pairs for group %s",
700
inst->config->xlat_name, group_list_tmp->groupname);
762
radlog_request(L_ERR, 0, request, "Error retrieving reply pairs for group %s",
763
group_list_tmp->groupname);
701
764
/* Remove the grouup we added above */
702
765
pairdelete(&request->packet->vps, PW_SQL_GROUP);
703
766
pairfree(&check_tmp);
792
860
memset(inst->config, 0, sizeof(SQL_CONFIG));
863
* Export these methods, too. This avoids RTDL_GLOBAL.
865
inst->sql_set_user = sql_set_user;
866
inst->sql_get_socket = sql_get_socket;
867
inst->sql_release_socket = sql_release_socket;
868
inst->sql_escape_func = sql_escape_func;
869
inst->sql_query = rlm_sql_query;
870
inst->sql_select_query = rlm_sql_select_query;
871
inst->sql_fetch_row = rlm_sql_fetch_row;
795
874
* If the configuration parameters can't be parsed, then
811
890
if (inst->config->num_sql_socks > MAX_SQL_SOCKS) {
812
radlog(L_ERR | L_CONS, "rlm_sql (%s): sql_instantiate: number of sqlsockets cannot exceed MAX_SQL_SOCKS, %d",
891
radlog(L_ERR, "rlm_sql (%s): sql_instantiate: number of sqlsockets cannot exceed MAX_SQL_SOCKS, %d",
813
892
inst->config->xlat_name, MAX_SQL_SOCKS);
814
893
rlm_sql_detach(inst);
819
898
* Sanity check for crazy people.
821
900
if (strncmp(inst->config->sql_driver, "rlm_sql_", 8) != 0) {
822
radlog(L_ERR, "rlm_sql (%s): \"%s\" is NOT an SQL driver!",
823
inst->config->xlat_name, inst->config->sql_driver);
901
radlog(L_ERR, "\"%s\" is NOT an SQL driver!",
902
inst->config->sql_driver);
824
903
rlm_sql_detach(inst);
828
907
inst->handle = lt_dlopenext(inst->config->sql_driver);
829
908
if (inst->handle == NULL) {
830
radlog(L_ERR, "rlm_sql (%s): Could not link driver %s: %s",
831
inst->config->xlat_name, inst->config->sql_driver,
909
radlog(L_ERR, "Could not link driver %s: %s",
910
inst->config->sql_driver,
833
radlog(L_ERR, "rlm_sql (%s): Make sure it (and all its dependent libraries!) are in the search path of your system's ld.",
834
inst->config->xlat_name);
912
radlog(L_ERR, "Make sure it (and all its dependent libraries!) are in the search path of your system's ld.");
835
913
rlm_sql_detach(inst);
839
917
inst->module = (rlm_sql_module_t *) lt_dlsym(inst->handle, inst->config->sql_driver);
840
918
if (!inst->module) {
841
radlog(L_ERR, "rlm_sql (%s): Could not link symbol %s: %s",
842
inst->config->xlat_name, inst->config->sql_driver,
919
radlog(L_ERR, "Could not link symbol %s: %s",
920
inst->config->sql_driver,
844
922
rlm_sql_detach(inst);
857
935
rlm_sql_detach(inst);
860
939
paircompare_register(PW_SQL_GROUP, PW_USER_NAME, sql_groupcmp, inst);
862
941
if (inst->config->do_clients){
863
942
if (generate_sql_clients(inst) == -1){
864
radlog(L_ERR, "rlm_sql (%s): generate_sql_clients() returned error",inst->config->xlat_name);
943
radlog(L_ERR, "Failed to load clients from SQL.");
865
944
rlm_sql_detach(inst);
919
998
* Alright, start by getting the specific entry for the user
921
1000
if (!radius_xlat(querystr, sizeof(querystr), inst->config->authorize_check_query, request, sql_escape_func)) {
922
radlog(L_ERR, "rlm_sql (%s): Error generating query; rejecting user",
923
inst->config->xlat_name);
1001
radlog_request(L_ERR, 0, request, "Error generating query; rejecting user");
924
1002
sql_release_socket(inst, sqlsocket);
925
1003
/* Remove the username we (maybe) added above */
926
1004
pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
929
1007
rows = sql_getvpdata(inst, sqlsocket, &check_tmp, querystr);
931
radlog(L_ERR, "rlm_sql (%s): SQL query error; rejecting user",
932
inst->config->xlat_name);
1009
radlog_request(L_ERR, 0, request, "SQL query error; rejecting user");
933
1010
sql_release_socket(inst, sqlsocket);
934
1011
/* Remove the username we (maybe) added above */
935
1012
pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
942
1019
if (paircompare(request, request->packet->vps, check_tmp, &request->reply->vps) == 0) {
944
DEBUG2("rlm_sql (%s): User found in radcheck table", inst->config->xlat_name);
1021
RDEBUG2("User found in radcheck table");
1023
if (inst->config->authorize_reply_query &&
1024
*inst->config->authorize_reply_query) {
946
1027
* Now get the reply pairs since the paircompare matched
948
1029
if (!radius_xlat(querystr, sizeof(querystr), inst->config->authorize_reply_query, request, sql_escape_func)) {
949
radlog(L_ERR, "rlm_sql (%s): Error generating query; rejecting user",
950
inst->config->xlat_name);
1030
radlog_request(L_ERR, 0, request, "Error generating query; rejecting user");
951
1031
sql_release_socket(inst, sqlsocket);
952
1032
/* Remove the username we (maybe) added above */
953
1033
pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
955
1035
return RLM_MODULE_FAIL;
957
1037
if (sql_getvpdata(inst, sqlsocket, &reply_tmp, querystr) < 0) {
958
radlog(L_ERR, "rlm_sql (%s): SQL query error; rejecting user",
959
inst->config->xlat_name);
1038
radlog_request(L_ERR, 0, request, "SQL query error; rejecting user");
960
1039
sql_release_socket(inst, sqlsocket);
961
1040
/* Remove the username we (maybe) added above */
962
1041
pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
986
1067
if (dofallthrough) {
987
1068
rows = rlm_sql_process_groups(inst, request, sqlsocket, &dofallthrough);
989
radlog(L_ERR, "rlm_sql (%s): Error processing groups; rejecting user",
990
inst->config->xlat_name);
1070
radlog_request(L_ERR, 0, request, "Error processing groups; rejecting user");
991
1071
sql_release_socket(inst, sqlsocket);
992
1072
/* Remove the username we (maybe) added above */
993
1073
pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
1012
1092
if (user_profile != NULL)
1013
1093
profile = user_profile->vp_strvalue;
1014
1094
if (profile && strlen(profile)){
1015
radlog(L_DBG, "rlm_sql (%s): Checking profile %s",
1016
inst->config->xlat_name, profile);
1095
RDEBUG("Checking profile %s", profile);
1017
1096
if (sql_set_user(inst, request, profileusername, profile) < 0) {
1018
radlog(L_ERR, "rlm_sql (%s): Error setting profile; rejecting user",
1019
inst->config->xlat_name);
1097
radlog_request(L_ERR, 0, request, "Error setting profile; rejecting user");
1020
1098
sql_release_socket(inst, sqlsocket);
1021
1099
/* Remove the username we (maybe) added above */
1022
1100
pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
1030
1108
if (profile_found) {
1031
1109
rows = rlm_sql_process_groups(inst, request, sqlsocket, &dofallthrough);
1032
1110
if (rows < 0) {
1033
radlog(L_ERR, "rlm_sql (%s): Error processing profile groups; rejecting user",
1034
inst->config->xlat_name);
1111
radlog_request(L_ERR, 0, request, "Error processing profile groups; rejecting user");
1035
1112
sql_release_socket(inst, sqlsocket);
1036
1113
/* Remove the username we (maybe) added above */
1037
1114
pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
1047
1124
sql_release_socket(inst, sqlsocket);
1050
radlog(L_DBG, "rlm_sql (%s): User %s not found",
1051
inst->config->xlat_name, sqlusername);
1127
RDEBUG("User %s not found", sqlusername);
1052
1128
return RLM_MODULE_NOTFOUND;
1054
1130
return RLM_MODULE_OK;
1083
1159
acctstatustype = pair->vp_integer;
1085
1161
radius_xlat(logstr, sizeof(logstr), "packet has no accounting status type. [user '%{User-Name}', nas '%{NAS-IP-Address}']", request, NULL);
1086
radlog(L_ERR, "rlm_sql (%s) in sql_accounting: %s",
1087
inst->config->xlat_name, logstr);
1162
radlog_request(L_ERR, 0, request, "%s", logstr);
1088
1163
return RLM_MODULE_INVALID;
1096
1171
case PW_STATUS_ACCOUNTING_ON:
1097
1172
case PW_STATUS_ACCOUNTING_OFF:
1098
radlog(L_INFO, "rlm_sql (%s): received Acct On/Off packet", inst->config->xlat_name);
1173
RDEBUG("Received Acct On/Off packet");
1099
1174
radius_xlat(querystr, sizeof(querystr), inst->config->accounting_onoff_query, request, sql_escape_func);
1100
1175
query_log(request, inst, querystr);
1104
1179
return(RLM_MODULE_FAIL);
1105
1180
if (*querystr) { /* non-empty query */
1106
1181
if (rlm_sql_query(sqlsocket, inst, querystr)) {
1107
radlog(L_ERR, "rlm_sql (%s): Couldn't update SQL accounting for Acct On/Off packet - %s",
1108
inst->config->xlat_name,
1182
radlog_request(L_ERR, 0, request, "Couldn't update SQL accounting for Acct On/Off packet - %s",
1109
1183
(inst->module->sql_error)(sqlsocket, inst->config));
1110
1184
ret = RLM_MODULE_FAIL;
1132
1206
return(RLM_MODULE_FAIL);
1133
1207
if (*querystr) { /* non-empty query */
1134
1208
if (rlm_sql_query(sqlsocket, inst, querystr)) {
1135
radlog(L_ERR, "rlm_sql (%s): Couldn't update SQL accounting ALIVE record - %s",
1136
inst->config->xlat_name,
1209
radlog_request(L_ERR, 0, request, "Couldn't update SQL accounting ALIVE record - %s",
1137
1210
(inst->module->sql_error)(sqlsocket, inst->config));
1138
1211
ret = RLM_MODULE_FAIL;
1151
1224
query_log(request, inst, querystr);
1152
1225
if (*querystr) { /* non-empty query */
1153
1226
if (rlm_sql_query(sqlsocket, inst, querystr)) {
1154
radlog(L_ERR, "rlm_sql (%s): Couldn't insert SQL accounting ALIVE record - %s",
1155
inst->config->xlat_name,
1227
radlog_request(L_ERR, 0, request, "Couldn't insert SQL accounting ALIVE record - %s",
1156
1228
(inst->module->sql_error)(sqlsocket, inst->config));
1157
1229
ret = RLM_MODULE_FAIL;
1182
1254
return(RLM_MODULE_FAIL);
1183
1255
if (*querystr) { /* non-empty query */
1184
1256
if (rlm_sql_query(sqlsocket, inst, querystr)) {
1185
radlog(L_ERR, "rlm_sql (%s): Couldn't insert SQL accounting START record - %s",
1186
inst->config->xlat_name,
1257
radlog_request(L_ERR, 0, request, "Couldn't insert SQL accounting START record - %s",
1187
1258
(inst->module->sql_error)(sqlsocket, inst->config));
1197
1268
if (*querystr) { /* non-empty query */
1198
1269
if (rlm_sql_query(sqlsocket, inst, querystr)) {
1199
radlog(L_ERR, "rlm_sql (%s): Couldn't update SQL accounting START record - %s",
1200
inst->config->xlat_name,
1270
radlog_request(L_ERR, 0, request, "Couldn't update SQL accounting START record - %s",
1201
1271
(inst->module->sql_error)(sqlsocket, inst->config));
1202
1272
ret = RLM_MODULE_FAIL;
1226
1296
return(RLM_MODULE_FAIL);
1227
1297
if (*querystr) { /* non-empty query */
1228
1298
if (rlm_sql_query(sqlsocket, inst, querystr)) {
1229
radlog(L_ERR, "rlm_sql (%s): Couldn't update SQL accounting STOP record - %s",
1230
inst->config->xlat_name,
1299
radlog_request(L_ERR, 0, request, "Couldn't update SQL accounting STOP record - %s",
1231
1300
(inst->module->sql_error)(sqlsocket, inst->config));
1232
1301
ret = RLM_MODULE_FAIL;
1253
1322
if (acctsessiontime <= 0) {
1254
1323
radius_xlat(logstr, sizeof(logstr), "stop packet with zero session length. [user '%{User-Name}', nas '%{NAS-IP-Address}']", request, NULL);
1255
radlog(L_ERR, "rlm_sql (%s) in sql_accounting: %s", inst->config->xlat_name, logstr);
1324
radlog_request(L_ERR, 0, request, "%s", logstr);
1256
1325
sql_release_socket(inst, sqlsocket);
1257
1326
ret = RLM_MODULE_NOOP;
1264
1333
if (*querystr) { /* non-empty query */
1265
1334
if (rlm_sql_query(sqlsocket, inst, querystr)) {
1266
radlog(L_ERR, "rlm_sql (%s): Couldn't insert SQL accounting STOP record - %s",
1267
inst->config->xlat_name,
1335
radlog_request(L_ERR, 0, request, "Couldn't insert SQL accounting STOP record - %s",
1268
1337
(inst->module->sql_error)(sqlsocket, inst->config));
1269
1338
ret = RLM_MODULE_FAIL;
1324
1394
if((request->username == NULL) || (request->username->length == 0)) {
1325
radlog(L_ERR, "rlm_sql (%s): Zero Length username not permitted\n", inst->config->xlat_name);
1395
radlog_request(L_ERR, 0, request, "Zero Length username not permitted\n");
1326
1396
return RLM_MODULE_INVALID;
1379
1449
radius_xlat(querystr, sizeof(querystr), inst->config->simul_verify_query, request, sql_escape_func);
1380
1450
if(rlm_sql_select_query(sqlsocket, inst, querystr)) {
1381
radlog(L_ERR, "rlm_sql (%s): sql_checksimul: Database query error", inst->config->xlat_name);
1451
radlog_request(L_ERR, 0, request, "Database query error");
1382
1452
sql_release_socket(inst, sqlsocket);
1383
1453
return RLM_MODULE_FAIL;
1402
1472
(inst->module->sql_finish_select_query)(sqlsocket, inst->config);
1403
1473
sql_release_socket(inst, sqlsocket);
1404
DEBUG("rlm_sql (%s): Cannot zap stale entry. No username present in entry.", inst->config->xlat_name);
1474
RDEBUG("Cannot zap stale entry. No username present in entry.", inst->config->xlat_name);
1405
1475
return RLM_MODULE_FAIL;
1408
1478
(inst->module->sql_finish_select_query)(sqlsocket, inst->config);
1409
1479
sql_release_socket(inst, sqlsocket);
1410
DEBUG("rlm_sql (%s): Cannot zap stale entry. No session id in entry.", inst->config->xlat_name);
1480
RDEBUG("Cannot zap stale entry. No session id in entry.", inst->config->xlat_name);
1411
1481
return RLM_MODULE_FAIL;
1464
1534
(inst->module->sql_finish_select_query)(sqlsocket, inst->config);
1465
1535
sql_release_socket(inst, sqlsocket);
1466
radlog(L_ERR, "rlm_sql (%s): sql_checksimul: Failed to check the terminal server for user '%s'.", inst->config->xlat_name, row[2]);
1536
radlog_request(L_ERR, 0, request, "Failed to check the terminal server for user '%s'.", row[2]);
1467
1537
return RLM_MODULE_FAIL;