]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Explicitly pass in the type of module we're loading to module_bootstrap
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 2 Mar 2022 14:57:25 +0000 (08:57 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 2 Mar 2022 14:57:25 +0000 (08:57 -0600)
src/lib/server/module.c
src/lib/server/module.h
src/lib/server/module_rlm.c
src/modules/rlm_cache/rlm_cache.c
src/modules/rlm_eap/rlm_eap.c

index 531b3068391f4047e87036bea583dbcefb5fc420..907cf05f9f0b75c58aef349b3686015efa2c21e7 100644 (file)
@@ -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);
index a61f7b9de1da5c5e668fa7c5cb7dbd58162f34c8..83901a079f8a95daaa569cbd0bfcc2da99d75835 100644 (file)
@@ -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);
 /** @} */
index e362e1103a97deffc46a706ea5b20498bd73fa1a..ea891e28fadaa5d96cea56224b7b5ba060db7bae 100644 (file)
@@ -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;
 
                /*
index e6b629e3f187edf32d53b4275642ef526e0d9296..559b3d55f665a586bd067772dca1e36a9e5a0399 100644 (file)
@@ -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;
index 26c3a8db71714f6f417bb39238afc7b824c1afef..386ee8b69f3f756277067795a9f4fd155fd3fe64 100644 (file)
@@ -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;