Massively cleaned up #include's, so they're in a consistent
[freeradius.git] / src / modules / rlm_unix / rlm_unix.c
index 1a70544..ec707c3 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 2000  The FreeRADIUS server project
+ * Copyright 2000,2006  The FreeRADIUS server project
  * Copyright 2000  Jeff Carneal <jeff@apex.net>
  * Copyright 2000  Alan Curry <pacman@world.std.com>
  */
-static const char rcsid[] = "$Id$";
 
-#include       "autoconf.h"
+#include       <freeradius-devel/ident.h>
+RCSID("$Id$")
+
+#include       <freeradius-devel/radiusd.h>
 
-#include       <stdlib.h>
-#include       <string.h>
 #include       <grp.h>
 #include       <pwd.h>
-#include       <sys/types.h>
 #include       <sys/stat.h>
 
 #include "config.h"
@@ -50,9 +49,8 @@ static const char rcsid[] = "$Id$";
 #  include     <siad.h>
 #endif
 
-#include       "radiusd.h"
-#include       "modules.h"
-#include       "sysutmp.h"
+#include       <freeradius-devel/modules.h>
+#include       <freeradius-devel/sysutmp.h>
 
 static char trans[64] =
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@@ -73,7 +71,7 @@ static const CONF_PARSER module_config[] = {
 /*
  *     The Group = handler.
  */
-static int groupcmp(void *instance, REQUEST *req, VALUE_PAIR *request,
+static int groupcmp(void *instance, UNUSED REQUEST *req, VALUE_PAIR *request,
                    VALUE_PAIR *check, VALUE_PAIR *check_pairs,
                    VALUE_PAIR **reply_pairs)
 {
@@ -98,13 +96,13 @@ static int groupcmp(void *instance, REQUEST *req, VALUE_PAIR *request,
                        return -1;
                }
        }
-       username = (char *)vp->strvalue;
+       username = (char *)vp->vp_strvalue;
 
        pwd = getpwnam(username);
        if (pwd == NULL)
                return -1;
 
-       grp = getgrnam((char *)check->strvalue);
+       grp = getgrnam((char *)check->vp_strvalue);
        if (grp == NULL)
                return -1;
 
@@ -120,29 +118,16 @@ static int groupcmp(void *instance, REQUEST *req, VALUE_PAIR *request,
 
 
 /*
- *     Done once when the module is loaded, and NOT on a per-instance
- *     basis.
- */
-static int unix_init(void)
-{
-       /* FIXME - delay these until a group file has been read so we know
-        * groupcmp can actually do something */
-       paircompare_register(PW_GROUP, PW_USER_NAME, groupcmp, NULL);
-#ifdef PW_GROUP_NAME /* compat */
-       paircompare_register(PW_GROUP_NAME, PW_USER_NAME, groupcmp, NULL);
-#endif
-       return 0;
-}
-
-
-/*
  *     Detach.
  */
 static int unix_detach(void *instance)
 {
 #define inst ((struct unix_instance *)instance)
-       if (inst->radwtmp)
-               free(inst->radwtmp);
+
+       paircompare_unregister(PW_GROUP, groupcmp);
+#ifdef PW_GROUP_NAME
+       paircompare_unregister(PW_GROUP_NAME, groupcmp);
+#endif
 #undef inst
        free(instance);
        return 0;
@@ -172,19 +157,15 @@ static int unix_instantiate(CONF_SECTION *conf, void **instance)
                return -1;
        }
 
-#undef inst
-
-       return 0;
-}
-
+       /* FIXME - delay these until a group file has been read so we know
+        * groupcmp can actually do something */
+       paircompare_register(PW_GROUP, PW_USER_NAME, groupcmp, NULL);
+#ifdef PW_GROUP_NAME /* compat */
+       paircompare_register(PW_GROUP_NAME, PW_USER_NAME, groupcmp, NULL);
+#endif
 
+#undef inst
 
-static int unix_destroy(void)
-{
-       paircompare_unregister(PW_GROUP, groupcmp);
-#ifdef PW_GROUP_NAME
-       paircompare_unregister(PW_GROUP_NAME, groupcmp);
-#endif
        return 0;
 }
 
@@ -193,7 +174,8 @@ static int unix_destroy(void)
  *     Pull the users password from where-ever, and add it to
  *     the given vp list.
  */
-static int unix_getpw(void *instance, REQUEST *request, VALUE_PAIR **vp_list)
+static int unix_getpw(UNUSED void *instance, REQUEST *request,
+                     VALUE_PAIR **vp_list)
 {
        const char      *name;
        const char      *encrypted_pass;
@@ -218,7 +200,7 @@ static int unix_getpw(void *instance, REQUEST *request, VALUE_PAIR **vp_list)
                return RLM_MODULE_NOOP;
        }
 
-       name = (char *)request->username->strvalue;
+       name = (char *)request->username->vp_strvalue;
        encrypted_pass = NULL;
 
 #ifdef OSFC2
@@ -382,10 +364,10 @@ static int unix_authenticate(void *instance, REQUEST *request)
        /*
         *      0 means "ok"
         */
-       if (lrad_crypt_check((char *) request->password->strvalue,
-                            (char *) vp->strvalue) != 0) {
+       if (lrad_crypt_check((char *) request->password->vp_strvalue,
+                            (char *) vp->vp_strvalue) != 0) {
                radlog(L_AUTH, "rlm_unix: [%s]: invalid password",
-                      request->username->strvalue);
+                      request->username->vp_strvalue);
                return RLM_MODULE_REJECT;
        }
 #endif /* OSFFIA */
@@ -490,9 +472,9 @@ static int unix_accounting(void *instance, REQUEST *request)
                switch (vp->attribute) {
                        case PW_USER_NAME:
                                if (vp->length >= sizeof(ut.ut_name)) {
-                                       memcpy(ut.ut_name, (char *)vp->strvalue, sizeof(ut.ut_name));
+                                       memcpy(ut.ut_name, (char *)vp->vp_strvalue, sizeof(ut.ut_name));
                                } else {
-                                       strNcpy(ut.ut_name, (char *)vp->strvalue, sizeof(ut.ut_name));
+                                       strlcpy(ut.ut_name, (char *)vp->vp_strvalue, sizeof(ut.ut_name));
                                }
                                break;
                        case PW_LOGIN_IP_HOST:
@@ -535,7 +517,7 @@ static int unix_accounting(void *instance, REQUEST *request)
                RADCLIENT *cl;
                nas_address = request->packet->src_ipaddr.ipaddr.ip4addr.s_addr;
                
-               if ((cl = client_find(&request->packet->src_ipaddr)) != NULL)
+               if ((cl = client_find_old(&request->packet->src_ipaddr)) != NULL)
                        s = cl->shortname;
        }
        if (!s || s[0] == 0) s = uue(&(nas_address));
@@ -551,7 +533,7 @@ static int unix_accounting(void *instance, REQUEST *request)
         *      and address so that the tty field is unique.
         */
        sprintf(buf, "%03d:%s", nas_port, s);
-       strNcpy(ut.ut_line, buf, sizeof(ut.ut_line));
+       strlcpy(ut.ut_line, buf, sizeof(ut.ut_line));
 
        /*
         *      We store the dynamic IP address in the hostname field.
@@ -559,7 +541,7 @@ static int unix_accounting(void *instance, REQUEST *request)
 #ifdef UT_HOSTSIZE
        if (framed_address) {
                ip_ntoa(buf, framed_address);
-               strncpy(ut.ut_host, buf, sizeof(ut.ut_host));
+               strlcpy(ut.ut_host, buf, sizeof(ut.ut_host));
        }
 #endif
 #ifdef HAVE_UTMPX_H
@@ -604,20 +586,19 @@ static int unix_accounting(void *instance, REQUEST *request)
 
 /* globally exported name */
 module_t rlm_unix = {
-  "System",
-  RLM_TYPE_THREAD_UNSAFE,        /* type */
-  unix_init,                    /* initialization */
-  unix_instantiate,            /* instantiation */
-  {
-         unix_authenticate,    /* authentication */
-         unix_authorize,       /* authorization */
-         NULL,                 /* preaccounting */
-         unix_accounting,      /* accounting */
-         NULL,                  /* checksimul */
-         NULL,                 /* pre-proxy */
-         NULL,                 /* post-proxy */
-         NULL                  /* post-auth */
-  },
-  unix_detach,                         /* detach */
-  unix_destroy,                  /* destroy */
+       RLM_MODULE_INIT,
+       "System",
+       RLM_TYPE_THREAD_UNSAFE,        /* type */
+       unix_instantiate,               /* instantiation */
+       unix_detach,                    /* detach */
+       {
+               unix_authenticate,    /* authentication */
+               unix_authorize,       /* authorization */
+               NULL,                 /* preaccounting */
+               unix_accounting,      /* accounting */
+               NULL,                  /* checksimul */
+               NULL,                   /* pre-proxy */
+               NULL,                   /* post-proxy */
+               NULL                    /* post-auth */
+       },
 };