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>
38 static char *allowed_chars = NULL;
40 static const CONF_PARSER module_config[] = {
41 {"driver",PW_TYPE_STRING_PTR,
42 offsetof(SQL_CONFIG,sql_driver), NULL, "mysql"},
43 {"server",PW_TYPE_STRING_PTR,
44 offsetof(SQL_CONFIG,sql_server), NULL, "localhost"},
45 {"port",PW_TYPE_STRING_PTR,
46 offsetof(SQL_CONFIG,sql_port), NULL, ""},
47 {"login", PW_TYPE_STRING_PTR,
48 offsetof(SQL_CONFIG,sql_login), NULL, ""},
49 {"password", PW_TYPE_STRING_PTR,
50 offsetof(SQL_CONFIG,sql_password), NULL, ""},
51 {"radius_db", PW_TYPE_STRING_PTR,
52 offsetof(SQL_CONFIG,sql_db), NULL, "radius"},
53 {"read_groups", PW_TYPE_BOOLEAN,
54 offsetof(SQL_CONFIG,read_groups), NULL, "yes"},
55 {"sqltrace", PW_TYPE_BOOLEAN,
56 offsetof(SQL_CONFIG,sqltrace), NULL, "no"},
57 {"sqltracefile", PW_TYPE_STRING_PTR,
58 offsetof(SQL_CONFIG,tracefile), NULL, SQLTRACEFILE},
59 {"readclients", PW_TYPE_BOOLEAN,
60 offsetof(SQL_CONFIG,do_clients), NULL, "no"},
61 {"deletestalesessions", PW_TYPE_BOOLEAN,
62 offsetof(SQL_CONFIG,deletestalesessions), NULL, "yes"},
63 {"num_sql_socks", PW_TYPE_INTEGER,
64 offsetof(SQL_CONFIG,num_sql_socks), NULL, "5"},
65 {"lifetime", PW_TYPE_INTEGER,
66 offsetof(SQL_CONFIG,lifetime), NULL, "0"},
67 {"sql_user_name", PW_TYPE_STRING_PTR,
68 offsetof(SQL_CONFIG,query_user), NULL, ""},
69 {"default_user_profile", PW_TYPE_STRING_PTR,
70 offsetof(SQL_CONFIG,default_profile), NULL, ""},
71 {"nas_query", PW_TYPE_STRING_PTR,
72 offsetof(SQL_CONFIG,nas_query), NULL, "SELECT id,nasname,shortname,type,secret FROM nas"},
73 {"authorize_check_query", PW_TYPE_STRING_PTR,
74 offsetof(SQL_CONFIG,authorize_check_query), NULL, ""},
75 {"authorize_reply_query", PW_TYPE_STRING_PTR,
76 offsetof(SQL_CONFIG,authorize_reply_query), NULL, NULL},
77 {"authorize_group_check_query", PW_TYPE_STRING_PTR,
78 offsetof(SQL_CONFIG,authorize_group_check_query), NULL, ""},
79 {"authorize_group_reply_query", PW_TYPE_STRING_PTR,
80 offsetof(SQL_CONFIG,authorize_group_reply_query), NULL, ""},
81 {"accounting_onoff_query", PW_TYPE_STRING_PTR,
82 offsetof(SQL_CONFIG,accounting_onoff_query), NULL, ""},
83 {"accounting_update_query", PW_TYPE_STRING_PTR,
84 offsetof(SQL_CONFIG,accounting_update_query), NULL, ""},
85 {"accounting_update_query_alt", PW_TYPE_STRING_PTR,
86 offsetof(SQL_CONFIG,accounting_update_query_alt), NULL, ""},
87 {"accounting_start_query", PW_TYPE_STRING_PTR,
88 offsetof(SQL_CONFIG,accounting_start_query), NULL, ""},
89 {"accounting_start_query_alt", PW_TYPE_STRING_PTR,
90 offsetof(SQL_CONFIG,accounting_start_query_alt), NULL, ""},
91 {"accounting_stop_query", PW_TYPE_STRING_PTR,
92 offsetof(SQL_CONFIG,accounting_stop_query), NULL, ""},
93 {"accounting_stop_query_alt", PW_TYPE_STRING_PTR,
94 offsetof(SQL_CONFIG,accounting_stop_query_alt), NULL, ""},
95 {"group_membership_query", PW_TYPE_STRING_PTR,
96 offsetof(SQL_CONFIG,groupmemb_query), NULL, NULL},
97 {"connect_failure_retry_delay", PW_TYPE_INTEGER,
98 offsetof(SQL_CONFIG,connect_failure_retry_delay), NULL, "60"},
99 {"simul_count_query", PW_TYPE_STRING_PTR,
100 offsetof(SQL_CONFIG,simul_count_query), NULL, ""},
101 {"simul_verify_query", PW_TYPE_STRING_PTR,
102 offsetof(SQL_CONFIG,simul_verify_query), NULL, ""},
103 {"postauth_query", PW_TYPE_STRING_PTR,
104 offsetof(SQL_CONFIG,postauth_query), NULL, ""},
105 {"safe-characters", PW_TYPE_STRING_PTR,
106 offsetof(SQL_CONFIG,allowed_chars), NULL,
107 "@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_: /"},
109 {NULL, -1, 0, NULL, NULL}
113 * Fall-Through checking function from rlm_files.c
115 static int fallthrough(VALUE_PAIR *vp)
118 tmp = pairfind(vp, PW_FALL_THROUGH);
120 return tmp ? tmp->vp_integer : 0;
128 static int generate_sql_clients(SQL_INST *inst);
129 static size_t sql_escape_func(char *out, size_t outlen, const char *in);
132 * sql xlat function. Right now only SELECTs are supported. Only
133 * the first element of the SELECT result will be used.
135 static int sql_xlat(void *instance, REQUEST *request,
136 char *fmt, char *out, size_t freespace,
137 UNUSED RADIUS_ESCAPE_STRING func)
141 SQL_INST *inst = instance;
142 char querystr[MAX_QUERY_LEN];
143 char sqlusername[MAX_STRING_LEN];
149 * Add SQL-User-Name attribute just in case it is needed
150 * We could search the string fmt for SQL-User-Name to see if this is
153 sql_set_user(inst, request, sqlusername, NULL);
155 * Do an xlat on the provided string (nice recursive operation).
157 if (!radius_xlat(querystr, sizeof(querystr), fmt, request, sql_escape_func)) {
158 radlog(L_ERR, "rlm_sql (%s): xlat failed.",
159 inst->config->xlat_name);
163 query_log(request, inst,querystr);
164 sqlsocket = sql_get_socket(inst);
165 if (sqlsocket == NULL)
167 if (rlm_sql_select_query(sqlsocket,inst,querystr)){
168 radlog(L_ERR, "rlm_sql (%s): database query error, %s: %s",
169 inst->config->xlat_name,querystr,
170 (inst->module->sql_error)(sqlsocket, inst->config));
171 sql_release_socket(inst,sqlsocket);
175 ret = rlm_sql_fetch_row(sqlsocket, inst);
178 RDEBUG("SQL query did not succeed");
179 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
180 sql_release_socket(inst,sqlsocket);
184 row = sqlsocket->row;
186 RDEBUG("SQL query did not return any results");
187 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
188 sql_release_socket(inst,sqlsocket);
193 RDEBUG("row[0] returned NULL");
194 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
195 sql_release_socket(inst,sqlsocket);
198 ret = strlen(row[0]);
199 if (ret >= freespace){
200 RDEBUG("Insufficient string space");
201 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
202 sql_release_socket(inst,sqlsocket);
206 strlcpy(out,row[0],freespace);
208 RDEBUG("sql_xlat finished");
210 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
211 sql_release_socket(inst,sqlsocket);
215 static int generate_sql_clients(SQL_INST *inst)
219 char querystr[MAX_QUERY_LEN];
221 char *prefix_ptr = NULL;
225 DEBUG("rlm_sql (%s): Processing generate_sql_clients",
226 inst->config->xlat_name);
228 /* NAS query isn't xlat'ed */
229 strlcpy(querystr, inst->config->nas_query, sizeof(querystr));
230 DEBUG("rlm_sql (%s) in generate_sql_clients: query is %s",
231 inst->config->xlat_name, querystr);
233 sqlsocket = sql_get_socket(inst);
234 if (sqlsocket == NULL)
236 if (rlm_sql_select_query(sqlsocket,inst,querystr)){
237 radlog(L_ERR, "rlm_sql (%s): database query error, %s: %s",
238 inst->config->xlat_name,querystr,
239 (inst->module->sql_error)(sqlsocket, inst->config));
240 sql_release_socket(inst,sqlsocket);
244 while(rlm_sql_fetch_row(sqlsocket, inst) == 0) {
246 row = sqlsocket->row;
250 * The return data for each row MUST be in the following order:
252 * 0. Row ID (currently unused)
253 * 1. Name (or IP address)
257 * 5. Virtual Server (optional)
260 radlog(L_ERR, "rlm_sql (%s): No row id found on pass %d",inst->config->xlat_name,i);
264 radlog(L_ERR, "rlm_sql (%s): No nasname found for row %s",inst->config->xlat_name,row[0]);
268 radlog(L_ERR, "rlm_sql (%s): No short name found for row %s",inst->config->xlat_name,row[0]);
272 radlog(L_ERR, "rlm_sql (%s): No secret found for row %s",inst->config->xlat_name,row[0]);
276 DEBUG("rlm_sql (%s): Read entry nasname=%s,shortname=%s,secret=%s",inst->config->xlat_name,
277 row[1],row[2],row[4]);
279 c = rad_malloc(sizeof(*c));
280 memset(c, 0, sizeof(*c));
282 #ifdef WITH_DYNAMIC_CLIENTS
290 prefix_ptr = strchr(row[1], '/');
292 c->prefix = atoi(prefix_ptr + 1);
293 if ((c->prefix < 0) || (c->prefix > 128)) {
294 radlog(L_ERR, "rlm_sql (%s): Invalid Prefix value '%s' for IP.",
295 inst->config->xlat_name, prefix_ptr + 1);
299 /* Replace '/' with '\0' */
304 * Always get the numeric representation of IP
306 if (ip_hton(row[1], AF_UNSPEC, &c->ipaddr) < 0) {
307 radlog(L_CONS|L_ERR, "rlm_sql (%s): Failed to look up hostname %s: %s",
308 inst->config->xlat_name,
309 row[1], fr_strerror());
314 ip_ntoh(&c->ipaddr, buffer, sizeof(buffer));
315 c->longname = strdup(buffer);
318 if (c->prefix < 0) switch (c->ipaddr.af) {
330 * Other values (secret, shortname, nastype, virtual_server)
332 c->secret = strdup(row[4]);
333 c->shortname = strdup(row[2]);
335 c->nastype = strdup(row[3]);
337 numf = (inst->module->sql_num_fields)(sqlsocket, inst->config);
338 if ((numf > 5) && (row[5] != NULL)) c->server = strdup(row[5]);
340 DEBUG("rlm_sql (%s): Adding client %s (%s, server=%s) to clients list",
341 inst->config->xlat_name,
342 c->longname,c->shortname, c->server ? c->server : "<none>");
343 if (!client_add(NULL, c)) {
344 DEBUG("rlm_sql (%s): Failed to add client %s (%s) to clients list. Maybe there's a duplicate?",
345 inst->config->xlat_name,
346 c->longname,c->shortname);
351 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
352 sql_release_socket(inst, sqlsocket);
359 * Translate the SQL queries.
361 static size_t sql_escape_func(char *out, size_t outlen, const char *in)
367 * Non-printable characters get replaced with their
368 * mime-encoded equivalents.
371 strchr(allowed_chars, *in) == NULL) {
373 * Only 3 or less bytes available.
379 snprintf(out, outlen, "=%02X", (unsigned char) in[0]);
388 * Only one byte left.
408 * Set the SQL user name.
410 * We don't call the escape function here. The resulting string
411 * will be escaped later in the queries xlat so we don't need to
412 * escape it twice. (it will make things wrong if we have an
413 * escape candidate character in the username)
415 int sql_set_user(SQL_INST *inst, REQUEST *request, char *sqlusername, const char *username)
418 char tmpuser[MAX_STRING_LEN];
421 sqlusername[0]= '\0';
423 /* Remove any user attr we added previously */
424 pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
426 if (username != NULL) {
427 strlcpy(tmpuser, username, sizeof(tmpuser));
428 } else if (strlen(inst->config->query_user)) {
429 radius_xlat(tmpuser, sizeof(tmpuser), inst->config->query_user, request, NULL);
434 strlcpy(sqlusername, tmpuser, MAX_STRING_LEN);
435 RDEBUG2("sql_set_user escaped user --> '%s'", sqlusername);
436 vp = radius_pairmake(request, &request->packet->vps,
437 "SQL-User-Name", NULL, 0);
439 radlog(L_ERR, "%s", fr_strerror());
443 strlcpy(vp->vp_strvalue, tmpuser, sizeof(vp->vp_strvalue));
444 vp->length = strlen(vp->vp_strvalue);
451 static void sql_grouplist_free (SQL_GROUPLIST **group_list)
457 *group_list = (*group_list)->next;
463 static int sql_get_grouplist (SQL_INST *inst, SQLSOCK *sqlsocket, REQUEST *request, SQL_GROUPLIST **group_list)
465 char querystr[MAX_QUERY_LEN];
468 SQL_GROUPLIST *group_list_tmp;
470 /* NOTE: sql_set_user should have been run before calling this function */
472 group_list_tmp = *group_list = NULL;
474 if (!inst->config->groupmemb_query ||
475 (inst->config->groupmemb_query[0] == 0))
478 if (!radius_xlat(querystr, sizeof(querystr), inst->config->groupmemb_query, request, sql_escape_func)) {
479 radlog_request(L_ERR, 0, request, "xlat \"%s\" failed.",
480 inst->config->groupmemb_query);
484 if (rlm_sql_select_query(sqlsocket, inst, querystr) < 0) {
485 radlog_request(L_ERR, 0, request,
486 "database query error, %s: %s",
488 (inst->module->sql_error)(sqlsocket,inst->config));
491 while (rlm_sql_fetch_row(sqlsocket, inst) == 0) {
492 row = sqlsocket->row;
496 RDEBUG("row[0] returned NULL");
497 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
498 sql_grouplist_free(group_list);
501 if (*group_list == NULL) {
502 *group_list = rad_malloc(sizeof(SQL_GROUPLIST));
503 group_list_tmp = *group_list;
505 group_list_tmp->next = rad_malloc(sizeof(SQL_GROUPLIST));
506 group_list_tmp = group_list_tmp->next;
508 group_list_tmp->next = NULL;
509 strlcpy(group_list_tmp->groupname, row[0], MAX_STRING_LEN);
512 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
519 * sql groupcmp function. That way we can do group comparisons (in the users file for example)
520 * with the group memberships reciding in sql
521 * The group membership query should only return one element which is the username. The returned
522 * username will then be checked with the passed check string.
525 static int sql_groupcmp(void *instance, REQUEST *request, VALUE_PAIR *request_vp, VALUE_PAIR *check,
526 VALUE_PAIR *check_pairs, VALUE_PAIR **reply_pairs)
529 SQL_INST *inst = instance;
530 char sqlusername[MAX_STRING_LEN];
531 SQL_GROUPLIST *group_list, *group_list_tmp;
533 check_pairs = check_pairs;
534 reply_pairs = reply_pairs;
535 request_vp = request_vp;
537 RDEBUG("sql_groupcmp");
538 if (!check || !check->vp_strvalue || !check->length){
539 RDEBUG("sql_groupcmp: Illegal group name");
543 RDEBUG("sql_groupcmp: NULL request");
547 * Set, escape, and check the user attr here
549 if (sql_set_user(inst, request, sqlusername, NULL) < 0)
553 * Get a socket for this lookup
555 sqlsocket = sql_get_socket(inst);
556 if (sqlsocket == NULL) {
557 /* Remove the username we (maybe) added above */
558 pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
563 * Get the list of groups this user is a member of
565 if (sql_get_grouplist(inst, sqlsocket, request, &group_list) < 0) {
566 radlog_request(L_ERR, 0, request,
567 "Error getting group membership");
568 /* Remove the username we (maybe) added above */
569 pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
570 sql_release_socket(inst, sqlsocket);
574 for (group_list_tmp = group_list; group_list_tmp != NULL; group_list_tmp = group_list_tmp->next) {
575 if (strcmp(group_list_tmp->groupname, check->vp_strvalue) == 0){
576 RDEBUG("sql_groupcmp finished: User is a member of group %s",
578 /* Free the grouplist */
579 sql_grouplist_free(&group_list);
580 /* Remove the username we (maybe) added above */
581 pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
582 sql_release_socket(inst, sqlsocket);
587 /* Free the grouplist */
588 sql_grouplist_free(&group_list);
589 /* Remove the username we (maybe) added above */
590 pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
591 sql_release_socket(inst,sqlsocket);
593 RDEBUG("sql_groupcmp finished: User is NOT a member of group %s",
601 static int rlm_sql_process_groups(SQL_INST *inst, REQUEST *request, SQLSOCK *sqlsocket, int *dofallthrough)
603 VALUE_PAIR *check_tmp = NULL;
604 VALUE_PAIR *reply_tmp = NULL;
605 SQL_GROUPLIST *group_list, *group_list_tmp;
606 VALUE_PAIR *sql_group = NULL;
607 char querystr[MAX_QUERY_LEN];
612 * Get the list of groups this user is a member of
614 if (sql_get_grouplist(inst, sqlsocket, request, &group_list) < 0) {
615 radlog_request(L_ERR, 0, request, "Error retrieving group list");
619 for (group_list_tmp = group_list; group_list_tmp != NULL && *dofallthrough != 0; group_list_tmp = group_list_tmp->next) {
621 * Add the Sql-Group attribute to the request list so we know
622 * which group we're retrieving attributes for
624 sql_group = pairmake("Sql-Group", group_list_tmp->groupname, T_OP_EQ);
626 radlog_request(L_ERR, 0, request,
627 "Error creating Sql-Group attribute");
630 pairadd(&request->packet->vps, sql_group);
631 if (!radius_xlat(querystr, sizeof(querystr), inst->config->authorize_group_check_query, request, sql_escape_func)) {
632 radlog_request(L_ERR, 0, request,
633 "Error generating query; rejecting user");
634 /* Remove the grouup we added above */
635 pairdelete(&request->packet->vps, PW_SQL_GROUP);
638 rows = sql_getvpdata(inst, sqlsocket, &check_tmp, querystr);
640 radlog_request(L_ERR, 0, request, "Error retrieving check pairs for group %s",
641 group_list_tmp->groupname);
642 /* Remove the grouup we added above */
643 pairdelete(&request->packet->vps, PW_SQL_GROUP);
644 pairfree(&check_tmp);
646 } else if (rows > 0) {
648 * Only do this if *some* check pairs were returned
650 if (paircompare(request, request->packet->vps, check_tmp, &request->reply->vps) == 0) {
652 RDEBUG2("User found in group %s",
653 group_list_tmp->groupname);
655 * Now get the reply pairs since the paircompare matched
657 if (!radius_xlat(querystr, sizeof(querystr), inst->config->authorize_group_reply_query, request, sql_escape_func)) {
658 radlog_request(L_ERR, 0, request, "Error generating query; rejecting user");
659 /* Remove the grouup we added above */
660 pairdelete(&request->packet->vps, PW_SQL_GROUP);
661 pairfree(&check_tmp);
664 if (sql_getvpdata(inst, sqlsocket, &reply_tmp, querystr) < 0) {
665 radlog_request(L_ERR, 0, request, "Error retrieving reply pairs for group %s",
666 group_list_tmp->groupname);
667 /* Remove the grouup we added above */
668 pairdelete(&request->packet->vps, PW_SQL_GROUP);
669 pairfree(&check_tmp);
670 pairfree(&reply_tmp);
673 *dofallthrough = fallthrough(reply_tmp);
674 pairxlatmove(request, &request->reply->vps, &reply_tmp);
675 pairxlatmove(request, &request->config_items, &check_tmp);
679 * rows == 0. This is like having the username on a line
680 * in the user's file with no check vp's. As such, we treat
681 * it as found and add the reply attributes, so that we
682 * match expected behavior
685 RDEBUG2("User found in group %s",
686 group_list_tmp->groupname);
688 * Now get the reply pairs since the paircompare matched
690 if (!radius_xlat(querystr, sizeof(querystr), inst->config->authorize_group_reply_query, request, sql_escape_func)) {
691 radlog_request(L_ERR, 0, request, "Error generating query; rejecting user");
692 /* Remove the grouup we added above */
693 pairdelete(&request->packet->vps, PW_SQL_GROUP);
694 pairfree(&check_tmp);
697 if (sql_getvpdata(inst, sqlsocket, &reply_tmp, querystr) < 0) {
698 radlog_request(L_ERR, 0, request, "Error retrieving reply pairs for group %s",
699 group_list_tmp->groupname);
700 /* Remove the grouup we added above */
701 pairdelete(&request->packet->vps, PW_SQL_GROUP);
702 pairfree(&check_tmp);
703 pairfree(&reply_tmp);
706 *dofallthrough = fallthrough(reply_tmp);
707 pairxlatmove(request, &request->reply->vps, &reply_tmp);
708 pairxlatmove(request, &request->config_items, &check_tmp);
712 * Delete the Sql-Group we added above
713 * And clear out the pairlists
715 pairdelete(&request->packet->vps, PW_SQL_GROUP);
716 pairfree(&check_tmp);
717 pairfree(&reply_tmp);
720 sql_grouplist_free(&group_list);
725 static int rlm_sql_detach(void *instance)
727 SQL_INST *inst = instance;
729 paircompare_unregister(PW_SQL_GROUP, sql_groupcmp);
738 if (inst->config->xlat_name) {
739 xlat_unregister(inst->config->xlat_name,(RAD_XLAT_FUNC)sql_xlat);
740 free(inst->config->xlat_name);
744 * Free up dynamically allocated string pointers.
746 for (i = 0; module_config[i].name != NULL; i++) {
748 if (module_config[i].type != PW_TYPE_STRING_PTR) {
753 * Treat 'config' as an opaque array of bytes,
754 * and take the offset into it. There's a
755 * (char*) pointer at that offset, and we want
758 p = (char **) (((char *)inst->config) + module_config[i].offset);
759 if (!*p) { /* nothing allocated */
765 allowed_chars = NULL;
773 * FIXME: Call the modules 'destroy' function?
775 lt_dlclose(inst->handle); /* ignore any errors */
782 static int rlm_sql_instantiate(CONF_SECTION * conf, void **instance)
785 const char *xlat_name;
787 inst = rad_malloc(sizeof(SQL_INST));
788 memset(inst, 0, sizeof(SQL_INST));
790 inst->config = rad_malloc(sizeof(SQL_CONFIG));
791 memset(inst->config, 0, sizeof(SQL_CONFIG));
794 * Export these methods, too. This avoids RTDL_GLOBAL.
796 inst->sql_set_user = sql_set_user;
797 inst->sql_get_socket = sql_get_socket;
798 inst->sql_release_socket = sql_release_socket;
799 inst->sql_escape_func = sql_escape_func;
802 * If the configuration parameters can't be parsed, then
805 if (cf_section_parse(conf, inst->config, module_config) < 0) {
806 rlm_sql_detach(inst);
810 xlat_name = cf_section_name2(conf);
811 if (xlat_name == NULL)
812 xlat_name = cf_section_name1(conf);
814 inst->config->xlat_name = strdup(xlat_name);
815 xlat_register(xlat_name, (RAD_XLAT_FUNC)sql_xlat, inst);
818 if (inst->config->num_sql_socks > MAX_SQL_SOCKS) {
819 radlog(L_ERR, "rlm_sql (%s): sql_instantiate: number of sqlsockets cannot exceed MAX_SQL_SOCKS, %d",
820 inst->config->xlat_name, MAX_SQL_SOCKS);
821 rlm_sql_detach(inst);
826 * Sanity check for crazy people.
828 if (strncmp(inst->config->sql_driver, "rlm_sql_", 8) != 0) {
829 radlog(L_ERR, "\"%s\" is NOT an SQL driver!",
830 inst->config->sql_driver);
831 rlm_sql_detach(inst);
835 inst->handle = lt_dlopenext(inst->config->sql_driver);
836 if (inst->handle == NULL) {
837 radlog(L_ERR, "Could not link driver %s: %s",
838 inst->config->sql_driver,
840 radlog(L_ERR, "Make sure it (and all its dependent libraries!) are in the search path of your system's ld.");
841 rlm_sql_detach(inst);
845 inst->module = (rlm_sql_module_t *) lt_dlsym(inst->handle, inst->config->sql_driver);
847 radlog(L_ERR, "Could not link symbol %s: %s",
848 inst->config->sql_driver,
850 rlm_sql_detach(inst);
854 radlog(L_INFO, "rlm_sql (%s): Driver %s (module %s) loaded and linked",
855 inst->config->xlat_name, inst->config->sql_driver,
857 radlog(L_INFO, "rlm_sql (%s): Attempting to connect to %s@%s:%s/%s",
858 inst->config->xlat_name, inst->config->sql_login,
859 inst->config->sql_server, inst->config->sql_port,
860 inst->config->sql_db);
862 if (sql_init_socketpool(inst) < 0) {
863 rlm_sql_detach(inst);
867 paircompare_register(PW_SQL_GROUP, PW_USER_NAME, sql_groupcmp, inst);
869 if (inst->config->do_clients){
870 if (generate_sql_clients(inst) == -1){
871 radlog(L_ERR, "Failed to load clients from SQL.");
872 rlm_sql_detach(inst);
876 allowed_chars = inst->config->allowed_chars;
880 return RLM_MODULE_OK;
884 static int rlm_sql_authorize(void *instance, REQUEST * request)
886 VALUE_PAIR *check_tmp = NULL;
887 VALUE_PAIR *reply_tmp = NULL;
888 VALUE_PAIR *user_profile = NULL;
890 int dofallthrough = 1;
893 SQL_INST *inst = instance;
894 char querystr[MAX_QUERY_LEN];
895 char sqlusername[MAX_STRING_LEN];
897 * the profile username is used as the sqlusername during
898 * profile checking so that we don't overwrite the orignal
901 char profileusername[MAX_STRING_LEN];
904 * Set, escape, and check the user attr here
906 if (sql_set_user(inst, request, sqlusername, NULL) < 0)
907 return RLM_MODULE_FAIL;
913 sqlsocket = sql_get_socket(inst);
914 if (sqlsocket == NULL) {
915 /* Remove the username we (maybe) added above */
916 pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
917 return RLM_MODULE_FAIL;
922 * After this point, ALL 'return's MUST release the SQL socket!
926 * Alright, start by getting the specific entry for the user
928 if (!radius_xlat(querystr, sizeof(querystr), inst->config->authorize_check_query, request, sql_escape_func)) {
929 radlog_request(L_ERR, 0, request, "Error generating query; rejecting user");
930 sql_release_socket(inst, sqlsocket);
931 /* Remove the username we (maybe) added above */
932 pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
933 return RLM_MODULE_FAIL;
935 rows = sql_getvpdata(inst, sqlsocket, &check_tmp, querystr);
937 radlog_request(L_ERR, 0, request, "SQL query error; rejecting user");
938 sql_release_socket(inst, sqlsocket);
939 /* Remove the username we (maybe) added above */
940 pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
941 pairfree(&check_tmp);
942 return RLM_MODULE_FAIL;
943 } else if (rows > 0) {
945 * Only do this if *some* check pairs were returned
947 if (paircompare(request, request->packet->vps, check_tmp, &request->reply->vps) == 0) {
949 RDEBUG2("User found in radcheck table");
951 if (inst->config->authorize_reply_query &&
952 *inst->config->authorize_reply_query) {
955 * Now get the reply pairs since the paircompare matched
957 if (!radius_xlat(querystr, sizeof(querystr), inst->config->authorize_reply_query, request, sql_escape_func)) {
958 radlog_request(L_ERR, 0, request, "Error generating query; rejecting user");
959 sql_release_socket(inst, sqlsocket);
960 /* Remove the username we (maybe) added above */
961 pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
962 pairfree(&check_tmp);
963 return RLM_MODULE_FAIL;
965 if (sql_getvpdata(inst, sqlsocket, &reply_tmp, querystr) < 0) {
966 radlog_request(L_ERR, 0, request, "SQL query error; rejecting user");
967 sql_release_socket(inst, sqlsocket);
968 /* Remove the username we (maybe) added above */
969 pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
970 pairfree(&check_tmp);
971 pairfree(&reply_tmp);
972 return RLM_MODULE_FAIL;
975 if (!inst->config->read_groups)
976 dofallthrough = fallthrough(reply_tmp);
977 pairxlatmove(request, &request->reply->vps, &reply_tmp);
979 pairxlatmove(request, &request->config_items, &check_tmp);
984 * Clear out the pairlists
986 pairfree(&check_tmp);
987 pairfree(&reply_tmp);
990 * dofallthrough is set to 1 by default so that if the user information
991 * is not found, we will still process groups. If the user information,
992 * however, *is* found, Fall-Through must be set in order to process
996 rows = rlm_sql_process_groups(inst, request, sqlsocket, &dofallthrough);
998 radlog_request(L_ERR, 0, request, "Error processing groups; rejecting user");
999 sql_release_socket(inst, sqlsocket);
1000 /* Remove the username we (maybe) added above */
1001 pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
1002 return RLM_MODULE_FAIL;
1003 } else if (rows > 0) {
1009 * repeat the above process with the default profile or User-Profile
1011 if (dofallthrough) {
1012 int profile_found = 0;
1014 * Check for a default_profile or for a User-Profile.
1016 user_profile = pairfind(request->config_items, PW_USER_PROFILE);
1017 if (inst->config->default_profile[0] != 0 || user_profile != NULL){
1018 char *profile = inst->config->default_profile;
1020 if (user_profile != NULL)
1021 profile = user_profile->vp_strvalue;
1022 if (profile && strlen(profile)){
1023 RDEBUG("Checking profile %s", profile);
1024 if (sql_set_user(inst, request, profileusername, profile) < 0) {
1025 radlog_request(L_ERR, 0, request, "Error setting profile; rejecting user");
1026 sql_release_socket(inst, sqlsocket);
1027 /* Remove the username we (maybe) added above */
1028 pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
1029 return RLM_MODULE_FAIL;
1036 if (profile_found) {
1037 rows = rlm_sql_process_groups(inst, request, sqlsocket, &dofallthrough);
1039 radlog_request(L_ERR, 0, request, "Error processing profile groups; rejecting user");
1040 sql_release_socket(inst, sqlsocket);
1041 /* Remove the username we (maybe) added above */
1042 pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
1043 return RLM_MODULE_FAIL;
1044 } else if (rows > 0) {
1050 /* Remove the username we (maybe) added above */
1051 pairdelete(&request->packet->vps, PW_SQL_USER_NAME);
1052 sql_release_socket(inst, sqlsocket);
1055 RDEBUG("User %s not found", sqlusername);
1056 return RLM_MODULE_NOTFOUND;
1058 return RLM_MODULE_OK;
1063 * Accounting: save the account data to our sql table
1065 static int rlm_sql_accounting(void *instance, REQUEST * request) {
1067 SQLSOCK *sqlsocket = NULL;
1069 SQL_INST *inst = instance;
1070 int ret = RLM_MODULE_OK;
1071 int numaffected = 0;
1072 int acctstatustype = 0;
1073 char querystr[MAX_QUERY_LEN];
1074 char logstr[MAX_QUERY_LEN];
1075 char sqlusername[MAX_STRING_LEN];
1077 #ifdef CISCO_ACCOUNTING_HACK
1078 int acctsessiontime = 0;
1081 memset(querystr, 0, MAX_QUERY_LEN);
1084 * Find the Acct Status Type
1086 if ((pair = pairfind(request->packet->vps, PW_ACCT_STATUS_TYPE)) != NULL) {
1087 acctstatustype = pair->vp_integer;
1089 radius_xlat(logstr, sizeof(logstr), "packet has no accounting status type. [user '%{User-Name}', nas '%{NAS-IP-Address}']", request, NULL);
1090 radlog_request(L_ERR, 0, request, "%s", logstr);
1091 return RLM_MODULE_INVALID;
1094 switch (acctstatustype) {
1096 * The Terminal server informed us that it was rebooted
1097 * STOP all records from this NAS
1099 case PW_STATUS_ACCOUNTING_ON:
1100 case PW_STATUS_ACCOUNTING_OFF:
1101 RDEBUG("Received Acct On/Off packet");
1102 radius_xlat(querystr, sizeof(querystr), inst->config->accounting_onoff_query, request, sql_escape_func);
1103 query_log(request, inst, querystr);
1105 sqlsocket = sql_get_socket(inst);
1106 if (sqlsocket == NULL)
1107 return(RLM_MODULE_FAIL);
1108 if (*querystr) { /* non-empty query */
1109 if (rlm_sql_query(sqlsocket, inst, querystr)) {
1110 radlog_request(L_ERR, 0, request, "Couldn't update SQL accounting for Acct On/Off packet - %s",
1111 (inst->module->sql_error)(sqlsocket, inst->config));
1112 ret = RLM_MODULE_FAIL;
1114 (inst->module->sql_finish_query)(sqlsocket, inst->config);
1120 * Got an update accounting packet
1122 case PW_STATUS_ALIVE:
1125 * Set, escape, and check the user attr here
1127 sql_set_user(inst, request, sqlusername, NULL);
1129 radius_xlat(querystr, sizeof(querystr), inst->config->accounting_update_query, request, sql_escape_func);
1130 query_log(request, inst, querystr);
1132 sqlsocket = sql_get_socket(inst);
1133 if (sqlsocket == NULL)
1134 return(RLM_MODULE_FAIL);
1135 if (*querystr) { /* non-empty query */
1136 if (rlm_sql_query(sqlsocket, inst, querystr)) {
1137 radlog_request(L_ERR, 0, request, "Couldn't update SQL accounting ALIVE record - %s",
1138 (inst->module->sql_error)(sqlsocket, inst->config));
1139 ret = RLM_MODULE_FAIL;
1142 numaffected = (inst->module->sql_affected_rows)(sqlsocket, inst->config);
1143 if (numaffected < 1) {
1146 * If our update above didn't match anything
1147 * we assume it's because we haven't seen a
1148 * matching Start record. So we have to
1149 * insert this update rather than do an update
1151 radius_xlat(querystr, sizeof(querystr), inst->config->accounting_update_query_alt, request, sql_escape_func);
1152 query_log(request, inst, querystr);
1153 if (*querystr) { /* non-empty query */
1154 if (rlm_sql_query(sqlsocket, inst, querystr)) {
1155 radlog_request(L_ERR, 0, request, "Couldn't insert SQL accounting ALIVE record - %s",
1156 (inst->module->sql_error)(sqlsocket, inst->config));
1157 ret = RLM_MODULE_FAIL;
1159 (inst->module->sql_finish_query)(sqlsocket, inst->config);
1163 (inst->module->sql_finish_query)(sqlsocket, inst->config);
1168 * Got accounting start packet
1170 case PW_STATUS_START:
1173 * Set, escape, and check the user attr here
1175 sql_set_user(inst, request, sqlusername, NULL);
1177 radius_xlat(querystr, sizeof(querystr), inst->config->accounting_start_query, request, sql_escape_func);
1178 query_log(request, inst, querystr);
1180 sqlsocket = sql_get_socket(inst);
1181 if (sqlsocket == NULL)
1182 return(RLM_MODULE_FAIL);
1183 if (*querystr) { /* non-empty query */
1184 if (rlm_sql_query(sqlsocket, inst, querystr)) {
1185 radlog_request(L_ERR, 0, request, "Couldn't insert SQL accounting START record - %s",
1186 (inst->module->sql_error)(sqlsocket, inst->config));
1189 * We failed the insert above. It's probably because
1190 * the stop record came before the start. We try
1191 * our alternate query now (typically an UPDATE)
1193 radius_xlat(querystr, sizeof(querystr), inst->config->accounting_start_query_alt, request, sql_escape_func);
1194 query_log(request, inst, querystr);
1196 if (*querystr) { /* non-empty query */
1197 if (rlm_sql_query(sqlsocket, inst, querystr)) {
1198 radlog_request(L_ERR, 0, request, "Couldn't update SQL accounting START record - %s",
1199 (inst->module->sql_error)(sqlsocket, inst->config));
1200 ret = RLM_MODULE_FAIL;
1202 (inst->module->sql_finish_query)(sqlsocket, inst->config);
1205 (inst->module->sql_finish_query)(sqlsocket, inst->config);
1210 * Got accounting stop packet
1212 case PW_STATUS_STOP:
1215 * Set, escape, and check the user attr here
1217 sql_set_user(inst, request, sqlusername, NULL);
1219 radius_xlat(querystr, sizeof(querystr), inst->config->accounting_stop_query, request, sql_escape_func);
1220 query_log(request, inst, querystr);
1222 sqlsocket = sql_get_socket(inst);
1223 if (sqlsocket == NULL)
1224 return(RLM_MODULE_FAIL);
1225 if (*querystr) { /* non-empty query */
1226 if (rlm_sql_query(sqlsocket, inst, querystr)) {
1227 radlog_request(L_ERR, 0, request, "Couldn't update SQL accounting STOP record - %s",
1228 (inst->module->sql_error)(sqlsocket, inst->config));
1229 ret = RLM_MODULE_FAIL;
1232 numaffected = (inst->module->sql_affected_rows)(sqlsocket, inst->config);
1233 if (numaffected < 1) {
1235 * If our update above didn't match anything
1236 * we assume it's because we haven't seen a
1237 * matching Start record. So we have to
1238 * insert this stop rather than do an update
1240 #ifdef CISCO_ACCOUNTING_HACK
1242 * If stop but zero session length AND no previous
1243 * session found, drop it as in invalid packet
1244 * This is to fix CISCO's aaa from filling our
1245 * table with bogus crap
1247 if ((pair = pairfind(request->packet->vps, PW_ACCT_SESSION_TIME)) != NULL)
1248 acctsessiontime = pair->vp_integer;
1250 if (acctsessiontime <= 0) {
1251 radius_xlat(logstr, sizeof(logstr), "stop packet with zero session length. [user '%{User-Name}', nas '%{NAS-IP-Address}']", request, NULL);
1252 radlog_request(L_ERR, 0, request, "%s", logstr);
1253 sql_release_socket(inst, sqlsocket);
1254 ret = RLM_MODULE_NOOP;
1258 radius_xlat(querystr, sizeof(querystr), inst->config->accounting_stop_query_alt, request, sql_escape_func);
1259 query_log(request, inst, querystr);
1261 if (*querystr) { /* non-empty query */
1262 if (rlm_sql_query(sqlsocket, inst, querystr)) {
1263 radlog_request(L_ERR, 0, request, "Couldn't insert SQL accounting STOP record - %s",
1265 (inst->module->sql_error)(sqlsocket, inst->config));
1266 ret = RLM_MODULE_FAIL;
1268 (inst->module->sql_finish_query)(sqlsocket, inst->config);
1272 (inst->module->sql_finish_query)(sqlsocket, inst->config);
1277 * Anything else is ignored.
1280 RDEBUG("Unsupported Acct-Status-Type = %d",
1282 return RLM_MODULE_NOOP;
1287 sql_release_socket(inst, sqlsocket);
1294 * See if a user is already logged in. Sets request->simul_count to the
1295 * current session count for this user.
1297 * Check twice. If on the first pass the user exceeds his
1298 * max. number of logins, do a second pass and validate all
1299 * logins by querying the terminal server (using eg. SNMP).
1302 static int rlm_sql_checksimul(void *instance, REQUEST * request) {
1304 SQL_INST *inst = instance;
1306 char querystr[MAX_QUERY_LEN];
1307 char sqlusername[MAX_STRING_LEN];
1310 char *call_num = NULL;
1313 uint32_t nas_addr = 0;
1316 /* If simul_count_query is not defined, we don't do any checking */
1317 if (!inst->config->simul_count_query ||
1318 (inst->config->simul_count_query[0] == 0)) {
1319 return RLM_MODULE_NOOP;
1322 if((request->username == NULL) || (request->username->length == 0)) {
1323 radlog_request(L_ERR, 0, request, "Zero Length username not permitted\n");
1324 return RLM_MODULE_INVALID;
1328 if(sql_set_user(inst, request, sqlusername, NULL) < 0)
1329 return RLM_MODULE_FAIL;
1331 radius_xlat(querystr, sizeof(querystr), inst->config->simul_count_query, request, sql_escape_func);
1333 /* initialize the sql socket */
1334 sqlsocket = sql_get_socket(inst);
1335 if(sqlsocket == NULL)
1336 return RLM_MODULE_FAIL;
1338 if(rlm_sql_select_query(sqlsocket, inst, querystr)) {
1339 radlog(L_ERR, "rlm_sql (%s) sql_checksimul: Database query failed", inst->config->xlat_name);
1340 sql_release_socket(inst, sqlsocket);
1341 return RLM_MODULE_FAIL;
1344 ret = rlm_sql_fetch_row(sqlsocket, inst);
1347 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
1348 sql_release_socket(inst, sqlsocket);
1349 return RLM_MODULE_FAIL;
1352 row = sqlsocket->row;
1354 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
1355 sql_release_socket(inst, sqlsocket);
1356 return RLM_MODULE_FAIL;
1359 request->simul_count = atoi(row[0]);
1360 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
1362 if(request->simul_count < request->simul_max) {
1363 sql_release_socket(inst, sqlsocket);
1364 return RLM_MODULE_OK;
1368 * Looks like too many sessions, so let's start verifying
1369 * them, unless told to rely on count query only.
1371 if (!inst->config->simul_verify_query ||
1372 (inst->config->simul_verify_query[0] == '\0')) {
1373 sql_release_socket(inst, sqlsocket);
1374 return RLM_MODULE_OK;
1377 radius_xlat(querystr, sizeof(querystr), inst->config->simul_verify_query, request, sql_escape_func);
1378 if(rlm_sql_select_query(sqlsocket, inst, querystr)) {
1379 radlog_request(L_ERR, 0, request, "Database query error");
1380 sql_release_socket(inst, sqlsocket);
1381 return RLM_MODULE_FAIL;
1385 * Setup some stuff, like for MPP detection.
1387 request->simul_count = 0;
1389 if ((vp = pairfind(request->packet->vps, PW_FRAMED_IP_ADDRESS)) != NULL)
1390 ipno = vp->vp_ipaddr;
1391 if ((vp = pairfind(request->packet->vps, PW_CALLING_STATION_ID)) != NULL)
1392 call_num = vp->vp_strvalue;
1395 while (rlm_sql_fetch_row(sqlsocket, inst) == 0) {
1396 row = sqlsocket->row;
1400 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
1401 sql_release_socket(inst, sqlsocket);
1402 RDEBUG("Cannot zap stale entry. No username present in entry.", inst->config->xlat_name);
1403 return RLM_MODULE_FAIL;
1406 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
1407 sql_release_socket(inst, sqlsocket);
1408 RDEBUG("Cannot zap stale entry. No session id in entry.", inst->config->xlat_name);
1409 return RLM_MODULE_FAIL;
1412 nas_addr = inet_addr(row[3]);
1414 nas_port = atoi(row[4]);
1416 check = rad_check_ts(nas_addr, nas_port, row[2], row[1]);
1420 * Stale record - zap it.
1422 if (inst->config->deletestalesessions == TRUE) {
1423 uint32_t framed_addr = 0;
1428 framed_addr = inet_addr(row[5]);
1430 if (strcmp(row[7], "PPP") == 0)
1432 else if (strcmp(row[7], "SLIP") == 0)
1436 sess_time = atoi(row[8]);
1437 session_zap(request, nas_addr, nas_port,
1438 row[2], row[1], framed_addr,
1442 else if (check == 1) {
1444 * User is still logged in.
1446 ++request->simul_count;
1449 * Does it look like a MPP attempt?
1451 if (row[5] && ipno && inet_addr(row[5]) == ipno)
1452 request->simul_mpp = 2;
1453 else if (row[6] && call_num &&
1454 !strncmp(row[6],call_num,16))
1455 request->simul_mpp = 2;
1459 * Failed to check the terminal server for
1460 * duplicate logins: return an error.
1462 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
1463 sql_release_socket(inst, sqlsocket);
1464 radlog_request(L_ERR, 0, request, "Failed to check the terminal server for user '%s'.", row[2]);
1465 return RLM_MODULE_FAIL;
1469 (inst->module->sql_finish_select_query)(sqlsocket, inst->config);
1470 sql_release_socket(inst, sqlsocket);
1473 * The Auth module apparently looks at request->simul_count,
1474 * not the return value of this module when deciding to deny
1475 * a call for too many sessions.
1477 return RLM_MODULE_OK;
1481 * Execute postauth_query after authentication
1483 static int rlm_sql_postauth(void *instance, REQUEST *request) {
1484 SQLSOCK *sqlsocket = NULL;
1485 SQL_INST *inst = instance;
1486 char querystr[MAX_QUERY_LEN];
1487 char sqlusername[MAX_STRING_LEN];
1489 if(sql_set_user(inst, request, sqlusername, NULL) < 0)
1490 return RLM_MODULE_FAIL;
1492 /* If postauth_query is not defined, we stop here */
1493 if (!inst->config->postauth_query ||
1494 (inst->config->postauth_query[0] == '\0'))
1495 return RLM_MODULE_NOOP;
1497 /* Expand variables in the query */
1498 memset(querystr, 0, MAX_QUERY_LEN);
1499 radius_xlat(querystr, sizeof(querystr), inst->config->postauth_query,
1500 request, sql_escape_func);
1501 query_log(request, inst, querystr);
1502 DEBUG2("rlm_sql (%s) in sql_postauth: query is %s",
1503 inst->config->xlat_name, querystr);
1505 /* Initialize the sql socket */
1506 sqlsocket = sql_get_socket(inst);
1507 if (sqlsocket == NULL)
1508 return RLM_MODULE_FAIL;
1510 /* Process the query */
1511 if (rlm_sql_query(sqlsocket, inst, querystr)) {
1512 radlog(L_ERR, "rlm_sql (%s) in sql_postauth: Database query error - %s",
1513 inst->config->xlat_name,
1514 (inst->module->sql_error)(sqlsocket, inst->config));
1515 sql_release_socket(inst, sqlsocket);
1516 return RLM_MODULE_FAIL;
1518 (inst->module->sql_finish_query)(sqlsocket, inst->config);
1520 sql_release_socket(inst, sqlsocket);
1521 return RLM_MODULE_OK;
1524 /* globally exported name */
1525 module_t rlm_sql = {
1528 RLM_TYPE_THREAD_SAFE, /* type: reserved */
1529 rlm_sql_instantiate, /* instantiation */
1530 rlm_sql_detach, /* detach */
1532 NULL, /* authentication */
1533 rlm_sql_authorize, /* authorization */
1534 NULL, /* preaccounting */
1535 rlm_sql_accounting, /* accounting */
1536 rlm_sql_checksimul, /* checksimul */
1537 NULL, /* pre-proxy */
1538 NULL, /* post-proxy */
1539 rlm_sql_postauth /* post-auth */