diff --git a/CHANGES b/CHANGES index 74d3bede60..705738547e 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +3459. [func] Added -J option to named-checkzone/named-compilezone + to specify the path to the journal file. [RT #30958] + 3458. [bug] Return FORMERR when presented with a overly long domain named in a request. [RT #29682] diff --git a/bin/check/check-tool.c b/bin/check/check-tool.c index 1e534071d0..148995af89 100644 --- a/bin/check/check-tool.c +++ b/bin/check/check-tool.c @@ -86,6 +86,7 @@ static const char *dbtype[] = { "rbt" }; int debug = 0; +const char *journal = NULL; isc_boolean_t nomerge = ISC_TRUE; #if CHECK_LOCAL isc_boolean_t docheckmx = ISC_TRUE; @@ -608,6 +609,8 @@ load_zone(isc_mem_t *mctx, const char *zonename, const char *filename, CHECK(dns_zone_setorigin(zone, origin)); CHECK(dns_zone_setdbtype(zone, 1, (const char * const *) dbtype)); CHECK(dns_zone_setfile2(zone, filename, fileformat)); + if (journal != NULL) + CHECK(dns_zone_setjournal(zone, journal)); DE_CONST(classname, region.base); region.length = strlen(classname); diff --git a/bin/check/check-tool.h b/bin/check/check-tool.h index 0794729ee0..5ff99f5549 100644 --- a/bin/check/check-tool.h +++ b/bin/check/check-tool.h @@ -50,6 +50,7 @@ void DestroySockets(void); #endif extern int debug; +extern const char *journal; extern isc_boolean_t nomerge; extern isc_boolean_t docheckmx; extern isc_boolean_t docheckns; diff --git a/bin/check/named-checkzone.c b/bin/check/named-checkzone.c index e5076dc798..e7ad0ba05e 100644 --- a/bin/check/named-checkzone.c +++ b/bin/check/named-checkzone.c @@ -78,7 +78,7 @@ static void usage(void) { fprintf(stderr, "usage: %s [-djqvD] [-c class] " - "[-f inputformat] [-F outputformat] " + "[-f inputformat] [-F outputformat] [-J filename] " "[-t directory] [-w directory] [-k (ignore|warn|fail)] " "[-n (ignore|warn|fail)] [-m (ignore|warn|fail)] " "[-r (ignore|warn|fail)] " @@ -167,7 +167,7 @@ main(int argc, char **argv) { isc_commandline_errprint = ISC_FALSE; while ((c = isc_commandline_parse(argc, argv, - "c:df:hi:jk:L:m:n:qr:s:t:o:vw:DF:M:S:W:")) + "c:df:hi:jJ:k:L:m:n:qr:s:t:o:vw:DF:M:S:W:")) != EOF) { switch (c) { case 'c': @@ -228,6 +228,11 @@ main(int argc, char **argv) { nomerge = ISC_FALSE; break; + case 'J': + journal = isc_commandline_argument; + nomerge = ISC_FALSE; + break; + case 'k': if (ARGCMP("warn")) { zone_options |= DNS_ZONEOPT_CHECKNAMES; diff --git a/bin/check/named-checkzone.docbook b/bin/check/named-checkzone.docbook index e289fbb15b..7fdf02ebe1 100644 --- a/bin/check/named-checkzone.docbook +++ b/bin/check/named-checkzone.docbook @@ -67,6 +67,7 @@ + @@ -94,6 +95,7 @@ + @@ -177,7 +179,19 @@ -j - When loading the zone file read the journal if it exists. + When loading a zone file, read the journal if it exists. + The journal file name is assumed to be the zone file name + appended with the string .jnl. + + + + + + -J filename + + + When loading the zone file read the journal from the given + file, if it exists. (Implies -j.) diff --git a/bin/tests/Makefile.in b/bin/tests/Makefile.in index bc040a3970..d7e6d5ed36 100644 --- a/bin/tests/Makefile.in +++ b/bin/tests/Makefile.in @@ -46,9 +46,10 @@ SUBDIRS = atomic db dst master mem hashes names net rbt resolver \ # Test programs that are built by default: # cfg_test is needed for regenerating doc/misc/options +# makejournal is needed by system tests # Alphabetically -TARGETS = cfg_test@EXEEXT@ +TARGETS = cfg_test@EXEEXT@ makejournal@EXEEXT@ # All the other tests are optional and not built by default. @@ -92,7 +93,7 @@ XTARGETS = adb_test@EXEEXT@ \ zone_test@EXEEXT@ # Alphabetically -SRCS = cfg_test.c ${XSRCS} +SRCS = cfg_test.c makejournal.c ${XSRCS} XSRCS = adb_test.c \ byaddr_test.c \ @@ -310,6 +311,10 @@ cfg_test@EXEEXT@: cfg_test.@O@ ${ISCCFGDEPLIBS} ${ISCDEPLIBS} ${LIBTOOL_MODE_LINK} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ cfg_test.@O@ \ ${ISCCFGLIBS} ${DNSLIBS} ${ISCLIBS} ${LIBS} +makejournal@EXEEXT@: makejournal.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS} + ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ makejournal.@O@ \ + ${DNSLIBS} ${ISCLIBS} ${LIBS} + distclean:: rm -f headerdep_test.sh diff --git a/bin/tests/makejournal.c b/bin/tests/makejournal.c new file mode 100644 index 0000000000..5ffe5f16a2 --- /dev/null +++ b/bin/tests/makejournal.c @@ -0,0 +1,171 @@ +/* + * 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. + */ + +/*! \file */ +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#define CHECK(r) \ + do { \ + result = (r); \ + if (result != ISC_R_SUCCESS) \ + goto cleanup; \ + } while (0) + +isc_mem_t *mctx = NULL; +isc_log_t *lctx = NULL; +isc_entropy_t *ectx = NULL; + +static isc_boolean_t hash_active = ISC_FALSE, dst_active = ISC_FALSE; + +/* + * Logging categories: this needs to match the list in bin/named/log.c. + */ +static isc_logcategory_t categories[] = { + { "", 0 }, + { "client", 0 }, + { "network", 0 }, + { "update", 0 }, + { "queries", 0 }, + { "unmatched", 0 }, + { "update-security", 0 }, + { "query-errors", 0 }, + { NULL, 0 } +}; + +static isc_result_t +loadzone(dns_db_t **db, const char *origin, const char *filename) { + isc_result_t result; + dns_fixedname_t fixed; + dns_name_t *name; + + dns_fixedname_init(&fixed); + name = dns_fixedname_name(&fixed); + + result = dns_name_fromstring(name, origin, 0, NULL); + if (result != ISC_R_SUCCESS) + return(result); + + result = dns_db_create(mctx, "rbt", name, dns_dbtype_zone, + dns_rdataclass_in, 0, NULL, db); + if (result != ISC_R_SUCCESS) + return (result); + + result = dns_db_load(*db, filename); + return (result); +} + +int +main(int argc, char **argv) { + isc_result_t result; + char *origin, *file1, *file2, *journal; + dns_db_t *old = NULL, *new = NULL; + isc_logdestination_t destination; + isc_logconfig_t *logconfig = NULL; + + if (argc != 5) { + printf("usage: %s origin file1 file2 journal\n", argv[0]); + return (1); + } + + origin = argv[1]; + file1 = argv[2]; + file2 = argv[3]; + journal = argv[4]; + + isc_mem_debugging |= ISC_MEM_DEBUGRECORD; + CHECK(isc_mem_create(0, 0, &mctx)); + CHECK(isc_entropy_create(mctx, &ectx)); + + CHECK(isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE)); + hash_active = ISC_TRUE; + + CHECK(dst_lib_init(mctx, ectx, ISC_ENTROPY_BLOCKING)); + dst_active = ISC_TRUE; + + CHECK(isc_log_create(mctx, &lctx, &logconfig)); + isc_log_registercategories(lctx, categories); + isc_log_setcontext(lctx); + dns_log_init(lctx); + dns_log_setcontext(lctx); + + destination.file.stream = stderr; + destination.file.name = NULL; + destination.file.versions = ISC_LOG_ROLLNEVER; + destination.file.maximum_size = 0; + CHECK(isc_log_createchannel(logconfig, "stderr", + ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, + &destination, 0)); + CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL)); + + dns_result_register(); + + result = loadzone(&old, origin, file1); + if (result != ISC_R_SUCCESS) { + fprintf(stderr, "Couldn't load %s: ", file1); + goto cleanup; + } + + result = loadzone(&new, origin, file2); + if (result != ISC_R_SUCCESS) { + fprintf(stderr, "Couldn't load %s: ", file2); + goto cleanup; + } + + result = dns_db_diff(mctx, new, NULL, old, NULL, journal); + + cleanup: + if (result != ISC_R_SUCCESS) + fprintf(stderr, "%s\n", isc_result_totext(result)); + + if (new != NULL) + dns_db_detach(&new); + if (old != NULL) + dns_db_detach(&old); + + if (lctx != NULL) + isc_log_destroy(&lctx); + if (dst_active) { + dst_lib_destroy(); + dst_active = ISC_FALSE; + } + if (hash_active) { + isc_hash_destroy(); + hash_active = ISC_FALSE; + } + if (ectx != NULL) + isc_entropy_detach(&ectx); + if (mctx != NULL) + isc_mem_destroy(&mctx); + + return(result != ISC_R_SUCCESS ? 1 : 0); +} + diff --git a/bin/tests/system/checkzone/clean.sh b/bin/tests/system/checkzone/clean.sh index c0efc60a7f..5cf70db9d4 100644 --- a/bin/tests/system/checkzone/clean.sh +++ b/bin/tests/system/checkzone/clean.sh @@ -14,4 +14,4 @@ # $Id: clean.sh,v 1.2 2011/03/02 04:20:33 marka Exp $ -rm -f test.out.* +rm -f test.* diff --git a/bin/tests/system/checkzone/tests.sh b/bin/tests/system/checkzone/tests.sh index b50722b7a2..f5e4301d52 100644 --- a/bin/tests/system/checkzone/tests.sh +++ b/bin/tests/system/checkzone/tests.sh @@ -12,8 +12,6 @@ # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # PERFORMANCE OF THIS SOFTWARE. -# $Id: tests.sh,v 1.2 2011/03/02 04:20:33 marka Exp $ - SYSTEMTESTTOP=.. . $SYSTEMTESTTOP/conf.sh @@ -30,4 +28,19 @@ do status=`expr $status + $ret` done +echo "I:checking with journal file ($n)" +ret=0 +$CHECKZONE -D -o test.orig.db test zones/test1.db > /dev/null 2>&1 || ret=1 +$CHECKZONE -D -o test.changed.db test zones/test2.db > /dev/null 2>&1 || ret=1 +../../makejournal test test.orig.db test.changed.db test.orig.db.jnl 2>&1 || ret=1 +jlines=`$JOURNALPRINT test.orig.db.jnl | wc -l` +[ $jlines = 3 ] || ret=1 +$CHECKZONE -D -j -o test.out1.db test test.orig.db > /dev/null 2>&1 || ret=1 +cmp -s test.changed.db test.out1.db || ret=1 +mv -f test.orig.db.jnl test.journal +$CHECKZONE -D -J test.journal -o test.out2.db test test.orig.db > /dev/null 2>&1 || ret=1 +cmp -s test.changed.db test.out2.db || ret=1 +if [ $ret != 0 ]; then echo "I:failed"; fi +status=`expr $status + $ret` + exit $status diff --git a/bin/tests/system/checkzone/zones/test1.db b/bin/tests/system/checkzone/zones/test1.db new file mode 100644 index 0000000000..ca9cfd1230 --- /dev/null +++ b/bin/tests/system/checkzone/zones/test1.db @@ -0,0 +1,21 @@ +; Copyright (C) 2012 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. + + +$TTL 600 +@ SOA ns hostmaster 2012010901 3600 1200 604800 1200 + NS ns +ns A 192.0.2.1 + +addr1 A 10.53.0.1 diff --git a/bin/tests/system/checkzone/zones/test2.db b/bin/tests/system/checkzone/zones/test2.db new file mode 100644 index 0000000000..9ddd0adf31 --- /dev/null +++ b/bin/tests/system/checkzone/zones/test2.db @@ -0,0 +1,22 @@ +; Copyright (C) 2012 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. + + +$TTL 600 +@ SOA ns hostmaster 2012010902 3600 1200 604800 1200 + NS ns +ns A 192.0.2.1 + +addr1 A 10.53.0.1 +addr2 A 10.53.0.2