]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add parse_new_conditions migration flag
authorAlan T. DeKok <aland@freeradius.org>
Fri, 14 Jul 2023 13:27:36 +0000 (09:27 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 14 Jul 2023 13:30:58 +0000 (09:30 -0400)
and set it to "true" by default.  So that the condition tests
will all be run through both the old fr_cond_tokenize() function,
and the new xlat_tokenize_condition() function.

src/bin/unit_test_attribute.c

index 5f3906f855d2c6179622453ec2f0130b6d844daa..c542d29585520f6d5dd35256735431727a35042b 100644 (file)
@@ -265,6 +265,7 @@ static xlat_action_t xlat_test(UNUSED TALLOC_CTX *ctx, UNUSED fr_dcursor_t *out,
 static char            proto_name_prev[128];
 static dl_t            *dl;
 static dl_loader_t     *dl_loader = NULL;
+static bool            parse_new_conditions = true;
 
 static fr_event_list_t *el = NULL;
 
@@ -1462,7 +1463,7 @@ static size_t command_radmin_tab(command_result_t *result, command_file_ctx_t *c
 static size_t command_condition_normalise(command_result_t *result, command_file_ctx_t *cc,
                                          char *data, UNUSED size_t data_used, char *in, size_t inlen)
 {
-       ssize_t                 dec_len;
+       ssize_t                 slen;
        fr_cond_t               *cond;
        CONF_SECTION            *cs;
        size_t                  len;
@@ -1475,9 +1476,11 @@ static size_t command_condition_normalise(command_result_t *result, command_file
        cf_filename_set(cs, cc->filename);
        cf_lineno_set(cs, cc->lineno);
 
-       dec_len = fr_cond_tokenize(cs, &cond, &cc->tmpl_rules, &FR_SBUFF_IN(in, inlen), false);
-       if (dec_len <= 0) {
-               fr_strerror_printf_push_head("ERROR offset %d", (int) -dec_len);
+       fr_skip_whitespace(in);
+
+       slen = fr_cond_tokenize(cs, &cond, &cc->tmpl_rules, &FR_SBUFF_IN(in, inlen), false);
+       if (slen <= 0) {
+               fr_strerror_printf_push_head("ERROR offset %d", (int) -slen);
 
        return_error:
                talloc_free(cs);
@@ -1491,12 +1494,29 @@ static size_t command_condition_normalise(command_result_t *result, command_file
                }
        }
 
-       in += dec_len;
-       if (*in != '\0') {
-               fr_strerror_printf_push_head("ERROR offset %d 'Too much text'", (int) dec_len);
+       if (in[slen] != '\0') {
+               fr_strerror_printf_push_head("ERROR offset %d 'Too much text'", (int) slen);
                goto return_error;
        }
 
+       /*
+        *      Use the new condition parser.  Except for !&foo==bar, because the
+        *      new one requires that to be formatted as !(&foo==bar).
+        *
+        *      Perhaps we should just change that?
+        */
+       if (parse_new_conditions && ((in[0] != '!') || (in[1] == '('))) {
+               xlat_exp_head_t *head = NULL;
+
+               slen = xlat_tokenize_condition(cc->tmp_ctx, &head, &FR_SBUFF_IN(in, inlen), NULL, &cc->tmpl_rules);
+               if (slen <= 0) {
+                       fr_strerror_printf_push_head("ERROR in xlat_tokenize_cond offset %d", (int) -slen);
+                       goto return_error;
+               }
+
+               talloc_free(head);
+       }
+
        len = cond_print(&FR_SBUFF_OUT(data, COMMAND_OUTPUT_MAX), cond);
        talloc_free(cs);
 
@@ -2469,6 +2489,10 @@ static size_t command_migrate(command_result_t *result, UNUSED command_file_ctx_
                p += sizeof("pair_legacy_nested") - 1;
                out = &fr_pair_legacy_nested;
 
+       } else if (strncmp(p, "parse_new_conditions", sizeof("parse_new_conditions") - 1) == 0) {
+               p += sizeof("parse_new_conditions") - 1;
+               out = &parse_new_conditions;
+
        } else {
                fr_strerror_const("Unknown migration flag");
                RETURN_PARSE_ERROR(0);