]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
warn about unused "send" and "recv" sections.
authorAlan T. DeKok <aland@freeradius.org>
Tue, 12 Sep 2017 14:24:13 +0000 (10:24 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 12 Sep 2017 14:24:13 +0000 (10:24 -0400)
And if -C is used, it's a hard error

src/main/virtual_servers.c

index 1c7aac2507c4b619efa59533c1243f0d49b096c5..03a88541175e567bbbe22f688056140d8879b27d 100644 (file)
@@ -52,6 +52,7 @@ static int default_component_results[MOD_COUNT] = {
 };
 
 typedef struct {
+       CONF_SECTION            *server_cs;     //!< what a hack...
        dl_instance_t           *proto_module;  //!< The proto_* module for a listen section.
        fr_app_t const          *app;           //!< Easy access to the exported struct.
 } fr_virtual_listen_t;
@@ -111,6 +112,8 @@ static int listen_parse(TALLOC_CTX *ctx, void *out, CONF_ITEM *ci, UNUSED CONF_P
 
        if (DEBUG_ENABLED4) cf_log_debug(ci, "Loading %s listener into %p", cf_pair_value(namespace), out);
 
+       listen->server_cs = server;
+
        if (dl_instance(ctx, &listen->proto_module, listen_cs, NULL, cf_pair_value(namespace), DL_TYPE_PROTO) < 0) {
                cf_log_err(listen_cs, "Failed loading proto module");
                return -1;
@@ -376,6 +379,7 @@ int virtual_servers_open(fr_schedule_t *sc)
        return 0;
 }
 
+
 /** Instantiate all the virtual servers
  *
  * @param[in] config   section containing all the virtual servers.
@@ -394,6 +398,8 @@ int virtual_servers_instantiate(UNUSED CONF_SECTION *config)
        for (i = 0; i < server_cnt; i++) {
                fr_virtual_listen_t     **listener;
                size_t                  j, listen_cnt;
+               CONF_ITEM               *ci;
+               CONF_SECTION            *cs;
 
                listener = virtual_servers[i]->listener;
                listen_cnt = talloc_array_length(listener);
@@ -412,6 +418,37 @@ int virtual_servers_instantiate(UNUSED CONF_SECTION *config)
                        }
                }
 
+               /*
+                *      Print out warnings for unused "recv" and
+                *      "send" sections.
+                */
+               cs = listener[0]->server_cs;
+               for (ci = cf_item_next(cs, NULL);
+                    ci != NULL;
+                    ci = cf_item_next(cs, ci)) {
+                       char const *name;
+                       CONF_SECTION *subcs;
+
+                       if (!cf_item_is_section(ci)) continue;
+
+
+                       subcs = cf_item_to_section(ci);
+                       name = cf_section_name1(subcs);
+
+                       if ((strcmp(name, "recv") != 0) &&
+                           (strcmp(name, "send") != 0)) continue;
+
+                       if (!cf_data_find(subcs, unlang_group_t, NULL)) {
+                               if (check_config) {
+                                       cf_log_err(subcs, "%s %s { ... } section is unused",
+                                                   name, cf_section_name2(subcs));
+                                       return -1;
+                               }
+
+                               cf_log_warn(subcs, "%s %s { ... } section is unused",
+                                       name, cf_section_name2(subcs));
+                       }
+               }
        }
 
        return 0;
@@ -451,7 +488,7 @@ int virtual_servers_bootstrap(CONF_SECTION *config)
                }
 
                /*
-                *      Skip old-style virtual servers.
+                *      Forbid old-style virtual servers.
                 */
                if (!cf_pair_find(cs, "namespace")) {
                        cf_log_err(cs, "server sections must set 'namesspace = ...'");