From: Alan T. DeKok Date: Sat, 14 Dec 2024 16:54:44 +0000 (+0100) Subject: add optional CONF_SECTION parsers, and use in rlm_radius X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6fafc59ca45c9da37f65d11d7a31e4eb4168df6b;p=thirdparty%2Ffreeradius-server.git add optional CONF_SECTION parsers, and use in rlm_radius this lets the RADIUS module put more things into a "udp" section, but only if the "udp" section ends up being used by the transport configuration. The RADIUS module can also push rules for "tcp", but those rules don't show up in the debug output (and are ignored by the parser) if a corresponding "tcp" section is defined --- diff --git a/src/lib/server/cf_parse.c b/src/lib/server/cf_parse.c index 301d53de1f6..a818e4f92a8 100644 --- a/src/lib/server/cf_parse.c +++ b/src/lib/server/cf_parse.c @@ -730,6 +730,13 @@ static int cf_section_parse_init(CONF_SECTION *cs, void *base, conf_parser_t con char const *name2 = NULL; CONF_SECTION *subcs; + /* + * Optional MUST be listed before required ones + */ + if ((rule->flags & CONF_FLAG_OPTIONAL) != 0) { + return 0; + } + subcs = cf_section_find(cs, rule->name1, rule->name2); /* @@ -1483,6 +1490,13 @@ int _cf_section_rule_push(CONF_SECTION *cs, conf_parser_t const *rule, char cons return -1; } + /* + * The old rules were delayed until we pushed a matching subsection which is actually used. + */ + if ((old->flags & CONF_FLAG_OPTIONAL) != 0) { + if (cf_section_rules_push(subcs, old->subcs) < 0) return -1; + } + return cf_section_rules_push(subcs, rule->subcs); } diff --git a/src/lib/server/cf_parse.h b/src/lib/server/cf_parse.h index 42fcfa4cc19..b7a3496ac94 100644 --- a/src/lib/server/cf_parse.h +++ b/src/lib/server/cf_parse.h @@ -441,6 +441,7 @@ typedef enum CC_HINT(flag_enum) { CONF_FLAG_HIDDEN = (1 << 23), //!< Used by scripts to omit items from the ///< generated documentation. CONF_FLAG_REF = (1 << 24), //!< reference another conf_parser_t inline in this one + CONF_FLAG_OPTIONAL = (1 << 25), //!< subsection is pushed only if a non-optional matching one is pushed } conf_parser_flags_t; DIAG_ON(attributes) diff --git a/src/modules/rlm_radius2/rlm_radius.c b/src/modules/rlm_radius2/rlm_radius.c index 4defcb5f3d0..0e6b5da5885 100644 --- a/src/modules/rlm_radius2/rlm_radius.c +++ b/src/modules/rlm_radius2/rlm_radius.c @@ -94,6 +94,12 @@ static conf_parser_t disconnect_config[] = { CONF_PARSER_TERMINATOR }; +static conf_parser_t const transport_config[] = { + { FR_CONF_OFFSET_FLAGS("secret", CONF_FLAG_REQUIRED, rlm_radius_t, secret) }, + + CONF_PARSER_TERMINATOR +}; + /* * A mapping of configuration file names to internal variables. @@ -109,8 +115,6 @@ static conf_parser_t const module_config[] = { { FR_CONF_OFFSET_FLAGS("type", CONF_FLAG_NOT_EMPTY | CONF_FLAG_MULTI | CONF_FLAG_REQUIRED, rlm_radius_t, types), .func = type_parse }, - { FR_CONF_OFFSET_FLAGS("secret", CONF_FLAG_REQUIRED, rlm_radius_t, secret) }, - { FR_CONF_OFFSET("max_packet_size", rlm_radius_t, max_packet_size), .dflt = "4096" }, { FR_CONF_OFFSET("max_send_coalesce", rlm_radius_t, max_send_coalesce), .dflt = "1024" }, @@ -137,6 +141,10 @@ static conf_parser_t const module_config[] = { { FR_CONF_OFFSET_SUBSECTION("pool", 0, rlm_radius_t, trunk_conf, trunk_config ) }, + { FR_CONF_POINTER("udp", 0, CONF_FLAG_SUBSECTION | CONF_FLAG_OPTIONAL, NULL), .subcs = (void const *) transport_config }, + + { FR_CONF_POINTER("tcp", 0, CONF_FLAG_SUBSECTION | CONF_FLAG_OPTIONAL, NULL), .subcs = (void const *) transport_config } +, CONF_PARSER_TERMINATOR };