From: Alan T. DeKok Date: Sat, 21 Jan 2023 21:23:43 +0000 (-0500) Subject: add magic flag for expressions X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5de6240fe3ddff9a27dd550cff43ae91e30bf385;p=thirdparty%2Ffreeradius-server.git add magic flag for expressions so that they always get parsed via xlat_tokenize_expression(). Because if we pass an expression to tmpl_afrom_substr(), it will happily return a tmpl for the entire string, which is a series of string concatenations. And that's not what we want. --- diff --git a/src/lib/server/cf_file.c b/src/lib/server/cf_file.c index 280d8f5d21f..62e5bb23a3b 100644 --- a/src/lib/server/cf_file.c +++ b/src/lib/server/cf_file.c @@ -2460,7 +2460,14 @@ check_for_eol: buff[2][slen] = '\0'; value = buff[2]; - value_token = T_BARE_WORD; + + /* + * Mark it up as an expression + * + * @todo - we should really just call cf_data_add() to add a flag, but this is good for + * now. See map_afrom_cp() + */ + value_token = T_HASH; /* * Skip terminal characters diff --git a/src/lib/server/map.c b/src/lib/server/map.c index c7892600913..30a4b79531b 100644 --- a/src/lib/server/map.c +++ b/src/lib/server/map.c @@ -203,35 +203,22 @@ int map_afrom_cp(TALLOC_CTX *ctx, map_t **out, map_t *parent, CONF_PAIR *cp, value = unescaped_value; p_rules = NULL; - } else if (edit && (type == T_BARE_WORD)) { + } else if (edit && (type == T_HASH)) { fr_slen_t slent; xlat_exp_head_t *head; /* - * Try to parse it as a bare word first. If that - * works, then we leave it as a stand-alone tmpl. - */ - slen = talloc_array_length(value) - 1; - - slen = tmpl_afrom_substr(map, &map->rhs, - &FR_SBUFF_IN(value, slen), - type, - p_rules, - rhs_rules); - if (slen > 0) { - fr_assert(map->rhs); - goto check_rhs; - } - - /* - * Not a bare word, it must be a complex expression. + * Not a bare word, it's marked up as a complex expression. + * + * See cf_file.c, parse_input() and the use of T_HASH when doing alloc_pair, + * in order to see what magic is going on here. */ slen = talloc_array_length(value) - 1; MEM(map->rhs = tmpl_alloc(map, TMPL_TYPE_XLAT, T_BARE_WORD, value, slen)); /* - * @todo - if there's only one thing in the expression, just hoist it to the tmpl? Or do we even need to do that? + * Tokenize the expression. */ slent = xlat_tokenize_expression(map->rhs, &head, &FR_SBUFF_IN(value, slen), p_rules, rhs_rules); if (slent <= 0) { @@ -262,7 +249,6 @@ int map_afrom_cp(TALLOC_CTX *ctx, map_t **out, map_t *parent, CONF_PAIR *cp, goto error; } -check_rhs: if (tmpl_is_attr(map->rhs) && (tmpl_attr_unknown_add(map->rhs) < 0)) { cf_log_perr(cp, "Failed creating attribute %s", map->rhs->name); goto error;