From: Alan T. DeKok Date: Wed, 28 Mar 2012 14:49:13 +0000 (+0200) Subject: Added '-name" to conditionally load a module X-Git-Tag: release_3_0_0_beta0~244 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9ee75fe6783af3b1dd4f66a4005c1e3ce109d8e6;p=thirdparty%2Ffreeradius-server.git Added '-name" to conditionally load a module Now that we have mods-enabled, we can more easily conditionally load a module. --- diff --git a/src/main/modcall.c b/src/main/modcall.c index 15449727cad..10320afc5ba 100644 --- a/src/main/modcall.c +++ b/src/main/modcall.c @@ -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; diff --git a/src/main/modules.c b/src/main/modules.c index 7aa71fa7db9..20a09dcffc9 100644 --- a/src/main/modules.c +++ b/src/main/modules.c @@ -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 */