From: Alan T. DeKok Date: Fri, 14 Jul 2023 13:27:36 +0000 (-0400) Subject: add parse_new_conditions migration flag X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9e766d0224c045d944eaa89c9fd0635434b7cab0;p=thirdparty%2Ffreeradius-server.git add parse_new_conditions migration flag 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. --- diff --git a/src/bin/unit_test_attribute.c b/src/bin/unit_test_attribute.c index 5f3906f855d..c542d295855 100644 --- a/src/bin/unit_test_attribute.c +++ b/src/bin/unit_test_attribute.c @@ -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);