From: Alan T. DeKok Date: Tue, 12 Sep 2017 14:24:13 +0000 (-0400) Subject: warn about unused "send" and "recv" sections. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bb929bd1e843e6d2c0afa2c7223e2ab577a13f48;p=thirdparty%2Ffreeradius-server.git warn about unused "send" and "recv" sections. And if -C is used, it's a hard error --- diff --git a/src/main/virtual_servers.c b/src/main/virtual_servers.c index 1c7aac2507c..03a88541175 100644 --- a/src/main/virtual_servers.c +++ b/src/main/virtual_servers.c @@ -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 = ...'");