]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Rename cf_section_has_parent to cf_section_find_parent and use that in the DNS modules
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 19 Feb 2024 01:17:40 +0000 (19:17 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 19 Feb 2024 01:25:03 +0000 (19:25 -0600)
Also, just use the sandard comparison function instead of duplicating the comparison logic.

src/lib/server/cf_file.c
src/lib/server/cf_util.c
src/lib/server/cf_util.h
src/listen/dns/proto_dns.c
src/listen/dns/proto_dns_udp.c

index bdf1a962b12f4513708a429ad7e41264db9b8b67..07f4a4233ce81c7ae0d86a8a18a4c4ddefa244f2 100644 (file)
@@ -145,7 +145,7 @@ typedef struct {
 
 static inline CC_HINT(always_inline) int cf_tmpl_rules_verify(CONF_SECTION *cs, tmpl_rules_t const *rules)
 {
-       if (cf_section_has_parent(cs, "policy", NULL)) {
+       if (cf_section_find_parent(cs, "policy", NULL)) {
                if (!fr_cond_assert_msg(!rules->attr.dict_def || (rules->attr.dict_def == fr_dict_internal()),
                                        "Protocol dictionary must be NULL not %s",
                                        fr_dict_root(rules->attr.dict_def)->name)) return -1;
index 0f062bffc6e549c8443be476258d7db45b7875fb..7bdf524b363946875c57eb34229960b7db09a63c 100644 (file)
@@ -995,7 +995,7 @@ CONF_SECTION *cf_section_find_next(CONF_SECTION const *cs, CONF_SECTION const *p
                                               CONF_ITEM_SECTION, name1, name2));
 }
 
-/** Find a CONF_SECTION with name1 and optionally name2 in the specified conf section of one of its parents
+/** Find a section in the lineage of a CONF_SECTION which matches a specific name1 and optionally name2.
  *
  * Will walk up the configuration tree, searching in each parent until a matching section is found or
  * we hit the root.
@@ -1036,30 +1036,16 @@ CONF_SECTION *cf_section_find_in_parent(CONF_SECTION const *cs,
  *     - The first matching subsection.
  *     - NULL if no subsections match.
  */
-CONF_SECTION *cf_section_has_parent(CONF_SECTION const *cs,
-                                   char const *name1, char const *name2)
+CONF_SECTION *cf_section_find_parent(CONF_SECTION const *cs,
+                                    char const *name1, char const *name2)
 {
-       CONF_ITEM *parent;
+       CONF_ITEM *parent = cf_section_to_item(cs);
 
-       for (parent = cf_parent(cf_section_to_item(cs));
-            parent != NULL;
-            parent = cf_parent(parent)) {
+       while ((parent = cf_parent(parent))) {
                CONF_SECTION *found = cf_item_to_section(parent);
 
-               if (IS_WILDCARD(name1)) return found;
-
-               if (strcmp(found->name1, name1) != 0) continue;
-
-               if (IS_WILDCARD(name2)) return found;
-
-               if (!name2) {
-                       if (!found->name2) return found;
-
-                       return NULL;
-               }
-
-               if (strcmp(found->name2, name2) == 0) return found;
-       }
+               if (cf_section_name_cmp(found, name1, name2) == 0) return found;
+       };
 
        return NULL;
 }
index 3eddaf0d77494ff664978758e6a7ff6c634183ab..6a31fb06dc2140d299017d2591d00b54f967d18d 100644 (file)
@@ -154,7 +154,7 @@ CONF_SECTION        *cf_section_find_next(CONF_SECTION const *cs, CONF_SECTION const *s
                                      char const *name1, char const *name2);
 CONF_SECTION   *cf_section_find_in_parent(CONF_SECTION const *cs,
                                           char const *name1, char const *name2);
-CONF_SECTION   *cf_section_has_parent(CONF_SECTION const *cs,
+CONF_SECTION   *cf_section_find_parent(CONF_SECTION const *cs,
                                       char const *name1, char const *name2);
 
 char const     *cf_section_value_find(CONF_SECTION const *, char const *attr);
index 4a289709bfbba56995b4661c17e9252f105eec12..3dacf56f5ada77aaa9960207f4b0cb0b754a257a 100644 (file)
@@ -386,7 +386,7 @@ static int mod_bootstrap(module_inst_ctx_t const *mctx)
        /*
         *      Ensure that the server CONF_SECTION is always set.
         */
-       inst->io.server_cs = cf_section_find_in_parent(mctx->inst->conf, "server", CF_IDENT_ANY);
+       inst->io.server_cs = cf_section_find_parent(mctx->inst->conf, "server", CF_IDENT_ANY);
 
        fr_assert(dict_dns != NULL);
        fr_assert(attr_packet_type != NULL);
index 000ce7252f6aa5acd1089eb83a54fe7578bfbf6f..a02bdbc950d73816551abc23068c92c54a71ef1d 100644 (file)
@@ -391,7 +391,7 @@ static int mod_bootstrap(module_inst_ctx_t const *mctx)
                }
        }
 
-       server_cs = cf_section_find_in_parent(inst->cs, "server", CF_IDENT_ANY);
+       server_cs = cf_section_find_parent(inst->cs, "server", CF_IDENT_ANY);
        fr_assert(server_cs != NULL);
 
        /*