]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add CALL_ENV_FLAG_PARSE_MISSING
authorNick Porter <nick@portercomputing.co.uk>
Fri, 15 Dec 2023 16:50:30 +0000 (16:50 +0000)
committerNick Porter <nick@portercomputing.co.uk>
Fri, 15 Dec 2023 16:50:30 +0000 (16:50 +0000)
For the case where the parser should still run for missing sections - to
run the parsing callback function.

src/lib/unlang/call_env.c
src/lib/unlang/call_env.h

index f1c6fe19a4bb22e530b4b0d6707f18bc8920ba9d..f62efb5295c901c88301d1e63afdd26ad92a9d1f 100644 (file)
@@ -353,7 +353,7 @@ static int call_env_parse(TALLOC_CTX *ctx, call_env_parsed_head_t *parsed, char
                if (call_env_is_subsection(rule->flags)) {
                        CONF_SECTION const *subcs;
                        subcs = cf_section_find(cs, rule->name, rule->section.ident2);
-                       if (!subcs) {
+                       if (!subcs && !call_env_parse_missing(rule->flags)) {
                                if (!call_env_required(rule->flags)) goto next;
                                cf_log_err(cs, "Module %s missing required section \"%s\"", name, rule->name);
                                return -1;
index 48ee07ae25815513f180df73f335d980df1cc2bd..5e0c85e142e0e43d2b56f9c741955b4ad55d4cc3 100644 (file)
@@ -80,7 +80,10 @@ typedef enum CC_HINT(flag_enum) {
                                                                ///< option of `rlm_exec` should always be parsed as T_BACK_QUOTED_STRING.
        CALL_ENV_FLAG_PARSE_ONLY        = (1 << 6),             //!< The result of parsing will not be evaluated at runtime.
        CALL_ENV_FLAG_ATTRIBUTE         = (1 << 7),             //!< Tmpl must contain an attribute reference.
-       CALL_ENV_FLAG_SUBSECTION        = (1 << 8)              //!< This is a subsection.
+       CALL_ENV_FLAG_SUBSECTION        = (1 << 8),             //!< This is a subsection.
+       CALL_ENV_FLAG_PARSE_MISSING     = (1 << 9)              //!< If this subsection is missing, still parse it.  Useful for cases where
+                                                               ///< there is a callback which always needs to be run to set up required
+                                                               ///< data structures.
 } call_env_flags_t;
 DIAG_ON(attributes)
 
@@ -99,7 +102,7 @@ DIAG_ON(attributes)
  *
  * @param[in] _flags to evaluate
  */
-#define call_env_subsection_flags(_flags)      (((_flags) & (CALL_ENV_FLAG_CONCAT | CALL_ENV_FLAG_SINGLE | CALL_ENV_FLAG_MULTI | CALL_ENV_FLAG_NULLABLE | CALL_ENV_FLAG_FORCE_QUOTE | CALL_ENV_FLAG_ATTRIBUTE)) == 0)
+#define call_env_subsection_flags(_flags)      (((_flags) & (CALL_ENV_FLAG_CONCAT | CALL_ENV_FLAG_SINGLE | CALL_ENV_FLAG_MULTI | CALL_ENV_FLAG_NULLABLE | CALL_ENV_FLAG_FORCE_QUOTE | CALL_ENV_FLAG_ATTRIBUTE | CALL_ENV_FLAG_PARSE_MISSING)) == 0)
 
 #define call_env_required(_flags)              ((_flags) & CALL_ENV_FLAG_REQUIRED)
 
@@ -118,6 +121,8 @@ DIAG_ON(attributes)
 #define call_env_attribute(_flags)             ((_flags) & CALL_ENV_FLAG_ATTRIBUTE)
 
 #define call_env_is_subsection(_flags)         ((_flags) & CALL_ENV_FLAG_SUBSECTION)
+
+#define call_env_parse_missing(_flags)         ((_flags) & CALL_ENV_FLAG_PARSE_MISSING)
 /** @} */
 
 /** Callback for performing custom parsing of a #CONF_PAIR