]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
add CFG_LIST_FOREACH macro
authorEvan Hunt <each@isc.org>
Thu, 27 Mar 2025 01:54:05 +0000 (18:54 -0700)
committerEvan Hunt <each@isc.org>
Wed, 28 May 2025 04:08:09 +0000 (21:08 -0700)
replace the pattern `for (elt = cfg_list_first(x); elt != NULL;
elt = cfg_list_next(elt))` with a new `CFG_LIST_FOREACH` macro.

19 files changed:
.clang-format
bin/check/named-checkconf.c
bin/delv/delv.c
bin/dnssec/dnssectool.c
bin/named/config.c
bin/named/controlconf.c
bin/named/logconf.c
bin/named/server.c
bin/named/statschannel.c
bin/named/transportconf.c
bin/named/tsigconf.c
bin/named/zoneconf.c
bin/rndc/rndc.c
lib/isccfg/aclconf.c
lib/isccfg/check.c
lib/isccfg/include/isccfg/cfg.h
lib/isccfg/kaspconf.c
lib/isccfg/parser.c
tests/isccfg/duration_test.c

index bfa81bee45181319cfa4503af788b80cd3d104c8..57e98f24536729964ef3759402076b63764e18c2 100644 (file)
@@ -78,6 +78,6 @@ PenaltyBreakString: 80
 PenaltyExcessCharacter: 100
 Standard: Cpp11
 ContinuationIndentWidth: 8
-ForEachMacros: [ 'cds_lfs_for_each', 'cds_lfs_for_each_safe', 'cds_list_for_each_entry_safe', 'ISC_LIST_FOREACH', 'ISC_LIST_FOREACH_SAFE', 'ISC_LIST_FOREACH_REV', 'ISC_LIST_FOREACH_REV_SAFE', 'MSG_SECTION_FOREACH', 'DNS_RDATASET_FOREACH' ]
+ForEachMacros: [ 'cds_lfs_for_each', 'cds_lfs_for_each_safe', 'cds_list_for_each_entry_safe', 'ISC_LIST_FOREACH', 'ISC_LIST_FOREACH_SAFE', 'ISC_LIST_FOREACH_REV', 'ISC_LIST_FOREACH_REV_SAFE', 'MSG_SECTION_FOREACH', 'DNS_RDATASET_FOREACH', 'CFG_LIST_FOREACH' ]
 RemoveParentheses: ReturnStatement
 RemoveSemicolon: true
index abdd78e8e49a6f9aadcf6818d5c76daecb5a4fcc..5f5f635ecdfc1e97ed5f545e78d7cd6b6be14637 100644 (file)
@@ -106,10 +106,9 @@ get_maps(const cfg_obj_t **maps, const char *name, const cfg_obj_t **obj) {
 
 static bool
 get_checknames(const cfg_obj_t **maps, const cfg_obj_t **obj) {
-       const cfg_listelt_t *element;
-       const cfg_obj_t *checknames;
-       const cfg_obj_t *type;
-       const cfg_obj_t *value;
+       const cfg_obj_t *checknames = NULL;
+       const cfg_obj_t *type = NULL;
+       const cfg_obj_t *value = NULL;
        isc_result_t result;
        int i;
 
@@ -126,9 +125,7 @@ get_checknames(const cfg_obj_t **maps, const cfg_obj_t **obj) {
                        *obj = checknames;
                        return true;
                }
-               for (element = cfg_list_first(checknames); element != NULL;
-                    element = cfg_list_next(element))
-               {
+               CFG_LIST_FOREACH (checknames, element) {
                        value = cfg_listelt_value(element);
                        type = cfg_tuple_get(value, "type");
                        if ((strcasecmp(cfg_obj_asstring(type), "primary") !=
@@ -471,9 +468,8 @@ configure_zone(const char *vclass, const char *view, const cfg_obj_t *zconfig,
 static isc_result_t
 configure_view(const char *vclass, const char *view, const cfg_obj_t *config,
               const cfg_obj_t *vconfig, isc_mem_t *mctx, bool list) {
-       const cfg_listelt_t *element;
-       const cfg_obj_t *voptions;
-       const cfg_obj_t *zonelist;
+       const cfg_obj_t *voptions = NULL;
+       const cfg_obj_t *zonelist = NULL;
        isc_result_t result = ISC_R_SUCCESS;
        isc_result_t tresult;
 
@@ -489,9 +485,7 @@ configure_view(const char *vclass, const char *view, const cfg_obj_t *config,
                (void)cfg_map_get(config, "zone", &zonelist);
        }
 
-       for (element = cfg_list_first(zonelist); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (zonelist, element) {
                const cfg_obj_t *zconfig = cfg_listelt_value(element);
                tresult = configure_zone(vclass, view, zconfig, vconfig, config,
                                         mctx, list);
@@ -520,18 +514,15 @@ config_getclass(const cfg_obj_t *classobj, dns_rdataclass_t defclass,
 static isc_result_t
 load_zones_fromconfig(const cfg_obj_t *config, isc_mem_t *mctx,
                      bool list_zones) {
-       const cfg_listelt_t *element;
-       const cfg_obj_t *views;
-       const cfg_obj_t *vconfig;
+       const cfg_obj_t *views = NULL;
+       const cfg_obj_t *vconfig = NULL;
        isc_result_t result = ISC_R_SUCCESS;
        isc_result_t tresult;
 
        views = NULL;
 
        (void)cfg_map_get(config, "view", &views);
-       for (element = cfg_list_first(views); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (views, element) {
                const cfg_obj_t *classobj;
                dns_rdataclass_t viewclass;
                const char *vname;
index 9b9de4034607b6af5280a2e9c571a3c0f3819727..2a4bc30f3d04ed6dde1afba5a57f387a4e5b457f 100644 (file)
@@ -794,17 +794,12 @@ cleanup:
 
 static isc_result_t
 load_keys(const cfg_obj_t *keys, dns_client_t *client, dns_view_t *toview) {
-       const cfg_listelt_t *elt, *elt2;
-       const cfg_obj_t *key, *keylist;
+       const cfg_obj_t *key = NULL, *keylist = NULL;
        isc_result_t result = ISC_R_SUCCESS;
 
-       for (elt = cfg_list_first(keys); elt != NULL; elt = cfg_list_next(elt))
-       {
+       CFG_LIST_FOREACH (keys, elt) {
                keylist = cfg_listelt_value(elt);
-
-               for (elt2 = cfg_list_first(keylist); elt2 != NULL;
-                    elt2 = cfg_list_next(elt2))
-               {
+               CFG_LIST_FOREACH (keylist, elt2) {
                        key = cfg_listelt_value(elt2);
                        CHECK(key_fromconfig(key, client, toview));
                }
index 7864fc05db08aaddc30e943d34660cb84c4dedec..e766aae0e732152c668124e66924349f646cf618 100644 (file)
@@ -591,7 +591,6 @@ void
 kasp_from_conf(cfg_obj_t *config, isc_mem_t *mctx, const char *name,
               const char *keydir, dns_kasp_t **kaspp) {
        isc_result_t result = ISC_R_NOTFOUND;
-       const cfg_listelt_t *element = NULL;
        const cfg_obj_t *kasps = NULL;
        dns_kasplist_t kasplist;
        const cfg_obj_t *keystores = NULL;
@@ -602,9 +601,7 @@ kasp_from_conf(cfg_obj_t *config, isc_mem_t *mctx, const char *name,
        ISC_LIST_INIT(kslist);
 
        (void)cfg_map_get(config, "key-store", &keystores);
-       for (element = cfg_list_first(keystores); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (keystores, element) {
                cfg_obj_t *kconfig = cfg_listelt_value(element);
                result = cfg_keystore_fromconfig(kconfig, mctx, &kslist, NULL);
                if (result != ISC_R_SUCCESS) {
@@ -623,9 +620,7 @@ kasp_from_conf(cfg_obj_t *config, isc_mem_t *mctx, const char *name,
        dns_keystore_detach(&keystore);
 
        (void)cfg_map_get(config, "dnssec-policy", &kasps);
-       for (element = cfg_list_first(kasps); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (kasps, element) {
                dns_kasp_t *kasp = NULL;
 
                cfg_obj_t *kconfig = cfg_listelt_value(element);
index 7bbf429456da8a31723f52b91b20e6ec5d0125e1..e23f95111f4ccbc8d3690237bac282604117276d 100644 (file)
@@ -390,10 +390,9 @@ named_config_get(cfg_obj_t const *const *maps, const char *name,
 isc_result_t
 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;
-       const cfg_obj_t *type;
-       const cfg_obj_t *value;
+       const cfg_obj_t *checknames = NULL;
+       const cfg_obj_t *type = NULL;
+       const cfg_obj_t *value = NULL;
        int i;
 
        REQUIRE(maps != NULL);
@@ -412,9 +411,7 @@ named_checknames_get(const cfg_obj_t **maps, const char *const names[],
                                *obj = checknames;
                                return ISC_R_SUCCESS;
                        }
-                       for (element = cfg_list_first(checknames);
-                            element != NULL; element = cfg_list_next(element))
-                       {
+                       CFG_LIST_FOREACH (checknames, element) {
                                value = cfg_listelt_value(element);
                                type = cfg_tuple_get(value, "type");
 
@@ -435,10 +432,9 @@ named_checknames_get(const cfg_obj_t **maps, const char *const names[],
 
 int
 named_config_listcount(const cfg_obj_t *list) {
-       const cfg_listelt_t *e;
        int i = 0;
 
-       for (e = cfg_list_first(list); e != NULL; e = cfg_list_next(e)) {
+       CFG_LIST_FOREACH (list, e) {
                i++;
        }
 
@@ -516,7 +512,6 @@ named_config_getremotesdef(const cfg_obj_t *cctx, const char *list,
                           const char *name, const cfg_obj_t **ret) {
        isc_result_t result;
        const cfg_obj_t *obj = NULL;
-       const cfg_listelt_t *elt;
 
        REQUIRE(cctx != NULL);
        REQUIRE(name != NULL);
@@ -526,8 +521,7 @@ named_config_getremotesdef(const cfg_obj_t *cctx, const char *list,
        if (result != ISC_R_SUCCESS) {
                return result;
        }
-       elt = cfg_list_first(obj);
-       while (elt != NULL) {
+       CFG_LIST_FOREACH (obj, elt) {
                obj = cfg_listelt_value(elt);
                if (strcasecmp(cfg_obj_asstring(cfg_tuple_get(obj, "name")),
                               name) == 0)
@@ -535,8 +529,8 @@ named_config_getremotesdef(const cfg_obj_t *cctx, const char *list,
                        *ret = obj;
                        return ISC_R_SUCCESS;
                }
-               elt = cfg_list_next(elt);
        }
+
        return ISC_R_NOTFOUND;
 }
 
index e1460b1a26faa35d00c9b4f923bb664985ed2da1..7fae6c8f5165a8f759a435e7452318a65a4b08cc 100644 (file)
@@ -676,39 +676,30 @@ named_controls_shutdown(named_controls_t *controls) {
 static isc_result_t
 cfgkeylist_find(const cfg_obj_t *keylist, const char *keyname,
                const cfg_obj_t **objp) {
-       const cfg_listelt_t *element = NULL;
        const char *str = NULL;
        const cfg_obj_t *obj = NULL;
 
-       for (element = cfg_list_first(keylist); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (keylist, element) {
                obj = cfg_listelt_value(element);
                str = cfg_obj_asstring(cfg_map_getname(obj));
                if (strcasecmp(str, keyname) == 0) {
-                       break;
+                       *objp = obj;
+                       return ISC_R_SUCCESS;
                }
        }
-       if (element == NULL) {
-               return ISC_R_NOTFOUND;
-       }
-       obj = cfg_listelt_value(element);
-       *objp = obj;
-       return ISC_R_SUCCESS;
+
+       return ISC_R_NOTFOUND;
 }
 
 static void
 controlkeylist_fromcfg(const cfg_obj_t *keylist, isc_mem_t *mctx,
                       controlkeylist_t *keyids) {
-       const cfg_listelt_t *element = NULL;
        char *newstr = NULL;
        const char *str = NULL;
        const cfg_obj_t *obj = NULL;
        controlkey_t *key = NULL;
 
-       for (element = cfg_list_first(keylist); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (keylist, element) {
                obj = cfg_listelt_value(element);
                str = cfg_obj_asstring(obj);
                newstr = isc_mem_strdup(mctx, str);
@@ -1147,7 +1138,6 @@ named_controls_configure(named_controls_t *cp, const cfg_obj_t *config,
        controllistener_t *listener = NULL;
        controllistenerlist_t new_listeners;
        const cfg_obj_t *controlslist = NULL;
-       const cfg_listelt_t *element, *element2;
        char socktext[ISC_SOCKADDR_FORMATSIZE];
 
        ISC_LIST_INIT(new_listeners);
@@ -1166,9 +1156,7 @@ named_controls_configure(named_controls_t *cp, const cfg_obj_t *config,
         * address-in-use error.
         */
        if (controlslist != NULL) {
-               for (element = cfg_list_first(controlslist); element != NULL;
-                    element = cfg_list_next(element))
-               {
+               CFG_LIST_FOREACH (controlslist, element) {
                        const cfg_obj_t *controls = NULL;
                        const cfg_obj_t *inetcontrols = NULL;
                        const cfg_obj_t *unixcontrols = NULL;
@@ -1188,10 +1176,7 @@ named_controls_configure(named_controls_t *cp, const cfg_obj_t *config,
                                continue;
                        }
 
-                       for (element2 = cfg_list_first(inetcontrols);
-                            element2 != NULL;
-                            element2 = cfg_list_next(element2))
-                       {
+                       CFG_LIST_FOREACH (inetcontrols, element2) {
                                const cfg_obj_t *control = NULL;
                                const cfg_obj_t *obj = NULL;
                                isc_sockaddr_t addr;
index 64d0d0eba88f4637ed384144cac5a8473ba7d39a..f9311c7cef3d85c107389fc8153ee36b2923b972 100644 (file)
@@ -45,7 +45,6 @@ category_fromconf(const cfg_obj_t *ccat, isc_logconfig_t *logconfig) {
        const char *catname;
        isc_logcategory_t category;
        const cfg_obj_t *destinations = NULL;
-       const cfg_listelt_t *element = NULL;
 
        catname = cfg_obj_asstring(cfg_tuple_get(ccat, "name"));
        category = isc_log_categorybyname(catname);
@@ -63,9 +62,7 @@ category_fromconf(const cfg_obj_t *ccat, isc_logconfig_t *logconfig) {
        }
 
        destinations = cfg_tuple_get(ccat, "destinations");
-       for (element = cfg_list_first(destinations); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (destinations, element) {
                const cfg_obj_t *channel = cfg_listelt_value(element);
                const char *channelname = cfg_obj_asstring(channel);
 
@@ -316,10 +313,9 @@ named_logconfig(isc_logconfig_t *logconfig, const cfg_obj_t *logstmt) {
        isc_result_t result;
        const cfg_obj_t *channels = NULL;
        const cfg_obj_t *categories = NULL;
-       const cfg_listelt_t *element;
        bool default_set = false;
        bool unmatched_set = false;
-       const cfg_obj_t *catname;
+       const cfg_obj_t *catname = NULL;
 
        if (logconfig != NULL) {
                named_log_setdefaultchannels(logconfig);
@@ -327,17 +323,13 @@ named_logconfig(isc_logconfig_t *logconfig, const cfg_obj_t *logstmt) {
        }
 
        (void)cfg_map_get(logstmt, "channel", &channels);
-       for (element = cfg_list_first(channels); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (channels, element) {
                const cfg_obj_t *channel = cfg_listelt_value(element);
                CHECK(channel_fromconf(channel, logconfig));
        }
 
        (void)cfg_map_get(logstmt, "category", &categories);
-       for (element = cfg_list_first(categories); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (categories, element) {
                const cfg_obj_t *category = cfg_listelt_value(element);
                CHECK(category_fromconf(category, logconfig));
                if (!default_set) {
index 6533bff6e8be95015431b4f8c801cdb7d3e3ef1a..756ea9a0c688b38352c3ecbde2b3b99d8e920343 100644 (file)
@@ -613,7 +613,6 @@ configure_view_nametable(const cfg_obj_t *vconfig, const cfg_obj_t *config,
        isc_result_t result = ISC_R_SUCCESS;
        const cfg_obj_t *maps[3];
        const cfg_obj_t *obj = NULL;
-       const cfg_listelt_t *element = NULL;
        int i = 0;
        dns_fixedname_t fixed;
        dns_name_t *name = NULL;
@@ -654,9 +653,7 @@ configure_view_nametable(const cfg_obj_t *vconfig, const cfg_obj_t *config,
        }
 
        name = dns_fixedname_initname(&fixed);
-       for (element = cfg_list_first(obj); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (obj, element) {
                nameobj = cfg_listelt_value(element);
                str = cfg_obj_asstring(nameobj);
                isc_buffer_constinit(&b, str, strlen(str));
@@ -984,20 +981,16 @@ done:
 static isc_result_t
 load_view_keys(const cfg_obj_t *keys, dns_view_t *view, bool managed,
               const dns_name_t *keyname) {
-       const cfg_listelt_t *elt, *elt2;
-       const cfg_obj_t *keylist;
        isc_result_t result;
+       const cfg_obj_t *keylist = NULL;
        dns_keytable_t *secroots = NULL;
 
        CHECK(dns_view_getsecroots(view, &secroots));
 
-       for (elt = cfg_list_first(keys); elt != NULL; elt = cfg_list_next(elt))
-       {
+       CFG_LIST_FOREACH (keys, elt) {
                keylist = cfg_listelt_value(elt);
 
-               for (elt2 = cfg_list_first(keylist); elt2 != NULL;
-                    elt2 = cfg_list_next(elt2))
-               {
+               CFG_LIST_FOREACH (keylist, elt2) {
                        CHECK(process_key(cfg_listelt_value(elt2), secroots,
                                          keyname, view, managed));
                }
@@ -1584,11 +1577,10 @@ configure_dyndb(const cfg_obj_t *dyndb, isc_mem_t *mctx,
 static isc_result_t
 disable_algorithms(const cfg_obj_t *disabled, dns_resolver_t *resolver) {
        isc_result_t result;
-       const cfg_obj_t *algorithms;
-       const cfg_listelt_t *element;
-       const char *str;
+       const cfg_obj_t *algorithms = NULL;
+       const char *str = NULL;
        dns_fixedname_t fixed;
-       dns_name_t *name;
+       dns_name_t *name = NULL;
        isc_buffer_t b;
 
        name = dns_fixedname_initname(&fixed);
@@ -1598,9 +1590,7 @@ disable_algorithms(const cfg_obj_t *disabled, dns_resolver_t *resolver) {
        CHECK(dns_name_fromtext(name, &b, dns_rootname, 0));
 
        algorithms = cfg_tuple_get(disabled, "algorithms");
-       for (element = cfg_list_first(algorithms); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (algorithms, element) {
                isc_textregion_t r;
                dns_secalg_t alg;
 
@@ -1627,11 +1617,10 @@ cleanup:
 static isc_result_t
 disable_ds_digests(const cfg_obj_t *disabled, dns_resolver_t *resolver) {
        isc_result_t result;
-       const cfg_obj_t *digests;
-       const cfg_listelt_t *element;
-       const char *str;
+       const cfg_obj_t *digests = NULL;
+       const char *str = NULL;
        dns_fixedname_t fixed;
-       dns_name_t *name;
+       dns_name_t *name = NULL;
        isc_buffer_t b;
 
        name = dns_fixedname_initname(&fixed);
@@ -1641,9 +1630,7 @@ disable_ds_digests(const cfg_obj_t *disabled, dns_resolver_t *resolver) {
        CHECK(dns_name_fromtext(name, &b, dns_rootname, 0));
 
        digests = cfg_tuple_get(disabled, "digests");
-       for (element = cfg_list_first(digests); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (digests, element) {
                isc_textregion_t r;
                dns_dsdigest_t digest;
 
@@ -1665,19 +1652,16 @@ cleanup:
 
 static bool
 on_disable_list(const cfg_obj_t *disablelist, dns_name_t *zonename) {
-       const cfg_listelt_t *element;
        dns_fixedname_t fixed;
-       dns_name_t *name;
+       dns_name_t *name = NULL;
        isc_result_t result;
-       const cfg_obj_t *value;
-       const char *str;
+       const cfg_obj_t *value = NULL;
+       const char *str = NULL;
        isc_buffer_t b;
 
        name = dns_fixedname_initname(&fixed);
 
-       for (element = cfg_list_first(disablelist); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (disablelist, element) {
                value = cfg_listelt_value(element);
                str = cfg_obj_asstring(value);
                isc_buffer_constinit(&b, str, strlen(str));
@@ -2105,24 +2089,23 @@ configure_rpz_zone(dns_view_t *view, const cfg_listelt_t *element,
 static isc_result_t
 configure_rpz(dns_view_t *view, dns_view_t *pview, const cfg_obj_t *rpz_obj,
              bool *old_rpz_okp) {
-       const cfg_listelt_t *zone_element;
-       const cfg_obj_t *sub_obj;
+       const cfg_obj_t *zonelist = NULL;
+       const cfg_obj_t *sub_obj = NULL;
        bool recursive_only_default, add_soa_default;
        bool nsip_enabled, nsdname_enabled;
        dns_rpz_zbits_t nsip_on, nsdname_on;
        dns_ttl_t ttl_default;
        uint32_t minupdateinterval_default;
-       dns_rpz_zones_t *zones;
-       const dns_rpz_zones_t *old;
+       dns_rpz_zones_t *zones = NULL;
+       const dns_rpz_zones_t *old = NULL;
        bool pview_must_detach = false;
-       const dns_rpz_zone_t *old_zone;
+       const dns_rpz_zone_t *old_zone = NULL;
        isc_result_t result;
-       int i;
 
        *old_rpz_okp = false;
 
-       zone_element = cfg_list_first(cfg_tuple_get(rpz_obj, "zone list"));
-       if (zone_element == NULL) {
+       zonelist = cfg_tuple_get(rpz_obj, "zone list");
+       if (cfg_list_length(zonelist, false) == 0) {
                return ISC_R_SUCCESS;
        }
 
@@ -2232,9 +2215,8 @@ configure_rpz(dns_view_t *view, dns_view_t *pview, const cfg_obj_t *rpz_obj,
                *old_rpz_okp = true;
        }
 
-       for (i = 0; zone_element != NULL;
-            ++i, zone_element = cfg_list_next(zone_element))
-       {
+       int i = 0;
+       CFG_LIST_FOREACH (zonelist, zone_element) {
                INSIST(!*old_rpz_okp || old != NULL);
                if (*old_rpz_okp && i < old->p.num_zones) {
                        old_zone = old->zones[i];
@@ -2242,6 +2224,7 @@ configure_rpz(dns_view_t *view, dns_view_t *pview, const cfg_obj_t *rpz_obj,
                        *old_rpz_okp = false;
                        old_zone = NULL;
                }
+               i++;
                result = configure_rpz_zone(
                        view, zone_element, recursive_only_default,
                        add_soa_default, ttl_default, minupdateinterval_default,
@@ -2833,7 +2816,7 @@ static dns_catz_zonemodmethods_t ns_catz_zonemodmethods = {
 static isc_result_t
 configure_catz(dns_view_t *view, dns_view_t *pview, const cfg_obj_t *config,
               const cfg_obj_t *catz_obj) {
-       const cfg_listelt_t *zone_element = NULL;
+       const cfg_obj_t *zones = NULL;
        const dns_catz_zones_t *old = NULL;
        bool pview_must_detach = false;
        isc_result_t result;
@@ -2841,8 +2824,8 @@ configure_catz(dns_view_t *view, dns_view_t *pview, const cfg_obj_t *config,
        /* xxxwpk TODO do it cleaner, once, somewhere */
        ns_catz_cbdata.server = named_g_server;
 
-       zone_element = cfg_list_first(cfg_tuple_get(catz_obj, "zone list"));
-       if (zone_element == NULL) {
+       zones = cfg_tuple_get(catz_obj, "zone list");
+       if (cfg_list_length(zones, false) == 0) {
                return ISC_R_SUCCESS;
        }
 
@@ -2866,9 +2849,8 @@ configure_catz(dns_view_t *view, dns_view_t *pview, const cfg_obj_t *config,
                                                 &ns_catz_zonemodmethods);
        }
 
-       while (zone_element != NULL) {
+       CFG_LIST_FOREACH (zones, zone_element) {
                CHECK(configure_catz_zone(view, pview, config, zone_element));
-               zone_element = cfg_list_next(zone_element);
        }
 
        if (old != NULL) {
@@ -3118,22 +3100,21 @@ create_empty_zone(dns_zone_t *pzone, dns_name_t *name, dns_view_t *view,
                  const cfg_obj_t *zonelist, const char **empty_dbtype,
                  int empty_dbtypec, dns_zonestat_level_t statlevel) {
        char namebuf[DNS_NAME_FORMATSIZE];
-       const cfg_listelt_t *element;
-       const cfg_obj_t *obj;
-       const cfg_obj_t *zconfig;
-       const cfg_obj_t *zoptions;
+       const cfg_obj_t *obj = NULL;
+       const cfg_obj_t *zconfig = NULL;
+       const cfg_obj_t *zoptions = NULL;
        const char *default_dbtype[4] = { ZONEDB_DEFAULT };
        const char *sep = ": view ";
-       const char *str;
+       const char *str = NULL;
        const char *viewname = view->name;
        dns_db_t *db = NULL;
        dns_dbversion_t *version = NULL;
        dns_fixedname_t cfixed;
        dns_fixedname_t fixed;
        dns_fixedname_t nsfixed;
-       dns_name_t *contact;
-       dns_name_t *ns;
-       dns_name_t *zname;
+       dns_name_t *contact = NULL;
+       dns_name_t *ns = NULL;
+       dns_name_t *zname = NULL;
        dns_zone_t *zone = NULL;
        int default_dbtypec = 1;
        isc_result_t result;
@@ -3149,9 +3130,7 @@ create_empty_zone(dns_zone_t *pzone, dns_name_t *name, dns_view_t *view,
         * Look for forward "zones" beneath this empty zone and if so
         * create a custom db for the empty zone.
         */
-       for (element = cfg_list_first(zonelist); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (zonelist, element) {
                zconfig = cfg_listelt_value(element);
                str = cfg_obj_asstring(cfg_tuple_get(zconfig, "name"));
                CHECK(dns_name_fromstring(zname, str, dns_rootname, 0, NULL));
@@ -3385,9 +3364,8 @@ cleanup:
 static isc_result_t
 configure_dnstap(const cfg_obj_t **maps, dns_view_t *view) {
        isc_result_t result;
-       const cfg_obj_t *obj, *obj2;
-       const cfg_listelt_t *element;
-       const char *dpath;
+       const cfg_obj_t *obj = NULL, *obj2 = NULL;
+       const char *dpath = NULL;
        const cfg_obj_t *dlist = NULL;
        dns_dtmsgtype_t dttypes = 0;
        unsigned int i;
@@ -3398,10 +3376,8 @@ configure_dnstap(const cfg_obj_t **maps, dns_view_t *view) {
                return ISC_R_SUCCESS;
        }
 
-       for (element = cfg_list_first(dlist); element != NULL;
-            element = cfg_list_next(element))
-       {
-               const char *str;
+       CFG_LIST_FOREACH (dlist, element) {
+               const char *str = NULL;
                dns_dtmsgtype_t dt = 0;
 
                obj = cfg_listelt_value(element);
@@ -3726,20 +3702,19 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
        const cfg_obj_t *optionmaps[3];
        const cfg_obj_t *options = NULL;
        const cfg_obj_t *voptions = NULL;
-       const cfg_obj_t *forwardtype;
-       const cfg_obj_t *forwarders;
-       const cfg_obj_t *alternates;
-       const cfg_obj_t *zonelist;
-       const cfg_obj_t *dlzlist;
-       const cfg_obj_t *dlz;
-       const cfg_obj_t *prefetch_trigger;
-       const cfg_obj_t *prefetch_eligible;
+       const cfg_obj_t *forwardtype = NULL;
+       const cfg_obj_t *forwarders = NULL;
+       const cfg_obj_t *alternates = NULL;
+       const cfg_obj_t *zonelist = NULL;
+       const cfg_obj_t *dlzlist = NULL;
+       const cfg_obj_t *dlz = NULL;
+       const cfg_obj_t *prefetch_trigger = NULL;
+       const cfg_obj_t *prefetch_eligible = NULL;
        unsigned int dlzargc;
-       char **dlzargv;
-       const cfg_obj_t *dyndb_list, *plugin_list;
-       const cfg_obj_t *disabled;
-       const cfg_obj_t *obj, *obj2;
-       const cfg_listelt_t *element = NULL;
+       char **dlzargv = NULL;
+       const cfg_obj_t *dyndb_list = NULL, *plugin_list = NULL;
+       const cfg_obj_t *disabled = NULL;
+       const cfg_obj_t *obj = NULL, *obj2 = NULL;
        const cfg_listelt_t *zone_element_latest = NULL;
        in_port_t port;
        dns_cache_t *cache = NULL;
@@ -3759,7 +3734,7 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
        bool catz_configured = false;
        bool shared_cache = false;
        int i = 0, j = 0, k = 0;
-       const char *str;
+       const char *str = NULL;
        const char *cachename = NULL;
        dns_order_t *order = NULL;
        uint32_t udpsize;
@@ -3860,9 +3835,7 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
        /*
         * Load zone configuration
         */
-       for (element = cfg_list_first(zonelist); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (zonelist, element) {
                const cfg_obj_t *zconfig = cfg_listelt_value(element);
                CHECK(configure_zone(config, zconfig, vconfig, view, viewlist,
                                     kasplist, keystores, actx, false,
@@ -3913,9 +3886,7 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
                (void)cfg_map_get(config, "dlz", &dlzlist);
        }
 
-       for (element = cfg_list_first(dlzlist); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (dlzlist, element) {
                dlz = cfg_listelt_value(element);
 
                obj = NULL;
@@ -4085,9 +4056,7 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
                        contact = NULL;
                }
 
-               for (element = cfg_list_first(obj); element != NULL;
-                    element = cfg_list_next(element))
-               {
+               CFG_LIST_FOREACH (obj, element) {
                        const cfg_obj_t *map = cfg_listelt_value(element);
                        dns_dns64_t *dns64 = NULL;
                        unsigned int dns64options = 0;
@@ -4608,9 +4577,7 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
        disabled = NULL;
        (void)named_config_get(maps, "disable-algorithms", &disabled);
        if (disabled != NULL) {
-               for (element = cfg_list_first(disabled); element != NULL;
-                    element = cfg_list_next(element))
-               {
+               CFG_LIST_FOREACH (disabled, element) {
                        CHECK(disable_algorithms(cfg_listelt_value(element),
                                                 view->resolver));
                }
@@ -4622,9 +4589,7 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
        disabled = NULL;
        (void)named_config_get(maps, "disable-ds-digests", &disabled);
        if (disabled != NULL) {
-               for (element = cfg_list_first(disabled); element != NULL;
-                    element = cfg_list_next(element))
-               {
+               CFG_LIST_FOREACH (disabled, element) {
                        CHECK(disable_ds_digests(cfg_listelt_value(element),
                                                 view->resolver));
                }
@@ -4751,9 +4716,7 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
 
                (void)named_config_get(cfgmaps, "server", &peers);
                dns_peerlist_new(mctx, &newpeers);
-               for (element = cfg_list_first(peers); element != NULL;
-                    element = cfg_list_next(element))
-               {
+               CFG_LIST_FOREACH (peers, element) {
                        const cfg_obj_t *cpeer = cfg_listelt_value(element);
                        dns_peer_t *peer;
 
@@ -4773,9 +4736,7 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
 
                (void)named_config_get(maps, "rrset-order", &rrsetorder);
                dns_order_create(mctx, &order);
-               for (element = cfg_list_first(rrsetorder); element != NULL;
-                    element = cfg_list_next(element))
-               {
+               CFG_LIST_FOREACH (rrsetorder, element) {
                        const cfg_obj_t *ent = cfg_listelt_value(element);
 
                        CHECK(configure_order(order, ent));
@@ -5327,9 +5288,7 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
                (void)cfg_map_get(config, "dyndb", &dyndb_list);
        }
 
-       for (element = cfg_list_first(dyndb_list); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (dyndb_list, element) {
                const cfg_obj_t *dyndb = cfg_listelt_value(element);
 
                if (dctx == NULL) {
@@ -5658,9 +5617,7 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
                result = dns_view_getntatable(view, &ntatable);
        }
        if (result == ISC_R_SUCCESS) {
-               for (element = cfg_list_first(obj); element != NULL;
-                    element = cfg_list_next(element))
-               {
+               CFG_LIST_FOREACH (obj, element) {
                        dns_fixedname_t fntaname;
                        dns_name_t *ntaname;
 
@@ -5754,9 +5711,7 @@ cleanup:
                }
 
                if (zone_element_latest != NULL) {
-                       for (element = cfg_list_first(zonelist);
-                            element != NULL; element = cfg_list_next(element))
-                       {
+                       CFG_LIST_FOREACH (zonelist, element) {
                                const cfg_obj_t *zconfig =
                                        cfg_listelt_value(element);
                                configure_zone_setviewcommit(result, zconfig,
@@ -5833,10 +5788,9 @@ configure_hints(dns_view_t *view, const char *filename) {
 static isc_result_t
 configure_alternates(const cfg_obj_t *config, dns_view_t *view,
                     const cfg_obj_t *alternates) {
-       const cfg_obj_t *portobj;
-       const cfg_obj_t *addresses;
-       const cfg_listelt_t *element;
        isc_result_t result = ISC_R_SUCCESS;
+       const cfg_obj_t *portobj = NULL;
+       const cfg_obj_t *addresses = NULL;
        in_port_t port;
 
        /*
@@ -5862,9 +5816,7 @@ configure_alternates(const cfg_obj_t *config, dns_view_t *view,
                addresses = cfg_tuple_get(alternates, "addresses");
        }
 
-       for (element = cfg_list_first(addresses); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (addresses, element) {
                const cfg_obj_t *alternate = cfg_listelt_value(element);
                isc_sockaddr_t sa;
 
@@ -5949,7 +5901,6 @@ configure_forward(const cfg_obj_t *config, dns_view_t *view,
        const cfg_obj_t *portobj = NULL;
        const cfg_obj_t *tlspobj = NULL;
        const cfg_obj_t *faddresses = NULL;
-       const cfg_listelt_t *element = NULL;
        dns_fwdpolicy_t fwdpolicy = dns_fwdpolicy_none;
        dns_forwarderlist_t fwdlist;
        isc_result_t result;
@@ -6000,9 +5951,7 @@ configure_forward(const cfg_obj_t *config, dns_view_t *view,
                faddresses = cfg_tuple_get(forwarders, "addresses");
        }
 
-       for (element = cfg_list_first(faddresses); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (faddresses, element) {
                const cfg_obj_t *forwarder = cfg_listelt_value(element);
                const char *cur_tls = NULL;
 
@@ -7491,9 +7440,8 @@ static isc_result_t
 configure_newzones(dns_view_t *view, cfg_obj_t *config, cfg_obj_t *vconfig,
                   cfg_aclconfctx_t *actx) {
        isc_result_t result;
-       ns_cfgctx_t *nzctx;
-       const cfg_obj_t *zonelist;
-       const cfg_listelt_t *element;
+       ns_cfgctx_t *nzctx = NULL;
+       const cfg_obj_t *zonelist = NULL;
 
        nzctx = view->new_zone_config;
        if (nzctx == NULL || nzctx->nzf_config == NULL) {
@@ -7507,9 +7455,7 @@ configure_newzones(dns_view_t *view, cfg_obj_t *config, cfg_obj_t *vconfig,
        zonelist = NULL;
        cfg_map_get(nzctx->nzf_config, "zone", &zonelist);
 
-       for (element = cfg_list_first(zonelist); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (zonelist, element) {
                const cfg_obj_t *zconfig = cfg_listelt_value(element);
                CHECK(configure_zone(config, zconfig, vconfig, view,
                                     &named_g_server->viewlist,
@@ -7521,9 +7467,7 @@ configure_newzones(dns_view_t *view, cfg_obj_t *config, cfg_obj_t *vconfig,
        result = ISC_R_SUCCESS;
 
 cleanup:
-       for (element = cfg_list_first(zonelist); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (zonelist, element) {
                const cfg_obj_t *zconfig = cfg_listelt_value(element);
                configure_zone_setviewcommit(result, zconfig, view);
        }
@@ -7836,7 +7780,6 @@ load_configuration(const char *filename, named_server_t *server,
                   bool first_time) {
        cfg_obj_t *config = NULL, *bindkeys = NULL;
        cfg_parser_t *conf_parser = NULL, *bindkeys_parser = NULL;
-       const cfg_listelt_t *element = NULL;
        const cfg_obj_t *builtin_views = NULL;
        const cfg_obj_t *maps[3];
        const cfg_obj_t *obj = NULL;
@@ -8582,9 +8525,7 @@ load_configuration(const char *filename, named_server_t *server,
         */
        keystores = NULL;
        (void)cfg_map_get(config, "key-store", &keystores);
-       for (element = cfg_list_first(keystores); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (keystores, element) {
                cfg_obj_t *kconfig = cfg_listelt_value(element);
 
                result = cfg_keystore_fromconfig(kconfig, named_g_mctx,
@@ -8599,9 +8540,7 @@ load_configuration(const char *filename, named_server_t *server,
         */
        kasps = NULL;
        (void)cfg_map_get(named_g_config, "dnssec-policy", &kasps);
-       for (element = cfg_list_first(kasps); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (kasps, element) {
                cfg_obj_t *kconfig = cfg_listelt_value(element);
                dns_kasp_t *kasp = NULL;
 
@@ -8629,9 +8568,7 @@ load_configuration(const char *filename, named_server_t *server,
         */
        kasps = NULL;
        (void)cfg_map_get(config, "dnssec-policy", &kasps);
-       for (element = cfg_list_first(kasps); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (kasps, element) {
                cfg_obj_t *kconfig = cfg_listelt_value(element);
                dns_kasp_t *kasp = NULL;
 
@@ -8667,9 +8604,7 @@ load_configuration(const char *filename, named_server_t *server,
        /*
         * Create the views.
         */
-       for (element = cfg_list_first(views); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (views, element) {
                cfg_obj_t *vconfig = cfg_listelt_value(element);
                dns_view_t *view = NULL;
 
@@ -8715,9 +8650,7 @@ load_configuration(const char *filename, named_server_t *server,
         * views that have zones were already created at parsing
         * time, but views with no zones must be created here.
         */
-       for (element = cfg_list_first(views); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (views, element) {
                cfg_obj_t *vconfig = cfg_listelt_value(element);
                dns_view_t *view = NULL;
 
@@ -8769,9 +8702,7 @@ load_configuration(const char *filename, named_server_t *server,
        builtin_views = NULL;
        RUNTIME_CHECK(cfg_map_get(named_g_config, "view", &builtin_views) ==
                      ISC_R_SUCCESS);
-       for (element = cfg_list_first(builtin_views); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (builtin_views, element) {
                cfg_obj_t *vconfig = cfg_listelt_value(element);
                dns_view_t *view = NULL;
 
@@ -8984,10 +8915,7 @@ load_configuration(const char *filename, named_server_t *server,
                                                  &categories);
                        }
                        if (categories != NULL) {
-                               for (element = cfg_list_first(categories);
-                                    element != NULL;
-                                    element = cfg_list_next(element))
-                               {
+                               CFG_LIST_FOREACH (categories, element) {
                                        const cfg_obj_t *catobj;
                                        const char *str;
 
@@ -9117,9 +9045,7 @@ load_configuration(const char *filename, named_server_t *server,
                unsigned int usedlength;
                unsigned int expectedlength;
 
-               for (element = cfg_list_first(obj); element != NULL;
-                    element = cfg_list_next(element))
-               {
+               CFG_LIST_FOREACH (obj, element) {
                        obj = cfg_listelt_value(element);
                        str = cfg_obj_asstring(obj);
 
@@ -10629,7 +10555,6 @@ listenlist_fromconfig(const cfg_obj_t *listenlist, const cfg_obj_t *config,
                      isc_tlsctx_cache_t *tlsctx_cache,
                      ns_listenlist_t **target) {
        isc_result_t result;
-       const cfg_listelt_t *element;
        ns_listenlist_t *dlist = NULL;
 
        REQUIRE(target != NULL && *target == NULL);
@@ -10639,9 +10564,7 @@ listenlist_fromconfig(const cfg_obj_t *listenlist, const cfg_obj_t *config,
                return result;
        }
 
-       for (element = cfg_list_first(listenlist); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (listenlist, element) {
                ns_listenelt_t *delt = NULL;
                const cfg_obj_t *listener = cfg_listelt_value(element);
                result = listenelt_fromconfig(listener, config, actx, mctx,
@@ -10663,7 +10586,6 @@ static const cfg_obj_t *
 find_maplist(const cfg_obj_t *config, const char *listname, const char *name) {
        isc_result_t result;
        const cfg_obj_t *maplist = NULL;
-       const cfg_listelt_t *elt = NULL;
 
        REQUIRE(config != NULL);
        REQUIRE(name != NULL);
@@ -10673,9 +10595,7 @@ find_maplist(const cfg_obj_t *config, const char *listname, const char *name) {
                return NULL;
        }
 
-       for (elt = cfg_list_first(maplist); elt != NULL;
-            elt = cfg_list_next(elt))
-       {
+       CFG_LIST_FOREACH (maplist, elt) {
                const cfg_obj_t *map = cfg_listelt_value(elt);
                if (strcasecmp(cfg_obj_asstring(cfg_map_getname(map)), name) ==
                    0)
@@ -10763,11 +10683,8 @@ listenelt_fromconfig(const cfg_obj_t *listener, const cfg_obj_t *config,
                        if (cfg_map_get(tlsmap, "protocols", &tls_proto_list) ==
                            ISC_R_SUCCESS)
                        {
-                               const cfg_listelt_t *proto = NULL;
                                INSIST(tls_proto_list != NULL);
-                               for (proto = cfg_list_first(tls_proto_list);
-                                    proto != 0; proto = cfg_list_next(proto))
-                               {
+                               CFG_LIST_FOREACH (tls_proto_list, proto) {
                                        const cfg_obj_t *tls_proto_obj =
                                                cfg_listelt_value(proto);
                                        const char *tls_sver =
@@ -10956,7 +10873,6 @@ listenelt_http(const cfg_obj_t *http, const uint16_t family, bool tls,
        ns_listenelt_t *delt = NULL;
        char **endpoints = NULL;
        const cfg_obj_t *eplist = NULL;
-       const cfg_listelt_t *elt = NULL;
        size_t len = 1, i = 0;
        uint32_t max_clients = named_g_http_listener_clients;
        uint32_t max_streams = named_g_http_streams_per_conn;
@@ -11003,9 +10919,7 @@ listenelt_http(const cfg_obj_t *http, const uint16_t family, bool tls,
        endpoints = isc_mem_allocate(mctx, sizeof(endpoints[0]) * len);
 
        if (http != NULL && eplist != NULL) {
-               for (elt = cfg_list_first(eplist); elt != NULL;
-                    elt = cfg_list_next(elt))
-               {
+               CFG_LIST_FOREACH (eplist, elt) {
                        const cfg_obj_t *ep = cfg_listelt_value(elt);
                        const char *path = cfg_obj_asstring(ep);
                        endpoints[i++] = isc_mem_strdup(mctx, path);
@@ -12823,8 +12737,7 @@ load_nzf(dns_view_t *view, ns_cfgctx_t *nzcfg) {
        int status;
        isc_buffer_t *text = NULL;
        bool commit = false;
-       const cfg_obj_t *zonelist;
-       const cfg_listelt_t *element;
+       const cfg_obj_t *zonelist = NULL;
        char tempname[PATH_MAX];
        MDB_txn *txn = NULL;
        MDB_dbi dbi;
@@ -12873,9 +12786,7 @@ load_nzf(dns_view_t *view, ns_cfgctx_t *nzcfg) {
 
        isc_buffer_allocate(view->mctx, &text, 256);
 
-       for (element = cfg_list_first(zonelist); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (zonelist, element) {
                const cfg_obj_t *zconfig;
                const cfg_obj_t *zoptions;
                char zname[DNS_NAME_FORMATSIZE];
@@ -13957,7 +13868,6 @@ find_name_in_list_from_map(const cfg_obj_t *config,
                           const char *map_key_for_list, const char *name,
                           bool redirect) {
        const cfg_obj_t *list = NULL;
-       const cfg_listelt_t *element;
        const cfg_obj_t *obj = NULL;
        dns_fixedname_t fixed1, fixed2;
        dns_name_t *name1 = NULL, *name2 = NULL;
@@ -13972,10 +13882,8 @@ find_name_in_list_from_map(const cfg_obj_t *config,
        }
 
        cfg_map_get(config, map_key_for_list, &list);
-       for (element = cfg_list_first(list); element != NULL;
-            element = cfg_list_next(element))
-       {
-               const char *vname;
+       CFG_LIST_FOREACH (list, element) {
+               const char *vname = NULL;
 
                obj = cfg_listelt_value(element);
                INSIST(obj != NULL);
index 901f5a77c60f36bf446ac71a3a41c5ead3faee13..6edfcc6f56a24ce13e6de770601945e307a3eb2e 100644 (file)
@@ -3804,7 +3804,6 @@ named_statschannels_configure(named_server_t *server, const cfg_obj_t *config,
                              cfg_aclconfctx_t *aclconfctx) {
        named_statschannellist_t new_listeners;
        const cfg_obj_t *statschannellist = NULL;
-       const cfg_listelt_t *element, *element2;
        char socktext[ISC_SOCKADDR_FORMATSIZE];
 
        isc_once_do(&once, init_desc);
@@ -3845,10 +3844,8 @@ named_statschannels_configure(named_server_t *server, const cfg_obj_t *config,
 #endif /* !HAVE_JSON_C */
 #endif /* EXTENDED_STATS */
 
-               for (element = cfg_list_first(statschannellist);
-                    element != NULL; element = cfg_list_next(element))
-               {
-                       const cfg_obj_t *statschannel;
+               CFG_LIST_FOREACH (statschannellist, element) {
+                       const cfg_obj_t *statschannel = NULL;
                        const cfg_obj_t *listenercfg = NULL;
 
                        statschannel = cfg_listelt_value(element);
@@ -3857,10 +3854,7 @@ named_statschannels_configure(named_server_t *server, const cfg_obj_t *config,
                                continue;
                        }
 
-                       for (element2 = cfg_list_first(listenercfg);
-                            element2 != NULL;
-                            element2 = cfg_list_next(element2))
-                       {
+                       CFG_LIST_FOREACH (listenercfg, element2) {
                                named_statschannel_t *listener = NULL;
                                const cfg_obj_t *listen_params = NULL;
                                const cfg_obj_t *obj = NULL;
index 5b904761eccccd0608425ce7ae39b9dbe255e773..81a8f4994b1173a6212ff06db3ca2af5b92dd90a 100644 (file)
                if (obj != NULL) {                                                \
                        {                                                         \
                                uint32_t tls_protos = 0;                          \
-                               const cfg_listelt_t *proto = NULL;                \
                                INSIST(obj != NULL);                              \
-                               for (proto = cfg_list_first(obj); proto != 0;     \
-                                    proto = cfg_list_next(proto))                \
-                               {                                                 \
+                               CFG_LIST_FOREACH (obj, proto) {                   \
                                        const cfg_obj_t *tls_proto_obj =          \
                                                cfg_listelt_value(proto);         \
                                        const char *tls_sver =                    \
@@ -96,9 +93,7 @@ add_doh_transports(const cfg_obj_t *transportlist, dns_transport_list_t *list) {
        const char *dohid = NULL;
        isc_result_t result;
 
-       for (const cfg_listelt_t *element = cfg_list_first(transportlist);
-            element != NULL; element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (transportlist, element) {
                dns_name_t *dohname = NULL;
                dns_transport_t *transport = NULL;
 
@@ -144,9 +139,7 @@ add_tls_transports(const cfg_obj_t *transportlist, dns_transport_list_t *list) {
        const char *tlsid = NULL;
        isc_result_t result;
 
-       for (const cfg_listelt_t *element = cfg_list_first(transportlist);
-            element != NULL; element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (transportlist, element) {
                dns_name_t *tlsname = NULL;
                dns_transport_t *transport = NULL;
 
index aa8be9dbaeb97e6c1098c648fd96ac66e5a936fc..564e1ca0876e3a991ba23fdc746937e0fa7d20bc 100644 (file)
@@ -34,16 +34,13 @@ static isc_result_t
 add_initial_keys(const cfg_obj_t *list, dns_tsigkeyring_t *ring,
                 isc_mem_t *mctx) {
        dns_tsigkey_t *tsigkey = NULL;
-       const cfg_listelt_t *element;
        const cfg_obj_t *key = NULL;
        const char *keyid = NULL;
        unsigned char *secret = NULL;
        int secretalloc = 0;
        isc_result_t ret;
 
-       for (element = cfg_list_first(list); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (list, element) {
                const cfg_obj_t *algobj = NULL;
                const cfg_obj_t *secretobj = NULL;
                dns_fixedname_t fkey;
index ca32fe1811200620533a8bc07d85d3808041edca..1b1c1842599f14917ce056ca65fe797d16533892 100644 (file)
@@ -191,7 +191,6 @@ static isc_result_t
 configure_zone_ssutable(const cfg_obj_t *zconfig, dns_zone_t *zone,
                        const char *zname) {
        const cfg_obj_t *updatepolicy = NULL;
-       const cfg_listelt_t *element, *element2;
        dns_ssutable_t *table = NULL;
        isc_mem_t *mctx = dns_zone_getmctx(zone);
        bool autoddns = false;
@@ -218,9 +217,7 @@ configure_zone_ssutable(const cfg_obj_t *zconfig, dns_zone_t *zone,
 
        dns_ssutable_create(mctx, &table);
 
-       for (element = cfg_list_first(updatepolicy); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (updatepolicy, element) {
                const cfg_obj_t *stmt = cfg_listelt_value(element);
                const cfg_obj_t *mode = cfg_tuple_get(stmt, "mode");
                const cfg_obj_t *identity = cfg_tuple_get(stmt, "identity");
@@ -303,9 +300,7 @@ configure_zone_ssutable(const cfg_obj_t *zconfig, dns_zone_t *zone,
                }
 
                i = 0;
-               for (element2 = cfg_list_first(typelist); element2 != NULL;
-                    element2 = cfg_list_next(element2))
-               {
+               CFG_LIST_FOREACH (typelist, element2) {
                        const cfg_obj_t *typeobj;
                        const char *bracket;
                        isc_textregion_t r;
@@ -411,15 +406,12 @@ configure_staticstub_serveraddrs(const cfg_obj_t *zconfig, dns_zone_t *zone,
                                 dns_rdatalist_t *rdatalist_ns,
                                 dns_rdatalist_t *rdatalist_a,
                                 dns_rdatalist_t *rdatalist_aaaa) {
-       const cfg_listelt_t *element;
        isc_mem_t *mctx = dns_zone_getmctx(zone);
        isc_region_t region, sregion;
-       dns_rdata_t *rdata;
+       dns_rdata_t *rdata = NULL;
        isc_result_t result = ISC_R_SUCCESS;
 
-       for (element = cfg_list_first(zconfig); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (zconfig, element) {
                const isc_sockaddr_t *sa;
                isc_netaddr_t na;
                const cfg_obj_t *address = cfg_listelt_value(element);
@@ -496,19 +488,16 @@ static isc_result_t
 configure_staticstub_servernames(const cfg_obj_t *zconfig, dns_zone_t *zone,
                                 dns_rdatalist_t *rdatalist,
                                 const char *zname) {
-       const cfg_listelt_t *element;
        isc_mem_t *mctx = dns_zone_getmctx(zone);
-       dns_rdata_t *rdata;
+       dns_rdata_t *rdata = NULL;
        isc_region_t sregion, region;
        isc_result_t result = ISC_R_SUCCESS;
 
-       for (element = cfg_list_first(zconfig); element != NULL;
-            element = cfg_list_next(element))
-       {
-               const cfg_obj_t *obj;
-               const char *str;
+       CFG_LIST_FOREACH (zconfig, element) {
+               const cfg_obj_t *obj = NULL;
+               const char *str = NULL;
                dns_fixedname_t fixed_name;
-               dns_name_t *nsname;
+               dns_name_t *nsname = NULL;
                isc_buffer_t b;
 
                obj = cfg_listelt_value(element);
index e7a04a24a5d4181cb7599c6277097e523e34bc11..03c4848ccbcdd49d5dbeeca9c4dce84bedb63980 100644 (file)
@@ -558,13 +558,11 @@ parse_config(isc_mem_t *mctx, const char *keyname, cfg_parser_t **pctxp,
        const cfg_obj_t *algorithmobj = NULL;
        cfg_obj_t *config = NULL;
        const cfg_obj_t *address = NULL;
-       const cfg_listelt_t *elt;
        const char *secretstr;
        const char *algorithmstr;
        static char secretarray[1024];
        const cfg_type_t *conftype = &cfg_type_rndcconf;
        bool key_only = false;
-       const cfg_listelt_t *element;
 
        if (!isc_file_exists(conffile)) {
                conffile = admin_keyfile;
@@ -617,9 +615,7 @@ parse_config(isc_mem_t *mctx, const char *keyname, cfg_parser_t **pctxp,
        if (!key_only) {
                (void)cfg_map_get(config, "server", &servers);
                if (servers != NULL) {
-                       for (elt = cfg_list_first(servers); elt != NULL;
-                            elt = cfg_list_next(elt))
-                       {
+                       CFG_LIST_FOREACH (servers, elt) {
                                const char *name = NULL;
                                server = cfg_listelt_value(elt);
                                name = cfg_obj_asstring(
@@ -655,18 +651,18 @@ parse_config(isc_mem_t *mctx, const char *keyname, cfg_parser_t **pctxp,
                DO("get key", cfg_map_get(config, "key", &key));
        } else {
                DO("get config key list", cfg_map_get(config, "key", &keys));
-               for (elt = cfg_list_first(keys); elt != NULL;
-                    elt = cfg_list_next(elt))
-               {
+               bool match = false;
+               CFG_LIST_FOREACH (keys, elt) {
                        const char *name = NULL;
 
                        key = cfg_listelt_value(elt);
                        name = cfg_obj_asstring(cfg_map_getname(key));
                        if (strcasecmp(name, keyname) == 0) {
+                               match = true;
                                break;
                        }
                }
-               if (elt == NULL) {
+               if (!match) {
                        fatal("no key definition for name %s", keyname);
                }
        }
@@ -729,9 +725,7 @@ parse_config(isc_mem_t *mctx, const char *keyname, cfg_parser_t **pctxp,
                result = ISC_R_NOTFOUND;
        }
        if (result == ISC_R_SUCCESS) {
-               for (element = cfg_list_first(addresses); element != NULL;
-                    element = cfg_list_next(element))
-               {
+               CFG_LIST_FOREACH (addresses, element) {
                        isc_sockaddr_t sa;
 
                        address = cfg_listelt_value(element);
index be3190d6b68a45cf0f1fdf3077e00e7ce116663d..cebe9430bb8f2d8d792c28864332774e42c68303 100644 (file)
@@ -92,14 +92,12 @@ static isc_result_t
 get_acl_def(const cfg_obj_t *cctx, const char *name, const cfg_obj_t **ret) {
        isc_result_t result;
        const cfg_obj_t *acls = NULL;
-       const cfg_listelt_t *elt;
 
        result = cfg_map_get(cctx, "acl", &acls);
        if (result != ISC_R_SUCCESS) {
                return result;
        }
-       for (elt = cfg_list_first(acls); elt != NULL; elt = cfg_list_next(elt))
-       {
+       CFG_LIST_FOREACH (acls, elt) {
                const cfg_obj_t *acl = cfg_listelt_value(elt);
                const char *aclname =
                        cfg_obj_asstring(cfg_tuple_get(acl, "name"));
@@ -197,7 +195,6 @@ static isc_result_t
 count_acl_elements(const cfg_obj_t *caml, const cfg_obj_t *cctx,
                   cfg_aclconfctx_t *ctx, isc_mem_t *mctx, uint32_t *count,
                   bool *has_negative) {
-       const cfg_listelt_t *elt;
        isc_result_t result;
        uint32_t n = 0;
 
@@ -205,8 +202,7 @@ count_acl_elements(const cfg_obj_t *caml, const cfg_obj_t *cctx,
 
        SET_IF_NOT_NULL(has_negative, false);
 
-       for (elt = cfg_list_first(caml); elt != NULL; elt = cfg_list_next(elt))
-       {
+       CFG_LIST_FOREACH (caml, elt) {
                const cfg_obj_t *ce = cfg_listelt_value(elt);
 
                /* might be a negated element, in which case get the value. */
@@ -615,9 +611,8 @@ cfg_acl_fromconfig(const cfg_obj_t *acl_data, const cfg_obj_t *cctx,
                   unsigned int nest_level, dns_acl_t **target) {
        isc_result_t result;
        dns_acl_t *dacl = NULL, *inneracl = NULL;
-       dns_aclelement_t *de;
-       const cfg_listelt_t *elt;
-       dns_iptable_t *iptab;
+       dns_aclelement_t *de = NULL;
+       dns_iptable_t *iptab = NULL;
        int new_nest_level = 0;
        bool setpos;
        const cfg_obj_t *caml = NULL;
@@ -735,8 +730,7 @@ cfg_acl_fromconfig(const cfg_obj_t *acl_data, const cfg_obj_t *cctx,
        }
 
        de = dacl->elements;
-       for (elt = cfg_list_first(caml); elt != NULL; elt = cfg_list_next(elt))
-       {
+       CFG_LIST_FOREACH (caml, elt) {
                const cfg_obj_t *ce = cfg_listelt_value(elt);
                bool neg = false;
 
index 79134cbf5f55729f4d75a34340da201ed1b7403f..61625bdc0b647e038e0e05db2950750bfe1928ff 100644 (file)
@@ -182,16 +182,13 @@ static isc_result_t
 check_order(const cfg_obj_t *options) {
        isc_result_t result = ISC_R_SUCCESS;
        isc_result_t tresult;
-       const cfg_listelt_t *element;
        const cfg_obj_t *obj = NULL;
 
        if (cfg_map_get(options, "rrset-order", &obj) != ISC_R_SUCCESS) {
                return result;
        }
 
-       for (element = cfg_list_first(obj); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (obj, element) {
                tresult = check_orderent(cfg_listelt_value(element));
                if (result == ISC_R_SUCCESS && tresult != ISC_R_SUCCESS) {
                        result = tresult;
@@ -202,11 +199,10 @@ check_order(const cfg_obj_t *options) {
 
 static isc_result_t
 check_dual_stack(const cfg_obj_t *options) {
-       const cfg_listelt_t *element;
        const cfg_obj_t *alternates = NULL;
-       const cfg_obj_t *value;
-       const cfg_obj_t *obj;
-       const char *str;
+       const cfg_obj_t *value = NULL;
+       const cfg_obj_t *obj = NULL;
+       const char *str = NULL;
        dns_fixedname_t fixed;
        dns_name_t *name;
        isc_buffer_t buffer;
@@ -231,9 +227,7 @@ check_dual_stack(const cfg_obj_t *options) {
                }
        }
        obj = cfg_tuple_get(alternates, "addresses");
-       for (element = cfg_list_first(obj); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (obj, element) {
                value = cfg_listelt_value(element);
                if (cfg_obj_issockaddr(value)) {
                        continue;
@@ -297,7 +291,6 @@ check_forward(const cfg_obj_t *config, const cfg_obj_t *options,
        const cfg_obj_t *forward = NULL;
        const cfg_obj_t *forwarders = NULL;
        const cfg_obj_t *faddresses = NULL;
-       const cfg_listelt_t *element;
 
        (void)cfg_map_get(options, "forward", &forward);
        (void)cfg_map_get(options, "forwarders", &forwarders);
@@ -331,9 +324,7 @@ check_forward(const cfg_obj_t *config, const cfg_obj_t *options,
                }
 
                faddresses = cfg_tuple_get(forwarders, "addresses");
-               for (element = cfg_list_first(faddresses); element != NULL;
-                    element = cfg_list_next(element))
-               {
+               CFG_LIST_FOREACH (faddresses, element) {
                        const cfg_obj_t *forwarder = cfg_listelt_value(element);
                        const char *tls = cfg_obj_getsockaddrtls(forwarder);
                        if (tls != NULL) {
@@ -352,12 +343,11 @@ static isc_result_t
 disabled_algorithms(const cfg_obj_t *disabled) {
        isc_result_t result = ISC_R_SUCCESS;
        isc_result_t tresult;
-       const cfg_listelt_t *element;
-       const char *str;
+       const char *str = NULL;
        isc_buffer_t b;
        dns_fixedname_t fixed;
-       dns_name_t *name;
-       const cfg_obj_t *obj;
+       dns_name_t *name = NULL;
+       const cfg_obj_t *obj = NULL;
 
        name = dns_fixedname_initname(&fixed);
        obj = cfg_tuple_get(disabled, "name");
@@ -372,9 +362,7 @@ disabled_algorithms(const cfg_obj_t *disabled) {
 
        obj = cfg_tuple_get(disabled, "algorithms");
 
-       for (element = cfg_list_first(obj); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (obj, element) {
                isc_textregion_t r;
                dns_secalg_t alg;
 
@@ -395,12 +383,11 @@ static isc_result_t
 disabled_ds_digests(const cfg_obj_t *disabled) {
        isc_result_t result = ISC_R_SUCCESS;
        isc_result_t tresult;
-       const cfg_listelt_t *element;
-       const char *str;
+       const char *str = NULL;
        isc_buffer_t b;
        dns_fixedname_t fixed;
-       dns_name_t *name;
-       const cfg_obj_t *obj;
+       dns_name_t *name = NULL;
+       const cfg_obj_t *obj = NULL;
 
        name = dns_fixedname_initname(&fixed);
        obj = cfg_tuple_get(disabled, "name");
@@ -415,9 +402,7 @@ disabled_ds_digests(const cfg_obj_t *disabled) {
 
        obj = cfg_tuple_get(disabled, "digests");
 
-       for (element = cfg_list_first(obj); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (obj, element) {
                isc_textregion_t r;
                dns_dsdigest_t digest;
 
@@ -578,8 +563,7 @@ check_dns64(cfg_aclconfctx_t *actx, const cfg_obj_t *voptions,
        isc_result_t result = ISC_R_SUCCESS;
        const cfg_obj_t *dns64 = NULL;
        const cfg_obj_t *options;
-       const cfg_listelt_t *element;
-       const cfg_obj_t *map, *obj;
+       const cfg_obj_t *map = NULL, *obj = NULL;
        isc_netaddr_t na, sa;
        unsigned int prefixlen;
        int nbytes;
@@ -601,9 +585,7 @@ check_dns64(cfg_aclconfctx_t *actx, const cfg_obj_t *voptions,
                return ISC_R_SUCCESS;
        }
 
-       for (element = cfg_list_first(dns64); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (dns64, element) {
                map = cfg_listelt_value(element);
                obj = cfg_map_getname(map);
 
@@ -1003,7 +985,6 @@ static const cfg_obj_t *
 find_maplist(const cfg_obj_t *config, const char *listname, const char *name) {
        isc_result_t result = ISC_R_SUCCESS;
        const cfg_obj_t *maplist = NULL;
-       const cfg_listelt_t *elt = NULL;
 
        REQUIRE(config != NULL);
        REQUIRE(name != NULL);
@@ -1013,9 +994,7 @@ find_maplist(const cfg_obj_t *config, const char *listname, const char *name) {
                return NULL;
        }
 
-       for (elt = cfg_list_first(maplist); elt != NULL;
-            elt = cfg_list_next(elt))
-       {
+       CFG_LIST_FOREACH (maplist, elt) {
                const cfg_obj_t *map = cfg_listelt_value(elt);
                if (strcasecmp(cfg_obj_asstring(cfg_map_getname(map)), name) ==
                    0)
@@ -1147,10 +1126,8 @@ static isc_result_t
 check_listeners(const cfg_obj_t *list, const cfg_obj_t *config,
                cfg_aclconfctx_t *actx, isc_mem_t *mctx) {
        isc_result_t tresult, result = ISC_R_SUCCESS;
-       const cfg_listelt_t *elt = NULL;
 
-       for (elt = cfg_list_first(list); elt != NULL; elt = cfg_list_next(elt))
-       {
+       CFG_LIST_FOREACH (list, elt) {
                const cfg_obj_t *obj = cfg_listelt_value(elt);
                tresult = check_listener(obj, config, actx, mctx);
                if (result == ISC_R_SUCCESS) {
@@ -1188,8 +1165,7 @@ check_options(const cfg_obj_t *options, const cfg_obj_t *config,
        isc_result_t tresult;
        unsigned int i;
        const cfg_obj_t *obj = NULL;
-       const cfg_listelt_t *element;
-       const char *str;
+       const char *str = NULL;
        isc_buffer_t b;
        uint32_t lifetime = 3600;
        dns_keystorelist_t kslist;
@@ -1332,13 +1308,11 @@ check_options(const cfg_obj_t *options, const cfg_obj_t *config,
                                result = ISC_R_FAILURE;
                        }
                } else if (cfg_obj_islist(obj)) {
-                       for (element = cfg_list_first(obj); element != NULL;
-                            element = cfg_list_next(element))
-                       {
+                       CFG_LIST_FOREACH (obj, element) {
                                isc_result_t ret;
-                               const char *val;
+                               const char *val = NULL;
                                cfg_obj_t *kconfig = cfg_listelt_value(element);
-                               const cfg_obj_t *kopt;
+                               const cfg_obj_t *kopt = NULL;
                                const cfg_obj_t *kobj = NULL;
                                if (!cfg_obj_istuple(kconfig)) {
                                        continue;
@@ -1432,10 +1406,7 @@ check_options(const cfg_obj_t *options, const cfg_obj_t *config,
                        ISC_LIST_INIT(list);
 
                        if (cfg_obj_islist(obj)) {
-                               for (element = cfg_list_first(obj);
-                                    element != NULL;
-                                    element = cfg_list_next(element))
-                               {
+                               CFG_LIST_FOREACH (obj, element) {
                                        isc_result_t ret;
                                        cfg_obj_t *kconfig =
                                                cfg_listelt_value(element);
@@ -1534,9 +1505,7 @@ check_options(const cfg_obj_t *options, const cfg_obj_t *config,
        obj = NULL;
        (void)cfg_map_get(options, "disable-algorithms", &obj);
        if (obj != NULL) {
-               for (element = cfg_list_first(obj); element != NULL;
-                    element = cfg_list_next(element))
-               {
+               CFG_LIST_FOREACH (obj, element) {
                        obj = cfg_listelt_value(element);
                        tresult = disabled_algorithms(obj);
                        if (tresult != ISC_R_SUCCESS) {
@@ -1551,9 +1520,7 @@ check_options(const cfg_obj_t *options, const cfg_obj_t *config,
        obj = NULL;
        (void)cfg_map_get(options, "disable-ds-digests", &obj);
        if (obj != NULL) {
-               for (element = cfg_list_first(obj); element != NULL;
-                    element = cfg_list_next(element))
-               {
+               CFG_LIST_FOREACH (obj, element) {
                        obj = cfg_listelt_value(element);
                        tresult = disabled_ds_digests(obj);
                        if (tresult != ISC_R_SUCCESS) {
@@ -1606,9 +1573,7 @@ check_options(const cfg_obj_t *options, const cfg_obj_t *config,
         */
        obj = NULL;
        (void)cfg_map_get(options, "disable-empty-zone", &obj);
-       for (element = cfg_list_first(obj); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (obj, element) {
                obj = cfg_listelt_value(element);
                str = cfg_obj_asstring(obj);
                if (check_name(str) != ISC_R_SUCCESS) {
@@ -1696,9 +1661,7 @@ check_options(const cfg_obj_t *options, const cfg_obj_t *config,
        if (obj != NULL) {
                unsigned char secret[32];
 
-               for (element = cfg_list_first(obj); element != NULL;
-                    element = cfg_list_next(element))
-               {
+               CFG_LIST_FOREACH (obj, element) {
                        unsigned int usedlength;
 
                        obj = cfg_listelt_value(element);
@@ -1899,9 +1862,7 @@ check_options(const cfg_obj_t *options, const cfg_obj_t *config,
        if (obj != NULL) {
                /* Note: SEC is defined in <sys/time.h> on some platforms. */
                enum { MAS = 1, PRI = 2, SLA = 4, SCN = 8 } values = 0;
-               for (const cfg_listelt_t *el = cfg_list_first(obj); el != NULL;
-                    el = cfg_list_next(el))
-               {
+               CFG_LIST_FOREACH (obj, el) {
                        const cfg_obj_t *tuple = cfg_listelt_value(el);
                        const cfg_obj_t *type = cfg_tuple_get(tuple, "type");
                        const char *keyword = cfg_obj_asstring(type);
@@ -2044,17 +2005,15 @@ check_remoteserverlist(const cfg_obj_t *cctx, const char *list,
        isc_symvalue_t symvalue;
        isc_result_t result = ISC_R_SUCCESS, tresult;
        const cfg_obj_t *obj = NULL;
-       const cfg_listelt_t *elt;
 
        result = cfg_map_get(cctx, list, &obj);
        if (result != ISC_R_SUCCESS) {
                return ISC_R_SUCCESS;
        }
 
-       elt = cfg_list_first(obj);
-       while (elt != NULL) {
-               char *tmp;
-               const char *name;
+       CFG_LIST_FOREACH (obj, elt) {
+               char *tmp = NULL;
+               const char *name = NULL;
 
                obj = cfg_listelt_value(elt);
                name = cfg_obj_asstring(cfg_tuple_get(obj, "name"));
@@ -2084,8 +2043,6 @@ check_remoteserverlist(const cfg_obj_t *cctx, const char *list,
                        result = tresult;
                        break;
                }
-
-               elt = cfg_list_next(elt);
        }
        return result;
 }
@@ -2127,7 +2084,6 @@ check_httpserver(const cfg_obj_t *http, isc_symtab_t *symtab) {
        isc_result_t result = ISC_R_SUCCESS, tresult;
        const char *name = cfg_obj_asstring(cfg_map_getname(http));
        const cfg_obj_t *eps = NULL;
-       const cfg_listelt_t *elt = NULL;
        isc_symvalue_t symvalue;
 
        if (strcasecmp(name, "default") == 0) {
@@ -2164,9 +2120,7 @@ check_httpserver(const cfg_obj_t *http, isc_symtab_t *symtab) {
        /* Check endpoints are valid */
        tresult = cfg_map_get(http, "endpoints", &eps);
        if (tresult == ISC_R_SUCCESS) {
-               for (elt = cfg_list_first(eps); elt != NULL;
-                    elt = cfg_list_next(elt))
-               {
+               CFG_LIST_FOREACH (eps, elt) {
                        const cfg_obj_t *ep = cfg_listelt_value(elt);
                        const char *path = cfg_obj_asstring(ep);
                        if (!isc_nm_http_path_isvalid(path)) {
@@ -2188,7 +2142,6 @@ static isc_result_t
 check_httpservers(const cfg_obj_t *config, isc_mem_t *mctx) {
        isc_result_t result = ISC_R_SUCCESS, tresult;
        const cfg_obj_t *obj = NULL;
-       const cfg_listelt_t *elt = NULL;
        isc_symtab_t *symtab = NULL;
 
        isc_symtab_create(mctx, NULL, NULL, false, &symtab);
@@ -2199,7 +2152,7 @@ check_httpservers(const cfg_obj_t *config, isc_mem_t *mctx) {
                goto done;
        }
 
-       for (elt = cfg_list_first(obj); elt != NULL; elt = cfg_list_next(elt)) {
+       CFG_LIST_FOREACH (obj, elt) {
                obj = cfg_listelt_value(elt);
                tresult = check_httpserver(obj, symtab);
                if (result == ISC_R_SUCCESS) {
@@ -2269,11 +2222,8 @@ check_tls_defintion(const cfg_obj_t *tlsobj, const char *name,
        /* Check protocols are valid */
        tresult = cfg_map_get(tlsobj, "protocols", &tls_proto_list);
        if (tresult == ISC_R_SUCCESS) {
-               const cfg_listelt_t *proto = NULL;
                INSIST(tls_proto_list != NULL);
-               for (proto = cfg_list_first(tls_proto_list); proto != 0;
-                    proto = cfg_list_next(proto))
-               {
+               CFG_LIST_FOREACH (tls_proto_list, proto) {
                        const cfg_obj_t *tls_proto_obj =
                                cfg_listelt_value(proto);
                        const char *tls_sver = cfg_obj_asstring(tls_proto_obj);
@@ -2352,7 +2302,6 @@ static isc_result_t
 check_tls_definitions(const cfg_obj_t *config, isc_mem_t *mctx) {
        isc_result_t result = ISC_R_SUCCESS, tresult;
        const cfg_obj_t *obj = NULL;
-       const cfg_listelt_t *elt = NULL;
        isc_symtab_t *symtab = NULL;
 
        result = cfg_map_get(config, "tls", &obj);
@@ -2363,7 +2312,7 @@ check_tls_definitions(const cfg_obj_t *config, isc_mem_t *mctx) {
 
        isc_symtab_create(mctx, NULL, NULL, false, &symtab);
 
-       for (elt = cfg_list_first(obj); elt != NULL; elt = cfg_list_next(elt)) {
+       CFG_LIST_FOREACH (obj, elt) {
                const char *name;
                obj = cfg_listelt_value(elt);
                name = cfg_obj_asstring(cfg_map_getname(obj));
@@ -2383,16 +2332,14 @@ get_remotes(const cfg_obj_t *cctx, const char *list, const char *name,
            const cfg_obj_t **ret) {
        isc_result_t result = ISC_R_SUCCESS;
        const cfg_obj_t *obj = NULL;
-       const cfg_listelt_t *elt = NULL;
 
        result = cfg_map_get(cctx, list, &obj);
        if (result != ISC_R_SUCCESS) {
                return result;
        }
 
-       elt = cfg_list_first(obj);
-       while (elt != NULL) {
-               const char *listname;
+       CFG_LIST_FOREACH (obj, elt) {
+               const char *listname = NULL;
 
                obj = cfg_listelt_value(elt);
                listname = cfg_obj_asstring(cfg_tuple_get(obj, "name"));
@@ -2401,8 +2348,6 @@ get_remotes(const cfg_obj_t *cctx, const char *list, const char *name,
                        *ret = obj;
                        return ISC_R_SUCCESS;
                }
-
-               elt = cfg_list_next(elt);
        }
 
        return ISC_R_NOTFOUND;
@@ -2436,7 +2381,7 @@ validate_remotes(const cfg_obj_t *obj, const cfg_obj_t *config,
        uint32_t count = 0;
        isc_symtab_t *symtab = NULL;
        isc_symvalue_t symvalue;
-       const cfg_listelt_t *element;
+       const cfg_listelt_t *element = NULL;
        cfg_listelt_t **stack = NULL;
        uint32_t stackcount = 0, pushed = 0;
        const cfg_obj_t *listobj;
@@ -2565,11 +2510,9 @@ static isc_result_t
 check_update_policy(const cfg_obj_t *policy) {
        isc_result_t result = ISC_R_SUCCESS;
        isc_result_t tresult;
-       const cfg_listelt_t *element;
-       const cfg_listelt_t *element2;
        dns_fixedname_t fixed_id, fixed_name;
-       dns_name_t *id, *name;
-       const char *str;
+       dns_name_t *id = NULL, *name = NULL;
+       const char *str = NULL;
        isc_textregion_t r;
        dns_rdatatype_t type;
 
@@ -2581,9 +2524,7 @@ check_update_policy(const cfg_obj_t *policy) {
        }
 
        /* Now check the grant policy */
-       for (element = cfg_list_first(policy); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (policy, element) {
                const cfg_obj_t *stmt = cfg_listelt_value(element);
                const cfg_obj_t *identity = cfg_tuple_get(stmt, "identity");
                const cfg_obj_t *matchtype = cfg_tuple_get(stmt, "matchtype");
@@ -2698,9 +2639,7 @@ check_update_policy(const cfg_obj_t *policy) {
                        UNREACHABLE();
                }
 
-               for (element2 = cfg_list_first(typelist); element2 != NULL;
-                    element2 = cfg_list_next(element2))
-               {
+               CFG_LIST_FOREACH (typelist, element2) {
                        const cfg_obj_t *typeobj;
                        const char *bracket;
 
@@ -2878,7 +2817,6 @@ check_keydir(const cfg_obj_t *config, const cfg_obj_t *zconfig,
             dns_name_t *zname, const char *name, const char *keydir,
             isc_symtab_t *keydirs, isc_mem_t *mctx) {
        const char *dir = keydir;
-       const cfg_listelt_t *element;
        isc_result_t ret, result = ISC_R_SUCCESS;
        bool do_cleanup = false;
        bool done = false;
@@ -2903,9 +2841,7 @@ check_keydir(const cfg_obj_t *config, const cfg_obj_t *zconfig,
        /*
         * Build the keystore list.
         */
-       for (element = cfg_list_first(keystores); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (keystores, element) {
                cfg_obj_t *kcfg = cfg_listelt_value(element);
                (void)cfg_keystore_fromconfig(kcfg, mctx, &kslist, NULL);
        }
@@ -2915,9 +2851,7 @@ check_keydir(const cfg_obj_t *config, const cfg_obj_t *zconfig,
         * Look for the dnssec-policy by name, which is the dnssec-policy
         * for the zone in question.
         */
-       for (element = cfg_list_first(kasps); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (kasps, element) {
                cfg_obj_t *kconfig = cfg_listelt_value(element);
                const cfg_obj_t *kaspobj = NULL;
 
@@ -2935,6 +2869,7 @@ check_keydir(const cfg_obj_t *config, const cfg_obj_t *zconfig,
                if (ret != ISC_R_SUCCESS) {
                        kasp = NULL;
                }
+
                break;
        }
        if (kasp == NULL) {
@@ -2992,7 +2927,7 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions,
               isc_symtab_t *files, isc_symtab_t *keydirs, isc_symtab_t *inview,
               const char *viewname, dns_rdataclass_t defclass,
               cfg_aclconfctx_t *actx, isc_mem_t *mctx) {
-       const char *znamestr;
+       const char *znamestr = NULL;
        const char *typestr = NULL;
        const char *target = NULL;
        int ztype;
@@ -3009,7 +2944,6 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions,
        bool root = false;
        bool rfc1918 = false;
        bool ula = false;
-       const cfg_listelt_t *element;
        bool dlz;
        bool ddns = false;
        bool has_dnssecpolicy = false;
@@ -3254,9 +3188,7 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions,
                } else {
                        const cfg_obj_t *kasps = NULL;
                        (void)cfg_map_get(config, "dnssec-policy", &kasps);
-                       for (element = cfg_list_first(kasps); element != NULL;
-                            element = cfg_list_next(element))
-                       {
+                       CFG_LIST_FOREACH (kasps, element) {
                                const cfg_obj_t *kobj = cfg_tuple_get(
                                        cfg_listelt_value(element), "name");
                                if (strcmp(kaspname, cfg_obj_asstring(kobj)) ==
@@ -3664,9 +3596,7 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions,
        obj = NULL;
        (void)cfg_map_get(zoptions, "server-addresses", &obj);
        if (ztype == CFG_ZONE_STATICSTUB && obj != NULL) {
-               for (element = cfg_list_first(obj); element != NULL;
-                    element = cfg_list_next(element))
-               {
+               CFG_LIST_FOREACH (obj, element) {
                        isc_sockaddr_t sa;
                        isc_netaddr_t na;
                        obj = cfg_listelt_value(element);
@@ -3689,13 +3619,11 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions,
        obj = NULL;
        (void)cfg_map_get(zoptions, "server-names", &obj);
        if (zname != NULL && ztype == CFG_ZONE_STATICSTUB && obj != NULL) {
-               for (element = cfg_list_first(obj); element != NULL;
-                    element = cfg_list_next(element))
-               {
-                       const char *snamestr;
+               CFG_LIST_FOREACH (obj, element) {
+                       const char *snamestr = NULL;
                        dns_fixedname_t fixed_sname;
                        isc_buffer_t b2;
-                       dns_name_t *sname;
+                       dns_name_t *sname = NULL;
 
                        obj = cfg_listelt_value(element);
                        snamestr = cfg_obj_asstring(obj);
@@ -4121,15 +4049,12 @@ static isc_result_t
 check_keylist(const cfg_obj_t *keys, isc_symtab_t *symtab, isc_mem_t *mctx) {
        char namebuf[DNS_NAME_FORMATSIZE];
        dns_fixedname_t fname;
-       dns_name_t *name;
+       dns_name_t *name = NULL;
        isc_result_t result = ISC_R_SUCCESS;
        isc_result_t tresult;
-       const cfg_listelt_t *element;
 
        name = dns_fixedname_initname(&fname);
-       for (element = cfg_list_first(keys); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (keys, element) {
                const cfg_obj_t *key = cfg_listelt_value(element);
                const char *keyid = cfg_obj_asstring(cfg_map_getname(key));
                isc_symvalue_t symvalue;
@@ -4189,19 +4114,13 @@ check_keylist(const cfg_obj_t *keys, isc_symtab_t *symtab, isc_mem_t *mctx) {
  */
 static bool
 rndckey_exists(const cfg_obj_t *keylist, const char *keyname) {
-       const cfg_listelt_t *element;
-       const cfg_obj_t *obj;
-       const char *str;
-
        if (keylist == NULL) {
                return false;
        }
 
-       for (element = cfg_list_first(keylist); element != NULL;
-            element = cfg_list_next(element))
-       {
-               obj = cfg_listelt_value(element);
-               str = cfg_obj_asstring(cfg_map_getname(obj));
+       CFG_LIST_FOREACH (keylist, element) {
+               const cfg_obj_t *obj = cfg_listelt_value(element);
+               const char *str = cfg_obj_asstring(cfg_map_getname(obj));
                if (!strcasecmp(str, keyname)) {
                        return true;
                }
@@ -4247,20 +4166,16 @@ check_servers(const cfg_obj_t *config, const cfg_obj_t *voptions,
        dns_fixedname_t fname;
        isc_result_t result = ISC_R_SUCCESS;
        isc_result_t tresult;
-       const cfg_listelt_t *e1, *e2;
-       const cfg_obj_t *v1, *v2, *keys;
-       const cfg_obj_t *servers;
-       isc_netaddr_t n1, n2;
-       unsigned int p1, p2;
-       const cfg_obj_t *obj;
+       const cfg_obj_t *servers = NULL;
+       const cfg_obj_t *obj = NULL;
+       const cfg_obj_t *keys = NULL;
        char buf[ISC_NETADDR_FORMATSIZE];
        char namebuf[DNS_NAME_FORMATSIZE];
-       const char *xfr;
-       const char *keyval;
+       const char *xfr = NULL;
+       const char *keyval = NULL;
        isc_buffer_t b;
        int source;
-       dns_name_t *keyname;
-
+       dns_name_t *keyname = NULL;
        servers = NULL;
        if (voptions != NULL) {
                (void)cfg_map_get(voptions, "server", &servers);
@@ -4272,11 +4187,14 @@ check_servers(const cfg_obj_t *config, const cfg_obj_t *voptions,
                return ISC_R_SUCCESS;
        }
 
-       for (e1 = cfg_list_first(servers); e1 != NULL; e1 = cfg_list_next(e1)) {
+       CFG_LIST_FOREACH (servers, e1) {
+               const cfg_obj_t *v1 = cfg_listelt_value(e1);
+               isc_netaddr_t n1;
+               unsigned int p1;
                dns_peer_t *peer = NULL;
-               size_t i;
-               v1 = cfg_listelt_value(e1);
+
                cfg_obj_asnetprefix(cfg_map_getname(v1), &n1, &p1);
+
                /*
                 * Check that unused bits are zero.
                 */
@@ -4348,10 +4266,14 @@ check_servers(const cfg_obj_t *config, const cfg_obj_t *voptions,
                                }
                        }
                } while (sources[++source].v4 != NULL);
-               e2 = e1;
+
+               const cfg_listelt_t *e2 = e1;
                while ((e2 = cfg_list_next(e2)) != NULL) {
-                       v2 = cfg_listelt_value(e2);
+                       unsigned int p2;
+                       isc_netaddr_t n2;
+                       const cfg_obj_t *v2 = cfg_listelt_value(e2);
                        cfg_obj_asnetprefix(cfg_map_getname(v2), &n2, &p2);
+
                        if (p1 == p2 && isc_netaddr_equal(&n1, &n2)) {
                                const char *file = cfg_obj_file(v1);
                                unsigned int line = cfg_obj_line(v1);
@@ -4368,6 +4290,7 @@ check_servers(const cfg_obj_t *config, const cfg_obj_t *voptions,
                                result = ISC_R_FAILURE;
                        }
                }
+
                keys = NULL;
                cfg_map_get(v1, "keys", &keys);
                if (keys != NULL) {
@@ -4395,7 +4318,7 @@ check_servers(const cfg_obj_t *config, const cfg_obj_t *voptions,
                        }
                }
                (void)dns_peer_newprefix(mctx, &n1, p1, &peer);
-               for (i = 0; i < ARRAY_SIZE(bools); i++) {
+               for (size_t i = 0; i < ARRAY_SIZE(bools); i++) {
                        const cfg_obj_t *opt = NULL;
                        cfg_map_get(v1, bools[i].name, &opt);
                        if (opt != NULL) {
@@ -4411,7 +4334,7 @@ check_servers(const cfg_obj_t *config, const cfg_obj_t *voptions,
                                }
                        }
                }
-               for (i = 0; i < ARRAY_SIZE(uint32s); i++) {
+               for (size_t i = 0; i < ARRAY_SIZE(uint32s); i++) {
                        const cfg_obj_t *opt = NULL;
                        cfg_map_get(v1, uint32s[i].name, &opt);
                        if (opt != NULL) {
@@ -4714,16 +4637,13 @@ static isc_result_t
 record_static_keys(isc_symtab_t *symtab, isc_mem_t *mctx,
                   const cfg_obj_t *keylist, bool autovalidation) {
        isc_result_t result, ret = ISC_R_SUCCESS;
-       const cfg_listelt_t *elt;
        dns_fixedname_t fixed;
-       dns_name_t *name;
+       dns_name_t *name = NULL;
        char namebuf[DNS_NAME_FORMATSIZE], *p = NULL;
 
        name = dns_fixedname_initname(&fixed);
 
-       for (elt = cfg_list_first(keylist); elt != NULL;
-            elt = cfg_list_next(elt))
-       {
+       CFG_LIST_FOREACH (keylist, elt) {
                const char *initmethod;
                const cfg_obj_t *init = NULL;
                const cfg_obj_t *obj = cfg_listelt_value(elt);
@@ -4777,16 +4697,13 @@ record_static_keys(isc_symtab_t *symtab, isc_mem_t *mctx,
 static isc_result_t
 check_initializing_keys(isc_symtab_t *symtab, const cfg_obj_t *keylist) {
        isc_result_t result, ret = ISC_R_SUCCESS;
-       const cfg_listelt_t *elt;
        dns_fixedname_t fixed;
-       dns_name_t *name;
+       dns_name_t *name = NULL;
        char namebuf[DNS_NAME_FORMATSIZE];
 
        name = dns_fixedname_initname(&fixed);
 
-       for (elt = cfg_list_first(keylist); elt != NULL;
-            elt = cfg_list_next(elt))
-       {
+       CFG_LIST_FOREACH (keylist, elt) {
                const cfg_obj_t *obj = cfg_listelt_value(elt);
                const cfg_obj_t *init = NULL;
                const char *str;
@@ -4834,16 +4751,13 @@ static isc_result_t
 record_ds_keys(isc_symtab_t *symtab, isc_mem_t *mctx,
               const cfg_obj_t *keylist) {
        isc_result_t result, ret = ISC_R_SUCCESS;
-       const cfg_listelt_t *elt;
        dns_fixedname_t fixed;
-       dns_name_t *name;
+       dns_name_t *name = NULL;
        char namebuf[DNS_NAME_FORMATSIZE], *p = NULL;
 
        name = dns_fixedname_initname(&fixed);
 
-       for (elt = cfg_list_first(keylist); elt != NULL;
-            elt = cfg_list_next(elt))
-       {
+       CFG_LIST_FOREACH (keylist, elt) {
                const char *initmethod;
                const cfg_obj_t *init = NULL;
                const cfg_obj_t *obj = cfg_listelt_value(elt);
@@ -4886,7 +4800,6 @@ static isc_result_t
 check_ta_conflicts(const cfg_obj_t *global_ta, const cfg_obj_t *view_ta,
                   bool autovalidation, isc_mem_t *mctx) {
        isc_result_t result = ISC_R_SUCCESS, tresult;
-       const cfg_listelt_t *elt = NULL;
        const cfg_obj_t *keylist = NULL;
        isc_symtab_t *statictab = NULL, *dstab = NULL;
 
@@ -4897,9 +4810,7 @@ check_ta_conflicts(const cfg_obj_t *global_ta, const cfg_obj_t *view_ta,
         * First we record all the static keys (trust-anchors configured with
         * "static-key"), and all the DS-style trust anchors.
         */
-       for (elt = cfg_list_first(global_ta); elt != NULL;
-            elt = cfg_list_next(elt))
-       {
+       CFG_LIST_FOREACH (global_ta, elt) {
                keylist = cfg_listelt_value(elt);
                tresult = record_static_keys(statictab, mctx, keylist,
                                             autovalidation);
@@ -4913,9 +4824,7 @@ check_ta_conflicts(const cfg_obj_t *global_ta, const cfg_obj_t *view_ta,
                }
        }
 
-       for (elt = cfg_list_first(view_ta); elt != NULL;
-            elt = cfg_list_next(elt))
-       {
+       CFG_LIST_FOREACH (view_ta, elt) {
                keylist = cfg_listelt_value(elt);
                tresult = record_static_keys(statictab, mctx, keylist,
                                             autovalidation);
@@ -4933,9 +4842,7 @@ check_ta_conflicts(const cfg_obj_t *global_ta, const cfg_obj_t *view_ta,
         * Next, ensure that there's no conflict between the
         * static keys and the trust-anchors configured with "initial-key".
         */
-       for (elt = cfg_list_first(global_ta); elt != NULL;
-            elt = cfg_list_next(elt))
-       {
+       CFG_LIST_FOREACH (global_ta, elt) {
                keylist = cfg_listelt_value(elt);
                tresult = check_initializing_keys(statictab, keylist);
                if (result == ISC_R_SUCCESS) {
@@ -4943,9 +4850,7 @@ check_ta_conflicts(const cfg_obj_t *global_ta, const cfg_obj_t *view_ta,
                }
        }
 
-       for (elt = cfg_list_first(view_ta); elt != NULL;
-            elt = cfg_list_next(elt))
-       {
+       CFG_LIST_FOREACH (view_ta, elt) {
                keylist = cfg_listelt_value(elt);
                tresult = check_initializing_keys(statictab, keylist);
                if (result == ISC_R_SUCCESS) {
@@ -4968,14 +4873,13 @@ static isc_result_t
 check_rpz_catz(const char *rpz_catz, const cfg_obj_t *rpz_obj,
               const char *viewname, isc_symtab_t *symtab,
               special_zonetype_t specialzonetype) {
-       const cfg_listelt_t *element;
-       const cfg_obj_t *obj, *nameobj, *zoneobj;
-       const char *zonename, *zonetype;
+       const cfg_obj_t *obj = NULL, *nameobj = NULL, *zoneobj = NULL;
+       const char *zonename = NULL, *zonetype = NULL;
        const char *forview = " for view ";
        isc_symvalue_t value;
        isc_result_t result = ISC_R_SUCCESS, tresult;
        dns_fixedname_t fixed;
-       dns_name_t *name;
+       dns_name_t *name = NULL;
        char namebuf[DNS_NAME_FORMATSIZE];
        unsigned int num_zones = 0;
 
@@ -4988,9 +4892,7 @@ check_rpz_catz(const char *rpz_catz, const cfg_obj_t *rpz_obj,
        name = dns_fixedname_initname(&fixed);
        obj = cfg_tuple_get(rpz_obj, "zone list");
 
-       for (element = cfg_list_first(obj); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (obj, element) {
                obj = cfg_listelt_value(element);
                nameobj = cfg_tuple_get(obj, "zone name");
                zonename = cfg_obj_asstring(nameobj);
@@ -5050,18 +4952,15 @@ check_rpz_catz(const char *rpz_catz, const cfg_obj_t *rpz_obj,
 
 static isc_result_t
 check_rpz(const cfg_obj_t *rpz_obj) {
-       const cfg_listelt_t *element;
-       const cfg_obj_t *obj, *nameobj, *edeobj;
-       const char *zonename;
+       const cfg_obj_t *obj = NULL, *nameobj = NULL, *edeobj = NULL;
+       const char *zonename = NULL;
        isc_result_t result = ISC_R_SUCCESS, tresult;
        dns_fixedname_t fixed;
        dns_name_t *name = dns_fixedname_initname(&fixed);
 
        obj = cfg_tuple_get(rpz_obj, "zone list");
 
-       for (element = cfg_list_first(obj); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (obj, element) {
                obj = cfg_listelt_value(element);
                nameobj = cfg_tuple_get(obj, "zone name");
                zonename = cfg_obj_asstring(nameobj);
@@ -5094,9 +4993,8 @@ check_rpz(const cfg_obj_t *rpz_obj) {
 
 static isc_result_t
 check_catz(const cfg_obj_t *catz_obj, const char *viewname, isc_mem_t *mctx) {
-       const cfg_listelt_t *element;
-       const cfg_obj_t *obj, *nameobj, *primariesobj;
-       const char *zonename;
+       const cfg_obj_t *obj = NULL, *nameobj = NULL, *primariesobj = NULL;
+       const char *zonename = NULL;
        const char *forview = " for view ";
        isc_result_t result = ISC_R_SUCCESS, tresult;
        isc_symtab_t *symtab = NULL;
@@ -5112,9 +5010,7 @@ check_catz(const cfg_obj_t *catz_obj, const char *viewname, isc_mem_t *mctx) {
 
        obj = cfg_tuple_get(catz_obj, "zone list");
 
-       for (element = cfg_list_first(obj); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (obj, element) {
                char namebuf[DNS_NAME_FORMATSIZE];
 
                obj = cfg_listelt_value(element);
@@ -5256,12 +5152,11 @@ check_viewconf(const cfg_obj_t *config, const cfg_obj_t *voptions,
        const cfg_obj_t *view_ta = NULL, *global_ta = NULL;
        const cfg_obj_t *check_keys[2] = { NULL, NULL };
        const cfg_obj_t *keys = NULL;
-       const cfg_listelt_t *element, *element2;
        isc_symtab_t *symtab = NULL;
        isc_result_t result = ISC_R_SUCCESS;
        isc_result_t tresult = ISC_R_SUCCESS;
        cfg_aclconfctx_t *actx = NULL;
-       const cfg_obj_t *obj;
+       const cfg_obj_t *obj = NULL;
        const cfg_obj_t *options = NULL;
        const cfg_obj_t *opts = NULL;
        const cfg_obj_t *plugin_list = NULL;
@@ -5299,9 +5194,7 @@ check_viewconf(const cfg_obj_t *config, const cfg_obj_t *voptions,
                (void)cfg_map_get(config, "zone", &zones);
        }
 
-       for (element = cfg_list_first(zones); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (zones, element) {
                const cfg_obj_t *zone = cfg_listelt_value(element);
 
                tresult = check_zoneconf(zone, voptions, config, symtab, files,
@@ -5448,15 +5341,10 @@ check_viewconf(const cfg_obj_t *config, const cfg_obj_t *voptions,
                if (check_keys[i] != NULL) {
                        unsigned int taflags = 0;
 
-                       for (element = cfg_list_first(check_keys[i]);
-                            element != NULL; element = cfg_list_next(element))
-                       {
+                       CFG_LIST_FOREACH (check_keys[i], element) {
                                const cfg_obj_t *keylist =
                                        cfg_listelt_value(element);
-                               for (element2 = cfg_list_first(keylist);
-                                    element2 != NULL;
-                                    element2 = cfg_list_next(element2))
-                               {
+                               CFG_LIST_FOREACH (keylist, element2) {
                                        obj = cfg_listelt_value(element2);
                                        tresult = check_trust_anchor(obj,
                                                                     &taflags);
@@ -5609,13 +5497,11 @@ static const char *default_channels[] = { "default_syslog", "default_stderr",
 static isc_result_t
 check_logging(const cfg_obj_t *config, isc_mem_t *mctx) {
        const cfg_obj_t *categories = NULL;
-       const cfg_obj_t *category;
+       const cfg_obj_t *category = NULL;
        const cfg_obj_t *channels = NULL;
-       const cfg_obj_t *channel;
-       const cfg_listelt_t *element;
-       const cfg_listelt_t *delement;
-       const char *channelname;
-       const char *catname;
+       const cfg_obj_t *channel = NULL;
+       const char *channelname = NULL;
+       const char *catname = NULL;
        const cfg_obj_t *fileobj = NULL;
        const cfg_obj_t *syslogobj = NULL;
        const cfg_obj_t *nullobj = NULL;
@@ -5643,9 +5529,7 @@ check_logging(const cfg_obj_t *config, isc_mem_t *mctx) {
 
        cfg_map_get(logobj, "channel", &channels);
 
-       for (element = cfg_list_first(channels); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (channels, element) {
                channel = cfg_listelt_value(element);
                channelname = cfg_obj_asstring(cfg_map_getname(channel));
                fileobj = syslogobj = nullobj = stderrobj = NULL;
@@ -5681,9 +5565,7 @@ check_logging(const cfg_obj_t *config, isc_mem_t *mctx) {
 
        cfg_map_get(logobj, "category", &categories);
 
-       for (element = cfg_list_first(categories); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (categories, element) {
                category = cfg_listelt_value(element);
                catname = cfg_obj_asstring(cfg_tuple_get(category, "name"));
                if (isc_log_categorybyname(catname) == ISC_LOGCATEGORY_INVALID)
@@ -5693,9 +5575,7 @@ check_logging(const cfg_obj_t *config, isc_mem_t *mctx) {
                        result = ISC_R_FAILURE;
                }
                channels = cfg_tuple_get(category, "destinations");
-               for (delement = cfg_list_first(channels); delement != NULL;
-                    delement = cfg_list_next(delement))
-               {
+               CFG_LIST_FOREACH (channels, delement) {
                        channel = cfg_listelt_value(delement);
                        channelname = cfg_obj_asstring(channel);
                        tresult = isc_symtab_lookup(symtab, channelname, 1,
@@ -5716,18 +5596,15 @@ static isc_result_t
 check_controlskeys(const cfg_obj_t *control, const cfg_obj_t *keylist) {
        isc_result_t result = ISC_R_SUCCESS;
        const cfg_obj_t *control_keylist;
-       const cfg_listelt_t *element;
-       const cfg_obj_t *key;
-       const char *keyval;
+       const cfg_obj_t *key = NULL;
+       const char *keyval = NULL;
 
        control_keylist = cfg_tuple_get(control, "keys");
        if (cfg_obj_isvoid(control_keylist)) {
                return ISC_R_SUCCESS;
        }
 
-       for (element = cfg_list_first(control_keylist); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (control_keylist, element) {
                key = cfg_listelt_value(element);
                keyval = cfg_obj_asstring(key);
 
@@ -5744,16 +5621,15 @@ static isc_result_t
 check_controls(const cfg_obj_t *config, isc_mem_t *mctx) {
        isc_result_t result = ISC_R_SUCCESS, tresult;
        cfg_aclconfctx_t *actx = NULL;
-       const cfg_listelt_t *element, *element2;
-       const cfg_obj_t *allow;
-       const cfg_obj_t *control;
-       const cfg_obj_t *controls;
+       const cfg_obj_t *allow = NULL;
+       const cfg_obj_t *control = NULL;
+       const cfg_obj_t *controls = NULL;
        const cfg_obj_t *controlslist = NULL;
-       const cfg_obj_t *inetcontrols;
-       const cfg_obj_t *unixcontrols;
+       const cfg_obj_t *inetcontrols = NULL;
+       const cfg_obj_t *unixcontrols = NULL;
        const cfg_obj_t *keylist = NULL;
        const cfg_obj_t *obj = NULL;
-       const char *path;
+       const char *path = NULL;
        dns_acl_t *acl = NULL;
        isc_symtab_t *symtab = NULL;
 
@@ -5772,17 +5648,13 @@ check_controls(const cfg_obj_t *config, isc_mem_t *mctx) {
         * INET: Check allow clause.
         * UNIX: Not supported.
         */
-       for (element = cfg_list_first(controlslist); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (controlslist, element) {
                controls = cfg_listelt_value(element);
                unixcontrols = NULL;
                inetcontrols = NULL;
                (void)cfg_map_get(controls, "unix", &unixcontrols);
                (void)cfg_map_get(controls, "inet", &inetcontrols);
-               for (element2 = cfg_list_first(inetcontrols); element2 != NULL;
-                    element2 = cfg_list_next(element2))
-               {
+               CFG_LIST_FOREACH (inetcontrols, element2) {
                        char socktext[ISC_SOCKADDR_FORMATSIZE];
                        isc_sockaddr_t addr;
 
@@ -5815,9 +5687,7 @@ check_controls(const cfg_obj_t *config, isc_mem_t *mctx) {
                                result = tresult;
                        }
                }
-               for (element2 = cfg_list_first(unixcontrols); element2 != NULL;
-                    element2 = cfg_list_next(element2))
-               {
+               CFG_LIST_FOREACH (unixcontrols, element2) {
                        control = cfg_listelt_value(element2);
                        path = cfg_obj_asstring(cfg_tuple_get(control, "path"));
                        cfg_obj_log(control, ISC_LOG_ERROR,
@@ -5839,7 +5709,6 @@ isccfg_check_namedconf(const cfg_obj_t *config, unsigned int flags,
        const cfg_obj_t *options = NULL;
        const cfg_obj_t *views = NULL;
        const cfg_obj_t *acls = NULL;
-       const cfg_listelt_t *velement;
        isc_result_t result = ISC_R_SUCCESS;
        isc_result_t tresult = ISC_R_SUCCESS;
        isc_symtab_t *symtab = NULL;
@@ -5935,9 +5804,7 @@ isccfg_check_namedconf(const cfg_obj_t *config, unsigned int flags,
 
        isc_symtab_create(mctx, NULL, NULL, true, &symtab);
 
-       for (velement = cfg_list_first(views); velement != NULL;
-            velement = cfg_list_next(velement))
-       {
+       CFG_LIST_FOREACH (views, velement) {
                const cfg_obj_t *view = cfg_listelt_value(velement);
                const cfg_obj_t *vname = cfg_tuple_get(view, "name");
                const cfg_obj_t *voptions = cfg_tuple_get(view, "options");
@@ -6005,13 +5872,9 @@ isccfg_check_namedconf(const cfg_obj_t *config, unsigned int flags,
        cfg_map_get(config, "acl", &acls);
 
        if (acls != NULL) {
-               const cfg_listelt_t *elt;
-               const cfg_listelt_t *elt2;
-               const char *aclname;
+               const char *aclname = NULL;
 
-               for (elt = cfg_list_first(acls); elt != NULL;
-                    elt = cfg_list_next(elt))
-               {
+               CFG_LIST_FOREACH (acls, elt) {
                        const cfg_obj_t *acl = cfg_listelt_value(elt);
                        unsigned int line = cfg_obj_line(acl);
                        unsigned int i;
@@ -6033,8 +5896,8 @@ isccfg_check_namedconf(const cfg_obj_t *config, unsigned int flags,
                                }
                        }
 
-                       for (elt2 = cfg_list_next(elt); elt2 != NULL;
-                            elt2 = cfg_list_next(elt2))
+                       for (const cfg_listelt_t *elt2 = cfg_list_next(elt);
+                            elt2 != NULL; elt2 = cfg_list_next(elt2))
                        {
                                const cfg_obj_t *acl2 = cfg_listelt_value(elt2);
                                const char *name;
index 8489a63e71e38cdb6c4cd5273c641af4e85fa3f8..260654073b2fbbd66a4c024bdff966f503bd1cae 100644 (file)
@@ -73,6 +73,12 @@ typedef struct cfg_listelt cfg_listelt_t;
 typedef isc_result_t (*cfg_parsecallback_t)(const char     *clausename,
                                            const cfg_obj_t *obj, void *arg);
 
+//* clang-format off */
+#define CFG_LIST_FOREACH(listobj, elt)                                        \
+       for (const cfg_listelt_t *elt = cfg_list_first(listobj); elt != NULL; \
+            elt = cfg_list_next(elt))
+//* clang-format on */
+
 /***
  *** Functions
  ***/
index 4645b503689a9c26a49d130aa62c80d1136ced33..8b5bd53f6df02ba69b3f7a7618c96515d5348d59 100644 (file)
@@ -443,7 +443,6 @@ cfg_kasp_fromconfig(const cfg_obj_t *config, dns_kasp_t *default_kasp,
        const cfg_obj_t *inlinesigning = NULL;
        const cfg_obj_t *cds = NULL;
        const cfg_obj_t *obj = NULL;
-       const cfg_listelt_t *element = NULL;
        const char *kaspname = NULL;
        dns_kasp_t *kasp = NULL;
        size_t i = 0;
@@ -591,9 +590,7 @@ cfg_kasp_fromconfig(const cfg_obj_t *config, dns_kasp_t *default_kasp,
 
        (void)confget(maps, "cds-digest-types", &cds);
        if (cds != NULL) {
-               for (element = cfg_list_first(cds); element != NULL;
-                    element = cfg_list_next(element))
-               {
+               CFG_LIST_FOREACH (cds, element) {
                        result = add_digest(kasp, cfg_listelt_value(element));
                        if (result != ISC_R_SUCCESS) {
                                goto cleanup;
@@ -630,9 +627,7 @@ cfg_kasp_fromconfig(const cfg_obj_t *config, dns_kasp_t *default_kasp,
                char role[256] = { 0 };
                bool warn[256][2] = { { false } };
 
-               for (element = cfg_list_first(keys); element != NULL;
-                    element = cfg_list_next(element))
-               {
+               CFG_LIST_FOREACH (keys, element) {
                        cfg_obj_t *kobj = cfg_listelt_value(element);
                        result = cfg_kaspkey_fromconfig(
                                kobj, kasp, check_algorithms, offline_ksk,
index 49058e3b415fbecfd5d571eb315181ccfc23cb9a..c9a358c35fff0b0515ad22d4c8dd47587742fe96 100644 (file)
@@ -3947,14 +3947,11 @@ isc_result_t
 cfg_pluginlist_foreach(const cfg_obj_t *config, const cfg_obj_t *list,
                       pluginlist_cb_t *callback, void *callback_data) {
        isc_result_t result = ISC_R_SUCCESS;
-       const cfg_listelt_t *element;
 
        REQUIRE(config != NULL);
        REQUIRE(callback != NULL);
 
-       for (element = cfg_list_first(list); element != NULL;
-            element = cfg_list_next(element))
-       {
+       CFG_LIST_FOREACH (list, element) {
                const cfg_obj_t *plugin = cfg_listelt_value(element);
                const cfg_obj_t *obj;
                const char *type, *library;
index 8808b0d0856e172f7feebd3c024c6440c4fb903f..d0300f235975b648bc9a5a099f4db3a185e22717 100644 (file)
@@ -125,7 +125,6 @@ ISC_RUN_TEST_IMPL(duration) {
        bool must_fail = false;
 
        for (size_t i = 0; i < ARRAY_SIZE(durations); i++) {
-               const cfg_listelt_t *element;
                const cfg_obj_t *kasps = NULL;
                const char cfg_tpl[] =
                        "dnssec-policy \"dp\"\n"
@@ -159,9 +158,7 @@ ISC_RUN_TEST_IMPL(duration) {
 
                (void)cfg_map_get(c1, "dnssec-policy", &kasps);
                assert_non_null(kasps);
-               for (element = cfg_list_first(kasps); element != NULL;
-                    element = cfg_list_next(element))
-               {
+               CFG_LIST_FOREACH (kasps, element) {
                        const cfg_listelt_t *key_element;
                        const cfg_obj_t *lifetime = NULL;
                        const cfg_obj_t *keys = NULL;