]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Pass a repeat function for going back up the stack
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 30 Jan 2018 00:22:49 +0000 (17:22 -0700)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 30 Jan 2018 00:22:49 +0000 (17:22 -0700)
src/include/modules.h
src/include/unlang.h
src/main/module_unlang.c
src/main/unlang_op.c
src/modules/rlm_eap/rlm_eap.c

index a4ae352506ac9a290156059ace227ebe0e85d72a..d5f5a3545235b9314a8d5ebcea00cace6dcbf2d7 100644 (file)
@@ -311,6 +311,7 @@ int         unlang_event_fd_delete(REQUEST *request, void const *ctx, int fd);
 
 rlm_rcode_t    module_unlang_push_function(REQUEST *request,
                                            unlang_function_t func,
+                                           unlang_function_t repeat,
                                            fr_module_unlang_resume_t resume,
                                            fr_module_unlang_signal_t signal, void *rctx);
 
index 88750de8b483bd7a56f5d55aa9ce61a9432ce710..d5df048b91df691e691e03b5192e7dfdf49d00f2 100644 (file)
@@ -118,7 +118,7 @@ typedef struct {
                                                                ///< in debug mode.
 } unlang_op_t;
 
-void           unlang_push_function(REQUEST *request, unlang_function_t func, void *uctx);
+void           unlang_push_function(REQUEST *request, unlang_function_t func, unlang_function_t repeat, void *uctx);
 
 void           unlang_push_section(REQUEST *request, CONF_SECTION *cs, rlm_rcode_t default_action);
 
index 100d65b9137fb3065c15639e80a7e9bc98732547..d07b69d1584a52293e396f418733cd55f7dea31b 100644 (file)
@@ -229,7 +229,7 @@ static unlang_action_t module_unlang_resume(REQUEST *request, rlm_rcode_t *presu
  *     - RLM_MODULE_YIELD.
  */
 rlm_rcode_t module_unlang_push_function(REQUEST *request,
-                                       unlang_function_t func,
+                                       unlang_function_t func, unlang_function_t repeat,
                                        fr_module_unlang_resume_t resume,
                                        fr_module_unlang_signal_t signal, void *rctx)
 {
@@ -238,7 +238,7 @@ rlm_rcode_t module_unlang_push_function(REQUEST *request,
         */
        (void) unlang_module_yield(request, resume, signal, rctx);
 
-       unlang_push_function(request, func, rctx);
+       unlang_push_function(request, func, repeat, rctx);
 
        return RLM_MODULE_YIELD;        /* This may allow us to do optimisations in future */
 }
index 5eb0ad05d4871d4189feb41799b0bdbf56dee12b..1b3cd2601db8898cff81be34474011db62645638 100644 (file)
@@ -90,7 +90,8 @@ static uint64_t unlang_active_callers(unlang_t *instruction)
 }
 
 typedef struct {
-       unlang_function_t               func;                   //!< To call.
+       unlang_function_t               func;                   //!< To call when going down the stack.
+       unlang_function_t               repeat;                 //!< To call when going back up the stack.
        void                            *uctx;                  //!< Uctx to pass to function.
 } unlang_frame_state_func_t;
 
@@ -129,7 +130,11 @@ static unlang_action_t unlang_function_call(REQUEST *request,
        unlang_t                        *instruction = frame->instruction;
        unlang_action_t                 ua;
 
-       ua = state->func(request, state->uctx);
+       if (!frame->repeat) {
+               ua = state->func(request, state->uctx);
+       } else {
+               ua = state->repeat(request, state->uctx);
+       }
 
        /*
         *      The success/failure of these functions
@@ -151,10 +156,12 @@ static unlang_action_t unlang_function_call(REQUEST *request,
  * deeper in the C call stack to establish a new resumption point.
  *
  * @param[in] request  The current request.
- * @param[in] func     to call.
+ * @param[in] func     to call going up the stack.
+ * @param[in] repeat   function to call going back down the stack (may be NULL).
+ *                     This may be the same as #func.
  * @param[in] uctx     to pass to func.
  */
-void unlang_push_function(REQUEST *request, unlang_function_t func, void *uctx)
+void unlang_push_function(REQUEST *request, unlang_function_t func, unlang_function_t repeat, void *uctx)
 {
        unlang_stack_t                  *stack = request->stack;
        unlang_stack_frame_t            *frame;
@@ -166,12 +173,19 @@ void unlang_push_function(REQUEST *request, unlang_function_t func, void *uctx)
        unlang_push(stack, &function_instruction, RLM_MODULE_UNKNOWN, UNLANG_NEXT_STOP, false);
        frame = &stack->frame[stack->depth];
 
+       /*
+        *      Tell the interpreter to call unlang_function_call
+        *      again when going back up the stack.
+        */
+       if (repeat) frame->repeat = true;
+
        /*
         *      Allocate state
         */
        MEM(frame->state = state = talloc_zero(stack, unlang_frame_state_func_t));
 
        state->func = func;
+       state->repeat = repeat;
        state->uctx = uctx;
 }
 
index a61f711296a434660353dd2f581d0b57d5fcd25f..cfd1c0c8895829db9738efebc59cf440c0042c83 100644 (file)
@@ -581,7 +581,8 @@ module_call:
        rctx->rcode = RLM_MODULE_UNKNOWN;
 
        request->module = method->submodule->name;
-       return module_unlang_push_function(request, eap_call_submodule, mod_authenticate_result, NULL, rctx);
+       return module_unlang_push_function(request, eap_call_submodule, eap_call_submodule,
+                                          mod_authenticate_result, NULL, rctx);
 }
 
 static rlm_rcode_t mod_authenticate(void *instance, UNUSED void *thread, REQUEST *request)