]> 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:51:53 +0000 (19:51 +1000)
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".

(cherry picked from commit a3c6516a75786c5716beb56410186ecc52057983)

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

index 875d6f52a6d599de5fdf622e37f8a9fa4588424b..13da0ad16bc8c943b7da1b74e2be925953bb6ec0 100644 (file)
@@ -341,18 +341,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;
@@ -361,13 +359,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) {
@@ -383,14 +378,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 53558ff7e5c4a16c3258fecd084ffd5326ec64ed..5c923ecfef88dc95abc3fcc04bdffda91bb7708a 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 60da9c9b1ef0350d071fc7cc8cbcd60becd11e2d..ab3a24abdaac5c715c846b17aa0179e590a6d2dd 100644 (file)
@@ -3921,6 +3921,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'.
@@ -4236,7 +4238,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 32cc034963b3358b15041fa1f59000d3736fbbb8..97c2094ca2917216658df1bbfa7fccb99a1429e4 100644 (file)
@@ -729,6 +729,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) {
@@ -737,16 +741,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);