From d0aebc5a55b6145297d94f8aee939852357c59fc Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Wed, 7 Jan 2004 05:27:17 +0000 Subject: [PATCH] 1549. [func] named-checkzone can now write out the zone contents in a easily parsable format (-D and -o). --- CHANGES | 3 +++ bin/check/check-tool.c | 35 ++++++++++++++++++++++++++++++- bin/check/check-tool.h | 5 ++++- bin/check/named-checkzone.c | 23 ++++++++++++++++---- bin/check/named-checkzone.docbook | 22 ++++++++++++++++++- lib/dns/include/dns/masterdump.h | 8 ++++++- lib/dns/include/dns/zone.h | 13 +++++++++++- lib/dns/masterdump.c | 8 ++++++- lib/dns/zone.c | 19 ++++++++++++----- 9 files changed, 121 insertions(+), 15 deletions(-) diff --git a/CHANGES b/CHANGES index 83c9ca2e6c..aec5db0252 100644 --- 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] diff --git a/bin/check/check-tool.c b/bin/check/check-tool.c index c9bebd0ccf..448887f5de 100644 --- a/bin/check/check-tool.c +++ b/bin/check/check-tool.c @@ -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 @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -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); +} diff --git a/bin/check/check-tool.h b/bin/check/check-tool.h index 85b05bab1b..37728e5705 100644 --- a/bin/check/check-tool.h +++ b/bin/check/check-tool.h @@ -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; diff --git a/bin/check/named-checkzone.c b/bin/check/named-checkzone.c index 799892753e..692a9a6846 100644 --- a/bin/check/named-checkzone.c +++ b/bin/check/named-checkzone.c @@ -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 @@ -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(); diff --git a/bin/check/named-checkzone.docbook b/bin/check/named-checkzone.docbook index 47356c9312..a40c99ea2e 100644 --- a/bin/check/named-checkzone.docbook +++ b/bin/check/named-checkzone.docbook @@ -16,7 +16,7 @@ - WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --> - + @@ -43,8 +43,10 @@ + + zonename filename @@ -122,6 +124,15 @@ + + -o filename + + + Write zone output to directory. + + + + -t directory @@ -145,6 +156,15 @@ + + -D + + + Dump zone file in canonical format. + + + + zonename diff --git a/lib/dns/include/dns/masterdump.h b/lib/dns/include/dns/masterdump.h index 17687afdb5..00d9de031f 100644 --- a/lib/dns/include/dns/masterdump.h +++ b/lib/dns/include/dns/masterdump.h @@ -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 diff --git a/lib/dns/include/dns/zone.h b/lib/dns/include/dns/zone.h index f39aca3b8f..80d7fd952b 100644 --- a/lib/dns/include/dns/zone.h +++ b/lib/dns/include/dns/zone.h @@ -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); /* diff --git a/lib/dns/masterdump.c b/lib/dns/masterdump.c index 5dfe19a008..0a871bc8a1 100644 --- a/lib/dns/masterdump.c +++ b/lib/dns/masterdump.c @@ -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 @@ -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 | diff --git a/lib/dns/zone.c b/lib/dns/zone.c index 65ff103346..ed8f613ae5 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -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 @@ -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));