From: Alan T. DeKok Date: Wed, 12 Nov 2025 15:37:15 +0000 (-0500) Subject: add CONF_ITEM to attr_rules_t, for complaining with -C X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0dd0dd16381729b9d2c5dbed584eaf65c19ab22c;p=thirdparty%2Ffreeradius-server.git add CONF_ITEM to attr_rules_t, for complaining with -C so that when -C is used, and attribute references begin with '&', it complains. This should arguably be a parse error in 4.2 --- diff --git a/src/lib/server/cf_parse.c b/src/lib/server/cf_parse.c index d631245b223..69ab0591cc4 100644 --- a/src/lib/server/cf_parse.c +++ b/src/lib/server/cf_parse.c @@ -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: diff --git a/src/lib/server/tmpl.h b/src/lib/server/tmpl.h index 843f1d7b8dd..d2be6918826 100644 --- a/src/lib/server/tmpl.h +++ b/src/lib/server/tmpl.h @@ -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. diff --git a/src/lib/server/tmpl_tokenize.c b/src/lib/server/tmpl_tokenize.c index e0a8bebd9fd..0d5dede74f1 100644 --- a/src/lib/server/tmpl_tokenize.c +++ b/src/lib/server/tmpl_tokenize.c @@ -35,7 +35,6 @@ RCSID("$Id$") #include #include - /* * 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}. diff --git a/src/lib/unlang/compile.c b/src/lib/unlang/compile.c index f60f735fee4..a085fb58f70 100644 --- a/src/lib/unlang/compile.c +++ b/src/lib/unlang/compile.c @@ -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: * diff --git a/src/lib/unlang/condition.c b/src/lib/unlang/condition.c index bf6b048af39..f0c6bd020d4 100644 --- a/src/lib/unlang/condition.c +++ b/src/lib/unlang/condition.c @@ -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, }; diff --git a/src/lib/unlang/edit.c b/src/lib/unlang/edit.c index 3150c0ef51c..3cc1ae8a13f 100644 --- a/src/lib/unlang/edit.c +++ b/src/lib/unlang/edit.c @@ -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) {