named-checkzone.c 2.9 KB
Newer Older
Mark Andrews's avatar
Mark Andrews committed
1
/*
Brian Wellington's avatar
Brian Wellington committed
2
 * Copyright (C) 1999-2001  Internet Software Consortium.
Mark Andrews's avatar
Mark Andrews committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 *
 * 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.
 */

18
/* $Id: named-checkzone.c,v 1.14 2001/09/03 08:21:44 marka Exp $ */
Mark Andrews's avatar
Mark Andrews committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

#include <config.h>

#include <stdlib.h>

#include <isc/app.h>
#include <isc/commandline.h>
#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>

Mark Andrews's avatar
cleanup    
Mark Andrews committed
42
43
#include "check-tool.h"

Mark Andrews's avatar
Mark Andrews committed
44
45
46
47
48
49
50
51
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) { \
Mark Andrews's avatar
Mark Andrews committed
52
53
54
			if (!quiet) \
				fprintf(stderr, "%s() returned %s\n", \
					function, dns_result_totext(result)); \
Mark Andrews's avatar
Mark Andrews committed
55
56
57
58
59
			return (result); \
		} \
	} while (0)

static void
Brian Wellington's avatar
Brian Wellington committed
60
usage(void) {
Mark Andrews's avatar
Mark Andrews committed
61
	fprintf(stderr,
62
		"usage: named-checkzone [-dqv] [-c class] zonename filename \n");
Mark Andrews's avatar
Mark Andrews committed
63
64
65
66
67
	exit(1);
}

static void
destroy(void) {
Mark Andrews's avatar
Mark Andrews committed
68
69
	if (zone != NULL)
		dns_zone_detach(&zone);
Mark Andrews's avatar
Mark Andrews committed
70
71
72
73
74
}

int
main(int argc, char **argv) {
	int c;
Mark Andrews's avatar
Mark Andrews committed
75
	char *origin = NULL;
Mark Andrews's avatar
Mark Andrews committed
76
77
78
	char *filename = NULL;
	isc_log_t *lctx = NULL;
	isc_result_t result;
79
	char classname_in[] = "IN";
80
	char *classname = classname_in;
Mark Andrews's avatar
Mark Andrews committed
81

82
	while ((c = isc_commandline_parse(argc, argv, "c:dqsv")) != EOF) {
Mark Andrews's avatar
Mark Andrews committed
83
84
85
86
87
88
89
90
91
92
		switch (c) {
		case 'c':
			classname = isc_commandline_argument;
			break;
		case 'd':
			debug++;
			break;
		case 'q':
			quiet++;
			break;
93
94
95
		case 'v':
			printf(VERSION "\n");
			exit(0);
Mark Andrews's avatar
Mark Andrews committed
96
97
98
99
100
		default:
			usage();
		}
	}

101
	if (isc_commandline_index + 2 > argc)
Mark Andrews's avatar
Mark Andrews committed
102
103
104
		usage();

	RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
105
	if (!quiet) {
Mark Andrews's avatar
cleanup    
Mark Andrews committed
106
		RUNTIME_CHECK(setup_logging(mctx, &lctx) == ISC_R_SUCCESS);
107
108
109
		dns_log_init(lctx);
		dns_log_setcontext(lctx);
	}
Mark Andrews's avatar
Mark Andrews committed
110

111
112
	origin = argv[isc_commandline_index++];
	filename = argv[isc_commandline_index++];
113
	result = load_zone(mctx, origin, filename, classname, &zone);
Mark Andrews's avatar
Mark Andrews committed
114
	if (!quiet && result == ISC_R_SUCCESS)
115
		fprintf(stdout, "OK\n");
Mark Andrews's avatar
Mark Andrews committed
116
	destroy();
Mark Andrews's avatar
Mark Andrews committed
117
118
	if (lctx != NULL)
		isc_log_destroy(&lctx);
Mark Andrews's avatar
Mark Andrews committed
119
	isc_mem_destroy(&mctx);
Mark Andrews's avatar
Mark Andrews committed
120
	return ((result == ISC_R_SUCCESS) ? 0 : 1);
Mark Andrews's avatar
Mark Andrews committed
121
}