3 * Main SQL module file. Most ICRADIUS code is located in sql.c
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * Copyright 2000,2006 The FreeRADIUS server project
22 * Copyright 2000 Mike Machado <mike@innercite.com>
23 * Copyright 2000 Alan DeKok <aland@ox.org>
26 #include <freeradius-devel/ident.h>
29 #include <freeradius-devel/radiusd.h>
30 #include <freeradius-devel/modules.h>
31 #include <freeradius-devel/rad_assert.h>
37 static char *allowed_chars = NULL;
39 static const CONF_PARSER module_config[] = {
40 {"driver",PW_TYPE_STRING_PTR,
41 offsetof(SQL_CONFIG,sql_driver), NULL, "mysql"},
42 {"server",PW_TYPE_STRING_PTR,
43 offsetof(SQL_CONFIG,sql_server), NULL, "localhost"},
44 {"port",PW_TYPE_STRING_PTR,
45 offsetof(SQL_CONFIG,sql_port), NULL, ""},
46 {"login", PW_TYPE_STRING_PTR,
47 offsetof(SQL_CONFIG,sql_login), NULL, ""},
48 {"password", PW_TYPE_STRING_PTR,
49 offsetof(SQL_CONFIG,sql_password), NULL, ""},
50 {"radius_db", PW_TYPE_STRING_PTR,
51 offsetof(SQL_CONFIG,sql_db), NULL, "radius"},
52 {"read_groups", PW_TYPE_BOOLEAN,
53 offsetof(SQL_CONFIG,read_groups), NULL, "yes"},
54 {"sqltrace", PW_TYPE_BOOLEAN,
55 offsetof(SQL_CONFIG,sqltrace), NULL, "no"},
56 {"sqltracefile", PW_TYPE_STRING_PTR,
57 offsetof(SQL_CONFIG,tracefile), NULL, SQLTRACEFILE},
58 {"readclients", PW_TYPE_BOOLEAN,
59 offsetof(SQL_CONFIG,do_clients), NULL, "no"},
60 {"deletestalesessions", PW_TYPE_BOOLEAN,
61 offsetof(SQL_CONFIG,deletestalesessions), NULL, "yes"},
62 {"num_sql_socks", PW_TYPE_INTEGER,
63 offsetof(SQL_CONFIG,num_sql_socks), NULL, "5"},
64 {"sql_user_name", PW_TYPE_STRING_PTR,
65 offsetof(SQL_CONFIG,query_user), NULL, ""},
66 {"default_user_profile", PW_TYPE_STRING_PTR,
67 offsetof(SQL_CONFIG,default_profile), NULL, ""},
68 {"nas_query", PW_TYPE_STRING_PTR,
69 offsetof(SQL_CONFIG,nas_query), NULL, "SELECT id,nasname,shortname,type,secret FROM nas"},
70 {"authorize_check_query", PW_TYPE_STRING_PTR,
71 offsetof(SQL_CONFIG,authorize_check_query), NULL, ""},
72 {"authorize_reply_query", PW_TYPE_STRING_PTR,
73 offsetof(SQL_CONFIG,authorize_reply_query), NULL, NULL},
74 {"authorize_group_check_query", PW_TYPE_STRING_PTR,
75 offsetof(SQL_CONFIG,authorize_group_check_query), NULL, ""},
76 {"authorize_group_reply_query", PW_TYPE_STRING_PTR,
77 offsetof(SQL_CONFIG,authorize_group_reply_query), NULL, ""},
78 {"accounting_onoff_query", PW_TYPE_STRING_PTR,
79 offsetof(SQL_CONFIG,accounting_onoff_query), NULL, ""},
80 {"accounting_update_query", PW_TYPE_STRING_PTR,
81 offsetof(SQL_CONFIG,accounting_update_query), NULL, ""},
82 {"accounting_update_query_alt", PW_TYPE_STRING_PTR,
83 offsetof(SQL_CONFIG,accounting_update_query_alt), NULL, ""},
84 {"accounting_start_query", PW_TYPE_STRING_PTR,
85 offsetof(SQL_CONFIG,accounting_start_query), NULL, ""},
86 {"accounting_start_query_alt", PW_TYPE_STRING_PTR,
87 offsetof(SQL_CONFIG,accounting_start_query_alt), NULL, ""},
88 {"accounting_stop_query", PW_TYPE_STRING_PTR,
89 offsetof(SQL_CONFIG,accounting_stop_query), NULL, ""},
90 {"accounting_stop_query_alt", PW_TYPE_STRING_PTR,
91 offsetof(SQL_CONFIG,accounting_stop_query_alt), NULL, ""},
92 {"group_membership_query", PW_TYPE_STRING_PTR,
93 offsetof(SQL_CONFIG,groupmemb_query), NULL, NULL},
94 {"connect_failure_retry_delay", PW_TYPE_INTEGER,
95 offsetof(SQL_CONFIG,connect_failure_retry_delay), NULL, "60"},
96 {"simul_count_query", PW_TYPE_STRING_PTR,
97 offsetof(SQL_CONFIG,simul_count_query), NULL, ""},
98 {"simul_verify_query", PW_TYPE_STRING_PTR,
99 offsetof(SQL_CONFIG,simul_verify_query), NULL, ""},
100 {"postauth_query", PW_TYPE_STRING_PTR,
101 offsetof(SQL_CONFIG,postauth_query), NULL, ""},
102 {"safe-characters", PW_TYPE_STRING_PTR,
103 offsetof(SQL_CONFIG,allowed_chars), NULL,
104 "@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_: /"},
106 {NULL, -1, 0, NULL, NULL}
110 * Fall-Through checking function from rlm_files.c
112 static int fallthrough(VALUE_PAIR *vp)
115 tmp = pairfind(vp, PW_FALL_THROUGH);
117 return tmp ? tmp->vp_integer : 0;
125 static int generate_sql_clients(SQL_INST *inst);
126 static size_t sql_escape_func(char *out, size_t outlen, const char *in);
129 * sql xlat function. Right now only SELECTs are supported. Only
130 * the first element of the SELECT result will be used.
132 static int sql_xlat(void *instance, REQUEST *request,
133 char *fmt, char *out, size_t freespace,
134 UNUSED RADIUS_ESCAPE_STRING func)
138 SQL_INST *inst = instance;
139 char querystr[MAX_QUERY_LEN];
140 char sqlusername[MAX_STRING_LEN];
146 * Add SQL-User-Name attribute just in case it is needed
147 * We could search the string fmt for SQL-User-Name to see if this is
150 sql_set_user(inst, request, sqlusername, NULL);
152 * Do an xlat on the provided string (nice recursive operation).
154 if (!radius_xlat(querystr, sizeof(querystr), fmt, request, sql_escape_func)) {
155 radlog(L_ERR, "rlm_sql (%s): xlat failed.",
156 inst->config->xlat_name);
160 query_log(request, inst,querystr);
161 sqlsocket = sql_get_socket(inst);
162 if (sqlsocket == NULL)
164 if (rlm_sql_select_query(sqlsocket,inst,querystr)){
165 radlog(L_ERR, "rlm_sql (%s): database query error, %s: %s",
166 inst->config->xlat_name,querystr,
167 (inst->module->sql_error)(sqlsocket, inst->config));
168 sql_release_socket(inst,sqlsocket);
172 ret = rlm_sql_fetch_row(sqlsocket, inst);
175 RDEBUG("SQL query did not succeed");
176 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
177 sql_release_socket(inst,sqlsocket);
181 row = sqlsocket->row;
183 RDEBUG("SQL query did not return any results");
184 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
185 sql_release_socket(inst,sqlsocket);
190 RDEBUG("row[0] returned NULL");
191 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
192 sql_release_socket(inst,sqlsocket);
195 ret = strlen(row[0]);
196 if (ret >= freespace){
197 RDEBUG("Insufficient string space");
198 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
199 sql_release_socket(inst,sqlsocket);
203 strlcpy(out,row[0],freespace);
205 RDEBUG("sql_xlat finished");
207 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
208 sql_release_socket(inst,sqlsocket);
212 static int generate_sql_clients(SQL_INST *inst)
216 char querystr[MAX_QUERY_LEN];
218 char *prefix_ptr = NULL;
222 DEBUG("rlm_sql (%s): Processing generate_sql_clients",
223 inst->config->xlat_name);
225 /* NAS query isn't xlat'ed */
226 strlcpy(querystr, inst->config->nas_query, sizeof(querystr));
227 DEBUG("rlm_sql (%s) in generate_sql_clients: query is %s",
228 inst->config->xlat_name, querystr);
230 sqlsocket = sql_get_socket(inst);
231 if (sqlsocket == NULL)
233 if (rlm_sql_select_query(sqlsocket,inst,querystr)){
234 radlog(L_ERR, "rlm_sql (%s): database query error, %s: %s",
235 inst->config->xlat_name,querystr,
236 (inst->module->sql_error)(sqlsocket, inst->config));
237 sql_release_socket(inst,sqlsocket);
241 while(rlm_sql_fetch_row(sqlsocket, inst) == 0) {
243 row = sqlsocket->row;
247 * The return data for each row MUST be in the following order:
249 * 0. Row ID (currently unused)
250 * 1. Name (or IP address)
254 * 5. Virtual Server (optional)
257 radlog(L_ERR, "rlm_sql (%s): No row id found on pass %d",inst->config->xlat_name,i);
261 radlog(L_ERR, "rlm_sql (%s): No nasname found for row %s",inst->config->xlat_name,row[0]);
265 radlog(L_ERR, "rlm_sql (%s): No short name found for row %s",inst->config->xlat_name,row[0]);
269 radlog(L_ERR, "rlm_sql (%s): No secret found for row %s",inst->config->xlat_name,row[0]);
273 DEBUG("rlm_sql (%s): Read entry nasname=%s,shortname=%s,secret=%s",inst->config->xlat_name,
274 row[1],row[2],row[4]);
276 c = rad_malloc(sizeof(*c));
277 memset(c, 0, sizeof(*c));
279 #ifdef WITH_DYNAMIC_CLIENTS
287 prefix_ptr = strchr(row[1], '/');
289 c->prefix = atoi(prefix_ptr + 1);
290 if ((c->prefix < 0) || (c->prefix > 128)) {
291 radlog(L_ERR, "rlm_sql (%s): Invalid Prefix value '%s' for IP.",
292 inst->config->xlat_name, prefix_ptr + 1);
296 /* Replace '/' with '\0' */
301 * Always get the numeric representation of IP
303 if (ip_hton(row[1], AF_UNSPEC, &c->ipaddr) < 0) {
304 radlog(L_CONS|L_ERR, "rlm_sql (%s): Failed to look up hostname %s: %s",
305 inst->config->xlat_name,
306 row[1], fr_strerror());
311 ip_ntoh(&c->ipaddr, buffer, sizeof(buffer));
312 c->longname = strdup(buffer);
315 if (c->prefix < 0) switch (c->ipaddr.af) {
327 * Other values (secret, shortname, nastype, virtual_server)
329 c->secret = strdup(row[4]);
330 c->shortname = strdup(row[2]);
332 c->nastype = strdup(row[3]);
334 numf = (inst->module->sql_num_fields)(sqlsocket, inst->config);
335 if ((numf > 5) && (row[5] != NULL)) c->server = strdup(row[5]);
337 DEBUG("rlm_sql (%s): Adding client %s (%s, server=%s) to clients list",
338 inst->config->xlat_name,
339 c->longname,c->shortname, c->server ? c->server : "<none>");
340 if (!client_add(NULL, c)) {
341 DEBUG("rlm_sql (%s): Failed to add client %s (%s) to clients list. Maybe there's a duplicate?",
342 inst->config->xlat_name,
343 c->longname,c->shortname);
348 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
349 sql_release_socket(inst, sqlsocket);
356 * Translate the SQL queries.
358 static size_t sql_escape_func(char *out, size_t outlen, const char *in)
364 * Non-printable characters get replaced with their
365 * mime-encoded equivalents.
368 strchr(allowed_chars, *in) == NULL) {
370 * Only 3 or less bytes available.
376 snprintf(out, outlen, "=%02X", (unsigned char) in[0]);
385 * Only one byte left.
405 * Set the SQL user name.
407 * We don't call the escape function here. The resulting string
408 * will be escaped later in the queries xlat so we don't need to
409 * escape it twice. (it will make things wrong if we have an
410 * escape candidate character in the username)
412 int sql_set_user(SQL_INST *inst, REQUEST *request, char *sqlusername, const char *username)
415 char tmpuser[MAX_STRING_LEN];
418 sqlusername[0]= '\0';
420 /* Remove any user attr we added previously */
421 pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
423 if (username != NULL) {
424 strlcpy(tmpuser, username, sizeof(tmpuser));
425 } else if (strlen(inst->config->query_user)) {
426 radius_xlat(tmpuser, sizeof(tmpuser), inst->config->query_user, request, NULL);
431 strlcpy(sqlusername, tmpuser, MAX_STRING_LEN);
432 RDEBUG2("sql_set_user escaped user --> '%s'", sqlusername);
433 vp = radius_pairmake(request, &request->packet->vps,
434 "SQL-User-Name", NULL, 0);
436 radlog(L_ERR, "%s", fr_strerror());
440 strlcpy(vp->vp_strvalue, tmpuser, sizeof(vp->vp_strvalue));
441 vp->length = strlen(vp->vp_strvalue);
448 static void sql_grouplist_free (SQL_GROUPLIST **group_list)
454 *group_list = (*group_list)->next;
460 static int sql_get_grouplist (SQL_INST *inst, SQLSOCK *sqlsocket, REQUEST *request, SQL_GROUPLIST **group_list)
462 char querystr[MAX_QUERY_LEN];
465 SQL_GROUPLIST *group_list_tmp;
467 /* NOTE: sql_set_user should have been run before calling this function */
469 group_list_tmp = *group_list = NULL;
471 if (!inst->config->groupmemb_query ||
472 (inst->config->groupmemb_query[0] == 0))
475 if (!radius_xlat(querystr, sizeof(querystr), inst->config->groupmemb_query, request, sql_escape_func)) {
476 radlog_request(L_ERR, 0, request, "xlat \"%s\" failed.",
477 inst->config->groupmemb_query);
481 if (rlm_sql_select_query(sqlsocket, inst, querystr) < 0) {
482 radlog_request(L_ERR, 0, request,
483 "database query error, %s: %s",
485 (inst->module->sql_error)(sqlsocket,inst->config));
488 while (rlm_sql_fetch_row(sqlsocket, inst) == 0) {
489 row = sqlsocket->row;
493 RDEBUG("row[0] returned NULL");
494 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
495 sql_grouplist_free(group_list);
498 if (*group_list == NULL) {
499 *group_list = rad_malloc(sizeof(SQL_GROUPLIST));
500 group_list_tmp = *group_list;
502 group_list_tmp->next = rad_malloc(sizeof(SQL_GROUPLIST));
503 group_list_tmp = group_list_tmp->next;
505 group_list_tmp->next = NULL;
506 strlcpy(group_list_tmp->groupname, row[0], MAX_STRING_LEN);
509 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
516 * sql groupcmp function. That way we can do group comparisons (in the users file for example)
517 * with the group memberships reciding in sql
518 * The group membership query should only return one element which is the username. The returned
519 * username will then be checked with the passed check string.
522 static int sql_groupcmp(void *instance, REQUEST *request, VALUE_PAIR *request_vp, VALUE_PAIR *check,
523 VALUE_PAIR *check_pairs, VALUE_PAIR **reply_pairs)
526 SQL_INST *inst = instance;
527 char sqlusername[MAX_STRING_LEN];
528 SQL_GROUPLIST *group_list, *group_list_tmp;
530 check_pairs = check_pairs;
531 reply_pairs = reply_pairs;
532 request_vp = request_vp;
534 RDEBUG("sql_groupcmp");
535 if (!check || !check->vp_strvalue || !check->length){
536 RDEBUG("sql_groupcmp: Illegal group name");
540 RDEBUG("sql_groupcmp: NULL request");
544 * Set, escape, and check the user attr here
546 if (sql_set_user(inst, request, sqlusername, NULL) < 0)
550 * Get a socket for this lookup
552 sqlsocket = sql_get_socket(inst);
553 if (sqlsocket == NULL) {
554 /* Remove the username we (maybe) added above */
555 pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
560 * Get the list of groups this user is a member of
562 if (sql_get_grouplist(inst, sqlsocket, request, &group_list) < 0) {
563 radlog_request(L_ERR, 0, request,
564 "Error getting group membership");
565 /* Remove the username we (maybe) added above */
566 pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
567 sql_release_socket(inst, sqlsocket);
571 for (group_list_tmp = group_list; group_list_tmp != NULL; group_list_tmp = group_list_tmp->next) {
572 if (strcmp(group_list_tmp->groupname, check->vp_strvalue) == 0){
573 RDEBUG("sql_groupcmp finished: User is a member of group %s",
575 /* Free the grouplist */
576 sql_grouplist_free(&group_list);
577 /* Remove the username we (maybe) added above */
578 pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
579 sql_release_socket(inst, sqlsocket);
584 /* Free the grouplist */
585 sql_grouplist_free(&group_list);
586 /* Remove the username we (maybe) added above */
587 pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
588 sql_release_socket(inst,sqlsocket);
590 RDEBUG("sql_groupcmp finished: User is NOT a member of group %s",
598 static int rlm_sql_process_groups(SQL_INST *inst, REQUEST *request, SQLSOCK *sqlsocket, int *dofallthrough)
600 VALUE_PAIR *check_tmp = NULL;
601 VALUE_PAIR *reply_tmp = NULL;
602 SQL_GROUPLIST *group_list, *group_list_tmp;
603 VALUE_PAIR *sql_group = NULL;
604 char querystr[MAX_QUERY_LEN];
609 * Get the list of groups this user is a member of
611 if (sql_get_grouplist(inst, sqlsocket, request, &group_list) < 0) {
612 radlog_request(L_ERR, 0, request, "Error retrieving group list");
616 for (group_list_tmp = group_list; group_list_tmp != NULL && *dofallthrough != 0; group_list_tmp = group_list_tmp->next) {
618 * Add the Sql-Group attribute to the request list so we know
619 * which group we're retrieving attributes for
621 sql_group = pairmake("Sql-Group", group_list_tmp->groupname, T_OP_EQ);
623 radlog_request(L_ERR, 0, request,
624 "Error creating Sql-Group attribute");
627 pairadd(&request->packet->vps, sql_group);
628 if (!radius_xlat(querystr, sizeof(querystr), inst->config->authorize_group_check_query, request, sql_escape_func)) {
629 radlog_request(L_ERR, 0, request,
630 "Error generating query; rejecting user");
631 /* Remove the grouup we added above */
632 pairdelete(&request->packet->vps, PW_SQL_GROUP);
635 rows = sql_getvpdata(inst, sqlsocket, &check_tmp, querystr);
637 radlog_request(L_ERR, 0, request, "Error retrieving check pairs for group %s",
638 group_list_tmp->groupname);
639 /* Remove the grouup we added above */
640 pairdelete(&request->packet->vps, PW_SQL_GROUP);
641 pairfree(&check_tmp);
643 } else if (rows > 0) {
645 * Only do this if *some* check pairs were returned
647 if (paircompare(request, request->packet->vps, check_tmp, &request->reply->vps) == 0) {
649 RDEBUG2("User found in group %s",
650 group_list_tmp->groupname);
652 * Now get the reply pairs since the paircompare matched
654 if (!radius_xlat(querystr, sizeof(querystr), inst->config->authorize_group_reply_query, request, sql_escape_func)) {
655 radlog_request(L_ERR, 0, request, "Error generating query; rejecting user");
656 /* Remove the grouup we added above */
657 pairdelete(&request->packet->vps, PW_SQL_GROUP);
658 pairfree(&check_tmp);
661 if (sql_getvpdata(inst, sqlsocket, &reply_tmp, querystr) < 0) {
662 radlog_request(L_ERR, 0, request, "Error retrieving reply pairs for group %s",
663 group_list_tmp->groupname);
664 /* Remove the grouup we added above */
665 pairdelete(&request->packet->vps, PW_SQL_GROUP);
666 pairfree(&check_tmp);
667 pairfree(&reply_tmp);
670 *dofallthrough = fallthrough(reply_tmp);
671 pairxlatmove(request, &request->reply->vps, &reply_tmp);
672 pairxlatmove(request, &request->config_items, &check_tmp);
676 * rows == 0. This is like having the username on a line
677 * in the user's file with no check vp's. As such, we treat
678 * it as found and add the reply attributes, so that we
679 * match expected behavior
682 RDEBUG2("User found in group %s",
683 group_list_tmp->groupname);
685 * Now get the reply pairs since the paircompare matched
687 if (!radius_xlat(querystr, sizeof(querystr), inst->config->authorize_group_reply_query, request, sql_escape_func)) {
688 radlog_request(L_ERR, 0, request, "Error generating query; rejecting user");
689 /* Remove the grouup we added above */
690 pairdelete(&request->packet->vps, PW_SQL_GROUP);
691 pairfree(&check_tmp);
694 if (sql_getvpdata(inst, sqlsocket, &reply_tmp, querystr) < 0) {
695 radlog_request(L_ERR, 0, request, "Error retrieving reply pairs for group %s",
696 group_list_tmp->groupname);
697 /* Remove the grouup we added above */
698 pairdelete(&request->packet->vps, PW_SQL_GROUP);
699 pairfree(&check_tmp);
700 pairfree(&reply_tmp);
703 *dofallthrough = fallthrough(reply_tmp);
704 pairxlatmove(request, &request->reply->vps, &reply_tmp);
705 pairxlatmove(request, &request->config_items, &check_tmp);
709 * Delete the Sql-Group we added above
710 * And clear out the pairlists
712 pairdelete(&request->packet->vps, PW_SQL_GROUP);
713 pairfree(&check_tmp);
714 pairfree(&reply_tmp);
717 sql_grouplist_free(&group_list);
722 static int rlm_sql_detach(void *instance)
724 SQL_INST *inst = instance;
726 paircompare_unregister(PW_SQL_GROUP, sql_groupcmp);
735 if (inst->config->xlat_name) {
736 xlat_unregister(inst->config->xlat_name,(RAD_XLAT_FUNC)sql_xlat);
737 free(inst->config->xlat_name);
741 * Free up dynamically allocated string pointers.
743 for (i = 0; module_config[i].name != NULL; i++) {
745 if (module_config[i].type != PW_TYPE_STRING_PTR) {
750 * Treat 'config' as an opaque array of bytes,
751 * and take the offset into it. There's a
752 * (char*) pointer at that offset, and we want
755 p = (char **) (((char *)inst->config) + module_config[i].offset);
756 if (!*p) { /* nothing allocated */
762 allowed_chars = NULL;
770 * FIXME: Call the modules 'destroy' function?
772 lt_dlclose(inst->handle); /* ignore any errors */
779 static int rlm_sql_instantiate(CONF_SECTION * conf, void **instance)
782 const char *xlat_name;
784 inst = rad_malloc(sizeof(SQL_INST));
785 memset(inst, 0, sizeof(SQL_INST));
787 inst->config = rad_malloc(sizeof(SQL_CONFIG));
788 memset(inst->config, 0, sizeof(SQL_CONFIG));
791 * Export these methods, too. This avoids RTDL_GLOBAL.
793 inst->sql_set_user = sql_set_user;
794 inst->sql_get_socket = sql_get_socket;
795 inst->sql_release_socket = sql_release_socket;
796 inst->sql_escape_func = sql_escape_func;
799 * If the configuration parameters can't be parsed, then
802 if (cf_section_parse(conf, inst->config, module_config) < 0) {
803 rlm_sql_detach(inst);
807 xlat_name = cf_section_name2(conf);
808 if (xlat_name == NULL)
809 xlat_name = cf_section_name1(conf);
811 inst->config->xlat_name = strdup(xlat_name);
812 xlat_register(xlat_name, (RAD_XLAT_FUNC)sql_xlat, inst);
815 if (inst->config->num_sql_socks > MAX_SQL_SOCKS) {
816 radlog(L_ERR, "rlm_sql (%s): sql_instantiate: number of sqlsockets cannot exceed MAX_SQL_SOCKS, %d",
817 inst->config->xlat_name, MAX_SQL_SOCKS);
818 rlm_sql_detach(inst);
823 * Sanity check for crazy people.
825 if (strncmp(inst->config->sql_driver, "rlm_sql_", 8) != 0) {
826 radlog(L_ERR, "\"%s\" is NOT an SQL driver!",
827 inst->config->sql_driver);
828 rlm_sql_detach(inst);
832 inst->handle = lt_dlopenext(inst->config->sql_driver);
833 if (inst->handle == NULL) {
834 radlog(L_ERR, "Could not link driver %s: %s",
835 inst->config->sql_driver,
837 radlog(L_ERR, "Make sure it (and all its dependent libraries!) are in the search path of your system's ld.");
838 rlm_sql_detach(inst);
842 inst->module = (rlm_sql_module_t *) lt_dlsym(inst->handle, inst->config->sql_driver);
844 radlog(L_ERR, "Could not link symbol %s: %s",
845 inst->config->sql_driver,
847 rlm_sql_detach(inst);
851 radlog(L_INFO, "rlm_sql (%s): Driver %s (module %s) loaded and linked",
852 inst->config->xlat_name, inst->config->sql_driver,
854 radlog(L_INFO, "rlm_sql (%s): Attempting to connect to %s@%s:%s/%s",
855 inst->config->xlat_name, inst->config->sql_login,
856 inst->config->sql_server, inst->config->sql_port,
857 inst->config->sql_db);
859 if (sql_init_socketpool(inst) < 0) {
860 rlm_sql_detach(inst);
864 paircompare_register(PW_SQL_GROUP, PW_USER_NAME, sql_groupcmp, inst);
866 if (inst->config->do_clients){
867 if (generate_sql_clients(inst) == -1){
868 radlog(L_ERR, "Failed to load clients from SQL.");
869 rlm_sql_detach(inst);
873 allowed_chars = inst->config->allowed_chars;
877 return RLM_MODULE_OK;
881 static int rlm_sql_authorize(void *instance, REQUEST * request)
883 VALUE_PAIR *check_tmp = NULL;
884 VALUE_PAIR *reply_tmp = NULL;
885 VALUE_PAIR *user_profile = NULL;
887 int dofallthrough = 1;
890 SQL_INST *inst = instance;
891 char querystr[MAX_QUERY_LEN];
892 char sqlusername[MAX_STRING_LEN];
894 * the profile username is used as the sqlusername during
895 * profile checking so that we don't overwrite the orignal
898 char profileusername[MAX_STRING_LEN];
901 * Set, escape, and check the user attr here
903 if (sql_set_user(inst, request, sqlusername, NULL) < 0)
904 return RLM_MODULE_FAIL;
910 sqlsocket = sql_get_socket(inst);
911 if (sqlsocket == NULL) {
912 /* Remove the username we (maybe) added above */
913 pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
914 return RLM_MODULE_FAIL;
919 * After this point, ALL 'return's MUST release the SQL socket!
923 * Alright, start by getting the specific entry for the user
925 if (!radius_xlat(querystr, sizeof(querystr), inst->config->authorize_check_query, request, sql_escape_func)) {
926 radlog_request(L_ERR, 0, request, "Error generating query; rejecting user");
927 sql_release_socket(inst, sqlsocket);
928 /* Remove the username we (maybe) added above */
929 pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
930 return RLM_MODULE_FAIL;
932 rows = sql_getvpdata(inst, sqlsocket, &check_tmp, querystr);
934 radlog_request(L_ERR, 0, request, "SQL query error; rejecting user");
935 sql_release_socket(inst, sqlsocket);
936 /* Remove the username we (maybe) added above */
937 pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
938 pairfree(&check_tmp);
939 return RLM_MODULE_FAIL;
940 } else if (rows > 0) {
942 * Only do this if *some* check pairs were returned
944 if (paircompare(request, request->packet->vps, check_tmp, &request->reply->vps) == 0) {
946 RDEBUG2("User found in radcheck table");
948 if (inst->config->authorize_reply_query &&
949 *inst->config->authorize_reply_query) {
952 * Now get the reply pairs since the paircompare matched
954 if (!radius_xlat(querystr, sizeof(querystr), inst->config->authorize_reply_query, request, sql_escape_func)) {
955 radlog_request(L_ERR, 0, request, "Error generating query; rejecting user");
956 sql_release_socket(inst, sqlsocket);
957 /* Remove the username we (maybe) added above */
958 pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
959 pairfree(&check_tmp);
960 return RLM_MODULE_FAIL;
962 if (sql_getvpdata(inst, sqlsocket, &reply_tmp, querystr) < 0) {
963 radlog_request(L_ERR, 0, request, "SQL query error; rejecting user");
964 sql_release_socket(inst, sqlsocket);
965 /* Remove the username we (maybe) added above */
966 pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
967 pairfree(&check_tmp);
968 pairfree(&reply_tmp);
969 return RLM_MODULE_FAIL;
972 if (!inst->config->read_groups)
973 dofallthrough = fallthrough(reply_tmp);
974 pairxlatmove(request, &request->reply->vps, &reply_tmp);
976 pairxlatmove(request, &request->config_items, &check_tmp);
981 * Clear out the pairlists
983 pairfree(&check_tmp);
984 pairfree(&reply_tmp);
987 * dofallthrough is set to 1 by default so that if the user information
988 * is not found, we will still process groups. If the user information,
989 * however, *is* found, Fall-Through must be set in order to process
993 rows = rlm_sql_process_groups(inst, request, sqlsocket, &dofallthrough);
995 radlog_request(L_ERR, 0, request, "Error processing groups; rejecting user");
996 sql_release_socket(inst, sqlsocket);
997 /* Remove the username we (maybe) added above */
998 pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
999 return RLM_MODULE_FAIL;
1000 } else if (rows > 0) {
1006 * repeat the above process with the default profile or User-Profile
1008 if (dofallthrough) {
1009 int profile_found = 0;
1011 * Check for a default_profile or for a User-Profile.
1013 user_profile = pairfind(request->config_items, PW_USER_PROFILE);
1014 if (inst->config->default_profile[0] != 0 || user_profile != NULL){
1015 char *profile = inst->config->default_profile;
1017 if (user_profile != NULL)
1018 profile = user_profile->vp_strvalue;
1019 if (profile && strlen(profile)){
1020 RDEBUG("Checking profile %s", profile);
1021 if (sql_set_user(inst, request, profileusername, profile) < 0) {
1022 radlog_request(L_ERR, 0, request, "Error setting profile; rejecting user");
1023 sql_release_socket(inst, sqlsocket);
1024 /* Remove the username we (maybe) added above */
1025 pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
1026 return RLM_MODULE_FAIL;
1033 if (profile_found) {
1034 rows = rlm_sql_process_groups(inst, request, sqlsocket, &dofallthrough);
1036 radlog_request(L_ERR, 0, request, "Error processing profile groups; rejecting user");
1037 sql_release_socket(inst, sqlsocket);
1038 /* Remove the username we (maybe) added above */
1039 pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
1040 return RLM_MODULE_FAIL;
1041 } else if (rows > 0) {
1047 /* Remove the username we (maybe) added above */
1048 pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
1049 sql_release_socket(inst, sqlsocket);
1052 RDEBUG("User %s not found", sqlusername);
1053 return RLM_MODULE_NOTFOUND;
1055 return RLM_MODULE_OK;
1060 * Accounting: save the account data to our sql table
1062 static int rlm_sql_accounting(void *instance, REQUEST * request) {
1064 SQLSOCK *sqlsocket = NULL;
1066 SQL_INST *inst = instance;
1067 int ret = RLM_MODULE_OK;
1068 int numaffected = 0;
1069 int acctstatustype = 0;
1070 char querystr[MAX_QUERY_LEN];
1071 char logstr[MAX_QUERY_LEN];
1072 char sqlusername[MAX_STRING_LEN];
1074 #ifdef CISCO_ACCOUNTING_HACK
1075 int acctsessiontime = 0;
1078 memset(querystr, 0, MAX_QUERY_LEN);
1081 * Find the Acct Status Type
1083 if ((pair = pairfind(request->packet->vps, PW_ACCT_STATUS_TYPE)) != NULL) {
1084 acctstatustype = pair->vp_integer;
1086 radius_xlat(logstr, sizeof(logstr), "packet has no accounting status type. [user '%{User-Name}', nas '%{NAS-IP-Address}']", request, NULL);
1087 radlog_request(L_ERR, 0, request, "%s", logstr);
1088 return RLM_MODULE_INVALID;
1091 switch (acctstatustype) {
1093 * The Terminal server informed us that it was rebooted
1094 * STOP all records from this NAS
1096 case PW_STATUS_ACCOUNTING_ON:
1097 case PW_STATUS_ACCOUNTING_OFF:
1098 RDEBUG("Received Acct On/Off packet");
1099 radius_xlat(querystr, sizeof(querystr), inst->config->accounting_onoff_query, request, sql_escape_func);
1100 query_log(request, inst, querystr);
1102 sqlsocket = sql_get_socket(inst);
1103 if (sqlsocket == NULL)
1104 return(RLM_MODULE_FAIL);
1105 if (*querystr) { /* non-empty query */
1106 if (rlm_sql_query(sqlsocket, inst, querystr)) {
1107 radlog_request(L_ERR, 0, request, "Couldn't update SQL accounting for Acct On/Off packet - %s",
1108 (inst->module->sql_error)(sqlsocket, inst->config));
1109 ret = RLM_MODULE_FAIL;
1111 (inst->module->sql_finish_query)(sqlsocket, inst->config);
1117 * Got an update accounting packet
1119 case PW_STATUS_ALIVE:
1122 * Set, escape, and check the user attr here
1124 sql_set_user(inst, request, sqlusername, NULL);
1126 radius_xlat(querystr, sizeof(querystr), inst->config->accounting_update_query, request, sql_escape_func);
1127 query_log(request, inst, querystr);
1129 sqlsocket = sql_get_socket(inst);
1130 if (sqlsocket == NULL)
1131 return(RLM_MODULE_FAIL);
1132 if (*querystr) { /* non-empty query */
1133 if (rlm_sql_query(sqlsocket, inst, querystr)) {
1134 radlog_request(L_ERR, 0, request, "Couldn't update SQL accounting ALIVE record - %s",
1135 (inst->module->sql_error)(sqlsocket, inst->config));
1136 ret = RLM_MODULE_FAIL;
1139 numaffected = (inst->module->sql_affected_rows)(sqlsocket, inst->config);
1140 if (numaffected < 1) {
1143 * If our update above didn't match anything
1144 * we assume it's because we haven't seen a
1145 * matching Start record. So we have to
1146 * insert this update rather than do an update
1148 radius_xlat(querystr, sizeof(querystr), inst->config->accounting_update_query_alt, request, sql_escape_func);
1149 query_log(request, inst, querystr);
1150 if (*querystr) { /* non-empty query */
1151 if (rlm_sql_query(sqlsocket, inst, querystr)) {
1152 radlog_request(L_ERR, 0, request, "Couldn't insert SQL accounting ALIVE record - %s",
1153 (inst->module->sql_error)(sqlsocket, inst->config));
1154 ret = RLM_MODULE_FAIL;
1156 (inst->module->sql_finish_query)(sqlsocket, inst->config);
1160 (inst->module->sql_finish_query)(sqlsocket, inst->config);
1165 * Got accounting start packet
1167 case PW_STATUS_START:
1170 * Set, escape, and check the user attr here
1172 sql_set_user(inst, request, sqlusername, NULL);
1174 radius_xlat(querystr, sizeof(querystr), inst->config->accounting_start_query, request, sql_escape_func);
1175 query_log(request, inst, querystr);
1177 sqlsocket = sql_get_socket(inst);
1178 if (sqlsocket == NULL)
1179 return(RLM_MODULE_FAIL);
1180 if (*querystr) { /* non-empty query */
1181 if (rlm_sql_query(sqlsocket, inst, querystr)) {
1182 radlog_request(L_ERR, 0, request, "Couldn't insert SQL accounting START record - %s",
1183 (inst->module->sql_error)(sqlsocket, inst->config));
1186 * We failed the insert above. It's probably because
1187 * the stop record came before the start. We try
1188 * our alternate query now (typically an UPDATE)
1190 radius_xlat(querystr, sizeof(querystr), inst->config->accounting_start_query_alt, request, sql_escape_func);
1191 query_log(request, inst, querystr);
1193 if (*querystr) { /* non-empty query */
1194 if (rlm_sql_query(sqlsocket, inst, querystr)) {
1195 radlog_request(L_ERR, 0, request, "Couldn't update SQL accounting START record - %s",
1196 (inst->module->sql_error)(sqlsocket, inst->config));
1197 ret = RLM_MODULE_FAIL;
1199 (inst->module->sql_finish_query)(sqlsocket, inst->config);
1202 (inst->module->sql_finish_query)(sqlsocket, inst->config);
1207 * Got accounting stop packet
1209 case PW_STATUS_STOP:
1212 * Set, escape, and check the user attr here
1214 sql_set_user(inst, request, sqlusername, NULL);
1216 radius_xlat(querystr, sizeof(querystr), inst->config->accounting_stop_query, request, sql_escape_func);
1217 query_log(request, inst, querystr);
1219 sqlsocket = sql_get_socket(inst);
1220 if (sqlsocket == NULL)
1221 return(RLM_MODULE_FAIL);
1222 if (*querystr) { /* non-empty query */
1223 if (rlm_sql_query(sqlsocket, inst, querystr)) {
1224 radlog_request(L_ERR, 0, request, "Couldn't update SQL accounting STOP record - %s",
1225 (inst->module->sql_error)(sqlsocket, inst->config));
1226 ret = RLM_MODULE_FAIL;
1229 numaffected = (inst->module->sql_affected_rows)(sqlsocket, inst->config);
1230 if (numaffected < 1) {
1232 * If our update above didn't match anything
1233 * we assume it's because we haven't seen a
1234 * matching Start record. So we have to
1235 * insert this stop rather than do an update
1237 #ifdef CISCO_ACCOUNTING_HACK
1239 * If stop but zero session length AND no previous
1240 * session found, drop it as in invalid packet
1241 * This is to fix CISCO's aaa from filling our
1242 * table with bogus crap
1244 if ((pair = pairfind(request->packet->vps, PW_ACCT_SESSION_TIME)) != NULL)
1245 acctsessiontime = pair->vp_integer;
1247 if (acctsessiontime <= 0) {
1248 radius_xlat(logstr, sizeof(logstr), "stop packet with zero session length. [user '%{User-Name}', nas '%{NAS-IP-Address}']", request, NULL);
1249 radlog_request(L_ERR, 0, request, "%s", logstr);
1250 sql_release_socket(inst, sqlsocket);
1251 ret = RLM_MODULE_NOOP;
1255 radius_xlat(querystr, sizeof(querystr), inst->config->accounting_stop_query_alt, request, sql_escape_func);
1256 query_log(request, inst, querystr);
1258 if (*querystr) { /* non-empty query */
1259 if (rlm_sql_query(sqlsocket, inst, querystr)) {
1260 radlog_request(L_ERR, 0, request, "Couldn't insert SQL accounting STOP record - %s",
1262 (inst->module->sql_error)(sqlsocket, inst->config));
1263 ret = RLM_MODULE_FAIL;
1265 (inst->module->sql_finish_query)(sqlsocket, inst->config);
1269 (inst->module->sql_finish_query)(sqlsocket, inst->config);
1274 * Anything else is ignored.
1277 RDEBUG("Unsupported Acct-Status-Type = %d",
1279 return RLM_MODULE_NOOP;
1284 sql_release_socket(inst, sqlsocket);
1291 * See if a user is already logged in. Sets request->simul_count to the
1292 * current session count for this user.
1294 * Check twice. If on the first pass the user exceeds his
1295 * max. number of logins, do a second pass and validate all
1296 * logins by querying the terminal server (using eg. SNMP).
1299 static int rlm_sql_checksimul(void *instance, REQUEST * request) {
1301 SQL_INST *inst = instance;
1303 char querystr[MAX_QUERY_LEN];
1304 char sqlusername[MAX_STRING_LEN];
1307 char *call_num = NULL;
1310 uint32_t nas_addr = 0;
1313 /* If simul_count_query is not defined, we don't do any checking */
1314 if (!inst->config->simul_count_query ||
1315 (inst->config->simul_count_query[0] == 0)) {
1316 return RLM_MODULE_NOOP;
1319 if((request->username == NULL) || (request->username->length == 0)) {
1320 radlog_request(L_ERR, 0, request, "Zero Length username not permitted\n");
1321 return RLM_MODULE_INVALID;
1325 if(sql_set_user(inst, request, sqlusername, NULL) < 0)
1326 return RLM_MODULE_FAIL;
1328 radius_xlat(querystr, sizeof(querystr), inst->config->simul_count_query, request, sql_escape_func);
1330 /* initialize the sql socket */
1331 sqlsocket = sql_get_socket(inst);
1332 if(sqlsocket == NULL)
1333 return RLM_MODULE_FAIL;
1335 if(rlm_sql_select_query(sqlsocket, inst, querystr)) {
1336 radlog(L_ERR, "rlm_sql (%s) sql_checksimul: Database query failed", inst->config->xlat_name);
1337 sql_release_socket(inst, sqlsocket);
1338 return RLM_MODULE_FAIL;
1341 ret = rlm_sql_fetch_row(sqlsocket, inst);
1344 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
1345 sql_release_socket(inst, sqlsocket);
1346 return RLM_MODULE_FAIL;
1349 row = sqlsocket->row;
1351 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
1352 sql_release_socket(inst, sqlsocket);
1353 return RLM_MODULE_FAIL;
1356 request->simul_count = atoi(row[0]);
1357 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
1359 if(request->simul_count < request->simul_max) {
1360 sql_release_socket(inst, sqlsocket);
1361 return RLM_MODULE_OK;
1365 * Looks like too many sessions, so let's start verifying
1366 * them, unless told to rely on count query only.
1368 if (!inst->config->simul_verify_query ||
1369 (inst->config->simul_verify_query[0] == '\0')) {
1370 sql_release_socket(inst, sqlsocket);
1371 return RLM_MODULE_OK;
1374 radius_xlat(querystr, sizeof(querystr), inst->config->simul_verify_query, request, sql_escape_func);
1375 if(rlm_sql_select_query(sqlsocket, inst, querystr)) {
1376 radlog_request(L_ERR, 0, request, "Database query error");
1377 sql_release_socket(inst, sqlsocket);
1378 return RLM_MODULE_FAIL;
1382 * Setup some stuff, like for MPP detection.
1384 request->simul_count = 0;
1386 if ((vp = pairfind(request->packet->vps, PW_FRAMED_IP_ADDRESS)) != NULL)
1387 ipno = vp->vp_ipaddr;
1388 if ((vp = pairfind(request->packet->vps, PW_CALLING_STATION_ID)) != NULL)
1389 call_num = vp->vp_strvalue;
1392 while (rlm_sql_fetch_row(sqlsocket, inst) == 0) {
1393 row = sqlsocket->row;
1397 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
1398 sql_release_socket(inst, sqlsocket);
1399 RDEBUG("Cannot zap stale entry. No username present in entry.", inst->config->xlat_name);
1400 return RLM_MODULE_FAIL;
1403 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
1404 sql_release_socket(inst, sqlsocket);
1405 RDEBUG("Cannot zap stale entry. No session id in entry.", inst->config->xlat_name);
1406 return RLM_MODULE_FAIL;
1409 nas_addr = inet_addr(row[3]);
1411 nas_port = atoi(row[4]);
1413 check = rad_check_ts(nas_addr, nas_port, row[2], row[1]);
1417 * Stale record - zap it.
1419 if (inst->config->deletestalesessions == TRUE) {
1420 uint32_t framed_addr = 0;
1425 framed_addr = inet_addr(row[5]);
1427 if (strcmp(row[7], "PPP") == 0)
1429 else if (strcmp(row[7], "SLIP") == 0)
1433 sess_time = atoi(row[8]);
1434 session_zap(request, nas_addr, nas_port,
1435 row[2], row[1], framed_addr,
1439 else if (check == 1) {
1441 * User is still logged in.
1443 ++request->simul_count;
1446 * Does it look like a MPP attempt?
1448 if (row[5] && ipno && inet_addr(row[5]) == ipno)
1449 request->simul_mpp = 2;
1450 else if (row[6] && call_num &&
1451 !strncmp(row[6],call_num,16))
1452 request->simul_mpp = 2;
1456 * Failed to check the terminal server for
1457 * duplicate logins: return an error.
1459 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
1460 sql_release_socket(inst, sqlsocket);
1461 radlog_request(L_ERR, 0, request, "Failed to check the terminal server for user '%s'.", row[2]);
1462 return RLM_MODULE_FAIL;
1466 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
1467 sql_release_socket(inst, sqlsocket);
1470 * The Auth module apparently looks at request->simul_count,
1471 * not the return value of this module when deciding to deny
1472 * a call for too many sessions.
1474 return RLM_MODULE_OK;
1478 * Execute postauth_query after authentication
1480 static int rlm_sql_postauth(void *instance, REQUEST *request) {
1481 SQLSOCK *sqlsocket = NULL;
1482 SQL_INST *inst = instance;
1483 char querystr[MAX_QUERY_LEN];
1484 char sqlusername[MAX_STRING_LEN];
1486 if(sql_set_user(inst, request, sqlusername, NULL) < 0)
1487 return RLM_MODULE_FAIL;
1489 /* If postauth_query is not defined, we stop here */
1490 if (!inst->config->postauth_query ||
1491 (inst->config->postauth_query[0] == '\0'))
1492 return RLM_MODULE_NOOP;
1494 /* Expand variables in the query */
1495 memset(querystr, 0, MAX_QUERY_LEN);
1496 radius_xlat(querystr, sizeof(querystr), inst->config->postauth_query,
1497 request, sql_escape_func);
1498 query_log(request, inst, querystr);
1499 DEBUG2("rlm_sql (%s) in sql_postauth: query is %s",
1500 inst->config->xlat_name, querystr);
1502 /* Initialize the sql socket */
1503 sqlsocket = sql_get_socket(inst);
1504 if (sqlsocket == NULL)
1505 return RLM_MODULE_FAIL;
1507 /* Process the query */
1508 if (rlm_sql_query(sqlsocket, inst, querystr)) {
1509 radlog(L_ERR, "rlm_sql (%s) in sql_postauth: Database query error - %s",
1510 inst->config->xlat_name,
1511 (inst->module->sql_error)(sqlsocket, inst->config));
1512 sql_release_socket(inst, sqlsocket);
1513 return RLM_MODULE_FAIL;
1515 (inst->module->sql_finish_query)(sqlsocket, inst->config);
1517 sql_release_socket(inst, sqlsocket);
1518 return RLM_MODULE_OK;
1521 /* globally exported name */
1522 module_t rlm_sql = {
1525 RLM_TYPE_THREAD_SAFE, /* type: reserved */
1526 rlm_sql_instantiate, /* instantiation */
1527 rlm_sql_detach, /* detach */
1529 NULL, /* authentication */
1530 rlm_sql_authorize, /* authorization */
1531 NULL, /* preaccounting */
1532 rlm_sql_accounting, /* accounting */
1533 rlm_sql_checksimul, /* checksimul */
1534 NULL, /* pre-proxy */
1535 NULL, /* post-proxy */
1536 rlm_sql_postauth /* post-auth */