]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
push xlat condition parsing until later
authorAlan T. DeKok <aland@freeradius.org>
Mon, 24 Oct 2022 21:31:12 +0000 (17:31 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 24 Oct 2022 21:31:12 +0000 (17:31 -0400)
to avoid having unused xlats hanging around when we parse
policies.

src/lib/server/cf_file.c
src/lib/unlang/compile.c

index 32d694dac63008c818b822767cf591e30b1c9cfa..34e6fa39931aa1f72d0651956d93e4a2219ff258 100644 (file)
@@ -1251,11 +1251,11 @@ static CONF_ITEM *process_if(cf_stack_t *stack)
        CONF_SECTION    *cs;
        uint8_t const   *p;
        char const      *ptr = stack->ptr;
+       char            *name2;
        cf_stack_frame_t *frame = &stack->frame[stack->depth];
        CONF_SECTION    *parent = frame->current;
        char            *buff[4];
        tmpl_rules_t    t_rules;
-       xlat_exp_head_t *head = NULL;
        fr_sbuff_parse_rules_t p_rules = { };
 
        p_rules.terminals = &if_terminals;
@@ -1443,6 +1443,8 @@ static CONF_ITEM *process_if(cf_stack_t *stack)
         */
        memcpy(buff[2], stack->ptr, slen);
        buff[2][slen] = '\0';
+       name2 = buff[2];
+
        while (slen > 0) {
                if (!isspace((int) buff[2][slen])) break;
 
@@ -1475,7 +1477,6 @@ static CONF_ITEM *process_if(cf_stack_t *stack)
                                ptr = buff[3];
                                slen = my_slen;
 
-                       parse_error:
                                fr_canonicalize_error(cs, &spaces, &text, slen, ptr);
 
                                cf_log_err(cs, "Parse error in condition");
@@ -1490,16 +1491,11 @@ static CONF_ITEM *process_if(cf_stack_t *stack)
                }
 
                if (main_config->parse_new_conditions) {
-                       my_slen = xlat_tokenize_condition(cs, &head, &FR_SBUFF_IN(buff[3], strlen(buff[3])), &p_rules, &t_rules);
-                       if (my_slen <= 0) {
-                               ptr = buff[3];
-                               slen = my_slen;
-                               goto parse_error;
-                       }
+                       name2 = buff[3];
                }
        }
 
-       MEM(cs->name2 = talloc_typed_strdup(cs, buff[2]));
+       MEM(cs->name2 = talloc_typed_strdup(cs, name2));
        cs->name2_quote = T_BARE_WORD;
 
        ptr += slen;
@@ -1520,9 +1516,6 @@ static CONF_ITEM *process_if(cf_stack_t *stack)
                cf_data_add(cs, cond, NULL, true);
        }
 
-       if (main_config->parse_new_conditions) {
-               cf_data_add(cs, head, NULL, true);
-       }
        stack->ptr = ptr;
 
        cs->allow_unlang = true;
index fa585f83031b7ab0f09e02e8761abfca2f0fa0e6..05f9faf5f0a111303eb03b2b5d14cfa2554c6741 100644 (file)
@@ -2962,6 +2962,11 @@ static unlang_t *compile_tmpl(unlang_t *parent,
        return c;
 }
 
+static const fr_sbuff_term_t if_terminals = FR_SBUFF_TERMS(
+       L(""),
+       L("{"),
+);
+
 static unlang_t *compile_if_subsection(unlang_t *parent, unlang_compile_t *unlang_ctx, CONF_SECTION *cs,
                                       unlang_ext_t const *ext)
 {
@@ -2988,8 +2993,35 @@ static unlang_t *compile_if_subsection(unlang_t *parent, unlang_compile_t *unlan
         *      Migration support.
         */
        if (main_config->parse_new_conditions) {
-               head = cf_data_value(cf_data_find(cs, xlat_exp_head_t, NULL));
-               fr_assert(head != NULL);
+               char const *name2 = cf_section_name2(cs);
+               ssize_t slen;
+
+               tmpl_rules_t t_rules = (tmpl_rules_t) {
+                       .attr = {
+                               .dict_def = xr_rules.tr_rules->dict_def,
+                               .allow_unresolved = true,
+                               .allow_unknown = true
+                       }
+               };
+
+               fr_sbuff_parse_rules_t p_rules = { };
+
+               p_rules.terminals = &if_terminals;
+
+               slen = xlat_tokenize_condition(cs, &head, &FR_SBUFF_IN(name2, strlen(name2)), &p_rules, &t_rules);
+               if (slen <= 0) {
+                       char *spaces, *text;
+
+                       fr_canonicalize_error(cs, &spaces, &text, slen, name2);
+
+                       cf_log_err(cs, "Parse error in condition!!!!");
+                       cf_log_err(cs, "%s", text);
+                       cf_log_err(cs, "%s^ %s", spaces, fr_strerror());
+
+                       talloc_free(spaces);
+                       talloc_free(text);
+                       return NULL;
+               }
 
                /*
                 *      Resolve the xlat first.