From: Alan T. DeKok Date: Mon, 28 Aug 2023 21:10:14 +0000 (-0400) Subject: allow and handled regexes X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=43c14eb107262faa5dfe99cd29c4ea11c76bbd26;p=thirdparty%2Ffreeradius-server.git allow and handled regexes --- diff --git a/src/modules/rlm_files/rlm_files.c b/src/modules/rlm_files/rlm_files.c index d6baea9d21d..439ef73f2ea 100644 --- a/src/modules/rlm_files/rlm_files.c +++ b/src/modules/rlm_files/rlm_files.c @@ -168,15 +168,12 @@ static int getusersfile(TALLOC_CTX *ctx, char const *filename, fr_htrie_t **ptre * Disallow regexes for now. */ if ((map->op == T_OP_REG_EQ) || (map->op == T_OP_REG_NE)) { - ERROR("%s[%d] Regular expression for check item %s is not supported", - entry->filename, entry->lineno, map->lhs->name); - return -1; - } + fr_assert(tmpl_is_regex(map->rhs)); /* * Disallow inter-attribute comparisons. */ - if (!tmpl_is_data(map->rhs)) { + } else if (!tmpl_is_data(map->rhs)) { ERROR("%s[%d] Right side of check item %s is not a leaf value", entry->filename, entry->lineno, map->lhs->name); return -1; @@ -404,6 +401,15 @@ static bool files_eval_map(request_t *request, map_t *map) if (tmpl_find_vp(&vp, request, map->lhs) < 0) return false; + /* + * The RHS is a compiled regex, which we don't yet + * support. So just re-parse it at run time for + * programmer laziness. + */ + if ((map->op == T_OP_REG_EQ) || (map->op == T_OP_REG_NE)) { + return (fr_regex_cmp_op(map->op, &vp->data, fr_box_strvalue(map->rhs->name)) == 1); + } + return (fr_value_box_cmp_op(map->op, &vp->data, tmpl_value(map->rhs)) == 1); }