this is a simple patch to rlm_sql module. it allows module to get attributes from db and send them in Accounting-Response packet. "select-query" configured via default sql.conf; parameter is accounting_reply_query. it is useful to, for example, send "vendor-specific-drop" attribute to NAS in response to Interim-Update. other accounting_*_query parameters may not be defined. configuration example: accounting_reply_query="select id, login as UserName, 'Terminate-Session' as Attribute, 'Yes' as Value, '=' as op from clients where ballance <= 0 and '%{Acct-Status-Type}' = 'Interim-Update' and login = '%{User-Name}'" creating db-view is also a good choise; query like: accounting_reply_query="select id, UserName, Attribute, Value, op from acct_reply status_type = '%{Acct-Status-Type}' and UserName = '%{User-Name}'" my patched pppd recieves "Terminate-Session" attribute. mpd can also receive "Drop-User" attr. currenty a lot of billing systems use different nas-specific scripts to drop client with negative ballance. i think this patch is pretty usefull. sorry, but it's patch to 1.1.3 version; not devel, from cvs. due to bad internet i didnt downloaded cvs version. here it is: diff -urN freeradius-1.1.3/src/modules/rlm_sql/conf.h freeradius-1.1.3-oops/src/modules/rlm_sql/conf.h --- freeradius-1.1.3/src/modules/rlm_sql/conf.h Sat May 20 12:44:37 2006 +++ freeradius-1.1.3-oops/src/modules/rlm_sql/conf.h Wed Dec 6 21:56:15 2006 @@ -29,6 +29,7 @@ char *accounting_start_query_alt; char *accounting_stop_query; char *accounting_stop_query_alt; + char *accounting_reply_query; char *simul_count_query; char *simul_verify_query; char *groupmemb_query; diff -urN freeradius-1.1.3/src/modules/rlm_sql/rlm_sql.c freeradius-1.1.3-oops/src/modules/rlm_sql/rlm_sql.c --- freeradius-1.1.3/src/modules/rlm_sql/rlm_sql.c Sat May 20 12:44:37 2006 +++ freeradius-1.1.3-oops/src/modules/rlm_sql/rlm_sql.c Wed Dec 6 22:03:35 2006 @@ -103,6 +103,8 @@ offsetof(SQL_CONFIG,accounting_stop_query), NULL, ""}, {"accounting_stop_query_alt", PW_TYPE_STRING_PTR, offsetof(SQL_CONFIG,accounting_stop_query_alt), NULL, ""}, + {"accounting_reply_query", PW_TYPE_STRING_PTR, + offsetof(SQL_CONFIG,accounting_reply_query), NULL, ""}, {"group_membership_query", PW_TYPE_STRING_PTR, offsetof(SQL_CONFIG,groupmemb_query), NULL, ""}, {"connect_failure_retry_delay", PW_TYPE_INTEGER, @@ -887,6 +889,7 @@ char querystr[MAX_QUERY_LEN]; char logstr[MAX_QUERY_LEN]; char sqlusername[MAX_STRING_LEN]; + VALUE_PAIR *sql_reply = NULL; #ifdef CISCO_ACCOUNTING_HACK int acctsessiontime = 0; @@ -1103,6 +1106,19 @@ break; } + + radius_xlat(querystr, sizeof(querystr), inst->config->accounting_reply_query, request, sql_escape_func); + query_log(request, inst, querystr); + + if (*querystr) { + if(sqlsocket == NULL && (sqlsocket = sql_get_socket(inst)) == NULL) + return(RLM_MODULE_FAIL); + + sql_getvpdata(inst, sqlsocket, &sql_reply, "SELECT 4 as id, 'dayset' as UserName, 'Terminate-Session' as Attribute, 'Yes' as Value, '=' as op", PW_VP_USERDATA); + + pairxlatmove(request, &request->reply->vps, &sql_reply); + pairfree(&sql_reply); + } sql_release_socket(inst, sqlsocket);
On Thu, 2006-12-07 at 14:59 +0200, halic wrote:
this is a simple patch to rlm_sql module. it allows module to get attributes from db and send them in Accounting-Response packet. "select-query" configured via default sql.conf; parameter is accounting_reply_query. it is useful to, for example, send "vendor-specific-drop" attribute to NAS in response to Interim-Update. other accounting_*_query parameters may not be defined.
configuration example: accounting_reply_query="select id, login as UserName, 'Terminate-Session' as Attribute, 'Yes' as Value, '=' as op from clients where ballance <= 0 and '%{Acct-Status-Type}' = 'Interim-Update' and login = '%{User-Name}'"
creating db-view is also a good choise; query like: accounting_reply_query="select id, UserName, Attribute, Value, op from acct_reply status_type = '%{Acct-Status-Type}' and UserName = '%{User-Name}'"
my patched pppd recieves "Terminate-Session" attribute. mpd can also receive "Drop-User" attr.
currenty a lot of billing systems use different nas-specific scripts to drop client with negative ballance. i think this patch is pretty usefull.
sorry, but it's patch to 1.1.3 version; not devel, from cvs. due to bad internet i didnt downloaded cvs version.
here it is:
diff -urN freeradius-1.1.3/src/modules/rlm_sql/conf.h freeradius-1.1.3-oops/src/modules/rlm_sql/conf.h --- freeradius-1.1.3/src/modules/rlm_sql/conf.h Sat May 20 12:44:37 2006 +++ freeradius-1.1.3-oops/src/modules/rlm_sql/conf.h Wed Dec 6 21:56:15 2006 @@ -29,6 +29,7 @@ char *accounting_start_query_alt; char *accounting_stop_query; char *accounting_stop_query_alt; + char *accounting_reply_query; char *simul_count_query; char *simul_verify_query; char *groupmemb_query; diff -urN freeradius-1.1.3/src/modules/rlm_sql/rlm_sql.c freeradius-1.1.3-oops/src/modules/rlm_sql/rlm_sql.c --- freeradius-1.1.3/src/modules/rlm_sql/rlm_sql.c Sat May 20 12:44:37 2006 +++ freeradius-1.1.3-oops/src/modules/rlm_sql/rlm_sql.c Wed Dec 6 22:03:35 2006 @@ -103,6 +103,8 @@ offsetof(SQL_CONFIG,accounting_stop_query), NULL, ""}, {"accounting_stop_query_alt", PW_TYPE_STRING_PTR, offsetof(SQL_CONFIG,accounting_stop_query_alt), NULL, ""}, + {"accounting_reply_query", PW_TYPE_STRING_PTR, + offsetof(SQL_CONFIG,accounting_reply_query), NULL, ""}, {"group_membership_query", PW_TYPE_STRING_PTR, offsetof(SQL_CONFIG,groupmemb_query), NULL, ""}, {"connect_failure_retry_delay", PW_TYPE_INTEGER, @@ -887,6 +889,7 @@ char querystr[MAX_QUERY_LEN]; char logstr[MAX_QUERY_LEN]; char sqlusername[MAX_STRING_LEN]; + VALUE_PAIR *sql_reply = NULL;
#ifdef CISCO_ACCOUNTING_HACK int acctsessiontime = 0; @@ -1103,6 +1106,19 @@ break;
} + + radius_xlat(querystr, sizeof(querystr), inst->config->accounting_reply_query, request, sql_escape_func); + query_log(request, inst, querystr); + + if (*querystr) { + if(sqlsocket == NULL && (sqlsocket = sql_get_socket(inst)) == NULL) + return(RLM_MODULE_FAIL); + + sql_getvpdata(inst, sqlsocket, &sql_reply, "SELECT 4 as id, 'dayset' as UserName, 'Terminate-Session' as Attribute, 'Yes' as Value, '=' as op", PW_VP_USERDATA);
I believe you left testing code in the patch. This should have said "sql_getvpdata(inst, sqlsocket, &sql_reply, querystr, PW_VP_USERDATA);" I assume.
+ + pairxlatmove(request, &request->reply->vps, &sql_reply); + pairfree(&sql_reply); + }
sql_release_socket(inst, sqlsocket);
- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html
participants (2)
-
Daniel Larsson -
halic