]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Look for duplicate module definitions.
authorAlan T. DeKok <aland@freeradius.org>
Sun, 13 Mar 2011 09:02:33 +0000 (10:02 +0100)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 13 Mar 2011 09:02:33 +0000 (10:02 +0100)
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

src/main/modules.c

index daa46b927f47a64d84df2e5649c51cd18f516183..d32e4a330f5a366bad059f3fd8e8711712d67932 100644 (file)
@@ -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;