2000-12-14 21:33:11 +00:00
|
|
|
/*
|
2005-01-10 23:43:27 +00:00
|
|
|
* Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
|
2004-03-05 05:14:21 +00:00
|
|
|
* Copyright (C) 2000-2002 Internet Software Consortium.
|
2000-12-14 21:33:11 +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.
|
|
|
|
*
|
2004-03-05 05:14:21 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
|
|
|
|
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
* AND FITNESS. IN NO EVENT SHALL ISC 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.
|
2000-12-14 21:33:11 +00:00
|
|
|
*/
|
|
|
|
|
2005-01-10 23:43:27 +00:00
|
|
|
/* $Id: check-tool.c,v 1.15 2005/01/10 23:43:12 marka Exp $ */
|
2000-12-23 22:02:49 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
2000-12-14 21:33:11 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2001-09-05 21:09:31 +00:00
|
|
|
#include <string.h>
|
2000-12-14 21:33:11 +00:00
|
|
|
|
|
|
|
#include "check-tool.h"
|
|
|
|
#include <isc/util.h>
|
|
|
|
|
2001-09-03 08:21:46 +00:00
|
|
|
#include <isc/buffer.h>
|
2000-12-14 21:33:11 +00:00
|
|
|
#include <isc/log.h>
|
2001-09-03 08:21:46 +00:00
|
|
|
#include <isc/region.h>
|
2004-01-07 05:27:17 +00:00
|
|
|
#include <isc/stdio.h>
|
2000-12-14 21:33:11 +00:00
|
|
|
#include <isc/types.h>
|
|
|
|
|
2001-09-03 08:21:46 +00:00
|
|
|
#include <dns/fixedname.h>
|
2004-11-30 01:12:52 +00:00
|
|
|
#include <dns/log.h>
|
2001-09-03 08:21:46 +00:00
|
|
|
#include <dns/name.h>
|
|
|
|
#include <dns/rdataclass.h>
|
|
|
|
#include <dns/types.h>
|
|
|
|
#include <dns/zone.h>
|
|
|
|
|
|
|
|
#define CHECK(r) \
|
|
|
|
do { \
|
|
|
|
result = (r); \
|
|
|
|
if (result != ISC_R_SUCCESS) \
|
|
|
|
goto cleanup; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
static const char *dbtype[] = { "rbt" };
|
|
|
|
|
|
|
|
int debug = 0;
|
2002-04-02 06:54:07 +00:00
|
|
|
isc_boolean_t nomerge = ISC_TRUE;
|
2004-10-06 05:56:29 +00:00
|
|
|
unsigned int zone_options = DNS_ZONEOPT_CHECKNS |
|
|
|
|
DNS_ZONEOPT_MANYERRORS |
|
2005-01-09 23:40:04 +00:00
|
|
|
DNS_ZONEOPT_CHECKNAMES |
|
|
|
|
DNS_ZONEOPT_CHECKWILDCARD;
|
2001-09-03 08:21:46 +00:00
|
|
|
|
2004-11-09 21:24:20 +00:00
|
|
|
/*
|
|
|
|
* This needs to match the list in bin/named/log.c.
|
|
|
|
*/
|
|
|
|
static isc_logcategory_t categories[] = {
|
|
|
|
{ "", 0 },
|
|
|
|
{ "client", 0 },
|
|
|
|
{ "network", 0 },
|
|
|
|
{ "update", 0 },
|
|
|
|
{ "queries", 0 },
|
|
|
|
{ "unmatched", 0 },
|
|
|
|
{ "update-security", 0 },
|
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
|
2000-12-14 21:33:11 +00:00
|
|
|
isc_result_t
|
|
|
|
setup_logging(isc_mem_t *mctx, isc_log_t **logp) {
|
|
|
|
isc_logdestination_t destination;
|
|
|
|
isc_logconfig_t *logconfig = NULL;
|
|
|
|
isc_log_t *log = NULL;
|
|
|
|
|
|
|
|
RUNTIME_CHECK(isc_log_create(mctx, &log, &logconfig) == ISC_R_SUCCESS);
|
2004-11-09 21:24:20 +00:00
|
|
|
isc_log_registercategories(log, categories);
|
2000-12-14 21:33:11 +00:00
|
|
|
isc_log_setcontext(log);
|
2004-11-09 21:24:20 +00:00
|
|
|
dns_log_init(log);
|
2000-12-14 21:33:11 +00:00
|
|
|
|
|
|
|
destination.file.stream = stdout;
|
|
|
|
destination.file.name = NULL;
|
|
|
|
destination.file.versions = ISC_LOG_ROLLNEVER;
|
|
|
|
destination.file.maximum_size = 0;
|
|
|
|
RUNTIME_CHECK(isc_log_createchannel(logconfig, "stderr",
|
|
|
|
ISC_LOG_TOFILEDESC,
|
|
|
|
ISC_LOG_DYNAMIC,
|
|
|
|
&destination, 0) == ISC_R_SUCCESS);
|
|
|
|
RUNTIME_CHECK(isc_log_usechannel(logconfig, "stderr",
|
|
|
|
NULL, NULL) == ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
*logp = log;
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
2001-09-03 08:21:46 +00:00
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
load_zone(isc_mem_t *mctx, const char *zonename, const char *filename,
|
|
|
|
const char *classname, dns_zone_t **zonep)
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
|
|
|
dns_rdataclass_t rdclass;
|
|
|
|
isc_textregion_t region;
|
|
|
|
isc_buffer_t buffer;
|
|
|
|
dns_fixedname_t fixorigin;
|
|
|
|
dns_name_t *origin;
|
|
|
|
dns_zone_t *zone = NULL;
|
|
|
|
|
|
|
|
REQUIRE(zonep == NULL || *zonep == NULL);
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
fprintf(stderr, "loading \"%s\" from \"%s\" class \"%s\"\n",
|
|
|
|
zonename, filename, classname);
|
|
|
|
|
|
|
|
CHECK(dns_zone_create(&zone, mctx));
|
|
|
|
|
|
|
|
dns_zone_settype(zone, dns_zone_master);
|
|
|
|
|
|
|
|
isc_buffer_init(&buffer, zonename, strlen(zonename));
|
|
|
|
isc_buffer_add(&buffer, strlen(zonename));
|
|
|
|
dns_fixedname_init(&fixorigin);
|
|
|
|
origin = dns_fixedname_name(&fixorigin);
|
|
|
|
CHECK(dns_name_fromtext(origin, &buffer, dns_rootname,
|
|
|
|
ISC_FALSE, NULL));
|
|
|
|
CHECK(dns_zone_setorigin(zone, origin));
|
|
|
|
CHECK(dns_zone_setdbtype(zone, 1, (const char * const *) dbtype));
|
|
|
|
CHECK(dns_zone_setfile(zone, filename));
|
|
|
|
|
|
|
|
DE_CONST(classname, region.base);
|
|
|
|
region.length = strlen(classname);
|
|
|
|
CHECK(dns_rdataclass_fromtext(&rdclass, ®ion));
|
|
|
|
|
|
|
|
dns_zone_setclass(zone, rdclass);
|
2002-07-19 02:34:58 +00:00
|
|
|
dns_zone_setoption(zone, zone_options, ISC_TRUE);
|
2002-04-02 06:54:07 +00:00
|
|
|
dns_zone_setoption(zone, DNS_ZONEOPT_NOMERGE, nomerge);
|
2001-09-03 08:21:46 +00:00
|
|
|
|
|
|
|
CHECK(dns_zone_load(zone));
|
|
|
|
if (zonep != NULL){
|
|
|
|
*zonep = zone;
|
|
|
|
zone = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (zone != NULL)
|
|
|
|
dns_zone_detach(&zone);
|
|
|
|
return (result);
|
|
|
|
}
|
2004-01-07 05:27:17 +00:00
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
dump_zone(const char *zonename, dns_zone_t *zone, const char *filename)
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
|
|
|
FILE *output = stdout;
|
|
|
|
|
|
|
|
if (debug) {
|
|
|
|
if (filename != NULL)
|
|
|
|
fprintf(stderr, "dumping \"%s\" to \"%s\"\n",
|
|
|
|
zonename, filename);
|
|
|
|
else
|
|
|
|
fprintf(stderr, "dumping \"%s\"\n", zonename);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filename != NULL) {
|
|
|
|
result = isc_stdio_open(filename, "w+", &output);
|
|
|
|
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fprintf(stderr, "could not open output "
|
|
|
|
"file \"%s\" for writing\n", filename);
|
|
|
|
return (ISC_R_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = dns_zone_fulldumptostream(zone, output);
|
|
|
|
|
|
|
|
if (filename != NULL)
|
|
|
|
(void)isc_stdio_close(output);
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|