]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Added '-name" to conditionally load a module
authorAlan T. DeKok <aland@freeradius.org>
Wed, 28 Mar 2012 14:49:13 +0000 (16:49 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 28 Mar 2012 14:49:13 +0000 (16:49 +0200)
Now that we have mods-enabled, we can more easily conditionally
load a module.

src/main/modcall.c
src/main/modules.c

index 15449727cada3756136d89c718e8cdf261e9edde..10320afc5baa747afa357f7567748a9f4fa04693 100644 (file)
@@ -2140,7 +2140,16 @@ static modcallable *do_compile_modsingle(modcallable *parent,
                        return do_compile_modserver(parent, component, ci,
                                                    modrefname, cs, buffer);
                }
-               
+
+               /*
+                *      We tried to load the module, but it doesn't exist.
+                *      Give a silent error.
+                */
+               if (modrefname[0] == '-') {
+                       *modname = modrefname;
+                       return NULL;
+               }
+
                *modname = NULL;
                cf_log_err(ci, "Failed to find \"%s\" in the \"modules\" section.", modrefname);
                return NULL;
index 7aa71fa7db91b26510aabb08d2fab24c54975381..20a09dcffc908166ce9fcef09d37b60c48056063 100644 (file)
@@ -574,16 +574,24 @@ static module_entry_t *linkto_module(const char *module_name,
  *     Find a module instance.
  */
 module_instance_t *find_module_instance(CONF_SECTION *modules,
-                                       const char *instname, int do_link)
+                                       const char *askedname, int do_link)
 {
        int check_config_safe = FALSE;
        CONF_SECTION *cs;
-       const char *name1;
+       const char *name1, *instname;
        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."
+        */
+       instname = askedname;
+       if (instname[0] == '-') instname++;
+
        /*
         *      Module instances are declared in the modules{} block
         *      and referenced later by their name, which is the
@@ -942,6 +950,15 @@ static int load_component_section(CONF_SECTION *cs,
                 *      Try to compile one entry.
                 */
                this = compile_modsingle(NULL, comp, modref, &modname);
+
+               /*
+                *      It's OK for the module to not exist.
+                */
+               if (!this && (modname[0] == '-')) {
+                       DEBUG("WARNING: Not loading module \"%s\" as it is not enabled", modname + 1);
+                       continue;
+               }
+
                if (!this) {
                        cf_log_err(cf_sectiontoitem(cs),
                                   "Errors parsing %s section.\n",
@@ -1579,7 +1596,7 @@ int setup_modules(int reload, CONF_SECTION *config)
                        cp = cf_itemtopair(ci);
                        name = cf_pair_attr(cp);
                        module = find_module_instance(modules, name, 1);
-                       if (!module) {
+                       if (!module && (name[0] != '-')) {
                                return -1;
                        }
                } /* loop over items in the subsection */