]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
clean up flag handling
authorAlan T. DeKok <aland@freeradius.org>
Mon, 23 May 2022 18:38:40 +0000 (14:38 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 24 May 2022 20:46:44 +0000 (16:46 -0400)
things are pure unless marked impure.

check input allow_unresolved once per loop, and not in some of the
individual "case" statements

src/lib/unlang/xlat_tokenize.c

index 52839155065bc973f086332be3b76972452a271f..c703fa630707ab27fd14943775e8890cd28f7c73 100644 (file)
@@ -516,7 +516,6 @@ int xlat_tokenize_function_args(xlat_exp_head_t *head, fr_sbuff_t *in,
        }
 
        xlat_exp_insert_tail(head, node);
-
        return 0;
 }
 
@@ -1629,9 +1628,16 @@ int xlat_resolve(xlat_exp_head_t *head, xlat_res_rules_t const *xr_rules)
 
        our_flags = head->flags;
        our_flags.needs_resolving = false;                      /* We flip this if not all resolutions are successful */
+       our_flags.pure = true;                                  /* we flip this if the children are not pure */
 
        xlat_exp_foreach(head, node) {
-               if (!node->flags.needs_resolving) continue;     /* This node and non of its children need resolving */
+               /*
+                *      This node and none of its children need resolving
+                */
+               if (!node->flags.needs_resolving) {
+                       xlat_flags_merge(&our_flags, &node->flags);
+                       continue;
+               }
 
                switch (node->type) {
                case XLAT_GROUP:
@@ -1663,6 +1669,7 @@ int xlat_resolve(xlat_exp_head_t *head, xlat_res_rules_t const *xr_rules)
                        } else {
                                if (xlat_resolve(node->call.args, xr_rules) < 0) return -1;
                        }
+
                        node->flags = node->call.func->flags;
                        xlat_flags_merge(&node->flags, &node->call.args->flags);
 
@@ -1695,7 +1702,6 @@ int xlat_resolve(xlat_exp_head_t *head, xlat_res_rules_t const *xr_rules)
                                                           fr_box_strvalue_buffer(node->fmt));
                                        return -1;
                                }
-                               our_flags.needs_resolving = true;       /* Still unresolved nodes */
                                break;
                        }
 
@@ -1749,6 +1755,7 @@ int xlat_resolve(xlat_exp_head_t *head, xlat_res_rules_t const *xr_rules)
                        if (xlat_bootstrap_func(node) < 0) return -1;
                }
                        break;
+
                /*
                 *      This covers unresolved attributes as well as
                 *      unresolved functions.
@@ -1776,18 +1783,16 @@ int xlat_resolve(xlat_exp_head_t *head, xlat_res_rules_t const *xr_rules)
                                        }
                                        return -1;
                                }
-                               our_flags.needs_resolving = true;       /* Still unresolved nodes */
                                break;
                        }
 
                        /*
-                        *      Just need to flip the type as the tmpl
-                        *      should already have been fixed up
+                        *      Just need to flip the type as the tmpl should already have been fixed up
                         */
                        xlat_exp_set_type(node, XLAT_TMPL);
 
                        /*
-                        *      Reset node flags
+                        *      Reset node flags.  Attributes aren't pure, and don't need further resolving.
                         */
                        node->flags = (xlat_flags_t){ };
                }
@@ -1801,10 +1806,11 @@ int xlat_resolve(xlat_exp_head_t *head, xlat_res_rules_t const *xr_rules)
                        if (node->quote != T_BARE_WORD) {
                                if (tmpl_resolve(node->vpt, xr_rules->tr_rules) < 0) return -1;
 
+                               node->flags.needs_resolving = false;
+                               node->flags.pure = tmpl_is_data(node->vpt);
                                break;
                        }
 
-                       if (!xr_rules->allow_unresolved) goto error_unresolved;
                        break;
 
                default:
@@ -1812,6 +1818,8 @@ int xlat_resolve(xlat_exp_head_t *head, xlat_res_rules_t const *xr_rules)
                        return -1;
                }
 
+               if (node->flags.needs_resolving && !xr_rules->allow_unresolved) goto error_unresolved;
+
                xlat_flags_merge(&our_flags, &node->flags);
        }