]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add CONF_ITEM* to unlang_t
authorAlan T. DeKok <aland@freeradius.org>
Tue, 30 Aug 2022 14:04:51 +0000 (10:04 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 30 Aug 2022 14:31:08 +0000 (10:31 -0400)
so that we can track where each instruction was created from.
and instructions generated from CONF_PAIRs can also get queried
for their filename and line number.

src/lib/unlang/call.c
src/lib/unlang/compile.c
src/lib/unlang/interpret.c
src/lib/unlang/unlang_priv.h

index 854de04f23c46478b8141e41df36f030b61e2702..36ef94a064e67fcc49730a96ba33319be65fe931 100644 (file)
@@ -189,6 +189,7 @@ unlang_action_t unlang_call_push(request_t *request, CONF_SECTION *server_cs, bo
                                .type = UNLANG_TYPE_CALL,
                                .name = name,
                                .debug_name = name,
+                               .ci = CF_TO_ITEM(server_cs),
                                .actions = {
                                        .actions = {
                                                [RLM_MODULE_REJECT]     = 0,
index 46bcb01c7572cbbc3e707fa1d860db3b1f909c1b..9b73b95ca914e71f36c2c1145f6215c832d30a4f 100644 (file)
@@ -1047,6 +1047,7 @@ static unlang_group_t *group_allocate(unlang_t *parent, CONF_SECTION *cs, unlang
        c = unlang_group_to_generic(g);
        c->parent = parent;
        c->type = ext->type;
+       c->ci = CF_TO_ITEM(cs);
 
        return g;
 }
@@ -1507,6 +1508,7 @@ static unlang_t *compile_edit_section(unlang_t *parent, unlang_compile_t *unlang
                c->name = cf_section_name1(cs);
                c->debug_name = c->name;
                c->type = UNLANG_TYPE_EDIT;
+               c->ci = CF_TO_ITEM(cs);
 
                map_list_init(&edit->maps);
                edit_free = edit;
@@ -1607,6 +1609,7 @@ static unlang_t *compile_edit_pair(unlang_t *parent, unlang_compile_t *unlang_ct
                c->name = cf_pair_attr(cp);
                c->debug_name = c->name;
                c->type = UNLANG_TYPE_EDIT;
+               c->ci = CF_TO_ITEM(cp);
 
                map_list_init(&edit->maps);
                edit_free = edit;
@@ -2911,6 +2914,7 @@ static unlang_t *compile_tmpl(unlang_t *parent,
        c->name = p;
        c->debug_name = c->name;
        c->type = UNLANG_TYPE_TMPL;
+       c->ci = CF_TO_ITEM(cp);
 
        RULES_VERIFY(unlang_ctx->rules);
        slen = tmpl_afrom_substr(ut, &vpt,
@@ -3995,6 +3999,7 @@ static unlang_t *compile_module(unlang_t *parent, unlang_compile_t *unlang_ctx,
        c->name = talloc_typed_strdup(c, realname);
        c->debug_name = c->name;
        c->type = UNLANG_TYPE_MODULE;
+       c->ci = ci;
 
        /*
         *      Set the default actions for this module.
index 6758779554950e9a61a4292f6def6145a6780643..9faa338cfacf5e34a00c17803e0050b4984b319f 100644 (file)
@@ -31,6 +31,7 @@ RCSID("$Id$")
 #include "module_priv.h"
 #include "parallel_priv.h"
 
+
 /** The default interpreter instance for this thread
  */
 static _Thread_local unlang_interpret_t *intp_thread_default;
@@ -1332,20 +1333,18 @@ static xlat_action_t unlang_interpret_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out,
        }
 
        /*
-        *      Line number of the current section.
+        *      All of the remaining things need a CONF_ITEM.
         */
-       if (strcmp(fmt, "line") == 0) {
-               unlang_group_t const *g;
-
-               if (!unlang_ops[instruction->type].debug_braces) {
-                       if (fr_value_box_bstrndup(ctx, vb, NULL, "???", 3, false) < 0) goto error;
+       if (!instruction->ci) {
+               if (fr_value_box_bstrndup(ctx, vb, NULL, "???", 3, false) < 0) goto error;
                        goto finish;
-               }
-
-               g = (unlang_group_t const *) instruction;
-               fr_assert(g->cs != NULL);
+       }
 
-               fr_value_box_int32(vb, NULL, cf_lineno(g->cs), false);
+       /*
+        *      Line number of the current section.
+        */
+       if (strcmp(fmt, "line") == 0) {
+               fr_value_box_int32(vb, NULL, cf_lineno(instruction->ci), false);
                goto finish;
        }
 
@@ -1353,18 +1352,9 @@ static xlat_action_t unlang_interpret_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out,
         *      Filename of the current section.
         */
        if (strcmp(fmt, "filename") == 0) {
-               unlang_group_t const *g;
-
-               if (!unlang_ops[instruction->type].debug_braces) {
-                       if (fr_value_box_bstrndup(ctx, vb, NULL, "???", 3, false) < 0) goto error;
-                       goto finish;
-               }
-
-               g = (unlang_group_t const *) instruction;
-               fr_assert(g->cs != NULL);
+               char const *filename = cf_filename(instruction->ci);
 
-               if (fr_value_box_bstrndup(ctx, vb, NULL, cf_filename(g->cs),
-                                         strlen(cf_filename(g->cs)), false) < 0) goto error;
+               if (fr_value_box_bstrndup(ctx, vb, NULL, filename, strlen(filename), false) < 0) goto error;
                goto finish;
        }
 
index 1f835d4f34852be088443b177239ee48d6eaa843..d12c2e343c89e77e927b36af1cbaec6e7720ec94 100644 (file)
@@ -122,6 +122,7 @@ struct unlang_s {
        char const              *debug_name;    //!< Printed in log messages when the node is executed.
        unlang_type_t           type;           //!< The specialisation of this node.
        bool                    closed;         //!< whether or not this section is closed to new statements
+       CONF_ITEM               *ci;            //!< used to generate this item
        unsigned int            number;         //!< unique node number
        unlang_actions_t        actions;        //!< Priorities, etc. for the various return codes.
 };