From: Alan T. DeKok Date: Tue, 24 May 2022 18:57:49 +0000 (-0400) Subject: just pass all of the tmpl_rules to the xlat tokenize functions X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bb3710df01bbca0b29c99f2bdad60a6eacf01a93;p=thirdparty%2Ffreeradius-server.git just pass all of the tmpl_rules to the xlat tokenize functions so that they all take the same thing, and so that we have better control over non-attribute parsing --- diff --git a/src/bin/unit_test_attribute.c b/src/bin/unit_test_attribute.c index 1757f6baeec..ba2143e7375 100644 --- a/src/bin/unit_test_attribute.c +++ b/src/bin/unit_test_attribute.c @@ -2672,10 +2672,12 @@ static size_t command_xlat_normalise(command_result_t *result, command_file_ctx_ fr_sbuff_parse_rules_t p_rules = { .escapes = &fr_value_unescape_double }; dec_len = xlat_tokenize(cc->tmp_ctx, &head, &FR_SBUFF_IN(in, input_len), &p_rules, - &(tmpl_attr_rules_t) { - .dict_def = cc->tmpl_rules.attr.dict_def ? + &(tmpl_rules_t) { + .attr = { + .dict_def = cc->tmpl_rules.attr.dict_def ? cc->tmpl_rules.attr.dict_def : cc->config->dict, - .allow_unresolved = cc->tmpl_rules.attr.allow_unresolved + .allow_unresolved = cc->tmpl_rules.attr.allow_unresolved + }, }); if (dec_len <= 0) { fr_strerror_printf_push_head("ERROR offset %d", (int) -dec_len); @@ -2797,10 +2799,12 @@ static size_t command_xlat_argv(command_result_t *result, command_file_ctx_t *cc slen = xlat_tokenize_argv(cc->tmp_ctx, &head, &FR_SBUFF_IN(in, input_len), NULL, - &(tmpl_attr_rules_t) { - .dict_def = cc->tmpl_rules.attr.dict_def ? - cc->tmpl_rules.attr.dict_def : cc->config->dict, - .allow_unresolved = cc->tmpl_rules.attr.allow_unresolved + &(tmpl_rules_t) { + .attr = { + .dict_def = cc->tmpl_rules.attr.dict_def ? + cc->tmpl_rules.attr.dict_def : cc->config->dict, + .allow_unresolved = cc->tmpl_rules.attr.allow_unresolved + }, }); if (slen <= 0) { fr_strerror_printf_push_head("ERROR offset %d", (int) -slen); diff --git a/src/lib/server/cf_parse.c b/src/lib/server/cf_parse.c index d793042edff..2354e90c9e5 100644 --- a/src/lib/server/cf_parse.c +++ b/src/lib/server/cf_parse.c @@ -1484,11 +1484,13 @@ int cf_section_parse_pass2(void *base, CONF_SECTION *cs) */ slen = xlat_tokenize(cs, &xlat, &FR_SBUFF_IN(cp->value, talloc_array_length(cp->value) - 1), NULL, - &(tmpl_attr_rules_t){ - .dict_def = dict, - .allow_unknown = false, - .allow_unresolved = false, - .allow_foreign = (dict == NULL) + &(tmpl_rules_t) { + .attr = { + .dict_def = dict, + .allow_unknown = false, + .allow_unresolved = false, + .allow_foreign = (dict == NULL) + }, }); if (slen < 0) { char *spaces, *text; diff --git a/src/lib/server/tmpl_tokenize.c b/src/lib/server/tmpl_tokenize.c index c7f67b9db92..ce1f73dcb58 100644 --- a/src/lib/server/tmpl_tokenize.c +++ b/src/lib/server/tmpl_tokenize.c @@ -2681,7 +2681,7 @@ ssize_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out, vpt = tmpl_alloc_null(ctx); if (!t_rules->at_runtime) { - slen = xlat_tokenize(vpt, &head, &our_in, p_rules, &t_rules->attr); + slen = xlat_tokenize(vpt, &head, &our_in, p_rules, t_rules); } else { slen = xlat_tokenize_ephemeral(vpt, &head, t_rules->xlat.runtime_el, &our_in, @@ -2865,7 +2865,7 @@ ssize_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out, vpt = tmpl_alloc_null(ctx); if (!t_rules->at_runtime) { - slen = xlat_tokenize(vpt, &head, &our_in, p_rules, &t_rules->attr); + slen = xlat_tokenize(vpt, &head, &our_in, p_rules, t_rules); } else { slen = xlat_tokenize_ephemeral(vpt, &head, t_rules->xlat.runtime_el, &our_in, p_rules, t_rules); @@ -2927,7 +2927,7 @@ ssize_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out, * FIXME - We need an ephemeral version of this * too. */ - slen = xlat_tokenize_argv(vpt, &head, &our_in, p_rules, &t_rules->attr); + slen = xlat_tokenize_argv(vpt, &head, &our_in, p_rules, t_rules); if (slen < 0) { fr_sbuff_advance(&our_in, slen * -1); talloc_free(vpt); @@ -2954,7 +2954,7 @@ ssize_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out, vpt = tmpl_alloc_null(ctx); - slen = xlat_tokenize(vpt, &head, &our_in, p_rules, &t_rules->attr); + slen = xlat_tokenize(vpt, &head, &our_in, p_rules, t_rules); if (!head) return slen; /* diff --git a/src/lib/unlang/xlat.h b/src/lib/unlang/xlat.h index e3b4ea75a08..a27edeb36c7 100644 --- a/src/lib/unlang/xlat.h +++ b/src/lib/unlang/xlat.h @@ -304,10 +304,10 @@ ssize_t xlat_tokenize_ephemeral(TALLOC_CTX *ctx, xlat_exp_head_t **head, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules); ssize_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_head_t **head, fr_sbuff_t *in, - fr_sbuff_parse_rules_t const *p_rules, tmpl_attr_rules_t const *t_rules); + fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules); ssize_t xlat_tokenize(TALLOC_CTX *ctx, xlat_exp_head_t **head, fr_sbuff_t *in, - fr_sbuff_parse_rules_t const *p_rules, tmpl_attr_rules_t const *t_rules); + fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules); ssize_t xlat_print(fr_sbuff_t *in, xlat_exp_head_t const *node, fr_sbuff_escape_rules_t const *e_rules); diff --git a/src/lib/unlang/xlat_priv.h b/src/lib/unlang/xlat_priv.h index 717c61a3044..a80270bef01 100644 --- a/src/lib/unlang/xlat_priv.h +++ b/src/lib/unlang/xlat_priv.h @@ -341,10 +341,10 @@ int xlat_register_expressions(void); * xlat_tokenize.c */ int xlat_tokenize_expansion(xlat_exp_head_t *head, fr_sbuff_t *in, - tmpl_attr_rules_t const *t_rules); + tmpl_rules_t const *t_rules); int xlat_tokenize_function_args(xlat_exp_head_t *head, fr_sbuff_t *in, - tmpl_attr_rules_t const *rules); + tmpl_rules_t const *t_rules); ssize_t xlat_print_node(fr_sbuff_t *out, xlat_exp_head_t const *head, xlat_exp_t const *node, fr_sbuff_escape_rules_t const *e_rules); diff --git a/src/lib/unlang/xlat_tokenize.c b/src/lib/unlang/xlat_tokenize.c index 933baa8ccb5..ea40a763243 100644 --- a/src/lib/unlang/xlat_tokenize.c +++ b/src/lib/unlang/xlat_tokenize.c @@ -151,10 +151,10 @@ static inline CC_HINT(always_inline) void xlat_exp_set_name_buffer(xlat_exp_t *n #endif static int xlat_tokenize_string(xlat_exp_head_t *head, fr_sbuff_t *in, bool brace, - fr_sbuff_parse_rules_t const *p_rules, tmpl_attr_rules_t const *t_rules); + fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules); static inline int xlat_tokenize_alternation(xlat_exp_head_t *head, fr_sbuff_t *in, - tmpl_attr_rules_t const *t_rules, bool func_args) + tmpl_rules_t const *t_rules, bool func_args) { xlat_exp_t *node; @@ -288,7 +288,7 @@ int xlat_validate_function_mono(xlat_exp_t *node) */ static inline int xlat_tokenize_function_mono(xlat_exp_head_t *head, fr_sbuff_t *in, - tmpl_attr_rules_t const *rules) + tmpl_rules_t const *t_rules) { xlat_exp_t *node; xlat_t *func; @@ -327,7 +327,7 @@ static inline int xlat_tokenize_function_mono(xlat_exp_head_t *head, MEM(node = xlat_exp_alloc(head, XLAT_FUNC, fr_sbuff_current(&m_s), fr_sbuff_behind(&m_s))); MEM(node->call.args = xlat_exp_head_alloc(node)); if (!func) { - if (!rules || !rules->allow_unresolved) { + if (!t_rules || !t_rules->attr.allow_unresolved) { fr_strerror_const("Unresolved expansion functions are not allowed here"); goto bad_function; } @@ -364,7 +364,7 @@ static inline int xlat_tokenize_function_mono(xlat_exp_head_t *head, * Now parse the child nodes that form the * function's arguments. */ - if (xlat_tokenize_string(node->call.args, in, true, &xlat_expansion_rules, rules) < 0) { + if (xlat_tokenize_string(node->call.args, in, true, &xlat_expansion_rules, t_rules) < 0) { goto error; } @@ -429,7 +429,7 @@ int xlat_validate_function_args(xlat_exp_t *node) * - <0 on parse error. */ int xlat_tokenize_function_args(xlat_exp_head_t *head, fr_sbuff_t *in, - tmpl_attr_rules_t const *rules) + tmpl_rules_t const *t_rules) { xlat_exp_t *node; xlat_t *func; @@ -467,7 +467,7 @@ int xlat_tokenize_function_args(xlat_exp_head_t *head, fr_sbuff_t *in, */ node = xlat_exp_alloc(head, XLAT_FUNC, fr_sbuff_current(&m_s), fr_sbuff_behind(&m_s)); if (!func) { - if (!rules || !rules->allow_unresolved) { + if (!t_rules || !t_rules->attr.allow_unresolved) { fr_strerror_const("Unresolved expansion functions are not allowed here"); goto bad_function; } @@ -503,7 +503,7 @@ int xlat_tokenize_function_args(xlat_exp_head_t *head, fr_sbuff_t *in, * Now parse the child nodes that form the * function's arguments. */ - if (xlat_tokenize_argv(node, &node->call.args, in, &xlat_multi_arg_rules, rules) < 0) { + if (xlat_tokenize_argv(node, &node->call.args, in, &xlat_multi_arg_rules, t_rules) < 0) { goto error; } xlat_flags_merge(&node->flags, &node->call.args->flags); @@ -552,7 +552,7 @@ static int xlat_resolve_virtual_attribute(xlat_exp_t *node, tmpl_t *vpt) * */ static inline int xlat_tokenize_attribute(xlat_exp_head_t *head, fr_sbuff_t *in, - fr_sbuff_parse_rules_t const *p_rules, tmpl_attr_rules_t const *t_rules) + fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules) { ssize_t slen; tmpl_attr_error_t err; @@ -574,7 +574,7 @@ static inline int xlat_tokenize_attribute(xlat_exp_head_t *head, fr_sbuff_t *in, if (t_rules) { memset(&our_t_rules, 0, sizeof(our_t_rules)); - our_t_rules.attr = *t_rules; + our_t_rules = *t_rules; } else { memset(&our_t_rules, 0, sizeof(our_t_rules)); } @@ -634,7 +634,7 @@ static inline int xlat_tokenize_attribute(xlat_exp_head_t *head, fr_sbuff_t *in, */ if ((tmpl_attr_count(vpt) == 1) && (xlat_resolve_virtual_attribute(node, vpt) == 0)) goto done; - if (!t_rules || !t_rules->allow_unresolved) { + if (!t_rules || !t_rules->attr.allow_unresolved) { talloc_free(vpt); fr_strerror_const("Unresolved attributes not allowed in expansions here"); @@ -677,7 +677,7 @@ done: } int xlat_tokenize_expansion(xlat_exp_head_t *head, fr_sbuff_t *in, - tmpl_attr_rules_t const *t_rules) + tmpl_rules_t const *t_rules) { size_t len; fr_sbuff_marker_t s_m; @@ -841,7 +841,7 @@ int xlat_tokenize_expansion(xlat_exp_head_t *head, fr_sbuff_t *in, */ static int xlat_tokenize_string(xlat_exp_head_t *head, fr_sbuff_t *in, bool brace, - fr_sbuff_parse_rules_t const *p_rules, tmpl_attr_rules_t const *t_rules) + fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules) { xlat_exp_t *node = NULL; fr_slen_t slen; @@ -1307,7 +1307,7 @@ ssize_t xlat_tokenize_ephemeral(TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_strerror_clear(); /* Clear error buffer */ if (xlat_tokenize_string(head, &our_in, - false, p_rules, &our_t_rules.attr) < 0) { + false, p_rules, &our_t_rules) < 0) { talloc_free(head); return -fr_sbuff_used(&our_in); } @@ -1350,7 +1350,7 @@ ssize_t xlat_tokenize_ephemeral(TALLOC_CTX *ctx, xlat_exp_head_t **out, * - >0 on success which is the number of characters parsed. */ ssize_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_sbuff_t *in, - fr_sbuff_parse_rules_t const *p_rules, tmpl_attr_rules_t const *t_rules) + fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules) { fr_sbuff_t our_in = FR_SBUFF(in); ssize_t slen; @@ -1360,7 +1360,7 @@ ssize_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_sbuff_t *i xlat_exp_head_t *head; MEM(head = xlat_exp_head_alloc(ctx)); - if (t_rules) head->dict = t_rules->dict_def; + if (t_rules) head->dict = t_rules->attr.dict_def; if (p_rules && p_rules->terminals) { tmp_p_rules = (fr_sbuff_parse_rules_t){ /* Stack allocated due to CL scope */ @@ -1518,13 +1518,13 @@ ssize_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_sbuff_t *i * - < 0 the negative offset of the parse failure. */ ssize_t xlat_tokenize(TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_sbuff_t *in, - fr_sbuff_parse_rules_t const *p_rules, tmpl_attr_rules_t const *t_rules) + fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules) { fr_sbuff_t our_in = FR_SBUFF(in); xlat_exp_head_t *head; MEM(head = xlat_exp_head_alloc(ctx)); - if (t_rules) head->dict = t_rules->dict_def; + if (t_rules) head->dict = t_rules->attr.dict_def; fr_strerror_clear(); /* Clear error buffer */