From: Alan T. DeKok Date: Mon, 21 Jul 2025 07:45:30 +0000 (+0200) Subject: push a function before running the trigger X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d95ac9c0337d6252d4a40dbd6bd0881e582cf7a2;p=thirdparty%2Ffreeradius-server.git push a function before running the trigger the interpreter needs the stack to be bootstrapped with a function or module that is something other than a tmpl. The tmpl expects to be a sub frame. Without this, the trigger subrequest never runs anything after the first instruction --- diff --git a/src/lib/server/trigger.c b/src/lib/server/trigger.c index e5b979bfcb..c6c0d887ae 100644 --- a/src/lib/server/trigger.c +++ b/src/lib/server/trigger.c @@ -103,6 +103,15 @@ typedef struct { int exec_status; //!< Result of the program (if the trigger is a tmpl) } fr_trigger_t; +/* + * Function to call when popping the frame + */ +static unlang_action_t trigger_pop(UNUSED unlang_result_t *p_result, UNUSED request_t *request, UNUSED void *uctx) +{ + return UNLANG_ACTION_CALCULATE_RESULT; +} + + /** Execute a trigger - call an executable to process an event * * A trigger ties a state change (e.g. connection up) in a module to an action @@ -156,6 +165,8 @@ int trigger(unlang_interpret_t *intp, fr_event_list_t *el; tmpl_rules_t t_rules; + unlang_action_t action; + /* * noop if trigger_init was never called, or if * we're just checking the configuration. @@ -323,6 +334,19 @@ int trigger(unlang_interpret_t *intp, fr_assert(trigger->vpt != NULL); + action = unlang_function_push_with_result(unlang_interpret_result(request), /* transparent */ + request, + NULL, /* don't call it immediately */ + trigger_pop, /* but when we pop the frame */ + NULL, ~(FR_SIGNAL_CANCEL), + UNLANG_TOP_FRAME, + NULL); + if (action != UNLANG_ACTION_PUSHED_CHILD) { + ERROR("Failed initializing the trigger"); + talloc_free(request); + return -1; + } + if (unlang_tmpl_push(trigger, &trigger->result, &trigger->out, request, trigger->vpt, &(unlang_tmpl_args_t) { .type = UNLANG_TMPL_ARGS_TYPE_EXEC, diff --git a/src/tests/modules/test/trigger.unlang b/src/tests/modules/test/trigger.unlang index 26dedf1237..7187b0b6c5 100644 --- a/src/tests/modules/test/trigger.unlang +++ b/src/tests/modules/test/trigger.unlang @@ -1,4 +1,4 @@ -if (%test_trigger('test') == false) { +if !%test_trigger('test') { test_fail } diff --git a/src/tests/modules/test/triggers.conf b/src/tests/modules/test/triggers.conf index 03bcd75398..580474259f 100644 --- a/src/tests/modules/test/triggers.conf +++ b/src/tests/modules/test/triggers.conf @@ -1,3 +1,3 @@ trigger { - test = "/bin/echo hello" + test = `/bin/echo hello` }