From: Alan T. DeKok Date: Sun, 13 Mar 2011 09:02:33 +0000 (+0100) Subject: Look for duplicate module definitions. X-Git-Tag: release_2_1_11~93 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c31ab5d05c023d647899bb5410083ca57d05a552;p=thirdparty%2Ffreeradius-server.git Look for duplicate module definitions. Doing an O(N^2) search over the modules{} section. If the same module is defined twice, print an error detailing *both* locations where it occurs, and exit. This helps prevent broken configurations by disallowing the server from loading two conflicting module definitions --- diff --git a/src/main/modules.c b/src/main/modules.c index daa46b927f4..d32e4a330f5 100644 --- a/src/main/modules.c +++ b/src/main/modules.c @@ -1333,6 +1333,7 @@ int module_hup(CONF_SECTION *modules) */ int setup_modules(int reload, CONF_SECTION *config) { + CONF_ITEM *ci, *next; CONF_SECTION *cs, *modules; rad_listen_t *listener; @@ -1414,6 +1415,43 @@ int setup_modules(int reload, CONF_SECTION *config) DEBUG2("%s: #### Instantiating modules ####", mainconfig.name); + /* + * 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); + ci != NULL; + ci=next) { + const char *name1, *name2; + CONF_SECTION *subcs, *duplicate; + + next = cf_item_find_next(modules, ci); + + if (!cf_item_is_section(ci)) continue; + + if (!next || !cf_item_is_section(next)) continue; + + subcs = cf_itemtosection(ci); + name1 = cf_section_name1(subcs); + name2 = cf_section_name2(subcs); + + duplicate = cf_section_find_name2(cf_itemtosection(next), + name1, name2); + if (!duplicate) continue; + + if (!name2) name2 = ""; + + radlog(L_ERR, "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; + } + /* * Look for the 'instantiate' section, which tells us * the instantiation order of the modules, and also allows @@ -1422,7 +1460,6 @@ int setup_modules(int reload, CONF_SECTION *config) */ cs = cf_section_sub_find(config, "instantiate"); if (cs != NULL) { - CONF_ITEM *ci; CONF_PAIR *cp; module_instance_t *module; const char *name;