]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add env_data to module_ctx, unlang_module_event and unlang_frame_state_module
authorNick Porter <nick@portercomputing.co.uk>
Tue, 28 Feb 2023 11:05:22 +0000 (11:05 +0000)
committerNick Porter <nick@portercomputing.co.uk>
Fri, 10 Mar 2023 17:18:36 +0000 (17:18 +0000)
A pointer to the evaluated per-call environment data

src/lib/server/auth.c
src/lib/server/module_ctx.h
src/lib/unlang/module.c
src/lib/unlang/module_priv.h
src/modules/rlm_radius/rlm_radius.c
src/modules/rlm_rest/io.c
src/modules/rlm_rest/rlm_rest.c
src/modules/rlm_tacacs/rlm_tacacs.c

index eba404f66a4b6eb0aabe853ef1f4a75d8d75d5f5..7b2bb174ef437b59b2a86364c38da2103f642525 100644 (file)
@@ -169,7 +169,7 @@ unlang_action_t rad_virtual_server(rlm_rcode_t *p_result, request_t *request)
 
        RDEBUG("server %s {", cf_section_name2(unlang_call_current(request)));
        request->async->process(&final,
-                               MODULE_CTX(dl_module_instance_by_data(request->async->process_inst), NULL, NULL),
+                               MODULE_CTX(dl_module_instance_by_data(request->async->process_inst), NULL, NULL, NULL),
                                request);
        RDEBUG("} # server %s", cf_section_name2(unlang_call_current(request)));
 
index 50d1f600bc484bd1cd30c3c086c6320405d06e92..efa267f01ce5a2912dc5f1ffcacbb169fdaca671 100644 (file)
@@ -41,6 +41,7 @@ extern "C" {
 typedef struct {
        dl_module_inst_t const          *inst;          //!< Dynamic loader API handle for the module.
        void                            *thread;        //!< Thread specific instance data.
+       void                            *env_data;      //!< Per call enviornment data.
        void                            *rctx;          //!< Resume ctx that a module previously set.
 } module_ctx_t;
 
@@ -118,7 +119,7 @@ DIAG_ON(unused-function)
  * @param[in] _thread  instance of the module being called.
  * @param[in] _rctx    Resume ctx (if any).
  */
-#define MODULE_CTX(_dl_inst, _thread, _rctx) &(module_ctx_t){ .inst = _dl_inst, .thread = _thread, .rctx = _rctx }
+#define MODULE_CTX(_dl_inst, _thread, _env_data, _rctx) &(module_ctx_t){ .inst = _dl_inst, .thread = _thread, .env_data = _env_data, .rctx = _rctx }
 
 /** Wrapper to create a module_ctx_t as a compound literal from a module_inst_ctx_t
  *
@@ -138,7 +139,7 @@ DIAG_ON(unused-function)
  *
  * @param[in] _mctx    to copy fields from.
  */
-#define MODULE_CTX_FROM_THREAD_INST(_mctx) &(module_ctx_t){ .inst = (_mctx)->inst, .thread = (_mctx)->thread }
+#define MODULE_CTX_FROM_THREAD_INST(_mctx) &(module_ctx_t){ .inst = (_mctx)->inst, .thread = (_mctx)->thread, .env_data = (_mctx)->env_data }
 
 /** Wrapper to create a module_inst_ctx_t as a compound literal
  *
index a4d61f507b59e6b4f1951007343f88db9b40df17..6822616d940672c142a508a5a942cd3fa85b4820 100644 (file)
@@ -48,6 +48,7 @@ typedef struct {
        dl_module_inst_t                *dl_inst;       //!< Module instance to pass to callbacks.
                                                        ///< Use dl_inst->data to get instance data.
        void                            *thread;        //!< Thread specific module instance.
+       void                            *env_data;      //!< Per call environment data.
        void const                      *rctx;          //!< rctx data to pass to callbacks.
        fr_event_timer_t const          *ev;            //!< Event in this worker's event heap.
 } unlang_module_event_t;
@@ -67,7 +68,7 @@ static void unlang_event_fd_read_handler(UNUSED fr_event_list_t *el, int fd, UNU
 
        fr_assert(ev->fd == fd);
 
-       ev->fd_read(MODULE_CTX(ev->dl_inst, ev->thread, UNCONST(void *, ev->rctx)), ev->request, fd);
+       ev->fd_read(MODULE_CTX(ev->dl_inst, ev->thread, ev->env_data, UNCONST(void *, ev->rctx)), ev->request, fd);
 }
 
 /** Frees an unlang event, removing it from the request's event loop
@@ -104,7 +105,7 @@ static void unlang_module_event_timeout_handler(UNUSED fr_event_list_t *el, fr_t
 {
        unlang_module_event_t *ev = talloc_get_type_abort(ctx, unlang_module_event_t);
 
-       ev->timeout(MODULE_CTX(ev->dl_inst, ev->thread, UNCONST(void *, ev->rctx)), ev->request, now);
+       ev->timeout(MODULE_CTX(ev->dl_inst, ev->thread, ev->env_data, UNCONST(void *, ev->rctx)), ev->request, now);
        talloc_free(ev);
 }
 
@@ -145,6 +146,7 @@ int unlang_module_timeout_add(request_t *request, unlang_module_timeout_t callba
                .timeout = callback,
                .dl_inst = mc->instance->dl_inst,
                .thread = state->thread,
+               .env_data = state->env_data,
                .rctx = rctx
        };
 
@@ -193,7 +195,7 @@ static void unlang_event_fd_write_handler(UNUSED fr_event_list_t *el, int fd, UN
        unlang_module_event_t *ev = talloc_get_type_abort(ctx, unlang_module_event_t);
        fr_assert(ev->fd == fd);
 
-       ev->fd_write(MODULE_CTX(ev->dl_inst, ev->thread, UNCONST(void *, ev->rctx)), ev->request, fd);
+       ev->fd_write(MODULE_CTX(ev->dl_inst, ev->thread, ev->env_data, UNCONST(void *, ev->rctx)), ev->request, fd);
 }
 
 /** Call the callback registered for an I/O error event
@@ -211,7 +213,7 @@ static void unlang_event_fd_error_handler(UNUSED fr_event_list_t *el, int fd,
 
        fr_assert(ev->fd == fd);
 
-       ev->fd_error(MODULE_CTX(ev->dl_inst, ev->thread, UNCONST(void *, ev->rctx)), ev->request, fd);
+       ev->fd_error(MODULE_CTX(ev->dl_inst, ev->thread, ev->env_data, UNCONST(void *, ev->rctx)), ev->request, fd);
 }
 
 
@@ -267,6 +269,7 @@ int unlang_module_fd_add(request_t *request,
        ev->fd_error = error;
        ev->dl_inst = mc->instance->dl_inst;
        ev->thread = state->thread;
+       ev->env_data = state->env_data;
        ev->rctx = rctx;
 
        /*
@@ -519,6 +522,7 @@ unlang_action_t unlang_module_yield_to_section(rlm_rcode_t *p_result,
                unlang_stack_t          *stack = request->stack;
                unlang_stack_frame_t    *frame = &stack->frame[stack->depth];
                unlang_module_t         *mc;
+               unlang_frame_state_module_t     *state;
 
                fr_assert(frame->instruction->type == UNLANG_TYPE_MODULE);
                mc = unlang_generic_to_module(frame->instruction);
@@ -529,9 +533,11 @@ unlang_action_t unlang_module_yield_to_section(rlm_rcode_t *p_result,
                 *      anyway when we return.
                 */
                stack->result = frame->result = default_rcode;
+               state = talloc_get_type_abort(frame->state, unlang_frame_state_module_t);
 
                return resume(p_result,
-                             MODULE_CTX(mc->instance->dl_inst, module_thread(mc->instance)->data, rctx),
+                             MODULE_CTX(mc->instance->dl_inst, module_thread(mc->instance)->data,
+                                        state->env_data, rctx),
                              request);
        }
 
@@ -628,7 +634,7 @@ static void unlang_module_signal(request_t *request, unlang_stack_frame_t *frame
        caller = request->module;
        request->module = mc->instance->name;
        safe_lock(mc->instance);
-       state->signal(MODULE_CTX(mc->instance->dl_inst, state->thread->data, state->rctx), request, action);
+       state->signal(MODULE_CTX(mc->instance->dl_inst, state->thread->data, state->env_data, state->rctx), request, action);
        safe_unlock(mc->instance);
        request->module = caller;
 
@@ -718,7 +724,8 @@ static unlang_action_t unlang_module_resume(rlm_rcode_t *p_result, request_t *re
        state->resume = NULL;
 
        safe_lock(mc->instance);
-       ua = resume(&state->rcode, MODULE_CTX(mc->instance->dl_inst, state->thread->data, state->rctx), request);
+       ua = resume(&state->rcode, MODULE_CTX(mc->instance->dl_inst, state->thread->data,
+                                             state->env_data, state->rctx), request);
        safe_unlock(mc->instance);
 
        if (request->master_state == REQUEST_STOP_PROCESSING) ua = UNLANG_ACTION_STOP_PROCESSING;
@@ -924,7 +931,7 @@ static unlang_action_t unlang_module(rlm_rcode_t *p_result, request_t *request,
        request->module = mc->instance->name;
        safe_lock(mc->instance);        /* Noop unless instance->mutex set */
        ua = mc->method(&state->rcode,
-                       MODULE_CTX(mc->instance->dl_inst, state->thread->data, NULL),
+                       MODULE_CTX(mc->instance->dl_inst, state->thread->data, state->env_data, NULL),
                        request);
        safe_unlock(mc->instance);
 
index 96be8e64592ea5b9329e472919e8db0fa6e944aa..49291d769fea6f8f3cbca30f050fb0cd5aadc55a 100644 (file)
@@ -54,6 +54,8 @@ typedef struct {
                                                                ///< shared between all threads, so we can't
                                                                ///< cache thread-specific data in the #unlang_t.
 
+       void                            *env_data;              //!< Expanded per call module environment tmpls.
+
 #ifndef NDEBUG
        int                             unlang_indent;          //!< Record what this was when we entered the module.
 #endif
index 44542166f3074a0ff650b83e82c15c160960f2c2..846b291cd593fabbd5522966c7e7dcea4ec42db9 100644 (file)
@@ -345,7 +345,7 @@ static void mod_radius_signal(module_ctx_t const *mctx, request_t *request, fr_s
        if (!io->signal) return;
 
        io->signal(MODULE_CTX(inst->io_submodule->dl_inst,
-                             module_thread(inst->io_submodule)->data,
+                             module_thread(inst->io_submodule)->data, mctx->env_data,
                              mctx->rctx), request, action);
 }
 
index 97dee323536b206194e2903db9f5090f81da3574..9fcc0f57935f5c2db906f923396ec20ebe92b4fe 100644 (file)
@@ -63,5 +63,6 @@ void rest_io_xlat_signal(xlat_ctx_t const *xctx, request_t *request, fr_state_si
        rlm_rest_xlat_rctx_t            *our_rctx = talloc_get_type_abort(xctx->rctx, rlm_rest_xlat_rctx_t);
        fr_curl_io_request_t            *randle = talloc_get_type_abort(our_rctx->handle, fr_curl_io_request_t);
 
-       rest_io_module_signal(MODULE_CTX(dl_module_instance_by_data(mod_inst), t, randle), request, action);
+       rest_io_module_signal(MODULE_CTX(dl_module_instance_by_data(mod_inst), t, xctx->mctx->env_data, randle),
+                             request, action);
 }
index 586e2c3a42326df41c08151104cad13ff3220b8b..c0ad3cf5b4a4049428f98801f69e4a2013b52404 100644 (file)
@@ -518,7 +518,7 @@ static xlat_action_t rest_xlat(UNUSED TALLOC_CTX *ctx, UNUSED fr_dcursor_t *out,
         *
         *  @todo We could extract the User-Name and password from the URL string.
         */
-       ret = rest_request_config(MODULE_CTX(dl_module_instance_by_data(inst), t, NULL),
+       ret = rest_request_config(MODULE_CTX(dl_module_instance_by_data(inst), t, NULL, NULL),
                                  section, request, randle, section->method,
                                  section->body, uri_vb->vb_strvalue, NULL, NULL);
        if (ret < 0) goto error;
index 48d535af4095eac52c01d9f7b9809e4912c1d058..83bb3b3f682ce2ffe869311b05e922feb774a53c 100644 (file)
@@ -142,7 +142,7 @@ static void mod_tacacs_signal(module_ctx_t const *mctx, request_t *request, fr_s
        if (!io->signal) return;
 
        io->signal(MODULE_CTX(inst->io_submodule->dl_inst,
-                             module_thread(inst->io_submodule)->data,
+                             module_thread(inst->io_submodule)->data, mctx->env_data,
                              mctx->rctx), request, action);
 }