]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
just pass all of the tmpl_rules to the xlat tokenize functions
authorAlan T. DeKok <aland@freeradius.org>
Tue, 24 May 2022 18:57:49 +0000 (14:57 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 24 May 2022 20:46:49 +0000 (16:46 -0400)
so that they all take the same thing, and so that we have better
control over non-attribute parsing

src/bin/unit_test_attribute.c
src/lib/server/cf_parse.c
src/lib/server/tmpl_tokenize.c
src/lib/unlang/xlat.h
src/lib/unlang/xlat_priv.h
src/lib/unlang/xlat_tokenize.c

index 1757f6baeec8d5695c64f1c940008aea198e2b53..ba2143e7375c1cc327053e4ca47badb0f717ec46 100644 (file)
@@ -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);
index d793042edffa09f68c20e6a95b912bfff556bea4..2354e90c9e5689e5135640fb137224811d4af624 100644 (file)
@@ -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;
index c7f67b9db920c696bd23242daafce8803e84bc90..ce1f73dcb587f50f4ed728ef1b7697a4cd28e515 100644 (file)
@@ -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;
 
                /*
index e3b4ea75a08501eaded3fb01d48c95649e86da15..a27edeb36c7a9cfaa70ba89cce949beea2b02ab1 100644 (file)
@@ -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);
 
index 717c61a30441879d0b3094818711aae68356fe6f..a80270bef0137ba7c3228cc2c911f138ad27bde4 100644 (file)
@@ -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);
 
index 933baa8ccb58194c36f069a269bb4989c80e1262..ea40a76324371bea07f34ace540a567ad78fabbc 100644 (file)
@@ -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 */