From: Arran Cudbard-Bell Date: Wed, 2 Mar 2022 14:57:25 +0000 (-0600) Subject: Explicitly pass in the type of module we're loading to module_bootstrap X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e9a358c99410bce084027a423536f7ce57d37424;p=thirdparty%2Ffreeradius-server.git Explicitly pass in the type of module we're loading to module_bootstrap --- diff --git a/src/lib/server/module.c b/src/lib/server/module.c index 531b3068391..907cf05f9f0 100644 --- a/src/lib/server/module.c +++ b/src/lib/server/module.c @@ -696,6 +696,11 @@ static int _module_instance_free(module_instance_t *mi) * Load the module shared library, allocate instance data for it, * parse the module configuration, and call the modules "bootstrap" method. * + * @param[in] type What type of module we're loading. Determines the prefix + * added to the library name. Should be one of: + * - DL_MODULE_TYPE_MODULE - Standard backend module. + * - DL_MODULE_TYPE_SUBMODULE - Usually a driver for a backend module. + * - DL_MODULE_TYPE_PROCESS - Protocol state machine bound to a virtual server. * @param[in] parent of the module being bootstrapped, if this is a submodule. * If this is not a submodule parent must be NULL. * @param[in] cs containing the configuration for this module or submodule. @@ -704,12 +709,16 @@ static int _module_instance_free(module_instance_t *mi) * and private instance data. * - NULL on error. */ -module_instance_t *module_bootstrap(module_instance_t const *parent, CONF_SECTION *cs) +module_instance_t *module_bootstrap(dl_module_type_t type, module_instance_t const *parent, CONF_SECTION *cs) { char *inst_name = NULL; module_instance_t *mi; char const *name1 = cf_section_name1(cs); + fr_assert((type == DL_MODULE_TYPE_MODULE) || + (parent && (type == DL_MODULE_TYPE_SUBMODULE)) || + (type == DL_MODULE_TYPE_PROCESS)); + module_instance_name(NULL, &inst_name, parent, cs); /* @@ -731,9 +740,9 @@ module_instance_t *module_bootstrap(module_instance_t const *parent, CONF_SECTIO talloc_set_destructor(mi, _module_instance_free); if (dl_module_instance(mi, &mi->dl_inst, cs, - parent ? parent->dl_inst : NULL, - name1, - parent ? DL_MODULE_TYPE_SUBMODULE : DL_MODULE_TYPE_MODULE) < 0) { + parent ? parent->dl_inst : NULL, + name1, + type) < 0) { error: mi->name = inst_name; /* Assigned purely for debug log output when mi is freed */ talloc_free(mi); diff --git a/src/lib/server/module.h b/src/lib/server/module.h index a61f7b9de1d..83901a079f8 100644 --- a/src/lib/server/module.h +++ b/src/lib/server/module.h @@ -314,7 +314,8 @@ void modules_thread_detach(void); int modules_instantiate(CONF_SECTION *root) CC_HINT(nonnull); -module_instance_t *module_bootstrap(module_instance_t const *parent, CONF_SECTION *cs) CC_HINT(nonnull(2)); +module_instance_t *module_bootstrap(dl_module_type_t type, module_instance_t const *parent, CONF_SECTION *cs) + CC_HINT(nonnull(3)); int modules_rlm_bootstrap(CONF_SECTION *root) CC_HINT(nonnull); /** @} */ diff --git a/src/lib/server/module_rlm.c b/src/lib/server/module_rlm.c index e362e1103a9..ea891e28fad 100644 --- a/src/lib/server/module_rlm.c +++ b/src/lib/server/module_rlm.c @@ -1004,7 +1004,7 @@ int modules_rlm_bootstrap(CONF_SECTION *root) continue; } - mi = module_bootstrap(NULL, subcs); + mi = module_bootstrap(DL_MODULE_TYPE_MODULE, NULL, subcs); if (!mi) return -1; /* diff --git a/src/modules/rlm_cache/rlm_cache.c b/src/modules/rlm_cache/rlm_cache.c index e6b629e3f18..559b3d55f66 100644 --- a/src/modules/rlm_cache/rlm_cache.c +++ b/src/modules/rlm_cache/rlm_cache.c @@ -979,7 +979,7 @@ static int mod_bootstrap(module_inst_ctx_t const *mctx) /* * Load the appropriate driver for our backend */ - inst->driver_inst = module_bootstrap(module_by_data(inst), driver_cs); + inst->driver_inst = module_bootstrap(DL_MODULE_TYPE_SUBMODULE, module_by_data(inst), driver_cs); if (!inst->driver_inst) { cf_log_err(driver_cs, "Failed loading driver"); return -1; diff --git a/src/modules/rlm_eap/rlm_eap.c b/src/modules/rlm_eap/rlm_eap.c index 26c3a8db717..386ee8b69f3 100644 --- a/src/modules/rlm_eap/rlm_eap.c +++ b/src/modules/rlm_eap/rlm_eap.c @@ -1105,7 +1105,7 @@ static int mod_bootstrap(module_inst_ctx_t const *mctx) if (!submodule_cs) continue; /* Skipped as we don't have SSL support */ - submodule_inst = module_bootstrap(module_by_data(inst), submodule_cs); + submodule_inst = module_bootstrap(DL_MODULE_TYPE_SUBMODULE, module_by_data(inst), submodule_cs); if (!submodule_inst) return -1; submodule = (rlm_eap_submodule_t const *)submodule_inst->dl_inst->module->common;