]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
1549. [func] named-checkzone can now write out the zone contents
authorMark Andrews <marka@isc.org>
Wed, 7 Jan 2004 05:27:17 +0000 (05:27 +0000)
committerMark Andrews <marka@isc.org>
Wed, 7 Jan 2004 05:27:17 +0000 (05:27 +0000)
                        in a easily parsable format (-D and -o).

CHANGES
bin/check/check-tool.c
bin/check/check-tool.h
bin/check/named-checkzone.c
bin/check/named-checkzone.docbook
lib/dns/include/dns/masterdump.h
lib/dns/include/dns/zone.h
lib/dns/masterdump.c
lib/dns/zone.c

diff --git a/CHANGES b/CHANGES
index 83c9ca2e6c14ca309661e2502ba610a33e00cb7f..aec5db025209dbf42dfc174b85f7bdf46c578288 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+1549.  [func]          named-checkzone can now write out the zone contents
+                       in a easily parsable format (-D and -o).
+
 1548.  [bug]           When parsing APL records it was possible to silently
                        accept out of range ADDRESSFAMILY values. [RT# 9979]
 
index c9bebd0ccf0277491445abdecbabec1050b0c3fe..448887f5ded9a65769abd006d79d12ccf92875dc 100644 (file)
@@ -15,7 +15,7 @@
  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: check-tool.c,v 1.8 2002/07/19 02:34:57 marka Exp $ */
+/* $Id: check-tool.c,v 1.9 2004/01/07 05:27:17 marka Exp $ */
 
 #include <config.h>
 
@@ -28,6 +28,7 @@
 #include <isc/buffer.h>
 #include <isc/log.h>
 #include <isc/region.h>
+#include <isc/stdio.h>
 #include <isc/types.h>
 
 #include <dns/fixedname.h>
@@ -124,3 +125,35 @@ load_zone(isc_mem_t *mctx, const char *zonename, const char *filename,
                dns_zone_detach(&zone);
        return (result);
 }
+
+isc_result_t
+dump_zone(const char *zonename, dns_zone_t *zone, const char *filename)
+{
+       isc_result_t result;
+       FILE *output = stdout;
+
+       if (debug) {
+               if (filename != NULL)
+                       fprintf(stderr, "dumping \"%s\" to \"%s\"\n",
+                               zonename, filename);
+               else
+                       fprintf(stderr, "dumping \"%s\"\n", zonename);
+       }
+
+       if (filename != NULL) {
+               result = isc_stdio_open(filename, "w+", &output);
+
+               if (result != ISC_R_SUCCESS) {
+                       fprintf(stderr, "could not open output "
+                               "file \"%s\" for writing\n", filename);
+                       return (ISC_R_FAILURE);
+               }
+       }
+
+       result = dns_zone_fulldumptostream(zone, output);
+
+       if (filename != NULL)
+               (void)isc_stdio_close(output);
+
+       return (result);
+}
index 85b05bab1b316cbd4e652080ea1e67626e028971..37728e5705cfda502787ab92c8000b3074d4617d 100644 (file)
@@ -15,7 +15,7 @@
  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: check-tool.h,v 1.5 2002/07/19 02:34:58 marka Exp $ */
+/* $Id: check-tool.h,v 1.6 2004/01/07 05:27:17 marka Exp $ */
 
 #ifndef CHECK_TOOL_H
 #define CHECK_TOOL_H
@@ -34,6 +34,9 @@ isc_result_t
 load_zone(isc_mem_t *mctx, const char *zonename, const char *filename,
          const char *classname, dns_zone_t **zonep);
 
+isc_result_t
+dump_zone(const char *zonename, dns_zone_t *zone, const char *filename);
+
 extern int debug;
 extern isc_boolean_t nomerge;
 extern unsigned int zone_options;
index 799892753ef0fbf8d0674c0e44e0971c94149950..692a9a6846c31a373ab75ce88a41b80d35db1a8f 100644 (file)
@@ -15,7 +15,7 @@
  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: named-checkzone.c,v 1.26 2003/10/17 03:46:41 marka Exp $ */
+/* $Id: named-checkzone.c,v 1.27 2004/01/07 05:27:17 marka Exp $ */
 
 #include <config.h>
 
@@ -46,6 +46,8 @@ static int quiet = 0;
 static isc_mem_t *mctx = NULL;
 dns_zone_t *zone = NULL;
 dns_zonetype_t zonetype = dns_zone_master;
+static int dumpzone = 0;
+static const char *output_filename;
 
 #define ERRRET(result, function) \
        do { \
@@ -60,8 +62,8 @@ dns_zonetype_t zonetype = dns_zone_master;
 static void
 usage(void) {
        fprintf(stderr,
-               "usage: named-checkzone [-djqv] [-c class] [-t directory] "
-               "[-w directory] zonename filename\n");
+               "usage: named-checkzone [-djqvD] [-c class] [-o output] "
+               "[-t directory] [-w directory] zonename filename\n");
        exit(1);
 }
 
@@ -82,7 +84,7 @@ main(int argc, char **argv) {
        char *classname = classname_in;
        const char *workdir = NULL;
 
-       while ((c = isc_commandline_parse(argc, argv, "c:dijn:qst:vw:")) != EOF) {
+       while ((c = isc_commandline_parse(argc, argv, "c:dijn:qst:o:vw:D")) != EOF) {
                switch (c) {
                case 'c':
                        classname = isc_commandline_argument;
@@ -128,6 +130,10 @@ main(int argc, char **argv) {
                        }
                        break;
 
+               case 'o':
+                       output_filename = isc_commandline_argument;
+                       break;
+
                case 'v':
                        printf(VERSION "\n");
                        exit(0);
@@ -136,6 +142,10 @@ main(int argc, char **argv) {
                        workdir = isc_commandline_argument;
                        break;
 
+               case 'D':
+                       dumpzone++;
+                       break;
+
                default:
                        usage();
                }
@@ -165,6 +175,11 @@ main(int argc, char **argv) {
        origin = argv[isc_commandline_index++];
        filename = argv[isc_commandline_index++];
        result = load_zone(mctx, origin, filename, classname, &zone);
+
+       if (result == ISC_R_SUCCESS && dumpzone) {
+               result = dump_zone(origin, zone, output_filename);
+       }
+
        if (!quiet && result == ISC_R_SUCCESS)
                fprintf(stdout, "OK\n");
        destroy();
index 47356c9312948c6171d616a36a12b91cbac98363..a40c99ea2e2cf313c621d5579a044e001f8e560e 100644 (file)
@@ -16,7 +16,7 @@
  - WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 -->
 
-<!-- $Id: named-checkzone.docbook,v 1.8 2002/07/19 02:34:58 marka Exp $ -->
+<!-- $Id: named-checkzone.docbook,v 1.9 2004/01/07 05:27:17 marka Exp $ -->
 
 <refentry>
   <refentryinfo>
       <arg><option>-v</option></arg>
       <arg><option>-c <replaceable class="parameter">class</replaceable></option></arg>
       <arg><option>-n <replaceable class="parameter">mode</replaceable></option></arg>
+      <arg><option>-o <replaceable class="parameter">filename</replaceable></option></arg>
       <arg><option>-t <replaceable class="parameter">directory</replaceable></option></arg>
       <arg><option>-w <replaceable class="parameter">directory</replaceable></option></arg>
+      <arg><option>-D</option></arg>
       <arg choice="req">zonename</arg>
       <arg choice="req">filename</arg>
     </cmdsynopsis>
        </listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term>-o <replaceable class="parameter">filename</replaceable></term>
+        <listitem>
+          <para>
+             Write zone output to <filename>directory</filename>.
+          </para>
+        </listitem>
+      </varlistentry>
+
       <varlistentry>
         <term>-t <replaceable class="parameter">directory</replaceable></term>
         <listitem>
         </listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term>-D</term>
+       <listitem>
+         <para>
+             Dump zone file in canonical format.
+         </para>
+       </listitem>
+      </varlistentry>
+
       <varlistentry>
         <term>zonename</term>
        <listitem>
index 17687afdb58e2d1b961dbd38bace0af930779660..00d9de031f1e1095b6ec2bb64c3894f97945c33b 100644 (file)
@@ -15,7 +15,7 @@
  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: masterdump.h,v 1.28 2002/05/21 06:12:45 marka Exp $ */
+/* $Id: masterdump.h,v 1.29 2004/01/07 05:27:17 marka Exp $ */
 
 #ifndef DNS_MASTERDUMP_H
 #define DNS_MASTERDUMP_H 1
@@ -110,6 +110,12 @@ ISC_LANG_BEGINDECLS
  */
 LIBDNS_EXTERNAL_DATA extern const dns_master_style_t dns_master_style_default;
 
+/*
+ * A master file style that dumps zones to a very generic format easily
+ * imported/checked with external tools.
+ */
+LIBDNS_EXTERNAL_DATA extern const dns_master_style_t dns_master_style_full;
+
 /*
  * A master file style that prints explicit TTL values on each 
  * record line, never using $TTL statements.  The TTL has a tab 
index f39aca3b8f64f68c282b0d594d423d9c795c7a6e..80d7fd952beab4cb6ab38b967cae1820017ae415 100644 (file)
@@ -15,7 +15,7 @@
  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: zone.h,v 1.123 2003/02/26 23:28:59 marka Exp $ */
+/* $Id: zone.h,v 1.124 2004/01/07 05:27:17 marka Exp $ */
 
 #ifndef DNS_ZONE_H
 #define DNS_ZONE_H 1
@@ -390,6 +390,17 @@ dns_zone_dumptostream(dns_zone_t *zone, FILE *fd);
  *     'fd' to be a stream open for writing.
  */
 
+isc_result_t
+dns_zone_fulldumptostream(dns_zone_t *zone, FILE *fd);
+/*
+ *     The same as dns_zone_dumptostream, but dumps the zone with
+ *     different dump settings (dns_master_style_full).
+ *
+ * Require:
+ *     'zone' to be a valid zone.
+ *     'fd' to be a stream open for writing.
+ */
+
 void
 dns_zone_maintenance(dns_zone_t *zone);
 /*
index 5dfe19a008755432cf537410eefd4def31ca9c91..0a871bc8a1a514b54675fd4628e29395b639992a 100644 (file)
@@ -15,7 +15,7 @@
  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: masterdump.c,v 1.71 2003/10/26 21:33:47 marka Exp $ */
+/* $Id: masterdump.c,v 1.72 2004/01/07 05:27:17 marka Exp $ */
 
 #include <config.h>
 
@@ -100,6 +100,12 @@ dns_master_style_default = {
        24, 24, 24, 32, 80, 8
 };
 
+LIBDNS_EXTERNAL_DATA const dns_master_style_t
+dns_master_style_full = {
+       DNS_STYLEFLAG_COMMENT,
+       46, 46, 46, 64, 120, 8
+};
+
 LIBDNS_EXTERNAL_DATA const dns_master_style_t
 dns_master_style_explicitttl = {
        DNS_STYLEFLAG_OMIT_OWNER |
index 65ff103346bb7e801ef83db527277137d346d26c..ed8f613ae53239a915fe5ab6a857fa6b42a1a6a0 100644 (file)
@@ -15,7 +15,7 @@
  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: zone.c,v 1.403 2004/01/05 04:21:30 marka Exp $ */
+/* $Id: zone.c,v 1.404 2004/01/07 05:27:17 marka Exp $ */
 
 #include <config.h>
 
@@ -2465,8 +2465,8 @@ zone_dump(dns_zone_t *zone, isc_boolean_t compact) {
        return (result);
 }
 
-isc_result_t
-dns_zone_dumptostream(dns_zone_t *zone, FILE *fd) {
+static isc_result_t
+dumptostream(dns_zone_t *zone, FILE *fd, const dns_master_style_t *style) {
        isc_result_t result;
        dns_dbversion_t *version = NULL;
        dns_db_t *db = NULL;
@@ -2481,13 +2481,22 @@ dns_zone_dumptostream(dns_zone_t *zone, FILE *fd) {
                return (DNS_R_NOTLOADED);
 
        dns_db_currentversion(db, &version);
-       result = dns_master_dumptostream(zone->mctx, db, version,
-                                        &dns_master_style_default, fd);
+       result = dns_master_dumptostream(zone->mctx, db, version, style, fd);
        dns_db_closeversion(db, &version, ISC_FALSE);
        dns_db_detach(&db);
        return (result);
 }
 
+isc_result_t
+dns_zone_dumptostream(dns_zone_t *zone, FILE *fd) {
+       return dumptostream(zone, fd, &dns_master_style_default);
+}
+
+isc_result_t
+dns_zone_fulldumptostream(dns_zone_t *zone, FILE *fd) {
+       return dumptostream(zone, fd, &dns_master_style_full);
+}
+
 void
 dns_zone_unload(dns_zone_t *zone) {
        REQUIRE(DNS_ZONE_VALID(zone));