Massively cleaned up #include's, so they're in a consistent
[freeradius.git] / src / modules / rlm_counter / rlm_counter.c
index 74491d8..5dae38a 100644 (file)
  *   along with this program; if not, write to the Free Software
  *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  *
- * Copyright 2001  The FreeRADIUS server project
+ * Copyright 2001,2006  The FreeRADIUS server project
  * Copyright 2001  Alan DeKok <aland@ox.org>
  * Copyright 2001-3  Kostas Kalevras <kkalev@noc.ntua.gr>
  */
 
-#include "config.h"
-#include <freeradius-devel/autoconf.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
+#include <freeradius-devel/ident.h>
+RCSID("$Id$")
 
 #include <freeradius-devel/radiusd.h>
 #include <freeradius-devel/modules.h>
-#include <freeradius-devel/conffile.h>
+
+#include <ctype.h>
+
+#include "config.h"
 
 #include <gdbm.h>
-#include <time.h>
 
 #ifdef NEEDS_GDBM_SYNC
 #      define GDBM_SYNCOPT GDBM_SYNC
@@ -55,8 +52,6 @@
 
 #define UNIQUEID_MAX_LEN 32
 
-static const char rcsid[] = "$Id$";
-
 /*
  *     Define a structure for our module configuration.
  *
@@ -69,16 +64,16 @@ typedef struct rlm_counter_t {
        char *reset;            /* daily, weekly, monthly, never or user defined */
        char *key_name;         /* User-Name */
        char *count_attribute;  /* Acct-Session-Time */
-       char *return_attribute; /* Session-Timeout */
        char *counter_name;     /* Daily-Session-Time */
        char *check_name;       /* Daily-Max-Session */
+       char *reply_name;       /* Session-Timeout */
        char *service_type;     /* Service-Type to search for */
        int cache_size;
        int service_val;
        int key_attr;
        int count_attr;
-       int return_attr;
        int check_attr;
+       int reply_attr;
        time_t reset_time;      /* The time of the next reset. */
        time_t last_reset;      /* The time of the last reset. */
        int dict_attr;          /* attribute number for the counter. */
@@ -118,9 +113,9 @@ static const CONF_PARSER module_config[] = {
   { "key", PW_TYPE_STRING_PTR, offsetof(rlm_counter_t,key_name), NULL, NULL },
   { "reset", PW_TYPE_STRING_PTR, offsetof(rlm_counter_t,reset), NULL,  NULL },
   { "count-attribute", PW_TYPE_STRING_PTR, offsetof(rlm_counter_t,count_attribute), NULL, NULL },
-  { "return-attribute", PW_TYPE_STRING_PTR, offsetof(rlm_counter_t,return_attribute), NULL, NULL },
   { "counter-name", PW_TYPE_STRING_PTR, offsetof(rlm_counter_t,counter_name), NULL,  NULL },
   { "check-name", PW_TYPE_STRING_PTR, offsetof(rlm_counter_t,check_name), NULL, NULL },
+  { "reply-name", PW_TYPE_STRING_PTR, offsetof(rlm_counter_t,reply_name), NULL, NULL },
   { "allowed-servicetype", PW_TYPE_STRING_PTR, offsetof(rlm_counter_t,service_type),NULL, NULL },
   { "cache-size", PW_TYPE_INTEGER, offsetof(rlm_counter_t,cache_size), NULL, "1000" },
   { NULL, -1, 0, NULL, NULL }
@@ -388,23 +383,23 @@ static int counter_instantiate(CONF_SECTION *conf, void **instance)
        data->count_attr = dattr->attr;
 
        /*
-        * Discover the attribute number of the return attribute.
+        * Discover the attribute number of the reply attribute.
         */
-       if (data->return_attribute != NULL) {
-               dattr = dict_attrbyname(data->return_attribute);
+       if (data->reply_name != NULL) {
+               dattr = dict_attrbyname(data->reply_name);
                if (dattr == NULL) {
                        radlog(L_ERR, "rlm_counter: No such attribute %s",
-                                       data->return_attribute);
+                                       data->reply_name);
                        counter_detach(data);
                        return -1;
                }
                if (dattr->type != PW_TYPE_INTEGER) {
-                       radlog(L_ERR, "rlm_counter: Return attribute %s is not of type integer",
-                               data->return_attribute);
+                       radlog(L_ERR, "rlm_counter: Reply attribute %s is not of type integer",
+                               data->reply_name);
                        counter_detach(data);
                        return -1;
                }
-               data->return_attr = dattr->attr;
+               data->reply_attr = dattr->attr;
        }
        
 
@@ -665,7 +660,8 @@ static int counter_accounting(void *instance, REQUEST *request)
                DEBUG("rlm_counter: Could not find the requested key in the database.");
                counter.user_counter = 0;
                if (uniqueid_vp != NULL)
-                       strncpy(counter.uniqueid,uniqueid_vp->vp_strvalue,UNIQUEID_MAX_LEN - 1);
+                       strlcpy(counter.uniqueid,uniqueid_vp->vp_strvalue,
+                               sizeof(counter.uniqueid));
                else
                        memset((char *)counter.uniqueid,0,UNIQUEID_MAX_LEN);
        }
@@ -681,7 +677,8 @@ static int counter_accounting(void *instance, REQUEST *request)
                                DEBUG("rlm_counter: Unique IDs for user match. Droping the request.");
                                return RLM_MODULE_NOOP;
                        }
-                       strncpy(counter.uniqueid,uniqueid_vp->vp_strvalue,UNIQUEID_MAX_LEN - 1);
+                       strlcpy(counter.uniqueid,uniqueid_vp->vp_strvalue,
+                               sizeof(counter.uniqueid));
                }
                DEBUG("rlm_counter: User=%s, Counter=%d.",request->username->vp_strvalue,counter.user_counter);
        }
@@ -863,13 +860,13 @@ static int counter_authorize(void *instance, REQUEST *request)
                                pairadd(&request->reply->vps, reply_item);
                        }
                }
-               else if (data->return_attr) {
-                       if ((reply_item = pairfind(request->reply->vps, data->return_attr)) != NULL) {
+               else if (data->reply_attr) {
+                       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(data->return_attr, 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;
                                }
@@ -917,13 +914,6 @@ static int counter_detach(void *instance)
        paircompare_unregister(data->dict_attr, counter_cmp);
        if (data->gdbm)
                gdbm_close(data->gdbm);
-       free(data->filename);
-       free(data->reset);
-       free(data->key_name);
-       free(data->count_attribute);
-       free(data->counter_name);
-       free(data->check_name);
-       free(data->service_type);
        pthread_mutex_destroy(&data->mutex);
 
        free(instance);