named-checkzone.c revision e9359db5e958bf05f9b9c5fe3c27d533f0f05550
e20788e1216ed720aefa84f3295f7899d9f28c22Mark Andrews/*
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * Copyright (C) 1999-2002 Internet Software Consortium.
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews *
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * Permission to use, copy, modify, and distribute this software for any
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * purpose with or without fee is hereby granted, provided that the above
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * copyright notice and this permission notice appear in all copies.
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews *
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
12178c86525332bb0ab66155feb61fbf32eca6acEvan Hunt */
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence/* $Id: named-checkzone.c,v 1.22 2002/07/11 04:49:26 marka Exp $ */
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence#include <config.h>
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
e13d04fda918c0c14c2247475bb99e0760d9a6a4Evan Hunt#include <stdlib.h>
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
c2bc56dc65b4b103a5600565680eb5f33fa4c90bMark Andrews#include <isc/app.h>
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence#include <isc/commandline.h>
dfe3edd7cd2cf9d22abfc8985bc25551583b3d46Andreas Gustafsson#include <isc/dir.h>
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt#include <isc/log.h>
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence#include <isc/mem.h>
12178c86525332bb0ab66155feb61fbf32eca6acEvan Hunt#include <isc/socket.h>
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence#include <isc/string.h>
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence#include <isc/task.h>
8f66dad9393ae0724f758c4a51e06ff55c2d1219Brian Wellington#include <isc/timer.h>
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington#include <isc/util.h>
08a768e82ad64ede97f640c88e02984b59122753Michael Graff
a27fe4c990f96bd792f2a07ca4d38c78d5b9df2cTatuya JINMEI 神明達哉#include <dns/db.h>
0e40083fdd5445703bd30e46e5bfe7d047bced12Brian Wellington#include <dns/fixedname.h>
b493dfe8bce94b05efc0f161238d32f1234c5670Brian Wellington#include <dns/log.h>
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence#include <dns/rdataclass.h>
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington#include <dns/rdataset.h>
1d92d8a2456b23842a649b6104c60a9d6ea25333Brian Wellington#include <dns/result.h>
08a768e82ad64ede97f640c88e02984b59122753Michael Graff#include <dns/zone.h>
4cd765650776027d05fe7fca248478918e02e63bDavid Lawrence
b493dfe8bce94b05efc0f161238d32f1234c5670Brian Wellington#include "check-tool.h"
08a768e82ad64ede97f640c88e02984b59122753Michael Graff
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Huntstatic int quiet = 0;
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Huntstatic isc_mem_t *mctx = NULL;
a27fe4c990f96bd792f2a07ca4d38c78d5b9df2cTatuya JINMEI 神明達哉dns_zone_t *zone = NULL;
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Huntdns_zonetype_t zonetype = dns_zone_master;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence
09f3e7461fd22076c01999b40435648de8c9da73Brian Wellington#define ERRRET(result, function) \
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence do { \
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt if (result != ISC_R_SUCCESS) { \
19aca386f1c75dd3f982e917cdaedb40ccafafc9Mark Andrews if (!quiet) \
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt fprintf(stderr, "%s() returned %s\n", \
326bcfa0e2a6b924cb829a0bcc3bf9590ce21ad6Mark Andrews function, dns_result_totext(result)); \
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt return (result); \
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence } \
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt } while (0)
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halleystatic void
01b8865b1462ba219c90cf6c00f1bf0fdf780d9bBrian Wellingtonusage(void) {
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence fprintf(stderr,
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence "usage: named-checkzone [-dqv] [-c class] zonename filename\n");
42833075debe1b1d4c4d39e94cb8f66e3fba2a0fBrian Wellington exit(1);
74cb99072c4b0ebd2ccafcfa284288fa760f7a1aMark Andrews}
4cd765650776027d05fe7fca248478918e02e63bDavid Lawrence
5da31b1ebedaedf1aa83d7ef853e1db843027f61Andreas Gustafssonstatic void
326bcfa0e2a6b924cb829a0bcc3bf9590ce21ad6Mark Andrewsdestroy(void) {
1ecd9d30a037218f01f8e15817d00ee431be0160Andreas Gustafsson if (zone != NULL)
87983da955bf63128de85d180359bdc418516c3cDavid Lawrence dns_zone_detach(&zone);
f4cbe536b11da614fe05aeaeff41e324854cda7bMark Andrews}
a27fe4c990f96bd792f2a07ca4d38c78d5b9df2cTatuya JINMEI 神明達哉
a27fe4c990f96bd792f2a07ca4d38c78d5b9df2cTatuya JINMEI 神明達哉int
a27fe4c990f96bd792f2a07ca4d38c78d5b9df2cTatuya JINMEI 神明達哉main(int argc, char **argv) {
4cd765650776027d05fe7fca248478918e02e63bDavid Lawrence int c;
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley char *origin = NULL;
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley char *filename = NULL;
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley isc_log_t *lctx = NULL;
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley isc_result_t result;
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley char classname_in[] = "IN";
c229b778b82c40f2186bfd6afcad2ee34c657216David Lawrence char *classname = classname_in;
922e6a3c2ac4ef900dd9dc99f0cc137f18372583Andreas Gustafsson const char *workdir = NULL;
01b8865b1462ba219c90cf6c00f1bf0fdf780d9bBrian Wellington
01b8865b1462ba219c90cf6c00f1bf0fdf780d9bBrian Wellington while ((c = isc_commandline_parse(argc, argv, "c:dijqst:vw:")) != EOF) {
c229b778b82c40f2186bfd6afcad2ee34c657216David Lawrence switch (c) {
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt case 'c':
74cb99072c4b0ebd2ccafcfa284288fa760f7a1aMark Andrews classname = isc_commandline_argument;
53aba5065d2ee3c103912ecfe865418bad6fa576Brian Wellington break;
53aba5065d2ee3c103912ecfe865418bad6fa576Brian Wellington
c229b778b82c40f2186bfd6afcad2ee34c657216David Lawrence case 'd':
4610465ed9408cbe434dbfb8be8ea53f48969c91Bob Halley debug++;
20bd7b4bbf2437ef2f9109edca168ab0ce8445b3David Lawrence break;
case 'j':
nomerge = ISC_FALSE;
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);
}
dns_result_register();
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);
}