]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix "check-names master" and "check-names slave"
authorMark Andrews <marka@isc.org>
Sat, 18 Sep 2021 23:11:15 +0000 (09:11 +1000)
committerMark Andrews <marka@isc.org>
Wed, 29 Sep 2021 09:18:59 +0000 (09:18 +0000)
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".

bin/named/config.c
bin/named/include/named/config.h
bin/named/server.c
bin/named/zoneconf.c

index fa5cfbc2aaf1e792d91ec9b4f22a206994d5b458..0a54bb2ec7099e40dc46b94df79ea10149a50447 100644 (file)
@@ -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
index 27dc30aac6c5750947487c3a03044648d5f325cf..7c48ff0bb798dc20647b3a1d899709276e2dea45 100644 (file)
@@ -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
index ae48993b6046ccf3ad9f80b3149c5e8e1a9f37e5..f80ec23afff3e9778ca0c3c532ef4173e4c3d315 100644 (file)
@@ -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);
index 5b3528eea84a399bde12188ea51c9c4091f17460..b99899f50fac44cfd5da038b43e1ed717f857d1a 100644 (file)
@@ -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);