check-tool.c revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
/*
* Copyright (C) 2000-2002, 2004-2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* $Id: check-tool.c,v 1.44 2011/12/22 07:32:39 each Exp $ */
/*! \file */
#include <config.h>
#include <stdio.h>
#ifdef _WIN32
#include <Winsock2.h>
#endif
#include "check-tool.h"
#include <dns/dbiterator.h>
#include <dns/fixedname.h>
#include <dns/rdataclass.h>
#include <dns/rdataset.h>
#include <dns/rdatasetiter.h>
#include <dns/rdatatype.h>
#ifndef CHECK_SIBLING
#define CHECK_SIBLING 1
#endif
#ifndef CHECK_LOCAL
#define CHECK_LOCAL 1
#endif
#ifdef HAVE_ADDRINFO
#ifdef HAVE_GETADDRINFO
#ifdef HAVE_GAISTRERROR
#define USE_GETADDRINFO
#endif
#endif
#endif
#define CHECK(r) \
do { \
result = (r); \
if (result != ISC_R_SUCCESS) \
goto cleanup; \
} while (0)
#define ERR_IS_CNAME 1
#define ERR_NO_ADDRESSES 2
#define ERR_LOOKUP_FAILURE 3
#define ERR_EXTRA_A 4
#define ERR_EXTRA_AAAA 5
#define ERR_MISSING_GLUE 5
#define ERR_IS_MXCNAME 6
#define ERR_IS_SRVCNAME 7
static const char *dbtype[] = { "rbt" };
int debug = 0;
#if CHECK_LOCAL
#else
#endif
unsigned int zone_options = DNS_ZONEOPT_CHECKNS |
#if CHECK_SIBLING
#endif
unsigned int zone_options2 = 0;
/*
*/
static isc_logcategory_t categories[] = {
{ "", 0 },
{ "client", 0 },
{ "network", 0 },
{ "update", 0 },
{ "queries", 0 },
{ "unmatched", 0 },
{ "update-security", 0 },
{ "query-errors", 0 },
{ NULL, 0 }
};
static void
}
static void
if (result != ISC_R_SUCCESS)
return;
}
if (result != ISC_R_SUCCESS)
return;
}
return;
if (result != ISC_R_SUCCESS)
}
static isc_boolean_t
return (ISC_FALSE);
if (result == ISC_R_SUCCESS)
return (ISC_TRUE);
return (ISC_FALSE);
}
static isc_boolean_t
{
#ifdef USE_GETADDRINFO
char ownerbuf[DNS_NAME_FORMATSIZE];
char addrbuf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:123.123.123.123")];
const char *type;
int result;
a->type == dns_rdatatype_a);
return (answer);
/*
* Turn off search.
*/
switch (result) {
case 0:
/*
* Work around broken getaddrinfo() implementations that
* fail to set ai_canonname on first entry.
*/
"is a CNAME '%s' (illegal)",
cur->ai_canonname);
/* XXX950 make fatal for 9.5.0 */
/* answer = ISC_FALSE; */
}
break;
case EAI_NONAME:
case EAI_NODATA:
#endif
"has no addresses records (A or AAAA)",
}
/* XXX950 make fatal for 9.5.0 */
return (ISC_TRUE);
default:
"getaddrinfo(%s) failed: %s",
}
return (ISC_TRUE);
}
/*
* Check that all glue records really exist.
*/
if (!dns_rdataset_isassociated(a))
goto checkaaaa;
result = dns_rdataset_first(a);
while (result == ISC_R_SUCCESS) {
dns_rdataset_current(a, &rdata);
continue;
break;
}
}
"extra GLUE A record (%s)",
/* XXX950 make fatal for 9.5.0 */
/* answer = ISC_FALSE; */
}
result = dns_rdataset_next(a);
}
if (!dns_rdataset_isassociated(aaaa))
goto checkmissing;
while (result == ISC_R_SUCCESS) {
continue;
break;
}
}
"extra GLUE AAAA record (%s)",
/* XXX950 make fatal for 9.5.0. */
/* answer = ISC_FALSE; */
}
}
/*
* Check that all addresses appear in the glue.
*/
case AF_INET:
rdataset = a;
type = "A";
break;
case AF_INET6:
type = "AAAA";
break;
default:
continue;
}
else
}
if (!match) {
"missing GLUE %s record (%s)",
/* XXX950 make fatal for 9.5.0. */
/* answer = ISC_FALSE; */
}
}
if (missing_glue)
}
return (answer);
#else
return (ISC_TRUE);
#endif
}
static isc_boolean_t
#ifdef USE_GETADDRINFO
char ownerbuf[DNS_NAME_FORMATSIZE];
int result;
int level = ISC_LOG_ERROR;
/*
* Turn off search.
*/
switch (result) {
case 0:
/*
* Work around broken getaddrinfo() implementations that
* fail to set ai_canonname on first entry.
*/
if ((zone_options & DNS_ZONEOPT_WARNMXCNAME) != 0)
if ((zone_options & DNS_ZONEOPT_IGNOREMXCNAME) == 0) {
" is a CNAME '%s' "
"(illegal)",
cur->ai_canonname);
}
if (level == ISC_LOG_ERROR)
}
}
return (answer);
case EAI_NONAME:
case EAI_NODATA:
#endif
"has no addresses records (A or AAAA)",
}
/* XXX950 make fatal for 9.5.0. */
return (ISC_TRUE);
default:
"getaddrinfo(%s) failed: %s",
}
return (ISC_TRUE);
}
#else
return (ISC_TRUE);
#endif
}
static isc_boolean_t
#ifdef USE_GETADDRINFO
char ownerbuf[DNS_NAME_FORMATSIZE];
int result;
int level = ISC_LOG_ERROR;
/*
* Turn off search.
*/
switch (result) {
case 0:
/*
* Work around broken getaddrinfo() implementations that
* fail to set ai_canonname on first entry.
*/
if ((zone_options & DNS_ZONEOPT_WARNSRVCNAME) != 0)
if ((zone_options & DNS_ZONEOPT_IGNORESRVCNAME) == 0) {
" (out of zone) is a "
"CNAME '%s' (illegal)",
cur->ai_canonname);
}
if (level == ISC_LOG_ERROR)
}
}
return (answer);
case EAI_NONAME:
case EAI_NODATA:
#endif
"has no addresses records (A or AAAA)",
}
/* XXX950 make fatal for 9.5.0. */
return (ISC_TRUE);
default:
"getaddrinfo(%s) failed: %s",
}
return (ISC_TRUE);
}
#else
return (ISC_TRUE);
#endif
}
&destination, 0) == ISC_R_SUCCESS);
return (ISC_R_SUCCESS);
}
/*% scan the zone for oversize TTLs */
static isc_result_t
result == ISC_R_SUCCESS;
if (result == DNS_R_NEWORIGIN)
result == ISC_R_SUCCESS;
char nbuf[DNS_NAME_FORMATSIZE];
char tbuf[255];
isc_buffer_t b;
isc_region_t r;
isc_buffer_usedregion(&b, &r);
"%s/%s TTL %d exceeds "
"maximum TTL %d",
}
}
if (result == ISC_R_NOMORE)
}
if (result == ISC_R_NOMORE)
dns_db_detach(&db);
return (result);
}
/*% load the zone */
{
if (debug)
if (docheckmx)
if (docheckns)
if (dochecksrv)
/*
* When loading map files we can't catch oversize TTLs during
* load, so we check for them here.
*/
}
}
return (result);
}
/*% dump the zone */
const isc_uint32_t rawversion)
{
const char *flags;
if (debug) {
else
}
if (result != ISC_R_SUCCESS) {
"file \"%s\" for writing\n", filename);
return (ISC_R_FAILURE);
}
}
(void)isc_stdio_close(output);
return (result);
}
#ifdef _WIN32
void
InitSockets(void) {
int err;
if (err != 0) {
exit(1);
}
}
void
DestroySockets(void) {
WSACleanup();
}
#endif