remove unnecessary assert
[freeradius.git] / src / main / modules.c
index 24d3b99..749c07e 100644 (file)
@@ -30,6 +30,11 @@ RCSID("$Id$")
 #include <freeradius-devel/parser.h>
 #include <freeradius-devel/rad_assert.h>
 
+/** Path to search for modules in
+ *
+ */
+char const *radlib_dir = NULL;
+
 typedef struct indexed_modcallable {
        rlm_components_t        comp;
        int                     idx;
@@ -42,8 +47,8 @@ typedef struct virtual_server_t {
        int             can_free;
        CONF_SECTION    *cs;
        rbtree_t        *components;
-       modcallable     *mc[RLM_COMPONENT_COUNT];
-       CONF_SECTION    *subcs[RLM_COMPONENT_COUNT];
+       modcallable     *mc[MOD_COUNT];
+       CONF_SECTION    *subcs[MOD_COUNT];
        struct virtual_server_t *next;
 } virtual_server_t;
 
@@ -67,7 +72,7 @@ struct fr_module_hup_t {
 /*
  *     Ordered by component
  */
-const section_type_value_t section_type_value[RLM_COMPONENT_COUNT] = {
+const section_type_value_t section_type_value[MOD_COUNT] = {
        { "authenticate", "Auth-Type",       PW_AUTH_TYPE },
        { "authorize",    "Autz-Type",       PW_AUTZ_TYPE },
        { "preacct",      "Pre-Acct-Type",   PW_PRE_ACCT_TYPE },
@@ -109,7 +114,15 @@ const section_type_value_t section_type_value[RLM_COMPONENT_COUNT] = {
  */
 static int check_module_magic(CONF_SECTION *cs, module_t const *module)
 {
+#ifdef HAVE_DLADDR
+       Dl_info dl_info;
+       dladdr(module, &dl_info);
+#endif
+
        if (MAGIC_PREFIX(module->magic) != MAGIC_PREFIX(RADIUSD_MAGIC_NUMBER)) {
+#ifdef HAVE_DLADDR
+               cf_log_err_cs(cs, "Failed loading module rlm_%s from file %s", module->name, dl_info.dli_fname);
+#endif
                cf_log_err_cs(cs, "Application and rlm_%s magic number (prefix) mismatch."
                              "  application: %x module: %x", module->name,
                              MAGIC_PREFIX(RADIUSD_MAGIC_NUMBER),
@@ -118,6 +131,9 @@ static int check_module_magic(CONF_SECTION *cs, module_t const *module)
        }
 
        if (MAGIC_VERSION(module->magic) != MAGIC_VERSION(RADIUSD_MAGIC_NUMBER)) {
+#ifdef HAVE_DLADDR
+               cf_log_err_cs(cs, "Failed loading module rlm_%s from file %s", module->name, dl_info.dli_fname);
+#endif
                cf_log_err_cs(cs, "Application and rlm_%s magic number (version) mismatch."
                              "  application: %lx module: %lx", module->name,
                              (unsigned long) MAGIC_VERSION(RADIUSD_MAGIC_NUMBER),
@@ -126,6 +142,9 @@ static int check_module_magic(CONF_SECTION *cs, module_t const *module)
        }
 
        if (MAGIC_COMMIT(module->magic) != MAGIC_COMMIT(RADIUSD_MAGIC_NUMBER)) {
+#ifdef HAVE_DLADDR
+               cf_log_err_cs(cs, "Failed loading module rlm_%s from file %s", module->name, dl_info.dli_fname);
+#endif
                cf_log_err_cs(cs, "Application and rlm_%s magic number (commit) mismatch."
                              "  application: %lx module: %lx", module->name,
                              (unsigned long) MAGIC_COMMIT(RADIUSD_MAGIC_NUMBER),
@@ -136,13 +155,13 @@ static int check_module_magic(CONF_SECTION *cs, module_t const *module)
        return 0;
 }
 
-lt_dlhandle lt_dlopenext(char const *name)
+fr_dlhandle fr_dlopenext(char const *name)
 {
-       int flags = RTLD_NOW;
-       void *handle;
-       char buffer[2048];
-       char *env;
-
+       int             flags = RTLD_NOW;
+       void            *handle;
+       char            buffer[2048];
+       char            *env;
+       char const      *search_path;
 #ifdef RTLD_GLOBAL
        if (strcmp(name, "rlm_perl") == 0) {
                flags |= RTLD_GLOBAL;
@@ -156,34 +175,56 @@ lt_dlhandle lt_dlopenext(char const *name)
         */
        flags |= RTLD_NOW;
 #endif
+
+       /*
+        *      Apple removed support for DYLD_LIBRARY_PATH in rootless mode.
+        */
+       env = getenv("FR_LIBRARY_PATH");
+       if (env) {
+               DEBUG3("Ignoring libdir as FR_LIBRARY_PATH set.  Module search path will be: %s", env);
+               search_path = env;
+       } else {
+               search_path = radlib_dir;
+       }
+
        /*
         *      Prefer loading our libraries by absolute path.
         */
-       snprintf(buffer, sizeof(buffer), "%s/%s%s", radlib_dir, name, LT_SHREXT);
+       if (search_path) {
+               char *error;
+               char *ctx, *paths, *path;
+               char *p;
 
-       DEBUG4("Loading library using absolute path \"%s\"", name);
+               fr_strerror();
 
-       handle = dlopen(buffer, flags);
-       if (handle) return handle;
+               ctx = paths = talloc_strdup(NULL, search_path);
+               while ((path = strsep(&paths, ":")) != NULL) {
+                       /*
+                        *      Trim the trailing slash
+                        */
+                       p = strrchr(path, '/');
+                       if (p && ((p[1] == '\0') || (p[1] == ':'))) *p = '\0';
 
-       /*
-        *      Because dlopen produces really shitty and inaccurate error messages
-        */
-       if (access(name, R_OK) < 0) switch (errno) {
-       case EACCES:
-               WARN("Library file found, but we don't have permission to read it");
-               break;
+                       path = talloc_asprintf(ctx, "%s/%s%s", path, name, LT_SHREXT);
+
+                       DEBUG4("Loading %s with path: %s", name, path);
 
-       case ENOENT:
-               DEBUG4("Library file not found");
-               break;
+                       handle = dlopen(path, flags);
+                       if (handle) {
+                               talloc_free(ctx);
+                               return handle;
+                       }
+                       error = dlerror();
 
-       default:
-               DEBUG4("Issue accessing library file: %s", fr_syserror(errno));
-               break;
+                       fr_strerror_printf("%s%s\n", fr_strerror(), error);
+                       DEBUG4("Loading %s failed: %s - %s", name, error,
+                              (access(path, R_OK) < 0) ? fr_syserror(errno) : "No access errors");
+                       talloc_free(path);
+               }
+               talloc_free(ctx);
        }
 
-       DEBUG4("Falling back to linker search path(s)");
+       DEBUG4("Loading library using linker search path(s)");
        if (DEBUG_ENABLED4) {
 #ifdef __APPLE__
                env = getenv("LD_LIBRARY_PATH");
@@ -217,22 +258,34 @@ lt_dlhandle lt_dlopenext(char const *name)
         */
        strlcat(buffer, LT_SHREXT, sizeof(buffer));
 
-       return dlopen(buffer, flags);
+       handle = dlopen(buffer, flags);
+       if (!handle) {
+               char *error = dlerror();
+
+               DEBUG4("Failed with error: %s", error);
+               /*
+                *      Don't overwrite the previous message
+                *      It's likely to contain a better error.
+                */
+               if (!radlib_dir) fr_strerror_printf("%s", dlerror());
+               return NULL;
+       }
+       return handle;
 }
 
-void *lt_dlsym(lt_dlhandle handle, char const *symbol)
+void *fr_dlsym(fr_dlhandle handle, char const *symbol)
 {
        return dlsym(handle, symbol);
 }
 
-int lt_dlclose(lt_dlhandle handle)
+int fr_dlclose(fr_dlhandle handle)
 {
        if (!handle) return 0;
 
        return dlclose(handle);
 }
 
-char const *lt_dlerror(void)
+char const *fr_dlerror(void)
 {
        return dlerror();
 }
@@ -378,16 +431,19 @@ static void module_instance_free(void *data)
        }
 #endif
 
-       /*
-        *      Remove any registered paircompares.
-        */
-       paircompare_unregister_instance(module->insthandle);
-
        xlat_unregister(module->name, NULL, module->insthandle);
+
        /*
         *      Remove all xlat's registered to module instance.
         */
-       if (module->insthandle) xlat_unregister_module(module->insthandle);
+       if (module->insthandle) {
+               /*
+                *      Remove any registered paircompares.
+                */
+               paircompare_unregister_instance(module->insthandle);
+
+               xlat_unregister_module(module->insthandle);
+       }
        talloc_free(module);
 }
 
@@ -434,9 +490,9 @@ int modules_free(void)
 
 
 /*
- *     Find a module on disk or in memory, and link to it.
+ *     dlopen() a module.
  */
-static module_entry_t *linkto_module(char const *module_name, CONF_SECTION *cs)
+static module_entry_t *module_dlopen(CONF_SECTION *cs, char const *module_name)
 {
        module_entry_t myentry;
        module_entry_t *node;
@@ -460,9 +516,9 @@ static module_entry_t *linkto_module(char const *module_name, CONF_SECTION *cs)
        /*
         *      Keep the handle around so we can dlclose() it.
         */
-       handle = lt_dlopenext(module_name);
+       handle = fr_dlopenext(module_name);
        if (!handle) {
-               cf_log_err_cs(cs, "Failed to link to module '%s': %s", module_name, dlerror());
+               cf_log_err_cs(cs, "Failed to link to module '%s': %s", module_name, fr_strerror());
                return NULL;
        }
 
@@ -521,15 +577,11 @@ static int module_conf_parse(module_instance_t *node, void **handle)
         *      Also parse the configuration data, if required.
         */
        if (node->entry->module->inst_size) {
-               /* FIXME: make this rlm_config_t ?? */
                *handle = talloc_zero_array(node, uint8_t, node->entry->module->inst_size);
-               rad_assert(handle);
+               rad_assert(*handle);
 
-               /*
-                *      So we can see where this configuration is from
-                *      FIXME: set it to rlm_NAME_t, or some such thing
-                */
-               talloc_set_name(*handle, "rlm_config_t");
+               talloc_set_name(*handle, "rlm_%s_t",
+                               node->entry->module->name ? node->entry->module->name : "config");
 
                if (node->entry->module->config &&
                    (cf_section_parse(node->cs, *handle, node->entry->module->config) < 0)) {
@@ -550,65 +602,48 @@ static int module_conf_parse(module_instance_t *node, void **handle)
        return 0;
 }
 
-/*
- *     Find a module instance.
+/** Bootstrap a module.
+ *
+ *  Load the module shared library, allocate instance memory for it,
+ *  parse the module configuration, and call the modules "bootstrap" method.
  */
-module_instance_t *find_module_instance(CONF_SECTION *modules,
-                                       char const *askedname, bool do_link)
+static module_instance_t *module_bootstrap(CONF_SECTION *cs)
 {
-       bool check_config_safe = false;
-       CONF_SECTION *cs;
-       char const *name1, *instname;
+       char const *name1, *name2;
        module_instance_t *node, myNode;
        char module_name[256];
 
-       if (!modules) return NULL;
-
        /*
-        *      Look for the real name.  Ignore the first character,
-        *      which tells the server "it's OK for this module to not
-        *      exist."
+        *      Figure out which module we want to load.
         */
-       instname = askedname;
-       if (instname[0] == '-') {
-               instname++;
-       }
+       name1 = cf_section_name1(cs);
+       name2 = cf_section_name2(cs);
+       if (!name2) name2 = name1;
 
-       /*
-        *      Module instances are declared in the modules{} block
-        *      and referenced later by their name, which is the
-        *      name2 from the config section, or name1 if there was
-        *      no name2.
-        */
-       cs = cf_section_sub_find_name2(modules, NULL, instname);
-       if (!cs) {
-               ERROR("Cannot find a configuration entry for module \"%s\"", instname);
-               return NULL;
-       }
+       strlcpy(myNode.name, name2, sizeof(myNode.name));
 
        /*
-        *      If there's already a module instance, return it.
+        *      See if the module already exists.
         */
-       strlcpy(myNode.name, instname, sizeof(myNode.name));
-
        node = rbtree_finddata(instance_tree, &myNode);
        if (node) {
-               return node;
-       }
-
-       if (!do_link) {
+               ERROR("Duplicate module \"%s %s\", in file %s:%d and file %s:%d",
+                     name1, name2,
+                     cf_section_filename(cs),
+                     cf_section_lineno(cs),
+                     cf_section_filename(node->cs),
+                     cf_section_lineno(node->cs));
                return NULL;
        }
 
-       name1 = cf_section_name1(cs);
-
        /*
-        *      Found the configuration entry, hang the node struct off of the
-        *      configuration section. If the CS is free'd the instance will
-        *      be too.
+        *      Hang the node struct off of the configuration
+        *      section. If the CS is free'd the instance will be
+        *      free'd, too.
         */
-       node = talloc_zero(cs, module_instance_t);
+       node = talloc_zero(instance_tree, module_instance_t);
        node->cs = cs;
+       strlcpy(node->name, name2, sizeof(node->name));
 
        /*
         *      Names in the "modules" section aren't prefixed
@@ -617,60 +652,116 @@ module_instance_t *find_module_instance(CONF_SECTION *modules,
        snprintf(module_name, sizeof(module_name), "rlm_%s", name1);
 
        /*
-        *      Pull in the module object
+        *      Load the module shared library.
         */
-       node->entry = linkto_module(module_name, cs);
+       node->entry = module_dlopen(cs, module_name);
        if (!node->entry) {
                talloc_free(node);
-               /* linkto_module logs any errors */
                return NULL;
        }
 
-       if (check_config && (node->entry->module->instantiate) &&
-           (node->entry->module->type & RLM_TYPE_CHECK_CONFIG_UNSAFE) != 0) {
-               char const *value = NULL;
-               CONF_PAIR *cp;
-
-               cp = cf_pair_find(cs, "force_check_config");
-               if (cp) {
-                       value = cf_pair_value(cp);
-               }
+       cf_log_module(cs, "Loading module \"%s\" from file %s", node->name,
+                     cf_section_filename(cs));
 
-               if (value && (strcmp(value, "yes") == 0)) goto print_inst;
+       /*
+        *      Parse the modules configuration.
+        */
+       if (module_conf_parse(node, &node->insthandle) < 0) {
+               talloc_free(node);
+               return NULL;
+       }
 
-               cf_log_module(cs, "Skipping instantiation of %s", instname);
-       } else {
-       print_inst:
-               check_config_safe = true;
-               cf_log_module(cs, "Instantiating module \"%s\" from file %s", instname,
-                             cf_section_filename(cs));
+       /*
+        *      Bootstrap the module.
+        */
+       if (node->entry->module->bootstrap &&
+           ((node->entry->module->bootstrap)(cs, node->insthandle) < 0)) {
+               cf_log_err_cs(cs, "Instantiation failed for module \"%s\"", node->name);
+               talloc_free(node);
+               return NULL;
        }
 
-       strlcpy(node->name, instname, sizeof(node->name));
+       /*
+        *      Remember the module for later.
+        */
+       rbtree_insert(instance_tree, node);
+
+       return node;
+}
+
+
+/** Find an existing module instance.
+ *
+ */
+module_instance_t *module_find(CONF_SECTION *modules, char const *askedname)
+{
+       char const *instname;
+       module_instance_t myNode;
+
+       if (!modules) return NULL;
 
        /*
-        *      Parse the module configuration, and setup destructors so the
-        *      module's detach method is called when it's instance data is
-        *      about to be freed.
+        *      Look for the real name.  Ignore the first character,
+        *      which tells the server "it's OK for this module to not
+        *      exist."
         */
-       if (module_conf_parse(node, &node->insthandle) < 0) {
-               talloc_free(node);
+       instname = askedname;
+       if (instname[0] == '-') instname++;
+
+       strlcpy(myNode.name, instname, sizeof(myNode.name));
 
+       return rbtree_finddata(instance_tree, &myNode);
+}
+
+
+/** Load a module, and instantiate it.
+ *
+ */
+module_instance_t *module_instantiate(CONF_SECTION *modules, char const *askedname)
+{
+       module_instance_t *node;
+
+       /*
+        *      Find the module.  If it's not there, do nothing.
+        */
+       node = module_find(modules, askedname);
+       if (!node) {
+               ERROR("Cannot find module \"%s\"", askedname);
                return NULL;
        }
 
        /*
-        *      Call the module's instantiation routine.
+        *      The module is already instantiated.  Return it.
         */
-       if ((node->entry->module->instantiate) &&
-           (!check_config || check_config_safe) &&
-           ((node->entry->module->instantiate)(cs, node->insthandle) < 0)) {
-               cf_log_err_cs(cs, "Instantiation failed for module \"%s\"", node->name);
-               talloc_free(node);
+       if (node->instantiated) return node;
 
+       /*
+        *      Now that ALL modules are instantiated, and ALL xlats
+        *      are defined, go compile the config items marked as XLAT.
+        */
+       if (node->entry->module->config &&
+           (cf_section_parse_pass2(node->cs, node->insthandle,
+                                   node->entry->module->config) < 0)) {
                return NULL;
        }
 
+       /*
+        *      Call the instantiate method, if any.
+        */
+       if (node->entry->module->instantiate) {
+               cf_log_module(node->cs, "Instantiating module \"%s\" from file %s", node->name,
+                             cf_section_filename(node->cs));
+
+               /*
+                *      Call the module's instantiation routine.
+                */
+               if ((node->entry->module->instantiate)(node->cs, node->insthandle) < 0) {
+                       cf_log_err_cs(node->cs, "Instantiation failed for module \"%s\"", node->name);
+
+                       return NULL;
+               }
+       }
+
 #ifdef HAVE_PTHREAD_H
        /*
         *      If we're threaded, check if the module is thread-safe.
@@ -684,19 +775,64 @@ module_instance_t *find_module_instance(CONF_SECTION *modules,
                 *      Initialize the mutex.
                 */
                pthread_mutex_init(node->mutex, NULL);
-       } else {
-               /*
-                *      The module is thread-safe.  Don't give it a mutex.
-                */
-               node->mutex = NULL;
        }
-
 #endif
-       rbtree_insert(instance_tree, node);
+
+       node->instantiated = true;
+       node->last_hup = time(NULL); /* don't let us load it, then immediately hup it */
 
        return node;
 }
 
+
+module_instance_t *module_instantiate_method(CONF_SECTION *modules, char const *name, rlm_components_t *method)
+{
+       char *p;
+       rlm_components_t i;
+       module_instance_t *mi;
+
+       /*
+        *      If the module exists, ensure it's instantiated.
+        *
+        *      Doing it this way avoids complaints from
+        *      module_instantiate()
+        */
+       mi = module_find(modules, name);
+       if (mi) return module_instantiate(modules, name);
+
+       /*
+        *      Find out which method is being used.
+        */
+       p = strrchr(name, '.');
+       if (!p) return NULL;
+
+       p++;
+
+       /*
+        *      Find the component.
+        */
+       for (i = MOD_AUTHENTICATE; i < MOD_COUNT; i++) {
+               if (strcmp(p, section_type_value[i].section) == 0) {
+                       char buffer[256];
+
+                       strlcpy(buffer, name, sizeof(buffer));
+                       buffer[p - name - 1] = '\0';
+
+                       mi = module_find(modules, buffer);
+                       if (mi) {
+                               if (method) *method = i;
+                               return module_instantiate(modules, buffer);
+                       }
+               }
+       }
+
+       /*
+        *      Not found.
+        */
+       return NULL;
+}
+
+
 /** Resolve polymorphic item's from a module's CONF_SECTION to a subsection in another module
  *
  * This allows certain module sections to reference module sections in other instances
@@ -764,7 +900,7 @@ int find_module_sibling_section(CONF_SECTION **out, CONF_SECTION *module, char c
         *      instantiation order issues.
         */
        inst_name = cf_pair_value(cp);
-       inst = find_module_instance(cf_item_parent(cf_sectiontoitem(module)), inst_name, true);
+       inst = module_instantiate(cf_item_parent(cf_section_to_item(module)), inst_name);
 
        /*
         *      Remove the config data we added for loop
@@ -858,8 +994,14 @@ rlm_rcode_t indexed_modcall(rlm_components_t comp, int idx, REQUEST *request)
 
        if (idx == 0) {
                list = server->mc[comp];
-               if (!list) RDEBUG3("Empty %s section.  Using default return values.", section_type_value[comp].section);
-
+               if (!list) {
+                       if (server->name) {
+                               RDEBUG3("Empty %s section in virtual server \"%s\".  Using default return values.",
+                                       section_type_value[comp].section, server->name);
+                       } else {
+                               RDEBUG3("Empty %s section.  Using default return values.", section_type_value[comp].section);
+                       }
+               }
        } else {
                indexed_modcallable *this;
 
@@ -867,8 +1009,7 @@ rlm_rcode_t indexed_modcall(rlm_components_t comp, int idx, REQUEST *request)
                if (this) {
                        list = this->modulelist;
                } else {
-                       RDEBUG3("%s sub-section not found.  Ignoring.",
-                               section_type_value[comp].typename);
+                       RDEBUG2("%s sub-section not found.  Ignoring.", section_type_value[comp].typename);
                }
        }
 
@@ -929,8 +1070,8 @@ static int load_subcomponent_section(CONF_SECTION *cs,
        if (!dval) {
                talloc_free(ml);
                cf_log_err_cs(cs,
-                          "%s %s Not previously configured",
-                          section_type_value[comp].typename, name2);
+                          "The %s attribute has no VALUE defined for %s",
+                             section_type_value[comp].typename, name2);
                return 0;
        }
 
@@ -947,38 +1088,6 @@ static int load_subcomponent_section(CONF_SECTION *cs,
        return 1;               /* OK */
 }
 
-static int define_type(CONF_SECTION *cs, DICT_ATTR const *da, char const *name)
-{
-       uint32_t value;
-       DICT_VALUE *dval;
-
-       /*
-        *      If the value already exists, don't
-        *      create it again.
-        */
-       dval = dict_valbyname(da->attr, da->vendor, name);
-       if (dval) return 1;
-
-       /*
-        *      Create a new unique value with a
-        *      meaningless number.  You can't look at
-        *      it from outside of this code, so it
-        *      doesn't matter.  The only requirement
-        *      is that it's unique.
-        */
-       do {
-               value = fr_rand() & 0x00ffffff;
-       } while (dict_valbyattr(da->attr, da->vendor, value));
-
-       cf_log_module(cs, "Creating %s = %s", da->name, name);
-       if (dict_addvalue(name, da->name, value) < 0) {
-               ERROR("%s", fr_strerror());
-               return 0;
-       }
-
-       return 1;
-}
-
 /*
  *     Don't complain too often.
  */
@@ -1019,7 +1128,7 @@ static int load_component_section(CONF_SECTION *cs,
                CONF_SECTION *scs = NULL;
 
                if (cf_item_is_section(modref)) {
-                       scs = cf_itemtosection(modref);
+                       scs = cf_item_to_section(modref);
 
                        name1 = cf_section_name1(scs);
 
@@ -1038,7 +1147,7 @@ static int load_component_section(CONF_SECTION *cs,
                        cp = NULL;
 
                } else if (cf_item_is_pair(modref)) {
-                       cp = cf_itemtopair(modref);
+                       cp = cf_item_to_pair(modref);
 
                } else {
                        continue; /* ignore it */
@@ -1052,7 +1161,7 @@ static int load_component_section(CONF_SECTION *cs,
                 *      i.e. They're not allowed in a "group" or "redundant"
                 *      subsection.
                 */
-               if (comp == RLM_COMPONENT_AUTH) {
+               if (comp == MOD_AUTHENTICATE) {
                        DICT_VALUE *dval;
                        char const *modrefname = NULL;
                        if (cp) {
@@ -1128,7 +1237,7 @@ static int load_component_section(CONF_SECTION *cs,
                        return -1;
                }
 
-               if (debug_flag > 2) modcall_debug(this, 2);
+               if (rad_debug_lvl > 2) modcall_debug(this, 2);
 
                add_to_modcallable(subcomp->modulelist, this);
        }
@@ -1139,11 +1248,13 @@ static int load_component_section(CONF_SECTION *cs,
 
 static int load_byserver(CONF_SECTION *cs)
 {
-       rlm_components_t comp, found;
+       rlm_components_t comp;
+       bool found;
        char const *name = cf_section_name2(cs);
        rbtree_t *components;
        virtual_server_t *server = NULL;
        indexed_modcallable *c;
+       bool is_bare;
 
        if (name) {
                cf_log_info(cs, "server %s { # from file %s",
@@ -1153,6 +1264,8 @@ static int load_byserver(CONF_SECTION *cs)
                            cf_section_filename(cs));
        }
 
+       is_bare = (cf_item_parent(cf_section_to_item(cs)) == NULL);
+
        server = talloc_zero(cs, virtual_server_t);
        server->name = name;
        server->created = time(NULL);
@@ -1160,92 +1273,33 @@ static int load_byserver(CONF_SECTION *cs)
        server->components = components = rbtree_create(server, indexed_modcallable_cmp, NULL, 0);
        if (!components) {
                ERROR("Failed to initialize components");
-               goto error;
-       }
-       talloc_set_destructor(server, _virtual_server_free);
 
-       /*
-        *      Define types first.
-        */
-       for (comp = 0; comp < RLM_COMPONENT_COUNT; ++comp) {
-               CONF_SECTION *subcs;
-               CONF_ITEM *modref;
-               DICT_ATTR const *da;
-
-               subcs = cf_section_sub_find(cs,
-                                           section_type_value[comp].section);
-               if (!subcs) continue;
-
-               if (cf_item_find_next(subcs, NULL) == NULL) continue;
-
-               /*
-                *      Find the attribute used to store VALUEs for this section.
-                */
-               da = dict_attrbyvalue(section_type_value[comp].attr, 0);
-               if (!da) {
-                       cf_log_err_cs(subcs,
-                                  "No such attribute %s",
-                                  section_type_value[comp].typename);
-               error:
-                       if (debug_flag == 0) {
-                               ERROR("Failed to load virtual server %s",
-                                      (name != NULL) ? name : "<default>");
-                       }
-                       talloc_free(server);
-                       return -1;
+       error:
+               if (rad_debug_lvl == 0) {
+                       ERROR("Failed to load virtual server %s",
+                             (name != NULL) ? name : "<default>");
                }
-
-               /*
-                *      Define dynamic types, so that others can reference
-                *      them.
-                */
-               for (modref = cf_item_find_next(subcs, NULL);
-                    modref != NULL;
-                    modref = cf_item_find_next(subcs, modref)) {
-                       char const *name1;
-                       CONF_SECTION *subsubcs;
-
-                       /*
-                        *      Create types for simple references
-                        *      only when parsing the authenticate
-                        *      section.
-                        */
-                       if ((section_type_value[comp].attr == PW_AUTH_TYPE) &&
-                           cf_item_is_pair(modref)) {
-                               CONF_PAIR *cp = cf_itemtopair(modref);
-                               if (!define_type(cs, da, cf_pair_attr(cp))) {
-                                       goto error;
-                               }
-
-                               continue;
-                       }
-
-                       if (!cf_item_is_section(modref)) continue;
-
-                       subsubcs = cf_itemtosection(modref);
-                       name1 = cf_section_name1(subsubcs);
-
-                       if (strcmp(name1, section_type_value[comp].typename) == 0) {
-                         if (!define_type(cs, da,
-                                          cf_section_name2(subsubcs))) {
-                                       goto error;
-                               }
-                       }
-               }
-       } /* loop over components */
+               return -1;
+       }
+       talloc_set_destructor(server, _virtual_server_free);
 
        /*
         *      Loop over all of the known components, finding their
         *      configuration section, and loading it.
         */
-       found = 0;
-       for (comp = 0; comp < RLM_COMPONENT_COUNT; ++comp) {
+       found = false;
+       for (comp = 0; comp < MOD_COUNT; ++comp) {
                CONF_SECTION *subcs;
 
                subcs = cf_section_sub_find(cs,
                                            section_type_value[comp].section);
                if (!subcs) continue;
 
+               if (is_bare) {
+                       cf_log_err_cs(subcs, "The %s section should be inside of a 'server { ... }' block!",
+                                     section_type_value[comp].section);
+               }
+
                if (cf_item_find_next(subcs, NULL) == NULL) continue;
 
                /*
@@ -1256,20 +1310,20 @@ static int load_byserver(CONF_SECTION *cs)
 #ifdef WITH_PROXY
                    !main_config.proxy_requests &&
 #endif
-                   ((comp == RLM_COMPONENT_PRE_PROXY) ||
-                    (comp == RLM_COMPONENT_POST_PROXY))) {
+                   ((comp == MOD_PRE_PROXY) ||
+                    (comp == MOD_POST_PROXY))) {
                        continue;
                }
 
 #ifndef WITH_ACCOUNTING
-               if (comp == RLM_COMPONENT_ACCT) continue;
+               if (comp == MOD_ACCOUNTING) continue;
 #endif
 
 #ifndef WITH_SESSION_MGMT
-               if (comp == RLM_COMPONENT_SESS) continue;
+               if (comp == MOD_SESSION) continue;
 #endif
 
-               if (debug_flag <= 3) {
+               if (rad_debug_lvl <= 3) {
                        cf_log_module(cs, "Loading %s {...}",
                                      section_type_value[comp].section);
                } else {
@@ -1280,7 +1334,7 @@ static int load_byserver(CONF_SECTION *cs)
                        goto error;
                }
 
-               if (debug_flag > 3) {
+               if (rad_debug_lvl > 3) {
                        DEBUG(" } # %s", section_type_value[comp].section);
                }
 
@@ -1293,7 +1347,7 @@ static int load_byserver(CONF_SECTION *cs)
 
                server->subcs[comp] = subcs;
 
-               found = 1;
+               found = true;
        } /* loop over components */
 
        /*
@@ -1315,12 +1369,12 @@ static int load_byserver(CONF_SECTION *cs)
                if (subcs) {
                        cf_log_module(cs, "Loading vmps {...}");
                        if (load_component_section(subcs, components,
-                                                  RLM_COMPONENT_POST_AUTH) < 0) {
+                                                  MOD_POST_AUTH) < 0) {
                                goto error;
                        }
                        c = lookup_by_index(components,
-                                           RLM_COMPONENT_POST_AUTH, 0);
-                       if (c) server->mc[RLM_COMPONENT_POST_AUTH] = c->modulelist;
+                                           MOD_POST_AUTH, 0);
+                       if (c) server->mc[MOD_POST_AUTH] = c->modulelist;
                        break;
                }
 #endif
@@ -1348,12 +1402,12 @@ static int load_byserver(CONF_SECTION *cs)
                        if (!load_subcomponent_section(subcs,
                                                       components,
                                                       da,
-                                                      RLM_COMPONENT_POST_AUTH)) {
+                                                      MOD_POST_AUTH)) {
                                goto error; /* FIXME: memleak? */
                        }
                        c = lookup_by_index(components,
-                                           RLM_COMPONENT_POST_AUTH, 0);
-                       if (c) server->mc[RLM_COMPONENT_POST_AUTH] = c->modulelist;
+                                           MOD_POST_AUTH, 0);
+                       if (c) server->mc[MOD_POST_AUTH] = c->modulelist;
 
                        subcs = cf_subsection_find_next(cs, subcs, "dhcp");
                }
@@ -1366,7 +1420,7 @@ static int load_byserver(CONF_SECTION *cs)
                cf_log_info(cs, "} # server");
        }
 
-       if (debug_flag == 0) {
+       if (rad_debug_lvl == 0) {
                INFO("Loaded virtual server %s",
                       (name != NULL) ? name : "<default>");
        }
@@ -1407,19 +1461,6 @@ static int pass2_cb(UNUSED void *ctx, void *data)
        return 0;
 }
 
-static int pass2_instance_cb(UNUSED void *ctx, void *data)
-{
-       module_instance_t *node = data;
-
-       if (!node->entry->module->config || !node->cs) return 0;
-
-       if (cf_section_parse_pass2(node->cs, node->insthandle,
-                                  node->entry->module->config) < 0) {
-               return -1;
-       }
-
-       return 0;
-}
 
 /*
  *     Load all of the virtual servers.
@@ -1488,11 +1529,22 @@ int virtual_servers_load(CONF_SECTION *config)
        }
 
        /*
-        *      Check all of the module config items which are xlat expanded.
+        *      Try to compile the "authorize", etc. sections which
+        *      aren't in a virtual server.
         */
-       if (rbtree_walk(instance_tree, RBTREE_IN_ORDER,
-                       pass2_instance_cb, NULL) != 0) {
-               return -1;
+       server = virtual_server_find(NULL);
+       if (server) {
+               int i;
+
+               for (i = MOD_AUTHENTICATE; i < MOD_COUNT; i++) {
+                       if (!modcall_pass2(server->mc[i])) return -1;
+               }
+
+               if (server->components &&
+                   (rbtree_walk(server->components, RBTREE_IN_ORDER,
+                                pass2_cb, NULL) != 0)) {
+                       return -1;
+               }
        }
 
        /*
@@ -1510,9 +1562,8 @@ int virtual_servers_load(CONF_SECTION *config)
                server = virtual_server_find(name2);
                if (!server) continue;
 
-               for (i = RLM_COMPONENT_AUTH; i < RLM_COMPONENT_COUNT; i++) {
+               for (i = MOD_AUTHENTICATE; i < MOD_COUNT; i++) {
                        if (!modcall_pass2(server->mc[i])) return -1;
-
                }
 
                if (server->components &&
@@ -1536,11 +1587,18 @@ int module_hup_module(CONF_SECTION *cs, module_instance_t *node, time_t when)
        fr_module_hup_t *mh;
 
        if (!node ||
+           node->entry->module->bootstrap ||
            !node->entry->module->instantiate ||
            ((node->entry->module->type & RLM_TYPE_HUP_SAFE) == 0)) {
                return 1;
        }
 
+       /*
+        *      Silently ignore multiple HUPs within a short time period.
+        */
+       if ((node->last_hup + 2) >= when) return 1;
+       node->last_hup = when;
+
        cf_log_module(cs, "Trying to reload module \"%s\"", node->name);
 
        /*
@@ -1576,6 +1634,9 @@ int module_hup_module(CONF_SECTION *cs, module_instance_t *node, time_t when)
        mh->next = node->mh;
        node->mh = mh;
 
+       /*
+        *      Replace the instance handle while the module is running.
+        */
        node->insthandle = insthandle;
 
        /*
@@ -1612,7 +1673,7 @@ int modules_hup(CONF_SECTION *modules)
                 */
                if (!cf_item_is_section(ci)) continue;
 
-               cs = cf_itemtosection(ci);
+               cs = cf_item_to_section(ci);
                instname = cf_section_name2(cs);
                if (!instname) instname = cf_section_name1(cs);
 
@@ -1626,6 +1687,170 @@ int modules_hup(CONF_SECTION *modules)
 }
 
 
+static int define_type(CONF_SECTION *cs, DICT_ATTR const *da, char const *name)
+{
+       uint32_t value;
+       DICT_VALUE *dval;
+
+       /*
+        *      If the value already exists, don't
+        *      create it again.
+        */
+       dval = dict_valbyname(da->attr, da->vendor, name);
+       if (dval) {
+               if (dval->value == 0) {
+                       ERROR("The dictionaries must not define VALUE %s %s 0",
+                             da->name, name);
+                       return 0;
+               }
+               return 1;
+       }
+
+       /*
+        *      Create a new unique value with a
+        *      meaningless number.  You can't look at
+        *      it from outside of this code, so it
+        *      doesn't matter.  The only requirement
+        *      is that it's unique.
+        */
+       do {
+               value = (fr_rand() & 0x00ffffff) + 1;
+       } while (dict_valbyattr(da->attr, da->vendor, value));
+
+       cf_log_module(cs, "Creating %s = %s", da->name, name);
+       if (dict_addvalue(name, da->name, value) < 0) {
+               ERROR("%s", fr_strerror());
+               return 0;
+       }
+
+       return 1;
+}
+
+/*
+ *     Define Auth-Type, etc. in a server.
+ */
+static bool server_define_types(CONF_SECTION *cs)
+{
+       rlm_components_t        comp;
+
+       /*
+        *      Loop over all of the components
+        */
+       for (comp = 0; comp < MOD_COUNT; ++comp) {
+               CONF_SECTION *subcs, *type_cs;
+               DICT_ATTR const *da;
+
+               subcs = cf_section_sub_find(cs,
+                                           section_type_value[comp].section);
+               if (!subcs) continue;
+
+               if (cf_item_find_next(subcs, NULL) == NULL) continue;
+
+               /*
+                *      Find the attribute used to store VALUEs for this section.
+                */
+               da = dict_attrbyvalue(section_type_value[comp].attr, 0);
+               if (!da) {
+                       cf_log_err_cs(subcs,
+                                  "No such attribute %s",
+                                  section_type_value[comp].typename);
+                       return false;
+               }
+
+               /*
+                *      Define dynamic types, so that others can reference
+                *      them.
+                *
+                *      First, bare modules for 'authenticate'.
+                *      Second, Auth-Type, etc.
+                */
+               if (section_type_value[comp].attr == PW_AUTH_TYPE) {
+                       CONF_ITEM *modref;
+
+                       for (modref = cf_item_find_next(subcs, NULL);
+                            modref != NULL;
+                            modref = cf_item_find_next(subcs, modref)) {
+                               CONF_PAIR *cp;
+
+                               if (!cf_item_is_pair(modref)) continue;
+
+                               cp = cf_item_to_pair(modref);
+                               if (!define_type(cs, da, cf_pair_attr(cp))) {
+                                       return false;
+                               }
+
+                               /*
+                                *      Check for duplicates
+                                */
+                               if (rad_debug_lvl) {
+                                       CONF_PAIR *cp2;
+                                       CONF_SECTION *cs2;
+
+                                       cp2 = cf_pair_find(subcs, cf_pair_attr(cp));
+                                       rad_assert(cp2 != NULL);
+                                       if (cp2 != cp) {
+                                               WARN("%s[%d]: Duplicate module '%s'",
+                                                    cf_pair_filename(cp2),
+                                                    cf_pair_lineno(cp2),
+                                                    cf_pair_attr(cp));
+                                       }
+
+                                       cs2 = cf_section_sub_find_name2(subcs, section_type_value[comp].typename, cf_pair_attr(cp));
+                                       if (cs2) {
+                                               WARN("%s[%d]: Duplicate Auth-Type '%s'",
+                                                    cf_section_filename(cs2),
+                                                    cf_section_lineno(cs2),
+                                                    cf_pair_attr(cp));
+                                       }
+                               }
+
+                       }
+               }
+
+               /*
+                *      And loop over the type names
+                */
+               for (type_cs = cf_subsection_find_next(subcs, NULL, section_type_value[comp].typename);
+                    type_cs != NULL;
+                    type_cs = cf_subsection_find_next(subcs, type_cs, section_type_value[comp].typename)) {
+                       if (!define_type(cs, da, cf_section_name2(type_cs))) {
+                               return false;
+                       }
+
+                       if (rad_debug_lvl) {
+                               CONF_SECTION *cs2;
+
+                               cs2 = cf_section_sub_find_name2(subcs, section_type_value[comp].typename, cf_section_name2(type_cs));
+                               rad_assert(cs2 != NULL);
+                               if (cs2 != type_cs) {
+                                       WARN("%s[%d]: Duplicate Auth-Type '%s'",
+                                            cf_section_filename(cs2),
+                                            cf_section_lineno(cs2),
+                                            cf_section_name2(cs2));
+                               }
+                       }
+               }
+       } /* loop over components */
+
+       return true;
+}
+
+extern char const *unlang_keyword[];
+
+static bool is_reserved_word(const char *name)
+{
+       int i;
+
+       if (!name || !*name) return false;
+
+       for (i = 1; unlang_keyword[i] != NULL; i++) {
+               if (strcmp(name, unlang_keyword[i]) == 0) return true;
+       }
+
+       return false;
+}
+
+
 /*
  *     Parse the module config sections, and load
  *     and call each module's init() function.
@@ -1661,15 +1886,16 @@ int modules_init(CONF_SECTION *config)
                WARN("Cannot find a \"modules\" section in the configuration file!");
        }
 
-#if defined(WITH_VMPS) || defined(WITH_DHCP)
        /*
         *      Load dictionaries.
         */
        for (cs = cf_subsection_find_next(config, NULL, "server");
             cs != NULL;
             cs = cf_subsection_find_next(config, cs, "server")) {
+#if defined(WITH_DHCP) || defined(WITH_VMPS)
                CONF_SECTION *subcs;
                DICT_ATTR const *da;
+#endif
 
 #ifdef WITH_VMPS
                /*
@@ -1722,46 +1948,49 @@ int modules_init(CONF_SECTION *config)
                 *      Else it's a RADIUS virtual server, and the
                 *      dictionaries are already loaded.
                 */
+
+               /*
+                *      Root through each virtual server, defining
+                *      Autz-Type and Auth-Type.  This is so that the
+                *      modules can reference a particular type.
+                */
+               if (!server_define_types(cs)) return -1;
        }
-#endif
 
        DEBUG2("%s: #### Instantiating modules ####", main_config.name);
 
+       cf_log_info(config, " modules {");
+
        /*
         *      Loop over module definitions, looking for duplicates.
         *
         *      This is O(N^2) in the number of modules, but most
         *      systems should have less than 100 modules.
         */
-       for (ci=cf_item_find_next(modules, NULL);
+       for (ci = cf_item_find_next(modules, NULL);
             ci != NULL;
-            ci=next) {
-               char const *name1, *name2;
-               CONF_SECTION *subcs, *duplicate;
+            ci = next) {
+               char const *name1;
+               CONF_SECTION *subcs;
+               module_instance_t *node;
 
                next = cf_item_find_next(modules, ci);
 
                if (!cf_item_is_section(ci)) continue;
 
-               if (!next || !cf_item_is_section(next)) continue;
+               subcs = cf_item_to_section(ci);
 
-               subcs = cf_itemtosection(ci);
-               name1 = cf_section_name1(subcs);
-               name2 = cf_section_name2(subcs);
+               node = module_bootstrap(subcs);
+               if (!node) return -1;
 
-               duplicate = cf_section_find_name2(cf_itemtosection(next),
-                                                 name1, name2);
-               if (!duplicate) continue;
+               if (!next || !cf_item_is_section(next)) continue;
 
-               if (!name2) name2 = "";
+               name1 = cf_section_name1(subcs);
 
-               ERROR("Duplicate module \"%s %s\", in file %s:%d and file %s:%d",
-                      name1, name2,
-                      cf_section_filename(subcs),
-                      cf_section_lineno(subcs),
-                      cf_section_filename(duplicate),
-                      cf_section_lineno(duplicate));
-               return -1;
+               if (is_reserved_word(name1)) {
+                       cf_log_err_cs(subcs, "Module cannot be named for an 'unlang' keyword");
+                       return -1;
+               }
        }
 
        /*
@@ -1776,7 +2005,7 @@ int modules_init(CONF_SECTION *config)
                module_instance_t *module;
                char const *name;
 
-               cf_log_info(cs, " instantiate {");
+               cf_log_info(cs, "  instantiate {");
 
                /*
                 *  Loop over the items in the 'instantiate' section.
@@ -1784,17 +2013,16 @@ int modules_init(CONF_SECTION *config)
                for (ci=cf_item_find_next(cs, NULL);
                     ci != NULL;
                     ci=cf_item_find_next(cs, ci)) {
-
                        /*
                         *      Skip sections and "other" stuff.
                         *      Sections will be handled later, if
                         *      they're referenced at all...
                         */
                        if (cf_item_is_pair(ci)) {
-                               cp = cf_itemtopair(ci);
+                               cp = cf_item_to_pair(ci);
                                name = cf_pair_attr(cp);
 
-                               module = find_module_instance(modules, name, true);
+                               module = module_instantiate(modules, name);
                                if (!module && (name[0] != '-')) {
                                        return -1;
                                }
@@ -1811,7 +2039,7 @@ int modules_init(CONF_SECTION *config)
                                CONF_SECTION *subcs;
                                CONF_ITEM *subci;
 
-                               subcs = cf_itemtosection(ci);
+                               subcs = cf_item_to_section(ci);
                                name = cf_section_name1(subcs);
 
                                /*
@@ -1826,6 +2054,16 @@ int modules_init(CONF_SECTION *config)
                                                cf_log_err_cs(subcs, "Subsection must have a name");
                                                return -1;
                                        }
+
+                                       if (is_reserved_word(name)) {
+                                               cf_log_err_cs(subcs, "Instantiate sections cannot be named for an 'unlang' keyword");
+                                               return -1;
+                                       }
+                               } else {
+                                       if (is_reserved_word(name)) {
+                                               cf_log_err_cs(subcs, "Instantiate sections cannot be named for an 'unlang' keyword");
+                                               return -1;
+                                       }
                                }
 
                                /*
@@ -1835,14 +2073,17 @@ int modules_init(CONF_SECTION *config)
                                     subci != NULL;
                                     subci=cf_item_find_next(subcs, subci)) {
                                        if (cf_item_is_pair(subci)) {
-                                               cp = cf_itemtopair(subci);
+                                               cp = cf_item_to_pair(subci);
                                                if (cf_pair_value(cp)) {
                                                        cf_log_err(subci, "Cannot set return codes in a %s block",
                                                                   cf_section_name1(subcs));
                                                        return -1;
                                                }
 
-                                               module = find_module_instance(modules, cf_pair_attr(cp), true);
+                                               /*
+                                                *      Allow "foo.authorize" in subsections.
+                                                */
+                                               module = module_instantiate_method(modules, cf_pair_attr(cp), NULL);
                                                if (!module) {
                                                        return -1;
                                                }
@@ -1868,7 +2109,7 @@ int modules_init(CONF_SECTION *config)
                                 *      Register a redundant xlat
                                 */
                                if (all_same) {
-                                       if (!xlat_register_redundant(cf_itemtosection(ci))) {
+                                       if (!xlat_register_redundant(cf_item_to_section(ci))) {
                                                WARN("%s[%d] Not registering expansions for %s",
                                                     cf_section_filename(subcs), cf_section_lineno(subcs),
                                                     cf_section_name2(subcs));
@@ -1877,7 +2118,7 @@ int modules_init(CONF_SECTION *config)
                        }  /* handle subsections */
                } /* loop over the "instantiate" section */
 
-               cf_log_info(cs, " }");
+               cf_log_info(cs, "  }");
        } /* if there's an 'instantiate' section. */
 
        /*
@@ -1886,7 +2127,6 @@ int modules_init(CONF_SECTION *config)
         *      because we've now split up the modules into
         *      mods-enabled.
         */
-       cf_log_info(cs, " modules {");
        for (ci=cf_item_find_next(modules, NULL);
             ci != NULL;
             ci=next) {
@@ -1898,14 +2138,14 @@ int modules_init(CONF_SECTION *config)
 
                if (!cf_item_is_section(ci)) continue;
 
-               subcs = cf_itemtosection(ci);
+               subcs = cf_item_to_section(ci);
                name = cf_section_name2(subcs);
                if (!name) name = cf_section_name1(subcs);
 
-               module = find_module_instance(modules, name, true);
+               module = module_instantiate(modules, name);
                if (!module) return -1;
        }
-       cf_log_info(cs, " } # modules");
+       cf_log_info(config, " } # modules");
 
        if (virtual_servers_load(config) < 0) return -1;
 
@@ -1918,7 +2158,7 @@ int modules_init(CONF_SECTION *config)
  */
 rlm_rcode_t process_authorize(int autz_type, REQUEST *request)
 {
-       return indexed_modcall(RLM_COMPONENT_AUTZ, autz_type, request);
+       return indexed_modcall(MOD_AUTHORIZE, autz_type, request);
 }
 
 /*
@@ -1926,7 +2166,7 @@ rlm_rcode_t process_authorize(int autz_type, REQUEST *request)
  */
 rlm_rcode_t process_authenticate(int auth_type, REQUEST *request)
 {
-       return indexed_modcall(RLM_COMPONENT_AUTH, auth_type, request);
+       return indexed_modcall(MOD_AUTHENTICATE, auth_type, request);
 }
 
 #ifdef WITH_ACCOUNTING
@@ -1935,7 +2175,7 @@ rlm_rcode_t process_authenticate(int auth_type, REQUEST *request)
  */
 rlm_rcode_t module_preacct(REQUEST *request)
 {
-       return indexed_modcall(RLM_COMPONENT_PREACCT, 0, request);
+       return indexed_modcall(MOD_PREACCT, 0, request);
 }
 
 /*
@@ -1943,7 +2183,7 @@ rlm_rcode_t module_preacct(REQUEST *request)
  */
 rlm_rcode_t process_accounting(int acct_type, REQUEST *request)
 {
-       return indexed_modcall(RLM_COMPONENT_ACCT, acct_type, request);
+       return indexed_modcall(MOD_ACCOUNTING, acct_type, request);
 }
 #endif
 
@@ -1964,7 +2204,7 @@ int process_checksimul(int sess_type, REQUEST *request, int maxsimul)
        request->simul_max = maxsimul;
        request->simul_mpp = 1;
 
-       rcode = indexed_modcall(RLM_COMPONENT_SESS, sess_type, request);
+       rcode = indexed_modcall(MOD_SESSION, sess_type, request);
 
        if (rcode != RLM_MODULE_OK) {
                /* FIXME: Good spot for a *rate-limited* warning to the log */
@@ -1981,7 +2221,7 @@ int process_checksimul(int sess_type, REQUEST *request, int maxsimul)
  */
 rlm_rcode_t process_pre_proxy(int type, REQUEST *request)
 {
-       return indexed_modcall(RLM_COMPONENT_PRE_PROXY, type, request);
+       return indexed_modcall(MOD_PRE_PROXY, type, request);
 }
 
 /*
@@ -1989,7 +2229,7 @@ rlm_rcode_t process_pre_proxy(int type, REQUEST *request)
  */
 rlm_rcode_t process_post_proxy(int type, REQUEST *request)
 {
-       return indexed_modcall(RLM_COMPONENT_POST_PROXY, type, request);
+       return indexed_modcall(MOD_POST_PROXY, type, request);
 }
 #endif
 
@@ -1998,17 +2238,17 @@ rlm_rcode_t process_post_proxy(int type, REQUEST *request)
  */
 rlm_rcode_t process_post_auth(int postauth_type, REQUEST *request)
 {
-       return indexed_modcall(RLM_COMPONENT_POST_AUTH, postauth_type, request);
+       return indexed_modcall(MOD_POST_AUTH, postauth_type, request);
 }
 
 #ifdef WITH_COA
 rlm_rcode_t process_recv_coa(int recv_coa_type, REQUEST *request)
 {
-       return indexed_modcall(RLM_COMPONENT_RECV_COA, recv_coa_type, request);
+       return indexed_modcall(MOD_RECV_COA, recv_coa_type, request);
 }
 
 rlm_rcode_t process_send_coa(int send_coa_type, REQUEST *request)
 {
-       return indexed_modcall(RLM_COMPONENT_SEND_COA, send_coa_type, request);
+       return indexed_modcall(MOD_SEND_COA, send_coa_type, request);
 }
 #endif