Massively cleaned up #include's, so they're in a consistent
[freeradius.git] / src / modules / rlm_logintime / rlm_logintime.c
index 31a18ab..03ca05a 100644 (file)
  *
  *   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,2006  The FreeRADIUS server project
  * Copyright 2004  Kostas Kalevras <kkalev@noc.ntua.gr>
  */
 
-#include "autoconf.h"
-#include "libradius.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-
-#include "radiusd.h"
-#include "modules.h"
-#include "conffile.h"
+#include <freeradius-devel/ident.h>
+RCSID("$Id$")
 
+#include <freeradius-devel/radiusd.h>
+#include <freeradius-devel/modules.h>
 
-static const char rcsid[] = "$Id$";
+#include <ctype.h>
 
 /*
  *     Define a structure for our module configuration.
@@ -83,7 +76,7 @@ static int timecmp(void *instance,
        /*
         *      If there's a request, use that timestamp.       
         */
-       if (timestr_match((char *)check->strvalue,
+       if (timestr_match((char *)check->vp_strvalue,
        req ? req->timestamp : time(NULL)) >= 0)
                return 0;
 
@@ -114,9 +107,9 @@ static int time_of_day(void *instance,
         */
        if (!req) return -1;
   
-       if (strspn(check->strvalue, "0123456789: ") != strlen(check->strvalue)) {
+       if (strspn(check->vp_strvalue, "0123456789: ") != strlen(check->vp_strvalue)) {
                DEBUG("rlm_logintime: Bad Time-Of-Day value \"%s\"",
-                     check->strvalue);
+                     check->vp_strvalue);
                return -1;
        }
 
@@ -126,12 +119,12 @@ static int time_of_day(void *instance,
        /*
         *      Time of day is a 24-hour clock
         */
-       p = check->strvalue;
+       p = check->vp_strvalue;
        scan = atoi(p);
        p = strchr(p, ':');
        if ((scan > 23) || !p) {
                DEBUG("rlm_logintime: Bad Time-Of-Day value \"%s\"",
-                     check->strvalue);
+                     check->vp_strvalue);
                return -1;
        }
        when = scan * 3600;
@@ -140,7 +133,7 @@ static int time_of_day(void *instance,
        scan = atoi(p);
        if (scan > 59) {
                DEBUG("rlm_logintime: Bad Time-Of-Day value \"%s\"",
-                     check->strvalue);
+                     check->vp_strvalue);
                return -1;
        }
        when += scan * 60;
@@ -150,7 +143,7 @@ static int time_of_day(void *instance,
                scan = atoi(p + 1);
                if (scan > 59) {
                        DEBUG("rlm_logintime: Bad Time-Of-Day value \"%s\"",
-                             check->strvalue);
+                             check->vp_strvalue);
                        return -1;
                }
                when += scan;
@@ -177,8 +170,8 @@ static int logintime_authorize(void *instance, REQUEST *request)
                 *      Authentication is OK. Now see if this
                 *      user may login at this time of the day.
                 */
-               DEBUG("rlm_logintime: Checking Login-Time: '%s'",check_item->strvalue);
-               r = timestr_match((char *)check_item->strvalue,
+               DEBUG("rlm_logintime: Checking Login-Time: '%s'",check_item->vp_strvalue);
+               r = timestr_match((char *)check_item->vp_strvalue,
                request->timestamp);
                if (r == 0) {   /* unlimited */
                        /*
@@ -200,7 +193,7 @@ static int logintime_authorize(void *instance, REQUEST *request)
                         */
                
                        DEBUG("rlm_logintime: timestr returned reject");
-                       if (data->msg){
+                       if (data->msg && data->msg[0]){
                                char msg[MAX_STRING_LEN];
                                VALUE_PAIR *tmp;
 
@@ -214,7 +207,7 @@ static int logintime_authorize(void *instance, REQUEST *request)
                        }
 
                        snprintf(logstr, sizeof(logstr), "Outside allowed timespan (time allowed %s)",
-                       check_item->strvalue);
+                       check_item->vp_strvalue);
                        module_fmsg_vp = pairmake("Module-Failure-Message", logstr, T_OP_EQ);
                        pairadd(&request->packet->vps, module_fmsg_vp);
 
@@ -282,17 +275,8 @@ static int logintime_instantiate(CONF_SECTION *conf, void **instance)
                return -1;
        }
 
-       /*
-        * If we are passed an empty reply-message don't use it
-        */
-       if (!strlen(data->msg)){
-               free(data->msg);
-               data->msg = NULL;
-       }
-
        if (data->min_time == 0){
                radlog(L_ERR, "rlm_logintime: Minimum timeout should be non zero.");
-               free(data->msg);
                free(data);
                return -1;
        }
@@ -313,8 +297,7 @@ static int logintime_detach(void *instance)
        rlm_logintime_t *data = (rlm_logintime_t *) instance;
 
        paircompare_unregister(PW_CURRENT_TIME, timecmp);
-       if (data->msg)
-               free(data->msg);
+       paircompare_unregister(PW_TIME_OF_DAY, time_of_day);
        free(instance);
        return 0;
 }
@@ -329,10 +312,11 @@ static int logintime_detach(void *instance)
  *     is single-threaded.
  */
 module_t rlm_logintime = {
+       RLM_MODULE_INIT,
        "logintime",
        RLM_TYPE_THREAD_SAFE,           /* type */
-       NULL,                           /* initialization */
        logintime_instantiate,          /* instantiation */
+       logintime_detach,               /* detach */
        {
                NULL,                   /* authentication */
                logintime_authorize,    /* authorization */
@@ -343,6 +327,4 @@ module_t rlm_logintime = {
                NULL,                   /* post-proxy */
                NULL                    /* post-auth */
        },
-       logintime_detach,               /* detach */
-       NULL,                           /* destroy */
 };