]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
mark sections as parsed when they're parsed, and complain on -C
authorAlan T. DeKok <aland@freeradius.org>
Thu, 29 Jan 2026 18:58:20 +0000 (13:58 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 29 Jan 2026 19:32:23 +0000 (14:32 -0500)
if we have "send FOO" or "recv BAR" which is unused, then that's
an error when using -C.

Otherwise, a warning message is produced.

src/lib/server/cf_parse.c
src/lib/server/client.c
src/lib/server/virtual_servers.c
src/lib/unlang/compile.c

index 6c8cdc71d30484d235d91fbb801e581c0e403218..110b7ab2e14fd2d21179132a12954d7ea0bcf2ec 100644 (file)
@@ -1226,6 +1226,7 @@ int cf_section_parse(TALLOC_CTX *ctx, void *base, CONF_SECTION *cs)
 
        cf_log_debug(cs, "%.*s}", SECTION_SPACE(cs), parse_spaces);
 
+       cf_item_mark_parsed(cs);
        return 0;
 }
 
index d1eac20cbd8e08a1a7811ae1e95fbd7085153fbc..952adce70d9d4c95a228b505b3427da79bedc2f2 100644 (file)
@@ -584,6 +584,7 @@ fr_client_list_t *client_list_parse_section(CONF_SECTION *section, int proto, TL
                        goto error;
                }
 
+               cf_item_mark_parsed(cs);
        }
 
        /*
@@ -916,6 +917,7 @@ fr_client_t *client_afrom_cs(TALLOC_CTX *ctx, CONF_SECTION *cs, CONF_SECTION *se
                        c->limit.idle_timeout = fr_time_delta_wrap(0);
        }
 
+       cf_item_mark_parsed(cs);
        return c;
 }
 
index 617cc7eb4f3491d38b0296074c7eb153b09edb59..c30cd11dde87a22e08e13cd8530dbe8b14ac57c3 100644 (file)
@@ -1379,6 +1379,50 @@ static int virtual_server_compile_sections(virtual_server_t *vs, tmpl_rules_t co
                return -1;
        }
 
+       if (!check_config && !DEBUG_ENABLED) return found;
+
+       /*
+        *      Check for 'send FOO' and 'recv BAR' which are unused.
+        */
+       for (subcs = cf_section_first(server);
+            subcs != NULL;
+            subcs = cf_section_next(server, subcs)) {
+               char const *name, *name2;
+
+               if (cf_item_is_parsed(subcs)) continue;
+
+               name = cf_section_name1(subcs);
+
+               /*
+                *      Allow them to "comment out" an entire block by prefixing the name with "-", ala
+                *      "-sql".
+                */
+               if (*name == '-') continue;
+
+               /*
+                *      Local clients are parsed by the listener after the virtual server is bootstrapped.  So
+                *      we just ignore them here.
+                */
+               if (strcmp(name, "client") == 0) continue;
+
+               /*
+                *      When checking the configuration, it is an error to have an unused "send FOO" or "recv
+                *      BAR" section.
+                */
+               if (check_config && ((strcmp(name, "recv") == 0) || (strcmp(name, "send") == 0))) {
+                       cf_log_err(subcs, "Unused processing section %s ... {", name);
+                       cf_log_err(subcs, "If this is intentional, please rename it to '-%s'", name);
+                       return -1;
+               }
+
+               name2 = cf_section_name2(subcs);
+               if (!name2) {
+                       cf_log_warn(subcs, "Ignoring %s { - it is unused", name);
+               } else {
+                       cf_log_warn(subcs, "Ignoring %s %s { - it is unused", name, name2);
+               }
+       }
+
        return found;
 }
 
@@ -1738,6 +1782,7 @@ static fr_dict_t const *virtual_server_local_dict(CONF_SECTION *server_cs, fr_di
         */
        cf_data_remove(server_cs, fr_dict_t, "dict");
        cf_data_add(server_cs, dict, "dict", false);
+       cf_item_mark_parsed(cs);
 
        return dict;
 }
index 851fe14a35e8f4e61ade0f032fd41047fd2ee8b5..f03b9456a438e5200ff9d7741665f76142f962b4 100644 (file)
@@ -2233,6 +2233,7 @@ int unlang_compile(virtual_server_t const *vs,
         *      section is freed.
         */
        cf_data_add(cs, c, NULL, true);
+       cf_item_mark_parsed(cs);
        if (instruction) *instruction = c;
 
        return 0;