summaryrefslogtreecommitdiff
path: root/usr.sbin/bind/bin/check/named-checkzone.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/bind/bin/check/named-checkzone.c')
-rw-r--r--usr.sbin/bind/bin/check/named-checkzone.c150
1 files changed, 86 insertions, 64 deletions
diff --git a/usr.sbin/bind/bin/check/named-checkzone.c b/usr.sbin/bind/bin/check/named-checkzone.c
index 2d8f7435714..45cf34ce416 100644
--- a/usr.sbin/bind/bin/check/named-checkzone.c
+++ b/usr.sbin/bind/bin/check/named-checkzone.c
@@ -1,21 +1,21 @@
/*
- * Copyright (C) 1999-2002 Internet Software Consortium.
+ * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (C) 1999-2003 Internet Software Consortium.
*
* Permission to use, copy, modify, and 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 INTERNET SOFTWARE CONSORTIUM
- * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
- * INTERNET SOFTWARE CONSORTIUM 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.
+ * 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.
*/
-/* $ISC: named-checkzone.c,v 1.13.2.3 2002/07/11 05:44:10 marka Exp $ */
+/* $ISC: named-checkzone.c,v 1.13.2.3.8.9 2004/03/06 10:21:11 marka Exp $ */
#include <config.h>
@@ -23,6 +23,7 @@
#include <isc/app.h>
#include <isc/commandline.h>
+#include <isc/dir.h>
#include <isc/log.h>
#include <isc/mem.h>
#include <isc/socket.h>
@@ -41,13 +42,12 @@
#include "check-tool.h"
-static int debug = 0;
-isc_boolean_t nomerge = ISC_TRUE;
static int quiet = 0;
static isc_mem_t *mctx = NULL;
dns_zone_t *zone = NULL;
dns_zonetype_t zonetype = dns_zone_master;
-static const char *dbtype[] = { "rbt" };
+static int dumpzone = 0;
+static const char *output_filename;
#define ERRRET(result, function) \
do { \
@@ -62,58 +62,11 @@ static const char *dbtype[] = { "rbt" };
static void
usage(void) {
fprintf(stderr,
- "usage: named-checkzone [-djqv] [-c class] zonename filename \n");
+ "usage: named-checkzone [-djqvD] [-c class] [-o output] "
+ "[-t directory] [-w directory] [-k option] zonename filename\n");
exit(1);
}
-static isc_result_t
-setup(char *zonename, char *filename, char *classname) {
- isc_result_t result;
- dns_rdataclass_t rdclass;
- isc_textregion_t region;
- isc_buffer_t buffer;
- dns_fixedname_t fixorigin;
- dns_name_t *origin;
-
- if (debug)
- fprintf(stderr, "loading \"%s\" from \"%s\" class \"%s\"\n",
- zonename, filename, classname);
- result = dns_zone_create(&zone, mctx);
- ERRRET(result, "dns_zone_new");
-
- dns_zone_settype(zone, zonetype);
-
- isc_buffer_init(&buffer, zonename, strlen(zonename));
- isc_buffer_add(&buffer, strlen(zonename));
- dns_fixedname_init(&fixorigin);
- result = dns_name_fromtext(dns_fixedname_name(&fixorigin),
- &buffer, dns_rootname, ISC_FALSE, NULL);
- ERRRET(result, "dns_name_fromtext");
- origin = dns_fixedname_name(&fixorigin);
-
- result = dns_zone_setorigin(zone, origin);
- ERRRET(result, "dns_zone_setorigin");
-
- result = dns_zone_setdbtype(zone, 1, (const char * const *) dbtype);
- ERRRET(result, "dns_zone_setdatabase");
-
- result = dns_zone_setfile(zone, filename);
- ERRRET(result, "dns_zone_setdatabase");
-
- region.base = classname;
- region.length = strlen(classname);
- result = dns_rdataclass_fromtext(&rdclass, &region);
- ERRRET(result, "dns_rdataclass_fromtext");
-
- dns_zone_setclass(zone, rdclass);
- dns_zone_setoption(zone, DNS_ZONEOPT_MANYERRORS, ISC_TRUE);
- dns_zone_setoption(zone, DNS_ZONEOPT_NOMERGE, nomerge);
-
- result = dns_zone_load(zone);
-
- return (result);
-}
-
static void
destroy(void) {
if (zone != NULL)
@@ -129,12 +82,14 @@ main(int argc, char **argv) {
isc_result_t result;
char classname_in[] = "IN";
char *classname = classname_in;
+ const char *workdir = NULL;
- while ((c = isc_commandline_parse(argc, argv, "c:djqsv")) != EOF) {
+ while ((c = isc_commandline_parse(argc, argv, "c:dijk:n:qst:o:vw:D")) != EOF) {
switch (c) {
case 'c':
classname = isc_commandline_argument;
break;
+
case 'd':
debug++;
break;
@@ -142,17 +97,79 @@ main(int argc, char **argv) {
case 'j':
nomerge = ISC_FALSE;
break;
+
+ case 'n':
+ if (!strcmp(isc_commandline_argument, "ignore"))
+ zone_options &= ~(DNS_ZONEOPT_CHECKNS|
+ DNS_ZONEOPT_FATALNS);
+ else if (!strcmp(isc_commandline_argument, "warn")) {
+ zone_options |= DNS_ZONEOPT_CHECKNS;
+ zone_options &= ~DNS_ZONEOPT_FATALNS;
+ } else if (!strcmp(isc_commandline_argument, "fail"))
+ zone_options |= DNS_ZONEOPT_CHECKNS|
+ DNS_ZONEOPT_FATALNS;
+ break;
+
+ case 'k':
+ if (!strcmp(isc_commandline_argument, "check-names")) {
+ zone_options |= DNS_ZONEOPT_CHECKNAMES;
+ } else if (!strcmp(isc_commandline_argument,
+ "check-names-fail")) {
+ zone_options |= DNS_ZONEOPT_CHECKNAMES |
+ DNS_ZONEOPT_CHECKNAMESFAIL;
+ }
+ break;
+
case 'q':
quiet++;
break;
+
+ case 't':
+ result = isc_dir_chroot(isc_commandline_argument);
+ if (result != ISC_R_SUCCESS) {
+ fprintf(stderr, "isc_dir_chroot: %s: %s\n",
+ isc_commandline_argument,
+ isc_result_totext(result));
+ exit(1);
+ }
+ result = isc_dir_chdir("/");
+ if (result != ISC_R_SUCCESS) {
+ fprintf(stderr, "isc_dir_chdir: %s\n",
+ isc_result_totext(result));
+ exit(1);
+ }
+ break;
+
+ case 'o':
+ output_filename = isc_commandline_argument;
+ break;
+
case 'v':
printf(VERSION "\n");
exit(0);
+
+ case 'w':
+ workdir = isc_commandline_argument;
+ break;
+
+ case 'D':
+ dumpzone++;
+ break;
+
default:
usage();
}
}
+ if (workdir != NULL) {
+ result = isc_dir_chdir(workdir);
+ if (result != ISC_R_SUCCESS) {
+ fprintf(stderr, "isc_dir_chdir: %s: %s\n",
+ workdir, isc_result_totext(result));
+ exit(1);
+ }
+ }
+
if (isc_commandline_index + 2 > argc)
usage();
@@ -167,7 +184,12 @@ main(int argc, char **argv) {
origin = argv[isc_commandline_index++];
filename = argv[isc_commandline_index++];
- result = setup(origin, filename, classname);
+ 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();