From: Arran Cudbard-Bell Date: Fri, 10 May 2024 04:17:42 +0000 (-0600) Subject: Use the prefix of the deepest module when loading submodules X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fcb4091028b98805f6dce57c8d1263e021bb11b4;p=thirdparty%2Ffreeradius-server.git Use the prefix of the deepest module when loading submodules --- diff --git a/src/lib/server/dl_module.c b/src/lib/server/dl_module.c index d774ec42241..48bd61d4573 100644 --- a/src/lib/server/dl_module.c +++ b/src/lib/server/dl_module.c @@ -74,6 +74,44 @@ static int8_t dl_module_cmp(void const *one, void const *two) return CMP(ret, 0); } +/** Find the module's shallowest parent, or the child if no parents are found + * + * @param[in] child to locate the root for. + * @return + * - The module's shallowest parent. + * - NULL on error. + */ +static dl_module_t const *dl_module_root(dl_module_t const *child) +{ + dl_module_t const *next; + + for (;;) { + next = child->parent; + if (!next) break; + + child = next; + } + + return child; +} + +/** Return the prefix string for the deepest module + * + * This is useful for submodules which don't have a prefix of their own. + * In this case we need to use the prefix of the shallowest module, which + * will be a proto or rlm module. + * + * @param[in] module to get the prefix for. + * @return The prefix string for the shallowest module. + */ +static inline CC_HINT(always_inline) +char const *dl_module_root_prefix_str(dl_module_t const *module) +{ + dl_module_t const *root = dl_module_root(module); + + return fr_table_str_by_value(dl_module_type_prefix, root->type, ""); +} + /** Call the load() function in a module's exported structure * * @param[in] dl to call the load function for. @@ -289,8 +327,7 @@ dl_module_t *dl_module_alloc(dl_module_t const *parent, char const *name, dl_mod if (parent) { module_name = talloc_typed_asprintf(NULL, "%s_%s_%s", - fr_table_str_by_value(dl_module_type_prefix, - parent->type, ""), + dl_module_root_prefix_str(parent), parent->exported->name, name); } else { module_name = talloc_typed_asprintf(NULL, "%s_%s",