named-checkzone.c revision e1fdebdcc80320b7f9afdde6e4f8b69fce11a167
e20788e1216ed720aefa84f3295f7899d9f28c22Mark Andrews/*
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Copyright (C) 1999-2001 Internet Software Consortium.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt *
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Permission to use, copy, modify, and distribute this software for any
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * purpose with or without fee is hereby granted, provided that the above
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * copyright notice and this permission notice appear in all copies.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt *
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt/* $Id: named-checkzone.c,v 1.16 2001/10/02 01:09:04 gson Exp $ */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt#include <config.h>
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt#include <stdlib.h>
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt#include <isc/app.h>
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt#include <isc/commandline.h>
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt#include <isc/dir.h>
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt#include <isc/log.h>
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt#include <isc/mem.h>
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt#include <isc/socket.h>
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt#include <isc/string.h>
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt#include <isc/task.h>
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt#include <isc/timer.h>
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt#include <isc/util.h>
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt#include <dns/db.h>
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt#include <dns/fixedname.h>
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt#include <dns/log.h>
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt#include <dns/rdataclass.h>
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt#include <dns/rdataset.h>
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt#include <dns/result.h>
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt#include <dns/zone.h>
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt#include "check-tool.h"
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Huntstatic int quiet = 0;
e2258edfef656bfaf21cbec4d8a86b71976c5983Francis Dupontstatic isc_mem_t *mctx = NULL;
e2258edfef656bfaf21cbec4d8a86b71976c5983Francis Dupontdns_zone_t *zone = NULL;
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Huntdns_zonetype_t zonetype = dns_zone_master;
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt
e2258edfef656bfaf21cbec4d8a86b71976c5983Francis Dupont#define ERRRET(result, function) \
e2258edfef656bfaf21cbec4d8a86b71976c5983Francis Dupont do { \
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt if (result != ISC_R_SUCCESS) { \
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt if (!quiet) \
e2258edfef656bfaf21cbec4d8a86b71976c5983Francis Dupont fprintf(stderr, "%s() returned %s\n", \
e2258edfef656bfaf21cbec4d8a86b71976c5983Francis Dupont function, dns_result_totext(result)); \
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt return (result); \
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt } \
e2258edfef656bfaf21cbec4d8a86b71976c5983Francis Dupont } while (0)
e2258edfef656bfaf21cbec4d8a86b71976c5983Francis Dupont
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Huntstatic void
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Huntusage(void) {
e2258edfef656bfaf21cbec4d8a86b71976c5983Francis Dupont fprintf(stderr,
e2258edfef656bfaf21cbec4d8a86b71976c5983Francis Dupont "usage: named-checkzone [-dqv] [-c class] zonename filename\n");
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt exit(1);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt}
e2258edfef656bfaf21cbec4d8a86b71976c5983Francis Dupont
e2258edfef656bfaf21cbec4d8a86b71976c5983Francis Dupontstatic void
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Huntdestroy(void) {
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt if (zone != NULL)
e2258edfef656bfaf21cbec4d8a86b71976c5983Francis Dupont dns_zone_detach(&zone);
e2258edfef656bfaf21cbec4d8a86b71976c5983Francis Dupont}
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Huntint
e2258edfef656bfaf21cbec4d8a86b71976c5983Francis Dupontmain(int argc, char **argv) {
e2258edfef656bfaf21cbec4d8a86b71976c5983Francis Dupont int c;
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt char *origin = NULL;
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt char *filename = NULL;
e2258edfef656bfaf21cbec4d8a86b71976c5983Francis Dupont isc_log_t *lctx = NULL;
e2258edfef656bfaf21cbec4d8a86b71976c5983Francis Dupont isc_result_t result;
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt char classname_in[] = "IN";
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt char *classname = classname_in;
e2258edfef656bfaf21cbec4d8a86b71976c5983Francis Dupont const char *workdir = NULL;
e2258edfef656bfaf21cbec4d8a86b71976c5983Francis Dupont
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt while ((c = isc_commandline_parse(argc, argv, "c:dqist:vw:")) != EOF) {
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt switch (c) {
e2258edfef656bfaf21cbec4d8a86b71976c5983Francis Dupont case 'c':
e2258edfef656bfaf21cbec4d8a86b71976c5983Francis Dupont classname = isc_commandline_argument;
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt break;
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt case 'd':
debug++;
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 'v':
printf(VERSION "\n");
exit(0);
case 'w':
workdir = isc_commandline_argument;
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();
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
if (!quiet) {
RUNTIME_CHECK(setup_logging(mctx, &lctx) == ISC_R_SUCCESS);
dns_log_init(lctx);
dns_log_setcontext(lctx);
}
origin = argv[isc_commandline_index++];
filename = argv[isc_commandline_index++];
result = load_zone(mctx, origin, filename, classname, &zone);
if (!quiet && result == ISC_R_SUCCESS)
fprintf(stdout, "OK\n");
destroy();
if (lctx != NULL)
isc_log_destroy(&lctx);
isc_mem_destroy(&mctx);
return ((result == ISC_R_SUCCESS) ? 0 : 1);
}