]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Tidy up ephemeral module_ctx_t struct creation
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 12 Nov 2021 02:06:02 +0000 (20:06 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 12 Nov 2021 03:08:56 +0000 (21:08 -0600)
16 files changed:
src/lib/server/auth.c
src/lib/server/dl_module.c
src/lib/server/module.c
src/lib/server/module.h
src/lib/server/module_ctx.h [new file with mode: 0644]
src/lib/server/virtual_servers.c
src/lib/unlang/module.c
src/modules/rlm_eap/rlm_eap.c
src/modules/rlm_lua/lua.c
src/modules/rlm_lua/rlm_lua.c
src/modules/rlm_mschap/rlm_mschap.c
src/modules/rlm_python/rlm_python.c
src/modules/rlm_radius/rlm_radius.c
src/modules/rlm_rest/io.c
src/modules/rlm_rest/rlm_rest.c
src/modules/rlm_yubikey/rlm_yubikey.c

index 12b88d6078d34c10ddc59ddd9771fe30621b6745..df3eb0dba3cd2887fa758efe33c780434a298bfc 100644 (file)
@@ -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);
index 5cf4b263c6e7da6316306a41426aa9e5ea4abe35..07fd862e487c323ede11cd285cfc8b725fa75d6b 100644 (file)
@@ -24,6 +24,9 @@
  * @copyright 2016-2019 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
  */
 RCSID("$Id$")
+#define _DL_MODULE_PRIVATE 1
+#include <freeradius-devel/server/dl_module.h>
+
 #include <freeradius-devel/server/log.h>
 #include <freeradius-devel/util/debug.h>
 
@@ -33,9 +36,6 @@ RCSID("$Id$")
 #include <ctype.h>
 #include <unistd.h>
 
-#define _DL_MODULE_PRIVATE 1
-#include <freeradius-devel/server/dl_module.h>
-
 #define DL_INIT_CHECK fr_assert(dl_module_loader)
 
 /** Wrapper struct around dl_loader_t
index 4c883a6bc4637b1be9d870ac2c65904400ed53cc..73eebc65781580d622c63065026cc2430a017a8d 100644 (file)
@@ -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;
index 5d7760e56ff94a910893856ed9e5a8336bc206f7..e5974d7adb11c39b82c574bb2b6750d8da2a1ae5 100644 (file)
@@ -31,6 +31,7 @@ extern "C" {
 
 #include <freeradius-devel/server/cf_util.h>
 #include <freeradius-devel/server/request.h>
+#include <freeradius-devel/server/module_ctx.h>
 #include <freeradius-devel/unlang/action.h>
 #include <freeradius-devel/unlang/compile.h>
 #include <freeradius-devel/util/event.h>
@@ -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 (file)
index 0000000..904c7a7
--- /dev/null
@@ -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 <a.cudbardb@freeradius.org>
+ */
+RCSIDH(module_ctx_h, "$Id$")
+
+#include <freeradius-devel/server/dl_module.h>
+#include <freeradius-devel/util/event.h>
+
+#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
index da49d28c19176f1bbf3461ed2679e63877075600..42d81d595679084403001af2585881884e7cea88 100644 (file)
@@ -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;
        }
index 238db6ef29a0cb4cc95ef7ffae9c54d2f2dfdf9e..740f538aeb42e7d0a7950d6c9f7316a6b32fab1d 100644 (file)
@@ -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;
index 83944f2ba27e1e4af592bd424ec49f409f93f910..82c8850094d2bb6c785cd7d73b7ef7ea66d3a916 100644 (file)
@@ -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);
index 037437462bf40aa827b827e1f9a1e057f54c11eb..71c2063921f0b78d9b3f8199155ef21ab5fbfa53 100644 (file)
@@ -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) {
index 3502a07c855cb5e77712fffa58830f76e751f8a8..e259b3127a0b1e11b839062e3c31441ddc7874f3 100644 (file)
@@ -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;
index d965d94b9ab222bebec1324c8d655b256fe47715..1da95a5dbcd4bed127b9ed6a78106c50e1f31470 100644 (file)
@@ -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();
index fd0d29fafb633c3d14f24656ffd27e34945af3af..4a6d760905454ebd8face7b0b4a2a1d52b4730e9 100644 (file)
@@ -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)
index ac0756c3352f95643e883691a584ebe57f16a5b8..039927ceebd79d838d4cad3d4be12e8451f17b3d 100644 (file)
@@ -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;
 }
index 50dd20a0c3de91029b20d3635013d4732def583d..09ad1e15d27fac8d505af4f41b5515659719187c 100644 (file)
@@ -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);
 }
index 581fc0488c89bedb26e2f746ff19945c5f1bacfc..26d66825e3120223012918687ece293ef45c7007 100644 (file)
@@ -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;
index 226fc61bdadfe469dc512266cd45fd11c95edd00..5a7bbc590a5076844bb6aa668f6d8c3c7b7b0ac2 100644 (file)
@@ -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