]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
some modules can _only_ be used in one namespace
authorAlan T. DeKok <aland@freeradius.org>
Thu, 24 Apr 2025 11:38:56 +0000 (07:38 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 24 Apr 2025 15:46:35 +0000 (11:46 -0400)
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

src/lib/server/module.h
src/lib/unlang/compile.c
src/modules/rlm_radius/rlm_radius.c
src/modules/rlm_tacacs/rlm_tacacs.c

index e734bce8ab9d0a13fd5a24165aa89fe16b450308..cc7497e52a80415f4e8f8c74a0f4f506d8ea5a35 100644 (file)
@@ -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.
index 228b4c0090fe5c8db68c2ca8b175a632075539d8..07dafc94a5b9fd1ca93981fee5b6a65fa610ea0b 100644 (file)
@@ -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;
index 46f59c27a79000fd079df0842ea848390fcf2a6b..548c366d348f59a5df21e37bd94137e4ae8176ee 100644 (file)
@@ -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,
index 7726cc5ca69687a52d4766188008f39f9679184d..0eead8873f4475fcfff58e612bd28f90949a5da2 100644 (file)
@@ -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,