From: Evan Hunt Date: Mon, 25 Nov 2013 21:25:00 +0000 (-0800) Subject: [v9_6] check hint files in named-checkconf -z X-Git-Tag: v9.6-ESV-R11b1~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=21e26d8f65781574ec50bbcf4e917a66b039d075;p=thirdparty%2Fbind9.git [v9_6] check hint files in named-checkconf -z 3676. [bug] "named-checkconf -z" now checks zones of type hint and redirect as well as master. [RT #35046] (cherry picked from commit d999ca28d40337907b55eebc28a255b638702379) (cherry picked from commit 2254826e4cab47a7a8b19ec566404f0aa6fe9e54) (cherry picked from commit 4ed930b4f89550131a6d2ab5f60ffb09e62d102f) --- diff --git a/CHANGES b/CHANGES index 6b0a55dd223..4e5fdb22d03 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +3676. [bug] "named-checkconf -z" now checks zones of type + hint as well as master. [RT #35046] + 3675. [misc] Provide a place for third parties to add version information for their extensions in the version file by setting the EXTENSIONS variable. diff --git a/bin/check/named-checkconf.c b/bin/check/named-checkconf.c index 48e1137e8a6..c49a1ca521c 100644 --- a/bin/check/named-checkconf.c +++ b/bin/check/named-checkconf.c @@ -39,10 +39,13 @@ #include +#include #include #include #include +#include #include +#include #include #include "check-tool.h" @@ -151,6 +154,30 @@ config_get(const cfg_obj_t **maps, const char *name, const cfg_obj_t **obj) { } } +static isc_result_t +configure_hint(const char *zfile, const char *zclass, isc_mem_t *mctx) { + isc_result_t result; + dns_db_t *db = NULL; + dns_rdataclass_t rdclass; + isc_textregion_t r; + + if (zfile == NULL) + return (ISC_R_FAILURE); + + DE_CONST(zclass, r.base); + r.length = strlen(zclass); + result = dns_rdataclass_fromtext(&rdclass, &r); + if (result != ISC_R_SUCCESS) + return (result); + + result = dns_rootns_create(mctx, rdclass, zfile, &db); + if (result != ISC_R_SUCCESS) + return (result); + + dns_db_detach(&db); + return (ISC_R_SUCCESS); +} + /*% configure the zone */ static isc_result_t configure_zone(const char *vclass, const char *view, @@ -161,7 +188,7 @@ configure_zone(const char *vclass, const char *view, isc_result_t result; const char *zclass; const char *zname; - const char *zfile; + const char *zfile = NULL; const cfg_obj_t *maps[4]; const cfg_obj_t *zoptions = NULL; const cfg_obj_t *classobj = NULL; @@ -195,15 +222,26 @@ configure_zone(const char *vclass, const char *view, cfg_map_get(zoptions, "type", &typeobj); if (typeobj == NULL) return (ISC_R_FAILURE); - if (strcasecmp(cfg_obj_asstring(typeobj), "master") != 0) + + cfg_map_get(zoptions, "file", &fileobj); + if (fileobj != NULL) + zfile = cfg_obj_asstring(fileobj); + + /* + * Check hints files for hint zones. + * Skip loading checks for any type other than master. + */ + if (strcasecmp(cfg_obj_asstring(typeobj), "hint") == 0) + return (configure_hint(zfile, zclass, mctx)); + else if ((strcasecmp(cfg_obj_asstring(typeobj), "master") != 0)) return (ISC_R_SUCCESS); + + if (zfile == NULL) + return (ISC_R_FAILURE); + cfg_map_get(zoptions, "database", &dbobj); if (dbobj != NULL) return (ISC_R_SUCCESS); - cfg_map_get(zoptions, "file", &fileobj); - if (fileobj == NULL) - return (ISC_R_FAILURE); - zfile = cfg_obj_asstring(fileobj); obj = NULL; if (get_maps(maps, "check-mx", &obj)) { @@ -323,7 +361,7 @@ configure_zone(const char *vclass, const char *view, if (result != ISC_R_SUCCESS) fprintf(stderr, "%s/%s/%s: %s\n", view, zname, zclass, dns_result_totext(result)); - return(result); + return (result); } /*% configure a view */ diff --git a/bin/tests/system/checkconf/hint-nofile.conf b/bin/tests/system/checkconf/hint-nofile.conf new file mode 100644 index 00000000000..57c07e7086a --- /dev/null +++ b/bin/tests/system/checkconf/hint-nofile.conf @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC") + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +zone "." { + type hint; + file "nonexistent.db"; +}; diff --git a/bin/tests/system/checkconf/tests.sh b/bin/tests/system/checkconf/tests.sh index cc5db0439ed..c034c1ae24d 100644 --- a/bin/tests/system/checkconf/tests.sh +++ b/bin/tests/system/checkconf/tests.sh @@ -38,6 +38,12 @@ $CHECKCONF badtsig.conf > /dev/null 2>&1 if [ $? != 1 ]; then echo "I:failed"; ret=1; fi status=`expr $status + $ret` +echo "I: checking that named-checkconf -z catches missing hint file" +ret=0 +$CHECKCONF -z hint-nofile.conf > /dev/null 2>&1 && ret=1 +if [ $ret != 0 ]; then echo "I:failed"; fi +status=`expr $status + $ret` + echo "I: range checking fields that do not allow zero" ret=0 for field in max-retry-time min-retry-time max-refresh-time min-refresh-time; do