From: Mark Andrews Date: Sat, 18 Sep 2021 23:11:15 +0000 (+1000) Subject: Fix "check-names master" and "check-names slave" X-Git-Tag: v9.17.19~23^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a3c6516a75786c5716beb56410186ecc52057983;p=thirdparty%2Fbind9.git Fix "check-names master" and "check-names slave" check for type "master" / "slave" at the same time as checking for "primary" / "secondary" as we step through the maps. Checking "primary" then "master" or "master" then "primary" does not work as the synomym is not checked for to stop the search. Similarly with "secondary" and "slave". --- diff --git a/bin/named/config.c b/bin/named/config.c index fa5cfbc2aaf..0a54bb2ec70 100644 --- a/bin/named/config.c +++ b/bin/named/config.c @@ -343,18 +343,16 @@ named_config_get(cfg_obj_t const *const *maps, const char *name, const cfg_obj_t **obj) { int i; - for (i = 0;; i++) { - if (maps[i] == NULL) { - return (ISC_R_NOTFOUND); - } + for (i = 0; maps[i] != NULL; i++) { if (cfg_map_get(maps[i], name, obj) == ISC_R_SUCCESS) { return (ISC_R_SUCCESS); } } + return (ISC_R_NOTFOUND); } isc_result_t -named_checknames_get(const cfg_obj_t **maps, const char *which, +named_checknames_get(const cfg_obj_t **maps, const char *const names[], const cfg_obj_t **obj) { const cfg_listelt_t *element; const cfg_obj_t *checknames; @@ -363,13 +361,10 @@ named_checknames_get(const cfg_obj_t **maps, const char *which, int i; REQUIRE(maps != NULL); - REQUIRE(which != NULL); + REQUIRE(names != NULL); REQUIRE(obj != NULL && *obj == NULL); - for (i = 0;; i++) { - if (maps[i] == NULL) { - return (ISC_R_NOTFOUND); - } + for (i = 0; maps[i] != NULL; i++) { checknames = NULL; if (cfg_map_get(maps[i], "check-names", &checknames) == ISC_R_SUCCESS) { @@ -385,14 +380,19 @@ named_checknames_get(const cfg_obj_t **maps, const char *which, { value = cfg_listelt_value(element); type = cfg_tuple_get(value, "type"); - if (strcasecmp(cfg_obj_asstring(type), which) == - 0) { - *obj = cfg_tuple_get(value, "mode"); - return (ISC_R_SUCCESS); + + for (size_t j = 0; names[j] != NULL; j++) { + if (strcasecmp(cfg_obj_asstring(type), + names[j]) == 0) { + *obj = cfg_tuple_get(value, + "mode"); + return (ISC_R_SUCCESS); + } } } } } + return (ISC_R_NOTFOUND); } int diff --git a/bin/named/include/named/config.h b/bin/named/include/named/config.h index 27dc30aac6c..7c48ff0bb79 100644 --- a/bin/named/include/named/config.h +++ b/bin/named/include/named/config.h @@ -31,7 +31,7 @@ named_config_get(cfg_obj_t const *const *maps, const char *name, const cfg_obj_t **obj); isc_result_t -named_checknames_get(const cfg_obj_t **maps, const char *name, +named_checknames_get(const cfg_obj_t **maps, const char *const names[], const cfg_obj_t **obj); int diff --git a/bin/named/server.c b/bin/named/server.c index ae48993b604..f80ec23afff 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -4008,6 +4008,8 @@ minimal_cache_allowed(const cfg_obj_t *maps[4], return (true); } +static const char *const response_synonyms[] = { "response", NULL }; + /* * Configure 'view' according to 'vconfig', taking defaults from * 'config' where values are missing in 'vconfig'. @@ -4323,7 +4325,7 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, /* Check-names. */ obj = NULL; - result = named_checknames_get(maps, "response", &obj); + result = named_checknames_get(maps, response_synonyms, &obj); INSIST(result == ISC_R_SUCCESS); str = cfg_obj_asstring(obj); diff --git a/bin/named/zoneconf.c b/bin/named/zoneconf.c index 5b3528eea84..b99899f50fa 100644 --- a/bin/named/zoneconf.c +++ b/bin/named/zoneconf.c @@ -750,6 +750,10 @@ strtoargv(isc_mem_t *mctx, char *s, unsigned int *argcp, char ***argvp) { return (strtoargvsub(mctx, s, argcp, argvp, 0)); } +static const char *const primary_synonyms[] = { "primary", "master", NULL }; + +static const char *const secondary_synonyms[] = { "secondary", "slave", NULL }; + static void checknames(dns_zonetype_t ztype, const cfg_obj_t **maps, const cfg_obj_t **objp) { @@ -758,16 +762,10 @@ checknames(dns_zonetype_t ztype, const cfg_obj_t **maps, switch (ztype) { case dns_zone_secondary: case dns_zone_mirror: - result = named_checknames_get(maps, "secondary", objp); - if (result != ISC_R_SUCCESS) { - result = named_checknames_get(maps, "slave", objp); - } + result = named_checknames_get(maps, secondary_synonyms, objp); break; case dns_zone_primary: - result = named_checknames_get(maps, "primary", objp); - if (result != ISC_R_SUCCESS) { - result = named_checknames_get(maps, "master", objp); - } + result = named_checknames_get(maps, primary_synonyms, objp); break; default: INSIST(0);