2000-12-13 06:05:42 +00:00
|
|
|
/*
|
2002-02-20 03:35:59 +00:00
|
|
|
* Copyright (C) 1999-2002 Internet Software Consortium.
|
2000-12-13 06:05:42 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2002-10-25 01:02:53 +00:00
|
|
|
/* $Id: named-checkzone.c,v 1.25 2002/10/25 01:02:53 marka Exp $ */
|
2000-12-13 06:05:42 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <isc/app.h>
|
|
|
|
#include <isc/commandline.h>
|
2001-09-15 02:05:35 +00:00
|
|
|
#include <isc/dir.h>
|
2000-12-13 06:05:42 +00:00
|
|
|
#include <isc/log.h>
|
|
|
|
#include <isc/mem.h>
|
|
|
|
#include <isc/socket.h>
|
|
|
|
#include <isc/string.h>
|
|
|
|
#include <isc/task.h>
|
|
|
|
#include <isc/timer.h>
|
|
|
|
#include <isc/util.h>
|
|
|
|
|
|
|
|
#include <dns/db.h>
|
|
|
|
#include <dns/fixedname.h>
|
|
|
|
#include <dns/log.h>
|
|
|
|
#include <dns/rdataclass.h>
|
|
|
|
#include <dns/rdataset.h>
|
|
|
|
#include <dns/result.h>
|
|
|
|
#include <dns/zone.h>
|
|
|
|
|
2000-12-14 21:33:34 +00:00
|
|
|
#include "check-tool.h"
|
|
|
|
|
2000-12-13 06:05:42 +00:00
|
|
|
static int quiet = 0;
|
|
|
|
static isc_mem_t *mctx = NULL;
|
|
|
|
dns_zone_t *zone = NULL;
|
|
|
|
dns_zonetype_t zonetype = dns_zone_master;
|
|
|
|
|
|
|
|
#define ERRRET(result, function) \
|
|
|
|
do { \
|
|
|
|
if (result != ISC_R_SUCCESS) { \
|
2000-12-14 01:03:48 +00:00
|
|
|
if (!quiet) \
|
|
|
|
fprintf(stderr, "%s() returned %s\n", \
|
|
|
|
function, dns_result_totext(result)); \
|
2000-12-13 06:05:42 +00:00
|
|
|
return (result); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
static void
|
2000-12-21 01:54:30 +00:00
|
|
|
usage(void) {
|
2000-12-13 06:05:42 +00:00
|
|
|
fprintf(stderr,
|
2002-10-25 01:02:53 +00:00
|
|
|
"usage: named-checkzone [-djqv] [-c class] [-t directory] "
|
|
|
|
"[-w directory] zonename filename\n");
|
2000-12-13 06:05:42 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy(void) {
|
2000-12-14 01:03:48 +00:00
|
|
|
if (zone != NULL)
|
|
|
|
dns_zone_detach(&zone);
|
2000-12-13 06:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv) {
|
|
|
|
int c;
|
2000-12-14 01:03:48 +00:00
|
|
|
char *origin = NULL;
|
2000-12-13 06:05:42 +00:00
|
|
|
char *filename = NULL;
|
|
|
|
isc_log_t *lctx = NULL;
|
|
|
|
isc_result_t result;
|
2000-12-19 19:54:29 +00:00
|
|
|
char classname_in[] = "IN";
|
2001-01-24 00:56:56 +00:00
|
|
|
char *classname = classname_in;
|
2001-09-15 02:05:35 +00:00
|
|
|
const char *workdir = NULL;
|
2000-12-13 06:05:42 +00:00
|
|
|
|
2002-07-19 02:34:58 +00:00
|
|
|
while ((c = isc_commandline_parse(argc, argv, "c:dijn:qst:vw:")) != EOF) {
|
2000-12-13 06:05:42 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'c':
|
|
|
|
classname = isc_commandline_argument;
|
|
|
|
break;
|
2001-09-15 02:05:35 +00:00
|
|
|
|
2000-12-13 06:05:42 +00:00
|
|
|
case 'd':
|
|
|
|
debug++;
|
|
|
|
break;
|
2001-09-15 02:05:35 +00:00
|
|
|
|
2002-07-11 04:49:27 +00:00
|
|
|
case 'j':
|
2002-04-02 06:54:07 +00:00
|
|
|
nomerge = ISC_FALSE;
|
|
|
|
break;
|
|
|
|
|
2002-07-19 02:34:58 +00:00
|
|
|
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;
|
|
|
|
|
2000-12-13 06:05:42 +00:00
|
|
|
case 'q':
|
|
|
|
quiet++;
|
|
|
|
break;
|
2001-09-15 02:05:35 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2001-06-29 01:05:11 +00:00
|
|
|
case 'v':
|
|
|
|
printf(VERSION "\n");
|
|
|
|
exit(0);
|
2001-09-15 02:05:35 +00:00
|
|
|
|
|
|
|
case 'w':
|
|
|
|
workdir = isc_commandline_argument;
|
|
|
|
break;
|
|
|
|
|
2000-12-13 06:05:42 +00:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-15 02:05:35 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-24 00:56:56 +00:00
|
|
|
if (isc_commandline_index + 2 > argc)
|
2000-12-13 06:05:42 +00:00
|
|
|
usage();
|
|
|
|
|
|
|
|
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
|
2001-03-03 23:11:36 +00:00
|
|
|
if (!quiet) {
|
2000-12-14 21:33:34 +00:00
|
|
|
RUNTIME_CHECK(setup_logging(mctx, &lctx) == ISC_R_SUCCESS);
|
2001-03-03 23:11:36 +00:00
|
|
|
dns_log_init(lctx);
|
|
|
|
dns_log_setcontext(lctx);
|
|
|
|
}
|
2000-12-13 06:05:42 +00:00
|
|
|
|
2002-01-14 01:42:04 +00:00
|
|
|
dns_result_register();
|
|
|
|
|
2001-01-24 00:56:56 +00:00
|
|
|
origin = argv[isc_commandline_index++];
|
|
|
|
filename = argv[isc_commandline_index++];
|
2001-09-03 08:21:46 +00:00
|
|
|
result = load_zone(mctx, origin, filename, classname, &zone);
|
2000-12-13 06:05:42 +00:00
|
|
|
if (!quiet && result == ISC_R_SUCCESS)
|
2000-12-21 22:11:03 +00:00
|
|
|
fprintf(stdout, "OK\n");
|
2000-12-13 06:05:42 +00:00
|
|
|
destroy();
|
2000-12-14 01:03:48 +00:00
|
|
|
if (lctx != NULL)
|
|
|
|
isc_log_destroy(&lctx);
|
2000-12-13 06:05:42 +00:00
|
|
|
isc_mem_destroy(&mctx);
|
2000-12-14 01:03:48 +00:00
|
|
|
return ((result == ISC_R_SUCCESS) ? 0 : 1);
|
2000-12-13 06:05:42 +00:00
|
|
|
}
|