2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2000-2002 Internet Software Consortium.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: check-tool.c,v 1.4.12.7 2004/11/30 01:15:40 marka Exp $ */
25 #include "check-tool.h"
28 #include <isc/buffer.h>
30 #include <isc/region.h>
31 #include <isc/stdio.h>
32 #include <isc/types.h>
34 #include <dns/fixedname.h>
37 #include <dns/rdataclass.h>
38 #include <dns/types.h>
44 if (result != ISC_R_SUCCESS) \
48 static const char *dbtype[] = { "rbt" };
51 isc_boolean_t nomerge = ISC_TRUE;
52 unsigned int zone_options = DNS_ZONEOPT_CHECKNS |
53 DNS_ZONEOPT_MANYERRORS |
54 DNS_ZONEOPT_CHECKNAMES;
57 setup_logging(isc_mem_t *mctx, isc_log_t **logp) {
58 isc_logdestination_t destination;
59 isc_logconfig_t *logconfig = NULL;
60 isc_log_t *log = NULL;
62 RUNTIME_CHECK(isc_log_create(mctx, &log, &logconfig) == ISC_R_SUCCESS);
63 isc_log_setcontext(log);
65 destination.file.stream = stdout;
66 destination.file.name = NULL;
67 destination.file.versions = ISC_LOG_ROLLNEVER;
68 destination.file.maximum_size = 0;
69 RUNTIME_CHECK(isc_log_createchannel(logconfig, "stderr",
72 &destination, 0) == ISC_R_SUCCESS);
73 RUNTIME_CHECK(isc_log_usechannel(logconfig, "stderr",
74 NULL, NULL) == ISC_R_SUCCESS);
77 return (ISC_R_SUCCESS);
81 load_zone(isc_mem_t *mctx, const char *zonename, const char *filename,
82 const char *classname, dns_zone_t **zonep)
85 dns_rdataclass_t rdclass;
86 isc_textregion_t region;
88 dns_fixedname_t fixorigin;
90 dns_zone_t *zone = NULL;
92 REQUIRE(zonep == NULL || *zonep == NULL);
95 fprintf(stderr, "loading \"%s\" from \"%s\" class \"%s\"\n",
96 zonename, filename, classname);
98 CHECK(dns_zone_create(&zone, mctx));
100 dns_zone_settype(zone, dns_zone_master);
102 isc_buffer_init(&buffer, zonename, strlen(zonename));
103 isc_buffer_add(&buffer, strlen(zonename));
104 dns_fixedname_init(&fixorigin);
105 origin = dns_fixedname_name(&fixorigin);
106 CHECK(dns_name_fromtext(origin, &buffer, dns_rootname,
108 CHECK(dns_zone_setorigin(zone, origin));
109 CHECK(dns_zone_setdbtype(zone, 1, (const char * const *) dbtype));
110 CHECK(dns_zone_setfile(zone, filename));
112 DE_CONST(classname, region.base);
113 region.length = strlen(classname);
114 CHECK(dns_rdataclass_fromtext(&rdclass, ®ion));
116 dns_zone_setclass(zone, rdclass);
117 dns_zone_setoption(zone, zone_options, ISC_TRUE);
118 dns_zone_setoption(zone, DNS_ZONEOPT_NOMERGE, nomerge);
120 CHECK(dns_zone_load(zone));
128 dns_zone_detach(&zone);
133 dump_zone(const char *zonename, dns_zone_t *zone, const char *filename)
136 FILE *output = stdout;
139 if (filename != NULL)
140 fprintf(stderr, "dumping \"%s\" to \"%s\"\n",
143 fprintf(stderr, "dumping \"%s\"\n", zonename);
146 if (filename != NULL) {
147 result = isc_stdio_open(filename, "w+", &output);
149 if (result != ISC_R_SUCCESS) {
150 fprintf(stderr, "could not open output "
151 "file \"%s\" for writing\n", filename);
152 return (ISC_R_FAILURE);
156 result = dns_zone_fulldumptostream(zone, output);
158 if (filename != NULL)
159 (void)isc_stdio_close(output);