Pull from CVS head:
authornbk <nbk>
Sat, 18 Nov 2006 14:45:17 +0000 (14:45 +0000)
committernbk <nbk>
Sat, 18 Nov 2006 14:45:17 +0000 (14:45 +0000)
Add a new "reply-name" directive to choose the attribute which will
contain the remaining value for the counter in the reply packet when
the user is successfully authorized. (closes: #403)

doc/rlm_sqlcounter
raddb/radiusd.conf.in
src/modules/rlm_sqlcounter/rlm_sqlcounter.c

index 57857ed..b170e89 100644 (file)
@@ -25,6 +25,7 @@ with the following content (for mysql):
 sqlcounter noresetcounter {
                 counter-name = Max-All-Session-Time
                 check-name = Max-All-Session
+                reply-name = Session-Timeout
                 sqlmod-inst = sql
                 key = User-Name
                 reset = never
@@ -38,6 +39,7 @@ sqlcounter dailycounter {
                 driver = "rlm_sqlcounter"
                 counter-name = Daily-Session-Time
                 check-name = Max-Daily-Session
+                reply-name = Session-Timeout
                 sqlmod-inst = sqlcca3
                 key = User-Name
                 reset = daily
@@ -49,6 +51,7 @@ sqlcounter dailycounter {
 sqlcounter monthlycounter {
                 counter-name = Monthly-Session-Time
                 check-name = Max-Monthly-Session
+                reply-name = Session-Timeout
                 sqlmod-inst = sqlcca3
                 key = User-Name
                 reset = monthly
index 8d4a503..a6c5a79 100644 (file)
@@ -1447,6 +1447,7 @@ $INCLUDE ${confdir}/eap.conf
        sqlcounter dailycounter {
                counter-name = Daily-Session-Time
                check-name = Max-Daily-Session
+               reply-name = Session-Timeout
                sqlmod-inst = sql
                key = User-Name
                reset = daily
@@ -1495,6 +1496,7 @@ $INCLUDE ${confdir}/eap.conf
        sqlcounter monthlycounter {
                counter-name = Monthly-Session-Time
                check-name = Max-Monthly-Session
+               reply-name = Session-Timeout
                sqlmod-inst = sql
                key = User-Name
                reset = monthly
index 45d6cd8..3266b6b 100644 (file)
@@ -15,7 +15,7 @@
  *
  *   You should have received a copy of the GNU General Public License
  *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  *
  * Copyright 2001  The FreeRADIUS server project
  * Copyright 2001  Alan DeKok <aland@ox.org>
@@ -67,6 +67,7 @@ static const char rcsid[] = "$Id$";
 typedef struct rlm_sqlcounter_t {
        char *counter_name;     /* Daily-Session-Time */
        char *check_name;       /* Max-Daily-Session */
+       char *reply_name;       /* Session-Timeout */
        char *key_name;         /* User-Name */
        char *sqlmod_inst;      /* instance of SQL module to use, usually just 'sql' */
        char *query;            /* SQL query to retrieve current session time */
@@ -76,6 +77,7 @@ typedef struct rlm_sqlcounter_t {
        time_t last_reset;
        int  key_attr;          /* attribute number for key field */
        int  dict_attr;         /* attribute number for the counter. */
+       int  reply_attr;        /* attribute number for the reply */
 } rlm_sqlcounter_t;
 
 /*
@@ -90,6 +92,7 @@ typedef struct rlm_sqlcounter_t {
 static CONF_PARSER module_config[] = {
   { "counter-name", PW_TYPE_STRING_PTR, offsetof(rlm_sqlcounter_t,counter_name), NULL,  NULL },
   { "check-name", PW_TYPE_STRING_PTR, offsetof(rlm_sqlcounter_t,check_name), NULL, NULL },
+  { "reply-name", PW_TYPE_STRING_PTR, offsetof(rlm_sqlcounter_t,reply_name), NULL, NULL },
   { "key", PW_TYPE_STRING_PTR, offsetof(rlm_sqlcounter_t,key_name), NULL, NULL },
   { "sqlmod-inst", PW_TYPE_STRING_PTR, offsetof(rlm_sqlcounter_t,sqlmod_inst), NULL, NULL },
   { "query", PW_TYPE_STRING_PTR, offsetof(rlm_sqlcounter_t,query), NULL, NULL },
@@ -455,7 +458,7 @@ static int sqlcounter_instantiate(CONF_SECTION *conf, void **instance)
 
        /*
         *      Safe characters list for sql queries. Everything else is
-        *      replaced rwith their mime-encoded equivalents.
+        *      replaced with their mime-encoded equivalents.
         */
        allowed_chars = data->allowed_chars;
 
@@ -480,6 +483,28 @@ static int sqlcounter_instantiate(CONF_SECTION *conf, void **instance)
        data->key_attr = dattr->attr;
 
        /*
+        *      Discover the attribute number of the reply.
+        *      If not set, set it to Session-Timeout
+        *      for backward compatibility.
+        */
+       if (data->reply_name == NULL) {
+               DEBUG2("rlm_sqlcounter: Reply attribute set to Session-Timeout.");
+               data->reply_attr = PW_SESSION_TIMEOUT;
+               data->reply_name = strdup("Session-Timeout");
+       }
+       else {
+               dattr = dict_attrbyname(data->reply_name);
+               if (dattr == NULL) {
+                       radlog(L_ERR, "rlm_sqlcounter: No such attribute %s",
+                              data->reply_name);
+                       return -1;
+               }
+               data->reply_attr = dattr->attr;
+               DEBUG2("rlm_sqlcounter: Reply attribute %s is number %d",
+                      data->reply_name, dattr->attr);
+       }
+
+       /*
         *      Check the "sqlmod-inst" option.
         */
        if (data->sqlmod_inst == NULL) {
@@ -666,11 +691,11 @@ static int sqlcounter_authorize(void *instance, REQUEST *request)
                        res += check_vp->lvalue;
                }
 
-               if ((reply_item = pairfind(request->reply->vps, PW_SESSION_TIMEOUT)) != NULL) {
+               if ((reply_item = pairfind(request->reply->vps, data->reply_attr)) != NULL) {
                        if (reply_item->lvalue > res)
                                reply_item->lvalue = res;
                } else {
-                       if ((reply_item = paircreate(PW_SESSION_TIMEOUT, PW_TYPE_INTEGER)) == NULL) {
+                       if ((reply_item = paircreate(data->reply_attr, PW_TYPE_INTEGER)) == NULL) {
                                radlog(L_ERR|L_CONS, "no memory");
                                return RLM_MODULE_NOOP;
                        }
@@ -682,8 +707,8 @@ static int sqlcounter_authorize(void *instance, REQUEST *request)
 
                DEBUG2("rlm_sqlcounter: Authorized user %s, check_item=%d, counter=%d",
                                key_vp->strvalue,check_vp->lvalue,counter);
-               DEBUG2("rlm_sqlcounter: Sent Reply-Item for user %s, Type=Session-Timeout, value=%d",
-                               key_vp->strvalue,reply_item->lvalue);
+               DEBUG2("rlm_sqlcounter: Sent Reply-Item for user %s, Type=%s, value=%d",
+                               key_vp->strvalue,data->reply_name,reply_item->lvalue);
        }
        else{
                char module_fmsg[MAX_STRING_LEN];
@@ -719,6 +744,7 @@ static int sqlcounter_detach(void *instance)
        free(data->reset);
        free(data->query);
        free(data->check_name);
+       if (data->reply_name) free(data->reply_name);
        free(data->sqlmod_inst);
        free(data->counter_name);
        free(data->allowed_chars);