Matthew Schumacher wrote:
List,
My radius system uses the NAS-Identifer attribute to make some decisions on how to log or record utmp records. Everything works fine until I have a situation where freeradius generates a stop packet in the session_zap function. Because the stop packet doesn't have the NAS-Identifier attribute it breaks the way I log things.
I started hacking together a patch that would pass the NAS-Identifier of the access-request packet, but it doesn't work. Can someone take a look at my patch, or perhaps suggest a better work around?
Thanks, schu
Ok, I have a working patch now, but would really appreciate it if someone else would look it over as I am not very good at C. Also, since the current code doesn't set any NAS-Identifier on generated stop packets I think this patch should be considered for inclusion as it is fairly common to have people make auth and acct decisions based on the NAS-Identifier attribute and the change wouldn't break or change anything currently in place. Thanks, schu diff -ruN freeradius-1.1.2.orig/src/include/radiusd.h freeradius-1.1.2/src/include/radiusd.h --- freeradius-1.1.2.orig/src/include/radiusd.h 2005-04-11 15:45:21.000000000 -0800 +++ freeradius-1.1.2/src/include/radiusd.h 2006-07-28 10:20:50.000000000 -0800 @@ -293,7 +293,7 @@ int session_zap(REQUEST *request, uint32_t nasaddr, unsigned int port, const char *user, const char *sessionid, uint32_t cliaddr, - char proto); + char proto, const char *nas_ident); /* radiusd.c */ #ifndef _LIBRADIUS diff -ruN freeradius-1.1.2.orig/src/main/session.c freeradius-1.1.2/src/main/session.c --- freeradius-1.1.2.orig/src/main/session.c 2006-03-24 08:54:57.000000000 -0900 +++ freeradius-1.1.2/src/main/session.c 2006-07-28 10:20:15.000000000 -0800 @@ -46,7 +46,7 @@ /* End a session by faking a Stop packet to all accounting modules */ int session_zap(REQUEST *request, uint32_t nasaddr, unsigned int port, const char *user, - const char *sessionid, uint32_t cliaddr, char proto) + const char *sessionid, uint32_t cliaddr, char proto, const char *nas_ident) { REQUEST *stopreq; VALUE_PAIR *vp, *userpair; @@ -83,6 +83,7 @@ IPPAIR(PW_NAS_IP_ADDRESS, nasaddr); INTPAIR(PW_ACCT_DELAY_TIME, 0); STRINGPAIR(PW_USER_NAME, user); + STRINGPAIR(PW_NAS_IDENTIFIER, nas_ident); userpair = vp; INTPAIR(PW_NAS_PORT, port); STRINGPAIR(PW_ACCT_SESSION_ID, sessionid); diff -ruN freeradius-1.1.2.orig/src/modules/rlm_radutmp/rlm_radutmp.c freeradius-1.1.2/src/modules/rlm_radutmp/rlm_radutmp.c --- freeradius-1.1.2.orig/src/modules/rlm_radutmp/rlm_radutmp.c 2004-02-26 10:04:34.000000000 -0900 +++ freeradius-1.1.2/src/modules/rlm_radutmp/rlm_radutmp.c 2006-07-28 10:24:06.000000000 -0800 @@ -589,6 +589,7 @@ rlm_radutmp_t *inst = instance; char login[256]; char filename[1024]; + char *nas_ident = NULL; /* * Get the filename, via xlat. @@ -656,6 +657,8 @@ ipno = vp->lvalue; if ((vp = pairfind(request->packet->vps, PW_CALLING_STATION_ID)) != NULL) call_num = vp->strvalue; + if ((vp = pairfind(request->packet->vps, PW_NAS_IDENTIFIER)) != NULL) + nas_ident = vp->strvalue; /* * lock the file while reading/writing. @@ -736,7 +739,7 @@ session_zap(request, u.nas_address, u.nas_port, login, session_id, u.framed_address, - u.proto); + u.proto, nas_ident); } } } diff -ruN freeradius-1.1.2.orig/src/modules/rlm_sql/rlm_sql.c freeradius-1.1.2/src/modules/rlm_sql/rlm_sql.c --- freeradius-1.1.2.orig/src/modules/rlm_sql/rlm_sql.c 2006-05-20 04:44:37.000000000 -0800 +++ freeradius-1.1.2/src/modules/rlm_sql/rlm_sql.c 2006-07-28 10:25:25.000000000 -0800 @@ -1132,6 +1132,7 @@ int ret; uint32_t nas_addr = 0; int nas_port = 0; + char *nas_ident = NULL; /* If simul_count_query is not defined, we don't do any checking */ if (inst->config->simul_count_query[0] == 0) { @@ -1207,7 +1208,8 @@ ipno = vp->lvalue; if ((vp = pairfind(request->packet->vps, PW_CALLING_STATION_ID)) != NULL) call_num = vp->strvalue; - + if ((vp = pairfind(request->packet->vps, PW_NAS_IDENTIFIER)) != NULL) + nas_ident = vp->strvalue; while (rlm_sql_fetch_row(sqlsocket, inst) == 0) { row = sqlsocket->row; @@ -1271,7 +1273,7 @@ session_zap(request, nas_addr,nas_port,row[2],row[1], - framed_addr, proto); + framed_addr, proto, nas_ident); } }