]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Remove dict from xlat_exp_head_t
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 8 Nov 2023 01:11:56 +0000 (19:11 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 8 Nov 2023 01:12:10 +0000 (19:12 -0600)
It's already in the nodes it needs to be in

src/lib/unlang/xlat_expr.c
src/lib/unlang/xlat_priv.h
src/lib/unlang/xlat_purify.c
src/lib/unlang/xlat_tokenize.c

index 57e1a9993236cb71f8bd807bd4a9591b39be6589..0e5f48eb1c97f63e73c7d1efb30cfb0c9895c588 100644 (file)
@@ -2958,11 +2958,7 @@ static fr_slen_t xlat_tokenize_expression_internal(TALLOC_CTX *ctx, xlat_exp_hea
                                                                 &bracket_terms));
 
        MEM(head = xlat_exp_head_alloc(ctx));
-       if (t_rules) {
-               head->dict = t_rules->attr.dict_def;
-       } else {
-               t_rules = &my_rules;
-       }
+       if (!t_rules) t_rules = &my_rules;
 
        slen = tokenize_expression(head, &node, in, terminal_rules, t_rules, T_INVALID, bracket_rules, p_rules, cond);
        talloc_free(bracket_rules);
index 53d64fcbc98ed9ee9736387b8a7c64776428ed8d..ec7c848e46bc2d838c3a879fd8abb35b6f254cc7 100644 (file)
@@ -124,6 +124,12 @@ typedef struct {
        xlat_t const            *func;                  //!< The xlat expansion to expand format with.
        xlat_exp_head_t         *args;                  //!< arguments to the function call
 
+       fr_dict_t const         *dict;                  //!< Records the namespace this xlat call was created in.
+                                                       ///< Used by the purify code to run fake requests in
+                                                       ///< the correct namespace, and accessible to instantiation
+                                                       ///< functions in case the xlat needs to perform runtime
+                                                       ///< resolution of attributes (as with %eval()).
+
        xlat_inst_t             *inst;                  //!< Instance data for the #xlat_t.
        xlat_thread_inst_t      *thread_inst;           //!< Thread specific instance.
                                                        ///< ONLY USED FOR EPHEMERAL XLATS.
@@ -132,8 +138,6 @@ typedef struct {
                                                        ///< into the instance tree.
        xlat_input_type_t       input_type;             //!< The input type used inferred from the
                                                        ///< bracketing style.
-
-       fr_dict_t const         *dict;                  //!< Dictionary to use when resolving call env tmpls
 } xlat_call_t;
 
 /** An xlat expansion node
@@ -147,7 +151,6 @@ struct xlat_exp_s {
        fr_token_t              quote;          //!< Type of quoting around XLAT_GROUP types.
 
        xlat_flags_t            flags;          //!< Flags that control resolution and evaluation.
-
        xlat_type_t _CONST      type;           //!< type of this expansion.
 
 #ifndef NDEBUG
@@ -184,11 +187,6 @@ struct xlat_exp_head_s {
        fr_dlist_head_t         dlist;
        xlat_flags_t            flags;          //!< Flags that control resolution and evaluation.
        bool                    instantiated;   //!< temporary flag until we fix more things
-       fr_dict_t const         *dict;          //!< Records the namespace this xlat was created in.
-                                               ///< Used by the purify code to run fake requests in
-                                               ///< the correct namespace, and passed to instantiation
-                                               ///< functions in case the xlat needs to perform runtime
-                                               ///< resolution of attributes (as with %eval()).
 
 #ifndef NDEBUG
        char const * _CONST     file;           //!< File where the xlat was allocated.
index 1c53dc9573e28a64aea38e929740653785c8dd17..085e9c4422e72f2dd984445d69391f1daa6497b9 100644 (file)
@@ -29,6 +29,7 @@ RCSID("$Id$")
 #include <freeradius-devel/server/base.h>
 #include <freeradius-devel/unlang/xlat_priv.h>
 #include <freeradius-devel/util/calc.h>
+#include <freeradius-devel/util/dict.h>
 
 static void xlat_value_list_to_xlat(xlat_exp_head_t *head, fr_value_box_list_t *list)
 {
@@ -130,8 +131,21 @@ int xlat_purify_list(xlat_exp_head_t *head, request_t *request)
                         */
                        if (!node->flags.pure) {
                                if (node->call.func->purify) {
+                                       fr_dict_t const *dict = request->dict;
+
+                                       /*
+                                        *      Swap in the node specific dictionary.
+                                        *
+                                        *      The previous code stored the dictionary in the xlat_exp_head_t,
+                                        *      and whilst this wasn't wrong, it was duplicative.
+                                        *
+                                        *      This allows future code to create inline definitions of local
+                                        *      attributes, and have them work correctly, as more deeply nested
+                                        *      expressions would swap in the correct dictionary.
+                                        */
+                                       request->dict = node->call.dict;
                                        if (node->call.func->purify(node, node->call.inst->data, request) < 0) return -1;
-
+                                       request->dict = dict;
                                } else {
                                        if (xlat_purify_list(node->call.args, request) < 0) return -1;
                                }
@@ -207,7 +221,7 @@ int xlat_purify(xlat_exp_head_t *head, unlang_interpret_t *intp)
 
        if (!head->flags.can_purify) return 0;
 
-       request = request_alloc_internal(NULL, (&(request_init_args_t){ .namespace = head->dict }));
+       request = request_alloc_internal(NULL, (&(request_init_args_t){ .namespace = fr_dict_internal() }));
        if (!request) return -1;
 
        if (intp) unlang_interpret_set(request, intp);
index 6e0eaa386d629cae31228e8ef8b3ea9d4e63f418..3b1fa9803bf38e725d9b1af083461aac29d982e4 100644 (file)
@@ -1672,8 +1672,6 @@ fr_slen_t xlat_tokenize_argv(TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_sbuff_t
        xlat_exp_head_t                 *head;
 
        MEM(head = xlat_exp_head_alloc(ctx));
-       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 */
                        .terminals = fr_sbuff_terminals_amerge(NULL, p_rules->terminals,
@@ -1908,7 +1906,6 @@ fr_slen_t xlat_tokenize(TALLOC_CTX *ctx, xlat_exp_head_t **out, fr_sbuff_t *in,
 
        MEM(head = xlat_exp_head_alloc(ctx));
        if (t_rules) {
-               head->dict = t_rules->attr.dict_def;
                fr_assert(!t_rules->at_runtime || t_rules->xlat.runtime_el); /* if it's at runtime, we need an event list */
        }