]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
allow in-line templates
authorAlan T. DeKok <aland@freeradius.org>
Wed, 8 Sep 2021 15:32:40 +0000 (11:32 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 8 Sep 2021 15:34:22 +0000 (11:34 -0400)
and skip them when defining modules.

And when referencing an item, look in the template if it can't
be found in the section.

src/lib/server/cf_file.c
src/lib/server/module.c

index 1aaae5fa00d6e9510ebb7b79ae1db83115f5ab87..921c586fb3c5189ab20c01d9b7b36a9a84f429de 100644 (file)
@@ -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);
index e6781a0407f46eefec5d8f3cb2cb985594a41ad5..765a8321e1e16a5d466e4d644579dbacac914293 100644 (file)
@@ -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;