Re-arrange entries in the module_t structure, and do some
authoraland <aland>
Wed, 17 Aug 2005 23:48:26 +0000 (23:48 +0000)
committeraland <aland>
Wed, 17 Aug 2005 23:48:26 +0000 (23:48 +0000)
more checking when we load modules.

45 files changed:
src/include/modules.h
src/main/modules.c
src/modules/rlm_acct_unique/rlm_acct_unique.c
src/modules/rlm_always/rlm_always.c
src/modules/rlm_attr_filter/rlm_attr_filter.c
src/modules/rlm_attr_rewrite/rlm_attr_rewrite.c
src/modules/rlm_caching/rlm_caching.c
src/modules/rlm_chap/rlm_chap.c
src/modules/rlm_checkval/rlm_checkval.c
src/modules/rlm_copy_packet/rlm_copy_packet.c
src/modules/rlm_counter/rlm_counter.c
src/modules/rlm_cram/rlm_cram.c
src/modules/rlm_dbm/rlm_dbm.c
src/modules/rlm_detail/rlm_detail.c
src/modules/rlm_digest/rlm_digest.c
src/modules/rlm_eap/rlm_eap.c
src/modules/rlm_example/rlm_example.c
src/modules/rlm_exec/rlm_exec.c
src/modules/rlm_expiration/rlm_expiration.c
src/modules/rlm_expr/rlm_expr.c
src/modules/rlm_fastusers/rlm_fastusers.c
src/modules/rlm_files/rlm_files.c
src/modules/rlm_ippool/rlm_ippool.c
src/modules/rlm_krb5/rlm_krb5.c
src/modules/rlm_ldap/rlm_ldap.c
src/modules/rlm_linelog/rlm_linelog.c
src/modules/rlm_logintime/rlm_logintime.c
src/modules/rlm_mschap/rlm_mschap.c
src/modules/rlm_otp/otp_rlm.c
src/modules/rlm_pam/rlm_pam.c
src/modules/rlm_pap/rlm_pap.c
src/modules/rlm_passwd/rlm_passwd.c
src/modules/rlm_perl/rlm_perl.c
src/modules/rlm_policy/rlm_policy.c
src/modules/rlm_preprocess/rlm_preprocess.c
src/modules/rlm_protocol_filter/rlm_protocol_filter.c
src/modules/rlm_python/rlm_python.c
src/modules/rlm_radutmp/rlm_radutmp.c
src/modules/rlm_realm/rlm_realm.c
src/modules/rlm_sim_files/rlm_sim_files.c
src/modules/rlm_smb/rlm_smb.c
src/modules/rlm_sql/rlm_sql.c
src/modules/rlm_sql_log/rlm_sql_log.c
src/modules/rlm_sqlcounter/rlm_sqlcounter.c
src/modules/rlm_unix/rlm_unix.c

index 58393c2..9a3f44e 100644 (file)
@@ -26,14 +26,16 @@ enum {
 #define RLM_TYPE_THREAD_SAFE   (0 << 0)
 #define RLM_TYPE_THREAD_UNSAFE (1 << 0)
 
+#define RLM_MODULE_MAGIC_NUMBER ((uint32_t) (0xf4ee4ad12))
+#define RLM_MODULE_INIT RLM_MODULE_MAGIC_NUMBER
+
 typedef struct module_t {
+       uint32_t        magic;  /* may later be opaque struct */
        const char      *name;
-       int     type;                   /* reserved */
-       int     (*init)(void);
-       int     (*instantiate)(CONF_SECTION *mod_cs, void **instance);
+       int             type;
+       int             (*instantiate)(CONF_SECTION *mod_cs, void **instance);
+       int             (*detach)(void *instance);
        packetmethod    methods[RLM_COMPONENT_COUNT];
-       int     (*detach)(void *instance);
-       int     (*destroy)(void);
 } module_t;
 
 enum {
index 258e43b..f6fed61 100644 (file)
@@ -131,8 +131,6 @@ static void module_entry_free(void *data)
 {
        module_entry_t *this = data;
 
-       if (this->module->destroy)
-               (this->module->destroy)();
        lt_dlclose(this->handle);       /* ignore any errors */
        free(this);
 }
@@ -166,6 +164,7 @@ static module_entry_t *linkto_module(CONF_SECTION *modules,
        lt_dlhandle handle;
        char module_struct[256];
        char *p;
+       const void *module;
 
        node = cf_data_find(modules, module_name);
        if (node) return node;
@@ -176,18 +175,10 @@ static module_entry_t *linkto_module(CONF_SECTION *modules,
        handle = lt_dlopenext(module_name);
        if (handle == NULL) {
                radlog(L_ERR|L_CONS, "%s[%d] Failed to link to module '%s':"
-                               " %s\n", cffilename, cflineno, module_name, lt_dlerror());
+                      " %s\n", cffilename, cflineno, module_name, lt_dlerror());
                return NULL;
        }
 
-       /* make room for the module type */
-       node = rad_malloc(sizeof(*node));
-       memset(node, 0, sizeof(*node));
-
-       /* fill in the module structure */
-       node->handle = handle;
-       strNcpy(node->name, module_name, sizeof(node->name));
-
        /*
         *      Link to the module's rlm_FOO{} module structure.
         *
@@ -198,26 +189,38 @@ static module_entry_t *linkto_module(CONF_SECTION *modules,
        p = strrchr(module_struct, '-');
        if (p) *p = '\0';
 
-       node->module = (module_t *) lt_dlsym(node->handle, module_struct);
-       if (!node->module) {
+       DEBUG3("    (Loaded %s, checking if it's valid)", module_name);
+
+       /*
+        *      libltld MAY core here, if the handle it gives us contains
+        *      garbage data.
+        */
+       module = lt_dlsym(handle, module_struct);
+       if (!module) {
                radlog(L_ERR|L_CONS, "%s[%d] Failed linking to "
                                "%s structure in %s: %s\n",
                                cffilename, cflineno,
                                module_name, cffilename, lt_dlerror());
-               lt_dlclose(node->handle);       /* ignore any errors */
-               free(node);
+               lt_dlclose(handle);
                return NULL;
        }
-
-       /* call the modules initialization */
-       if (node->module->init && (node->module->init)() < 0) {
-               radlog(L_ERR|L_CONS, "%s[%d] Module initialization failed.\n",
-                               cffilename, cflineno);
-               lt_dlclose(node->handle);       /* ignore any errors */
-               free(node);
+       /*
+        *      Before doing anything else, check if it's sane.
+        */
+       if ((*(uint32_t *) module) != RLM_MODULE_MAGIC_NUMBER) {
+               lt_dlclose(handle);
+               DEBUG2("%08x %08x\n", (*(uint32_t *) handle), RLM_MODULE_MAGIC_NUMBER);
+               radlog(L_ERR|L_CONS, "%s[%d] Invalid version in module '%s'",
+                      cffilename, cflineno, module_name);
                return NULL;
+               
        }
 
+       /* make room for the module type */
+       node = rad_malloc(sizeof(*node));
+       memset(node, 0, sizeof(*node));
+       node->module = module;
+
        DEBUG("Module: Loaded %s ", node->module->name);
 
        /*
index 666bfb1..7106ab4 100644 (file)
@@ -233,10 +233,11 @@ static int add_unique_id(void *instance, REQUEST *request)
 
 /* globally exported name */
 module_t rlm_acct_unique = {
+       RLM_MODULE_INIT,
        "Acct-Unique-Session-Id",
        0,                              /* type: reserved */
-       NULL,                           /* initialization */
        unique_instantiate,             /* instantiation */
+       unique_detach,          /* detach */
        {
                NULL,                   /* authentication */
                add_unique_id,  /* authorization */
@@ -247,6 +248,4 @@ module_t rlm_acct_unique = {
                NULL,                   /* post-proxy */
                NULL                    /* post-auth */
        },
-       unique_detach,          /* detach */
-       NULL,                           /* destroy */
 };
index 00cd263..370f7d4 100644 (file)
@@ -160,10 +160,11 @@ static int always_detach(void *instance)
 }
 
 module_t rlm_always = {
+       RLM_MODULE_INIT,
        "always",
        RLM_TYPE_THREAD_SAFE,           /* type */
-       NULL,                           /* initialization */
        always_instantiate,             /* instantiation */
+       always_detach,                  /* detach */
        {
                always_return,          /* authentication */
                always_return,          /* authorization */
@@ -174,6 +175,4 @@ module_t rlm_always = {
                always_return,          /* post-proxy */
                always_return           /* post-auth */
        },
-       always_detach,                  /* detach */
-       NULL,                           /* destroy */
 };
index 3555647..e677458 100644 (file)
@@ -656,10 +656,11 @@ static int attr_filter_detach(void *instance)
 
 /* globally exported name */
 module_t rlm_attr_filter = {
+       RLM_MODULE_INIT,
        "attr_filter",
        0,                              /* type: reserved */
-       NULL,                           /* initialization */
        attr_filter_instantiate,        /* instantiation */
+       attr_filter_detach,             /* detach */
        {
                NULL,                   /* authentication */
                NULL,                   /* authorization */
@@ -670,7 +671,5 @@ module_t rlm_attr_filter = {
                attr_filter_postproxy,  /* post-proxy */
                NULL                    /* post-auth */
        },
-       attr_filter_detach,             /* detach */
-       NULL                            /* destroy */
 };
 
index ca06e50..d3ae017 100644 (file)
@@ -76,7 +76,7 @@ static int attr_rewrite_instantiate(CONF_SECTION *conf, void **instance)
 {
        rlm_attr_rewrite_t *data;
        DICT_ATTR *dattr;
-       char *instance_name = NULL;
+       const char *instance_name = NULL;
 
        /*
         *      Set up a storage area for instance data
@@ -478,10 +478,11 @@ static int attr_rewrite_detach(void *instance)
  *     is single-threaded.
  */
 module_t rlm_attr_rewrite = {
+       RLM_MODULE_INIT,
        "attr_rewrite",
        RLM_TYPE_THREAD_UNSAFE,         /* type */
-       NULL,                           /* initialization */
        attr_rewrite_instantiate,               /* instantiation */
+       attr_rewrite_detach,                    /* detach */
        {
                attr_rewrite_authenticate,      /* authentication */
                attr_rewrite_authorize,         /* authorization */
@@ -492,6 +493,4 @@ module_t rlm_attr_rewrite = {
                attr_rewrite_postproxy,         /* post-proxy */
                attr_rewrite_postauth           /* post-auth */
        },
-       attr_rewrite_detach,                    /* detach */
-       NULL,                           /* destroy */
 };
index b011941..8ec269d 100644 (file)
@@ -500,10 +500,11 @@ static int caching_detach(void *instance)
  *     is single-threaded.
  */
 module_t rlm_caching = {
+       RLM_MODULE_INIT,
        "Caching",
        RLM_TYPE_THREAD_SAFE,           /* type */
-       NULL,                           /* initialization */
        caching_instantiate,            /* instantiation */
+       caching_detach,                 /* detach */
        {
                NULL,                   /* authentication */
                caching_authorize,      /* authorization */
@@ -514,6 +515,4 @@ module_t rlm_caching = {
                NULL,                   /* post-proxy */
                caching_postauth        /* post-auth */
        },
-       caching_detach,                 /* detach */
-       NULL,                           /* destroy */
 };
index a459584..e57a9c0 100644 (file)
@@ -140,10 +140,11 @@ static int chap_authenticate(void *instance, REQUEST *request)
  *     is single-threaded.
  */
 module_t rlm_chap = {
+        RLM_MODULE_INIT,
        "CHAP",
        0,                              /* type */
-       NULL,                           /* initialization */
        NULL,                           /* instantiation */
+       NULL,                           /* detach */
        {
                chap_authenticate,      /* authentication */
                chap_authorize,         /* authorization */
@@ -154,6 +155,4 @@ module_t rlm_chap = {
                NULL,                   /* post-proxy */
                NULL                    /* post-auth */
        },
-       NULL,                           /* detach */
-       NULL,                           /* destroy */
 };
index 95ee380..e82abf6 100644 (file)
@@ -335,10 +335,11 @@ static int checkval_accounting(void *instance, REQUEST *request)
  *     is single-threaded.
  */
 module_t rlm_checkval = {
+        RLM_MODULE_INIT,
        "checkval",
        0,              /* type */
-       NULL,                           /* initialization */
        checkval_instantiate,           /* instantiation */
+       checkval_detach,                /* detach */
        {
                NULL,                   /* authentication */
                checkval_authorize,     /* authorization */
@@ -349,6 +350,4 @@ module_t rlm_checkval = {
                NULL,                   /* post-proxy */
                NULL                    /* post-auth */
        },
-       checkval_detach,                /* detach */
-       NULL,                           /* destroy */
 };
index 2d9b6df..a78a896 100644 (file)
@@ -131,10 +131,11 @@ static int packet_authorize(void *instance, REQUEST *request)
  *     is single-threaded.
  */
 module_t rlm_copy_packet = {
+        RLM_MODULE_INIT,
        "copy_packet",
        RLM_TYPE_THREAD_SAFE,           /* type */
-       NULL,                           /* initialization */
        packet_instantiate,             /* instantiation */
+       packet_detach,                  /* detach */
        {
                NULL,                   /* authentication */
                packet_authorize,       /* authorization */
@@ -145,6 +146,4 @@ module_t rlm_copy_packet = {
                NULL,                   /* post-proxy */
                NULL                    /* post-auth */
        },
-       packet_detach,                  /* detach */
-       NULL,                           /* destroy */
 };
index a45c0b6..085f66f 100644 (file)
@@ -938,10 +938,11 @@ static int counter_detach(void *instance)
  *     is single-threaded.
  */
 module_t rlm_counter = {
-       "Counter",
+        RLM_MODULE_INIT,
+       "counter",
        RLM_TYPE_THREAD_SAFE,           /* type */
-       NULL,                           /* initialization */
        counter_instantiate,            /* instantiation */
+       counter_detach,                 /* detach */
        {
                NULL,                   /* authentication */
                counter_authorize,      /* authorization */
@@ -952,6 +953,4 @@ module_t rlm_counter = {
                NULL,                   /* post-proxy */
                NULL                    /* post-auth */
        },
-       counter_detach,                 /* detach */
-       NULL,                           /* destroy */
 };
index 8483850..58dd55c 100644 (file)
@@ -198,20 +198,19 @@ static int cram_authenticate(void * instance, REQUEST *request)
 }
 
 module_t rlm_cram = {
-  "CRAM",
-  RLM_TYPE_THREAD_SAFE,                                /* type */
-  NULL,                                /* initialize */
-  NULL,                /* instantiation */
-  {
-         cram_authenticate,    /* authenticate */
-         NULL,                 /* authorize */
-         NULL,                 /* pre-accounting */
-         NULL,                 /* accounting */
-         NULL,                 /* checksimul */
-         NULL,                 /* pre-proxy */
-         NULL,                 /* post-proxy */
-         NULL                  /* post-auth */
-  },
-  NULL,                                /* detach */
-  NULL,                                /* destroy */
+       RLM_MODULE_INIT,
+       "CRAM",
+       RLM_TYPE_THREAD_SAFE,           /* type */
+       NULL,                           /* instantiation */
+       NULL,                           /* detach */
+       {
+               cram_authenticate,      /* authenticate */
+               NULL,                   /* authorize */
+               NULL,                   /* pre-accounting */
+               NULL,                   /* accounting */
+               NULL,                   /* checksimul */
+               NULL,                   /* pre-proxy */
+               NULL,                   /* post-proxy */
+               NULL                    /* post-auth */
+       },
 };
index c4eb2ce..c1f5a19 100644 (file)
@@ -369,10 +369,11 @@ static int rlm_dbm_detach(void *instance)
 
 /* globally exported name */
 module_t rlm_dbm = {
+       RLM_MODULE_INIT,
         "dbm",
         0,                              /* type: reserved */
-        NULL,                           /* initialization */
         rlm_dbm_instantiate,            /* instantiation */
+        rlm_dbm_detach,                 /* detach */
         {
                 NULL,                   /* authentication */
                 rlm_dbm_authorize,      /* authorization */
@@ -383,6 +384,4 @@ module_t rlm_dbm = {
                 NULL,                  /* post-proxy */
                 NULL                   /* post-auth */
        },
-        rlm_dbm_detach,                 /* detach */
-       NULL                            /* destroy */
 };
index 03677d3..c221b6f 100644 (file)
@@ -175,15 +175,7 @@ static int do_detail(void *instance, REQUEST *request, RADIUS_PACKET *packet,
                 */
                if ((inst->last_made_directory == NULL) ||
                    (strcmp(inst->last_made_directory, buffer) != 0)) {
-
-                       /*
-                        *      Free any previously cached name.
-                        */
-                       if (inst->last_made_directory != NULL) {
-                               free((char *) inst->last_made_directory);
-                               inst->last_made_directory = NULL;
-                       }
-
+                       free((char *) inst->last_made_directory);
                        inst->last_made_directory = strdup(buffer);
                }
 
@@ -441,10 +433,11 @@ static int detail_detach(void *instance)
 
 /* globally exported name */
 module_t rlm_detail = {
+       RLM_MODULE_INIT,
        "detail",
        RLM_TYPE_THREAD_UNSAFE,        /* type: reserved */
-       NULL,                           /* initialization */
        detail_instantiate,             /* instantiation */
+       detail_detach,                  /* detach */
        {
                NULL,                   /* authentication */
                detail_authorize,       /* authorization */
@@ -455,7 +448,5 @@ module_t rlm_detail = {
                detail_post_proxy,      /* post-proxy */
                detail_postauth         /* post-auth */
        },
-       detail_detach,                  /* detach */
-       NULL                            /* destroy */
 };
 
index cac36cf..2dac0a0 100644 (file)
@@ -188,6 +188,8 @@ static int digest_authenticate(void *instance, REQUEST *request)
        VALUE_PAIR *vp;
        VALUE_PAIR *qop, *nonce;
 
+       instance = instance;    /* -Wunused */
+
        /*
         *      We require access to the plain-text password.
         */
@@ -487,10 +489,11 @@ static int digest_authenticate(void *instance, REQUEST *request)
  *     is single-threaded.
  */
 module_t rlm_digest = {
-       "DIGEST",
+       RLM_MODULE_INIT,
+       "digest",
        0,                              /* type */
-       NULL,                           /* initialization */
        NULL,                           /* instantiation */
+       NULL,                           /* detach */
        {
                digest_authenticate,    /* authentication */
                digest_authorize,       /* authorization */
@@ -501,6 +504,4 @@ module_t rlm_digest = {
                NULL,                   /* post-proxy */
                NULL                    /* post-auth */
        },
-       NULL,                           /* detach */
-       NULL,                           /* destroy */
 };
index f845ddf..667e80f 100644 (file)
@@ -41,12 +41,6 @@ static const CONF_PARSER module_config[] = {
        { NULL, -1, 0, NULL, NULL }           /* end the list */
 };
 
-static int eap_init(void)
-{
-       return 0;
-}
-
-
 /*
  * delete all the allocated space by eap module
  */
@@ -654,10 +648,11 @@ static int eap_post_proxy(void *inst, REQUEST *request)
  *     That is, everything else should be 'static'.
  */
 module_t rlm_eap = {
+       RLM_MODULE_INIT,
        "eap",
        RLM_TYPE_THREAD_SAFE,           /* type */
-       eap_init,                       /* initialization */
        eap_instantiate,                /* instantiation */
+       eap_detach,                     /* detach */
        {
                eap_authenticate,       /* authentication */
                eap_authorize,          /* authorization */
@@ -668,6 +663,4 @@ module_t rlm_eap = {
                eap_post_proxy,         /* post-proxy */
                NULL                    /* post-auth */
        },
-       eap_detach,                     /* detach */
-       NULL,                           /* destroy */
 };
index eb91c3a..839d23c 100644 (file)
@@ -64,21 +64,6 @@ static const CONF_PARSER module_config[] = {
   { NULL, -1, 0, NULL, NULL }          /* end the list */
 };
 
-/*
- *     Do any per-module initialization.  e.g. set up connections
- *     to external databases, read configuration files, set up
- *     dictionary entries, etc.
- *
- *     Try to avoid putting too much stuff in here - it's better to
- *     do it in instantiate() where it is not global.
- */
-static int example_init(void)
-{
-       /*
-        *      Everything's OK, return without an error.
-        */
-       return 0;
-}
 
 /*
  *     Do any per-module initialization that is separate to each
@@ -232,10 +217,11 @@ static int example_detach(void *instance)
  *     is single-threaded.
  */
 module_t rlm_example = {
+       RLM_MODULE_INIT,
        "example",
        RLM_TYPE_THREAD_SAFE,           /* type */
-       example_init,                   /* initialization */
        example_instantiate,            /* instantiation */
+       example_detach,                 /* detach */
        {
                example_authenticate,   /* authentication */
                example_authorize,      /* authorization */
@@ -246,6 +232,4 @@ module_t rlm_example = {
                NULL,                   /* post-proxy */
                NULL                    /* post-auth */
        },
-       example_detach,                 /* detach */
-       NULL,                           /* destroy */
 };
index 8e88c0d..07cfffa 100644 (file)
@@ -190,7 +190,7 @@ static int exec_detach(void *instance)
 static int exec_instantiate(CONF_SECTION *conf, void **instance)
 {
        rlm_exec_t      *inst;
-       char            *xlat_name;
+       const char      *xlat_name;
 
        /*
         *      Set up a storage area for instance data
@@ -237,7 +237,7 @@ static int exec_instantiate(CONF_SECTION *conf, void **instance)
         */
        if (inst->wait &&
            (inst->output == NULL)) {
-               radlog(L_INFO, "rlm_exec: Wait=yes but no output defined. Did you mean output=none?");
+               radlog(L_INFO, "rlm_exec: wait=yes but no output defined. Did you mean output=none?");
        }
 
        /*
@@ -368,10 +368,11 @@ static int exec_dispatch(void *instance, REQUEST *request)
  *     is single-threaded.
  */
 module_t rlm_exec = {
+       RLM_MODULE_INIT,
        "exec",                         /* Name */
        RLM_TYPE_THREAD_SAFE,           /* type */
-       NULL,                           /* initialization */
        exec_instantiate,               /* instantiation */
+       exec_detach,                    /* detach */
        {
                exec_dispatch,          /* authentication */
                exec_dispatch,          /* authorization */
@@ -382,6 +383,4 @@ module_t rlm_exec = {
                exec_dispatch,          /* post-proxy */
                exec_dispatch           /* post-auth */
        },
-       exec_detach,                    /* detach */
-       NULL,                           /* destroy */
 };
index be952b5..7d35011 100644 (file)
@@ -219,10 +219,11 @@ static int expiration_instantiate(CONF_SECTION *conf, void **instance)
  *     is single-threaded.
  */
 module_t rlm_expiration = {
-       "Expiration",
+       RLM_MODULE_INIT,
+       "expiration",
        RLM_TYPE_THREAD_SAFE,           /* type */
-       NULL,                           /* initialization */
        expiration_instantiate,         /* instantiation */
+       expiration_detach,              /* detach */
        {
                NULL,                   /* authentication */
                expiration_authorize,   /* authorization */
@@ -233,6 +234,4 @@ module_t rlm_expiration = {
                NULL,                   /* post-proxy */
                NULL                    /* post-auth */
        },
-       expiration_detach,              /* detach */
-       NULL,                           /* destroy */
 };
index d9ff01f..1b3487b 100644 (file)
@@ -312,16 +312,15 @@ static int expr_detach(void *instance)
  *     is single-threaded.
  */
 module_t rlm_expr = {
+       RLM_MODULE_INIT,
        "expr",                         /* Name */
        RLM_TYPE_THREAD_SAFE,           /* type */
-       NULL,                           /* initialization */
        expr_instantiate,               /* instantiation */
+       expr_detach,                    /* detach */
        {
                NULL,                   /* authentication */
                NULL,                   /* authorization */
                NULL,                   /* pre-accounting */
                NULL                    /* accounting */
        },
-       expr_detach,                    /* detach */
-       NULL,                           /* destroy */
 };
index 96203b9..a3cd789 100644 (file)
@@ -788,10 +788,11 @@ static int fastuser_accounting(void *instance UNUSED, REQUEST *request UNUSED)
 
 /* globally exported name */
 module_t rlm_fastusers = {
+       RLM_MODULE_INIT,
        "fastusers",
        0,                              /* type: reserved */
-       NULL,                           /* initialization */
        fastuser_instantiate,           /* instantiation */
+       fastuser_detach,                /* detach */
        {
                fastuser_authenticate,  /* authentication */
                fastuser_authorize,     /* authorization */
@@ -802,7 +803,5 @@ module_t rlm_fastusers = {
                NULL,                   /* post-proxy */
                NULL                    /* post-auth */
        },
-       fastuser_detach,                /* detach */
-       NULL                            /* destroy */
 };
 
index 3c7b7ba..5861b21 100644 (file)
@@ -286,7 +286,6 @@ static int file_authorize(void *instance, REQUEST *request)
        const char      *name;
        struct file_instance *inst = instance;
        VALUE_PAIR **check_pairs, **reply_pairs;
-       VALUE_PAIR *check_save;
 
        request_pairs = request->packet->vps;
        check_pairs = &request->config_items;
@@ -519,10 +518,11 @@ static int file_detach(void *instance)
 
 /* globally exported name */
 module_t rlm_files = {
+       RLM_MODULE_INIT,
        "files",
        0,                              /* type: reserved */
-       NULL,                           /* initialization */
        file_instantiate,               /* instantiation */
+       file_detach,                    /* detach */
        {
                NULL,                   /* authentication */
                file_authorize,         /* authorization */
@@ -533,7 +533,5 @@ module_t rlm_files = {
                NULL,                   /* post-proxy */
                NULL                    /* post-auth */
        },
-       file_detach,                    /* detach */
-       NULL                            /* destroy */
 };
 
index 6c6da88..6496f7d 100644 (file)
@@ -853,10 +853,11 @@ static int ippool_detach(void *instance)
  *     is single-threaded.
  */
 module_t rlm_ippool = {
-       "IPPOOL",
+       RLM_MODULE_INIT,
+       "ippool",
        RLM_TYPE_THREAD_SAFE,           /* type */
-       NULL,                           /* initialization */
        ippool_instantiate,             /* instantiation */
+       ippool_detach,                  /* detach */
        {
                NULL,                   /* authentication */
                NULL,                   /* authorization */
@@ -867,6 +868,4 @@ module_t rlm_ippool = {
                NULL,                   /* post-proxy */
                ippool_postauth         /* post-auth */
        },
-       ippool_detach,                  /* detach */
-       NULL,                           /* destroy */
 };
index 4c8d42c..164bc8e 100644 (file)
@@ -399,20 +399,19 @@ static int krb5_auth(void *instance, REQUEST *request)
 #endif /* HEIMDAL_KRB5 */
 
 module_t rlm_krb5 = {
-  "Kerberos",
-  RLM_TYPE_THREAD_UNSAFE,      /* type: not thread safe */
-  NULL,                                /* initialize */
-  krb5_instantiate,            /* instantiation */
-  {
-         krb5_auth,            /* authenticate */
-         NULL,                 /* authorize */
-         NULL,                 /* pre-accounting */
-         NULL,                 /* accounting */
-         NULL,                 /* checksimul */
-         NULL,                 /* pre-proxy */
-         NULL,                 /* post-proxy */
-         NULL                  /* post-auth */
-  },
-  krb5_detach,                 /* detach */
-  NULL,                                /* destroy */
+       RLM_MODULE_INIT,
+       "Kerberos",
+       RLM_TYPE_THREAD_UNSAFE, /* type: not thread safe */
+       krb5_instantiate,               /* instantiation */
+       krb5_detach,                    /* detach */
+       {
+               krb5_auth,              /* authenticate */
+               NULL,                   /* authorize */
+               NULL,                   /* pre-accounting */
+               NULL,                   /* accounting */
+               NULL,                   /* checksimul */
+               NULL,                   /* pre-proxy */
+               NULL,                   /* post-proxy */
+               NULL                    /* post-auth */
+       },
 };
index 31d1a88..d7832d8 100644 (file)
@@ -2457,10 +2457,11 @@ static VALUE_PAIR *ldap_pairget(LDAP *ld, LDAPMessage *entry,
 
 /* globally exported name */
 module_t rlm_ldap = {
+       RLM_MODULE_INIT,
        "LDAP",
        RLM_TYPE_THREAD_SAFE,   /* type: reserved        */
-       NULL,                   /* initialization        */
        ldap_instantiate,       /* instantiation         */
+       ldap_detach,            /* detach                */
        {
                ldap_authenticate,      /* authentication        */
                ldap_authorize,         /* authorization         */
@@ -2475,6 +2476,4 @@ module_t rlm_ldap = {
                NULL
 #endif
        },
-       ldap_detach,            /* detach                */
-       NULL,                   /* destroy               */
 };
index c8b8ff7..3840259 100755 (executable)
@@ -147,10 +147,11 @@ static int do_linelog(rlm_linelog_t *inst, REQUEST *request)
  *     Externally visible module definition.
  */
 module_t rlm_linelog = {
+       RLM_MODULE_INIT,
        "example",
        RLM_TYPE_THREAD_SAFE,           /* type */
-       NULL,                           /* initialization */
        linelog_instantiate,            /* instantiation */
+       linelog_detach,                 /* detach */
        {
                do_linelog,     /* authentication */
                do_linelog,     /* authorization */
@@ -161,6 +162,4 @@ module_t rlm_linelog = {
                do_linelog,     /* post-proxy */
                do_linelog      /* post-auth */
        },
-       linelog_detach,                 /* detach */
-       NULL,                           /* destroy */
 };
index 7314bee..c5e10f9 100644 (file)
@@ -328,10 +328,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 */
@@ -342,6 +343,4 @@ module_t rlm_logintime = {
                NULL,                   /* post-proxy */
                NULL                    /* post-auth */
        },
-       logintime_detach,               /* detach */
-       NULL,                           /* destroy */
 };
index f40fd25..aefb807 100644 (file)
@@ -1317,20 +1317,19 @@ static int mschap_authenticate(void * instance, REQUEST *request)
 }
 
 module_t rlm_mschap = {
-  "MS-CHAP",
-  RLM_TYPE_THREAD_SAFE,                /* type */
-  NULL,                                /* initialize */
-  mschap_instantiate,          /* instantiation */
-  {
-         mschap_authenticate,  /* authenticate */
-         mschap_authorize,     /* authorize */
-         NULL,                 /* pre-accounting */
-         NULL,                 /* accounting */
-         NULL,                 /* checksimul */
-         NULL,                 /* pre-proxy */
-         NULL,                 /* post-proxy */
-         NULL                  /* post-auth */
-  },
-  mschap_detach,               /* detach */
-  NULL,                                /* destroy */
+       RLM_MODULE_INIT,
+       "MS-CHAP",
+       RLM_TYPE_THREAD_SAFE,           /* type */
+       mschap_instantiate,             /* instantiation */
+       mschap_detach,          /* detach */
+       {
+               mschap_authenticate,    /* authenticate */
+               mschap_authorize,       /* authorize */
+               NULL,                   /* pre-accounting */
+               NULL,                   /* accounting */
+               NULL,                   /* checksimul */
+               NULL,                   /* pre-proxy */
+               NULL,                   /* post-proxy */
+               NULL                    /* post-auth */
+       },
 };
index a4d7146..ad4e1fe 100644 (file)
@@ -573,6 +573,7 @@ otp_destroy(void)
  *     is single-threaded.
  */
 module_t rlm_otp = {
+       RLM_MODULE_INIT,
        "otp",
        RLM_TYPE_THREAD_SAFE,           /* type */
        otp_init,                       /* initialization */
index 9b1f75a..342d3d7 100644 (file)
@@ -286,21 +286,20 @@ static int pam_auth(void *instance, REQUEST *request)
 }
 
 module_t rlm_pam = {
-  "Pam",
-  RLM_TYPE_THREAD_UNSAFE,      /* The PAM libraries are not thread-safe */
-  NULL,                                /* initialize */
-  pam_instantiate,             /* instantiation */
-  {
-         pam_auth,             /* authenticate */
-         NULL,                 /* authorize */
-         NULL,                 /* pre-accounting */
-         NULL,                 /* accounting */
-         NULL,                 /* checksimul */
-         NULL,                 /* pre-proxy */
-         NULL,                 /* post-proxy */
-         NULL                  /* post-auth */
-  },
-  pam_detach,                  /* detach */
-  NULL,                                /* destroy */
+       RLM_MODULE_INIT,
+       "pam",
+       RLM_TYPE_THREAD_UNSAFE, /* The PAM libraries are not thread-safe */
+       pam_instantiate,                /* instantiation */     
+       pam_detach,                     /* detach */
+       {
+               pam_auth,               /* authenticate */
+               NULL,                   /* authorize */
+               NULL,                   /* pre-accounting */
+               NULL,                   /* accounting */
+               NULL,                   /* checksimul */
+               NULL,                   /* pre-proxy */
+               NULL,                   /* post-proxy */
+               NULL                    /* post-auth */
+       },
 };
 
index 36b22d6..58ef2bb 100644 (file)
@@ -779,10 +779,11 @@ static int pap_authenticate(void *instance, REQUEST *request)
  *     is single-threaded.
  */
 module_t rlm_pap = {
+       RLM_MODULE_INIT,
        "PAP",
        0,                              /* type */
-       NULL,                           /* initialization */
        pap_instantiate,                /* instantiation */
+       pap_detach,                     /* detach */
        {
                pap_authenticate,       /* authentication */
                pap_authorize,          /* authorization */
@@ -793,6 +794,4 @@ module_t rlm_pap = {
                NULL,                   /* post-proxy */
                NULL                    /* post-auth */
        },
-       pap_detach,                     /* detach */
-       NULL,                           /* destroy */
 };
index 7a2307c..4df5c27 100644 (file)
@@ -547,10 +547,11 @@ static int passwd_authorize(void *instance, REQUEST *request)
 }
 
 module_t rlm_passwd = {
+       RLM_MODULE_INIT,
        "passwd",
        RLM_TYPE_THREAD_SAFE,           /* type */
-       NULL,                           /* initialize */
        passwd_instantiate,             /* instantiation */
+       passwd_detach,                  /* detach */
        {
                NULL,                   /* authentication */
                passwd_authorize,       /* authorization */
@@ -561,7 +562,5 @@ module_t rlm_passwd = {
                NULL,                   /* post-proxy */
                NULL                    /* post-auth */
        },
-       passwd_detach,                  /* detach */
-       NULL                            /* destroy */
 };
 #endif /* TEST */
index eba0a30..4024255 100644 (file)
@@ -165,7 +165,7 @@ EXTERN_C void boot_DynaLoader(pTHX_ CV* cv);
  *     We clone it for every instance if we have perl
  *     with -Duseithreads compiled in
  */
-static PerlInterpreter *interp;
+static PerlInterpreter *interp = NULL;
 
 static const CONF_PARSER pool_conf[] = {
        { "max_clones", PW_TYPE_INTEGER, offsetof(PERL_POOL, max_clones), NULL,         "32"},
@@ -549,6 +549,18 @@ static int init_pool (CONF_SECTION *conf, PERL_INST *inst) {
        int t;
        PERL_POOL       *pool;
 
+       if (!interp) {
+#ifdef USE_ITHREADS
+               if ((interp = perl_alloc()) == NULL) {
+                       radlog(L_DBG, "rlm_perl: No memory for allocating new perl !");
+                       return -1;
+               }
+               
+               perl_construct(interp);
+               PL_perl_destruct_level = 2;
+#endif
+       }
+
        pool = rad_malloc(sizeof(PERL_POOL));
        memset(pool,0,sizeof(PERL_POOL));
 
@@ -587,15 +599,6 @@ static int init_pool (CONF_SECTION *conf, PERL_INST *inst) {
  */
 static int perl_init(void)
 {
-#ifdef USE_ITHREADS
-       if ((interp = perl_alloc()) == NULL) {
-               radlog(L_DBG, "rlm_perl: No memory for allocating new perl !");
-               return -1;
-       }
-
-       perl_construct(interp);
-       PL_perl_destruct_level = 2;
-#endif
        return 0;
 
 }
@@ -1295,14 +1298,15 @@ static int perl_detach(void *instance)
  *     is single-threaded.
  */
 module_t rlm_perl = {
+       RLM_MODULE_INIT,
        "perl",                         /* Name */
 #ifdef USE_ITHREADS
        RLM_TYPE_THREAD_SAFE,           /* type */
 #else
        RLM_TYPE_THREAD_UNSAFE,
 #endif
-       perl_init,                      /* initialization */
        perl_instantiate,               /* instantiation */
+       perl_detach,                    /* detach */
        {
                perl_authenticate,
                perl_authorize,
@@ -1313,6 +1317,4 @@ module_t rlm_perl = {
                perl_post_proxy,        /* post-proxy */
                perl_post_auth    /* post-auth */
        },
-       perl_detach,                    /* detach */
-       NULL,                           /* destroy */
 };
index b7642fc..658b817 100644 (file)
@@ -309,10 +309,11 @@ void rlm_policy_free_item(policy_item_t *item)
  *     is single-threaded.
  */
 module_t rlm_policy = {
+       RLM_MODULE_INIT,
        "policy",
        RLM_TYPE_THREAD_SAFE,           /* type */
-       NULL,                           /* initialization */
        policy_instantiate,             /* instantiation */
+       policy_detach,                  /* detach */
        {
                NULL,                   /* authentication */
                policy_authorize,       /* authorization */
@@ -323,6 +324,4 @@ module_t rlm_policy = {
                policy_post_proxy,      /* post-proxy */
                policy_post_auth        /* post-auth */
        },
-       policy_detach,                  /* detach */
-       NULL,                           /* destroy */
 };
index bc94ce8..f5e58ee 100644 (file)
@@ -624,11 +624,12 @@ static int preprocess_detach(void *instance)
 }
 
 /* globally exported name */
-module_t rlm_preprocess = {
+module_t rlm_preprocess = {    
+       RLM_MODULE_INIT,
        "preprocess",
        0,                      /* type: reserved */
-       NULL,                   /* initialization */
        preprocess_instantiate, /* instantiation */
+       preprocess_detach,      /* detach */
        {
                NULL,                   /* authentication */
                preprocess_authorize,   /* authorization */
@@ -639,7 +640,5 @@ module_t rlm_preprocess = {
                NULL,                   /* post-proxy */
                NULL                    /* post-auth */
        },
-       preprocess_detach,      /* detach */
-       NULL,                   /* destroy */
 };
 
index 1122b1f..96c295e 100755 (executable)
@@ -281,10 +281,11 @@ static int filter_authorize(void *instance, REQUEST *request)
  *     is single-threaded.
  */
 module_t rlm_protocol_filter = {
+       RLM_MODULE_INIT,
        "protocol_filter",
        RLM_TYPE_THREAD_SAFE,           /* type */
-       NULL,                           /* initialization */
        filter_instantiate,             /* instantiation */
+       filter_detach,                  /* detach */
        {
                NULL,                   /* authentication */
                filter_authorize,       /* authorization */
@@ -295,6 +296,4 @@ module_t rlm_protocol_filter = {
                NULL,                   /* post-proxy */
                NULL                    /* post-auth */
        },
-       filter_detach,                  /* detach */
-       NULL,                           /* destroy */
 };
index 29cd4c2..96a6d5a 100644 (file)
@@ -162,25 +162,6 @@ static PyMethodDef radiusd_methods[] = {
     {NULL, NULL, 0, NULL}
 };
 
-/*
- *     Do any per-module initialization.  e.g. set up connections
- *     to external databases, read configuration files, set up
- *     dictionary entries, etc.
- *
- *     Try to avoid putting too much stuff in here - it's better to
- *     do it in instantiate() where it is not global.
- */
-static int python_init(void)
-{
-    /*
-     * Initialize Python interpreter. Fatal error if this fails.
-     */
-    Py_Initialize();
-
-    radlog(L_DBG, "python_init done");
-
-    return 0;
-}
 
 /* Extract string representation of Python error. */
 static void python_error(void) {
@@ -574,8 +555,13 @@ static int python_instantiate(CONF_SECTION *conf, void **instance)
     int idx;
 
     /*
-        *      Set up a storage area for instance data
-        */
+     * Initialize Python interpreter. Fatal error if this fails.
+     */
+    Py_Initialize();
+
+    /*
+     * Set up a storage area for instance data
+     */
     data = rad_malloc(sizeof(*data));
     if (!data) {
       return -1;
@@ -770,10 +756,11 @@ static int python_detach(void *instance)
  *     is single-threaded.
  */
 module_t rlm_python = {
+       RLM_MODULE_INIT,
        "python",
        RLM_TYPE_THREAD_SAFE,           /* type */
-       python_init,                    /* initialization */
        python_instantiate,             /* instantiation */
+       python_detach,                  /* detach */
        {
                python_authenticate,    /* authentication */
                python_authorize,       /* authorization */
@@ -784,6 +771,4 @@ module_t rlm_python = {
                NULL,                   /* post-proxy */
                NULL                    /* post-auth */
        },
-       python_detach,                  /* detach */
-       NULL,                           /* destroy */
 };
index e545b41..70abe2d 100644 (file)
@@ -755,21 +755,20 @@ static int radutmp_checksimul(void *instance, REQUEST *request)
 
 /* globally exported name */
 module_t rlm_radutmp = {
-  "radutmp",
-  0,                            /* type: reserved */
-  NULL,                        /* initialization */
-  radutmp_instantiate,          /* instantiation */
-  {
-         NULL,                 /* authentication */
-         NULL,                 /* authorization */
-         NULL,                 /* preaccounting */
-         radutmp_accounting,   /* accounting */
-         radutmp_checksimul,   /* checksimul */
-         NULL,                 /* pre-proxy */
-         NULL,                 /* post-proxy */
-         NULL                  /* post-auth */
-  },
-  radutmp_detach,               /* detach */
-  NULL,                        /* destroy */
+       RLM_MODULE_INIT,
+       "radutmp",
+       0,                            /* type: reserved */
+       radutmp_instantiate,          /* instantiation */
+       radutmp_detach,               /* detach */
+       {
+               NULL,                 /* authentication */
+               NULL,                 /* authorization */
+               NULL,                 /* preaccounting */
+               radutmp_accounting,   /* accounting */
+               radutmp_checksimul,     /* checksimul */
+               NULL,                   /* pre-proxy */
+               NULL,                   /* post-proxy */
+               NULL                    /* post-auth */
+       },
 };
 
index 9957908..a595346 100644 (file)
@@ -440,20 +440,19 @@ static int realm_detach(void *instance)
 
 /* globally exported name */
 module_t rlm_realm = {
-  "realm",
-  0,                           /* type: reserved */
-  NULL,                                /* initialization */
-  realm_instantiate,           /* instantiation */
-  {
-         NULL,                 /* authentication */
-         realm_authorize,      /* authorization */
-         realm_preacct,        /* preaccounting */
-         NULL,                 /* accounting */
-         NULL,                 /* checksimul */
-         NULL,                 /* pre-proxy */
-         NULL,                 /* post-proxy */
-         NULL                  /* post-auth */
-  },
-  realm_detach,                        /* detach */
-  NULL,                                /* destroy */
+       RLM_MODULE_INIT,
+       "realm",
+       0,                              /* type: reserved */
+       realm_instantiate,              /* instantiation */
+       realm_detach,                   /* detach */
+       {
+               NULL,                   /* authentication */
+               realm_authorize,        /* authorization */
+               realm_preacct,  /* preaccounting */
+               NULL,                   /* accounting */
+               NULL,                   /* checksimul */
+               NULL,                   /* pre-proxy */
+               NULL,                   /* post-proxy */
+               NULL                    /* post-auth */
+       },
 };
index d5da7b1..6eacfde 100644 (file)
@@ -274,10 +274,11 @@ static int sim_file_detach(void *instance)
 
 /* globally exported name */
 module_t rlm_sim_files = {
+       RLM_MODULE_INIT,
        "sim_files",
        0,                              /* type: reserved */
-       NULL,                           /* initialization */
        sim_file_instantiate,           /* instantiation */
+       sim_file_detach,                /* detach */
        {
                NULL,                   /* authentication */
                sim_file_authorize,     /* authorization */
@@ -288,7 +289,5 @@ module_t rlm_sim_files = {
                NULL,                   /* post-proxy */
                NULL                    /* post-auth */
        },
-       sim_file_detach,                /* detach */
-       NULL                            /* destroy */
 };
 
index 5f8ff7f..7e044ed 100644 (file)
@@ -185,10 +185,11 @@ static int smb_detach(void *instance)
  *     is single-threaded.
  */
 module_t rlm_smb = {
+       RLM_MODULE_INIT,
        "SMB",
        RLM_TYPE_THREAD_UNSAFE,         /* type */
-       NULL,                           /* initialization */
        smb_instantiate,                /* instantiation */
+       smb_detach,                     /* detach */
        {
                smb_authenticate,       /* authentication */
                NULL,                   /* authorization */
@@ -199,6 +200,4 @@ module_t rlm_smb = {
                NULL,                   /* post-proxy */
                NULL                    /* post-auth */
        },
-       smb_detach,                     /* detach */
-       NULL,                           /* destroy */
 };
index 3f3da1f..ab63d29 100644 (file)
@@ -152,20 +152,6 @@ static int fallthrough(VALUE_PAIR *vp)
 }
 
 
-/***********************************************************************
- * start of main routines
- ***********************************************************************/
-static int rlm_sql_init(void) {
-
-       /*
-        * FIXME:
-        * We should put the sqlsocket array here once
-        * the module code is reworked to not unload
-        * modules on HUP.  This way we can have
-        * persistant connections.  -jcarneal
-        */
-       return 0;
-}
 
 /*
  *     Yucky prototype.
@@ -909,11 +895,6 @@ static int rlm_sql_instantiate(CONF_SECTION * conf, void **instance)
        return RLM_MODULE_OK;
 }
 
-static int rlm_sql_destroy(void)
-{
-       return 0;
-}
-
 
 static int rlm_sql_authorize(void *instance, REQUEST * request)
 {
@@ -1579,10 +1560,11 @@ static int rlm_sql_postauth(void *instance, REQUEST *request) {
 
 /* globally exported name */
 module_t rlm_sql = {
+       RLM_MODULE_INIT,
        "SQL",
        RLM_TYPE_THREAD_SAFE,   /* type: reserved */
-       rlm_sql_init,           /* initialization */
        rlm_sql_instantiate,    /* instantiation */
+       rlm_sql_detach,         /* detach */
        {
                NULL,                   /* authentication */
                rlm_sql_authorize,      /* authorization */
@@ -1593,6 +1575,4 @@ module_t rlm_sql = {
                NULL,                   /* post-proxy */
                rlm_sql_postauth        /* post-auth */
        },
-       rlm_sql_detach,         /* detach */
-       rlm_sql_destroy,        /* destroy */
 };
index becfa87..03da5a7 100644 (file)
@@ -427,10 +427,11 @@ static int sql_log_postauth(void *instance, REQUEST *request)
  *     is single-threaded.
  */
 module_t rlm_sql_log = {
+       RLM_MODULE_INIT,
        "sql_log",
        RLM_TYPE_THREAD_SAFE,           /* type */
-       NULL,                           /* initialization */
        sql_log_instantiate,            /* instantiation */
+       sql_log_detach,                 /* detach */
        {
                NULL,                   /* authentication */
                NULL,                   /* authorization */
@@ -441,6 +442,4 @@ module_t rlm_sql_log = {
                NULL,                   /* post-proxy */
                sql_log_postauth        /* post-auth */
        },
-       sql_log_detach,                 /* detach */
-       NULL,                           /* destroy */
 };
index 8957586..c8b60ba 100644 (file)
@@ -651,10 +651,11 @@ static int sqlcounter_detach(void *instance)
  *     is single-threaded.
  */
 module_t rlm_sqlcounter = {
+       RLM_MODULE_INIT,
        "SQL Counter",
        RLM_TYPE_THREAD_SAFE,           /* type */
-       NULL,                           /* initialization */
        sqlcounter_instantiate,         /* instantiation */
+       sqlcounter_detach,              /* detach */
        {
                NULL,                   /* authentication */
                sqlcounter_authorize,   /* authorization */
@@ -665,7 +666,5 @@ module_t rlm_sqlcounter = {
                NULL,                   /* post-proxy */
                NULL                    /* post-auth */
        },
-       sqlcounter_detach,              /* detach */
-       NULL,                           /* destroy */
 };
 
index e500605..dc6f50a 100644 (file)
@@ -120,22 +120,6 @@ 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)
@@ -143,6 +127,11 @@ 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 +161,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;
 }
 
@@ -604,20 +589,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 */
+       },
 };