]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add optional CONF_SECTION parsers, and use in rlm_radius
authorAlan T. DeKok <aland@freeradius.org>
Sat, 14 Dec 2024 16:54:44 +0000 (17:54 +0100)
committerAlan T. DeKok <aland@freeradius.org>
Sat, 14 Dec 2024 17:04:23 +0000 (18:04 +0100)
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

src/lib/server/cf_parse.c
src/lib/server/cf_parse.h
src/modules/rlm_radius2/rlm_radius.c

index 301d53de1f673a4e15be6a0f24dcc411fd740c21..a818e4f92a8f2d5bb1583a8ebcf735e3289db139 100644 (file)
@@ -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);
                }
 
index 42fcfa4cc19e91523d1c4e5392386856b40ca44b..b7a3496ac94f0ac08ffcea07762945608cb05e29 100644 (file)
@@ -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)
 
index 4defcb5f3d0dc94488909d67562ad21383c7e6c9..0e6b5da58851ba9cb142e71a031e190e25f11b62 100644 (file)
@@ -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
 };