patch to rlm_sql
onespell at yandex.ru
onespell at yandex.ru
Thu Mar 30 11:29:34 CEST 2006
Here is patch to rlm_sql.c and rlm_sql/conf.h which adds support of
postproxy_query:
*** ./conf.h Thu Apr 29 00:55:16 2004
--- ./conf.h Thu Mar 30 10:42:29 2006
***************
*** 50,55 ****
--- 50,56 ----
int query_on_not_found;
char *sql_postauth_table;
char *postauth_query;
+ char *postproxy_query;
char *allowed_chars;
/* individual driver config */
*** ./rlm_sql.c Tue Dec 13 16:11:53 2005
--- ./rlm_sql.c Thu Mar 30 10:49:58 2006
***************
*** 131,136 ****
--- 131,138 ----
offsetof(SQL_CONFIG,sql_postauth_table), NULL, "radpostauth"},
{"postauth_query", PW_TYPE_STRING_PTR,
offsetof(SQL_CONFIG,postauth_query), NULL, ""},
+ {"postproxy_query", PW_TYPE_STRING_PTR,
+ offsetof(SQL_CONFIG,postproxy_query), NULL, ""},
{"safe-characters", PW_TYPE_STRING_PTR,
offsetof(SQL_CONFIG,allowed_chars), NULL,
"@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_: /"},
***************
*** 1347,1352 ****
--- 1349,1400 ----
return RLM_MODULE_OK;
}
+ /*
+ * Execute postproxy_query after authentication
+ */
+ static int rlm_sql_postproxy(void *instance, REQUEST *request) {
+ SQLSOCK *sqlsocket = NULL;
+ SQL_INST *inst = instance;
+ char querystr[MAX_QUERY_LEN];
+ char sqlusername[MAX_STRING_LEN];
+
+ DEBUG("rlm_sql (%s): Processing sql_postproxy", inst->config->xlat_name);
+
+ if(sql_set_user(inst, request, sqlusername, 0) <0)
+ return RLM_MODULE_FAIL;
+
+ /* If postproxy_query is not defined, we stop here */
+ if (inst->config->postproxy_query[0] == '\0')
+ return RLM_MODULE_NOOP;
+
+ /* Expand variables in the query */
+ memset(querystr, 0, MAX_QUERY_LEN);
+ radius_xlat(querystr, sizeof(querystr), inst->config->postproxy_query,
+ request, sql_escape_func);
+ query_log(request, inst, querystr);
+ DEBUG2("rlm_sql (%s) in sql_postproxy: query is %s",
+ inst->config->xlat_name, querystr);
+
+ /* Initialize the sql socket */
+ sqlsocket = sql_get_socket(inst);
+ if (sqlsocket == NULL)
+ return RLM_MODULE_FAIL;
+
+ /* Process the query */
+ if (rlm_sql_query(sqlsocket, inst, querystr)) {
+ radlog(L_ERR, "rlm_sql (%s) in sql_postproxy: Database query error - %s",
+ inst->config->xlat_name,
+ (char *)(inst->module->sql_error)(sqlsocket, inst->config));
+ sql_release_socket(inst, sqlsocket);
+ return RLM_MODULE_FAIL;
+ }
+ (inst->module->sql_finish_query)(sqlsocket, inst->config);
+
+ sql_release_socket(inst, sqlsocket);
+ return RLM_MODULE_OK;
+ }
+
+
/* globally exported name */
module_t rlm_sql = {
"SQL",
***************
*** 1360,1368 ****
rlm_sql_accounting, /* accounting */
rlm_sql_checksimul, /* checksimul */
NULL, /* pre-proxy */
! NULL, /* post-proxy */
rlm_sql_postauth /* post-auth */
},
rlm_sql_detach, /* detach */
rlm_sql_destroy, /* destroy */
};
--- 1408,1419 ----
rlm_sql_accounting, /* accounting */
rlm_sql_checksimul, /* checksimul */
NULL, /* pre-proxy */
! rlm_sql_postproxy, /* post-proxy */
rlm_sql_postauth /* post-auth */
},
rlm_sql_detach, /* detach */
rlm_sql_destroy, /* destroy */
};
+
+
+
More information about the Freeradius-Devel
mailing list