From: Arran Cudbard-Bell Date: Thu, 11 Nov 2021 21:00:46 +0000 (-0600) Subject: Use structures to pass arguments to instantiation and detach functions X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=188e5447c72fb6e188dc5db3f44f943f098aea42;p=thirdparty%2Ffreeradius-server.git Use structures to pass arguments to instantiation and detach functions --- diff --git a/src/lib/ldap/connection.c b/src/lib/ldap/connection.c index 6fbb422028..d33eea3363 100644 --- a/src/lib/ldap/connection.c +++ b/src/lib/ldap/connection.c @@ -507,11 +507,13 @@ static void _ldap_trunk_idle_timeout(fr_event_list_t *el, UNUSED fr_time_t now, * * Inform the remote LDAP server that we no longer want responses to specific queries. * + * @param[in] el For timer mangement. * @param[in] tconn The trunk connection handle * @param[in] conn The specific connection queries will be cancelled on * @param[in] uctx Context provided to fr_trunk_alloc */ -static void ldap_request_cancel_mux(fr_trunk_connection_t *tconn, fr_connection_t *conn, UNUSED void *uctx) +static void ldap_request_cancel_mux(UNUSED fr_event_list_t *el, fr_trunk_connection_t *tconn, + fr_connection_t *conn, UNUSED void *uctx) { fr_trunk_request_t *treq; fr_ldap_connection_t *ldap_conn = talloc_get_type_abort(conn->h, fr_ldap_connection_t); @@ -748,11 +750,12 @@ static void ldap_trunk_request_mux(UNUSED fr_event_list_t *el, fr_trunk_connecti * only gather those which are complete before either following a referral or passing * the head of the resulting chain of messages back. * + * @param[in] el To insert timers into. * @param[in] tconn Trunk connection associated with these results. * @param[in] conn Connection handle for these results. * @param[in] uctx Thread specific trunk structure - contains tree of pending queries. */ -static void ldap_trunk_request_demux(fr_trunk_connection_t *tconn, fr_connection_t *conn, void *uctx) +static void ldap_trunk_request_demux(fr_event_list_t *el, fr_trunk_connection_t *tconn, fr_connection_t *conn, void *uctx) { fr_ldap_connection_t *ldap_conn = talloc_get_type_abort(conn->h, fr_ldap_connection_t); fr_ldap_thread_trunk_t *ttrunk = talloc_get_type_abort(uctx, fr_ldap_thread_trunk_t); @@ -768,7 +771,7 @@ static void ldap_trunk_request_demux(fr_trunk_connection_t *tconn, fr_connection /* * Reset the idle timeout event */ - fr_event_timer_in(ttrunk, ttrunk->t->el, &ttrunk->ev, + fr_event_timer_in(ttrunk, el, &ttrunk->ev, ttrunk->t->config->idle_timeout, _ldap_trunk_idle_timeout, ttrunk); do { diff --git a/src/lib/server/dl_module.c b/src/lib/server/dl_module.c index 7a86cae8f4..5cf4b263c6 100644 --- a/src/lib/server/dl_module.c +++ b/src/lib/server/dl_module.c @@ -256,7 +256,7 @@ static int _dl_module_instance_data_free(void *data) return -1; } - if (dl_inst->module->common->detach) dl_inst->module->common->detach(dl_inst->data); + if (dl_inst->module->common->detach) dl_inst->module->common->detach(&(module_detach_ctx_t){ .inst = dl_inst }); return 0; } diff --git a/src/lib/server/dl_module.h b/src/lib/server/dl_module.h index bc98572c8b..def61141a6 100644 --- a/src/lib/server/dl_module.h +++ b/src/lib/server/dl_module.h @@ -57,6 +57,8 @@ extern "C" { # define DL_EXTENSION ".so" #endif +typedef struct dl_module_instance_s dl_module_inst_t; + /** Stop people using different module/library/server versions together * */ @@ -80,6 +82,10 @@ typedef enum { typedef struct dl_module_loader_s dl_module_loader_t; +typedef struct { + dl_module_inst_t const *inst; +} module_detach_ctx_t; + /** Module detach callback * * Is called just before the server exits, and after re-instantiation on HUP, @@ -88,12 +94,12 @@ typedef struct dl_module_loader_s dl_module_loader_t; * Detach should close all handles associated with the module instance, and * free any memory allocated during instantiate. * - * @param[in] instance to free. + * @param[in] inst to free. * @return * - 0 on success. * - -1 if detach failed. */ -typedef int (*module_detach_t)(void *instance); +typedef int (*module_detach_t)(module_detach_ctx_t const *inst); /** Callback to call when a module is first loaded * @@ -152,7 +158,6 @@ struct dl_module_s { * * Used to pass data back from dl_module_instance_parse_func */ -typedef struct dl_module_instance_s dl_module_inst_t; struct dl_module_instance_s { char const * _CONST name; //!< Instance name. dl_module_t const * _CONST module; //!< Module diff --git a/src/lib/server/module.c b/src/lib/server/module.c index 7d1bb328fd..4c883a6bc4 100644 --- a/src/lib/server/module.c +++ b/src/lib/server/module.c @@ -1199,7 +1199,13 @@ static int _module_thread_inst_array_free(module_thread_instance_t **array) * and should be removed along with * starting the instance number at 0 */ - if (ti->mi && ti->mi->module->thread_detach) ti->mi->module->thread_detach(ti->el, ti->data); + if (ti->mi && ti->mi->module->thread_detach) { + ti->mi->module->thread_detach(&(module_thread_inst_ctx_t const ){ + .inst = ti->mi->dl_inst, + .thread = ti->data, + .el = ti->el + }); + } talloc_free(ti); } @@ -1265,7 +1271,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(mi->dl_inst->conf, mi->dl_inst->data, el, ti->data) < 0) { + 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; @@ -1324,7 +1334,9 @@ static int _module_instantiate(void *instance) /* * Call the module's instantiation routine. */ - if ((mi->module->instantiate)(mi->dl_inst->data, mi->dl_inst->conf) < 0) { + 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); @@ -1585,7 +1597,9 @@ 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)(mi->dl_inst->data, cs) < 0) { + if ((mi->module->bootstrap)(&(module_inst_ctx_t){ + .inst = 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 f35d79b60e..5d7760e56f 100644 --- a/src/lib/server/module.h +++ b/src/lib/server/module.h @@ -40,6 +40,8 @@ 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. @@ -66,42 +68,36 @@ typedef unlang_action_t (*module_method_t)(rlm_rcode_t *p_result, module_ctx_t c * Is called once per module instance. Is not called when new threads are * spawned. See module_thread_instantiate_t for that. * - * @param[in] mod_cs Module instance's configuration section. - * @param[in] instance data, specific to an instantiated module. - * Pre-allocated, and populated during the - * bootstrap and instantiate calls. + * @param[in] mctx Holds global instance data. * @return * - 0 on success. * - -1 if instantiation failed. */ -typedef int (*module_instantiate_t)(void *instance, CONF_SECTION *mod_cs); +typedef int (*module_instantiate_t)(module_inst_ctx_t const *mctx); /** Module thread creation callback * * Called whenever a new thread is created. * - * @param[in] mod_cs Module instance's configuration section. - * @param[in] instance data, specific to an instantiated module. - * Pre-allocated, and populated during the - * bootstrap and instantiate calls. - * @param[in] el The event list serviced by this thread. - * @param[in] thread data specific to this module instance. + * @param[in] mctx Holds global instance data, thread instance + * data, and the thread-specific event list. * @return * - 0 on success. * - -1 if instantiation failed. */ -typedef int (*module_thread_instantiate_t)(CONF_SECTION const *mod_cs, void *instance, fr_event_list_t *el, void *thread); +typedef int (*module_thread_instantiate_t)(module_thread_inst_ctx_t const *mctx); /** Module thread destruction callback * * Destroy a module/thread instance. * - * @param[in] thread data specific to this module instance. + * @param[in] mctx Holds global instance data, thread instance + * data, and the thread-specific event list. * @return * - 0 on success. * - -1 if instantiation failed. */ -typedef int (*module_thread_detach_t)(fr_event_list_t *el, void *thread); +typedef int (*module_thread_detach_t)(module_thread_inst_ctx_t const *mctx); #define FR_MODULE_COMMON \ struct { \ @@ -265,6 +261,25 @@ struct module_ctx_s { 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/trunk.c b/src/lib/server/trunk.c index 8d46448145..8428e553e9 100644 --- a/src/lib/server/trunk.c +++ b/src/lib/server/trunk.c @@ -622,7 +622,7 @@ do { \ (_tconn)->pub.conn, \ (_tconn)->pub.trunk->uctx); \ (_tconn)->pub.trunk->in_handler = (void *)(_tconn)->pub.trunk->funcs.request_demux; \ - (_tconn)->pub.trunk->funcs.request_demux((_tconn), (_tconn)->pub.conn, (_tconn)->pub.trunk->uctx); \ + (_tconn)->pub.trunk->funcs.request_demux((_tconn)->pub.trunk->el, (_tconn), (_tconn)->pub.conn, (_tconn)->pub.trunk->uctx); \ (_tconn)->pub.trunk->in_handler = _prev; \ } while(0) @@ -639,7 +639,7 @@ do { \ (_tconn)->pub.conn, \ (_tconn)->pub.trunk->uctx); \ (_tconn)->pub.trunk->in_handler = (void *)(_tconn)->pub.trunk->funcs.request_cancel_mux; \ - (_tconn)->pub.trunk->funcs.request_cancel_mux((_tconn), (_tconn)->pub.conn, (_tconn)->pub.trunk->uctx); \ + (_tconn)->pub.trunk->funcs.request_cancel_mux((_tconn)->pub.trunk->el, (_tconn), (_tconn)->pub.conn, (_tconn)->pub.trunk->uctx); \ (_tconn)->pub.trunk->in_handler = _prev; \ } \ } while(0) diff --git a/src/lib/server/trunk.h b/src/lib/server/trunk.h index ddf117197f..73641589ee 100644 --- a/src/lib/server/trunk.h +++ b/src/lib/server/trunk.h @@ -461,7 +461,6 @@ typedef void (*fr_trunk_connection_notify_t)(fr_trunk_connection_t *tconn, fr_co * popping/processing other requests. * * @param[in] el For timer management. - * * @param[in] tconn The trunk connection to dequeue trunk * requests from. * @param[in] conn Connection to write the request to. @@ -496,13 +495,15 @@ typedef void (*fr_trunk_request_mux_t)(fr_event_list_t *el, * used for reporting failures at an I/O layer level not failures of queries or * external services. * + * @param[in] el For timer management. * @param[in] tconn The trunk connection. * @param[in] conn Connection to read the request from. * Use conn->h to access the * connection handle or file descriptor. * @param[in] uctx User context data passed to #fr_trunk_alloc. */ -typedef void (*fr_trunk_request_demux_t)(fr_trunk_connection_t *tconn, fr_connection_t *conn, void *uctx); +typedef void (*fr_trunk_request_demux_t)(fr_event_list_t *el, + fr_trunk_connection_t *tconn, fr_connection_t *conn, void *uctx); /** Inform a remote service like a datastore that a request should be cancelled * @@ -526,6 +527,8 @@ typedef void (*fr_trunk_request_demux_t)(fr_trunk_connection_t *tconn, fr_connec * remove the entry from the tracking tree and call * #fr_trunk_request_signal_cancel_complete. * + * @param[in] el To insert any timers into. + * * @param[in] tconn The trunk connection used to dequeue * cancellation requests. * @param[in] conn Connection to write the request to. @@ -533,7 +536,8 @@ typedef void (*fr_trunk_request_demux_t)(fr_trunk_connection_t *tconn, fr_connec * connection handle or file descriptor. * @param[in] uctx User context data passed to #fr_trunk_alloc. */ -typedef void (*fr_trunk_request_cancel_mux_t)(fr_trunk_connection_t *tconn, fr_connection_t *conn, void *uctx); +typedef void (*fr_trunk_request_cancel_mux_t)(fr_event_list_t *el, + fr_trunk_connection_t *tconn, fr_connection_t *conn, void *uctx); /** Remove an outstanding "sent" request from a tracking/matching structure * diff --git a/src/lib/server/trunk_tests.c b/src/lib/server/trunk_tests.c index 2399610b04..fc7f51831a 100644 --- a/src/lib/server/trunk_tests.c +++ b/src/lib/server/trunk_tests.c @@ -57,7 +57,7 @@ static void test_mux(UNUSED fr_event_list_t *el, fr_trunk_connection_t *tconn, f TEST_CHECK(count > 0); } -static void test_cancel_mux(fr_trunk_connection_t *tconn, fr_connection_t *conn, UNUSED void *uctx) +static void test_cancel_mux(UNUSED fr_event_list_t *el, fr_trunk_connection_t *tconn, fr_connection_t *conn, UNUSED void *uctx) { fr_trunk_request_t *treq; size_t count = 0; @@ -94,7 +94,7 @@ static void test_cancel_mux(fr_trunk_connection_t *tconn, fr_connection_t *conn, TEST_CHECK(count > 0); } -static void test_demux(UNUSED fr_trunk_connection_t *tconn, fr_connection_t *conn, UNUSED void *uctx) +static void test_demux(UNUSED fr_event_list_t *el, UNUSED fr_trunk_connection_t *tconn, fr_connection_t *conn, UNUSED void *uctx) { int fd = *(talloc_get_type_abort(conn->h, int)); test_proto_request_t *preq; diff --git a/src/lib/server/virtual_servers.c b/src/lib/server/virtual_servers.c index 49ad0d7990..da49d28c19 100644 --- a/src/lib/server/virtual_servers.c +++ b/src/lib/server/virtual_servers.c @@ -723,7 +723,9 @@ 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(dl_inst->data, dl_inst->conf) < 0)) { + (process->instantiate(&(module_inst_ctx_t){ + .inst = dl_inst + }) < 0)) { cf_log_err(dl_inst->conf, "Instantiate failed"); return -1; } @@ -879,8 +881,9 @@ 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(dl_inst->data, - dl_inst->conf) < 0)) { + (process->bootstrap(&(module_inst_ctx_t){ + .inst = dl_inst + }) < 0)) { cf_log_err(dl_inst->conf, "Bootstrap failed"); return -1; } diff --git a/src/lib/util/net.c b/src/lib/util/net.c index 795610d9c7..585ac9d9bc 100644 --- a/src/lib/util/net.c +++ b/src/lib/util/net.c @@ -165,7 +165,7 @@ uint16_t fr_ip_header_checksum(uint8_t const *data, uint8_t ihl) return ((uint16_t) ~sum); } -uint16_t fr_ip6_pesudo_header_checksum(struct in6_addr *src, struct in6_addr *dst, uint16_t ip_len, uint8_t ip_next) +uint16_t fr_ip6_pesudo_header_checksum(struct in6_addr const *src, struct in6_addr const *dst, uint16_t ip_len, uint8_t ip_next) { uint64_t sum = 0; ip_pseudo_header6_t ip6; /* Keep correct alignment for the pointer */ diff --git a/src/lib/util/net.h b/src/lib/util/net.h index e548f61104..5de3433507 100644 --- a/src/lib/util/net.h +++ b/src/lib/util/net.h @@ -153,7 +153,7 @@ uint16_t fr_udp_checksum(uint8_t const *data, uint16_t len, uint16_t checksum, struct in_addr const src_addr, struct in_addr const dst_addr); int fr_udp_header_check(uint8_t const *data, uint16_t remaining, ip_header_t const *ip); uint16_t fr_ip_header_checksum(uint8_t const *data, uint8_t ihl); -uint16_t fr_ip6_pesudo_header_checksum(struct in6_addr *src, struct in6_addr *dst, uint16_t ip_len, uint8_t ip_next); +uint16_t fr_ip6_pesudo_header_checksum(struct in6_addr const *src, struct in6_addr const *dst, uint16_t ip_len, uint8_t ip_next); /** Write out an unsigned 16bit integer in wire format (big endian) * diff --git a/src/modules/rlm_always/rlm_always.c b/src/modules/rlm_always/rlm_always.c index 068eb8e35b..fd7b0460d9 100644 --- a/src/modules/rlm_always/rlm_always.c +++ b/src/modules/rlm_always/rlm_always.c @@ -24,7 +24,7 @@ */ RCSID("$Id$") -#define LOG_PREFIX inst->name +#define LOG_PREFIX mctx->inst->name #include #include @@ -34,7 +34,6 @@ RCSID("$Id$") * going to return. */ typedef struct { - char const *name; char const *rcode_str; //!< The base value. module_instance_t *mi; @@ -123,37 +122,34 @@ done: } -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - rlm_always_t *inst = instance; + rlm_always_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_always_t); xlat_t *xlat; - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - - inst->mi = module_by_name(NULL, inst->name); + inst->mi = module_by_name(NULL, mctx->inst->name); if (!inst->mi) { - cf_log_err(conf, "Can't find the module instance data for this module: %s", inst->name); + cf_log_err(mctx->inst->conf, "Can't find the module instance data for this module: %s", mctx->inst->name); return -1; } - xlat = xlat_register(inst, inst->name, always_xlat, false); + xlat = xlat_register(inst, mctx->inst->name, always_xlat, false); xlat_func_args(xlat, always_xlat_args); xlat_async_instantiate_set(xlat, always_xlat_instantiate, rlm_always_t *, NULL, inst); return 0; } -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_always_t *inst = instance; + rlm_always_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_always_t); /* * Convert the rcode string to an int */ inst->rcode = fr_table_value_by_str(rcode_table, inst->rcode_str, RLM_MODULE_NOT_SET); if (inst->rcode == RLM_MODULE_NOT_SET) { - cf_log_err(conf, "rcode value \"%s\" is invalid", inst->rcode_str); + cf_log_err(mctx->inst->conf, "rcode value \"%s\" is invalid", inst->rcode_str); return -1; } diff --git a/src/modules/rlm_attr_filter/rlm_attr_filter.c b/src/modules/rlm_attr_filter/rlm_attr_filter.c index 288a5b2a15..df5727e1f7 100644 --- a/src/modules/rlm_attr_filter/rlm_attr_filter.c +++ b/src/modules/rlm_attr_filter/rlm_attr_filter.c @@ -24,7 +24,7 @@ */ RCSID("$Id$") -#define LOG_PREFIX inst->name +#define LOG_PREFIX mctx->inst->name #include #include @@ -41,7 +41,6 @@ RCSID("$Id$") * be used as the instance handle. */ typedef struct { - char const *name; char const *filename; tmpl_t *key; bool relaxed; @@ -101,7 +100,7 @@ static void check_pair(request_t *request, fr_pair_t *check_item, fr_pair_t *rep return; } -static int attr_filter_getfile(TALLOC_CTX *ctx, rlm_attr_filter_t *inst, char const *filename, PAIR_LIST_LIST *pair_list) +static int attr_filter_getfile(TALLOC_CTX *ctx, module_inst_ctx_t const *mctx, char const *filename, PAIR_LIST_LIST *pair_list) { int rcode; PAIR_LIST *entry = NULL; @@ -160,27 +159,16 @@ static int attr_filter_getfile(TALLOC_CTX *ctx, rlm_attr_filter_t *inst, char co return 0; } - -static int mod_bootstrap(void *instance, CONF_SECTION *conf) -{ - rlm_attr_filter_t *inst = instance; - - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - - return 0; -} - /* * (Re-)read the "attrs" file into memory. */ -static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_attr_filter_t *inst = instance; + rlm_attr_filter_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_attr_filter_t); int rcode; pairlist_list_init(&inst->attrs); - rcode = attr_filter_getfile(inst, inst, inst->filename, &inst->attrs); + rcode = attr_filter_getfile(inst, mctx, inst->filename, &inst->attrs); if (rcode != 0) { ERROR("Errors reading %s", inst->filename); @@ -195,10 +183,10 @@ static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf) * Common attr_filter checks */ static unlang_action_t CC_HINT(nonnull(1,2)) attr_filter_common(rlm_rcode_t *p_result, - void const *instance, request_t *request, + module_ctx_t const *mctx, request_t *request, fr_radius_packet_t *packet, fr_pair_list_t *list) { - rlm_attr_filter_t const *inst = talloc_get_type_abort_const(instance, rlm_attr_filter_t); + rlm_attr_filter_t const *inst = talloc_get_type_abort_const(mctx->inst->data, rlm_attr_filter_t); fr_pair_list_t output; PAIR_LIST *pl = NULL; int found = 0; @@ -369,7 +357,7 @@ static unlang_action_t CC_HINT(nonnull(1,2)) attr_filter_common(rlm_rcode_t *p_r #define RLM_AF_FUNC(_x, _y, _z) static unlang_action_t CC_HINT(nonnull) mod_##_x(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request) \ { \ - return attr_filter_common(p_result, mctx->inst->data, request, request->_y, &request->_z##_pairs); \ + return attr_filter_common(p_result, mctx, request, request->_y, &request->_z##_pairs); \ } RLM_AF_FUNC(authorize, packet, request) @@ -385,7 +373,6 @@ module_t rlm_attr_filter = { .name = "attr_filter", .inst_size = sizeof(rlm_attr_filter_t), .config = module_config, - .bootstrap = mod_bootstrap, .instantiate = mod_instantiate, .methods = { [MOD_AUTHORIZE] = mod_authorize, diff --git a/src/modules/rlm_cache/drivers/rlm_cache_memcached/rlm_cache_memcached.c b/src/modules/rlm_cache/drivers/rlm_cache_memcached/rlm_cache_memcached.c index 87d0815a23..df1719ffae 100644 --- a/src/modules/rlm_cache/drivers/rlm_cache_memcached/rlm_cache_memcached.c +++ b/src/modules/rlm_cache/drivers/rlm_cache_memcached/rlm_cache_memcached.c @@ -99,24 +99,22 @@ static void *mod_conn_create(TALLOC_CTX *ctx, void *instance, fr_time_delta_t ti /** Create a new rlm_cache_memcached instance * - * @param instance A uint8_t array of inst_size if inst_size > 0, else NULL, - * this should contain the result of parsing the driver's - * CONF_PARSER array that it specified in the interface struct. - * @param conf section holding driver specific #CONF_PAIR (s). + * @param[in] mctx Data required for instantiation. * @return * - 0 on success. * - -1 on failure. */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_cache_memcached_t *driver = instance; + rlm_cache_memcached_t *driver = talloc_get_type_abort(mctx->inst->data, rlm_cache_memcached_t); + CONF_SECTION *conf = mctx->inst->conf; memcached_return_t ret; char buffer[256]; - rlm_cache_config_t const *config = dl_module_parent_data_by_child_data(instance); + rlm_cache_config_t const *config = talloc_get_type_abort(mctx->inst->parent->data, rlm_cache_config_t); fr_assert(config); - snprintf(buffer, sizeof(buffer), "rlm_cache (%s)", config->name); + snprintf(buffer, sizeof(buffer), "rlm_cache (%s)", mctx->inst->parent->name); ret = libmemcached_check_configuration(driver->options, talloc_array_length(driver->options) -1, buffer, sizeof(buffer)); diff --git a/src/modules/rlm_cache/drivers/rlm_cache_rbtree/rlm_cache_rbtree.c b/src/modules/rlm_cache/drivers/rlm_cache_rbtree/rlm_cache_rbtree.c index 229d902e63..6cc4c7f91e 100644 --- a/src/modules/rlm_cache/drivers/rlm_cache_rbtree/rlm_cache_rbtree.c +++ b/src/modules/rlm_cache/drivers/rlm_cache_rbtree/rlm_cache_rbtree.c @@ -66,9 +66,9 @@ static int8_t cache_heap_cmp(void const *one, void const *two) /** Cleanup a cache_rbtree instance * */ -static int mod_detach(void *instance) +static int mod_detach(module_detach_ctx_t const *mctx) { - rlm_cache_rbtree_t *driver = talloc_get_type_abort(instance, rlm_cache_rbtree_t); + rlm_cache_rbtree_t *driver = talloc_get_type_abort(mctx->inst->data, rlm_cache_rbtree_t); if (driver->cache) { fr_rb_iter_inorder_t iter; @@ -89,17 +89,14 @@ static int mod_detach(void *instance) /** Create a new cache_rbtree instance * - * @param instance A uint8_t array of inst_size if inst_size > 0, else NULL, - * this should contain the result of parsing the driver's - * CONF_PARSER array that it specified in the interface struct. - * @param conf section holding driver specific #CONF_PAIR (s). + * @param[in] mctx Data required for instantiation. * @return * - 0 on success. * - -1 on failure. */ -static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_cache_rbtree_t *driver = talloc_get_type_abort(instance, rlm_cache_rbtree_t); + rlm_cache_rbtree_t *driver = talloc_get_type_abort(mctx->inst->data, rlm_cache_rbtree_t); /* * The cache. @@ -341,6 +338,7 @@ rlm_cache_driver_t rlm_cache_rbtree = { .instantiate = mod_instantiate, .detach = mod_detach, .inst_size = sizeof(rlm_cache_rbtree_t), + .inst_type = "rlm_cache_rbtree_t", .alloc = cache_entry_alloc, .find = cache_entry_find, diff --git a/src/modules/rlm_cache/drivers/rlm_cache_redis/rlm_cache_redis.c b/src/modules/rlm_cache/drivers/rlm_cache_redis/rlm_cache_redis.c index 9edc7a586b..7acbc979f2 100644 --- a/src/modules/rlm_cache/drivers/rlm_cache_redis/rlm_cache_redis.c +++ b/src/modules/rlm_cache/drivers/rlm_cache_redis/rlm_cache_redis.c @@ -64,30 +64,24 @@ fr_dict_attr_autoload_t rlm_cache_redis_dict_attr[] = { /** Create a new rlm_cache_redis instance * - * @param instance A uint8_t array of inst_size if inst_size > 0, else NULL, - * this should contain the result of parsing the driver's - * CONF_PARSER array that it specified in the interface struct. - * @param conf section holding driver specific #CONF_PAIR (s). + * @param[in] mctx Data required for instantiation. * @return * - 0 on success. * - -1 on failure. */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_cache_redis_t *driver = instance; + rlm_cache_redis_t *driver = talloc_get_type_abort(mctx->inst->data, rlm_cache_redis_t); char buffer[256]; - rlm_cache_config_t const *config = dl_module_parent_data_by_child_data(instance); - - fr_assert(config); buffer[0] = '\0'; - if (cf_section_rules_push(conf, driver_config) < 0) return -1; - if (cf_section_parse(driver, driver, conf) < 0) return -1; + if (cf_section_rules_push(mctx->inst->conf, driver_config) < 0) return -1; + if (cf_section_parse(driver, driver, mctx->inst->conf) < 0) return -1; - snprintf(buffer, sizeof(buffer), "rlm_cache (%s)", config->name); + snprintf(buffer, sizeof(buffer), "rlm_cache (%s)", mctx->inst->parent->name); - driver->cluster = fr_redis_cluster_alloc(driver, conf, &driver->conf, true, + driver->cluster = fr_redis_cluster_alloc(driver, mctx->inst->conf, &driver->conf, true, buffer, "modules.cache.pool", NULL); if (!driver->cluster) { ERROR("Cluster failure"); diff --git a/src/modules/rlm_cache/rlm_cache.c b/src/modules/rlm_cache/rlm_cache.c index fd37db185e..5517191363 100644 --- a/src/modules/rlm_cache/rlm_cache.c +++ b/src/modules/rlm_cache/rlm_cache.c @@ -23,7 +23,7 @@ */ RCSID("$Id$") -#define LOG_PREFIX inst->config.name +#define LOG_PREFIX mctx->inst->name #include #include @@ -938,9 +938,9 @@ static void cache_unref(request_t *request, rlm_cache_t const *inst, rlm_cache_e /** Free any memory allocated under the instance * */ -static int mod_detach(void *instance) +static int mod_detach(module_detach_ctx_t const *mctx) { - rlm_cache_t *inst = instance; + rlm_cache_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_cache_t); /* * We need to explicitly free all children, so if the driver @@ -958,16 +958,14 @@ static int mod_detach(void *instance) /** Register module xlats * */ -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - rlm_cache_t *inst = instance; + rlm_cache_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_cache_t ); + CONF_SECTION *conf = mctx->inst->conf; CONF_SECTION *driver_cs; char const *name; xlat_t *xlat; - inst->config.name = cf_section_name2(conf); - if (!inst->config.name) inst->config.name = cf_section_name1(conf); - name = strrchr(inst->config.driver_name, '_'); if (!name) { name = inst->config.driver_name; @@ -1010,7 +1008,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) /* * Register the cache xlat function */ - xlat = xlat_register(inst, inst->config.name, cache_xlat, true); + xlat = xlat_register(inst, mctx->inst->name, cache_xlat, true); xlat_func_args(xlat, cache_xlat_args); xlat_async_thread_instantiate_set(xlat, mod_xlat_thread_instantiate, cache_xlat_thread_inst_t, NULL, inst); @@ -1020,9 +1018,10 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) /** Create a new rlm_cache_instance * */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_cache_t *inst = instance; + rlm_cache_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_cache_t); + CONF_SECTION *conf = mctx->inst->conf; CONF_SECTION *update; fr_assert(inst->config.key); @@ -1084,7 +1083,7 @@ static unlang_action_t CC_HINT(nonnull) mod_method_status(rlm_rcode_t *p_result, rlm_cache_entry_t *entry = NULL; rlm_cache_handle_t *handle = NULL; - DEBUG3("Calling %s.status", inst->config.name); + DEBUG3("Calling %s.status", mctx->inst->name); key_len = tmpl_expand((char const **)&key, (char *)buffer, sizeof(buffer), request, inst->config.key, NULL, NULL); @@ -1132,7 +1131,7 @@ static unlang_action_t CC_HINT(nonnull) mod_method_load(rlm_rcode_t *p_result, m rlm_cache_entry_t *entry = NULL; rlm_cache_handle_t *handle = NULL; - DEBUG3("Calling %s.load", inst->config.name); + DEBUG3("Calling %s.load", mctx->inst->name); key_len = tmpl_expand((char const **)&key, (char *)buffer, sizeof(buffer), request, inst->config.key, NULL, NULL); @@ -1187,7 +1186,7 @@ static unlang_action_t CC_HINT(nonnull) mod_method_store(rlm_rcode_t *p_result, rlm_cache_handle_t *handle = NULL; fr_pair_t *vp; - DEBUG3("Calling %s.store", inst->config.name); + DEBUG3("Calling %s.store", mctx->inst->name); key_len = tmpl_expand((char const **)&key, (char *)buffer, sizeof(buffer), request, inst->config.key, NULL, NULL); @@ -1284,7 +1283,7 @@ static unlang_action_t CC_HINT(nonnull) mod_method_clear(rlm_rcode_t *p_result, rlm_cache_entry_t *entry = NULL; rlm_cache_handle_t *handle = NULL; - DEBUG3("Calling %s.clear", inst->config.name); + DEBUG3("Calling %s.clear", mctx->inst->name); key_len = tmpl_expand((char const **)&key, (char *)buffer, sizeof(buffer), request, inst->config.key, NULL, NULL); @@ -1338,7 +1337,7 @@ static unlang_action_t CC_HINT(nonnull) mod_method_ttl(rlm_rcode_t *p_result, mo rlm_cache_handle_t *handle = NULL; fr_pair_t *vp; - DEBUG3("Calling %s.ttl", inst->config.name); + DEBUG3("Calling %s.ttl", mctx->inst->name); key_len = tmpl_expand((char const **)&key, (char *)buffer, sizeof(buffer), request, inst->config.key, NULL, NULL); diff --git a/src/modules/rlm_cache/rlm_cache.h b/src/modules/rlm_cache/rlm_cache.h index de24c8da1f..dbb0c27aae 100644 --- a/src/modules/rlm_cache/rlm_cache.h +++ b/src/modules/rlm_cache/rlm_cache.h @@ -49,7 +49,6 @@ typedef enum { * rlm_cache instance data. */ typedef struct { - char const *name; //!< Name of xlat function to register. char const *driver_name; //!< Driver name. tmpl_t *key; //!< What to expand to get the value of the key. fr_time_delta_t ttl; //!< How long an entry is valid for. diff --git a/src/modules/rlm_chap/rlm_chap.c b/src/modules/rlm_chap/rlm_chap.c index aadbd2e615..7fb8be57f5 100644 --- a/src/modules/rlm_chap/rlm_chap.c +++ b/src/modules/rlm_chap/rlm_chap.c @@ -23,7 +23,7 @@ */ RCSID("$Id$") -#define LOG_PREFIX inst->name +#define LOG_PREFIX mctx->inst->name #include #include @@ -31,7 +31,6 @@ RCSID("$Id$") #include typedef struct { - char const *name; //!< Auth-Type value for this module instance. fr_dict_enum_value_t *auth_type; } rlm_chap_t; @@ -114,7 +113,7 @@ static unlang_action_t CC_HINT(nonnull) mod_authorize(rlm_rcode_t *p_result, mod rlm_chap_t const *inst = talloc_get_type_abort_const(mctx->inst->data, rlm_chap_t); if (fr_pair_find_by_da_idx(&request->control_pairs, attr_auth_type, 0) != NULL) { - RDEBUG3("Auth-Type is already set. Not setting 'Auth-Type := %s'", inst->name); + RDEBUG3("Auth-Type is already set. Not setting 'Auth-Type := %s'", mctx->inst->name); RETURN_MODULE_NOOP; } @@ -143,7 +142,7 @@ static unlang_action_t CC_HINT(nonnull) mod_authorize(rlm_rcode_t *p_result, mod if (!inst->auth_type) { WARN("No 'authenticate %s {...}' section or 'Auth-Type = %s' set. Cannot setup CHAP authentication", - inst->name, inst->name); + mctx->inst->name, mctx->inst->name); RETURN_MODULE_NOOP; } @@ -273,28 +272,18 @@ static unlang_action_t CC_HINT(nonnull) mod_authenticate(rlm_rcode_t *p_result, RETURN_MODULE_OK; } -static int mod_bootstrap(void *instance, CONF_SECTION *conf) -{ - rlm_chap_t *inst = instance; - - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - - return 0; -} - /* * Create instance for our module. Allocate space for * instance structure and read configuration parameters */ -static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_chap_t *inst = instance; + rlm_chap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_chap_t); - inst->auth_type = fr_dict_enum_by_name(attr_auth_type, inst->name, -1); + inst->auth_type = fr_dict_enum_by_name(attr_auth_type, mctx->inst->name, -1); if (!inst->auth_type) { WARN("Failed to find 'authenticate %s {...}' section. CHAP authentication will likely not work", - inst->name); + mctx->inst->name); } return 0; @@ -332,7 +321,6 @@ module_t rlm_chap = { .inst_size = sizeof(rlm_chap_t), .onload = mod_load, .unload = mod_unload, - .bootstrap = mod_bootstrap, .instantiate = mod_instantiate, .dict = &dict_radius, .methods = { diff --git a/src/modules/rlm_cipher/rlm_cipher.c b/src/modules/rlm_cipher/rlm_cipher.c index 7ec2a91587..ef24da4b6b 100644 --- a/src/modules/rlm_cipher/rlm_cipher.c +++ b/src/modules/rlm_cipher/rlm_cipher.c @@ -176,7 +176,6 @@ typedef struct { * */ typedef struct { - char const *name; //!< Name of xlat we registered. cipher_type_t type; //!< Type of encryption to use. /** Supported cipher types @@ -1123,11 +1122,10 @@ static int cipher_rsa_padding_params_set(EVP_PKEY_CTX *evp_pkey_ctx, cipher_rsa_ * * @return 0. */ -static int cipher_rsa_thread_instantiate(UNUSED CONF_SECTION const *conf, void *instance, - UNUSED fr_event_list_t *el, void *thread) +static int cipher_rsa_thread_instantiate(module_thread_inst_ctx_t const *mctx) { - rlm_cipher_t const *inst = talloc_get_type_abort(instance, rlm_cipher_t); - rlm_cipher_rsa_thread_inst_t *ti = thread; + rlm_cipher_t const *inst = talloc_get_type_abort(mctx->inst->data, rlm_cipher_t); + rlm_cipher_rsa_thread_inst_t *ti = talloc_get_type_abort(mctx->thread, rlm_cipher_rsa_thread_inst_t); /* * Pre-allocate different contexts for the different operations @@ -1284,15 +1282,14 @@ static int cipher_rsa_thread_instantiate(UNUSED CONF_SECTION const *conf, void * return 0; } -static int mod_thread_instantiate(CONF_SECTION const *conf, void *instance, - fr_event_list_t *el, void *thread) +static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx) { - rlm_cipher_t *inst = talloc_get_type_abort(instance, rlm_cipher_t); + rlm_cipher_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_cipher_t); switch (inst->type) { case RLM_CIPHER_TYPE_RSA: - talloc_set_type(thread, rlm_cipher_rsa_thread_inst_t); - return cipher_rsa_thread_instantiate(conf, instance, el, thread); + talloc_set_type(mctx->thread, rlm_cipher_rsa_thread_inst_t); + return cipher_rsa_thread_instantiate(mctx); case RLM_CIPHER_TYPE_INVALID: fr_assert(0); @@ -1307,12 +1304,10 @@ static int mod_thread_instantiate(CONF_SECTION const *conf, void *instance, * to external databases, read configuration files, set up * dictionary entries, etc. */ -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - rlm_cipher_t *inst = talloc_get_type_abort(instance, rlm_cipher_t); - - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); + rlm_cipher_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_cipher_t); + CONF_SECTION *conf = mctx->inst->conf; switch (inst->type) { case RLM_CIPHER_TYPE_RSA: @@ -1334,7 +1329,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) /* * Register decrypt xlat */ - xlat_name = talloc_asprintf(inst, "%s_decrypt", inst->name); + xlat_name = talloc_asprintf(inst, "%s_decrypt", mctx->inst->name); xlat = xlat_register(inst, xlat_name, cipher_rsa_decrypt_xlat, false); xlat_func_mono(xlat, &cipher_rsa_decrypt_xlat_arg); xlat_async_instantiate_set(xlat, cipher_xlat_instantiate, @@ -1351,7 +1346,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) /* * Verify sign xlat */ - xlat_name = talloc_asprintf(inst, "%s_verify", inst->name); + xlat_name = talloc_asprintf(inst, "%s_verify", mctx->inst->name); xlat = xlat_register(inst, xlat_name, cipher_rsa_verify_xlat, false); xlat_func_args(xlat, cipher_rsa_verify_xlat_arg); xlat_async_instantiate_set(xlat, cipher_xlat_instantiate, @@ -1389,7 +1384,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) /* * Register encrypt xlat */ - xlat_name = talloc_asprintf(inst, "%s_encrypt", inst->name); + xlat_name = talloc_asprintf(inst, "%s_encrypt", mctx->inst->name); xlat = xlat_register(inst, xlat_name, cipher_rsa_encrypt_xlat, false); xlat_func_mono(xlat, &cipher_rsa_encrypt_xlat_arg); xlat_async_instantiate_set(xlat, cipher_xlat_instantiate, @@ -1405,7 +1400,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) /* * Register sign xlat */ - xlat_name = talloc_asprintf(inst, "%s_sign", inst->name); + xlat_name = talloc_asprintf(inst, "%s_sign", mctx->inst->name); xlat = xlat_register(inst, xlat_name, cipher_rsa_sign_xlat, false); xlat_func_mono(xlat, &cipher_rsa_sign_xlat_arg); xlat_async_instantiate_set(xlat, cipher_xlat_instantiate, @@ -1418,7 +1413,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) inst); talloc_free(xlat_name); - xlat_name = talloc_asprintf(inst, "%s_certificate", inst->name); + xlat_name = talloc_asprintf(inst, "%s_certificate", mctx->inst->name); xlat = xlat_register(inst, xlat_name, cipher_certificate_xlat, false); xlat_func_args(xlat, cipher_certificate_xlat_args); xlat_async_instantiate_set(xlat, cipher_xlat_instantiate, diff --git a/src/modules/rlm_client/rlm_client.c b/src/modules/rlm_client/rlm_client.c index b18443cd39..1d2231aed8 100644 --- a/src/modules/rlm_client/rlm_client.c +++ b/src/modules/rlm_client/rlm_client.c @@ -358,15 +358,16 @@ static unlang_action_t CC_HINT(nonnull) mod_authorize(rlm_rcode_t *p_result, UNU * that must be referenced in later calls, store a handle to it * in *instance otherwise put a null pointer there. */ -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { + CONF_SECTION *conf = mctx->inst->conf; xlat_t *xlat; if (cf_section_name2(conf)) return 0; - xlat = xlat_register(instance, "client", xlat_client, false); + xlat = xlat_register(mctx->inst->data, "client", xlat_client, false); xlat_func_args(xlat, xlat_client_args); - map_proc_register(instance, "client", map_proc_client, NULL, 0); + map_proc_register(mctx->inst->data, "client", map_proc_client, NULL, 0); return 0; } diff --git a/src/modules/rlm_couchbase/mod.c b/src/modules/rlm_couchbase/mod.c index f05033b074..1d1642219b 100644 --- a/src/modules/rlm_couchbase/mod.c +++ b/src/modules/rlm_couchbase/mod.c @@ -62,7 +62,7 @@ static int _mod_conn_free(rlm_couchbase_handle_t *chandle) */ int mod_free_api_opts(void *instance) { - rlm_couchbase_t *inst = instance; /* our module instance */ + rlm_couchbase_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_couchbase_t); /* our module instance */ couchbase_opts_t *opts = inst->api_opts; if (!opts) return 0; @@ -93,7 +93,7 @@ int mod_free_api_opts(void *instance) */ int mod_build_api_opts(CONF_SECTION *conf, void *instance) { - rlm_couchbase_t *inst = instance; /* our module instance */ + rlm_couchbase_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_couchbase_t); /* our module instance */ CONF_SECTION *cs; /* module config list */ CONF_ITEM *ci; /* config item */ CONF_PAIR *cp; /* config pair */ @@ -238,7 +238,7 @@ int mod_conn_alive(UNUSED void *instance, void *handle) */ int mod_build_attribute_element_map(CONF_SECTION *conf, void *instance) { - rlm_couchbase_t *inst = instance; /* our module instance */ + rlm_couchbase_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_couchbase_t); /* our module instance */ CONF_SECTION *cs; /* module config list */ CONF_ITEM *ci; /* config item */ CONF_PAIR *cp; /* conig pair */ diff --git a/src/modules/rlm_couchbase/rlm_couchbase.c b/src/modules/rlm_couchbase/rlm_couchbase.c index 27baacd68f..47e2d4b2a9 100644 --- a/src/modules/rlm_couchbase/rlm_couchbase.c +++ b/src/modules/rlm_couchbase/rlm_couchbase.c @@ -424,7 +424,7 @@ finish: */ static int mod_detach(void *instance) { - rlm_couchbase_t *inst = instance; + rlm_couchbase_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_couchbase_t); if (inst->map) json_object_put(inst->map); if (inst->pool) fr_pool_free(inst->pool); @@ -433,26 +433,6 @@ static int mod_detach(void *instance) return 0; } -/** Bootstrap the module - * - * Define attributes. - * - * @param conf to parse. - * @param instance configuration data. - * @return - * - 0 on success. - * - < 0 on failure. - */ -static int mod_bootstrap(void *instance, CONF_SECTION *conf) -{ - rlm_couchbase_t *inst = instance; - - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - - return 0; -} - /** Initialize the rlm_couchbase module * * Intialize the module and create the initial Couchbase connection pool. @@ -463,9 +443,9 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) * - 0 on success. * - -1 on failure. */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_couchbase_t *inst = instance; /* our module instance */ + rlm_couchbase_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_couchbase_t); /* our module instance */ { char *server, *p; @@ -572,7 +552,6 @@ module_t rlm_couchbase = { .type = RLM_TYPE_THREAD_SAFE, .inst_size = sizeof(rlm_couchbase_t), .config = module_config, - .bootstrap = mod_bootstrap, .onload = mod_load, .instantiate = mod_instantiate, .detach = mod_detach, diff --git a/src/modules/rlm_csv/rlm_csv.c b/src/modules/rlm_csv/rlm_csv.c index ea425ae2a0..cd2872c484 100644 --- a/src/modules/rlm_csv/rlm_csv.c +++ b/src/modules/rlm_csv/rlm_csv.c @@ -42,7 +42,6 @@ static rlm_rcode_t mod_map_proc(void *mod_inst, UNUSED void *proc_inst, request_ * be used as the instance handle. */ typedef struct { - char const *name; char const *filename; char const *delimiter; char const *fields; @@ -386,7 +385,7 @@ static int fieldname2offset(rlm_csv_t const *inst, char const *field_name, int * */ static int csv_map_verify(map_t *map, void *instance) { - rlm_csv_t *inst = instance; + rlm_csv_t *inst = talloc_get_type_abort(instance, rlm_csv_t); int offset; fr_type_t type = FR_TYPE_NULL; @@ -511,18 +510,16 @@ static int csv_maps_verify(CONF_SECTION *cs, void *mod_inst, UNUSED void *proc_i * that must be referenced in later calls, store a handle to it * in *instance otherwise put a null pointer there. */ -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - rlm_csv_t *inst = instance; - int i; - char const *p; - char *q; - char *fields; + rlm_csv_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_csv_t); + CONF_SECTION *conf = mctx->inst->conf; + int i; + char const *p; + char *q; + char *fields; fr_htrie_type_t htype; - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - if (inst->delimiter[1]) { cf_log_err(conf, "'delimiter' must be one character long"); return -1; @@ -738,7 +735,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) /* * And register the `map csv { ... }` function. */ - map_proc_register(inst, inst->name, mod_map_proc, csv_maps_verify, 0); + map_proc_register(inst, mctx->inst->name, mod_map_proc, csv_maps_verify, 0); return 0; } @@ -748,18 +745,18 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) * * Creates a new instance of the module reading parameters from a configuration section. * - * @param conf to parse. - * @param instance configuration data. + * @param[in] mctx configuration data. * @return * - 0 on success. * - < 0 on failure. */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_csv_t *inst = instance; - CONF_SECTION *cs; - int lineno; - FILE *fp; + rlm_csv_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_csv_t); + CONF_SECTION *conf = mctx->inst->conf; + CONF_SECTION *cs; + int lineno; + FILE *fp; tmpl_rules_t parse_rules = { .allow_foreign = true /* Because we don't know where we'll be called */ }; diff --git a/src/modules/rlm_date/rlm_date.c b/src/modules/rlm_date/rlm_date.c index 8d46e87830..adaf24dfc8 100644 --- a/src/modules/rlm_date/rlm_date.c +++ b/src/modules/rlm_date/rlm_date.c @@ -30,7 +30,6 @@ #include typedef struct { - char const *name; char const *fmt; bool utc; } rlm_date_t; @@ -64,7 +63,7 @@ static xlat_action_t date_convert_string(TALLOC_CTX *ctx, fr_dcursor_t *out, req char *p; /* - * + * */ MEM(my_str = talloc_strdup(ctx, str)); p = my_str + (tz - str); @@ -76,7 +75,7 @@ static xlat_action_t date_convert_string(TALLOC_CTX *ctx, fr_dcursor_t *out, req talloc_free(my_str); return XLAT_ACTION_FAIL; } - talloc_free(my_str); + talloc_free(my_str); /* * The output is converted to the local time zone, so @@ -231,15 +230,12 @@ static xlat_action_t xlat_date_convert(TALLOC_CTX *ctx, fr_dcursor_t *out, reque return XLAT_ACTION_FAIL; } -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - rlm_date_t *inst = instance; + rlm_date_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_date_t ); xlat_t *xlat; - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - - xlat = xlat_register(inst, inst->name, xlat_date_convert, false); + xlat = xlat_register(inst, mctx->inst->name, xlat_date_convert, false); xlat_func_args(xlat,xlat_date_convert_args); xlat_async_instantiate_set(xlat, mod_xlat_instantiate, rlm_date_t *, NULL, inst); diff --git a/src/modules/rlm_delay/rlm_delay.c b/src/modules/rlm_delay/rlm_delay.c index 5e626ae7e7..6e0eab9d57 100644 --- a/src/modules/rlm_delay/rlm_delay.c +++ b/src/modules/rlm_delay/rlm_delay.c @@ -31,8 +31,7 @@ RCSID("$Id$") #include typedef struct { - char const *name; //!< Name of our xlat function. - tmpl_t *delay; //!< How long we delay for. + tmpl_t *delay; //!< How long we delay for. bool relative; //!< Whether the delay is relative to the start of request processing. bool force_reschedule; //!< Whether we should force rescheduling of the request. } rlm_delay_t; @@ -275,15 +274,12 @@ static int mod_xlat_instantiate(void *xlat_inst, UNUSED xlat_exp_t const *exp, v return 0; } -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - rlm_delay_t *inst = instance; + rlm_delay_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_delay_t); xlat_t *xlat; - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - - xlat = xlat_register(inst, inst->name, xlat_delay, true); + xlat = xlat_register(inst, mctx->inst->name, xlat_delay, true); xlat_func_args(xlat, xlat_delay_args); xlat_async_instantiate_set(xlat, mod_xlat_instantiate, rlm_delay_t *, NULL, inst); return 0; diff --git a/src/modules/rlm_detail/rlm_detail.c b/src/modules/rlm_detail/rlm_detail.c index 5c75bfb3be..8a7a894478 100644 --- a/src/modules/rlm_detail/rlm_detail.c +++ b/src/modules/rlm_detail/rlm_detail.c @@ -23,7 +23,7 @@ */ RCSID("$Id$") -#define LOG_PREFIX inst->name +#define LOG_PREFIX mctx->inst->name #include #include @@ -50,7 +50,6 @@ RCSID("$Id$") * Holds the configuration and preparsed data for a instance of rlm_detail. */ typedef struct { - char const *name; //!< Instance name. char const *filename; //!< File/path to write to. uint32_t perm; //!< Permissions to use for new files. char const *group; //!< Group to use for new files. @@ -130,14 +129,12 @@ static int8_t detail_cmp(void const *a, void const *b) /* * (Re-)read radiusd.conf into memory. */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_detail_t *inst = instance; + rlm_detail_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_detail_t); + CONF_SECTION *conf = mctx->inst->conf; CONF_SECTION *cs; - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - /* * Escape filenames only if asked. */ diff --git a/src/modules/rlm_dhcpv4/rlm_dhcpv4.c b/src/modules/rlm_dhcpv4/rlm_dhcpv4.c index 704100f0eb..1876bd5c27 100644 --- a/src/modules/rlm_dhcpv4/rlm_dhcpv4.c +++ b/src/modules/rlm_dhcpv4/rlm_dhcpv4.c @@ -70,8 +70,6 @@ fr_dict_attr_autoload_t rlm_dhcpv4_dict_attr[] = { * be used as the instance handle. */ typedef struct { - char const *name; - fr_udp_queue_config_t config; //!< UDP queue config uint32_t max_packet_size; //!< Maximum packet size. @@ -106,18 +104,15 @@ static const CONF_PARSER module_config[] = { * * Bootstrap I/O and type submodules. * - * @param[in] instance Ctx data for this module - * @param[in] conf our configuration section parsed to give us instance. + * @param[in] mctx data for this module * @return * - 0 on success. * - -1 on failure. */ -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - rlm_dhcpv4_t *inst = talloc_get_type_abort(instance, rlm_dhcpv4_t); - - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); + rlm_dhcpv4_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_dhcpv4_t); + CONF_SECTION *conf = mctx->inst->conf; /* * Ensure that we have a destination address. @@ -163,22 +158,23 @@ static void dhcpv4_queue_resume(bool sent, void *rctx) /** Instantiate thread data for the submodule. * */ -static int mod_thread_instantiate(CONF_SECTION const *cs, void *instance, fr_event_list_t *el, void *thread) +static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx) { - rlm_dhcpv4_t *inst = talloc_get_type_abort(instance, rlm_dhcpv4_t); - rlm_dhcpv4_thread_t *t = talloc_get_type_abort(thread, rlm_dhcpv4_thread_t); + rlm_dhcpv4_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_dhcpv4_t); + rlm_dhcpv4_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_dhcpv4_thread_t); + CONF_SECTION *conf = mctx->inst->conf; t->buffer = talloc_array(t, uint8_t, inst->max_packet_size); if (!t->buffer) { - cf_log_err(cs, "Failed allocating buffer"); + cf_log_err(conf, "Failed allocating buffer"); return -1; } t->buffer_size = inst->max_packet_size; - t->uq = fr_udp_queue_alloc(t, &inst->config, el, dhcpv4_queue_resume); + t->uq = fr_udp_queue_alloc(t, &inst->config, mctx->el, dhcpv4_queue_resume); if (!t->uq) { - cf_log_err(cs, "Failed allocating outbound udp queue - %s", fr_strerror()); + cf_log_err(conf, "Failed allocating outbound udp queue - %s", fr_strerror()); return -1; } diff --git a/src/modules/rlm_dict/rlm_dict.c b/src/modules/rlm_dict/rlm_dict.c index abe7e0cb9e..2b1e6f1d1b 100644 --- a/src/modules/rlm_dict/rlm_dict.c +++ b/src/modules/rlm_dict/rlm_dict.c @@ -225,26 +225,28 @@ static xlat_action_t xlat_attr_num(TALLOC_CTX *ctx, fr_dcursor_t *out, request_t * that must be referenced in later calls, store a handle to it * in *instance otherwise put a null pointer there. */ -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { + void *inst = mctx->inst->data; + xlat_t *xlat; /* * Only register these xlats for the first instance of the dictionary module. */ - if (cf_section_name2(conf) != NULL) return 0; + if (cf_section_name2(mctx->inst->conf) != NULL) return 0; - xlat = xlat_register(instance, "attr_by_num", xlat_dict_attr_by_num, false); + xlat = xlat_register(inst, "attr_by_num", xlat_dict_attr_by_num, false); xlat_func_args(xlat, xlat_dict_attr_by_num_args); - xlat = xlat_register(instance, "attr_by_oid", xlat_dict_attr_by_oid, false); + xlat = xlat_register(inst, "attr_by_oid", xlat_dict_attr_by_oid, false); xlat_func_args(xlat, xlat_dict_attr_by_oid_args); - xlat = xlat_register(instance, "vendor", xlat_vendor, false); + xlat = xlat_register(inst, "vendor", xlat_vendor, false); xlat_func_args(xlat, xlat_vendor_args); - xlat = xlat_register(instance, "vendor_num", xlat_vendor_num, false); + xlat = xlat_register(inst, "vendor_num", xlat_vendor_num, false); xlat_func_args(xlat, xlat_vendor_num_args); - xlat = xlat_register(instance, "attr", xlat_attr, false); + xlat = xlat_register(inst, "attr", xlat_attr, false); xlat_func_args(xlat, xlat_attr_args); - xlat = xlat_register(instance, "attr_num", xlat_attr_num, false); + xlat = xlat_register(inst, "attr_num", xlat_attr_num, false); xlat_func_args(xlat, xlat_attr_num_args); return 0; diff --git a/src/modules/rlm_digest/rlm_digest.c b/src/modules/rlm_digest/rlm_digest.c index ac9706433c..e437ba0252 100644 --- a/src/modules/rlm_digest/rlm_digest.c +++ b/src/modules/rlm_digest/rlm_digest.c @@ -31,7 +31,6 @@ RCSID("$Id$") #include typedef struct { - char const *name; //!< Auth-Type value for this module instance. fr_dict_enum_value_t *auth_type; } rlm_digest_t; @@ -97,7 +96,7 @@ static unlang_action_t CC_HINT(nonnull) mod_authorize(rlm_rcode_t *p_result, mod if (!inst->auth_type) { WARN("No 'authenticate %s {...}' section or 'Auth-Type = %s' set. Cannot setup Digest authentication", - inst->name, inst->name); + mctx->inst->name, mctx->inst->name); RETURN_MODULE_NOOP; } @@ -446,33 +445,19 @@ static unlang_action_t CC_HINT(nonnull) mod_authenticate(rlm_rcode_t *p_result, RETURN_MODULE_REJECT; } -static int mod_bootstrap(void *instance, CONF_SECTION *conf) -{ - char const *name; - rlm_digest_t *inst = instance; - - /* - * Create the dynamic translation. - */ - name = cf_section_name2(conf); - if (!name) name = cf_section_name1(conf); - inst->name = name; - - return 0; -} /* * Create instance for our module. Allocate space for * instance structure and read configuration parameters */ -static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_digest_t *inst = instance; + rlm_digest_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_digest_t); - inst->auth_type = fr_dict_enum_by_name(attr_auth_type, inst->name, -1); + inst->auth_type = fr_dict_enum_by_name(attr_auth_type, mctx->inst->name, -1); if (!inst->auth_type) { WARN("Failed to find 'authenticate %s {...}' section. Digest authentication will likely not work", - inst->name); + mctx->inst->name); } return 0; @@ -492,7 +477,6 @@ module_t rlm_digest = { .magic = RLM_MODULE_INIT, .name = "digest", .inst_size = sizeof(rlm_digest_t), - .bootstrap = mod_bootstrap, .instantiate = mod_instantiate, .dict = &dict_radius, .methods = { diff --git a/src/modules/rlm_eap/rlm_eap.c b/src/modules/rlm_eap/rlm_eap.c index d6deae62f7..83944f2ba2 100644 --- a/src/modules/rlm_eap/rlm_eap.c +++ b/src/modules/rlm_eap/rlm_eap.c @@ -25,7 +25,7 @@ */ RCSID("$Id$") -#define LOG_PREFIX inst->name +#define LOG_PREFIX mctx->inst->name #include #include @@ -178,9 +178,10 @@ static int submodule_parse(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *paren case FR_EAP_METHOD_AKA: case FR_EAP_METHOD_SIM: { - rlm_eap_t *inst = ((dl_module_inst_t *)cf_data_value(cf_data_find(eap_cs, - dl_module_inst_t, "rlm_eap")))->data; - + 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"))) + }; WARN("Ignoring EAP method %s because we don't have OpenSSL support", name); talloc_free(our_name); @@ -886,7 +887,7 @@ static unlang_action_t mod_authorize(rlm_rcode_t *p_result, module_ctx_t const * if (!inst->auth_type) { WARN("No 'authenticate %s {...}' section or 'Auth-Type = %s' set. Cannot setup EAP authentication", - inst->name, inst->name); + mctx->inst->name, mctx->inst->name); RETURN_MODULE_NOOP; } @@ -920,7 +921,6 @@ static unlang_action_t mod_authorize(rlm_rcode_t *p_result, module_ctx_t const * static unlang_action_t mod_post_auth(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request) { - rlm_eap_t const *inst = talloc_get_type_abort_const(mctx->inst->data, rlm_eap_t); fr_pair_t *vp; eap_session_t *eap_session; fr_pair_t *username; @@ -989,7 +989,7 @@ static unlang_action_t mod_post_auth(rlm_rcode_t *p_result, module_ctx_t const * * Was *NOT* an EAP-Failure, so we now need to turn it into one. */ REDEBUG("Request rejected after last call to module \"%s\", transforming response into EAP-Failure", - inst->name); + mctx->inst->name); eap_fail(eap_session); /* Compose an EAP failure */ eap_session_destroy(&eap_session); /* Free the EAP session, and dissociate it from the request */ @@ -1003,15 +1003,15 @@ static unlang_action_t mod_post_auth(rlm_rcode_t *p_result, module_ctx_t const * RETURN_MODULE_UPDATED; } -static int mod_instantiate(void *instance, UNUSED CONF_SECTION *cs) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_eap_t *inst = talloc_get_type_abort(instance, rlm_eap_t); + rlm_eap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_eap_t); size_t i; - inst->auth_type = fr_dict_enum_by_name(attr_auth_type, inst->name, -1); + inst->auth_type = fr_dict_enum_by_name(attr_auth_type, mctx->inst->name, -1); if (!inst->auth_type) { WARN("Failed to find 'authenticate %s {...}' section. EAP authentication will likely not work", - inst->name); + mctx->inst->name); } /* @@ -1024,14 +1024,11 @@ static int mod_instantiate(void *instance, UNUSED CONF_SECTION *cs) return 0; } -static int mod_bootstrap(void *instance, CONF_SECTION *cs) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - rlm_eap_t *inst = talloc_get_type_abort(instance, rlm_eap_t); + rlm_eap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_eap_t); size_t i, j, loaded, count = 0; - inst->name = cf_section_name2(cs); - if (!inst->name) inst->name = cf_section_name1(cs); - /* * Load and bootstrap the submodules now * We have to do that here instead of in a parse function @@ -1112,13 +1109,13 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) * allowed by the config. */ if (inst->default_method_is_set && !inst->methods[inst->default_method].submodule) { - cf_log_err_by_child(cs, "default_eap_type", "EAP-Type \"%s\" is not enabled", + cf_log_err_by_child(mctx->inst->conf, "default_eap_type", "EAP-Type \"%s\" is not enabled", eap_type2name(inst->default_method)); return -1; } if (count == 0) { - cf_log_err(cs, "No EAP method(s) configured, module cannot do anything"); + cf_log_err(mctx->inst->conf, "No EAP method(s) configured, module cannot do anything"); return -1; } @@ -1141,11 +1138,8 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs) static int mod_load(void) { - rlm_eap_t instance = { .name = "global" }; - rlm_eap_t *inst = &instance; - if (eap_base_init() < 0) { - PERROR("Failed initialising EAP base library"); + fr_perror("Failed initialising EAP base library"); return -1; } return 0; diff --git a/src/modules/rlm_eap/types/rlm_eap_aka/rlm_eap_aka.c b/src/modules/rlm_eap/types/rlm_eap_aka/rlm_eap_aka.c index 6ef6f90aef..329789fb9b 100644 --- a/src/modules/rlm_eap/types/rlm_eap_aka/rlm_eap_aka.c +++ b/src/modules/rlm_eap/types/rlm_eap_aka/rlm_eap_aka.c @@ -59,9 +59,10 @@ static unlang_action_t mod_session_init(rlm_rcode_t *p_result, module_ctx_t cons return eap_session->process(p_result, mctx, request); } -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - eap_aka_sim_module_conf_t *inst = talloc_get_type_abort(instance, eap_aka_sim_module_conf_t); + eap_aka_sim_module_conf_t *inst = talloc_get_type_abort(mctx->inst->data, eap_aka_sim_module_conf_t); + CONF_SECTION *conf = mctx->inst->conf; inst->type = rlm_eap_aka.provides[0]; diff --git a/src/modules/rlm_eap/types/rlm_eap_aka_prime/rlm_eap_aka_prime.c b/src/modules/rlm_eap/types/rlm_eap_aka_prime/rlm_eap_aka_prime.c index ba867153e9..9ae92d6cb5 100644 --- a/src/modules/rlm_eap/types/rlm_eap_aka_prime/rlm_eap_aka_prime.c +++ b/src/modules/rlm_eap/types/rlm_eap_aka_prime/rlm_eap_aka_prime.c @@ -58,9 +58,9 @@ static unlang_action_t mod_session_init(rlm_rcode_t *p_result, module_ctx_t cons return eap_session->process(p_result, mctx, request); } -static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - eap_aka_sim_module_conf_t *inst = talloc_get_type_abort(instance, eap_aka_sim_module_conf_t); + eap_aka_sim_module_conf_t *inst = talloc_get_type_abort(mctx->inst->data, eap_aka_sim_module_conf_t); inst->type = rlm_eap_aka_prime.provides[0]; diff --git a/src/modules/rlm_eap/types/rlm_eap_fast/rlm_eap_fast.c b/src/modules/rlm_eap/types/rlm_eap_fast/rlm_eap_fast.c index c920718ef9..cda9f7897f 100644 --- a/src/modules/rlm_eap/types/rlm_eap_fast/rlm_eap_fast.c +++ b/src/modules/rlm_eap/types/rlm_eap_fast/rlm_eap_fast.c @@ -600,11 +600,10 @@ static unlang_action_t mod_session_init(rlm_rcode_t *p_result, module_ctx_t cons RETURN_MODULE_HANDLED; } -static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, - UNUSED fr_event_list_t *el, void *thread) +static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx) { - rlm_eap_fast_t *inst = talloc_get_type_abort(instance, rlm_eap_fast_t); - rlm_eap_fast_thread_t *t = talloc_get_type_abort(thread, rlm_eap_fast_thread_t); + rlm_eap_fast_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_eap_fast_t); + rlm_eap_fast_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_eap_fast_thread_t); t->ssl_ctx = fr_tls_ctx_alloc(inst->tls_conf, false); if (!t->ssl_ctx) return -1; @@ -612,9 +611,9 @@ static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, return 0; } -static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread) +static int mod_thread_detach(module_thread_inst_ctx_t const *mctx) { - rlm_eap_fast_thread_t *t = talloc_get_type_abort(thread, rlm_eap_fast_thread_t); + rlm_eap_fast_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_eap_fast_thread_t); if (likely(t->ssl_ctx != NULL)) SSL_CTX_free(t->ssl_ctx); t->ssl_ctx = NULL; @@ -625,18 +624,20 @@ static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread) /* * Attach the module. */ -static int mod_instantiate(void *instance, CONF_SECTION *cs) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_eap_fast_t *inst = talloc_get_type_abort(instance, rlm_eap_fast_t); + rlm_eap_fast_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_eap_fast_t); + CONF_SECTION *conf = mctx->inst->conf; if (!virtual_server_find(inst->virtual_server)) { - cf_log_err_by_child(cs, "virtual_server", "Unknown virtual server '%s'", inst->virtual_server); + cf_log_err_by_child(mctx->inst->conf, "virtual_server", "Unknown virtual server '%s'", + inst->virtual_server); return -1; } inst->default_provisioning_method = eap_name2type(inst->default_provisioning_method_name); if (!inst->default_provisioning_method) { - cf_log_err_by_child(cs, "default_provisioning_eap_type", "Unknown EAP type %s", + cf_log_err_by_child(conf, "default_provisioning_eap_type", "Unknown EAP type %s", inst->default_provisioning_method_name); return -1; } @@ -645,15 +646,15 @@ static int mod_instantiate(void *instance, CONF_SECTION *cs) * Read tls configuration, either from group given by 'tls' * option, or from the eap-tls configuration. */ - inst->tls_conf = eap_tls_conf_parse(cs, "tls"); + inst->tls_conf = eap_tls_conf_parse(conf, "tls"); if (!inst->tls_conf) { - cf_log_err_by_child(cs, "tls", "Failed initializing SSL context"); + cf_log_err_by_child(conf, "tls", "Failed initializing SSL context"); return -1; } if (talloc_array_length(inst->pac_opaque_key) - 1 != 32) { - cf_log_err_by_child(cs, "pac_opaque_key", "Must be 32 bytes long"); + cf_log_err_by_child(conf, "pac_opaque_key", "Must be 32 bytes long"); return -1; } @@ -662,12 +663,12 @@ static int mod_instantiate(void *instance, CONF_SECTION *cs) * disable TLSv1.2 later. */ if (inst->tls_conf->tls_min_version > (float) 1.1) { - cf_log_err_by_child(cs, "tls_min_version", "require tls_min_version <= 1.1"); + cf_log_err_by_child(conf, "tls_min_version", "require tls_min_version <= 1.1"); return -1; } if (!fr_time_delta_ispos(inst->pac_lifetime)) { - cf_log_err_by_child(cs, "pac_lifetime", "must be non-zero"); + cf_log_err_by_child(conf, "pac_lifetime", "must be non-zero"); return -1; } diff --git a/src/modules/rlm_eap/types/rlm_eap_mschapv2/rlm_eap_mschapv2.c b/src/modules/rlm_eap/types/rlm_eap_mschapv2/rlm_eap_mschapv2.c index 9d60d925bc..be6db1a9ae 100644 --- a/src/modules/rlm_eap/types/rlm_eap_mschapv2/rlm_eap_mschapv2.c +++ b/src/modules/rlm_eap/types/rlm_eap_mschapv2/rlm_eap_mschapv2.c @@ -873,12 +873,12 @@ static unlang_action_t mod_session_init(rlm_rcode_t *p_result, module_ctx_t cons /* * Attach the module. */ -static int mod_instantiate(void *instance, CONF_SECTION *cs) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_eap_mschapv2_t *inst = talloc_get_type_abort(instance, rlm_eap_mschapv2_t); + rlm_eap_mschapv2_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_eap_mschapv2_t); if (inst->identity && (strlen(inst->identity) > 255)) { - cf_log_err(cs, "identity is too long"); + cf_log_err(mctx->inst->conf, "identity is too long"); return -1; } diff --git a/src/modules/rlm_eap/types/rlm_eap_peap/rlm_eap_peap.c b/src/modules/rlm_eap/types/rlm_eap_peap/rlm_eap_peap.c index 66dfa75939..a34a42b6d0 100644 --- a/src/modules/rlm_eap/types/rlm_eap_peap/rlm_eap_peap.c +++ b/src/modules/rlm_eap/types/rlm_eap_peap/rlm_eap_peap.c @@ -347,11 +347,10 @@ static unlang_action_t mod_session_init(rlm_rcode_t *p_result, module_ctx_t cons RETURN_MODULE_HANDLED; } -static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, - UNUSED fr_event_list_t *el, void *thread) +static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx) { - rlm_eap_peap_t *inst = talloc_get_type_abort(instance, rlm_eap_peap_t); - rlm_eap_peap_thread_t *t = talloc_get_type_abort(thread, rlm_eap_peap_thread_t); + rlm_eap_peap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_eap_peap_t); + rlm_eap_peap_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_eap_peap_thread_t); t->ssl_ctx = fr_tls_ctx_alloc(inst->tls_conf, false); if (!t->ssl_ctx) return -1; @@ -359,9 +358,9 @@ static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, return 0; } -static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread) +static int mod_thread_detach(module_thread_inst_ctx_t const *mctx) { - rlm_eap_peap_thread_t *t = talloc_get_type_abort(thread, rlm_eap_peap_thread_t); + rlm_eap_peap_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_eap_peap_thread_t); if (likely(t->ssl_ctx != NULL)) SSL_CTX_free(t->ssl_ctx); t->ssl_ctx = NULL; @@ -372,18 +371,19 @@ static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread) /* * Attach the module. */ -static int mod_instantiate(void *instance, CONF_SECTION *cs) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_eap_peap_t *inst = talloc_get_type_abort(instance, rlm_eap_peap_t); + rlm_eap_peap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_eap_peap_t); + CONF_SECTION *conf = mctx->inst->conf; if (!virtual_server_find(inst->virtual_server)) { - cf_log_err_by_child(cs, "virtual_server", "Unknown virtual server '%s'", inst->virtual_server); + cf_log_err_by_child(conf, "virtual_server", "Unknown virtual server '%s'", inst->virtual_server); return -1; } if (inst->soh_virtual_server) { if (!virtual_server_find(inst->soh_virtual_server)) { - cf_log_err_by_child(cs, "soh_virtual_server", "Unknown virtual server '%s'", inst->virtual_server); + cf_log_err_by_child(conf, "soh_virtual_server", "Unknown virtual server '%s'", inst->virtual_server); return -1; } } @@ -392,9 +392,9 @@ static int mod_instantiate(void *instance, CONF_SECTION *cs) * Read tls configuration, either from group given by 'tls' * option, or from the eap-tls configuration. */ - inst->tls_conf = eap_tls_conf_parse(cs, "tls"); + inst->tls_conf = eap_tls_conf_parse(conf, "tls"); if (!inst->tls_conf) { - cf_log_err(cs, "Failed initializing SSL context"); + cf_log_err(conf, "Failed initializing SSL context"); return -1; } diff --git a/src/modules/rlm_eap/types/rlm_eap_pwd/rlm_eap_pwd.c b/src/modules/rlm_eap/types/rlm_eap_pwd/rlm_eap_pwd.c index 5ac2ba424a..eaf5e99524 100644 --- a/src/modules/rlm_eap/types/rlm_eap_pwd/rlm_eap_pwd.c +++ b/src/modules/rlm_eap/types/rlm_eap_pwd/rlm_eap_pwd.c @@ -542,23 +542,22 @@ static unlang_action_t mod_session_init(rlm_rcode_t *p_result, module_ctx_t cons RETURN_MODULE_HANDLED; } -static int mod_detach(void *arg) +static int mod_detach(module_detach_ctx_t const *mctx) { - rlm_eap_pwd_t *inst; - - inst = (rlm_eap_pwd_t *) arg; + rlm_eap_pwd_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_eap_pwd_t); if (inst->bnctx) BN_CTX_free(inst->bnctx); return 0; } -static int mod_instantiate(void *instance, CONF_SECTION *cs) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_eap_pwd_t *inst = talloc_get_type_abort(instance, rlm_eap_pwd_t); + rlm_eap_pwd_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_eap_pwd_t); + CONF_SECTION *conf = mctx->inst->conf; if (inst->fragment_size < 100) { - cf_log_err(cs, "Fragment size is too small"); + cf_log_err(conf, "Fragment size is too small"); return -1; } @@ -571,13 +570,13 @@ static int mod_instantiate(void *instance, CONF_SECTION *cs) break; default: - cf_log_err_by_child(cs, "group", "Group %i is not supported", inst->group); + cf_log_err_by_child(conf, "group", "Group %i is not supported", inst->group); return -1; } inst->bnctx = BN_CTX_new(); if (!inst->bnctx) { - cf_log_err(cs, "Failed to get BN context"); + cf_log_err(conf, "Failed to get BN context"); return -1; } diff --git a/src/modules/rlm_eap/types/rlm_eap_sim/rlm_eap_sim.c b/src/modules/rlm_eap/types/rlm_eap_sim/rlm_eap_sim.c index 9620321f63..1bc60593ce 100644 --- a/src/modules/rlm_eap/types/rlm_eap_sim/rlm_eap_sim.c +++ b/src/modules/rlm_eap/types/rlm_eap_sim/rlm_eap_sim.c @@ -57,9 +57,9 @@ static unlang_action_t mod_session_init(rlm_rcode_t *p_result, module_ctx_t cons return eap_session->process(p_result, mctx, request); } -static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - eap_aka_sim_module_conf_t *inst = talloc_get_type_abort(instance, eap_aka_sim_module_conf_t); + eap_aka_sim_module_conf_t *inst = talloc_get_type_abort(mctx->inst->data, eap_aka_sim_module_conf_t); inst->type = rlm_eap_sim.provides[0]; diff --git a/src/modules/rlm_eap/types/rlm_eap_tls/rlm_eap_tls.c b/src/modules/rlm_eap/types/rlm_eap_tls/rlm_eap_tls.c index dee63f34a2..c7563ac033 100644 --- a/src/modules/rlm_eap/types/rlm_eap_tls/rlm_eap_tls.c +++ b/src/modules/rlm_eap/types/rlm_eap_tls/rlm_eap_tls.c @@ -222,11 +222,10 @@ static unlang_action_t mod_session_init(rlm_rcode_t *p_result, module_ctx_t cons RETURN_MODULE_HANDLED; } -static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, - UNUSED fr_event_list_t *el, void *thread) +static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx) { - rlm_eap_tls_t *inst = talloc_get_type_abort(instance, rlm_eap_tls_t); - rlm_eap_tls_thread_t *t = talloc_get_type_abort(thread, rlm_eap_tls_thread_t); + rlm_eap_tls_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_eap_tls_t); + rlm_eap_tls_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_eap_tls_thread_t); t->ssl_ctx = fr_tls_ctx_alloc(inst->tls_conf, false); if (!t->ssl_ctx) return -1; @@ -234,9 +233,9 @@ static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, return 0; } -static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread) +static int mod_thread_detach(module_thread_inst_ctx_t const *mctx) { - rlm_eap_tls_thread_t *t = talloc_get_type_abort(thread, rlm_eap_tls_thread_t); + rlm_eap_tls_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_eap_tls_thread_t); if (likely(t->ssl_ctx != NULL)) SSL_CTX_free(t->ssl_ctx); t->ssl_ctx = NULL; @@ -247,18 +246,19 @@ static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread) /* * Attach the EAP-TLS module. */ -static int mod_instantiate(void *instance, CONF_SECTION *cs) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_eap_tls_t *inst = talloc_get_type_abort(instance, rlm_eap_tls_t); + rlm_eap_tls_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_eap_tls_t); + CONF_SECTION *conf = mctx->inst->conf; - inst->tls_conf = eap_tls_conf_parse(cs, "tls"); + inst->tls_conf = eap_tls_conf_parse(conf, "tls"); if (!inst->tls_conf) { - cf_log_err(cs, "Failed initializing SSL context"); + cf_log_err(conf, "Failed initializing SSL context"); return -1; } if (inst->virtual_server && !virtual_server_find(inst->virtual_server)) { - cf_log_err_by_child(cs, "virtual_server", "Unknown virtual server '%s'", inst->virtual_server); + cf_log_err_by_child(conf, "virtual_server", "Unknown virtual server '%s'", inst->virtual_server); return -1; } diff --git a/src/modules/rlm_eap/types/rlm_eap_ttls/rlm_eap_ttls.c b/src/modules/rlm_eap/types/rlm_eap_ttls/rlm_eap_ttls.c index 881fcbf74a..d091792cf5 100644 --- a/src/modules/rlm_eap/types/rlm_eap_ttls/rlm_eap_ttls.c +++ b/src/modules/rlm_eap/types/rlm_eap_ttls/rlm_eap_ttls.c @@ -329,11 +329,10 @@ static unlang_action_t mod_session_init(rlm_rcode_t *p_result, module_ctx_t cons RETURN_MODULE_OK; } -static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, - UNUSED fr_event_list_t *el, void *thread) +static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx) { - rlm_eap_ttls_t *inst = talloc_get_type_abort(instance, rlm_eap_ttls_t); - rlm_eap_ttls_thread_t *t = talloc_get_type_abort(thread, rlm_eap_ttls_thread_t); + rlm_eap_ttls_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_eap_ttls_t); + rlm_eap_ttls_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_eap_ttls_thread_t); t->ssl_ctx = fr_tls_ctx_alloc(inst->tls_conf, false); if (!t->ssl_ctx) return -1; @@ -341,9 +340,9 @@ static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, return 0; } -static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread) +static int mod_thread_detach(module_thread_inst_ctx_t const *mctx) { - rlm_eap_ttls_thread_t *t = talloc_get_type_abort(thread, rlm_eap_ttls_thread_t); + rlm_eap_ttls_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_eap_ttls_thread_t); if (likely(t->ssl_ctx != NULL)) SSL_CTX_free(t->ssl_ctx); t->ssl_ctx = NULL; @@ -354,12 +353,13 @@ static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread) /* * Attach the module. */ -static int mod_instantiate(void *instance, CONF_SECTION *cs) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_eap_ttls_t *inst = talloc_get_type_abort(instance, rlm_eap_ttls_t); + rlm_eap_ttls_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_eap_ttls_t); + CONF_SECTION *conf = mctx->inst->conf; if (!virtual_server_find(inst->virtual_server)) { - cf_log_err_by_child(cs, "virtual_server", "Unknown virtual server '%s'", inst->virtual_server); + cf_log_err_by_child(conf, "virtual_server", "Unknown virtual server '%s'", inst->virtual_server); return -1; } @@ -367,9 +367,9 @@ static int mod_instantiate(void *instance, CONF_SECTION *cs) * Read tls configuration, either from group given by 'tls' * option, or from the eap-tls configuration. */ - inst->tls_conf = eap_tls_conf_parse(cs, "tls"); + inst->tls_conf = eap_tls_conf_parse(conf, "tls"); if (!inst->tls_conf) { - cf_log_err(cs, "Failed initializing SSL context"); + cf_log_err(conf, "Failed initializing SSL context"); return -1; } diff --git a/src/modules/rlm_escape/rlm_escape.c b/src/modules/rlm_escape/rlm_escape.c index 810fac09fd..3379a6ce23 100644 --- a/src/modules/rlm_escape/rlm_escape.c +++ b/src/modules/rlm_escape/rlm_escape.c @@ -35,7 +35,6 @@ USES_APPLE_DEPRECATED_API * Define a structure for our module configuration. */ typedef struct { - char const *name; char const *allowed_chars; } rlm_escape_t; @@ -193,17 +192,14 @@ static xlat_action_t unescape_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, request_t * that must be referenced in later calls, store a handle to it * in *instance otherwise put a null pointer there. */ -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - rlm_escape_t *inst = instance; + rlm_escape_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_escape_t); char *unescape; xlat_t *xlat; - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - - MEM(unescape = talloc_asprintf(NULL, "un%s", inst->name)); - xlat = xlat_register(NULL, inst->name, escape_xlat, false); + MEM(unescape = talloc_asprintf(NULL, "un%s", mctx->inst->name)); + xlat = xlat_register(NULL, mctx->inst->name, escape_xlat, false); xlat_func_mono(xlat, &escape_xlat_arg); xlat_async_instantiate_set(xlat, mod_xlat_instantiate, rlm_escape_t *, NULL, inst); diff --git a/src/modules/rlm_exec/rlm_exec.c b/src/modules/rlm_exec/rlm_exec.c index b73e05de6b..bef6165bd0 100644 --- a/src/modules/rlm_exec/rlm_exec.c +++ b/src/modules/rlm_exec/rlm_exec.c @@ -24,7 +24,7 @@ */ RCSID("$Id$") -#define LOG_PREFIX inst->name +#define LOG_PREFIX mctx->inst->name #include #include @@ -35,7 +35,6 @@ RCSID("$Id$") * Define a structure for our module configuration. */ typedef struct { - char const *name; bool wait; char const *program; char const *input; @@ -164,18 +163,14 @@ static int mod_xlat_instantiate(void *xlat_inst, UNUSED xlat_exp_t const *exp, v * that must be referenced in later calls, store a handle to it * in *instance otherwise put a null pointer there. */ -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - char const *p; - rlm_exec_t *inst = instance; + rlm_exec_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_exec_t); + CONF_SECTION *conf = mctx->inst->conf; xlat_t *xlat; + char const *p; - inst->name = cf_section_name2(conf); - if (!inst->name) { - inst->name = cf_section_name1(conf); - } - - xlat = xlat_register(NULL, inst->name, exec_xlat, true); + xlat = xlat_register(NULL, mctx->inst->name, exec_xlat, true); xlat_func_args(xlat, exec_xlat_args); xlat_async_instantiate_set(xlat, mod_xlat_instantiate, rlm_exec_t *, NULL, inst); @@ -238,15 +233,15 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) * * Creates a new instance of the module reading parameters from a configuration section. * - * @param conf to parse. - * @param instance configuration data. + * @param[in] mctx to parse. * @return * - 0 on success. * - < 0 on failure. */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_exec_t *inst = instance; + rlm_exec_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_exec_t); + CONF_SECTION *conf = mctx->inst->conf; ssize_t slen; if (!inst->program) return 0; diff --git a/src/modules/rlm_expr/rlm_expr.c b/src/modules/rlm_expr/rlm_expr.c index 23044298a7..a3fb60ae6f 100644 --- a/src/modules/rlm_expr/rlm_expr.c +++ b/src/modules/rlm_expr/rlm_expr.c @@ -34,13 +34,6 @@ USES_APPLE_DEPRECATED_API #include "rlm_expr.h" -/* - * Define a structure for our module configuration. - */ -typedef struct { - char const *name; -} rlm_expr_t; - /** Calculate powers * * @author Orson Peters @@ -605,15 +598,11 @@ static xlat_action_t expr_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, request_t *re * that must be referenced in later calls, store a handle to it * in *instance otherwise put a null pointer there. */ -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - rlm_expr_t *inst = instance; xlat_t *xlat; - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - - xlat = xlat_register(inst, inst->name, expr_xlat, false); + xlat = xlat_register(mctx->inst->data, mctx->inst->name, expr_xlat, false); xlat_func_mono(xlat, &expr_xlat_arg); return 0; @@ -632,6 +621,5 @@ extern module_t rlm_expr; module_t rlm_expr = { .magic = RLM_MODULE_INIT, .name = "expr", - .inst_size = sizeof(rlm_expr_t), .bootstrap = mod_bootstrap, }; diff --git a/src/modules/rlm_files/rlm_files.c b/src/modules/rlm_files/rlm_files.c index 503d24bd41..75b69158fb 100644 --- a/src/modules/rlm_files/rlm_files.c +++ b/src/modules/rlm_files/rlm_files.c @@ -350,13 +350,13 @@ static int getusersfile(TALLOC_CTX *ctx, char const *filename, fr_htrie_t **ptre /* * (Re-)read the "users" file into memory. */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_files_t *inst = instance; + rlm_files_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_files_t); inst->key_data_type = tmpl_expanded_type(inst->key); if (fr_htrie_hint(inst->key_data_type) == FR_HTRIE_INVALID) { - cf_log_err(conf, "Invalid data type '%s' for 'files' module.", + cf_log_err(mctx->inst->conf, "Invalid data type '%s' for 'files' module.", fr_table_str_by_value(fr_value_box_type_table, inst->key_data_type, "???")); return -1; } diff --git a/src/modules/rlm_icmp/rlm_icmp.c b/src/modules/rlm_icmp/rlm_icmp.c index 38102561b8..d57710ae53 100644 --- a/src/modules/rlm_icmp/rlm_icmp.c +++ b/src/modules/rlm_icmp/rlm_icmp.c @@ -23,7 +23,7 @@ */ RCSID("$Id$") -#define LOG_PREFIX inst->name +#define LOG_PREFIX mctx->inst->name #include #include @@ -37,17 +37,14 @@ RCSID("$Id$") * Define a structure for our module configuration. */ typedef struct { - char const *name; char const *interface; fr_time_delta_t timeout; fr_ipaddr_t src_ipaddr; } rlm_icmp_t; typedef struct { - rlm_icmp_t *inst; fr_rb_tree_t *tree; int fd; - fr_event_list_t *el; uint32_t data; uint16_t ident; @@ -256,7 +253,7 @@ static xlat_action_t xlat_icmp(TALLOC_CTX *ctx, UNUSED fr_dcursor_t *out, * Start off with the IPv6 pseudo-header checksum */ if (thread->t->ipaddr_type == FR_TYPE_IPV6_ADDR) { - checksum = fr_ip6_pesudo_header_checksum(&thread->t->inst->src_ipaddr.addr.v6, &echo->ip->vb_ip.addr.v6, + checksum = fr_ip6_pesudo_header_checksum(&inst->src_ipaddr.addr.v6, &echo->ip->vb_ip.addr.v6, sizeof(ip_header6_t) + sizeof(icmp), IPPROTO_ICMPV6); } @@ -294,14 +291,15 @@ static int8_t echo_cmp(void const *one, void const *two) return CMP(a->counter, b->counter); } -static void mod_icmp_read(UNUSED fr_event_list_t *el, UNUSED int sockfd, UNUSED int flags, void *ctx) +static void mod_icmp_read(UNUSED fr_event_list_t *el, UNUSED int sockfd, UNUSED int flags, void *uctx) { - rlm_icmp_thread_t *t = talloc_get_type_abort(ctx, rlm_icmp_thread_t); - rlm_icmp_t *inst = t->inst; - ssize_t len; - icmp_header_t *icmp; - rlm_icmp_echo_t my_echo, *echo; - uint64_t buffer[256]; + module_thread_inst_ctx_t const *mctx = talloc_get_type_abort(uctx, module_thread_inst_ctx_t); + rlm_icmp_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_icmp_thread_t); + + ssize_t len; + icmp_header_t *icmp; + rlm_icmp_echo_t my_echo, *echo; + uint64_t buffer[256]; len = read(t->fd, (char *) buffer, sizeof(buffer)); if (len <= 0) return; @@ -379,10 +377,10 @@ static void mod_icmp_read(UNUSED fr_event_list_t *el, UNUSED int sockfd, UNUSED } static void mod_icmp_error(fr_event_list_t *el, UNUSED int sockfd, UNUSED int flags, - UNUSED int fd_errno, void *ctx) + UNUSED int fd_errno, void *uctx) { - rlm_icmp_thread_t *t = talloc_get_type_abort(ctx, rlm_icmp_thread_t); - rlm_icmp_t *inst = t->inst; + module_ctx_t const *mctx = talloc_get_type_abort(uctx, module_ctx_t); + rlm_icmp_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_icmp_thread_t); ERROR("Failed reading from ICMP socket - Closing it"); @@ -422,16 +420,23 @@ static int mod_xlat_instantiate(void *xlat_inst, UNUSED xlat_exp_t const *exp, v /** Instantiate thread data for the submodule. * */ -static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, fr_event_list_t *el, void *thread) +static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx) { + module_thread_inst_ctx_t *our_mctx; + rlm_icmp_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_icmp_t); + rlm_icmp_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_icmp_thread_t); + fr_ipaddr_t ipaddr, *src; + int fd, af, proto; - rlm_icmp_t *inst = talloc_get_type_abort(instance, rlm_icmp_t); - rlm_icmp_thread_t *t = talloc_get_type_abort(thread, rlm_icmp_thread_t); - fr_ipaddr_t ipaddr, *src; + + /* + * Create a copy of the mctx on the heap that we can + * pass as the uctx to the io functions. + */ + MEM(our_mctx = talloc_zero(t, module_thread_inst_ctx_t)); + memcpy(our_mctx, mctx, sizeof(*our_mctx)); MEM(t->tree = fr_rb_inline_alloc(t, rlm_icmp_echo_t, node, echo_cmp, NULL)); - t->inst = inst; - t->el = el; /* * Since these fields are random numbers, we don't care @@ -517,11 +522,11 @@ static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, * We assume that the outbound socket is always writable. * If not, too bad. Packets will get lost. */ - if (fr_event_fd_insert(t, el, fd, + if (fr_event_fd_insert(t, mctx->el, fd, mod_icmp_read, NULL, mod_icmp_error, - t) < 0) { + our_mctx) < 0) { fr_strerror_const_push("Failed adding socket to event loop"); close(fd); return -1; @@ -531,15 +536,12 @@ static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, return 0; } -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - rlm_icmp_t *inst = instance; + rlm_icmp_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_icmp_t); xlat_t *xlat; - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - - xlat = xlat_register(inst, inst->name, xlat_icmp, true); + xlat = xlat_register(inst, mctx->inst->name, xlat_icmp, true); xlat_func_args(xlat, xlat_icmp_args); xlat_async_instantiate_set(xlat, mod_xlat_instantiate, rlm_icmp_t *, NULL, inst); xlat_async_thread_instantiate_set(xlat, mod_xlat_thread_instantiate, xlat_icmp_thread_inst_t, NULL, inst); @@ -568,13 +570,13 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) /** Destroy thread data for the submodule. * */ -static int mod_thread_detach(fr_event_list_t *el, void *thread) +static int mod_thread_detach(module_thread_inst_ctx_t const *mctx) { - rlm_icmp_thread_t *t = talloc_get_type_abort(thread, rlm_icmp_thread_t); + rlm_icmp_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_icmp_thread_t); if (t->fd < 0) return 0; - (void) fr_event_fd_delete(el, t->fd, FR_EVENT_FILTER_IO); + (void) fr_event_fd_delete(mctx->el, t->fd, FR_EVENT_FILTER_IO); close(t->fd); t->fd = -1; diff --git a/src/modules/rlm_idn/rlm_idn.c b/src/modules/rlm_idn/rlm_idn.c index 4c70171a6d..dca0b56f83 100644 --- a/src/modules/rlm_idn/rlm_idn.c +++ b/src/modules/rlm_idn/rlm_idn.c @@ -32,7 +32,6 @@ RCSID("$Id$") * Structure for module configuration */ typedef struct { - char const *name; bool use_std3_ascii_rules; bool allow_unassigned; } rlm_idn_t; @@ -156,15 +155,12 @@ static xlat_action_t xlat_idna(TALLOC_CTX *ctx, fr_dcursor_t *out, request_t *re return XLAT_ACTION_DONE; } -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - rlm_idn_t *inst = instance; + rlm_idn_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_idn_t); xlat_t *xlat; - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - - xlat = xlat_register(inst, inst->name, xlat_idna, false); + xlat = xlat_register(inst, mctx->inst->name, xlat_idna, false); xlat_func_mono(xlat, &xlat_idna_arg); xlat_async_instantiate_set(xlat, mod_xlat_instantiate, rlm_idn_t *, NULL, inst); diff --git a/src/modules/rlm_imap/rlm_imap.c b/src/modules/rlm_imap/rlm_imap.c index ba103d80b9..b6bd245172 100644 --- a/src/modules/rlm_imap/rlm_imap.c +++ b/src/modules/rlm_imap/rlm_imap.c @@ -53,7 +53,6 @@ typedef struct { } rlm_imap_t; typedef struct { - rlm_imap_t const *inst; //!< Instance of rlm_imap. fr_curl_handle_t *mhandle; //!< Thread specific multi handle. Serves as the dispatch and coralling structure for imap requests. } rlm_imap_thread_t; @@ -185,14 +184,12 @@ static void mod_unload(void) /* * Initialize a new thread with a curl instance */ -static int mod_thread_instantiate(UNUSED CONF_SECTION const *conf, void *instance, fr_event_list_t *el, void *thread) +static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx) { - rlm_imap_thread_t *t = thread; + rlm_imap_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_imap_thread_t); fr_curl_handle_t *mhandle; - t->inst = instance; - - mhandle = fr_curl_io_init(t, el, false); + mhandle = fr_curl_io_init(t, mctx->el, false); if (!mhandle) return -1; t->mhandle = mhandle; @@ -202,12 +199,12 @@ static int mod_thread_instantiate(UNUSED CONF_SECTION const *conf, void *instanc /* * Close the thread and free the memory */ -static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread) +static int mod_thread_detach(module_thread_inst_ctx_t const *mctx) { - rlm_imap_thread_t *t = thread; + rlm_imap_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_imap_thread_t); - talloc_free(t->mhandle); - return 0; + talloc_free(t->mhandle); + return 0; } /* diff --git a/src/modules/rlm_isc_dhcp/rlm_isc_dhcp.c b/src/modules/rlm_isc_dhcp/rlm_isc_dhcp.c index a06bcfcd11..b6aec24e5a 100644 --- a/src/modules/rlm_isc_dhcp/rlm_isc_dhcp.c +++ b/src/modules/rlm_isc_dhcp/rlm_isc_dhcp.c @@ -74,7 +74,6 @@ typedef struct rlm_isc_dhcp_info_s rlm_isc_dhcp_info_t; * be used as the instance handle. */ typedef struct { - char const *name; char const *filename; bool debug; bool pedantic; @@ -2176,16 +2175,14 @@ static int read_file(rlm_isc_dhcp_t *inst, rlm_isc_dhcp_info_t *parent, char con return 1; } -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - int ret; - rlm_isc_dhcp_t *inst = instance; - rlm_isc_dhcp_info_t *info; - - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); + rlm_isc_dhcp_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_isc_dhcp_t); + CONF_SECTION *conf = mctx->inst->conf; + rlm_isc_dhcp_info_t *info; + int ret; - inst->head = info = talloc_zero(inst, rlm_isc_dhcp_info_t); + MEM(inst->head = info = talloc_zero(inst, rlm_isc_dhcp_info_t)); fr_pair_list_init(&info->options); info->last = &(info->child); diff --git a/src/modules/rlm_json/rlm_json.c b/src/modules/rlm_json/rlm_json.c index 9562153ab4..a97fdc0dd2 100644 --- a/src/modules/rlm_json/rlm_json.c +++ b/src/modules/rlm_json/rlm_json.c @@ -52,7 +52,6 @@ static fr_sbuff_parse_rules_t const json_arg_parse_rules = { * */ typedef struct { - char const *name; fr_json_format_t *format; } rlm_json_t; @@ -550,23 +549,21 @@ finish: return rcode; } -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - rlm_json_t *inst = talloc_get_type_abort(instance, rlm_json_t); + rlm_json_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_json_t); + CONF_SECTION *conf = mctx->inst->conf; xlat_t *xlat; char *name; fr_json_format_t *format = inst->format; - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - - xlat = xlat_register(instance, "jsonquote", json_quote_xlat, false); + xlat = xlat_register(inst, "jsonquote", json_quote_xlat, false); if (xlat) xlat_func_mono(xlat, &json_quote_xlat_arg); - xlat = xlat_register(instance, "jpathvalidate", jpath_validate_xlat, false); + xlat = xlat_register(inst, "jpathvalidate", jpath_validate_xlat, false); if (xlat) xlat_func_mono(xlat, &jpath_validate_xlat_arg); - name = talloc_asprintf(inst, "%s_encode", inst->name); - xlat = xlat_register(instance, name, json_encode_xlat, false); + name = talloc_asprintf(inst, "%s_encode", mctx->inst->name); + xlat = xlat_register(inst, name, json_encode_xlat, false); xlat_func_mono(xlat, &json_encode_xlat_arg); xlat_async_instantiate_set(xlat, json_xlat_instantiate, rlm_json_t *, NULL, inst); @@ -583,7 +580,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) } fr_json_format_verify(format, true); - if (map_proc_register(instance, "json", mod_map_proc, + if (map_proc_register(inst, "json", mod_map_proc, mod_map_proc_instantiate, sizeof(rlm_json_jpath_cache_t)) < 0) return -1; return 0; } diff --git a/src/modules/rlm_krb5/rlm_krb5.c b/src/modules/rlm_krb5/rlm_krb5.c index 20ef7deb42..681e1c2d66 100644 --- a/src/modules/rlm_krb5/rlm_krb5.c +++ b/src/modules/rlm_krb5/rlm_krb5.c @@ -57,9 +57,9 @@ fr_dict_attr_autoload_t rlm_krb5_dict_attr[] = { { NULL } }; -static int mod_detach(void *instance) +static int mod_detach(module_detach_ctx_t const *mctx) { - rlm_krb5_t *inst = instance; + rlm_krb5_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_krb5_t); #ifndef HEIMDAL_KRB5 talloc_free(inst->vic_options); @@ -79,9 +79,9 @@ static int mod_detach(void *instance) return 0; } -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_krb5_t *inst = instance; + rlm_krb5_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_krb5_t); krb5_error_code ret; #ifndef HEIMDAL_KRB5 krb5_keytab keytab; @@ -123,9 +123,6 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) #endif } - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - ret = krb5_init_context(&inst->context); if (ret) { ERROR("Context initialisation failed: %s", rlm_krb5_error(inst, NULL, ret)); @@ -225,7 +222,7 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) /* * Initialize the socket pool. */ - inst->pool = module_connection_pool_init(conf, inst, krb5_mod_conn_create, NULL, NULL, NULL, NULL); + inst->pool = module_connection_pool_init(mctx->inst->conf, inst, krb5_mod_conn_create, NULL, NULL, NULL, NULL); if (!inst->pool) return -1; #else inst->conn = krb5_mod_conn_create(inst, inst, fr_time_delta_wrap(0)); diff --git a/src/modules/rlm_ldap/rlm_ldap.c b/src/modules/rlm_ldap/rlm_ldap.c index a4bcedac59..5c2466135f 100644 --- a/src/modules/rlm_ldap/rlm_ldap.c +++ b/src/modules/rlm_ldap/rlm_ldap.c @@ -1431,7 +1431,7 @@ skip_edir: if (fr_ldap_map_do(request, handle, inst->valuepair_attr, &expanded, entry) > 0) rcode = RLM_MODULE_UPDATED; REXDENT(); - rlm_ldap_check_reply(inst, request, ttrunk); + rlm_ldap_check_reply(mctx, request, ttrunk); } finish: @@ -1697,9 +1697,9 @@ static unlang_action_t CC_HINT(nonnull) mod_post_auth(rlm_rcode_t *p_result, mod /** Detach from the LDAP server and cleanup internal state. * */ -static int mod_detach(void *instance) +static int mod_detach(module_detach_ctx_t const *mctx) { - rlm_ldap_t *inst = instance; + rlm_ldap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_ldap_t); #ifdef HAVE_LDAP_CREATE_SORT_CONTROL if (inst->userobj_sort_ctrl) ldap_control_free(inst->userobj_sort_ctrl); @@ -1714,7 +1714,7 @@ static int mod_detach(void *instance) * * Allocate a new ldap_acct_section_t and write the config data into it. * - * @param[in] inst rlm_ldap configuration. + * @param[in] mctx rlm_ldap configuration. * @param[in] parent of the config section. * @param[out] config to write the sub section parameters to. * @param[in] comp The section name were parsing the config for. @@ -1722,17 +1722,19 @@ static int mod_detach(void *instance) * - 0 on success. * - < 0 on failure. */ -static int parse_sub_section(rlm_ldap_t *inst, CONF_SECTION *parent, ldap_acct_section_t **config, +static int parse_sub_section(module_inst_ctx_t const *mctx, + CONF_SECTION *parent, ldap_acct_section_t **config, rlm_components_t comp) { - CONF_SECTION *cs; + rlm_ldap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_ldap_t); + CONF_SECTION *cs; char const *name = section_type_value[comp]; cs = cf_section_find(parent, name, NULL); if (!cs) { DEBUG2("rlm_ldap (%s) - Couldn't find configuration for %s, will return NOOP for calls " - "from this section", inst->name, name); + "from this section", mctx->inst->name, name); return 0; } @@ -1741,7 +1743,7 @@ static int parse_sub_section(rlm_ldap_t *inst, CONF_SECTION *parent, ldap_acct_s *config = talloc_zero(inst, ldap_acct_section_t); if (cf_section_parse(*config, *config, cs) < 0) { - PERROR("rlm_ldap (%s) - Failed parsing configuration for section %s", inst->name, name); + PERROR("rlm_ldap (%s) - Failed parsing configuration for section %s", mctx->inst->name, name); return -1; } @@ -1765,26 +1767,25 @@ static int mod_xlat_thread_instantiate(UNUSED void *xlat_inst, void *xlat_thread /** Initialise thread specific data structure * */ -static int mod_thread_instatiate(UNUSED CONF_SECTION const *conf, void *instance, - fr_event_list_t *el, void *thread) +static int mod_thread_instatiate(module_thread_inst_ctx_t const *mctx) { - rlm_ldap_t *inst = instance; - fr_ldap_thread_t *this_thread = thread; + rlm_ldap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_ldap_t); + fr_ldap_thread_t *t = talloc_get_type_abort(mctx->thread, fr_ldap_thread_t); fr_ldap_thread_trunk_t *ttrunk; /* * Initialise tree for connection trunks used by this thread */ - MEM(this_thread->trunks = fr_rb_inline_talloc_alloc(this_thread, fr_ldap_thread_trunk_t, node, fr_ldap_trunk_cmp, NULL)); + MEM(t->trunks = fr_rb_inline_talloc_alloc(t, fr_ldap_thread_trunk_t, node, fr_ldap_trunk_cmp, NULL)); - this_thread->config = &inst->handle_config; - this_thread->trunk_conf = &inst->trunk_conf; - this_thread->el = el; + t->config = &inst->handle_config; + t->trunk_conf = &inst->trunk_conf; + t->el = mctx->el; /* * Launch trunk for module default connection */ - ttrunk = fr_thread_ldap_trunk_get(this_thread, inst->handle_config.server, inst->handle_config.admin_identity, + ttrunk = fr_thread_ldap_trunk_get(t, inst->handle_config.server, inst->handle_config.admin_identity, inst->handle_config.admin_password, NULL, &inst->handle_config); if (!ttrunk) { ERROR("Unable to launch LDAP trunk"); @@ -1794,11 +1795,11 @@ static int mod_thread_instatiate(UNUSED CONF_SECTION const *conf, void *instance /* * Set up a per-thread LDAP connection to use for bind auths */ - this_thread->conn = fr_ldap_connection_state_alloc(this_thread, el, this_thread->config, inst->name); - fr_connection_add_watch_post(this_thread->conn, FR_CONNECTION_STATE_CONNECTED, _ldap_async_bind_auth_watch, false, this_thread); - fr_connection_signal_init(this_thread->conn); + t->conn = fr_ldap_connection_state_alloc(t, mctx->el, t->config, mctx->inst->name); + fr_connection_add_watch_post(t->conn, FR_CONNECTION_STATE_CONNECTED, _ldap_async_bind_auth_watch, false, t); + fr_connection_signal_init(t->conn); - MEM(this_thread->binds = fr_rb_inline_talloc_alloc(this_thread, fr_ldap_bind_auth_ctx_t, node, fr_ldap_bind_auth_cmp, NULL)); + MEM(t->binds = fr_rb_inline_talloc_alloc(t, fr_ldap_bind_auth_ctx_t, node, fr_ldap_bind_auth_cmp, NULL)); return 0; } @@ -1806,17 +1807,17 @@ static int mod_thread_instatiate(UNUSED CONF_SECTION const *conf, void *instance /** Clean up thread specific data structure * */ -static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread) +static int mod_thread_detach(module_thread_inst_ctx_t const *mctx) { - fr_ldap_thread_t *this_thread = thread; + fr_ldap_thread_t *t = talloc_get_type_abort(mctx->thread, fr_ldap_thread_t); void **trunks_to_free; int i; - if (fr_rb_flatten_inorder(NULL, &trunks_to_free, this_thread->trunks) < 0) return -1; + if (fr_rb_flatten_inorder(NULL, &trunks_to_free, t->trunks) < 0) return -1; for (i = talloc_array_length(trunks_to_free) - 1; i >= 0; i--) talloc_free(trunks_to_free[i]); talloc_free(trunks_to_free); - talloc_free(this_thread->trunks); + talloc_free(t->trunks); return 0; } @@ -1825,28 +1826,25 @@ static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread) * * Define attributes. * - * @param conf to parse. - * @param instance configuration data. + * @param[in] mctx configuration data. * @return * - 0 on success. * - < 0 on failure. */ -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - rlm_ldap_t *inst = instance; + rlm_ldap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_ldap_t); + CONF_SECTION *conf = mctx->inst->conf; char buffer[256]; char const *group_attribute; xlat_t *xlat; - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - - inst->handle_config.name = talloc_typed_asprintf(inst, "rlm_ldap (%s)", inst->name); + inst->handle_config.name = talloc_typed_asprintf(inst, "rlm_ldap (%s)", mctx->inst->name); if (inst->group_attribute) { group_attribute = inst->group_attribute; } else if (cf_section_name2(conf)) { - snprintf(buffer, sizeof(buffer), "%s-LDAP-Group", inst->name); + snprintf(buffer, sizeof(buffer), "%s-LDAP-Group", mctx->inst->name); group_attribute = buffer; } else { group_attribute = "LDAP-Group"; @@ -1878,7 +1876,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) inst->cache_da = inst->group_da; /* Default to the group_da */ } - xlat = xlat_register(NULL, inst->name, ldap_xlat, false); + xlat = xlat_register(NULL, mctx->inst->name, ldap_xlat, false); xlat_func_mono(xlat, &ldap_xlat_arg); xlat_async_thread_instantiate_set(xlat, mod_xlat_thread_instantiate, ldap_xlat_thread_inst_t, NULL, inst); @@ -1887,7 +1885,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) xlat = xlat_register(NULL, "ldap_unescape", ldap_unescape_xlat, false); if (xlat) xlat_func_mono(xlat, &ldap_escape_xlat_arg); - map_proc_register(inst, inst->name, mod_map_proc, ldap_map_verify, 0); + map_proc_register(inst, mctx->inst->name, mod_map_proc, ldap_map_verify, 0); return 0; } @@ -1896,18 +1894,18 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) * * Creates a new instance of the module reading parameters from a configuration section. * - * @param conf to parse. - * @param instance configuration data. + * @param [in] mctx configuration data. * @return * - 0 on success. * - < 0 on failure. */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { size_t i; CONF_SECTION *options, *update; - rlm_ldap_t *inst = instance; + rlm_ldap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_ldap_t); + CONF_SECTION *conf = mctx->inst->conf; fr_map_list_init(&inst->user_map); @@ -1919,8 +1917,8 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) /* * If the configuration parameters can't be parsed, then fail. */ - if ((parse_sub_section(inst, conf, &inst->accounting, MOD_ACCOUNTING) < 0) || - (parse_sub_section(inst, conf, &inst->postauth, MOD_POST_AUTH) < 0)) { + if ((parse_sub_section(mctx, conf, &inst->accounting, MOD_ACCOUNTING) < 0) || + (parse_sub_section(mctx, conf, &inst->postauth, MOD_POST_AUTH) < 0)) { cf_log_err(conf, "Failed parsing configuration"); goto error; @@ -2202,7 +2200,7 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) */ if (inst->handle_config.server) { inst->handle_config.server[talloc_array_length(inst->handle_config.server) - 2] = '\0'; - DEBUG4("rlm_ldap (%s) - LDAP server string: %s", inst->name, inst->handle_config.server); + DEBUG4("rlm_ldap (%s) - LDAP server string: %s", mctx->inst->name, inst->handle_config.server); } #ifdef LDAP_OPT_X_TLS_NEVER diff --git a/src/modules/rlm_ldap/rlm_ldap.h b/src/modules/rlm_ldap/rlm_ldap.h index b859dcad09..73958ca0b4 100644 --- a/src/modules/rlm_ldap/rlm_ldap.h +++ b/src/modules/rlm_ldap/rlm_ldap.h @@ -30,8 +30,6 @@ typedef struct { } ldap_acct_section_t; typedef struct { - char const *name; //!< Instance name. - bool expect_password; //!< True if the user_map included a mapping between an LDAP //!< attribute and one of our password reference attributes. @@ -165,7 +163,7 @@ char const *rlm_ldap_find_user(rlm_ldap_t const *inst, request_t *request, fr_ld rlm_rcode_t rlm_ldap_check_access(rlm_ldap_t const *inst, request_t *request, LDAP *handle, LDAPMessage *entry); -void rlm_ldap_check_reply(rlm_ldap_t const *inst, request_t *request, fr_ldap_thread_trunk_t const *ttrunk); +void rlm_ldap_check_reply(module_ctx_t const *mctx, request_t *request, fr_ldap_thread_trunk_t const *ttrunk); /* * groups.c - Group membership functions. diff --git a/src/modules/rlm_ldap/user.c b/src/modules/rlm_ldap/user.c index 68a264ff2d..460af07fcc 100644 --- a/src/modules/rlm_ldap/user.c +++ b/src/modules/rlm_ldap/user.c @@ -31,7 +31,7 @@ USES_APPLE_DEPRECATED_API #include #include -#define LOG_PREFIX inst->name +#define LOG_PREFIX mctx->inst->name #include "rlm_ldap.h" @@ -227,12 +227,14 @@ rlm_rcode_t rlm_ldap_check_access(rlm_ldap_t const *inst, request_t *request, LD * * Checks to see if after the LDAP to RADIUS mapping has been completed that a reference password. * - * @param inst rlm_ldap configuration. - * @param request Current request. - * @param ttrunk the connection thread trunk. + * @param[in] mctx rlm_ldap configuration. + * @param[in] request Current request. + * @param[in] ttrunk the connection thread trunk. */ -void rlm_ldap_check_reply(rlm_ldap_t const *inst, request_t *request, fr_ldap_thread_trunk_t const *ttrunk) +void rlm_ldap_check_reply(module_ctx_t const *mctx, request_t *request, fr_ldap_thread_trunk_t const *ttrunk) { + rlm_ldap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_ldap_t); + /* * More warning messages for people who can't be bothered to read the documentation. * @@ -255,9 +257,9 @@ void rlm_ldap_check_reply(rlm_ldap_t const *inst, request_t *request, fr_ldap_th RWDEBUG2("!!! - Configure authentication via wbclient (mschapv2 only)"); RWDEBUG2("!!! that password attribute"); RWDEBUG2("!!! - Bind as the user by listing %s in the authenticate section, and", - inst->name); + mctx->inst->name); RWDEBUG2("!!! setting attribute &control.Auth-Type := '%s' in the authorize section", - inst->name); + mctx->inst->name); RWDEBUG2("!!! (pap only)"); break; @@ -270,9 +272,9 @@ void rlm_ldap_check_reply(rlm_ldap_t const *inst, request_t *request, fr_ldap_th RWDEBUG2("!!! eDir server (recommended)"); RWDEBUG2("!!! that password attribute"); RWDEBUG2("!!! - Bind as the user by listing %s in the authenticate section, and", - inst->name); + mctx->inst->name); RWDEBUG2("!!! setting attribute &control.Auth-Type := '%s' in the authorize section", - inst->name); + mctx->inst->name); RWDEBUG("!!! (pap only)"); break; @@ -285,9 +287,9 @@ void rlm_ldap_check_reply(rlm_ldap_t const *inst, request_t *request, fr_ldap_th RWDEBUG2("!!! \"%s\" has permission to read that password attribute (recommended)", ttrunk->config.admin_identity); RWDEBUG2("!!! - Bind as the user by listing %s in the authenticate section, and", - inst->name); + mctx->inst->name); RWDEBUG2("!!! setting attribute &control.Auth-Type := '%s' in the authorize section", - inst->name); + mctx->inst->name); RWDEBUG2("!!! (pap only)"); } else { RWDEBUG2("!!! No \"known good\" password added"); @@ -297,9 +299,9 @@ void rlm_ldap_check_reply(rlm_ldap_t const *inst, request_t *request, fr_ldap_th RWDEBUG2("!!! 'identity' is set to the DN of an account that has permission to read"); RWDEBUG2("!!! that password attribute"); RWDEBUG2("!!! - Bind as the user by listing %s in the authenticate section, and", - inst->name); + mctx->inst->name); RWDEBUG2("!!! setting attribute &control.Auth-Type := '%s' in the authorize section", - inst->name); + mctx->inst->name); RWDEBUG2("!!! (pap only)"); } break; diff --git a/src/modules/rlm_linelog/rlm_linelog.c b/src/modules/rlm_linelog/rlm_linelog.c index ad8b6fa4db..9c480dc606 100644 --- a/src/modules/rlm_linelog/rlm_linelog.c +++ b/src/modules/rlm_linelog/rlm_linelog.c @@ -78,7 +78,6 @@ typedef struct { /** linelog module instance */ typedef struct { - char const *name; //!< Module instance name. fr_pool_t *pool; //!< Connection pool instance. char const *delimiter; //!< Line termination string (usually \n). @@ -196,9 +195,9 @@ static int _mod_conn_free(linelog_conn_t *conn) static void *mod_conn_create(TALLOC_CTX *ctx, void *instance, fr_time_delta_t timeout) { - rlm_linelog_t const *inst = instance; - linelog_conn_t *conn; - int sockfd = -1; + rlm_linelog_t const *inst = talloc_get_type_abort(instance, rlm_linelog_t const); + linelog_conn_t *conn; + int sockfd = -1; switch (inst->log_dst) { case LINELOG_DST_UNIX: @@ -270,9 +269,9 @@ static void *mod_conn_create(TALLOC_CTX *ctx, void *instance, fr_time_delta_t ti return conn; } -static int mod_detach(void *instance) +static int mod_detach(module_detach_ctx_t const *mctx) { - rlm_linelog_t *inst = instance; + rlm_linelog_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_linelog_t); fr_pool_free(inst->pool); @@ -283,9 +282,10 @@ static int mod_detach(void *instance) /* * Instantiate the module. */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_linelog_t *inst = instance; + rlm_linelog_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_linelog_t); + CONF_SECTION *conf = mctx->inst->conf; char prefix[100]; /* @@ -308,10 +308,7 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) return -1; } - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - - snprintf(prefix, sizeof(prefix), "rlm_linelog (%s)", inst->name); + snprintf(prefix, sizeof(prefix), "rlm_linelog (%s)", mctx->inst->name); /* * Setup the logging destination diff --git a/src/modules/rlm_logintime/rlm_logintime.c b/src/modules/rlm_logintime/rlm_logintime.c index 7b99a17342..7f492b24b9 100644 --- a/src/modules/rlm_logintime/rlm_logintime.c +++ b/src/modules/rlm_logintime/rlm_logintime.c @@ -232,9 +232,10 @@ static unlang_action_t CC_HINT(nonnull) mod_authorize(rlm_rcode_t *p_result, mod * that must be referenced in later calls, store a handle to it * in *instance otherwise put a null pointer there. */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_logintime_t *inst = instance; + rlm_logintime_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_logintime_t); + CONF_SECTION *conf = mctx->inst->conf; if (!fr_time_delta_ispos(inst->min_time)) { cf_log_err(conf, "Invalid value '0' for minimum_timeout"); diff --git a/src/modules/rlm_logtee/rlm_logtee.c b/src/modules/rlm_logtee/rlm_logtee.c index 4ca400f8c2..75ab8e98ad 100644 --- a/src/modules/rlm_logtee/rlm_logtee.c +++ b/src/modules/rlm_logtee/rlm_logtee.c @@ -545,23 +545,20 @@ static unlang_action_t mod_insert_logtee(rlm_rcode_t *p_result, module_ctx_t con /** Create thread-specific connections and buffers * - * @param[in] conf section containing the configuration of this module instance. - * @param[in] instance of rlm_logtee_t. - * @param[in] el The event list serviced by this thread. - * @param[in] thread specific data. + * @param[in] mctx specific data. * @return * - 0 on success. * - -1 on failure. */ -static int mod_thread_instantiate(UNUSED CONF_SECTION const *conf, void *instance, fr_event_list_t *el, void *thread) +static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx) { - rlm_logtee_t *inst = talloc_get_type_abort(instance, rlm_logtee_t); - rlm_logtee_thread_t *t = talloc_get_type_abort(thread, rlm_logtee_thread_t); + rlm_logtee_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_logtee_t); + rlm_logtee_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_logtee_thread_t); MEM(t->fring = fr_fring_alloc(t, inst->buffer_depth, false)); t->inst = inst; - t->el = el; + t->el = mctx->el; /* * Pre-allocate temporary attributes @@ -574,7 +571,7 @@ static int mod_thread_instantiate(UNUSED CONF_SECTION const *conf, void *instanc /* * This opens the outbound connection */ - t->conn = fr_connection_alloc(t, el, + t->conn = fr_connection_alloc(t, t->el, &(fr_connection_funcs_t){ .init = _logtee_conn_init, .open = _logtee_conn_open, @@ -595,9 +592,10 @@ static int mod_thread_instantiate(UNUSED CONF_SECTION const *conf, void *instanc /* * Instantiate the module. */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_logtee_t *inst = instance; + rlm_logtee_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_logtee_t); + CONF_SECTION *conf = mctx->inst->conf; char prefix[100]; /* @@ -615,9 +613,6 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) return -1; } - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - snprintf(prefix, sizeof(prefix), "rlm_logtee (%s)", inst->name); FR_SIZE_BOUND_CHECK("buffer_depth", inst->buffer_depth, >=, (size_t)1); diff --git a/src/modules/rlm_lua/lua.c b/src/modules/rlm_lua/lua.c index 65d21ac42d..037437462b 100644 --- a/src/modules/rlm_lua/lua.c +++ b/src/modules/rlm_lua/lua.c @@ -25,7 +25,7 @@ */ RCSID("$Id$") -#define LOG_PREFIX inst->name +#define LOG_PREFIX mctx->inst->name #include #include @@ -352,15 +352,15 @@ static int _lua_pair_get(lua_State *L) */ static int _lua_pair_set(lua_State *L) { - rlm_lua_t const *inst = fr_lua_util_get_inst(); - request_t *request = fr_lua_util_get_request(); + module_ctx_t const *mctx = fr_lua_util_get_mctx(); + rlm_lua_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_lua_t); + request_t *request = fr_lua_util_get_request(); fr_dcursor_t cursor; fr_dict_attr_t const *da; fr_pair_t *vp = NULL, *new; lua_Integer index; bool delete = false; - /* * This function should only be called as a closure. * As we control the upvalues, we should assert on errors. @@ -612,12 +612,12 @@ char const *fr_lua_version(lua_State *L) * * Also check what was loaded there is a function and that it accepts the correct arguments. * - * @param inst Current instance of fr_lua - * @param L the lua state - * @param name of function to check. + * @param[in] mctx module instantiation data. + * @param[in] L the lua state. + * @param[in] name of function to check. * @returns 0 on success (function is present and correct), or -1 on failure. */ -static int fr_lua_check_func(rlm_lua_t const *inst, lua_State *L, char const *name) +static int fr_lua_check_func(module_inst_ctx_t const *mctx, lua_State *L, char const *name) { int ret; int type; @@ -739,12 +739,11 @@ static void _lua_fr_request_register(lua_State *L, request_t *request) unlang_action_t fr_lua_run(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request, char const *funcname) { - rlm_lua_t const *inst = talloc_get_type_abort_const(mctx->inst->data, rlm_lua_t); rlm_lua_thread_t *thread = talloc_get_type_abort(mctx->thread, rlm_lua_thread_t); lua_State *L = thread->interpreter; rlm_rcode_t rcode = RLM_MODULE_OK; - fr_lua_util_set_inst(inst); + fr_lua_util_set_mctx(mctx); fr_lua_util_set_request(request); ROPTIONAL(RDEBUG2, DEBUG2, "Calling %s() in interpreter %p", funcname, L); @@ -756,7 +755,7 @@ unlang_action_t fr_lua_run(rlm_rcode_t *p_result, module_ctx_t const *mctx, requ */ if (fr_lua_get_field(L, request, funcname) < 0) { error: - fr_lua_util_set_inst(NULL); + fr_lua_util_set_mctx(NULL); fr_lua_util_set_request(NULL); RETURN_MODULE_FAIL; @@ -801,7 +800,7 @@ error: } done: - fr_lua_util_set_inst(NULL); + fr_lua_util_set_mctx(NULL); fr_lua_util_set_request(NULL); RETURN_MODULE_RCODE(rcode); @@ -874,17 +873,15 @@ static void fr_lua_rcode_register(lua_State *L, char const *name) * Creates a new lua_State and verifies all required functions have been loaded correctly. * * @param[in] out Where to write a pointer to the new state. - * @param[in] instance Current instance of fr_lua, a talloc marker - * context will be inserted into the context of instance - * to ensure the interpreter is freed when instance data is freed. + * @parma[in] mctx configuration data for the * @return 0 on success else -1. */ -int fr_lua_init(lua_State **out, rlm_lua_t const *instance) +int fr_lua_init(lua_State **out, module_inst_ctx_t const *mctx) { - rlm_lua_t const *inst = talloc_get_type_abort_const(instance, rlm_lua_t); + rlm_lua_t const *inst = talloc_get_type_abort_const(mctx->inst->data, rlm_lua_t); lua_State *L; - fr_lua_util_set_inst(inst); + fr_lua_util_set_mctx(&(module_ctx_t){ .inst = mctx->inst }); L = luaL_newstate(); if (!L) { @@ -902,7 +899,7 @@ int fr_lua_init(lua_State **out, rlm_lua_t const *instance) error: *out = NULL; - fr_lua_util_set_inst(NULL); + fr_lua_util_set_mctx(NULL); lua_close(L); return -1; } @@ -923,10 +920,10 @@ int fr_lua_init(lua_State **out, rlm_lua_t const *instance) */ if (inst->jit) { DEBUG4("Initialised new LuaJIT interpreter %p", L); - if (fr_lua_util_jit_log_register(inst, L) < 0) goto error; + if (fr_lua_util_jit_log_register(L) < 0) goto error; } else { DEBUG4("Initialised new Lua interpreter %p", L); - if (fr_lua_util_log_register(inst, L) < 0) goto error; + if (fr_lua_util_log_register(L) < 0) goto error; } /* @@ -938,14 +935,14 @@ int fr_lua_init(lua_State **out, rlm_lua_t const *instance) /* * Verify all the functions were provided. */ - if (fr_lua_check_func(inst, L, inst->func_authorize) - || fr_lua_check_func(inst, L, inst->func_authenticate) - || fr_lua_check_func(inst, L, inst->func_preacct) - || fr_lua_check_func(inst, L, inst->func_accounting) - || fr_lua_check_func(inst, L, inst->func_post_auth) - || fr_lua_check_func(inst, L, inst->func_instantiate) - || fr_lua_check_func(inst, L, inst->func_detach) - || fr_lua_check_func(inst, L, inst->func_xlat)) { + if (fr_lua_check_func(mctx, L, inst->func_authorize) + || fr_lua_check_func(mctx, L, inst->func_authenticate) + || fr_lua_check_func(mctx, L, inst->func_preacct) + || fr_lua_check_func(mctx, L, inst->func_accounting) + || fr_lua_check_func(mctx, L, inst->func_post_auth) + || fr_lua_check_func(mctx, L, inst->func_instantiate) + || fr_lua_check_func(mctx, L, inst->func_detach) + || fr_lua_check_func(mctx, L, inst->func_xlat)) { goto error; } diff --git a/src/modules/rlm_lua/lua.h b/src/modules/rlm_lua/lua.h index 51c3e591eb..f61ffb1e70 100644 --- a/src/modules/rlm_lua/lua.h +++ b/src/modules/rlm_lua/lua.h @@ -46,7 +46,6 @@ typedef struct { //!< basis, or use a single mutex protected interpreter. bool jit; //!< Whether the linked interpreter is Lua 5.1 or LuaJIT. - const char *name; //!< Name of this instance. const char *module; //!< Full path to lua script to load and execute. const char *func_instantiate; //!< Name of function to run on instantiation. @@ -65,7 +64,7 @@ typedef struct { } rlm_lua_thread_t; /* lua.c */ -int fr_lua_init(lua_State **out, rlm_lua_t const *instance); +int fr_lua_init(lua_State **out, module_inst_ctx_t const *mctx); unlang_action_t fr_lua_run(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request, char const *funcname); bool fr_lua_isjit(lua_State *L); char const *fr_lua_version(lua_State *L); @@ -76,10 +75,10 @@ void fr_lua_util_jit_log_info(char const *msg); void fr_lua_util_jit_log_warn(char const *msg); void fr_lua_util_jit_log_error(char const *msg); -int fr_lua_util_jit_log_register(rlm_lua_t const *inst, lua_State *L); -int fr_lua_util_log_register(rlm_lua_t const *inst, lua_State *L); -void fr_lua_util_set_inst(rlm_lua_t const *inst); -rlm_lua_t const *fr_lua_util_get_inst(void); +int fr_lua_util_jit_log_register(lua_State *L); +int fr_lua_util_log_register(lua_State *L); +void fr_lua_util_set_mctx(module_ctx_t const *mctx); +module_ctx_t const *fr_lua_util_get_mctx(void); void fr_lua_util_set_request(request_t *request); request_t *fr_lua_util_get_request(void); void fr_lua_util_fr_register(lua_State *L); diff --git a/src/modules/rlm_lua/rlm_lua.c b/src/modules/rlm_lua/rlm_lua.c index 0476921887..3502a07c85 100644 --- a/src/modules/rlm_lua/rlm_lua.c +++ b/src/modules/rlm_lua/rlm_lua.c @@ -25,7 +25,7 @@ */ RCSID("$Id$") -#define LOG_PREFIX inst->name +#define LOG_PREFIX mctx->inst->name #include #include @@ -73,34 +73,30 @@ DO_LUA(post_auth) /** Free any thread specific interpreters * */ -static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread) +static int mod_thread_detach(module_thread_inst_ctx_t const *mctx) { - rlm_lua_thread_t *this_thread = thread; + rlm_lua_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_lua_thread_t); /* * May be NULL if fr_lua_init failed */ - if (this_thread->interpreter) lua_close(this_thread->interpreter); + if (t->interpreter) lua_close(t->interpreter); return 0; } /** Create thread-specific connections and buffers * - * @param[in] conf section containing the configuration of this module instance. - * @param[in] instance of rlm_lua_t. - * @param[in] el The event list serviced by this thread. - * @param[in] thread specific data (where we write the interpreter). + * @param[in] mctx specific data (where we write the interpreter). * @return * - 0 on success. * - -1 on failure. */ -static int mod_thread_instantiate(UNUSED CONF_SECTION const *conf, void *instance, - UNUSED fr_event_list_t *el, void *thread) +static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx) { - rlm_lua_thread_t *this_thread = thread; + rlm_lua_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_lua_thread_t); - if (fr_lua_init(&this_thread->interpreter, instance) < 0) return -1; + if (fr_lua_init(&t->interpreter, (module_inst_ctx_t const *)mctx) < 0) return -1; return 0; } @@ -108,9 +104,9 @@ static int mod_thread_instantiate(UNUSED CONF_SECTION const *conf, void *instanc /** Close the global interpreter * */ -static int mod_detach(void *instance) +static int mod_detach(module_detach_ctx_t const *mctx) { - rlm_lua_t *inst = instance; + rlm_lua_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_lua_t); rlm_rcode_t ret = 0; /* @@ -119,7 +115,7 @@ static int mod_detach(void *instance) if (inst->interpreter) { if (inst->func_detach) { fr_lua_run(&ret, &(module_ctx_t){ - .inst = dl_module_instance_by_data(instance), + .inst = mctx->inst, .thread = &(rlm_lua_thread_t){ .interpreter = inst->interpreter } @@ -132,18 +128,15 @@ static int mod_detach(void *instance) return ret; } -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_lua_t *inst = instance; + rlm_lua_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_lua_t); rlm_rcode_t rcode; - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - /* * Get an instance global interpreter to use with various things... */ - if (fr_lua_init(&inst->interpreter, inst) < 0) return -1; + if (fr_lua_init(&inst->interpreter, mctx) < 0) return -1; inst->jit = fr_lua_isjit(inst->interpreter); if (!inst->jit) WARN("Using standard Lua interpreter, performance will be suboptimal"); @@ -151,11 +144,11 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) if (inst->func_instantiate) { fr_lua_run(&rcode, &(module_ctx_t){ - .inst = dl_module_instance_by_data(instance), - .thread = &(rlm_lua_thread_t){ - .interpreter = inst->interpreter - } - }, + .inst = mctx->inst, + .thread = &(rlm_lua_thread_t){ + .interpreter = inst->interpreter + } + }, NULL, inst->func_instantiate); } diff --git a/src/modules/rlm_lua/util.c b/src/modules/rlm_lua/util.c index 6f5842b996..e9b3589b88 100644 --- a/src/modules/rlm_lua/util.c +++ b/src/modules/rlm_lua/util.c @@ -24,7 +24,7 @@ */ RCSID("$Id$") -#define LOG_PREFIX inst->name +#define LOG_PREFIX fr_lua_mctx->inst->name #include @@ -35,7 +35,7 @@ RCSID("$Id$") #include static _Thread_local request_t *fr_lua_request; -static _Thread_local rlm_lua_t const *fr_lua_inst; +static _Thread_local module_ctx_t const *fr_lua_mctx; void fr_lua_util_fr_register(lua_State *L) { @@ -54,8 +54,7 @@ void fr_lua_util_fr_register(lua_State *L) */ static int _util_log_debug(lua_State *L) { - rlm_lua_t const *inst = fr_lua_inst; - request_t *request = fr_lua_request; + request_t *request = fr_lua_request; int idx; while ((idx = lua_gettop(L))) { @@ -78,8 +77,7 @@ static int _util_log_debug(lua_State *L) */ static int _util_log_info(lua_State *L) { - rlm_lua_t const *inst = fr_lua_inst; - request_t *request = fr_lua_request; + request_t *request = fr_lua_request; int idx; while ((idx = lua_gettop(L))) { @@ -103,8 +101,7 @@ static int _util_log_info(lua_State *L) */ static int _util_log_warn(lua_State *L) { - rlm_lua_t const *inst = fr_lua_inst; - request_t *request = fr_lua_request; + request_t *request = fr_lua_request; int idx; while ((idx = lua_gettop(L))) { @@ -127,8 +124,7 @@ static int _util_log_warn(lua_State *L) */ static int _util_log_error(lua_State *L) { - rlm_lua_t const *inst = fr_lua_inst; - request_t *request = fr_lua_request; + request_t *request = fr_lua_request; int idx; while ((idx = lua_gettop(L))) { @@ -157,8 +153,7 @@ static int _util_log_newindex(UNUSED lua_State *L) */ void fr_lua_util_jit_log_debug(char const *msg) { - rlm_lua_t const *inst = fr_lua_inst; - request_t *request = fr_lua_request; + request_t *request = fr_lua_request; ROPTIONAL(RDEBUG2, DEBUG2, "%s", msg); } @@ -169,8 +164,7 @@ void fr_lua_util_jit_log_debug(char const *msg) */ void fr_lua_util_jit_log_info(char const *msg) { - rlm_lua_t const *inst = fr_lua_inst; - request_t *request = fr_lua_request; + request_t *request = fr_lua_request; ROPTIONAL(RINFO, INFO, "%s", msg); } @@ -181,8 +175,7 @@ void fr_lua_util_jit_log_info(char const *msg) */ void fr_lua_util_jit_log_warn(char const *msg) { - rlm_lua_t const *inst = fr_lua_inst; - request_t *request = fr_lua_request; + request_t *request = fr_lua_request; ROPTIONAL(RWARN, WARN, "%s", msg); } @@ -193,8 +186,7 @@ void fr_lua_util_jit_log_warn(char const *msg) */ void fr_lua_util_jit_log_error(char const *msg) { - rlm_lua_t const *inst = fr_lua_inst; - request_t *request = fr_lua_request; + request_t *request = fr_lua_request; ROPTIONAL(RERROR, ERROR, "%s", msg); } @@ -204,16 +196,17 @@ void fr_lua_util_jit_log_error(char const *msg) * For LuaJIT using the FFI is significantly faster than the Lua interface. * Help people wishing to use the FFI by inserting cdefs for standard functions. * - * @param inst Current instance of the fr_lua module. * @param L Lua interpreter. * @return 0 (no arguments). */ -int fr_lua_util_jit_log_register(rlm_lua_t const *inst, lua_State *L) +int fr_lua_util_jit_log_register(lua_State *L) { char const *search_path; char *lua_str; int ret; + fr_assert(fr_lua_mctx); + search_path = dl_module_search_path(); lua_str = talloc_asprintf(NULL, "\ ffi = require(\"ffi\")\ @@ -262,11 +255,10 @@ int fr_lua_util_jit_log_register(rlm_lua_t const *inst, lua_State *L) /** Register utililiary functions in the lua environment * - * @param inst Current instance of the fr_lua module. * @param L Lua interpreter. * @return 0 (no arguments). */ -int fr_lua_util_log_register(UNUSED rlm_lua_t const *inst, lua_State *L) +int fr_lua_util_log_register(lua_State *L) { /* fr.{} */ lua_getglobal(L, "fr"); @@ -305,20 +297,20 @@ int fr_lua_util_log_register(UNUSED rlm_lua_t const *inst, lua_State *L) /** Set the thread local instance * - * @param[in] inst all helper and C functions callable from Lua should use. + * @param[in] mctx all helper and C functions callable from Lua should use. */ -void fr_lua_util_set_inst(rlm_lua_t const *inst) +void fr_lua_util_set_mctx(module_ctx_t const *mctx) { - fr_lua_inst = inst; + fr_lua_mctx = mctx; } /** Get the thread local instance * - * @return inst all helper and C functions callable from Lua should use. + * @return mctx all helper and C functions callable from Lua should use. */ -rlm_lua_t const *fr_lua_util_get_inst(void) +module_ctx_t const *fr_lua_util_get_mctx(void) { - return fr_lua_inst; + return fr_lua_mctx; } /** Set the thread local request diff --git a/src/modules/rlm_mruby/rlm_mruby.c b/src/modules/rlm_mruby/rlm_mruby.c index 102ed0bd31..c7d5b1b02e 100644 --- a/src/modules/rlm_mruby/rlm_mruby.c +++ b/src/modules/rlm_mruby/rlm_mruby.c @@ -129,9 +129,9 @@ static void mruby_parse_config(mrb_state *mrb, CONF_SECTION *cs, int lvl, mrb_va * to external databases, read configuration files, set up * dictionary entries, etc. */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_mruby_t *inst = instance; + rlm_mruby_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_mruby_t); mrb_state *mrb; CONF_SECTION *cs; FILE *f; @@ -489,7 +489,7 @@ RLM_MRUBY_FUNC(accounting) */ static int mod_detach(void *instance) { - rlm_mruby_t *inst = instance; + rlm_mruby_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_mruby_t); mrb_close(inst->mrb); diff --git a/src/modules/rlm_mschap/rlm_mschap.c b/src/modules/rlm_mschap/rlm_mschap.c index 26995b0b38..d965d94b9a 100644 --- a/src/modules/rlm_mschap/rlm_mschap.c +++ b/src/modules/rlm_mschap/rlm_mschap.c @@ -25,7 +25,7 @@ /* MPPE support from Takahiro Wagatsuma */ RCSID("$Id$") -#define LOG_PREFIX inst->name +#define LOG_PREFIX mctx->inst->name #include #include @@ -722,8 +722,8 @@ 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; - rlm_mschap_t const *inst = talloc_get_type_abort_const(instance, rlm_mschap_t); + struct wbcContext **wb_ctx; + module_inst_ctx_t *mctx = &(module_inst_ctx_t){ .inst = dl_module_instance_by_data(instance) }; wb_ctx = talloc_zero(ctx, struct wbcContext *); *wb_ctx = wbcCtxCreate(); @@ -1457,7 +1457,7 @@ static unlang_action_t CC_HINT(nonnull) mod_authorize(rlm_rcode_t *p_result, mod if (!inst->auth_type) { WARN("No 'authenticate %s {...}' section or 'Auth-Type = %s' set. Cannot setup MS-CHAP authentication", - inst->name, inst->name); + mctx->inst->name, mctx->inst->name); RETURN_MODULE_NOOP; } @@ -2104,7 +2104,7 @@ static unlang_action_t CC_HINT(nonnull) mod_authenticate(rlm_rcode_t *p_result, challenge = fr_pair_find_by_da_idx(&request->request_pairs, attr_ms_chap_challenge, 0); if (!challenge) { REDEBUG("&control.Auth-Type = %s set for a request that does not contain &%s", - inst->name, attr_ms_chap_challenge->name); + mctx->inst->name, attr_ms_chap_challenge->name); rcode = RLM_MODULE_INVALID; goto finish; } @@ -2130,7 +2130,7 @@ static unlang_action_t CC_HINT(nonnull) mod_authenticate(rlm_rcode_t *p_result, if (rcode != RLM_MODULE_OK) goto finish; } else { /* Neither CHAPv1 or CHAPv2 response: die */ REDEBUG("&control.Auth-Type = %s set for a request that does not contain &%s or &%s attributes", - inst->name, attr_ms_chap_response->name, attr_ms_chap2_response->name); + mctx->inst->name, attr_ms_chap_response->name, attr_ms_chap2_response->name); rcode = RLM_MODULE_INVALID; goto finish; } @@ -2192,14 +2192,15 @@ finish: * Create instance for our module. Allocate space for * instance structure and read configuration parameters */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_mschap_t *inst = instance; + rlm_mschap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_mschap_t); + CONF_SECTION *conf = mctx->inst->conf; - inst->auth_type = fr_dict_enum_by_name(attr_auth_type, inst->name, -1); + inst->auth_type = fr_dict_enum_by_name(attr_auth_type, mctx->inst->name, -1); if (!inst->auth_type) { WARN("Failed to find 'authenticate %s {...}' section. MS-CHAP authentication will likely not work", - inst->name); + mctx->inst->name); } /* @@ -2261,15 +2262,12 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) return 0; } -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - rlm_mschap_t *inst = instance; + rlm_mschap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_mschap_t); xlat_t *xlat; - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - - xlat = xlat_register(inst, inst->name, mschap_xlat, false); + xlat = xlat_register(inst, mctx->inst->name, mschap_xlat, false); xlat_func_args(xlat, mschap_xlat_args); xlat_async_instantiate_set(xlat, mod_xlat_instantiate, rlm_mschap_t *, NULL, inst); @@ -2283,10 +2281,10 @@ static int mod_detach( #ifndef WITH_AUTH_WINBIND UNUSED #endif - void *instance) + module_detach_ctx_t const *mctx) { #ifdef WITH_AUTH_WINBIND - rlm_mschap_t *inst = instance; + rlm_mschap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_mschap_t); fr_pool_free(inst->wb_pool); #endif diff --git a/src/modules/rlm_mschap/rlm_mschap.h b/src/modules/rlm_mschap/rlm_mschap.h index 473a7da915..f437e9292b 100644 --- a/src/modules/rlm_mschap/rlm_mschap.h +++ b/src/modules/rlm_mschap/rlm_mschap.h @@ -50,8 +50,7 @@ extern HIDDEN fr_dict_attr_t const *attr_ms_mppe_encryption_types; extern HIDDEN fr_dict_attr_t const *attr_ms_chap2_cpw; typedef struct { - char const *name; - fr_dict_enum_value_t *auth_type; + fr_dict_enum_value_t *auth_type; bool normify; diff --git a/src/modules/rlm_opendirectory/rlm_opendirectory.c b/src/modules/rlm_opendirectory/rlm_opendirectory.c index a27f920f6b..6363df10a6 100644 --- a/src/modules/rlm_opendirectory/rlm_opendirectory.c +++ b/src/modules/rlm_opendirectory/rlm_opendirectory.c @@ -46,7 +46,6 @@ USES_APPLE_DEPRECATED_API #include typedef struct { - char const *name; //!< Auth-Type value for this module instance. fr_dict_enum_value_t *auth_type; } rlm_opendirectory_t; @@ -506,7 +505,7 @@ static unlang_action_t CC_HINT(nonnull) mod_authorize(rlm_rcode_t *p_result, mod setup_auth_type: if (!inst->auth_type) { WARN("No 'authenticate %s {...}' section or 'Auth-Type = %s' set. Cannot setup OpenDirectory authentication", - inst->name, inst->name); + mctx->inst->name, mctx->inst->name); RETURN_MODULE_NOOP; } @@ -515,24 +514,14 @@ setup_auth_type: RETURN_MODULE_OK; } -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_opendirectory_t *inst = instance; + rlm_opendirectory_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_opendirectory_t); - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - - return 0; -} - -static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf) -{ - rlm_opendirectory_t *inst = instance; - - inst->auth_type = fr_dict_enum_by_name(attr_auth_type, inst->name, -1); + inst->auth_type = fr_dict_enum_by_name(attr_auth_type, mctx->inst->name, -1); if (!inst->auth_type) { WARN("Failed to find 'authenticate %s {...}' section. OpenDirectory authentication will likely not work", - inst->name); + mctx->inst->name); } return 0; @@ -545,7 +534,6 @@ module_t rlm_opendirectory = { .name = "opendirectory", .inst_size = sizeof(rlm_opendirectory_t), .type = RLM_TYPE_THREAD_SAFE, - .bootstrap = mod_bootstrap, .instantiate = mod_instantiate, .methods = { [MOD_AUTHENTICATE] = mod_authenticate, diff --git a/src/modules/rlm_pam/rlm_pam.c b/src/modules/rlm_pam/rlm_pam.c index e38577fdf4..ad13dff3a3 100644 --- a/src/modules/rlm_pam/rlm_pam.c +++ b/src/modules/rlm_pam/rlm_pam.c @@ -85,9 +85,9 @@ fr_dict_attr_autoload_t rlm_pam_dict_attr[] = { { NULL } }; -static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_pam_t *inst = instance; + rlm_pam_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_pam_t); if (!inst->pam_auth_name) inst->pam_auth_name = main_config->name; diff --git a/src/modules/rlm_pap/rlm_pap.c b/src/modules/rlm_pap/rlm_pap.c index 403e2e275e..a89d489612 100644 --- a/src/modules/rlm_pap/rlm_pap.c +++ b/src/modules/rlm_pap/rlm_pap.c @@ -68,8 +68,7 @@ static pthread_mutex_t fr_crypt_mutex = PTHREAD_MUTEX_INITIALIZER; * be used as the instance handle. */ typedef struct { - char const *name; - fr_dict_enum_value_t *auth_type; + fr_dict_enum_value_t *auth_type; bool normify; } rlm_pap_t; @@ -141,7 +140,7 @@ static unlang_action_t CC_HINT(nonnull) mod_authorize(rlm_rcode_t *p_result, mod fr_pair_t *password; if (fr_pair_find_by_da_idx(&request->control_pairs, attr_auth_type, 0) != NULL) { - RDEBUG3("Auth-Type is already set. Not setting 'Auth-Type := %s'", inst->name); + RDEBUG3("Auth-Type is already set. Not setting 'Auth-Type := %s'", mctx->inst->name); RETURN_MODULE_NOOP; } @@ -153,7 +152,7 @@ static unlang_action_t CC_HINT(nonnull) mod_authorize(rlm_rcode_t *p_result, mod if (!inst->auth_type) { WARN("No 'authenticate %s {...}' section or 'Auth-Type = %s' set. Cannot setup PAP authentication.", - inst->name, inst->name); + mctx->inst->name, mctx->inst->name); RETURN_MODULE_NOOP; } @@ -993,29 +992,14 @@ static unlang_action_t CC_HINT(nonnull) mod_authenticate(rlm_rcode_t *p_result, RETURN_MODULE_RCODE(rcode); } -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - char const *name; - rlm_pap_t *inst = instance; + rlm_pap_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_pap_t); - /* - * Create the dynamic translation. - */ - name = cf_section_name2(conf); - if (!name) name = cf_section_name1(conf); - inst->name = name; - - return 0; -} - -static int mod_instantiate(void *instance, UNUSED CONF_SECTION *cs) -{ - rlm_pap_t *inst = talloc_get_type_abort(instance, rlm_pap_t); - - inst->auth_type = fr_dict_enum_by_name(attr_auth_type, inst->name, -1); + inst->auth_type = fr_dict_enum_by_name(attr_auth_type, mctx->inst->name, -1); if (!inst->auth_type) { WARN("Failed to find 'authenticate %s {...}' section. PAP will likely not work", - inst->name); + mctx->inst->name); } return 0; @@ -1094,7 +1078,6 @@ module_t rlm_pap = { .onload = mod_load, .unload = mod_unload, .config = module_config, - .bootstrap = mod_bootstrap, .instantiate = mod_instantiate, .methods = { [MOD_AUTHENTICATE] = mod_authenticate, diff --git a/src/modules/rlm_passwd/rlm_passwd.c b/src/modules/rlm_passwd/rlm_passwd.c index c3cf63ee49..5625a54f4c 100644 --- a/src/modules/rlm_passwd/rlm_passwd.c +++ b/src/modules/rlm_passwd/rlm_passwd.c @@ -387,7 +387,7 @@ static const CONF_PARSER module_config[] = { CONF_PARSER_TERMINATOR }; -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { int num_fields = 0, key_field = -1, listable = 0; char const *s; @@ -395,7 +395,8 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) size_t len; int i; fr_dict_attr_t const *da; - rlm_passwd_t *inst = instance; + rlm_passwd_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_passwd_t); + CONF_SECTION *conf = mctx->inst->conf; fr_assert(inst->filename && *inst->filename); fr_assert(inst->format && *inst->format); @@ -501,15 +502,15 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) #undef inst } -static int mod_detach (void *instance) { -#define inst ((rlm_passwd_t *)instance) - if(inst->ht) { +static int mod_detach(module_detach_ctx_t const *mctx) +{ + rlm_passwd_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_passwd_t); + if (inst->ht) { release_ht(inst->ht); inst->ht = NULL; } talloc_free(inst->pwd_fmt); return 0; -#undef inst } static void result_add(TALLOC_CTX *ctx, rlm_passwd_t const *inst, request_t *request, diff --git a/src/modules/rlm_perl/rlm_perl.c b/src/modules/rlm_perl/rlm_perl.c index a4a372ec84..507afdc2ef 100644 --- a/src/modules/rlm_perl/rlm_perl.c +++ b/src/modules/rlm_perl/rlm_perl.c @@ -60,8 +60,6 @@ extern char **environ; * be used as the instance handle. */ typedef struct { - char const *name; - /* Name of the perl module */ char const *module; @@ -636,15 +634,12 @@ static void perl_parse_config(CONF_SECTION *cs, int lvl, HV *rad_hv) DEBUG("%*s}", indent_section, " "); } -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - rlm_perl_t *inst = instance; + rlm_perl_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_perl_t); xlat_t *xlat; - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - - xlat = xlat_register(NULL, inst->name, perl_xlat, false); + xlat = xlat_register(NULL, mctx->inst->name, perl_xlat, false); xlat_func_args(xlat, perl_xlat_args); xlat_async_instantiate_set(xlat, mod_xlat_instantiate, rlm_perl_xlat_t, NULL, inst); @@ -848,11 +843,11 @@ static int get_hv_content(TALLOC_CTX *ctx, request_t *request, HV *my_hv, fr_pai * Store all vps in hashes %RAD_CONFIG %RAD_REPLY %RAD_REQUEST * */ -static unlang_action_t do_perl(rlm_rcode_t *p_result, void *instance, request_t *request, +static unlang_action_t do_perl(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request, PerlInterpreter *interp, char const *function_name) { - rlm_perl_t *inst = instance; + rlm_perl_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_perl_t); fr_pair_list_t vps; int ret=0, count; STRLEN n_a; @@ -958,7 +953,7 @@ static unlang_action_t do_perl(rlm_rcode_t *p_result, void *instance, request_t static unlang_action_t CC_HINT(nonnull) mod_##_x(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request) \ { \ rlm_perl_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_perl_t); \ - return do_perl(p_result, inst, request, \ + return do_perl(p_result, mctx, request, \ ((rlm_perl_thread_t *)talloc_get_type_abort(mctx->thread, rlm_perl_thread_t))->perl, \ inst->func_##_x); \ } @@ -1008,7 +1003,7 @@ static unlang_action_t CC_HINT(nonnull) mod_accounting(rlm_rcode_t *p_result, mo break; } - return do_perl(p_result, inst, request, + return do_perl(p_result, mctx, request, ((rlm_perl_thread_t *)talloc_get_type_abort(mctx->thread, rlm_perl_thread_t))->perl, func); } @@ -1042,11 +1037,10 @@ static void rlm_perl_interp_free(PerlInterpreter *perl) DIAG_ON(shadow) DIAG_ON(DIAG_UNKNOWN_PRAGMAS) -static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, - UNUSED fr_event_list_t *el, void *thread) +static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx) { - rlm_perl_t *inst = talloc_get_type_abort(instance, rlm_perl_t); - rlm_perl_thread_t *t = talloc_get_type_abort(thread, rlm_perl_thread_t); + rlm_perl_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_perl_t); + rlm_perl_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_perl_thread_t); PerlInterpreter *interp; UV clone_flags = 0; @@ -1070,9 +1064,9 @@ static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, return 0; } -static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread) +static int mod_thread_detach(module_thread_inst_ctx_t const *mctx) { - rlm_perl_thread_t *t = talloc_get_type_abort(thread, rlm_perl_thread_t); + rlm_perl_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_perl_thread_t); rlm_perl_interp_free(t->perl); @@ -1093,9 +1087,10 @@ static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread) * parse a module and give it a chance to live * */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_perl_t *inst = instance; + rlm_perl_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_perl_t); + CONF_SECTION *conf = mctx->inst->conf; AV *end_AV; char const **embed_c; /* Stupid Perl and lack of const consistency */ @@ -1170,9 +1165,9 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) * Detach a instance give a chance to a module to make some internal setup ... */ DIAG_OFF(nested-externs) -static int mod_detach(void *instance) +static int mod_detach(module_detach_ctx_t const *mctx) { - rlm_perl_t *inst = (rlm_perl_t *) instance; + rlm_perl_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_perl_t); int ret = 0, count = 0; diff --git a/src/modules/rlm_python/rlm_python.c b/src/modules/rlm_python/rlm_python.c index 9e5de17e36..fd0d29fafb 100644 --- a/src/modules/rlm_python/rlm_python.c +++ b/src/modules/rlm_python/rlm_python.c @@ -27,7 +27,7 @@ */ RCSID("$Id$") -#define LOG_PREFIX inst->name +#define LOG_PREFIX mctx->inst->name #include #include @@ -86,12 +86,12 @@ typedef struct { PyThreadState *state; //!< Module instance/thread specific state. } rlm_python_thread_t; -static void *python_dlhandle; -static PyThreadState *global_interpreter; //!< Our first interpreter. +static void *python_dlhandle; +static PyThreadState *global_interpreter; //!< Our first interpreter. -static rlm_python_t *current_inst; //!< Used for communication with inittab functions. -static CONF_SECTION *current_conf; //!< Used for communication with inittab functions. -static char *default_path; //!< The default python path. +static module_ctx_t const *current_mctx; //!< Used for communication with inittab functions. +static CONF_SECTION *current_conf; //!< Used for communication with inittab functions. +static char *default_path; //!< The default python path. /* * As of Python 3.8 the GIL will be per-interpreter @@ -202,7 +202,7 @@ static PyMethodDef module_methods[] = { * * Must be called with a valid thread state set */ -static void python_error_log(const rlm_python_t *inst, request_t *request) +static void python_error_log(module_ctx_t const *mctx, request_t *request) { PyObject *p_type = NULL, *p_value = NULL, *p_traceback = NULL, *p_str_1 = NULL, *p_str_2 = NULL; @@ -241,14 +241,14 @@ failed: Py_XDECREF(p_traceback); } -static void mod_vptuple(TALLOC_CTX *ctx, rlm_python_t const *inst, request_t *request, +static void mod_vptuple(TALLOC_CTX *ctx, module_ctx_t const *mctx, request_t *request, fr_pair_list_t *vps, PyObject *p_value, char const *funcname, char const *list_name) { int i; Py_ssize_t tuple_len; - tmpl_t *dst; + tmpl_t *dst; fr_pair_t *vp; - request_t *current = request; + request_t *current = request; fr_pair_list_t tmp_list; fr_pair_list_init(&tmp_list); @@ -361,7 +361,7 @@ static void mod_vptuple(TALLOC_CTX *ctx, rlm_python_t const *inst, request_t *re * This is the core Python function that the others wrap around. * Pass the value-pair print strings in a tuple. */ -static int mod_populate_vptuple(rlm_python_t const *inst, request_t *request, PyObject *pp, fr_pair_t *vp) +static int mod_populate_vptuple(module_ctx_t const *mctx, request_t *request, PyObject *pp, fr_pair_t *vp) { PyObject *attribute = NULL; PyObject *value = NULL; @@ -444,7 +444,7 @@ static int mod_populate_vptuple(rlm_python_t const *inst, request_t *request, Py if (slen < 0) { error: ROPTIONAL(REDEBUG, ERROR, "Failed marshalling %pP to Python value", vp); - python_error_log(inst, request); + python_error_log(mctx, request); Py_XDECREF(attribute); return -1; } @@ -465,8 +465,8 @@ static int mod_populate_vptuple(rlm_python_t const *inst, request_t *request, Py return 0; } -static unlang_action_t do_python_single(rlm_rcode_t *p_result, - rlm_python_t const *inst, request_t *request, PyObject *p_func, char const *funcname) +static unlang_action_t do_python_single(rlm_rcode_t *p_result, module_ctx_t const *mctx, + request_t *request, PyObject *p_func, char const *funcname) { fr_pair_t *vp; PyObject *p_ret = NULL; @@ -508,7 +508,7 @@ static unlang_action_t do_python_single(rlm_rcode_t *p_result, goto finish; } - if (mod_populate_vptuple(inst, request, pp, vp) == 0) { + if (mod_populate_vptuple(mctx, request, pp, vp) == 0) { /* Put the tuple inside the container */ PyTuple_SET_ITEM(p_arg, i, pp); } else { @@ -522,7 +522,7 @@ static unlang_action_t do_python_single(rlm_rcode_t *p_result, /* Call Python function. */ p_ret = PyObject_CallFunctionObjArgs(p_func, p_arg, NULL); if (!p_ret) { - python_error_log(inst, request); /* Needs valid thread with GIL */ + python_error_log(mctx, request); /* Needs valid thread with GIL */ rcode = RLM_MODULE_FAIL; goto finish; } @@ -564,10 +564,10 @@ static unlang_action_t do_python_single(rlm_rcode_t *p_result, /* Now have the return value */ rcode = PyLong_AsLong(p_tuple_int); /* Reply item tuple */ - mod_vptuple(request->reply_ctx, inst, request, &request->reply_pairs, + mod_vptuple(request->reply_ctx, mctx, request, &request->reply_pairs, PyTuple_GET_ITEM(p_ret, 1), funcname, "reply"); /* Config item tuple */ - mod_vptuple(request->control_ctx, inst, request, &request->control_pairs, + mod_vptuple(request->control_ctx, mctx, request, &request->control_pairs, PyTuple_GET_ITEM(p_ret, 2), funcname, "config"); } else if (PyNumber_Check(p_ret)) { @@ -585,7 +585,7 @@ static unlang_action_t do_python_single(rlm_rcode_t *p_result, } finish: - if (rcode == RLM_MODULE_FAIL) python_error_log(inst, request); + if (rcode == RLM_MODULE_FAIL) python_error_log(mctx, request); Py_XDECREF(p_arg); Py_XDECREF(p_ret); @@ -596,9 +596,10 @@ finish: * * Will swap in thread state specific to module/thread. */ -static unlang_action_t do_python(rlm_rcode_t *p_result, rlm_python_t const *inst, rlm_python_thread_t *this_thread, - request_t *request, PyObject *p_func, char const *funcname) +static unlang_action_t do_python(rlm_rcode_t *p_result, module_ctx_t const *mctx, + request_t *request, PyObject *p_func, char const *funcname) { + rlm_python_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_python_thread_t); rlm_rcode_t rcode; /* @@ -606,11 +607,11 @@ static unlang_action_t do_python(rlm_rcode_t *p_result, rlm_python_t const *inst */ if (!p_func) RETURN_MODULE_NOOP; - RDEBUG3("Using thread state %p/%p", inst, this_thread->state); + RDEBUG3("Using thread state %p/%p", mctx->inst->data, t->state); - PyEval_RestoreThread(this_thread->state); /* Swap in our local thread state */ - do_python_single(&rcode, inst, request, p_func, funcname); - (void)fr_cond_assert(PyEval_SaveThread() == this_thread->state); + PyEval_RestoreThread(t->state); /* Swap in our local thread state */ + do_python_single(&rcode, mctx, request, p_func, funcname); + (void)fr_cond_assert(PyEval_SaveThread() == t->state); RETURN_MODULE_RCODE(rcode); } @@ -619,8 +620,7 @@ static unlang_action_t do_python(rlm_rcode_t *p_result, rlm_python_t const *inst static unlang_action_t CC_HINT(nonnull) mod_##x(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request) \ { \ rlm_python_t const *inst = talloc_get_type_abort_const(mctx->inst->data, rlm_python_t); \ - rlm_python_thread_t *thread = talloc_get_type_abort(mctx->thread, rlm_python_thread_t); \ - return do_python(p_result, inst, thread, request, inst->x.function, #x);\ + return do_python(p_result, mctx, request, inst->x.function, #x);\ } MOD_FUNC(authenticate) @@ -646,7 +646,7 @@ static void python_function_destroy(python_func_def_t *def) /** Import a user module and load a function from it * */ -static int python_function_load(rlm_python_t *inst, python_func_def_t *def) +static int python_function_load(module_inst_ctx_t const *mctx, python_func_def_t *def) { char const *funcname = "python_function_load"; @@ -656,7 +656,7 @@ static int python_function_load(rlm_python_t *inst, python_func_def_t *def) if (!def->module) { ERROR("%s - Module '%s' load failed", funcname, def->module_name); error: - python_error_log(inst, NULL); + python_error_log(&(module_ctx_t){ .inst = mctx->inst }, NULL); Py_XDECREF(def->function); def->function = NULL; Py_XDECREF(def->module); @@ -683,7 +683,7 @@ static int python_function_load(rlm_python_t *inst, python_func_def_t *def) * Parse a configuration section, and populate a dict. * This function is recursively called (allows to have nested dicts.) */ -static int python_parse_config(rlm_python_t *inst, CONF_SECTION *cs, int lvl, PyObject *dict) +static int python_parse_config(module_inst_ctx_t const *mctx, CONF_SECTION *cs, int lvl, PyObject *dict) { int indent_section = (lvl * 4); int indent_item = (lvl + 1) * 4; @@ -719,7 +719,7 @@ static int python_parse_config(rlm_python_t *inst, CONF_SECTION *cs, int lvl, Py MEM(sub_dict = PyDict_New()); (void)PyDict_SetItem(dict, p_key, sub_dict); - ret = python_parse_config(inst, sub_cs, lvl + 1, sub_dict); + ret = python_parse_config(mctx, sub_cs, lvl + 1, sub_dict); if (ret < 0) break; } else if (cf_item_is_pair(ci)) { CONF_PAIR *cp = cf_item_to_pair(ci); @@ -766,8 +766,9 @@ static int python_parse_config(rlm_python_t *inst, CONF_SECTION *cs, int lvl, Py /** Make the current instance's config available within the module we're initialising * */ -static int python_module_import_config(rlm_python_t *inst, CONF_SECTION *conf, PyObject *module) +static int python_module_import_config(module_inst_ctx_t const *mctx, CONF_SECTION *conf, PyObject *module) { + rlm_python_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_python_t); CONF_SECTION *cs; /* @@ -780,14 +781,14 @@ static int python_module_import_config(rlm_python_t *inst, CONF_SECTION *conf, P error: Py_XDECREF(inst->pythonconf_dict); inst->pythonconf_dict = NULL; - python_error_log(inst, NULL); + python_error_log(&(module_ctx_t){ .inst = mctx->inst }, NULL); return -1; } cs = cf_section_find(conf, "config", NULL); if (cs) { DEBUG("Inserting \"config\" section into python environment as radiusd.config"); - if (python_parse_config(inst, cs, 0, inst->pythonconf_dict) < 0) goto error; + if (python_parse_config(mctx, cs, 0, inst->pythonconf_dict) < 0) goto error; } /* @@ -801,14 +802,14 @@ static int python_module_import_config(rlm_python_t *inst, CONF_SECTION *conf, P /** Import integer constants into the module we're initialising * */ -static int python_module_import_constants(rlm_python_t *inst, PyObject *module) +static int python_module_import_constants(module_inst_ctx_t const *mctx, PyObject *module) { size_t i; 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(inst, NULL); + python_error_log(&(module_ctx_t){ .inst = mctx->inst }, NULL); return -1; } } @@ -842,8 +843,7 @@ static char *python_path_build(TALLOC_CTX *ctx, rlm_python_t *inst, CONF_SECTION */ static PyObject *python_module_init(void) { - rlm_python_t *inst = current_inst; - PyObject *module; + PyObject *module; static struct PyModuleDef py_module_def = { PyModuleDef_HEAD_INIT, @@ -853,19 +853,21 @@ static PyObject *python_module_init(void) .m_methods = module_methods }; - fr_assert(inst); + fr_assert(current_mctx); module = PyModule_Create(&py_module_def); if (!module) { - python_error_log(inst, NULL); + python_error_log(current_mctx, NULL); Py_RETURN_NONE; } return module; } -static int python_interpreter_init(rlm_python_t *inst, CONF_SECTION *conf) +static int python_interpreter_init(module_inst_ctx_t const *mctx) { + rlm_python_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_python_t); + CONF_SECTION *conf = mctx->inst->conf; char *path; PyObject *module; wchar_t *wide_path; @@ -876,7 +878,7 @@ static int python_interpreter_init(rlm_python_t *inst, CONF_SECTION *conf) * called during interpreter initialisation * it can get at the current instance config. */ - current_inst = inst; + current_mctx = &(module_ctx_t){ .inst = mctx->inst }; current_conf = conf; PyEval_RestoreThread(global_interpreter); @@ -908,8 +910,8 @@ static int python_interpreter_init(rlm_python_t *inst, CONF_SECTION *conf) ERROR("Failed importing \"freeradius\" module into interpreter %p", inst->interpreter); return -1; } - if ((python_module_import_config(inst, conf, module) < 0) || - (python_module_import_constants(inst, module) < 0)) { + if ((python_module_import_config(mctx, conf, module) < 0) || + (python_module_import_constants(mctx, module) < 0)) { Py_DECREF(module); return -1; } @@ -944,14 +946,11 @@ static void python_interpreter_free(rlm_python_t *inst, PyThreadState *interp) * in *instance otherwise put a null pointer there. * */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_python_t *inst = instance; - - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); + rlm_python_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_python_t); - if (python_interpreter_init(inst, conf) < 0) return -1; + if (python_interpreter_init(mctx) < 0) return -1; /* * Switch to our module specific interpreter @@ -961,7 +960,7 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) /* * Process the various sections */ -#define PYTHON_FUNC_LOAD(_x) if (python_function_load(inst, &inst->_x) < 0) goto error +#define PYTHON_FUNC_LOAD(_x) if (python_function_load(mctx, &inst->_x) < 0) goto error PYTHON_FUNC_LOAD(instantiate); PYTHON_FUNC_LOAD(authenticate); PYTHON_FUNC_LOAD(authorize); @@ -976,7 +975,7 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) if (inst->instantiate.function) { rlm_rcode_t rcode; - do_python_single(&rcode, inst, NULL, inst->instantiate.function, "instantiate"); + do_python_single(&rcode, &(module_ctx_t){ .inst = mctx->inst }, NULL, inst->instantiate.function, "instantiate"); switch (rcode) { case RLM_MODULE_FAIL: case RLM_MODULE_REJECT: @@ -997,9 +996,9 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) return 0; } -static int mod_detach(void *instance) +static int mod_detach(module_detach_ctx_t const *mctx) { - rlm_python_t *inst = instance; + rlm_python_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_python_t); /* * If we don't have a interpreter @@ -1020,7 +1019,7 @@ static int mod_detach(void *instance) if (inst->detach.function) { rlm_rcode_t rcode; - (void)do_python_single(&rcode, inst, NULL, inst->detach.function, "detach"); + (void)do_python_single(&rcode, &(module_ctx_t){ .inst = mctx->inst }, NULL, inst->detach.function, "detach"); } #define PYTHON_FUNC_DESTROY(_x) python_function_destroy(&inst->_x) @@ -1043,12 +1042,11 @@ static int mod_detach(void *instance) return 0; } -static int mod_thread_instantiate(UNUSED CONF_SECTION const *conf, void *instance, - UNUSED fr_event_list_t *el, void *thread) +static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx) { PyThreadState *state; - rlm_python_t *inst = instance; - rlm_python_thread_t *this_thread = thread; + rlm_python_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_python_t); + rlm_python_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_python_thread_t); state = PyThreadState_New(inst->interpreter->interp); if (!state) { @@ -1057,20 +1055,20 @@ static int mod_thread_instantiate(UNUSED CONF_SECTION const *conf, void *instanc } DEBUG3("Initialised new thread state %p", state); - this_thread->state = state; + t->state = state; return 0; } -static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread) +static int mod_thread_detach(module_thread_inst_ctx_t const *mctx) { - rlm_python_thread_t *this_thread = thread; + rlm_python_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_python_thread_t); - PyEval_RestoreThread(this_thread->state); /* Swap in our local thread state */ - PyThreadState_Clear(this_thread->state); + PyEval_RestoreThread(t->state); /* Swap in our local thread state */ + PyThreadState_Clear(t->state); PyEval_SaveThread(); - PyThreadState_Delete(this_thread->state); /* Don't need to hold lock for this */ + PyThreadState_Delete(t->state); /* Don't need to hold lock for this */ return 0; } diff --git a/src/modules/rlm_radius/rlm_radius.c b/src/modules/rlm_radius/rlm_radius.c index d3b72ac861..ac0756c335 100644 --- a/src/modules/rlm_radius/rlm_radius.c +++ b/src/modules/rlm_radius/rlm_radius.c @@ -507,17 +507,21 @@ static unlang_action_t CC_HINT(nonnull) mod_process(rlm_rcode_t *p_result, modul /** Destroy thread data for the submodule. * */ -static int mod_thread_detach(fr_event_list_t *el, void *thread) +static int mod_thread_detach(module_thread_inst_ctx_t const *mctx) { - rlm_radius_thread_t *t = talloc_get_type_abort(thread, rlm_radius_thread_t); - rlm_radius_t const *inst = t->inst; + rlm_radius_t const *inst = talloc_get_type_abort(mctx->inst->data, rlm_radius_t); + rlm_radius_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_radius_thread_t); /* * Tell the submodule to shut down all of its * connections. */ if (inst->io->thread_detach && - (inst->io->thread_detach(el, t->io_thread) < 0)) { + (inst->io->thread_detach(&(module_thread_inst_ctx_t){ + .inst = inst->io_submodule, + .thread = t->io_thread, + .el = mctx->el + }) < 0)) { return -1; } @@ -527,12 +531,10 @@ static int mod_thread_detach(fr_event_list_t *el, void *thread) /** Instantiate thread data for the submodule. * */ -static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, fr_event_list_t *el, void *thread) +static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx) { - rlm_radius_t *inst = talloc_get_type_abort(instance, rlm_radius_t); - rlm_radius_thread_t *t = talloc_get_type_abort(thread, rlm_radius_thread_t); - - t->inst = instance; + rlm_radius_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_radius_t); + rlm_radius_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_radius_thread_t); /* * Allocate thread-specific data. The connections should @@ -553,47 +555,34 @@ static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, * sockets, set timers, etc. */ if (inst->io->thread_instantiate && - inst->io->thread_instantiate(inst->io_conf, inst->io_instance, el, t->io_thread) < 0) return -1; + inst->io->thread_instantiate(&(module_thread_inst_ctx_t){ + .inst = inst->io_submodule, + .thread = t->io_thread, + .el = mctx->el + }) < 0) return -1; return 0; } -/** Instantiate the module - * - * Instantiate I/O and type submodules. - * - * @param[in] instance Ctx data for this module - * @param[in] conf our configuration section parsed to give us instance. - * @return - * - 0 on success. - * - -1 on failure. - */ -static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_radius_t *inst = talloc_get_type_abort(instance, rlm_radius_t); + rlm_radius_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_radius_t); - if (inst->io->instantiate && inst->io->instantiate(inst->io_instance, inst->io_conf) < 0) return -1; + if (inst->io->instantiate && + inst->io->instantiate(&(module_inst_ctx_t){ + .inst = inst->io_submodule + }) < 0) return -1; return 0; } -/** Bootstrap the module - * - * Bootstrap I/O and type submodules. - * - * @param[in] instance Ctx data for this module - * @param[in] conf our configuration section parsed to give us instance. - * @return - * - 0 on success. - * - -1 on failure. - */ -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { size_t i, num_types; - rlm_radius_t *inst = talloc_get_type_abort(instance, rlm_radius_t); + rlm_radius_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_radius_t); + CONF_SECTION *conf = mctx->inst->conf; - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); + inst->name = mctx->inst->name; /* * These limits are specific to RADIUS, and cannot be over-ridden @@ -754,9 +743,6 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) setup_io_submodule: inst->io = (rlm_radius_io_t const *) inst->io_submodule->module->common; - inst->io_instance = inst->io_submodule->data; - inst->io_conf = inst->io_submodule->conf; - fr_assert(inst->io->thread_inst_size > 0); fr_assert(inst->io->bootstrap != NULL); fr_assert(inst->io->instantiate != NULL); @@ -769,7 +755,10 @@ setup_io_submodule: /* * Bootstrap the submodule. */ - if (inst->io->bootstrap(inst->io_instance, inst->io_conf) < 0) return -1; + if (inst->io->bootstrap && + inst->io->bootstrap(&(module_inst_ctx_t){ + .inst = inst->io_submodule + }) < 0) return -1; return 0; } diff --git a/src/modules/rlm_radius/rlm_radius.h b/src/modules/rlm_radius/rlm_radius.h index 83291b3a62..0f5a401cc1 100644 --- a/src/modules/rlm_radius/rlm_radius.h +++ b/src/modules/rlm_radius/rlm_radius.h @@ -41,7 +41,6 @@ typedef struct rlm_radius_io_s rlm_radius_io_t; * Contains buffers and connection handles specific to the thread. */ typedef struct { - rlm_radius_t const *inst; //!< Instance of the module. void *io_thread; //!< thread context for the IO submodule } rlm_radius_thread_t; @@ -49,8 +48,7 @@ typedef struct { * Define a structure for our module configuration. */ struct rlm_radius_s { - char const *name; //!< Module instance name. - + char const *name; dl_module_inst_t *io_submodule; //!< As provided by the transport_parse rlm_radius_io_t const *io; //!< Easy access to the IO handle void *io_instance; //!< Easy access to the IO instance diff --git a/src/modules/rlm_radius/rlm_radius_udp.c b/src/modules/rlm_radius/rlm_radius_udp.c index 458d9a113b..3ffac7ef7c 100644 --- a/src/modules/rlm_radius/rlm_radius_udp.c +++ b/src/modules/rlm_radius/rlm_radius_udp.c @@ -2365,7 +2365,7 @@ static void status_check_reply(fr_trunk_request_t *treq, fr_time_t now) fr_trunk_connection_signal_active(treq->tconn); } -static void request_demux(fr_trunk_connection_t *tconn, fr_connection_t *conn, UNUSED void *uctx) +static void request_demux(UNUSED fr_event_list_t *el, fr_trunk_connection_t *tconn, fr_connection_t *conn, UNUSED void *uctx) { udp_handle_t *h = talloc_get_type_abort(conn->h, udp_handle_t);; @@ -2815,10 +2815,10 @@ static unlang_action_t mod_enqueue(rlm_rcode_t *p_result, void **rctx_out, void /** Instantiate thread data for the submodule. * */ -static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, fr_event_list_t *el, void *tctx) +static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx) { - rlm_radius_udp_t *inst = talloc_get_type_abort(instance, rlm_radius_udp_t); - udp_thread_t *thread = talloc_get_type_abort(tctx, udp_thread_t); + rlm_radius_udp_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_radius_udp_t); + udp_thread_t *thread = talloc_get_type_abort(mctx->thread, udp_thread_t); static fr_trunk_io_funcs_t io_funcs = { .connection_alloc = thread_conn_alloc, @@ -2849,30 +2849,20 @@ static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, inst->trunk_conf->req_pool_headers = 4; /* One for the request, one for the buffer, one for the tracking binding, one for Proxy-State VP */ inst->trunk_conf->req_pool_size = sizeof(udp_request_t) + inst->max_packet_size + sizeof(radius_track_entry_t ***) + sizeof(fr_pair_t) + 20; - thread->el = el; + thread->el = mctx->el; thread->inst = inst; - thread->trunk = fr_trunk_alloc(thread, el, inst->replicate ? &io_funcs_replicate : &io_funcs, + thread->trunk = fr_trunk_alloc(thread, mctx->el, inst->replicate ? &io_funcs_replicate : &io_funcs, inst->trunk_conf, inst->parent->name, thread, false); if (!thread->trunk) return -1; return 0; } -/** Instantiate the module - * - * Instantiate I/O and type submodules. - * - * @param[in] instance data for this module - * @param[in] conf our configuration section parsed to give us instance. - * @return - * - 0 on success. - * - -1 on failure. - */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_radius_t *parent = talloc_get_type_abort(dl_module_parent_data_by_child_data(instance), - rlm_radius_t); - rlm_radius_udp_t *inst = talloc_get_type_abort(instance, rlm_radius_udp_t); + rlm_radius_t *parent = talloc_get_type_abort(mctx->inst->parent->data, rlm_radius_t); + rlm_radius_udp_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_radius_udp_t); + CONF_SECTION *conf = mctx->inst->conf; if (!parent) { ERROR("IO module cannot be instantiated directly"); @@ -2962,26 +2952,6 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) return 0; } -/** Bootstrap the module - * - * Bootstrap I/O and type submodules. - * - * @param[in] instance Ctx data for this module - * @param[in] conf our configuration section parsed to give us instance. - * @return - * - 0 on success. - * - -1 on failure. - */ -static int mod_bootstrap(void *instance, CONF_SECTION *conf) -{ - rlm_radius_udp_t *inst = talloc_get_type_abort(instance, rlm_radius_udp_t); - - (void) talloc_set_type(inst, rlm_radius_udp_t); - inst->config = conf; - - return 0; -} - extern rlm_radius_io_t rlm_radius_udp; rlm_radius_io_t rlm_radius_udp = { .magic = RLM_MODULE_INIT, @@ -2992,7 +2962,6 @@ rlm_radius_io_t rlm_radius_udp = { .thread_inst_type = "udp_thread_t", .config = module_config, - .bootstrap = mod_bootstrap, .instantiate = mod_instantiate, .thread_instantiate = mod_thread_instantiate, diff --git a/src/modules/rlm_redis/rlm_redis.c b/src/modules/rlm_redis/rlm_redis.c index 53e0bbb5b7..1b15081e4b 100644 --- a/src/modules/rlm_redis/rlm_redis.c +++ b/src/modules/rlm_redis/rlm_redis.c @@ -48,8 +48,6 @@ typedef struct { fr_redis_conf_t conf; //!< Connection parameters for the Redis server. //!< Must be first field in this struct. - char const *name; //!< Instance name. - fr_redis_cluster_t *cluster; //!< Redis cluster. } rlm_redis_t; @@ -461,29 +459,26 @@ finish: return action; } -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - rlm_redis_t *inst = instance; + rlm_redis_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_redis_t); char *name; xlat_t *xlat; - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - - xlat = xlat_register(inst, inst->name, redis_xlat, false); + xlat = xlat_register(inst, mctx->inst->name, redis_xlat, false); xlat_func_args(xlat, redis_args); xlat_async_instantiate_set(xlat, redis_xlat_instantiate, rlm_redis_t *, NULL, inst); /* * %(redis_node:[ idx]) */ - name = talloc_asprintf(NULL, "%s_node", inst->name); + name = talloc_asprintf(NULL, "%s_node", mctx->inst->name); xlat = xlat_register(inst, name, redis_node_xlat, false); xlat_func_args(xlat, redis_node_xlat_args); xlat_async_instantiate_set(xlat, redis_xlat_instantiate, rlm_redis_t *, NULL, inst); talloc_free(name); - name = talloc_asprintf(NULL, "%s_remap", inst->name); + name = talloc_asprintf(NULL, "%s_remap", mctx->inst->name); xlat = xlat_register(inst, name, redis_remap_xlat, false); xlat_func_args(xlat, redis_remap_xlat_args); xlat_async_instantiate_set(xlat, redis_xlat_instantiate, rlm_redis_t *, NULL, inst); @@ -492,11 +487,11 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) return 0; } -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_redis_t *inst = instance; + rlm_redis_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_redis_t); - inst->cluster = fr_redis_cluster_alloc(inst, conf, &inst->conf, true, NULL, NULL, NULL); + inst->cluster = fr_redis_cluster_alloc(inst, mctx->inst->conf, &inst->conf, true, NULL, NULL, NULL); if (!inst->cluster) return -1; return 0; diff --git a/src/modules/rlm_redis_ippool/rlm_redis_ippool.c b/src/modules/rlm_redis_ippool/rlm_redis_ippool.c index cca236f463..ff661afa98 100644 --- a/src/modules/rlm_redis_ippool/rlm_redis_ippool.c +++ b/src/modules/rlm_redis_ippool/rlm_redis_ippool.c @@ -1370,12 +1370,12 @@ static unlang_action_t CC_HINT(nonnull) mod_release(rlm_rcode_t *p_result, modul return mod_action(p_result, inst, request, vp ? vp->vp_uint32 : POOL_ACTION_RELEASE); } -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { static bool done_hash = false; - CONF_SECTION *subcs = cf_section_find(conf, "redis", NULL); + CONF_SECTION *subcs = cf_section_find(mctx->inst->conf, "redis", NULL); - rlm_redis_ippool_t *inst = instance; + rlm_redis_ippool_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_redis_ippool_t); fr_assert(tmpl_is_attr(inst->allocated_address_attr)); fr_assert(subcs); diff --git a/src/modules/rlm_rediswho/rlm_rediswho.c b/src/modules/rlm_rediswho/rlm_rediswho.c index ff59ccc29e..82cc3a9b16 100644 --- a/src/modules/rlm_rediswho/rlm_rediswho.c +++ b/src/modules/rlm_rediswho/rlm_rediswho.c @@ -40,8 +40,6 @@ typedef struct { fr_redis_conf_t conf; //!< Connection parameters for the Redis server. //!< Must be first field in this struct. - char const *name; //!< Instance name. - CONF_SECTION *cs; fr_redis_cluster_t *cluster; //!< Pool O pools int expiry_time; //!< Expiry time in seconds if no updates are received for a user @@ -199,9 +197,10 @@ static unlang_action_t mod_accounting_all(rlm_rcode_t *p_result, rlm_rediswho_t static unlang_action_t CC_HINT(nonnull) mod_accounting(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request) { rlm_rediswho_t const *inst = talloc_get_type_abort_const(mctx->inst->data, rlm_rediswho_t); + CONF_SECTION *conf = mctx->inst->conf; rlm_rcode_t rcode; fr_pair_t *vp; - fr_dict_enum_value_t *dv; + fr_dict_enum_value_t *dv; CONF_SECTION *cs; char const *insert, *trim, *expire; @@ -217,7 +216,7 @@ static unlang_action_t CC_HINT(nonnull) mod_accounting(rlm_rcode_t *p_result, mo RETURN_MODULE_NOOP; } - cs = cf_section_find(inst->cs, dv->name, NULL); + cs = cf_section_find(conf, dv->name, NULL); if (!cs) { RDEBUG2("No subsection %s", dv->name); RETURN_MODULE_NOOP; @@ -230,20 +229,10 @@ static unlang_action_t CC_HINT(nonnull) mod_accounting(rlm_rcode_t *p_result, mo return mod_accounting_all(&rcode, inst, request, insert, trim, expire); } -static int mod_bootstrap(void *instance, CONF_SECTION *conf) -{ - rlm_rediswho_t *inst = instance; - - inst->cs = conf; - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - - return 0; -} - -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_rediswho_t *inst = instance; + rlm_rediswho_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_rediswho_t); + CONF_SECTION *conf = mctx->inst->conf; inst->cluster = fr_redis_cluster_alloc(inst, conf, &inst->conf, true, NULL, NULL, NULL); if (!inst->cluster) return -1; @@ -267,7 +256,6 @@ module_t rlm_rediswho = { .config = module_config, .onload = mod_load, .instantiate = mod_instantiate, - .bootstrap = mod_bootstrap, .methods = { [MOD_ACCOUNTING] = mod_accounting }, diff --git a/src/modules/rlm_rest/rest.c b/src/modules/rlm_rest/rest.c index 6bf23516e1..b5b2a4698b 100644 --- a/src/modules/rlm_rest/rest.c +++ b/src/modules/rlm_rest/rest.c @@ -20,12 +20,12 @@ * @brief Functions and datatypes for the REST (HTTP) transport. * @file rest.c * - * @copyright 2012-2019 Arran Cudbard-Bell (a.cudbardb@freeradius.org) + * @copyright 2012-2021 Arran Cudbard-Bell (a.cudbardb@freeradius.org) */ RCSID("$Id$") -#define LOG_PREFIX inst->name +#define LOG_PREFIX mctx->inst->name #include #include @@ -1626,7 +1626,7 @@ size_t rest_get_handle_data(char const **out, fr_curl_io_request_t *randle) * data will be sent using multiple HTTP requests, or contiguous mode where * the request data will be sent in a single HTTP request. * - * @param[in] inst configuration data. + * @param[in] mctx Call data. * @param[in] section configuration data. * @param[in] request Current request. * @param[in] randle fr_curl_io_request_t to configure. @@ -1636,11 +1636,11 @@ size_t rest_get_handle_data(char const **out, fr_curl_io_request_t *randle) * - 0 on success. * - -1 on failure. */ -static int rest_request_config_body(rlm_rest_t const *inst, rlm_rest_section_t const *section, +static int rest_request_config_body(module_ctx_t const *mctx, rlm_rest_section_t const *section, request_t *request, fr_curl_io_request_t *randle, rest_read_t func) { + rlm_rest_t const *inst = talloc_get_type_abort(mctx->inst, rlm_rest_t); rlm_rest_curl_context_t *uctx = talloc_get_type_abort(randle->uctx, rlm_rest_curl_context_t); - ssize_t len; /* @@ -1696,8 +1696,7 @@ error: * * Sets up callbacks for all response processing (buffers and body data). * - * @param[in] inst configuration data. - * @param[in] t Thread specific instance data. + * @param[in] mctx call data. * @param[in] section configuration data. * @param[in] randle to configure. * @param[in] request Current request. @@ -1713,11 +1712,13 @@ error: * - 0 on success (all opts configured). * - -1 on failure. */ -int rest_request_config(rlm_rest_t const *inst, rlm_rest_thread_t *t, rlm_rest_section_t const *section, +int rest_request_config(module_ctx_t const *mctx, rlm_rest_section_t const *section, request_t *request, fr_curl_io_request_t *randle, http_method_t method, http_body_type_t type, char const *uri, char const *username, char const *password) { + rlm_rest_t const *inst = talloc_get_type_abort(mctx->inst, rlm_rest_t); + rlm_rest_thread_t const *t = talloc_get_type_abort(mctx->inst, rlm_rest_thread_t); rlm_rest_curl_context_t *ctx = talloc_get_type_abort(randle->uctx, rlm_rest_curl_context_t); CURL *candle = randle->candle; fr_time_delta_t timeout; @@ -1966,7 +1967,7 @@ do {\ */ switch (type) { case REST_HTTP_BODY_NONE: - if (rest_request_config_body(inst, section, request, randle, NULL) < 0) return -1; + if (rest_request_config_body(mctx, section, request, randle, NULL) < 0) return -1; break; @@ -1984,7 +1985,7 @@ do {\ /* Use the encoder specific pointer to store the data we need to encode */ ctx->request.encoder = data; - if (rest_request_config_body(inst, section, request, randle, rest_encode_custom) < 0) { + if (rest_request_config_body(mctx, section, request, randle, rest_encode_custom) < 0) { TALLOC_FREE(ctx->request.encoder); return -1; } @@ -2003,7 +2004,7 @@ do {\ /* Use the encoder specific pointer to store the data we need to encode */ ctx->request.encoder = data; - if (rest_request_config_body(inst, section, request, randle, rest_encode_custom) < 0) { + if (rest_request_config_body(mctx, section, request, randle, rest_encode_custom) < 0) { TALLOC_FREE(ctx->request.encoder); return -1; } @@ -2020,7 +2021,7 @@ do {\ rest_request_init(section, request, &ctx->request); - if (rest_request_config_body(inst, section, request, randle, rest_encode_json) < 0) return -1; + if (rest_request_config_body(mctx, section, request, randle, rest_encode_json) < 0) return -1; } break; @@ -2030,7 +2031,7 @@ do {\ rest_request_init(section, request, &ctx->request); fr_pair_dcursor_init(&(ctx->request.cursor), &request->request_pairs); - if (rest_request_config_body(inst, section, request, randle, rest_encode_post) < 0) return -1; + if (rest_request_config_body(mctx, section, request, randle, rest_encode_post) < 0) return -1; break; diff --git a/src/modules/rlm_rest/rest.h b/src/modules/rlm_rest/rest.h index 259397c8b3..feea0fdb19 100644 --- a/src/modules/rlm_rest/rest.h +++ b/src/modules/rlm_rest/rest.h @@ -146,8 +146,6 @@ typedef struct { * Structure for module configuration */ typedef struct { - char const *name; //!< Instance name. - char const *connect_proxy; //!< Send request via this proxy. int http_negotiation; //!< What HTTP version to negotiate, and how to @@ -288,11 +286,11 @@ void *rest_mod_conn_create(TALLOC_CTX *ctx, void *instance, fr_time_delta_t time /* * Request processing API */ -int rest_request_config(rlm_rest_t const *instance, rlm_rest_thread_t *thread, +int rest_request_config(module_ctx_t const *mctx, rlm_rest_section_t const *section, request_t *request, fr_curl_io_request_t *randle, http_method_t method, http_body_type_t type, char const *uri, - char const *username, char const *password) CC_HINT(nonnull (1,2,3,5,8)); + char const *username, char const *password) CC_HINT(nonnull (1,2,4,7)); int rest_response_decode(rlm_rest_t const *instance, UNUSED rlm_rest_section_t const *section, request_t *request, diff --git a/src/modules/rlm_rest/rlm_rest.c b/src/modules/rlm_rest/rlm_rest.c index 2337c87c7b..581fc0488c 100644 --- a/src/modules/rlm_rest/rlm_rest.c +++ b/src/modules/rlm_rest/rlm_rest.c @@ -206,13 +206,15 @@ static int rlm_rest_status_update(request_t *request, void *handle) return 0; } -static int rlm_rest_perform(rlm_rest_t const *instance, rlm_rest_thread_t *t, +static int rlm_rest_perform(module_ctx_t const *mctx, rlm_rest_section_t const *section, fr_curl_io_request_t *randle, request_t *request, char const *username, char const *password) { - ssize_t uri_len; - char *uri = NULL; - int ret; + rlm_rest_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_rest_t); + rlm_rest_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_rest_thread_t); + ssize_t uri_len; + char *uri = NULL; + int ret; RDEBUG2("Expanding URI components"); @@ -220,7 +222,7 @@ static int rlm_rest_perform(rlm_rest_t const *instance, rlm_rest_thread_t *t, * Build xlat'd URI, this allows REST servers to be specified by * request attributes. */ - uri_len = rest_uri_build(&uri, instance, request, section->uri); + uri_len = rest_uri_build(&uri, inst, request, section->uri); if (uri_len <= 0) return -1; RDEBUG2("Sending HTTP %s to \"%s\"", fr_table_str_by_value(http_method_table, section->method, NULL), uri); @@ -229,7 +231,7 @@ static int rlm_rest_perform(rlm_rest_t const *instance, rlm_rest_thread_t *t, * Configure various CURL options, and initialise the read/write * context data. */ - ret = rest_request_config(instance, t, section, request, randle, section->method, section->body, + ret = rest_request_config(mctx, section, request, randle, section->method, section->body, uri, username, password); talloc_free(uri); if (ret < 0) return -1; @@ -502,7 +504,8 @@ 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(mod_inst, t, section, request, randle, section->method, + ret = rest_request_config(&(module_ctx_t){ .inst = dl_module_instance_by_data(mod_inst), .thread = t }, + section, request, randle, section->method, section->body, uri_vb->vb_strvalue, NULL, NULL); if (ret < 0) goto error; @@ -621,7 +624,7 @@ static unlang_action_t CC_HINT(nonnull) mod_authorize(rlm_rcode_t *p_result, mod handle = fr_pool_connection_get(t->pool, request); if (!handle) RETURN_MODULE_FAIL; - ret = rlm_rest_perform(inst, t, section, handle, request, NULL, NULL); + ret = rlm_rest_perform(mctx, section, handle, request, NULL, NULL); if (ret < 0) { rest_request_cleanup(inst, handle); fr_pool_connection_release(t->pool, request, handle); @@ -770,7 +773,7 @@ static unlang_action_t CC_HINT(nonnull) mod_authenticate(rlm_rcode_t *p_result, handle = fr_pool_connection_get(t->pool, request); if (!handle) RETURN_MODULE_FAIL; - ret = rlm_rest_perform(inst, t, section, + ret = rlm_rest_perform(mctx, section, handle, request, username->vp_strvalue, password->vp_strvalue); if (ret < 0) { rest_request_cleanup(inst, handle); @@ -850,7 +853,7 @@ static unlang_action_t CC_HINT(nonnull) mod_accounting(rlm_rcode_t *p_result, mo handle = fr_pool_connection_get(t->pool, request); if (!handle) RETURN_MODULE_FAIL; - ret = rlm_rest_perform(inst, t, section, handle, request, NULL, NULL); + ret = rlm_rest_perform(mctx, section, handle, request, NULL, NULL); if (ret < 0) { rest_request_cleanup(inst, handle); fr_pool_connection_release(t->pool, request, handle); @@ -929,7 +932,7 @@ static unlang_action_t CC_HINT(nonnull) mod_post_auth(rlm_rcode_t *p_result, mod handle = fr_pool_connection_get(t->pool, request); if (!handle) RETURN_MODULE_FAIL; - ret = rlm_rest_perform(inst, t, section, handle, request, NULL, NULL); + ret = rlm_rest_perform(mctx, section, handle, request, NULL, NULL); if (ret < 0) { rest_request_cleanup(inst, handle); @@ -1102,29 +1105,27 @@ static int mod_xlat_thread_instantiate(UNUSED void *xlat_inst, void *xlat_thread * Easy handles representing requests are added to the curl multihandle * with the multihandle used for mux/demux. * - * @param[in] conf section containing the configuration of this module instance. - * @param[in] instance of rlm_rest_t. - * @param[in] thread specific data. - * @param[in] el The event list serviced by this thread. + * @param[in] mctx Thread instantiation data. * @return * - 0 on success. * - -1 on failure. */ -static int mod_thread_instantiate(CONF_SECTION const *conf, void *instance, fr_event_list_t *el, void *thread) +static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx) { - rlm_rest_t *inst = instance; - rlm_rest_thread_t *t = thread; + rlm_rest_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_rest_t); + rlm_rest_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_rest_thread_t); + CONF_SECTION *conf = mctx->inst->conf; fr_curl_handle_t *mhandle; CONF_SECTION *my_conf; - t->inst = instance; + t->inst = inst; /* * Temporary hack to make config parsing * thread safe. */ my_conf = cf_section_dup(NULL, NULL, conf, cf_section_name1(conf), cf_section_name2(conf), true); - t->pool = fr_pool_init(NULL, my_conf, instance, rest_mod_conn_create, NULL, inst->name); + t->pool = fr_pool_init(NULL, my_conf, inst, rest_mod_conn_create, NULL, mctx->inst->name); talloc_free(my_conf); if (!t->pool) { @@ -1137,7 +1138,7 @@ static int mod_thread_instantiate(CONF_SECTION const *conf, void *instance, fr_e return -1; } - mhandle = fr_curl_io_init(t, el, inst->multiplex); + mhandle = fr_curl_io_init(t, mctx->el, inst->multiplex); if (!mhandle) return -1; t->mhandle = mhandle; @@ -1150,13 +1151,12 @@ static int mod_thread_instantiate(CONF_SECTION const *conf, void *instance, fr_e * Destroys all curl easy handles, and then the multihandle associated * with this thread. * - * @param[in] el for this thread. - * @param[in] thread specific data to destroy. + * @param[in] mctx data to destroy. * @return 0 */ -static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread) +static int mod_thread_detach(module_thread_inst_ctx_t const *mctx) { - rlm_rest_thread_t *t = thread; + rlm_rest_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_rest_thread_t); talloc_free(t->mhandle); /* Ensure this is shutdown before the pool */ fr_pool_free(t->pool); @@ -1174,9 +1174,10 @@ static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread) * that must be referenced in later calls, store a handle to it * in *instance otherwise put a null pointer there. */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_rest_t *inst = instance; + rlm_rest_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_rest_t); + CONF_SECTION *conf = mctx->inst->conf; inst->xlat.method_str = "GET"; inst->xlat.body = REST_HTTP_BODY_NONE; @@ -1203,15 +1204,12 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) return 0; } -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - rlm_rest_t *inst = instance; + rlm_rest_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_rest_t); xlat_t *xlat; - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - - xlat = xlat_register(inst, inst->name, rest_xlat, true); + xlat = xlat_register(inst, mctx->inst->name, rest_xlat, true); xlat_func_args(xlat, rest_xlat_args); xlat_async_thread_instantiate_set(xlat, mod_xlat_thread_instantiate, rest_xlat_thread_inst_t, NULL, inst); diff --git a/src/modules/rlm_securid/rlm_securid.c b/src/modules/rlm_securid/rlm_securid.c index 083f4dd710..15a3e9374d 100644 --- a/src/modules/rlm_securid/rlm_securid.c +++ b/src/modules/rlm_securid/rlm_securid.c @@ -427,9 +427,9 @@ static SECURID_AUTH_RC securidAuth(void *instance, request_t *request, } /******************************************/ -static int mod_detach(void *instance) +static int mod_detach(module_detach_ctx_t *mctx) { - rlm_securid_t *inst = (rlm_securid_t *) instance; + rlm_securid_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_securid_t); /* delete session tree */ if (inst->session_tree) { @@ -443,9 +443,9 @@ static int mod_detach(void *instance) } -static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_securid_t *inst = instance; + rlm_securid_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_securid_t); /* * Lookup sessions in the tree. We don't free them in diff --git a/src/modules/rlm_sigtran/rlm_sigtran.c b/src/modules/rlm_sigtran/rlm_sigtran.c index e245b521e9..ae976f1694 100644 --- a/src/modules/rlm_sigtran/rlm_sigtran.c +++ b/src/modules/rlm_sigtran/rlm_sigtran.c @@ -34,7 +34,7 @@ */ RCSID("$Id$") -#define LOG_PREFIX_ARGS inst->name +#define LOG_PREFIX_ARGS mctx->inst->name #include @@ -305,11 +305,10 @@ static int sigtran_sccp_sockaddr_from_conf(TALLOC_CTX *ctx, rlm_sigtran_t *inst, return 0; } -static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, - fr_event_list_t *el, void *thread) +static int mod_thread_instantiate(module_thread_inst_ctx_t *mctx) { - rlm_sigtran_t *inst = instance; - rlm_sigtran_thread_t *t = thread; + rlm_sigtran_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_sigtran_t); + rlm_sigtran_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_sigtran_thread_t); int fd; t->inst = instance; @@ -325,21 +324,18 @@ static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, return 0; } -static int mod_thread_detach(fr_event_list_t *el, void *thread) +static int mod_thread_detach(module_thread_inst_ctx_t *mctx) { - rlm_sigtran_thread_t *t = thread; + rlm_sigtran_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_sigtran_thread_t); sigtran_client_thread_unregister(el, t->fd); /* Also closes our side */ return 0; } -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_sigtran_t *inst = instance; - - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); + rlm_sigtran_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_sigtran_t); /* * Translate traffic mode string to integer @@ -402,9 +398,9 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) /** * Cleanup internal state. */ -static int mod_detach(UNUSED void *instance) +static int mod_detach(module_detach_ctx_t *mctx) { - rlm_sigtran_t *inst = instance; + rlm_sigtran_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_sigtran_t); /* * If we're just checking the config we didn't start the diff --git a/src/modules/rlm_sigtran/sigtran.h b/src/modules/rlm_sigtran/sigtran.h index 1d75a63958..2fc250be9f 100644 --- a/src/modules/rlm_sigtran/sigtran.h +++ b/src/modules/rlm_sigtran/sigtran.h @@ -229,13 +229,11 @@ typedef struct sigtran_map_send_auth_info_res { } sigtran_map_send_auth_info_res_t; typedef struct rlm_sigtran { - char const *name; //!< Instance name. - sigtran_conn_t const *conn; //!< Linkset associated with this instance. sigtran_conn_conf_t conn_conf; //!< Connection configuration - tmpl_t *imsi; //!< Subscriber identifier. + tmpl_t *imsi; //!< Subscriber identifier. } rlm_sigtran_t; typedef struct rlm_sigtran_thread { diff --git a/src/modules/rlm_smtp/rlm_smtp.c b/src/modules/rlm_smtp/rlm_smtp.c index 05ca280353..6dfea892f2 100644 --- a/src/modules/rlm_smtp/rlm_smtp.c +++ b/src/modules/rlm_smtp/rlm_smtp.c @@ -77,7 +77,6 @@ typedef struct { } rlm_smtp_t; typedef struct { - rlm_smtp_t const *inst; //!< Instance of rlm_smtp. fr_curl_handle_t *mhandle; //!< Thread specific multi handle. Serves as the dispatch and coralling structure for smtp requests } rlm_smtp_thread_t; @@ -970,9 +969,9 @@ static int smtp_verify(map_t *map, void *ctx) return 0; } -static int mod_bootstrap(void *instance, UNUSED CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - rlm_smtp_t *inst = instance; + rlm_smtp_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_smtp_t ); talloc_foreach(inst->recipient_addrs, vpt) INFO("NAME: %s", vpt->name); @@ -980,9 +979,10 @@ static int mod_bootstrap(void *instance, UNUSED CONF_SECTION *conf) } -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_smtp_t *inst = instance; + rlm_smtp_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_smtp_t); + CONF_SECTION *conf = mctx->inst->conf; CONF_SECTION *header; fr_map_list_init(&inst->header_maps); @@ -1013,14 +1013,12 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) /* * Initialize a new thread with a curl instance */ -static int mod_thread_instantiate(UNUSED CONF_SECTION const *conf, void *instance, fr_event_list_t *el, void *thread) +static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx) { - rlm_smtp_thread_t *t = thread; + rlm_smtp_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_smtp_thread_t); fr_curl_handle_t *mhandle; - t->inst = instance; - - mhandle = fr_curl_io_init(t, el, false); + mhandle = fr_curl_io_init(t, mctx->el, false); if (!mhandle) return -1; t->mhandle = mhandle; @@ -1030,9 +1028,9 @@ static int mod_thread_instantiate(UNUSED CONF_SECTION const *conf, void *instanc /* * Close the thread and free the memory */ -static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread) +static int mod_thread_detach(module_thread_inst_ctx_t const *mctx) { - rlm_smtp_thread_t *t = thread; + rlm_smtp_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_smtp_thread_t); talloc_free(t->mhandle); return 0; } diff --git a/src/modules/rlm_soh/rlm_soh.c b/src/modules/rlm_soh/rlm_soh.c index 4d2f08e05e..8377dd05c8 100644 --- a/src/modules/rlm_soh/rlm_soh.c +++ b/src/modules/rlm_soh/rlm_soh.c @@ -28,7 +28,6 @@ RCSID("$Id$") #include typedef struct { - char const *name; bool dhcp; } rlm_soh_t; @@ -269,15 +268,12 @@ static unlang_action_t CC_HINT(nonnull) mod_authorize(rlm_rcode_t *p_result, UNU RETURN_MODULE_OK; } -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - rlm_soh_t *inst = instance; + rlm_soh_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_soh_t); xlat_t *xlat; - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - - xlat = xlat_register(inst, inst->name, soh_xlat, false); + xlat = xlat_register(inst, mctx->inst->name, soh_xlat, false); xlat_func_args(xlat, soh_xlat_args); return 0; diff --git a/src/modules/rlm_sometimes/rlm_sometimes.c b/src/modules/rlm_sometimes/rlm_sometimes.c index 81e8b37c01..bfeb99734a 100644 --- a/src/modules/rlm_sometimes/rlm_sometimes.c +++ b/src/modules/rlm_sometimes/rlm_sometimes.c @@ -46,9 +46,10 @@ static const CONF_PARSER module_config[] = { CONF_PARSER_TERMINATOR }; -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_sometimes_t *inst = instance; + rlm_sometimes_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_sometimes_t); + CONF_SECTION *conf = mctx->inst->conf; /* * Convert the rcode string to an int, and get rid of it @@ -70,11 +71,11 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) /* * A lie! It always returns! */ -static unlang_action_t sometimes_return(rlm_rcode_t *p_result, void const *instance, request_t *request, +static unlang_action_t sometimes_return(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request, fr_radius_packet_t *packet, fr_radius_packet_t *reply) { + rlm_sometimes_t const *inst = talloc_get_type_abort_const(mctx->inst->data, rlm_sometimes_t); uint32_t hash; - rlm_sometimes_t const *inst = talloc_get_type_abort_const(instance, rlm_sometimes_t); fr_pair_t *vp; float value; @@ -144,12 +145,12 @@ static unlang_action_t sometimes_return(rlm_rcode_t *p_result, void const *insta static unlang_action_t CC_HINT(nonnull) mod_sometimes_packet(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request) { - return sometimes_return(p_result, mctx->inst->data, request, request->packet, request->reply); + return sometimes_return(p_result, mctx, request, request->packet, request->reply); } static unlang_action_t CC_HINT(nonnull) mod_sometimes_reply(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request) { - return sometimes_return(p_result, mctx->inst->data, request, request->reply, NULL); + return sometimes_return(p_result, mctx, request, request->reply, NULL); } extern module_t rlm_sometimes; diff --git a/src/modules/rlm_sql/drivers/rlm_sql_cassandra/rlm_sql_cassandra.c b/src/modules/rlm_sql/drivers/rlm_sql_cassandra/rlm_sql_cassandra.c index 97b4ead1d5..e214776d70 100644 --- a/src/modules/rlm_sql/drivers/rlm_sql_cassandra/rlm_sql_cassandra.c +++ b/src/modules/rlm_sql/drivers/rlm_sql_cassandra/rlm_sql_cassandra.c @@ -706,9 +706,9 @@ static int sql_affected_rows(UNUSED rlm_sql_handle_t *handle, UNUSED rlm_sql_con return 1; } -static int mod_detach(void *instance) +static int mod_detach(module_detach_ctx_t const *mctx) { - rlm_sql_cassandra_t *inst = instance; + rlm_sql_cassandra_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_sql_cassandra_t); if (inst->ssl) cass_ssl_free(inst->ssl); if (inst->session) cass_session_free(inst->session); /* also synchronously closes the session */ @@ -723,7 +723,7 @@ static int mod_instantiate(rlm_sql_config_t const *config, void *instance, CONF_ { bool do_tls = false; bool do_latency_aware_routing = false; - rlm_sql_cassandra_t *inst = instance; + rlm_sql_cassandra_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_sql_cassandra_t); CassCluster *cluster; diff --git a/src/modules/rlm_sql/drivers/rlm_sql_mysql/rlm_sql_mysql.c b/src/modules/rlm_sql/drivers/rlm_sql_mysql/rlm_sql_mysql.c index 73d2538f17..e2b9abc40f 100644 --- a/src/modules/rlm_sql/drivers/rlm_sql_mysql/rlm_sql_mysql.c +++ b/src/modules/rlm_sql/drivers/rlm_sql_mysql/rlm_sql_mysql.c @@ -169,7 +169,7 @@ static int _sql_socket_destructor(rlm_sql_mysql_conn_t *conn) static int mod_instantiate(UNUSED rlm_sql_config_t const *config, void *instance, UNUSED CONF_SECTION *cs) { - rlm_sql_mysql_t *inst = instance; + rlm_sql_mysql_t *inst = talloc_get_type_abort(instance, rlm_sql_mysql_t); int warnings; warnings = fr_table_value_by_str(server_warnings_table, inst->warnings_str, -1); diff --git a/src/modules/rlm_sql/drivers/rlm_sql_oracle/rlm_sql_oracle.c b/src/modules/rlm_sql/drivers/rlm_sql_oracle/rlm_sql_oracle.c index 0db84b58a4..016f295b06 100644 --- a/src/modules/rlm_sql/drivers/rlm_sql_oracle/rlm_sql_oracle.c +++ b/src/modules/rlm_sql/drivers/rlm_sql_oracle/rlm_sql_oracle.c @@ -142,9 +142,9 @@ static size_t sql_error(TALLOC_CTX *ctx, sql_log_entry_t out[], NDEBUG_UNUSED si return 1; } -static int mod_detach(void *instance) +static int mod_detach(module_detach_ctx_t const *mctx) { - rlm_sql_oracle_t *inst = instance; + rlm_sql_oracle_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_sql_oracle_t); if (inst->pool) OCISessionPoolDestroy((dvoid *)inst->pool, (dvoid *)inst->error, OCI_DEFAULT ); if (inst->error) OCIHandleFree((dvoid *)inst->error, OCI_HTYPE_ERROR); @@ -157,7 +157,7 @@ static int mod_instantiate(rlm_sql_config_t const *config, void *instance, CONF_ { char errbuff[512]; sb4 errcode = 0; - rlm_sql_oracle_t *inst = instance; + rlm_sql_oracle_t *inst = talloc_get_type_abort(instance, rlm_sql_oracle_t); OraText *sql_password = NULL; OraText *sql_login = NULL; diff --git a/src/modules/rlm_sql/drivers/rlm_sql_postgresql/rlm_sql_postgresql.c b/src/modules/rlm_sql/drivers/rlm_sql_postgresql/rlm_sql_postgresql.c index f48d6161a1..5bcfa0232a 100644 --- a/src/modules/rlm_sql/drivers/rlm_sql_postgresql/rlm_sql_postgresql.c +++ b/src/modules/rlm_sql/drivers/rlm_sql_postgresql/rlm_sql_postgresql.c @@ -546,7 +546,7 @@ static size_t sql_escape_func(request_t *request, char *out, size_t outlen, char static int mod_instantiate(rlm_sql_config_t const *config, void *instance, CONF_SECTION *conf) { - rlm_sql_postgres_t *inst = instance; + rlm_sql_postgres_t *inst = talloc_get_type_abort(instance, rlm_sql_postgres_t); char application_name[NAMEDATALEN]; char *db_string; diff --git a/src/modules/rlm_sql/drivers/rlm_sql_sqlite/rlm_sql_sqlite.c b/src/modules/rlm_sql/drivers/rlm_sql_sqlite/rlm_sql_sqlite.c index c5872909db..84c358e7db 100644 --- a/src/modules/rlm_sql/drivers/rlm_sql_sqlite/rlm_sql_sqlite.c +++ b/src/modules/rlm_sql/drivers/rlm_sql_sqlite/rlm_sql_sqlite.c @@ -686,7 +686,7 @@ static int sql_affected_rows(rlm_sql_handle_t *handle, static int mod_instantiate(rlm_sql_config_t const *config, void *instance, CONF_SECTION *cs) { bool exists; - rlm_sql_sqlite_t *inst = instance; + rlm_sql_sqlite_t *inst = talloc_get_type_abort(instance, rlm_sql_sqlite_t); struct stat buf; if (!inst->filename) { diff --git a/src/modules/rlm_sql/rlm_sql.c b/src/modules/rlm_sql/rlm_sql.c index 4c6bbb9ac1..09145e2bed 100644 --- a/src/modules/rlm_sql/rlm_sql.c +++ b/src/modules/rlm_sql/rlm_sql.c @@ -1006,9 +1006,9 @@ static int mod_xlat_instantiate(void *xlat_inst, UNUSED xlat_exp_t const *exp, v return 0; } -static int mod_detach(void *instance) +static int mod_detach(module_detach_ctx_t const *mctx) { - rlm_sql_t *inst = talloc_get_type_abort(instance, rlm_sql_t); + rlm_sql_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_sql_t); if (inst->pool) fr_pool_free(inst->pool); @@ -1025,9 +1025,10 @@ static int mod_detach(void *instance) return 0; } -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - rlm_sql_t *inst = talloc_get_type_abort(instance, rlm_sql_t); + rlm_sql_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_sql_t); + CONF_SECTION *conf = mctx->inst->conf; CONF_SECTION *driver_cs; char const *name; xlat_t *xlat; @@ -1144,9 +1145,10 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) } -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_sql_t *inst = instance; + rlm_sql_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_sql_t); + CONF_SECTION *conf = mctx->inst->conf; /* * Sanity check for crazy people. diff --git a/src/modules/rlm_sql/sql.c b/src/modules/rlm_sql/sql.c index 24617da702..e1439d9e1b 100644 --- a/src/modules/rlm_sql/sql.c +++ b/src/modules/rlm_sql/sql.c @@ -65,7 +65,7 @@ size_t sql_rcode_table_len = NUM_ELEMENTS(sql_rcode_table); void *sql_mod_conn_create(TALLOC_CTX *ctx, void *instance, fr_time_delta_t timeout) { int rcode; - rlm_sql_t *inst = instance; + rlm_sql_t *inst = talloc_get_type_abort(instance, rlm_sql_t); rlm_sql_handle_t *handle; /* diff --git a/src/modules/rlm_sqlcounter/rlm_sqlcounter.c b/src/modules/rlm_sqlcounter/rlm_sqlcounter.c index eb94ea2e40..450220a83e 100644 --- a/src/modules/rlm_sqlcounter/rlm_sqlcounter.c +++ b/src/modules/rlm_sqlcounter/rlm_sqlcounter.c @@ -552,9 +552,10 @@ static unlang_action_t CC_HINT(nonnull) mod_authorize(rlm_rcode_t *p_result, mod * that must be referenced in later calls, store a handle to it * in *instance otherwise put a null pointer there. */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_sqlcounter_t *inst = instance; + rlm_sqlcounter_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_sqlcounter_t); + CONF_SECTION *conf = mctx->inst->conf; fr_assert(inst->query && *inst->query); @@ -578,10 +579,11 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) return 0; } -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - rlm_sqlcounter_t *inst = instance; - fr_dict_attr_flags_t flags; + rlm_sqlcounter_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_sqlcounter_t); + CONF_SECTION *conf = mctx->inst->conf; + fr_dict_attr_flags_t flags; /* * Create a new attribute for the counter. diff --git a/src/modules/rlm_sqlippool/rlm_sqlippool.c b/src/modules/rlm_sqlippool/rlm_sqlippool.c index 11c4813b86..8486b3ab5b 100644 --- a/src/modules/rlm_sqlippool/rlm_sqlippool.c +++ b/src/modules/rlm_sqlippool/rlm_sqlippool.c @@ -397,15 +397,10 @@ finish: return retval; } -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - rlm_sqlippool_t *inst = instance; - char const *name; - - name = cf_section_name2(conf); - if (!name) name = cf_section_name1(conf); - - inst->name = talloc_asprintf(inst, "%s - %s", name, inst->sql_instance_name); + rlm_sqlippool_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_sqlippool_t); + inst->name = talloc_asprintf(inst, "%s - %s", mctx->inst->name, inst->sql_instance_name); return 0; } @@ -420,10 +415,11 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) * that must be referenced in later calls, store a handle to it * in *instance otherwise put a null pointer there. */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { module_instance_t *sql_inst; - rlm_sqlippool_t *inst = instance; + rlm_sqlippool_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_sqlippool_t); + CONF_SECTION *conf = mctx->inst->conf; char const *pool_name = NULL; pool_name = cf_section_name2(conf); diff --git a/src/modules/rlm_stats/rlm_stats.c b/src/modules/rlm_stats/rlm_stats.c index 93cb22ed69..040821907f 100644 --- a/src/modules/rlm_stats/rlm_stats.c +++ b/src/modules/rlm_stats/rlm_stats.c @@ -351,10 +351,10 @@ static int8_t data_cmp(const void *one, const void *two) /** Instantiate thread data for the submodule. * */ -static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, UNUSED fr_event_list_t *el, void *thread) +static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx) { - rlm_stats_t *inst = talloc_get_type_abort(instance, rlm_stats_t); - rlm_stats_thread_t *t = thread; + rlm_stats_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_stats_t); + rlm_stats_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_stats_thread_t); (void) talloc_set_type(t, rlm_stats_thread_t); @@ -381,9 +381,9 @@ static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, /** Destroy thread data for the submodule. * */ -static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread) +static int mod_thread_detach(module_thread_inst_ctx_t const *mctx) { - rlm_stats_thread_t *t = talloc_get_type_abort(thread, rlm_stats_thread_t); + rlm_stats_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_stats_thread_t); rlm_stats_t *inst = t->inst; int i; @@ -398,9 +398,9 @@ static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread) return 0; } -static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_stats_t *inst = instance; + rlm_stats_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_stats_t); pthread_mutex_init(&inst->mutex, NULL); fr_dlist_init(&inst->list, rlm_stats_thread_t, entry); @@ -412,9 +412,9 @@ static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf) * Only free memory we allocated. The strings allocated via * cf_section_parse() do not need to be freed. */ -static int mod_detach(void *instance) +static int mod_detach(module_detach_ctx_t const *mctx) { - rlm_stats_t *inst = talloc_get_type_abort(instance, rlm_stats_t); + rlm_stats_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_stats_t); pthread_mutex_destroy(&inst->mutex); diff --git a/src/modules/rlm_test/rlm_test.c b/src/modules/rlm_test/rlm_test.c index b03bd1b0b8..dcd6089ec6 100644 --- a/src/modules/rlm_test/rlm_test.c +++ b/src/modules/rlm_test/rlm_test.c @@ -408,11 +408,10 @@ static xlat_action_t test_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, UNUSED reques } -static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, UNUSED fr_event_list_t *el, - void *thread) +static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx) { - rlm_test_t *inst = instance; - rlm_test_thread_t *t = thread; + rlm_test_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_test_t); + rlm_test_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_test_thread_t); t->inst = inst; t->value = pthread_self(); @@ -421,10 +420,10 @@ static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance return 0; } -static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread) +static int mod_thread_detach(module_thread_inst_ctx_t const *mctx) { - rlm_test_thread_t *t = thread; - rlm_test_t *inst = t->inst; + rlm_test_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_test_t); + rlm_test_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_test_thread_t); INFO("Performing detach for thread %p", (void *)t->value); @@ -443,16 +442,12 @@ static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread) * that must be referenced in later calls, store a handle to it * in *instance otherwise put a null pointer there. */ -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { + rlm_test_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_test_t); xlat_t *xlat; - rlm_test_t *inst = instance; - char const *name2; - inst->name = name2 = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - - if (!name2) { + if (!cf_section_name2(mctx->inst->conf)) { if (paircmp_register_by_name("Test-Paircmp", attr_user_name, false, rlm_test_cmp, inst) < 0) { PERROR("Failed registering \"Test-Paircmp\""); @@ -486,27 +481,21 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) INFO("inst->tmpl_m is NULL"); } - if (!name2) { - if (!(xlat = xlat_register(instance, "test_trigger", trigger_test_xlat, false))) return -1; + if (!cf_section_name2(mctx->inst->conf)) { + if (!(xlat = xlat_register(inst, "test_trigger", trigger_test_xlat, false))) return -1; xlat_func_args(xlat, trigger_test_xlat_args); - if (!(xlat = xlat_register(instance, "test", test_xlat, false))) return -1; + if (!(xlat = xlat_register(inst, "test", test_xlat, false))) return -1; xlat_func_args(xlat, test_xlat_args); } else { - if (!(xlat = xlat_register(instance, name2, test_xlat, false))) return -1; + if (!(xlat = xlat_register(inst, mctx->inst->name, test_xlat, false))) return -1; xlat_func_args(xlat, test_xlat_args); } return 0; } -static int mod_detach(UNUSED void *instance) -{ - /* free things here */ - return 0; -} - /* * The module name should be the only globally exported symbol. * That is, everything else should be 'static'. @@ -527,7 +516,6 @@ module_t rlm_test = { .bootstrap = mod_bootstrap, .thread_instantiate = mod_thread_instantiate, .thread_detach = mod_thread_detach, - .detach = mod_detach, .methods = { [MOD_AUTHENTICATE] = mod_authenticate, [MOD_AUTHORIZE] = mod_authorize, diff --git a/src/modules/rlm_unbound/rlm_unbound.c b/src/modules/rlm_unbound/rlm_unbound.c index 0069ebf7b0..62c65aceb4 100644 --- a/src/modules/rlm_unbound/rlm_unbound.c +++ b/src/modules/rlm_unbound/rlm_unbound.c @@ -24,7 +24,7 @@ */ RCSID("$Id$") -#define LOG_PREFIX inst->name +#define LOG_PREFIX mctx->inst->name #include #include @@ -36,7 +36,6 @@ RCSID("$Id$") typedef struct { char const *name; - uint32_t timeout; char const *filename; //!< Unbound configuration file @@ -426,14 +425,14 @@ static int mod_xlat_thread_instantiate(UNUSED void *xlat_inst, void *xlat_thread return 0; } -static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, fr_event_list_t *el, void *thread) +static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx) { - rlm_unbound_t *inst = talloc_get_type_abort(instance, rlm_unbound_t); - rlm_unbound_thread_t *t = talloc_get_type_abort(thread, rlm_unbound_thread_t); + rlm_unbound_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_unbound_t); + rlm_unbound_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_unbound_thread_t); int res; t->inst = inst; - if (unbound_io_init(t, &t->ev_b, el) < 0) { + if (unbound_io_init(t, &t->ev_b, mctx->el) < 0) { PERROR("Unable to create unbound event base"); return -1; } @@ -479,9 +478,9 @@ static int mod_thread_instantiate(UNUSED CONF_SECTION const *cs, void *instance, return 0; } -static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread) +static int mod_thread_detach(module_thread_inst_ctx_t const *mctx) { - rlm_unbound_thread_t *t = talloc_get_type_abort(thread, rlm_unbound_thread_t); + rlm_unbound_thread_t *t = talloc_get_type_abort(mctx->thread, rlm_unbound_thread_t); talloc_free(t->u_log); talloc_free(t->ev_b); @@ -489,20 +488,17 @@ static int mod_thread_detach(UNUSED fr_event_list_t *el, void *thread) return 0; } -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - rlm_unbound_t *inst = instance; + rlm_unbound_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_unbound_t); xlat_t *xlat; - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - if (inst->timeout > 10000) { - cf_log_err(conf, "timeout must be 0 to 10000"); + cf_log_err(mctx->inst->conf, "timeout must be 0 to 10000"); return -1; } - if(!(xlat = xlat_register(NULL, inst->name, xlat_unbound, true))) return -1; + if(!(xlat = xlat_register(NULL, mctx->inst->name, xlat_unbound, true))) return -1; xlat_func_args(xlat, xlat_unbound_args); xlat_async_thread_instantiate_set(xlat, mod_xlat_thread_instantiate, unbound_xlat_thread_inst_t, NULL, inst); diff --git a/src/modules/rlm_unix/rlm_unix.c b/src/modules/rlm_unix/rlm_unix.c index a963aeaeae..56d905f0d8 100644 --- a/src/modules/rlm_unix/rlm_unix.c +++ b/src/modules/rlm_unix/rlm_unix.c @@ -30,7 +30,7 @@ RCSID("$Id$") USES_APPLE_DEPRECATED_API -#define LOG_PREFIX inst->name +#define LOG_PREFIX mctx->inst->name #include #include @@ -52,7 +52,6 @@ static char trans[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012 #define ENC(c) trans[c] typedef struct { - char const *name; //!< Instance name. char const *radwtmp; } rlm_unix_t; @@ -153,20 +152,17 @@ static int groupcmp(UNUSED void *instance, request_t *request, UNUSED fr_pair_li /* * Read the config */ -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - rlm_unix_t *inst = instance; - - inst->name = cf_section_name2(conf); - if (!inst->name) { - inst->name = cf_section_name1(conf); + rlm_unix_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_unix_t); + if (!cf_section_name2(mctx->inst->conf)) { if (paircmp_register_by_name("Unix-Group", attr_user_name, false, groupcmp, inst) < 0) { PERROR("Failed registering Unix-Group"); return -1; } } else { - char *unix_group = talloc_asprintf(inst, "%s-Unix-Group", inst->name); + char *unix_group = talloc_asprintf(inst, "%s-Unix-Group", mctx->inst->name); if (paircmp_register_by_name(unix_group, attr_user_name, false, groupcmp, inst) < 0) { PERROR("Failed registering %s", unix_group); diff --git a/src/modules/rlm_unpack/rlm_unpack.c b/src/modules/rlm_unpack/rlm_unpack.c index 7bea8a8f68..ada5e205c9 100644 --- a/src/modules/rlm_unpack/rlm_unpack.c +++ b/src/modules/rlm_unpack/rlm_unpack.c @@ -145,7 +145,7 @@ static xlat_action_t unpack_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, request_t * /* * Register the xlats */ -static int mod_bootstrap(UNUSED void *instance, UNUSED CONF_SECTION *conf) +static int mod_bootstrap(UNUSED module_inst_ctx_t const *mctx) { xlat_t *xlat; diff --git a/src/modules/rlm_winbind/rlm_winbind.c b/src/modules/rlm_winbind/rlm_winbind.c index 14dd21f078..1f0eefe52c 100644 --- a/src/modules/rlm_winbind/rlm_winbind.c +++ b/src/modules/rlm_winbind/rlm_winbind.c @@ -85,7 +85,7 @@ fr_dict_attr_autoload_t rlm_winbind_dict_attr[] = { */ static int winbind_group_cmp(void *instance, request_t *request, UNUSED fr_pair_list_t *request_list, fr_pair_t const *check) { - rlm_winbind_t *inst = instance; + rlm_winbind_t *inst = talloc_get_type_abort(instance, rlm_winbind_t); int ret = 1; struct wbcContext *wb_ctx; wbcErr err; @@ -323,26 +323,22 @@ static void *mod_conn_create(TALLOC_CTX *ctx, UNUSED void *instance, UNUSED fr_t * - 0 success * - -1 failure */ -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - rlm_winbind_t *inst = instance; + rlm_winbind_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_winbind_t); char const *group_attribute; char buffer[256]; - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - if (inst->group_attribute) { group_attribute = inst->group_attribute; - } else if (cf_section_name2(conf)) { - snprintf(buffer, sizeof(buffer), "%s-Winbind-Group", inst->name); + } else if (cf_section_name2(mctx->inst->conf)) { + snprintf(buffer, sizeof(buffer), "%s-Winbind-Group", mctx->inst->name); group_attribute = buffer; } else { group_attribute = "Winbind-Group"; } - if (paircmp_register_by_name(group_attribute, attr_user_name, false, - winbind_group_cmp, inst) < 0) { + if (paircmp_register_by_name(group_attribute, attr_user_name, false, winbind_group_cmp, inst) < 0) { PERROR("Error registering group comparison"); return -1; } @@ -360,10 +356,11 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) * - 0 instantiation succeeded * - -1 instantiation failed */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_winbind_t *inst = instance; + rlm_winbind_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_winbind_t); struct wbcInterfaceDetails *wb_info = NULL; + CONF_SECTION *conf = mctx->inst->conf; if (!inst->wb_username) { cf_log_err(conf, "winbind_username must be defined to use rlm_winbind"); @@ -376,10 +373,10 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) return -1; } - inst->auth_type = fr_dict_enum_by_name(attr_auth_type, inst->name, -1); + inst->auth_type = fr_dict_enum_by_name(attr_auth_type, mctx->inst->name, -1); if (!inst->auth_type) { WARN("Failed to find 'authenticate %s {...}' section. Winbind authentication will likely not work", - inst->name); + mctx->inst->name); } /* @@ -414,7 +411,7 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) goto no_domain; } - tmpl_afrom_substr(instance, &inst->wb_domain, + tmpl_afrom_substr(inst, &inst->wb_domain, &FR_SBUFF_IN(wb_info->netbios_domain, strlen(wb_info->netbios_domain)), T_SINGLE_QUOTED_STRING, NULL, @@ -445,9 +442,9 @@ no_domain: * @param[in] instance This module's instance (unused) * @return 0 */ -static int mod_detach(void *instance) +static int mod_detach(module_detach_ctx_t const *mctx) { - rlm_winbind_t *inst = instance; + rlm_winbind_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_winbind_t); fr_pool_free(inst->wb_pool); @@ -479,7 +476,7 @@ static unlang_action_t CC_HINT(nonnull) mod_authorize(rlm_rcode_t *p_result, mod if (!inst->auth_type) { WARN("No 'authenticate %s {...}' section or 'Auth-Type = %s' set. Cannot setup Winbind authentication", - inst->name, inst->name); + mctx->inst->name, mctx->inst->name); RETURN_MODULE_NOOP; } diff --git a/src/modules/rlm_winbind/rlm_winbind.h b/src/modules/rlm_winbind/rlm_winbind.h index bf59605ead..891dc535fb 100644 --- a/src/modules/rlm_winbind/rlm_winbind.h +++ b/src/modules/rlm_winbind/rlm_winbind.h @@ -9,7 +9,6 @@ * Structure for the module configuration. */ typedef struct { - char const *name; fr_pool_t *wb_pool; fr_dict_enum_value_t *auth_type; diff --git a/src/modules/rlm_yubikey/decrypt.c b/src/modules/rlm_yubikey/decrypt.c index 0cc99305ac..a37276944a 100644 --- a/src/modules/rlm_yubikey/decrypt.c +++ b/src/modules/rlm_yubikey/decrypt.c @@ -14,12 +14,13 @@ /** Decrypt a Yubikey OTP AES block * * @param[out] p_result The result of attempt to decrypt the token. - * @param[in] inst Module configuration. + * @param[in] mctx call data. * @param[in] request The current request. * @param[in] passcode string to decrypt. */ -unlang_action_t rlm_yubikey_decrypt(rlm_rcode_t *p_result, rlm_yubikey_t const *inst, request_t *request, char const *passcode) +unlang_action_t rlm_yubikey_decrypt(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request, char const *passcode) { + rlm_yubikey_t const *inst = talloc_get_type_abort(mctx->inst->data, rlm_yubikey_t); uint32_t counter, timestamp; yubikey_token_st token; diff --git a/src/modules/rlm_yubikey/rlm_yubikey.c b/src/modules/rlm_yubikey/rlm_yubikey.c index fdb381e843..226fc61bda 100644 --- a/src/modules/rlm_yubikey/rlm_yubikey.c +++ b/src/modules/rlm_yubikey/rlm_yubikey.c @@ -183,14 +183,11 @@ static void mod_unload(void) fr_dict_autofree(rlm_yubikey_dict); } -static int mod_bootstrap(void *instance, CONF_SECTION *conf) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - rlm_yubikey_t *inst = instance; + rlm_yubikey_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_yubikey_t); xlat_t *xlat; - inst->name = cf_section_name2(conf); - if (!inst->name) inst->name = cf_section_name1(conf); - #ifndef HAVE_YUBIKEY if (inst->decrypt) { cf_log_err(conf, "Requires libyubikey for OTP decryption"); @@ -214,14 +211,17 @@ static int mod_bootstrap(void *instance, CONF_SECTION *conf) * that must be referenced in later calls, store a handle to it * in *instance otherwise put a null pointer there. */ -static int mod_instantiate(void *instance, CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - rlm_yubikey_t *inst = instance; + rlm_yubikey_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_yubikey_t); + CONF_SECTION *conf = mctx->inst->conf; + + inst->name = mctx->inst->name; inst->auth_type = fr_dict_enum_by_name(attr_auth_type, inst->name, -1); if (!inst->auth_type) { WARN("Failed to find 'authenticate %s {...}' section. Yubikey authentication will likely not work", - inst->name); + mctx->inst->name); } if (inst->validate) { @@ -247,9 +247,9 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf) } #ifdef HAVE_YKCLIENT -static int mod_detach(void *instance) +static int mod_detach(module_detach_ctx_t const *mctx) { - rlm_yubikey_ykclient_detach((rlm_yubikey_t *) instance); + rlm_yubikey_ykclient_detach(talloc_get_type_abort(mctx->inst->data, rlm_yubikey_t)); return 0; } #endif @@ -370,7 +370,7 @@ static unlang_action_t CC_HINT(nonnull) mod_authorize(rlm_rcode_t *p_result, mod if (!inst->auth_type) { WARN("No 'authenticate %s {...}' section or 'Auth-Type = %s' set. Cannot setup Yubikey authentication", - inst->name, inst->name); + mctx->inst->name, mctx->inst->name); RETURN_MODULE_NOOP; } @@ -433,14 +433,14 @@ static unlang_action_t CC_HINT(nonnull) mod_authenticate(rlm_rcode_t *p_result, #ifdef HAVE_YUBIKEY if (inst->decrypt) { - rlm_yubikey_decrypt(&rcode, inst, request, passcode); + rlm_yubikey_decrypt(&rcode, mctx, request, passcode); if (rcode != RLM_MODULE_OK) RETURN_MODULE_RCODE(rcode); /* Fall-Through to doing ykclient auth in addition to local auth */ } #endif #ifdef HAVE_YKCLIENT - if (inst->validate) return rlm_yubikey_validate(p_result, inst, request, passcode); + if (inst->validate) return rlm_yubikey_validate(p_result, mctx, request, passcode); #endif RETURN_MODULE_RCODE(rcode); } diff --git a/src/modules/rlm_yubikey/rlm_yubikey.h b/src/modules/rlm_yubikey/rlm_yubikey.h index f01b26de70..6926f72166 100644 --- a/src/modules/rlm_yubikey/rlm_yubikey.h +++ b/src/modules/rlm_yubikey/rlm_yubikey.h @@ -38,8 +38,8 @@ * be used as the instance handle. */ typedef struct { - char const *name; //!< Instance name. - fr_dict_enum_value_t *auth_type; //!< Our Auth-Type. + char const *name; + fr_dict_enum_value_t *auth_type; //!< Our Auth-Type. unsigned int id_len; //!< The length of the Public ID portion of the OTP string. bool split; //!< Split password string into components. bool decrypt; //!< Decrypt the OTP string using the yubikey library. @@ -50,7 +50,7 @@ typedef struct { unsigned int client_id; //!< Validation API client ID. char const *api_key; //!< Validation API signing key. ykclient_t *ykc; //!< ykclient configuration. - fr_pool_t *pool; //!< Connection pool instance. + fr_pool_t *pool; //!< Connection pool instance. #endif } rlm_yubikey_t; @@ -58,7 +58,8 @@ typedef struct { /* * decrypt.c - Decryption functions */ -unlang_action_t rlm_yubikey_decrypt(rlm_rcode_t *p_result, rlm_yubikey_t const *inst, request_t *request, char const *passcode); +unlang_action_t rlm_yubikey_decrypt(rlm_rcode_t *p_result, module_ctx_t const *mctx, + request_t *request, char const *passcode); /* * validate.c - Connection pool and validation functions @@ -67,7 +68,8 @@ int rlm_yubikey_ykclient_init(CONF_SECTION *conf, rlm_yubikey_t *inst); int rlm_yubikey_ykclient_detach(rlm_yubikey_t *inst); -unlang_action_t rlm_yubikey_validate(rlm_rcode_t *p_result, rlm_yubikey_t const *inst, request_t *request, char const *passcode); +unlang_action_t rlm_yubikey_validate(rlm_rcode_t *p_result, module_ctx_t const *mctx, + request_t *request, char const *passcode); extern HIDDEN fr_dict_attr_t const *attr_auth_type; extern HIDDEN fr_dict_attr_t const *attr_user_password; diff --git a/src/modules/rlm_yubikey/validate.c b/src/modules/rlm_yubikey/validate.c index df9b0ed251..b58b73c655 100644 --- a/src/modules/rlm_yubikey/validate.c +++ b/src/modules/rlm_yubikey/validate.c @@ -146,8 +146,10 @@ int rlm_yubikey_ykclient_detach(rlm_yubikey_t *inst) return 0; } -unlang_action_t rlm_yubikey_validate(rlm_rcode_t *p_result, rlm_yubikey_t const *inst, request_t *request, char const *passcode) +unlang_action_t rlm_yubikey_validate(rlm_rcode_t *p_result, module_ctx_t const *mctx, + request_t *request, char const *passcode) { + rlm_yubikey_t const *inst = talloc_get_type_abort(mctx->inst->data, rlm_yubikey_t); rlm_rcode_t rcode = RLM_MODULE_OK; ykclient_rc status; ykclient_handle_t *yandle; diff --git a/src/process/dhcpv6/base.c b/src/process/dhcpv6/base.c index 15a5140143..eae4266fa8 100644 --- a/src/process/dhcpv6/base.c +++ b/src/process/dhcpv6/base.c @@ -737,11 +737,11 @@ static unlang_action_t mod_process(rlm_rcode_t *p_result, module_ctx_t const *mc return state->recv(p_result, mctx, request); } -static int mod_bootstrap(void *instance, CONF_SECTION *cs) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - process_dhcpv6_t *inst = instance; + process_dhcpv6_t *inst = talloc_get_type_abort(mctx->inst->data, process_dhcpv6_t); - inst->server_cs = cf_section_find_in_parent(cs, "server", CF_IDENT_ANY); + inst->server_cs = cf_section_find_in_parent(mctx->inst->conf, "server", CF_IDENT_ANY); return 0; } diff --git a/src/process/eap_aka/base.c b/src/process/eap_aka/base.c index 0c111b3220..239b10ac5d 100644 --- a/src/process/eap_aka/base.c +++ b/src/process/eap_aka/base.c @@ -232,9 +232,9 @@ static virtual_server_compile_t const compile_list[] = { COMPILE_TERMINATOR }; -static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - eap_aka_sim_process_conf_t *inst = talloc_get_type_abort(instance, eap_aka_sim_process_conf_t); + eap_aka_sim_process_conf_t *inst = talloc_get_type_abort(mctx->inst->data, eap_aka_sim_process_conf_t); inst->type = FR_EAP_METHOD_AKA; diff --git a/src/process/eap_aka_prime/base.c b/src/process/eap_aka_prime/base.c index 984da47c31..0ee2d7c060 100644 --- a/src/process/eap_aka_prime/base.c +++ b/src/process/eap_aka_prime/base.c @@ -233,9 +233,9 @@ static virtual_server_compile_t const compile_list[] = { COMPILE_TERMINATOR }; -static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - eap_aka_sim_process_conf_t *inst = talloc_get_type_abort(instance, eap_aka_sim_process_conf_t); + eap_aka_sim_process_conf_t *inst = talloc_get_type_abort(mctx->inst->data, eap_aka_sim_process_conf_t); inst->type = FR_EAP_METHOD_AKA_PRIME; diff --git a/src/process/eap_sim/base.c b/src/process/eap_sim/base.c index e3d86efa3b..7fd8a8c8c6 100644 --- a/src/process/eap_sim/base.c +++ b/src/process/eap_sim/base.c @@ -220,9 +220,9 @@ static virtual_server_compile_t compile_list[] = { COMPILE_TERMINATOR }; -static int mod_instantiate(void *instance, UNUSED CONF_SECTION *conf) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - eap_aka_sim_process_conf_t *inst = talloc_get_type_abort(instance, eap_aka_sim_process_conf_t); + eap_aka_sim_process_conf_t *inst = talloc_get_type_abort(mctx->inst->data, eap_aka_sim_process_conf_t); inst->type = FR_EAP_METHOD_SIM; diff --git a/src/process/radius/base.c b/src/process/radius/base.c index cc4fc62926..14cf41b04a 100644 --- a/src/process/radius/base.c +++ b/src/process/radius/base.c @@ -775,9 +775,9 @@ static unlang_action_t mod_process(rlm_rcode_t *p_result, module_ctx_t const *mc return state->recv(p_result, mctx, request); } -static int mod_instantiate(void *instance, UNUSED CONF_SECTION *process_app_cs) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - process_radius_t *inst = instance; + process_radius_t *inst = talloc_get_type_abort(mctx->inst->data, process_radius_t); inst->auth.state_tree = fr_state_tree_init(inst, attr_state, main_config->spawn_workers, inst->auth.max_session, inst->auth.session_timeout, inst->auth.state_server_id, @@ -786,11 +786,11 @@ static int mod_instantiate(void *instance, UNUSED CONF_SECTION *process_app_cs) return 0; } -static int mod_bootstrap(void *instance, CONF_SECTION *cs) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - process_radius_t *inst = instance; + process_radius_t *inst = talloc_get_type_abort(mctx->inst->data, process_radius_t); - inst->server_cs = cf_section_find_in_parent(cs, "server", CF_IDENT_ANY); + inst->server_cs = cf_section_find_in_parent(mctx->inst->conf, "server", CF_IDENT_ANY); if (virtual_server_section_attribute_define(inst->server_cs, "authenticate", attr_auth_type) < 0) return -1; return 0; diff --git a/src/process/tacacs/base.c b/src/process/tacacs/base.c index 9942c40fa8..68f8371b79 100644 --- a/src/process/tacacs/base.c +++ b/src/process/tacacs/base.c @@ -578,9 +578,9 @@ static unlang_action_t mod_process(rlm_rcode_t *p_result, module_ctx_t const *mc } -static int mod_instantiate(void *instance, UNUSED CONF_SECTION *process_app_cs) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - process_tacacs_t *inst = instance; + process_tacacs_t *inst = talloc_get_type_abort(mctx->inst->data, process_tacacs_t); /* * Usually we use the 'State' attribute. But, in this @@ -596,12 +596,12 @@ static int mod_instantiate(void *instance, UNUSED CONF_SECTION *process_app_cs) return 0; } -static int mod_bootstrap(void *instance, CONF_SECTION *process_app_cs) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - process_tacacs_t *inst = instance; - CONF_SECTION *server_cs = cf_item_to_section(cf_parent(process_app_cs)); + process_tacacs_t *inst = talloc_get_type_abort(mctx->inst->data, process_tacacs_t); + CONF_SECTION *server_cs = cf_item_to_section(cf_parent(mctx->inst->conf)); - fr_assert(process_app_cs); + fr_assert(mctx->inst->conf); fr_assert(server_cs); fr_assert(strcmp(cf_section_name1(server_cs), "server") == 0); diff --git a/src/process/ttls/base.c b/src/process/ttls/base.c index 2cc0f6465a..6d3863773c 100644 --- a/src/process/ttls/base.c +++ b/src/process/ttls/base.c @@ -657,9 +657,9 @@ static unlang_action_t mod_process(rlm_rcode_t *p_result, module_ctx_t const *mc return state->recv(p_result, mctx, request); } -static int mod_instantiate(void *instance, UNUSED CONF_SECTION *process_app_cs) +static int mod_instantiate(module_inst_ctx_t const *mctx) { - process_ttls_t *inst = instance; + process_ttls_t *inst = talloc_get_type_abort(mctx->inst->data, process_ttls_t); inst->auth.state_tree = fr_state_tree_init(inst, attr_state, main_config->spawn_workers, inst->auth.max_session, inst->auth.session_timeout, inst->auth.state_server_id, @@ -668,11 +668,11 @@ static int mod_instantiate(void *instance, UNUSED CONF_SECTION *process_app_cs) return 0; } -static int mod_bootstrap(void *instance, CONF_SECTION *cs) +static int mod_bootstrap(module_inst_ctx_t const *mctx) { - process_ttls_t *inst = instance; + process_ttls_t *inst = talloc_get_type_abort(mctx->inst->data, process_ttls_t); - inst->server_cs = cf_section_find_in_parent(cs, "server", CF_IDENT_ANY); + inst->server_cs = cf_section_find_in_parent(mctx->inst->conf, "server", CF_IDENT_ANY); if (virtual_server_section_attribute_define(inst->server_cs, "authenticate", attr_auth_type) < 0) return -1; return 0;