From: Alan T. DeKok Date: Fri, 28 Mar 2025 14:03:04 +0000 (-0400) Subject: always parse the LHS of a map as an attribute X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=82d32c20f9fd3b744cc1bd358f99487d0f7fce2e;p=thirdparty%2Ffreeradius-server.git always parse the LHS of a map as an attribute --- diff --git a/src/lib/server/map.c b/src/lib/server/map.c index 53718e0ae3f..737a0a4e2fc 100644 --- a/src/lib/server/map.c +++ b/src/lib/server/map.c @@ -501,53 +501,60 @@ ssize_t map_afrom_substr(TALLOC_CTX *ctx, map_t **out, map_t **parent_p, fr_sbuf our_lhs_rules = *lhs_rules; + /* + * Bare words on the LHS are always attributes. + * + * It doesn't make sense to allow "5 = 4". Or, "5 = NAS-Port". + * + * The conditions do allow "5 == NAS-Port", but + * they use a different parser for that. + */ + + /* + * Absolute references are from the root. + */ + if (!fr_sbuff_next_if_char(&our_in, '.')) { + parent = NULL; + + lhs_root: + slen = tmpl_afrom_attr_substr(map, NULL, &map->lhs, &our_in, + &map_parse_rules_bareword_quoted, &our_lhs_rules); + break; + } + /* * Allow for ".foo" to refer to the current * parents list. Allow for "..foo" to refer to * the grandparent list. */ - if (our_lhs_rules.attr.prefix != TMPL_ATTR_REF_PREFIX_YES) { - /* - * Absolute references are from the root. - */ - if (!fr_sbuff_next_if_char(&our_in, '.')) { - parent = NULL; - goto lhs_root; - } - /* - * Relative references must have a parent. - */ + /* + * Relative references must have a parent. + */ + if (!parent) { + fr_strerror_const("Unexpected location for relative attribute - no parent attribute exists"); + goto error; + } + + /* + * Multiple '.' means "go to our parents parent". + */ + while (fr_sbuff_next_if_char(&our_in, '.')) { if (!parent) { - fr_strerror_const("Unexpected location for relative attribute - no parent attribute exists"); + fr_strerror_const("Too many '.' in relative reference"); goto error; } + parent = parent->parent; + } - /* - * Multiple '.' means "go to our parents parent". - */ - while (fr_sbuff_next_if_char(&our_in, '.')) { - if (!parent) { - fr_strerror_const("Too many '.' in relative reference"); - goto error; - } - parent = parent->parent; - } - - if (!parent) goto lhs_root; - - /* - * Start looking in the correct parent, not in whatever we were handed. - */ - fr_assert(tmpl_is_attr(parent->lhs)); - our_lhs_rules.attr.namespace = tmpl_attr_tail_da(parent->lhs); + if (!parent) goto lhs_root; - slen = tmpl_afrom_attr_substr(map, NULL, &map->lhs, &our_in, - &map_parse_rules_bareword_quoted, &our_lhs_rules); - break; - } + /* + * Start looking in the correct parent, not in whatever we were handed. + */ + fr_assert(tmpl_is_attr(parent->lhs)); + our_lhs_rules.attr.namespace = tmpl_attr_tail_da(parent->lhs); - lhs_root: slen = tmpl_afrom_attr_substr(map, NULL, &map->lhs, &our_in, &map_parse_rules_bareword_quoted, &our_lhs_rules); break;