From: Alan T. DeKok Date: Mon, 29 Apr 2019 15:33:06 +0000 (-0400) Subject: allow for subsections to be used in other sections. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=76feeb327dc6adfe9b8744dbb27d3e5be147f285;p=thirdparty%2Ffreeradius-server.git allow for subsections to be used in other sections. Finishing off the previous commit. --- diff --git a/src/lib/server/module.c b/src/lib/server/module.c index 6f0ceebc2e4..8d27ced919d 100644 --- a/src/lib/server/module.c +++ b/src/lib/server/module.c @@ -1436,6 +1436,7 @@ int modules_bootstrap(CONF_SECTION *root) typedef struct { char const *name1; char const *name2; + rlm_components_t component; } module_section_name_t; @@ -1460,7 +1461,7 @@ static int module_section_name_cmp(void const *one, void const *two) * This function is called from the virtual server bootstrap routine, * which happens before module_bootstrap(); */ -int module_section_register(char const *name1, char const *name2) +int module_section_register(char const *name1, char const *name2, rlm_components_t component) { module_section_name_t *sname; @@ -1479,6 +1480,7 @@ int module_section_register(char const *name1, char const *name2) sname->name1 = name1; sname->name2 = name2; + sname->component = component; if (!rbtree_insert(module_section_name_tree, sname)) { talloc_free(sname); @@ -1489,10 +1491,10 @@ int module_section_register(char const *name1, char const *name2) } -/** See if a named section exists +/** Find the component for a section * */ -bool module_section_exists(char const *name1, char const *name2) +int module_section_component(rlm_components_t *component, char const *name1, char const *name2) { module_section_name_t *sname; @@ -1504,10 +1506,10 @@ bool module_section_exists(char const *name1, char const *name2) if (name2 != CF_IDENT_ANY) { sname = rbtree_finddata(module_section_name_tree, &(module_section_name_t) { - .name1 = name2, - .name2 = CF_IDENT_ANY, - }); - if (sname) return true; + .name1 = name1, + .name2 = CF_IDENT_ANY, + }); + if (sname) goto done; } /* @@ -1518,5 +1520,10 @@ bool module_section_exists(char const *name1, char const *name2) .name1 = name1, .name2 = name2, }); - return (sname != NULL); + if (!sname) return -1; + +done: + *component = sname->component; + + return 0; } diff --git a/src/lib/server/module.h b/src/lib/server/module.h index 71d6863448b..558f01b75e2 100644 --- a/src/lib/server/module.h +++ b/src/lib/server/module.h @@ -253,9 +253,9 @@ bool module_section_type_set(REQUEST *request, fr_dict_attr_t const *type_da, f int module_instance_read_only(TALLOC_CTX *ctx, char const *name); -int module_section_register(char const *name1, char const *name2); +int module_section_register(char const *name1, char const *name2, rlm_components_t component); -bool module_section_exists(char const *name1, char const *name2); +int module_section_component(rlm_components_t *component, char const *name1, char const *name2); /** @{ */ diff --git a/src/lib/server/virtual_servers.c b/src/lib/server/virtual_servers.c index 10d0bf8acd7..63ee9a40e95 100644 --- a/src/lib/server/virtual_servers.c +++ b/src/lib/server/virtual_servers.c @@ -1058,7 +1058,7 @@ int fr_app_process_bootstrap(CONF_SECTION *server, dl_instance_t **type_submodul for (j = 0; list[j].name != NULL; j++) { if (list[j].name == CF_IDENT_ANY) continue; - if (module_section_register(list[j].name, list[j].name2) < 0) { + if (module_section_register(list[j].name, list[j].name2, list[j].component) < 0) { cf_log_err(conf, "Failed registering section name for %s", app_process->name); return -1; diff --git a/src/lib/unlang/compile.c b/src/lib/unlang/compile.c index 371de40f2d8..2e68057496d 100644 --- a/src/lib/unlang/compile.c +++ b/src/lib/unlang/compile.c @@ -3173,12 +3173,15 @@ static unlang_t *compile_item(unlang_t *parent, /* * Allow for named subsections, to change processing method types. */ - if (name2 && module_section_exists(modrefname, name2)) { - /* - * @todo - change the parse rules? - */ - cf_log_err(ci, "Placeholder not implemented"); - return NULL; + if (name2 && (module_section_component(&component, modrefname, name2) == 0)) { + UPDATE_CTX2; + + c = compile_group(parent, &unlang_ctx2, cs, UNLANG_GROUP_TYPE_SIMPLE, parent_group_type, UNLANG_TYPE_GROUP); + if (!c) return NULL; + + c->name = modrefname; + c->debug_name = talloc_typed_asprintf(c, "%s %s", modrefname, name2); + return c; } #ifdef WITH_UNLANG