]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
allow for subsections to be used in other sections.
authorAlan T. DeKok <aland@freeradius.org>
Mon, 29 Apr 2019 15:33:06 +0000 (11:33 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 29 Apr 2019 15:33:06 +0000 (11:33 -0400)
Finishing off the previous commit.

src/lib/server/module.c
src/lib/server/module.h
src/lib/server/virtual_servers.c
src/lib/unlang/compile.c

index 6f0ceebc2e4edb275076924165557aabbf1cbc82..8d27ced919d593e1c3013f7cccea4e7e06686ffb 100644 (file)
@@ -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;
 }
index 71d6863448bd483080781acfae2fa149e0fc759e..558f01b75e2d75ecee1bc759e7fa8756668ca0fc 100644 (file)
@@ -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);
 
 /** @{ */
 
index 10d0bf8acd7c664877c7d30105ddc7c3816b66c3..63ee9a40e9509bc679c65cfc032eb39a20d83a14 100644 (file)
@@ -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;
index 371de40f2d85aa7347bcdd9778257aed3a5aa293..2e68057496dd847d0a7f6d04b12d82d933fa01ba 100644 (file)
@@ -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