]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
[master] add -J option to checkzone/compilezone
authorEvan Hunt <each@isc.org>
Thu, 10 Jan 2013 00:56:46 +0000 (16:56 -0800)
committerEvan Hunt <each@isc.org>
Thu, 10 Jan 2013 00:56:46 +0000 (16:56 -0800)
3459. [func] Added -J option to named-checkzone/named-compilezone
to specify the path to the journal file. [RT #30958]

CHANGES
bin/check/check-tool.c
bin/check/check-tool.h
bin/check/named-checkzone.c
bin/check/named-checkzone.docbook
bin/tests/Makefile.in
bin/tests/makejournal.c [new file with mode: 0644]
bin/tests/system/checkzone/clean.sh
bin/tests/system/checkzone/tests.sh
bin/tests/system/checkzone/zones/test1.db [new file with mode: 0644]
bin/tests/system/checkzone/zones/test2.db [new file with mode: 0644]

diff --git a/CHANGES b/CHANGES
index 74d3bede607608c1f2bc69da92add692c9480197..705738547e06874a7a2278de4f857cde4d11a7dc 100644 (file)
--- 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]
 
index 1e534071d0c80fa6361b118291fb47cc6e069e62..148995af893c1f1bbc7c0b7eb0f9840f735fabaa 100644 (file)
@@ -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);
index 0794729ee05f56cd091c3ab5c88d60b68ab938cd..5ff99f5549a52c0640b90ea118cd46cc7283ab91 100644 (file)
@@ -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;
index e5076dc7984c0f6a3b9e71d390382e6d1364ee33..e7ad0ba05edc940b6314e6826d85f264e4bae27c 100644 (file)
@@ -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;
index e289fbb15b4e5c10cded3f5de5594d1886b8afd0..7fdf02ebe1d695cd78a94a0711ee8592afd2ee4d 100644 (file)
@@ -67,6 +67,7 @@
       <arg><option>-c <replaceable class="parameter">class</replaceable></option></arg>
       <arg><option>-f <replaceable class="parameter">format</replaceable></option></arg>
       <arg><option>-F <replaceable class="parameter">format</replaceable></option></arg>
+      <arg><option>-J <replaceable class="parameter">filename</replaceable></option></arg>
       <arg><option>-i <replaceable class="parameter">mode</replaceable></option></arg>
       <arg><option>-k <replaceable class="parameter">mode</replaceable></option></arg>
       <arg><option>-m <replaceable class="parameter">mode</replaceable></option></arg>
@@ -94,6 +95,7 @@
       <arg><option>-C <replaceable class="parameter">mode</replaceable></option></arg>
       <arg><option>-f <replaceable class="parameter">format</replaceable></option></arg>
       <arg><option>-F <replaceable class="parameter">format</replaceable></option></arg>
+      <arg><option>-J <replaceable class="parameter">filename</replaceable></option></arg>
       <arg><option>-i <replaceable class="parameter">mode</replaceable></option></arg>
       <arg><option>-k <replaceable class="parameter">mode</replaceable></option></arg>
       <arg><option>-m <replaceable class="parameter">mode</replaceable></option></arg>
         <term>-j</term>
         <listitem>
           <para>
-            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 <filename>.jnl</filename>.
+          </para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>-J <replaceable class="parameter">filename</replaceable></term>
+        <listitem>
+          <para>
+            When loading the zone file read the journal from the given
+            file, if it exists. (Implies -j.)
           </para>
         </listitem>
       </varlistentry>
index bc040a397064ac5e9324784b9e6da244de0c0a54..d7e6d5ed36dc630bc33098c4b2c7fa3f59f9b85e 100644 (file)
@@ -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 (file)
index 0000000..5ffe5f1
--- /dev/null
@@ -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 <config.h>
+
+#include <isc/entropy.h>
+#include <isc/hash.h>
+#include <isc/log.h>
+#include <isc/mem.h>
+#include <isc/util.h>
+
+#include <dns/db.h>
+#include <dns/fixedname.h>
+#include <dns/journal.h>
+#include <dns/log.h>
+#include <dns/name.h>
+#include <dns/result.h>
+#include <dns/types.h>
+
+#include <stdlib.h>
+
+#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);
+}
+
index c0efc60a7f1c197ff8bbf186979928b983aaef23..5cf70db9d4cc821f6dbf0be99895b0c6021fe535 100644 (file)
@@ -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.*
index b50722b7a2482b4474aa9410c63a6a89ffb6c597..f5e4301d52c20e00be4fe40b0196275e6dae3a07 100644 (file)
@@ -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 (file)
index 0000000..ca9cfd1
--- /dev/null
@@ -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 (file)
index 0000000..9ddd0ad
--- /dev/null
@@ -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