From: Alan T. DeKok Date: Wed, 8 Sep 2021 15:32:40 +0000 (-0400) Subject: allow in-line templates X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae1caff3e0f2df4b8ee900bf445bfcea536aa98c;p=thirdparty%2Ffreeradius-server.git allow in-line templates and skip them when defining modules. And when referencing an item, look in the template if it can't be found in the section. --- diff --git a/src/lib/server/cf_file.c b/src/lib/server/cf_file.c index 1aaae5fa00d..921c586fb3c 100644 --- a/src/lib/server/cf_file.c +++ b/src/lib/server/cf_file.c @@ -421,7 +421,7 @@ char const *cf_expand_variables(char const *cf, int lineno, } /* - * Merge the template so everyting else "just works". + * Merge the template so everything else "just works". */ static bool cf_template_merge(CONF_SECTION *cs, CONF_SECTION const *template) { @@ -1120,6 +1120,15 @@ static int process_template(cf_stack_t *stack) return -1; } + /* + * Allow in-line templates. + */ + templatecs = cf_section_find(cf_item_to_section(cf_parent(parent)), "template", stack->buff[2]); + if (templatecs) { + parent->template = templatecs; + return 0; + } + parent_cs = cf_root(parent); templatecs = cf_section_find(parent_cs, "templates", NULL); @@ -2648,6 +2657,7 @@ CONF_ITEM *cf_reference_item(CONF_SECTION const *parent_cs, *r = '\0'; *q = '\0'; next = cf_section_find(cs, p, r + 1); + if (!next && cs->template) next = cf_section_find(cs->template, p, r + 1); *r = '['; *q = ']'; @@ -2664,6 +2674,7 @@ CONF_ITEM *cf_reference_item(CONF_SECTION const *parent_cs, } else { *q = '\0'; next = cf_section_find(cs, p, NULL); + if (!next && cs->template) next = cf_section_find(cs->template, p, NULL); *q = '.'; } @@ -2681,6 +2692,7 @@ retry: * section. */ cp = cf_pair_find(cs, p); + if (!cp && cs->template) cp = cf_pair_find(cs->template, p); if (cp) { cp->referenced = true; /* conf pairs which are referenced count as used */ return &(cp->item); diff --git a/src/lib/server/module.c b/src/lib/server/module.c index e6781a0407f..765a8321e1e 100644 --- a/src/lib/server/module.c +++ b/src/lib/server/module.c @@ -1720,6 +1720,14 @@ int modules_bootstrap(CONF_SECTION *root) name = cf_section_name1(subcs); if (unlang_compile_is_keyword(name)) goto invalid_name; + /* + * Skip inline templates, and disallow "template { ... }" + */ + if (strcmp(name, "template") == 0) { + if (!cf_section_name2(subcs)) goto invalid_name; + continue; + } + instance = module_bootstrap(NULL, subcs); if (!instance) return -1;