]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
leave fewer unresolved tmpls at runtime
authorAlan T. DeKok <aland@freeradius.org>
Wed, 20 Dec 2023 14:10:25 +0000 (09:10 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 20 Dec 2023 15:16:05 +0000 (10:16 -0500)
If it's runtime, then we know an enum name can't possibly match
at some point in the future.  We we just parse it now as the
expected data type.

src/lib/server/tmpl_tokenize.c

index c929e41c66fd3041b6d36bd566138f67b3f76157..4fed053d2b4b1e41a05e46ebec5d86c3aae30144 100644 (file)
@@ -2987,6 +2987,13 @@ static ssize_t tmpl_afrom_enum(TALLOC_CTX *ctx, tmpl_t **out, fr_sbuff_t *in,
                }
        }
 
+       /*
+        *      Either there's no enum, or the enum name didn't match one of the listed ones.  There's no
+        *      point in waiting for an enum which might be declared later.  That's not possible, so we fall
+        *      back to parsing the various data types.
+        */
+       if (t_rules->at_runtime) return 0;
+
        tmpl_init(vpt, TMPL_TYPE_DATA_UNRESOLVED, T_BARE_WORD,
                  fr_sbuff_start(&our_in), fr_sbuff_used(&our_in), t_rules);
        vpt->data.unescaped = str;
@@ -3079,6 +3086,21 @@ fr_slen_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out,
                if (!fr_type_is_null(t_rules->cast)) return tmpl_afrom_value_substr(ctx, out, in, quote,
                                                                                    t_rules, true, p_rules);
 
+               /*
+                *      We're at runtime and have a data type.  Just parse it as that data type, without doing
+                *      endless "maybe it's this thing" attempts.
+                */
+               if (t_rules->at_runtime && t_rules->enumv) {
+                       tmpl_rules_t my_t_rules = *t_rules;
+
+                       fr_assert(fr_type_is_leaf(t_rules->enumv->type));
+
+                       my_t_rules.cast = my_t_rules.enumv->type;
+
+                       return tmpl_afrom_value_substr(ctx, out, in, quote,
+                                                      &my_t_rules, true, p_rules);
+               }
+
                /*
                 *      See if it's a boolean value
                 */