From: Nick Porter Date: Tue, 28 Feb 2023 11:05:22 +0000 (+0000) Subject: Add env_data to module_ctx, unlang_module_event and unlang_frame_state_module X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=661fee7fea85763fb19b906ed81db2917c3ec787;p=thirdparty%2Ffreeradius-server.git Add env_data to module_ctx, unlang_module_event and unlang_frame_state_module A pointer to the evaluated per-call environment data --- diff --git a/src/lib/server/auth.c b/src/lib/server/auth.c index eba404f66a4..7b2bb174ef4 100644 --- a/src/lib/server/auth.c +++ b/src/lib/server/auth.c @@ -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))); diff --git a/src/lib/server/module_ctx.h b/src/lib/server/module_ctx.h index 50d1f600bc4..efa267f01ce 100644 --- a/src/lib/server/module_ctx.h +++ b/src/lib/server/module_ctx.h @@ -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 * diff --git a/src/lib/unlang/module.c b/src/lib/unlang/module.c index a4d61f507b5..6822616d940 100644 --- a/src/lib/unlang/module.c +++ b/src/lib/unlang/module.c @@ -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); diff --git a/src/lib/unlang/module_priv.h b/src/lib/unlang/module_priv.h index 96be8e64592..49291d769fe 100644 --- a/src/lib/unlang/module_priv.h +++ b/src/lib/unlang/module_priv.h @@ -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 diff --git a/src/modules/rlm_radius/rlm_radius.c b/src/modules/rlm_radius/rlm_radius.c index 44542166f30..846b291cd59 100644 --- a/src/modules/rlm_radius/rlm_radius.c +++ b/src/modules/rlm_radius/rlm_radius.c @@ -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); } diff --git a/src/modules/rlm_rest/io.c b/src/modules/rlm_rest/io.c index 97dee323536..9fcc0f57935 100644 --- a/src/modules/rlm_rest/io.c +++ b/src/modules/rlm_rest/io.c @@ -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); } diff --git a/src/modules/rlm_rest/rlm_rest.c b/src/modules/rlm_rest/rlm_rest.c index 586e2c3a423..c0ad3cf5b4a 100644 --- a/src/modules/rlm_rest/rlm_rest.c +++ b/src/modules/rlm_rest/rlm_rest.c @@ -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; diff --git a/src/modules/rlm_tacacs/rlm_tacacs.c b/src/modules/rlm_tacacs/rlm_tacacs.c index 48d535af409..83bb3b3f682 100644 --- a/src/modules/rlm_tacacs/rlm_tacacs.c +++ b/src/modules/rlm_tacacs/rlm_tacacs.c @@ -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); }