]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add CONF_ITEM to attr_rules_t, for complaining with -C
authorAlan T. DeKok <aland@freeradius.org>
Wed, 12 Nov 2025 15:37:15 +0000 (10:37 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 12 Nov 2025 16:45:11 +0000 (11:45 -0500)
so that when -C is used, and attribute references begin with '&',
it complains.

This should arguably be a parse error in 4.2

src/lib/server/cf_parse.c
src/lib/server/tmpl.h
src/lib/server/tmpl_tokenize.c
src/lib/unlang/compile.c
src/lib/unlang/condition.c
src/lib/unlang/edit.c

index d631245b2231ee07e6f0596d0838022e70122d61..69ab0591cc4d5832b2e90196cf11dd5234844ee8 100644 (file)
@@ -1281,7 +1281,6 @@ static int cf_parse_tmpl_pass2(UNUSED CONF_SECTION *cs, tmpl_t **out, CONF_PAIR
                        cf_log_err(cp, "Please remove '&' from the attribute name");
                        return -1;
                }
-               cf_log_warn(cp, "Please remove '&' from the attribute name");
                break;
 
        case TMPL_TYPE_DATA:
index 843f1d7b8ddc8e5e0d735e081e74773df46ccad5..d2be6918826d1601038f6ee8d3a28211d0b4fffe 100644 (file)
@@ -298,6 +298,8 @@ struct tmpl_attr_rules_s {
        tmpl_attr_list_presence_t list_presence;        //!< Whether the attribute reference can
                                                        ///< have a list, forbid it, or require it.
 
+       CONF_ITEM               *ci;                    //!< for migration support and various warnings
+
        uint8_t                 allow_unknown:1;        //!< Allow unknown attributes i.e. attributes
                                                        ///< defined by OID string.
 
index e0a8bebd9fdf71efe3306ea85c5e3c8f697d3289..0d5dede74f1993c3b3b168b8e5e1bff01b24ca4f 100644 (file)
@@ -35,7 +35,6 @@ RCSID("$Id$")
 #include <freeradius-devel/util/base16.h>
 #include <freeradius-devel/util/skip.h>
 
-
 /*
  *     For xlat_exp_head_alloc(), because xlat_copy() doesn't create an output head.
  */
@@ -2226,7 +2225,9 @@ ssize_t tmpl_afrom_attr_substr(TALLOC_CTX *ctx, tmpl_attr_error_t *err,
        /*
         *      '&' prefix is ignored.
         */
-       (void) fr_sbuff_next_if_char(&our_name, '&');
+       if (fr_sbuff_next_if_char(&our_name, '&') && check_config && at_rules->ci) {
+               cf_log_warn(at_rules->ci, "Using '&' is no longer necessary when referencing attributes, and should be deleted.");
+       }
 
        /*
         *      We parsed the tmpl as User-Name, but NOT %{User-Name}.
index f60f735fee44717e37a133b1e062f01eeb734f3d..a085fb58f70d534394647b381bdf8bcdf11f8647 100644 (file)
@@ -774,6 +774,7 @@ static unlang_t *compile_edit_pair(unlang_t *parent, unlang_compile_ctx_t *unlan
         */
        t_rules = *(unlang_ctx->rules);
        t_rules.attr.allow_unknown = true;
+       fr_assert(t_rules.attr.ci == cf_pair_to_item(cp));
        RULES_VERIFY(&t_rules);
 
        edit = talloc_zero(parent, unlang_edit_t);
@@ -1292,7 +1293,7 @@ unlang_t *unlang_compile_children(unlang_group_t *g, unlang_compile_ctx_t *unlan
        char const      *skip_else = NULL;
        unlang_compile_ctx_t *unlang_ctx;
        unlang_compile_ctx_t unlang_ctx2;
-       tmpl_rules_t    t_rules;
+       tmpl_rules_t    t_rules, t2_rules; /* yes, it does */
 
        c = unlang_group_to_generic(g);
 
@@ -1301,7 +1302,11 @@ unlang_t *unlang_compile_children(unlang_group_t *g, unlang_compile_ctx_t *unlan
         *      by a variable definition.
         */
        unlang_compile_ctx_copy(&unlang_ctx2, unlang_ctx_in);
+       t2_rules = *(unlang_ctx_in->rules);
+
        unlang_ctx = &unlang_ctx2;
+       unlang_ctx2.rules = &t2_rules;
+
        t_rules = *unlang_ctx_in->rules;
 
        /*
@@ -1310,6 +1315,9 @@ unlang_t *unlang_compile_children(unlang_group_t *g, unlang_compile_ctx_t *unlan
        while ((ci = cf_item_next(g->cs, ci))) {
                if (cf_item_is_data(ci)) continue;
 
+               t_rules.attr.ci = ci;
+               t2_rules.attr.ci = ci;
+
                /*
                 *      Sections are keywords, or references to
                 *      modules with updated return codes.
@@ -1639,6 +1647,8 @@ static unlang_t *compile_function(unlang_t *parent, unlang_compile_ctx_t *unlang
        unlang_compile_ctx_t            unlang_ctx2;
        unlang_t                        *c;
 
+       UPDATE_CTX2;
+
        /*
         *      module.c takes care of ensuring that this is:
         *
@@ -1651,8 +1661,6 @@ static unlang_t *compile_function(unlang_t *parent, unlang_compile_ctx_t *unlang
         *      if it was found here.
         */
        if (cf_section_name2(subcs)) {
-               UPDATE_CTX2;
-
                if (policy) {
                        cf_log_err(subcs, "Unexpected second name in policy");
                        return NULL;
@@ -1661,8 +1669,6 @@ static unlang_t *compile_function(unlang_t *parent, unlang_compile_ctx_t *unlang
                c = compile_item(parent, &unlang_ctx2, cf_section_to_item(subcs));
 
        } else {
-               UPDATE_CTX2;
-
                /*
                 *      We have:
                 *
index bf6b048af39f577da72633ebd61d57c4979f6416..f0c6bd020d4549f507691ba0ca0d50299f11460b 100644 (file)
@@ -162,10 +162,11 @@ static unlang_t *compile_if_subsection(unlang_t *parent, unlang_compile_ctx_t *u
                        .attr = {
                                .dict_def = xr_rules.tr_rules->dict_def,
                                .list_def = request_attr_request,
+                               .ci = cf_section_to_item(cs),
                                .allow_unresolved = false,
                                .allow_unknown = false,
                                .allow_wildcard = true,
-               },
+                       },
                        .literals_safe_for = unlang_ctx->rules->literals_safe_for,
                };
 
index 3150c0ef51ce04a3e6f2d41a0e74bee62399225f..3cc1ae8a13f956b6757e0b6bddd81f96000c70f6 100644 (file)
@@ -132,6 +132,7 @@ static int tmpl_attr_from_result(TALLOC_CTX *ctx, map_t const *map, edit_result_
                                        .attr = {
                                                .dict_def = request->local_dict,
                                                .list_def = request_attr_request,
+                                               .ci = map->ci,
                                        }
                                   });
        if (slen <= 0) {