From: Alan T. DeKok Date: Wed, 5 Apr 2023 19:08:30 +0000 (-0400) Subject: force RHS of edits to use full paths when referencing an attribute X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=532ac5f2ecdd7150872634a3616deea7e9f9d0c5;p=thirdparty%2Ffreeradius-server.git force RHS of edits to use full paths when referencing an attribute because it's crazy to do &reply += { &User-Name = &User-Name } --- diff --git a/src/lib/server/map.c b/src/lib/server/map.c index 43d2494a88..f50233be8f 100644 --- a/src/lib/server/map.c +++ b/src/lib/server/map.c @@ -725,6 +725,8 @@ static int _map_afrom_cs(TALLOC_CTX *ctx, map_list_t *out, map_t *parent, CONF_S tmpl_rules_t our_lhs_rules = *lhs_rules; /* Mutable copy of the destination */ TALLOC_CTX *tmp_ctx = NULL; /* Temporary context for request lists */ + tmpl_rules_t child_rhs_rules = *rhs_rules; + tmpl_rules_t const *our_rhs_rules; /* * The first map has ctx as the parent context. @@ -908,7 +910,33 @@ do_children: cp = cf_item_to_pair(ci); fr_assert(cp != NULL); - if (map_afrom_cp(parent_ctx, &map, parent, cp, &child_lhs_rules, rhs_rules, edit) < 0) { + /* + * Over-ride RHS rules for + * + * &reply += { + * &User-Name = &User-Name + * } + * + * Which looks stupid. Instead we require + * + * &reply += { + * &User-Name = &request.User-Name + * } + * + * On the other hand, any xlats on the RHS don't use the full path. :( And we still need + * to allow relative attribute references via "&.foo", when updating structures. + */ + our_rhs_rules = rhs_rules; + if (edit && (rhs_rules->attr.list_def != child_lhs_rules.attr.list_def)) { + char const *value = cf_pair_value(cp); + + if (value && (*value == '&')) { + child_rhs_rules.attr.list_presence = TMPL_ATTR_LIST_REQUIRE; + our_rhs_rules = &child_rhs_rules; + } + } + + if (map_afrom_cp(parent_ctx, &map, parent, cp, &child_lhs_rules, our_rhs_rules, edit) < 0) { cf_log_err(ci, "Failed creating map from '%s = %s'", cf_pair_attr(cp), cf_pair_value(cp)); goto error;