]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
push a function before running the trigger
authorAlan T. DeKok <aland@freeradius.org>
Mon, 21 Jul 2025 07:45:30 +0000 (09:45 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 21 Jul 2025 08:25:04 +0000 (10:25 +0200)
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

src/lib/server/trigger.c
src/tests/modules/test/trigger.unlang
src/tests/modules/test/triggers.conf

index e5b979bfcb0e198f66be7d69daee7c3dab59e4ad..c6c0d887aedd74beee9a75532c3969377e019798 100644 (file)
@@ -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,
index 26dedf123789ae9638b0f3e92e2c480f1e46768e..7187b0b6c564731ec18b99520dade6abf07447ee 100644 (file)
@@ -1,4 +1,4 @@
-if (%test_trigger('test') == false) {
+if !%test_trigger('test') {
        test_fail
 }
 
index 03bcd753989845ae05c4b338e81a12d6e13c4e8c..580474259f094907f4bb30fac67331f74ecdb412 100644 (file)
@@ -1,3 +1,3 @@
 trigger {
-       test = "/bin/echo hello"
+       test = `/bin/echo hello`
 }