]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
allow and handled regexes
authorAlan T. DeKok <aland@freeradius.org>
Mon, 28 Aug 2023 21:10:14 +0000 (17:10 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 28 Aug 2023 21:10:14 +0000 (17:10 -0400)
src/modules/rlm_files/rlm_files.c

index d6baea9d21dae8415fb4abefa9bb5382ce69597f..439ef73f2eadc50a04e8e9a01e681977f4a80c82 100644 (file)
@@ -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);
 }