From: Arran Cudbard-Bell Date: Fri, 12 Nov 2021 02:06:02 +0000 (-0600) Subject: Tidy up ephemeral module_ctx_t struct creation X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3ac24b1de85ba3e101d20750ea4a80ae67080c59;p=thirdparty%2Ffreeradius-server.git Tidy up ephemeral module_ctx_t struct creation --- diff --git a/src/lib/server/auth.c b/src/lib/server/auth.c index 12b88d6078..df3eb0dba3 100644 --- a/src/lib/server/auth.c +++ b/src/lib/server/auth.c @@ -168,7 +168,9 @@ 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_t){ .inst = dl_module_instance_by_data(request->async->process_inst) }, request); + request->async->process(&final, + MODULE_CTX(dl_module_instance_by_data(request->async->process_inst), NULL, NULL), + request); RDEBUG("} # server %s", cf_section_name2(unlang_call_current(request))); fr_cond_assert(final == RLM_MODULE_OK); diff --git a/src/lib/server/dl_module.c b/src/lib/server/dl_module.c index 5cf4b263c6..07fd862e48 100644 --- a/src/lib/server/dl_module.c +++ b/src/lib/server/dl_module.c @@ -24,6 +24,9 @@ * @copyright 2016-2019 Arran Cudbard-Bell (a.cudbardb@freeradius.org) */ RCSID("$Id$") +#define _DL_MODULE_PRIVATE 1 +#include + #include #include @@ -33,9 +36,6 @@ RCSID("$Id$") #include #include -#define _DL_MODULE_PRIVATE 1 -#include - #define DL_INIT_CHECK fr_assert(dl_module_loader) /** Wrapper struct around dl_loader_t diff --git a/src/lib/server/module.c b/src/lib/server/module.c index 4c883a6bc4..73eebc6578 100644 --- a/src/lib/server/module.c +++ b/src/lib/server/module.c @@ -1270,16 +1270,11 @@ int modules_thread_instantiate(TALLOC_CTX *ctx, fr_event_list_t *el) } DEBUG4("Worker alloced %s thread instance data (%p/%p)", ti->mi->module->name, ti, ti->data); - if (mi->module->thread_instantiate) { - if (mi->module->thread_instantiate(&(module_thread_inst_ctx_t){ - .inst = mi->dl_inst, - .thread = ti->data, - .el = el - }) < 0) { - PERROR("Thread instantiation failed for module \"%s\"", mi->name); - TALLOC_FREE(module_thread_inst_array); - return -1; - } + if (mi->module->thread_instantiate && + mi->module->thread_instantiate(MODULE_THREAD_INST_CTX(mi->dl_inst, ti->data, el)) < 0) { + PERROR("Thread instantiation failed for module \"%s\"", mi->name); + TALLOC_FREE(module_thread_inst_array); + return -1; } fr_assert(mi->number < talloc_array_length(module_thread_inst_array)); @@ -1334,11 +1329,8 @@ static int _module_instantiate(void *instance) /* * Call the module's instantiation routine. */ - if ((mi->module->instantiate)(&(module_inst_ctx_t){ - .inst = mi->dl_inst - }) < 0) { - cf_log_err(mi->dl_inst->conf, "Instantiation failed for module \"%s\"", - mi->name); + if (mi->module->instantiate(MODULE_INST_CTX(mi->dl_inst)) < 0) { + cf_log_err(mi->dl_inst->conf, "Instantiation failed for module \"%s\"", mi->name); return -1; } @@ -1597,9 +1589,7 @@ module_instance_t *module_bootstrap(module_instance_t const *parent, CONF_SECTIO if (mi->module->bootstrap) { cf_log_debug(mi->dl_inst->conf, "Bootstrapping module \"%s\"", mi->name); - if ((mi->module->bootstrap)(&(module_inst_ctx_t){ - .inst = mi->dl_inst, - }) < 0) { + if (mi->module->bootstrap(MODULE_INST_CTX(mi->dl_inst)) < 0) { cf_log_err(cs, "Bootstrap failed for module \"%s\"", mi->name); talloc_free(mi); return NULL; diff --git a/src/lib/server/module.h b/src/lib/server/module.h index 5d7760e56f..e5974d7adb 100644 --- a/src/lib/server/module.h +++ b/src/lib/server/module.h @@ -31,6 +31,7 @@ extern "C" { #include #include +#include #include #include #include @@ -39,9 +40,6 @@ typedef struct module_s module_t; typedef struct module_method_names_s module_method_names_t; typedef struct module_instance_s module_instance_t; typedef struct module_thread_instance_s module_thread_instance_t; -typedef struct module_ctx_s module_ctx_t; -typedef struct module_inst_ctx_s module_inst_ctx_t; -typedef struct module_thread_inst_ctx_s module_thread_inst_ctx_t; #define RLM_TYPE_THREAD_SAFE (0 << 0) //!< Module is threadsafe. #define RLM_TYPE_THREAD_UNSAFE (1 << 0) //!< Module is not threadsafe. @@ -252,33 +250,6 @@ typedef struct { module_method_t func; //!< State function. } module_state_func_table_t; -/** Temporary structure to hold arguments for module calls - * - */ -struct module_ctx_s { - dl_module_inst_t const *inst; //!< Dynamic loader API handle for the module. - void *thread; //!< Thread specific instance data. - void *rctx; //!< Resume ctx that a module previously set. -}; - -/** Temporary structure to hold arguments for instantiation calls - * - */ -struct module_inst_ctx_s { - dl_module_inst_t const *inst; //!< Dynamic loader API handle for the module. -}; - -/** Temporary structure to hold arguments for thread_instantiation calls - * - */ -struct module_thread_inst_ctx_s { - dl_module_inst_t const *inst; //!< Dynamic loader API handle for the module. - ///< Must come first to allow cast between - ///< module_inst_ctx. - void *thread; //!< Thread instance data. - fr_event_list_t *el; //!< Event list to register any IO handlers - ///< and timers against. -}; /** @name Convenience wrappers around other internal APIs to make them easier to instantiate with modules * diff --git a/src/lib/server/module_ctx.h b/src/lib/server/module_ctx.h new file mode 100644 index 0000000000..904c7a733a --- /dev/null +++ b/src/lib/server/module_ctx.h @@ -0,0 +1,172 @@ +#pragma once +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/** + * $Id$ + * + * @file lib/server/module_call_ctx.h + * @brief Temporary argument structures for module calls. + * + * These get used in various places where we may not want to include + * the full module.h. + * + * @copyright 2021 Arran Cudbard-bell + */ +RCSIDH(module_ctx_h, "$Id$") + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** Temporary structure to hold arguments for module calls + * + */ +typedef struct { + dl_module_inst_t const *inst; //!< Dynamic loader API handle for the module. + void *thread; //!< Thread specific instance data. + void *rctx; //!< Resume ctx that a module previously set. +} module_ctx_t; + +/** Temporary structure to hold arguments for instantiation calls + * + */ +typedef struct { + dl_module_inst_t const *inst; //!< Dynamic loader API handle for the module. +} module_inst_ctx_t; + +/** Temporary structure to hold arguments for thread_instantiation calls + * + */ +typedef struct { + dl_module_inst_t const *inst; //!< Dynamic loader API handle for the module. + ///< Must come first to allow cast between + ///< module_inst_ctx. + void *thread; //!< Thread instance data. + fr_event_list_t *el; //!< Event list to register any IO handlers + ///< and timers against. +} module_thread_inst_ctx_t; + +DIAG_OFF(unused-function) +/** Allocate a module calling ctx on the heap based on an instance ctx + * + */ +static module_ctx_t *module_ctx_from_inst(TALLOC_CTX *ctx, module_inst_ctx_t const *mctx) +{ + module_ctx_t *nmctx; + + MEM(nmctx = talloc_zero(ctx, module_ctx_t)); + nmctx->inst = mctx->inst; + + return nmctx; +} + +/** Allocate a module calling ctx on the heap based on an instance ctx + * + */ +static module_ctx_t *module_ctx_from_thread_inst(TALLOC_CTX *ctx, module_thread_inst_ctx_t const *mctx) +{ + module_ctx_t *nmctx; + + MEM(nmctx = talloc_zero(ctx, module_ctx_t)); + nmctx->inst = mctx->inst; + nmctx->thread = mctx->thread; + + return nmctx; +} + +/** Duplicate a stack based module_ctx_t on the heap + * + */ +static module_ctx_t *module_ctx_dup(TALLOC_CTX *ctx, module_ctx_t const *mctx) +{ + module_ctx_t *nmctx; + + nmctx = talloc_zero(ctx, module_ctx_t); + memcpy(nmctx, mctx, sizeof(*nmctx)); + + return nmctx; +} +DIAG_ON(unused-function) + +/** Wrapper to create a module_ctx_t as a compound literal + * + * This is used so that the compiler will flag any uses of (module_ctx_t) + * which don't set the required fields. Additional arguments should be added + * to this macro whenever the module_ctx_t fields are altered. + * + * @param[in] _dl_inst of the module being called. + * @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 } + +/** Wrapper to create a module_ctx_t as a compound literal from a module_inst_ctx_t + * + * This is used so that the compiler will flag any uses of (module_ctx_t) + * which don't set the required fields. Additional arguments should be added + * to this macro whenever the module_ctx_t fields are altered. + * + * @param[in] _mctx to copy fields from. + */ +#define MODULE_CTX_FROM_INST(_mctx) &(module_ctx_t){ .inst = (_mctx)->inst } + +/** Wrapper to create a module_ctx_t as a compound literal from a module_inst_ctx_t + * + * This is used so that the compiler will flag any uses of (module_ctx_t) + * which don't set the required fields. Additional arguments should be added + * to this macro whenever the module_ctx_t fields are altered. + * + * @param[in] _mctx to copy fields from. + */ +#define MODULE_CTX_FROM_THREAD_INST(_mctx) &(module_ctx_t){ .inst = (_mctx)->inst, .thread = (_mctx)->thread } + +/** Wrapper to create a module_inst_ctx_t as a compound literal + * + * This is used so that the compiler will flag any uses of (module_inst_ctx_t) + * which don't set the required fields. Additional arguments should be added + * to this macro whenever the module_inst_ctx_t fields are altered. + * + * @param[in] _dl_inst of the module being called.. + */ +#define MODULE_INST_CTX(_dl_inst) &(module_inst_ctx_t){ .inst = _dl_inst } + +/** Wrapper to create a module_thread_inst_ctx_t as a compound literal + * + * This is used so that the compiler will flag any uses of (module_thread_inst_ctx_t) + * which don't set the required fields. Additional arguments should be added + * to this macro whenever the module_thread_inst_ctx_t fields are altered. + * + * @param[in] _dl_inst of the module being called. + * @param[in] _thread instance of the module being called. + * @param[in] _el Thread specific event list. + */ +#define MODULE_THREAD_INST_CTX(_dl_inst, _thread, _el) &(module_thread_inst_ctx_t){ .inst = _dl_inst, .thread = _thread, .el = _el } + +/** Wrapper to create a module_inst_ctx_t as a comound listeral from a module_thread_ctx_t + * + * Extract the dl_module_inst_t from a module_thread_inst_ctx_t. + * + * @param[in] _mctx to extract module_thread_inst_ctx_t from. + */ +#define MODULE_THREAD_INST_CTX_FROM_INST_CTX(_mctx) &(module_ctx_t){ .inst = (_mctx)->inst } + +#ifdef __cplusplus +} +#endif diff --git a/src/lib/server/virtual_servers.c b/src/lib/server/virtual_servers.c index da49d28c19..42d81d5956 100644 --- a/src/lib/server/virtual_servers.c +++ b/src/lib/server/virtual_servers.c @@ -723,9 +723,7 @@ static int process_instantiate(CONF_SECTION *server_cs, dl_module_inst_t *dl_ins fr_process_module_t const *process = (fr_process_module_t const *) dl_inst->module->common; if (process->instantiate && - (process->instantiate(&(module_inst_ctx_t){ - .inst = dl_inst - }) < 0)) { + (process->instantiate(MODULE_INST_CTX(dl_inst)) < 0)) { cf_log_err(dl_inst->conf, "Instantiate failed"); return -1; } @@ -881,9 +879,7 @@ static int process_bootstrap(dl_module_inst_t *dl_inst, char const *namespace) fr_process_module_t const *process = (fr_process_module_t const *) dl_inst->module->common; if (process->bootstrap && - (process->bootstrap(&(module_inst_ctx_t){ - .inst = dl_inst - }) < 0)) { + (process->bootstrap(MODULE_INST_CTX(dl_inst)) < 0)) { cf_log_err(dl_inst->conf, "Bootstrap failed"); return -1; } diff --git a/src/lib/unlang/module.c b/src/lib/unlang/module.c index 238db6ef29..740f538aeb 100644 --- a/src/lib/unlang/module.c +++ b/src/lib/unlang/module.c @@ -67,11 +67,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_t){ - .inst = ev->dl_inst, - .thread = ev->thread, - .rctx = UNCONST(void *, ev->ctx) }, - ev->request, fd); + ev->fd_read(MODULE_CTX(ev->dl_inst, ev->thread, UNCONST(void *, ev->ctx)), ev->request, fd); } /** Frees an unlang event, removing it from the request's event loop @@ -108,11 +104,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_t){ - .inst = ev->dl_inst, - .thread = ev->thread, - .rctx = UNCONST(void *, ev->ctx) - }, ev->request, now); + ev->timeout(MODULE_CTX(ev->dl_inst, ev->thread, UNCONST(void *, ev->ctx)), ev->request, now); talloc_free(ev); } @@ -202,11 +194,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_t){ - .inst = ev->dl_inst, - .thread = ev->thread, - .rctx = UNCONST(void *, ev->ctx) }, - ev->request, fd); + ev->fd_write(MODULE_CTX(ev->dl_inst, ev->thread, UNCONST(void *, ev->ctx)), ev->request, fd); } /** Call the callback registered for an I/O error event @@ -224,11 +212,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_t){ - .inst = ev->dl_inst, - .thread = ev->thread, - .rctx = UNCONST(void *, ev->ctx) - }, ev->request, fd); + ev->fd_error(MODULE_CTX(ev->dl_inst, ev->thread, UNCONST(void *, ev->ctx)), ev->request, fd); } @@ -547,11 +531,8 @@ unlang_action_t unlang_module_yield_to_section(rlm_rcode_t *p_result, stack->result = frame->result = default_rcode; return resume(p_result, - &(module_ctx_t){ - .inst = mc->instance->dl_inst, - .thread = module_thread(mc->instance)->data, - .rctx = rctx - }, request); + MODULE_CTX(mc->instance->dl_inst, module_thread(mc->instance)->data, rctx), + request); } /* @@ -644,12 +625,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_t){ - .inst = mc->instance->dl_inst, - .thread = state->thread->data, - .rctx = state->rctx - }, - request, action); + state->signal(MODULE_CTX(mc->instance->dl_inst, state->thread->data, state->rctx), request, action); safe_unlock(mc->instance); request->module = caller; @@ -741,12 +717,7 @@ 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_t){ - .inst = mc->instance->dl_inst, - .thread = state->thread->data, - .rctx = state->rctx, - }, request); + ua = resume(&state->rcode, MODULE_CTX(mc->instance->dl_inst, state->thread->data, state->rctx), request); safe_unlock(mc->instance); request->rcode = state->rcode; @@ -951,10 +922,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_t){ - .inst = mc->instance->dl_inst, - .thread = state->thread->data - }, + MODULE_CTX(mc->instance->dl_inst, state->thread->data, NULL), request); safe_unlock(mc->instance); request->module = caller; diff --git a/src/modules/rlm_eap/rlm_eap.c b/src/modules/rlm_eap/rlm_eap.c index 83944f2ba2..82c8850094 100644 --- a/src/modules/rlm_eap/rlm_eap.c +++ b/src/modules/rlm_eap/rlm_eap.c @@ -178,10 +178,9 @@ static int submodule_parse(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *paren case FR_EAP_METHOD_AKA: case FR_EAP_METHOD_SIM: { - module_inst_ctx_t *mctx = &(module_inst_ctx_t){ - .inst = ((dl_module_inst_t *)cf_data_value(cf_data_find(eap_cs, - dl_module_inst_t, "rlm_eap"))) - }; + module_inst_ctx_t *mctx = MODULE_INST_CTX( + ((dl_module_inst_t *)cf_data_value(cf_data_find(eap_cs, + dl_module_inst_t, "rlm_eap")))); WARN("Ignoring EAP method %s because we don't have OpenSSL support", name); talloc_free(our_name); diff --git a/src/modules/rlm_lua/lua.c b/src/modules/rlm_lua/lua.c index 037437462b..71c2063921 100644 --- a/src/modules/rlm_lua/lua.c +++ b/src/modules/rlm_lua/lua.c @@ -881,7 +881,7 @@ int fr_lua_init(lua_State **out, module_inst_ctx_t const *mctx) rlm_lua_t const *inst = talloc_get_type_abort_const(mctx->inst->data, rlm_lua_t); lua_State *L; - fr_lua_util_set_mctx(&(module_ctx_t){ .inst = mctx->inst }); + fr_lua_util_set_mctx(MODULE_CTX_FROM_INST(mctx)); L = luaL_newstate(); if (!L) { diff --git a/src/modules/rlm_lua/rlm_lua.c b/src/modules/rlm_lua/rlm_lua.c index 3502a07c85..e259b3127a 100644 --- a/src/modules/rlm_lua/rlm_lua.c +++ b/src/modules/rlm_lua/rlm_lua.c @@ -114,13 +114,13 @@ static int mod_detach(module_detach_ctx_t const *mctx) */ if (inst->interpreter) { if (inst->func_detach) { - fr_lua_run(&ret, &(module_ctx_t){ - .inst = mctx->inst, - .thread = &(rlm_lua_thread_t){ + fr_lua_run(&ret, + MODULE_CTX(mctx->inst, + &(rlm_lua_thread_t){ .interpreter = inst->interpreter - } - }, - NULL, inst->func_detach); + }, + NULL), + NULL, inst->func_detach); } lua_close(inst->interpreter); } @@ -143,13 +143,13 @@ static int mod_instantiate(module_inst_ctx_t const *mctx) DEBUG("Using %s interpreter", fr_lua_version(inst->interpreter)); if (inst->func_instantiate) { - fr_lua_run(&rcode, &(module_ctx_t){ - .inst = mctx->inst, - .thread = &(rlm_lua_thread_t){ - .interpreter = inst->interpreter - } - }, - NULL, inst->func_instantiate); + fr_lua_run(&rcode, + MODULE_CTX(mctx->inst, + &(rlm_lua_thread_t){ + .interpreter = inst->interpreter + }, + NULL), + NULL, inst->func_instantiate); } return 0; diff --git a/src/modules/rlm_mschap/rlm_mschap.c b/src/modules/rlm_mschap/rlm_mschap.c index d965d94b9a..1da95a5dbc 100644 --- a/src/modules/rlm_mschap/rlm_mschap.c +++ b/src/modules/rlm_mschap/rlm_mschap.c @@ -723,7 +723,7 @@ static int _mod_conn_free(struct wbcContext **wb_ctx) static void *mod_conn_create(TALLOC_CTX *ctx, void *instance, UNUSED fr_time_delta_t timeout) { struct wbcContext **wb_ctx; - module_inst_ctx_t *mctx = &(module_inst_ctx_t){ .inst = dl_module_instance_by_data(instance) }; + module_inst_ctx_t *mctx = MODULE_INST_CTX(dl_module_instance_by_data(instance)); wb_ctx = talloc_zero(ctx, struct wbcContext *); *wb_ctx = wbcCtxCreate(); diff --git a/src/modules/rlm_python/rlm_python.c b/src/modules/rlm_python/rlm_python.c index fd0d29fafb..4a6d760905 100644 --- a/src/modules/rlm_python/rlm_python.c +++ b/src/modules/rlm_python/rlm_python.c @@ -656,7 +656,7 @@ static int python_function_load(module_inst_ctx_t const *mctx, python_func_def_t if (!def->module) { ERROR("%s - Module '%s' load failed", funcname, def->module_name); error: - python_error_log(&(module_ctx_t){ .inst = mctx->inst }, NULL); + python_error_log(MODULE_CTX_FROM_INST(mctx), NULL); Py_XDECREF(def->function); def->function = NULL; Py_XDECREF(def->module); @@ -781,7 +781,7 @@ static int python_module_import_config(module_inst_ctx_t const *mctx, CONF_SECTI error: Py_XDECREF(inst->pythonconf_dict); inst->pythonconf_dict = NULL; - python_error_log(&(module_ctx_t){ .inst = mctx->inst }, NULL); + python_error_log(MODULE_CTX_FROM_INST(mctx), NULL); return -1; } @@ -809,7 +809,7 @@ static int python_module_import_constants(module_inst_ctx_t const *mctx, PyObjec for (i = 0; freeradius_constants[i].name; i++) { if ((PyModule_AddIntConstant(module, freeradius_constants[i].name, freeradius_constants[i].value)) < 0) { ERROR("Failed adding constant to module"); - python_error_log(&(module_ctx_t){ .inst = mctx->inst }, NULL); + python_error_log(MODULE_CTX_FROM_INST(mctx), NULL); return -1; } } @@ -878,7 +878,7 @@ static int python_interpreter_init(module_inst_ctx_t const *mctx) * called during interpreter initialisation * it can get at the current instance config. */ - current_mctx = &(module_ctx_t){ .inst = mctx->inst }; + current_mctx = MODULE_CTX_FROM_INST(mctx); current_conf = conf; PyEval_RestoreThread(global_interpreter); @@ -975,7 +975,7 @@ static int mod_instantiate(module_inst_ctx_t const *mctx) if (inst->instantiate.function) { rlm_rcode_t rcode; - do_python_single(&rcode, &(module_ctx_t){ .inst = mctx->inst }, NULL, inst->instantiate.function, "instantiate"); + do_python_single(&rcode, MODULE_CTX_FROM_INST(mctx), NULL, inst->instantiate.function, "instantiate"); switch (rcode) { case RLM_MODULE_FAIL: case RLM_MODULE_REJECT: @@ -1019,7 +1019,7 @@ static int mod_detach(module_detach_ctx_t const *mctx) if (inst->detach.function) { rlm_rcode_t rcode; - (void)do_python_single(&rcode, &(module_ctx_t){ .inst = mctx->inst }, NULL, inst->detach.function, "detach"); + (void)do_python_single(&rcode, MODULE_CTX_FROM_INST(mctx), NULL, inst->detach.function, "detach"); } #define PYTHON_FUNC_DESTROY(_x) python_function_destroy(&inst->_x) diff --git a/src/modules/rlm_radius/rlm_radius.c b/src/modules/rlm_radius/rlm_radius.c index ac0756c335..039927ceeb 100644 --- a/src/modules/rlm_radius/rlm_radius.c +++ b/src/modules/rlm_radius/rlm_radius.c @@ -377,11 +377,7 @@ static void mod_radius_signal(module_ctx_t const *mctx, request_t *request, fr_s if (!inst->io->signal) return; - inst->io->signal(&(module_ctx_t){ - .inst = inst->io_submodule, - .thread = t->io_thread, - .rctx = mctx->rctx - }, request, action); + inst->io->signal(MODULE_CTX(inst->io_submodule, t->io_thread, mctx->rctx), request, action); } @@ -393,12 +389,7 @@ static unlang_action_t mod_radius_resume(rlm_rcode_t *p_result, module_ctx_t con rlm_radius_t const *inst = talloc_get_type_abort_const(mctx->inst->data, rlm_radius_t); rlm_radius_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_radius_thread_t); - return inst->io->resume(p_result, - &(module_ctx_t){ - .inst = inst->io_submodule, - .thread = t->io_thread, - .rctx = mctx->rctx - }, request); + return inst->io->resume(p_result, MODULE_CTX(inst->io_submodule, t->io_thread, mctx->rctx), request); } /** Do any RADIUS-layer fixups for proxying. @@ -517,11 +508,8 @@ static int mod_thread_detach(module_thread_inst_ctx_t const *mctx) * connections. */ if (inst->io->thread_detach && - (inst->io->thread_detach(&(module_thread_inst_ctx_t){ - .inst = inst->io_submodule, - .thread = t->io_thread, - .el = mctx->el - }) < 0)) { + (inst->io->thread_detach(MODULE_THREAD_INST_CTX(inst->io_submodule, + t->io_thread, mctx->el)) < 0)) { return -1; } @@ -555,11 +543,8 @@ static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx) * sockets, set timers, etc. */ if (inst->io->thread_instantiate && - inst->io->thread_instantiate(&(module_thread_inst_ctx_t){ - .inst = inst->io_submodule, - .thread = t->io_thread, - .el = mctx->el - }) < 0) return -1; + inst->io->thread_instantiate(MODULE_THREAD_INST_CTX(inst->io_submodule, + t->io_thread, mctx->el)) < 0) return -1; return 0; } @@ -569,9 +554,7 @@ static int mod_instantiate(module_inst_ctx_t const *mctx) rlm_radius_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_radius_t); if (inst->io->instantiate && - inst->io->instantiate(&(module_inst_ctx_t){ - .inst = inst->io_submodule - }) < 0) return -1; + inst->io->instantiate(MODULE_INST_CTX(inst->io_submodule)) < 0) return -1; return 0; } @@ -756,9 +739,7 @@ setup_io_submodule: * Bootstrap the submodule. */ if (inst->io->bootstrap && - inst->io->bootstrap(&(module_inst_ctx_t){ - .inst = inst->io_submodule - }) < 0) return -1; + inst->io->bootstrap(MODULE_INST_CTX(inst->io_submodule)) < 0) return -1; return 0; } diff --git a/src/modules/rlm_rest/io.c b/src/modules/rlm_rest/io.c index 50dd20a0c3..09ad1e15d2 100644 --- a/src/modules/rlm_rest/io.c +++ b/src/modules/rlm_rest/io.c @@ -65,5 +65,5 @@ void rest_io_xlat_signal(request_t *request, UNUSED void *instance, void *thread rlm_rest_xlat_rctx_t *our_rctx = talloc_get_type_abort(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_action(&(module_ctx_t){ .inst = dl_module_instance_by_data(mod_inst), .thread = t, .rctx = randle }, request, action); + rest_io_module_action(MODULE_CTX(dl_module_instance_by_data(mod_inst), t, randle), request, action); } diff --git a/src/modules/rlm_rest/rlm_rest.c b/src/modules/rlm_rest/rlm_rest.c index 581fc0488c..26d66825e3 100644 --- a/src/modules/rlm_rest/rlm_rest.c +++ b/src/modules/rlm_rest/rlm_rest.c @@ -504,7 +504,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_t){ .inst = dl_module_instance_by_data(mod_inst), .thread = t }, + ret = rest_request_config(MODULE_CTX(dl_module_instance_by_data(mod_inst), t, 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_yubikey/rlm_yubikey.c b/src/modules/rlm_yubikey/rlm_yubikey.c index 226fc61bda..5a7bbc590a 100644 --- a/src/modules/rlm_yubikey/rlm_yubikey.c +++ b/src/modules/rlm_yubikey/rlm_yubikey.c @@ -190,7 +190,7 @@ static int mod_bootstrap(module_inst_ctx_t const *mctx) #ifndef HAVE_YUBIKEY if (inst->decrypt) { - cf_log_err(conf, "Requires libyubikey for OTP decryption"); + cf_log_err(mctx->inst->conf, "Requires libyubikey for OTP decryption"); return -1; } #endif