From: Alan T. DeKok Date: Thu, 24 Apr 2025 11:38:56 +0000 (-0400) Subject: some modules can _only_ be used in one namespace X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dff6e4e9ed1137750c05e80fa6aab4da9dc4b8dd;p=thirdparty%2Ffreeradius-server.git some modules can _only_ be used in one namespace so we add the namespace to the module configuration, and then check for it when we compile the reference to the module. We also add a reference to the online documentation, so the user knows what to do in order to fix the issue --- diff --git a/src/lib/server/module.h b/src/lib/server/module.h index e734bce8ab9..cc7497e52a8 100644 --- a/src/lib/server/module.h +++ b/src/lib/server/module.h @@ -196,6 +196,7 @@ struct module_s { DL_MODULE_COMMON; //!< Common fields for all loadable modules. conf_parser_t const *config; //!< How to convert a CONF_SECTION to a module instance. + fr_dict_t const **dict; //!< _required_ dictionary for this module. size_t boot_size; //!< Size of the module's bootstrap data. char const *boot_type; //!< talloc type to assign to bootstrap data. diff --git a/src/lib/unlang/compile.c b/src/lib/unlang/compile.c index 228b4c0090f..07dafc94a5b 100644 --- a/src/lib/unlang/compile.c +++ b/src/lib/unlang/compile.c @@ -4625,6 +4625,16 @@ static unlang_t *compile_module(unlang_t *parent, unlang_compile_t *unlang_ctx, return NULL; } + if (m->mmc.rlm->common.dict && + !fr_dict_compatible(*m->mmc.rlm->common.dict, unlang_ctx->rules->attr.dict_def)) { + cf_log_err(ci, "The '%s' module can only be used within a '%s' namespace.", + m->mmc.rlm->common.name, fr_dict_root(*m->mmc.rlm->common.dict)->name); + cf_log_err(ci, "Please use the 'subrequest' keyword to change namespaces"); + cf_log_err(ci, DOC_KEYWORD_REF(subrequest)); + talloc_free(m); + return NULL; + } + c = unlang_module_to_generic(m); c->parent = parent; c->next = NULL; diff --git a/src/modules/rlm_radius/rlm_radius.c b/src/modules/rlm_radius/rlm_radius.c index 46f59c27a79..548c366d348 100644 --- a/src/modules/rlm_radius/rlm_radius.c +++ b/src/modules/rlm_radius/rlm_radius.c @@ -1067,6 +1067,7 @@ module_rlm_t rlm_radius = { .name = "radius", .inst_size = sizeof(rlm_radius_t), .config = module_config, + .dict = &dict_radius, .onload = mod_load, .unload = mod_unload, diff --git a/src/modules/rlm_tacacs/rlm_tacacs.c b/src/modules/rlm_tacacs/rlm_tacacs.c index 7726cc5ca69..0eead8873f4 100644 --- a/src/modules/rlm_tacacs/rlm_tacacs.c +++ b/src/modules/rlm_tacacs/rlm_tacacs.c @@ -258,6 +258,7 @@ module_rlm_t rlm_tacacs = { .name = "tacacs", .inst_size = sizeof(rlm_tacacs_t), .config = module_config, + .dict = &dict_tacacs, .onload = mod_load, .unload = mod_unload,