From: Arran Cudbard-Bell Date: Mon, 19 Feb 2024 01:17:40 +0000 (-0600) Subject: Rename cf_section_has_parent to cf_section_find_parent and use that in the DNS modules X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=54e8bc78afdca0bbb223c09fc124ead52438da04;p=thirdparty%2Ffreeradius-server.git Rename cf_section_has_parent to cf_section_find_parent and use that in the DNS modules Also, just use the sandard comparison function instead of duplicating the comparison logic. --- diff --git a/src/lib/server/cf_file.c b/src/lib/server/cf_file.c index bdf1a962b12..07f4a4233ce 100644 --- a/src/lib/server/cf_file.c +++ b/src/lib/server/cf_file.c @@ -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; diff --git a/src/lib/server/cf_util.c b/src/lib/server/cf_util.c index 0f062bffc6e..7bdf524b363 100644 --- a/src/lib/server/cf_util.c +++ b/src/lib/server/cf_util.c @@ -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; } diff --git a/src/lib/server/cf_util.h b/src/lib/server/cf_util.h index 3eddaf0d774..6a31fb06dc2 100644 --- a/src/lib/server/cf_util.h +++ b/src/lib/server/cf_util.h @@ -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); diff --git a/src/listen/dns/proto_dns.c b/src/listen/dns/proto_dns.c index 4a289709bfb..3dacf56f5ad 100644 --- a/src/listen/dns/proto_dns.c +++ b/src/listen/dns/proto_dns.c @@ -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); diff --git a/src/listen/dns/proto_dns_udp.c b/src/listen/dns/proto_dns_udp.c index 000ce7252f6..a02bdbc950d 100644 --- a/src/listen/dns/proto_dns_udp.c +++ b/src/listen/dns/proto_dns_udp.c @@ -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); /*