From: Alan T. DeKok Date: Tue, 30 Aug 2022 14:04:51 +0000 (-0400) Subject: add CONF_ITEM* to unlang_t X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8bb65247ed46e4ac283a1b22f9c5953f774f1b8b;p=thirdparty%2Ffreeradius-server.git add CONF_ITEM* to unlang_t 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. --- diff --git a/src/lib/unlang/call.c b/src/lib/unlang/call.c index 854de04f23c..36ef94a064e 100644 --- a/src/lib/unlang/call.c +++ b/src/lib/unlang/call.c @@ -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, diff --git a/src/lib/unlang/compile.c b/src/lib/unlang/compile.c index 46bcb01c757..9b73b95ca91 100644 --- a/src/lib/unlang/compile.c +++ b/src/lib/unlang/compile.c @@ -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. diff --git a/src/lib/unlang/interpret.c b/src/lib/unlang/interpret.c index 67587795549..9faa338cfac 100644 --- a/src/lib/unlang/interpret.c +++ b/src/lib/unlang/interpret.c @@ -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; } diff --git a/src/lib/unlang/unlang_priv.h b/src/lib/unlang/unlang_priv.h index 1f835d4f348..d12c2e343c8 100644 --- a/src/lib/unlang/unlang_priv.h +++ b/src/lib/unlang/unlang_priv.h @@ -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. };