I have setup a captive portal with mysql,chilli, and freeradius. My portal allows users access base on data use (quota), I am using the rlm_sqlcounter (from freeradius 1.1.4) to measure the usage on login. The problem Im having is that if I assign a quota more than 2gb freeradius sees the bytes in a negative value for some reason, I have attached rad logs. This is the line I dont understand (rlm_sqlcounter: Rejected user will, check_item=-1149239296, counter=0). Yet in mysql its fine! Any help with this will be greatly appreciated! rad_recv: Access-Request packet from host 127.0.0.1:32772, id=0, length=195 User-Name = "will" User-Password = "pass" NAS-IP-Address = 0.0.0.0 Service-Type = Login-User Framed-IP-Address = 192.168.182.3 Calling-Station-Id = "00-16-CB-BE-3A-41" Called-Station-Id = "00-14-5E-18-83-D9" NAS-Identifier = "nas01" Acct-Session-Id = "45b7e66b00000001" NAS-Port-Type = Wireless-802.11 NAS-Port = 1 Message-Authenticator = 0x0444eede46ea26a2629277905eb408f7 WISPr-Logoff-URL = "http://192.168.182.1:3990/logoff" Processing the authorize section of radiusd.conf modcall: entering group authorize for request 0 modcall[authorize]: module "preprocess" returns ok for request 0 modcall[authorize]: module "chap" returns noop for request 0 modcall[authorize]: module "mschap" returns noop for request 0 rlm_realm: No '@' in User-Name = "will", looking up realm NULL rlm_realm: No such realm "NULL" modcall[authorize]: module "suffix" returns noop for request 0 radius_xlat: 'will' rlm_sql (sql): sql_set_user escaped user --> 'will' radius_xlat: 'SELECT id, UserName, Attribute, Value, op FROM radcheck WHERE Username = 'will' ORDER BY id' rlm_sql (sql): Reserving sql socket id: 4 radius_xlat: 'SELECT radgroupcheck.id,radgroupcheck.GroupName,radgroupcheck.Attribute,radgroupcheck.Value,radgroupcheck.op FROM radgroupcheck,usergroup WHERE usergroup.Username = 'will' AND usergroup.GroupName = radgroupcheck.GroupName ORDER BY radgroupcheck.id' radius_xlat: 'SELECT id, UserName, Attribute, Value, op FROM radreply WHERE Username = 'will' ORDER BY id' radius_xlat: 'SELECT radgroupreply.id,radgroupreply.GroupName,radgroupreply.Attribute,radgroupreply.Value,radgroupreply.op FROM radgroupreply,usergroup WHERE usergroup.Username = 'will' AND usergroup.GroupName = radgroupreply.GroupName ORDER BY radgroupreply.id' rlm_sql (sql): Released sql socket id: 4 modcall[authorize]: module "sql" returns ok for request 0 rlm_sqlcounter: Entering module authorize code rlm_sqlcounter: Could not find Check item value pair modcall[authorize]: module "noresetcounter" returns noop for request 0 rlm_sqlcounter: Entering module authorize code sqlcounter_expand: 'SELECT SUM(AcctOutputOctets) FROM radacct where UserName='%{User-Name}'' radius_xlat: 'SELECT SUM(AcctOutputOctets) FROM radacct where UserName='will'' sqlcounter_expand: '%{sql:SELECT SUM(AcctOutputOctets) FROM radacct where UserName='will'}' radius_xlat: Running registered xlat function of module sql for string 'SELECT SUM(AcctOutputOctets) FROM radacct where UserName='will'' rlm_sql (sql): - sql_xlat radius_xlat: 'will' rlm_sql (sql): sql_set_user escaped user --> 'will' radius_xlat: 'SELECT SUM(AcctOutputOctets) FROM radacct where UserName='will'' rlm_sql (sql): Reserving sql socket id: 3 rlm_sql (sql): row[0] returned NULL rlm_sql (sql): Released sql socket id: 3 radius_xlat: '' rlm_sqlcounter: (Check item - counter) is less than zero rlm_sqlcounter: Rejected user will, check_item=-1149239296, counter=0 modcall[authorize]: module "mb" returns reject for request 0 modcall: leaving group authorize (returns reject) for request 0 -- ************************************* Tas Dionisakos IT Manager St Mary’s College and Newman College The University of Melbourne T: 03 9342 1708 M: 0439 655 565 E: tas@newman.unimelb.edu.au C: (0o (||||)(||||) o0) *************************************
Tas Dionisakos wrote:
I have setup a captive portal with mysql,chilli, and freeradius.
My portal allows users access base on data use (quota), I am using the rlm_sqlcounter (from freeradius 1.1.4) to measure the usage on login.
The problem Im having is that if I assign a quota more than 2gb freeradius sees the bytes in a negative value for some reason, I have attached rad logs.
Try this patch. If it works, please say so on the list. Alan DeKok. -- http://deployingradius.com - The web site of the book http://deployingradius.com/blog/ - The blog Index: rlm_sqlcounter.c =================================================================== RCS file: /source/radiusd/src/modules/rlm_sqlcounter/rlm_sqlcounter.c,v retrieving revision 1.11.2.3.2.6 diff -u -r1.11.2.3.2.6 rlm_sqlcounter.c --- rlm_sqlcounter.c 18 Nov 2006 14:45:19 -0000 1.11.2.3.2.6 +++ rlm_sqlcounter.c 25 Jan 2007 09:03:40 -0000 @@ -175,8 +175,8 @@ last = data->reset[len - 1]; if (!isalpha((int) last)) last = 'd'; -/* num = atoi(data->reset); */ - DEBUG("rlm_sqlcounter: num=%d, last=%c",num,last); + num = atoi(data->reset); + DEBUG("rlm_sqlcounter: num=%u, last=%c",num,last); } if (strcmp(data->reset, "hourly") == 0 || last == 'h') { /* @@ -392,6 +392,7 @@ check_pairs = check_pairs; /* shut the compiler up */ reply_pairs = reply_pairs; + request = request; /* first, expand %k, %b and %e in query */ sqlcounter_expand(querystr, MAX_QUERY_LEN, data->query, instance); @@ -596,7 +597,7 @@ { rlm_sqlcounter_t *data = (rlm_sqlcounter_t *) instance; int ret=RLM_MODULE_NOOP; - int counter=0; + uint32_t counter=0; int res=0; DICT_ATTR *dattr; VALUE_PAIR *key_vp, *check_vp; @@ -659,13 +660,18 @@ /* Finally, xlat resulting SQL query */ radius_xlat(querystr, MAX_QUERY_LEN, responsestr, request, sql_escape_func); - counter = atoi(querystr); + counter = strtoul(querystr, NULL, 10); /* * Check if check item > counter */ - res=check_vp->lvalue - counter; + if (check_vp->lvalue > counter) { + res = check_vp->lvalue - counter; + } else { + res = - ((int) (counter - check_vp->lvalue)); + } + if (res > 0) { DEBUG2("rlm_sqlcounter: (Check item - counter) is greater than zero"); /* @@ -692,7 +698,7 @@ } if ((reply_item = pairfind(request->reply->vps, data->reply_attr)) != NULL) { - if (reply_item->lvalue > res) + if (reply_item->lvalue > (uint32_t) res) reply_item->lvalue = res; } else { if ((reply_item = paircreate(data->reply_attr, PW_TYPE_INTEGER)) == NULL) { @@ -705,7 +711,7 @@ ret=RLM_MODULE_OK; - DEBUG2("rlm_sqlcounter: Authorized user %s, check_item=%d, counter=%d", + DEBUG2("rlm_sqlcounter: Authorized user %s, check_item=%d, counter=%u", key_vp->strvalue,check_vp->lvalue,counter); DEBUG2("rlm_sqlcounter: Sent Reply-Item for user %s, Type=%s, value=%d", key_vp->strvalue,data->reply_name,reply_item->lvalue); @@ -729,7 +735,7 @@ ret=RLM_MODULE_REJECT; - DEBUG2("rlm_sqlcounter: Rejected user %s, check_item=%d, counter=%d", + DEBUG2("rlm_sqlcounter: Rejected user %s, check_item=%d, counter=%u", key_vp->strvalue,check_vp->lvalue,counter); }
I have just applied the patch yet it still doesn't work, it produces the same result. It is still producing a negative value, are there any workarounds? Tas. Alan DeKok wrote:
Tas Dionisakos wrote:
I have setup a captive portal with mysql,chilli, and freeradius.
My portal allows users access base on data use (quota), I am using the rlm_sqlcounter (from freeradius 1.1.4) to measure the usage on login.
The problem Im having is that if I assign a quota more than 2gb freeradius sees the bytes in a negative value for some reason, I have attached rad logs.
Try this patch. If it works, please say so on the list.
Alan DeKok. -- http://deployingradius.com - The web site of the book http://deployingradius.com/blog/ - The blog
------------------------------------------------------------------------
Index: rlm_sqlcounter.c =================================================================== RCS file: /source/radiusd/src/modules/rlm_sqlcounter/rlm_sqlcounter.c,v retrieving revision 1.11.2.3.2.6 diff -u -r1.11.2.3.2.6 rlm_sqlcounter.c --- rlm_sqlcounter.c 18 Nov 2006 14:45:19 -0000 1.11.2.3.2.6 +++ rlm_sqlcounter.c 25 Jan 2007 09:03:40 -0000 @@ -175,8 +175,8 @@ last = data->reset[len - 1]; if (!isalpha((int) last)) last = 'd'; -/* num = atoi(data->reset); */ - DEBUG("rlm_sqlcounter: num=%d, last=%c",num,last); + num = atoi(data->reset); + DEBUG("rlm_sqlcounter: num=%u, last=%c",num,last); } if (strcmp(data->reset, "hourly") == 0 || last == 'h') { /* @@ -392,6 +392,7 @@
check_pairs = check_pairs; /* shut the compiler up */ reply_pairs = reply_pairs; + request = request;
/* first, expand %k, %b and %e in query */ sqlcounter_expand(querystr, MAX_QUERY_LEN, data->query, instance); @@ -596,7 +597,7 @@ { rlm_sqlcounter_t *data = (rlm_sqlcounter_t *) instance; int ret=RLM_MODULE_NOOP; - int counter=0; + uint32_t counter=0; int res=0; DICT_ATTR *dattr; VALUE_PAIR *key_vp, *check_vp; @@ -659,13 +660,18 @@ /* Finally, xlat resulting SQL query */ radius_xlat(querystr, MAX_QUERY_LEN, responsestr, request, sql_escape_func);
- counter = atoi(querystr); + counter = strtoul(querystr, NULL, 10);
/* * Check if check item > counter */ - res=check_vp->lvalue - counter; + if (check_vp->lvalue > counter) { + res = check_vp->lvalue - counter; + } else { + res = - ((int) (counter - check_vp->lvalue)); + } + if (res > 0) { DEBUG2("rlm_sqlcounter: (Check item - counter) is greater than zero"); /* @@ -692,7 +698,7 @@ }
if ((reply_item = pairfind(request->reply->vps, data->reply_attr)) != NULL) { - if (reply_item->lvalue > res) + if (reply_item->lvalue > (uint32_t) res) reply_item->lvalue = res; } else { if ((reply_item = paircreate(data->reply_attr, PW_TYPE_INTEGER)) == NULL) { @@ -705,7 +711,7 @@
ret=RLM_MODULE_OK;
- DEBUG2("rlm_sqlcounter: Authorized user %s, check_item=%d, counter=%d", + DEBUG2("rlm_sqlcounter: Authorized user %s, check_item=%d, counter=%u", key_vp->strvalue,check_vp->lvalue,counter); DEBUG2("rlm_sqlcounter: Sent Reply-Item for user %s, Type=%s, value=%d", key_vp->strvalue,data->reply_name,reply_item->lvalue); @@ -729,7 +735,7 @@
ret=RLM_MODULE_REJECT;
- DEBUG2("rlm_sqlcounter: Rejected user %s, check_item=%d, counter=%d", + DEBUG2("rlm_sqlcounter: Rejected user %s, check_item=%d, counter=%u", key_vp->strvalue,check_vp->lvalue,counter); }
------------------------------------------------------------------------
- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
-- ************************************* Tas Dionisakos IT Manager St Mary’s College and Newman College The University of Melbourne T: 03 9342 1708 M: 0439 655 565 E: tas@newman.unimelb.edu.au C: (0o (||||)(||||) o0) *************************************
Hi! I am trying to set the destination file for detail log file in the detail file module in the following way detailfile = ${radacctdir}/%{check:Huntgroup-Name}/detail-%Y%m but radius instead allways writes to the following destination?? rlm_detail: %A/%{Client-IP-Address}/detail expands to /var/log/radiusd/radacct/127.0.0.1/detail I have one more small question: How can I take from the User-Name attribute value wich is of the form username@domain.com the domain part in order to forward logging to the {radacctdir}/"cutted_domain_part"/detail-%Y%m file I kindly ask for your help. Best Tomasz
participants (3)
-
Alan DeKok -
Tas Dionisakos -
tzieleniewski