2000-12-13 06:05:42 +00:00
|
|
|
/*
|
2014-02-20 10:53:11 +11:00
|
|
|
* Copyright (C) 2004-2014 Internet Systems Consortium, Inc. ("ISC")
|
2004-03-05 05:14:21 +00:00
|
|
|
* Copyright (C) 1999-2003 Internet Software Consortium.
|
2000-12-13 06:05:42 +00:00
|
|
|
*
|
2007-06-18 23:47:57 +00:00
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
2000-12-13 06:05:42 +00:00
|
|
|
* 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-13 06:05:42 +00:00
|
|
|
*/
|
|
|
|
|
2012-06-20 14:13:12 -05:00
|
|
|
/* $Id: named-checkzone.c,v 1.65.32.2 2012/02/07 02:45:21 each Exp $ */
|
2005-04-27 04:57:32 +00:00
|
|
|
|
|
|
|
/*! \file */
|
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>
|
2004-10-25 01:27:54 +00:00
|
|
|
#include <isc/entropy.h>
|
|
|
|
#include <isc/hash.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>
|
2011-12-22 07:32:41 +00:00
|
|
|
#include <dns/master.h>
|
2005-06-20 01:05:33 +00:00
|
|
|
#include <dns/masterdump.h>
|
2005-05-19 04:59:05 +00:00
|
|
|
#include <dns/name.h>
|
2000-12-13 06:05:42 +00:00
|
|
|
#include <dns/rdataclass.h>
|
|
|
|
#include <dns/rdataset.h>
|
|
|
|
#include <dns/result.h>
|
2005-06-20 01:05:33 +00:00
|
|
|
#include <dns/types.h>
|
2000-12-13 06:05:42 +00:00
|
|
|
#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;
|
2004-10-25 01:27:54 +00:00
|
|
|
static isc_entropy_t *ectx = NULL;
|
2000-12-13 06:05:42 +00:00
|
|
|
dns_zone_t *zone = NULL;
|
|
|
|
dns_zonetype_t zonetype = dns_zone_master;
|
2004-01-07 05:27:17 +00:00
|
|
|
static int dumpzone = 0;
|
|
|
|
static const char *output_filename;
|
2005-06-20 01:05:33 +00:00
|
|
|
static char *prog_name = NULL;
|
2005-09-01 02:25:06 +00:00
|
|
|
static const dns_master_style_t *outputstyle = NULL;
|
2005-06-20 01:05:33 +00:00
|
|
|
static enum { progmode_check, progmode_compile } progmode;
|
2000-12-13 06:05:42 +00:00
|
|
|
|
|
|
|
#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)
|
|
|
|
|
2009-09-29 15:06:07 +00:00
|
|
|
ISC_PLATFORM_NORETURN_PRE static void
|
|
|
|
usage(void) ISC_PLATFORM_NORETURN_POST;
|
|
|
|
|
2000-12-13 06:05:42 +00:00
|
|
|
static void
|
2000-12-21 01:54:30 +00:00
|
|
|
usage(void) {
|
2000-12-13 06:05:42 +00:00
|
|
|
fprintf(stderr,
|
2009-11-10 20:02:01 +00:00
|
|
|
"usage: %s [-djqvD] [-c class] "
|
2013-01-09 16:56:46 -08:00
|
|
|
"[-f inputformat] [-F outputformat] [-J filename] "
|
2004-10-06 05:56:29 +00:00
|
|
|
"[-t directory] [-w directory] [-k (ignore|warn|fail)] "
|
2005-05-19 04:59:05 +00:00
|
|
|
"[-n (ignore|warn|fail)] [-m (ignore|warn|fail)] "
|
2009-12-04 21:09:34 +00:00
|
|
|
"[-r (ignore|warn|fail)] "
|
2008-10-24 00:56:32 +00:00
|
|
|
"[-i (full|full-sibling|local|local-sibling|none)] "
|
|
|
|
"[-M (ignore|warn|fail)] [-S (ignore|warn|fail)] "
|
|
|
|
"[-W (ignore|warn)] "
|
2009-11-10 20:02:01 +00:00
|
|
|
"%s zonename filename\n",
|
|
|
|
prog_name,
|
2009-11-10 21:30:42 +00:00
|
|
|
progmode == progmode_check ? "[-o filename]" : "-o filename");
|
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);
|
2005-09-18 07:16:24 +00:00
|
|
|
dns_name_destroy();
|
2000-12-13 06:05:42 +00:00
|
|
|
}
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*% main processing routine */
|
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;
|
2005-06-20 01:05:33 +00:00
|
|
|
const char *inputformatstr = NULL;
|
|
|
|
const char *outputformatstr = NULL;
|
|
|
|
dns_masterformat_t inputformat = dns_masterformat_text;
|
|
|
|
dns_masterformat_t outputformat = dns_masterformat_text;
|
2011-12-22 07:32:41 +00:00
|
|
|
dns_masterrawheader_t header;
|
|
|
|
isc_uint32_t rawversion = 1, serialnum = 0;
|
2014-02-18 23:26:50 -08:00
|
|
|
dns_ttl_t maxttl = 0;
|
2011-12-22 07:32:41 +00:00
|
|
|
isc_boolean_t snset = ISC_FALSE;
|
2011-12-22 17:29:22 +00:00
|
|
|
isc_boolean_t logdump = ISC_FALSE;
|
2007-05-21 02:47:25 +00:00
|
|
|
FILE *errout = stdout;
|
2011-12-22 07:32:41 +00:00
|
|
|
char *endp;
|
2005-06-20 01:05:33 +00:00
|
|
|
|
2012-06-20 14:13:12 -05:00
|
|
|
/*
|
|
|
|
* Uncomment the following line if memory debugging is needed:
|
|
|
|
* isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
|
|
|
|
*/
|
|
|
|
|
2005-09-01 02:25:06 +00:00
|
|
|
outputstyle = &dns_master_style_full;
|
|
|
|
|
2005-06-20 01:05:33 +00:00
|
|
|
prog_name = strrchr(argv[0], '/');
|
2007-03-29 04:39:07 +00:00
|
|
|
if (prog_name == NULL)
|
|
|
|
prog_name = strrchr(argv[0], '\\');
|
2005-06-20 01:05:33 +00:00
|
|
|
if (prog_name != NULL)
|
|
|
|
prog_name++;
|
|
|
|
else
|
|
|
|
prog_name = argv[0];
|
2005-06-22 23:29:07 +00:00
|
|
|
/*
|
|
|
|
* Libtool doesn't preserve the program name prior to final
|
|
|
|
* installation. Remove the libtool prefix ("lt-").
|
|
|
|
*/
|
|
|
|
if (strncmp(prog_name, "lt-", 3) == 0)
|
|
|
|
prog_name += 3;
|
2009-05-29 02:14:31 +00:00
|
|
|
|
|
|
|
#define PROGCMP(X) \
|
|
|
|
(strcasecmp(prog_name, X) == 0 || strcasecmp(prog_name, X ".exe") == 0)
|
|
|
|
|
|
|
|
if (PROGCMP("named-checkzone"))
|
2005-06-20 01:05:33 +00:00
|
|
|
progmode = progmode_check;
|
2009-05-29 02:14:31 +00:00
|
|
|
else if (PROGCMP("named-compilezone"))
|
2005-06-20 01:05:33 +00:00
|
|
|
progmode = progmode_compile;
|
|
|
|
else
|
|
|
|
INSIST(0);
|
|
|
|
|
|
|
|
/* Compilation specific defaults */
|
|
|
|
if (progmode == progmode_compile) {
|
|
|
|
zone_options |= (DNS_ZONEOPT_CHECKNS |
|
|
|
|
DNS_ZONEOPT_FATALNS |
|
2013-04-30 13:49:41 +10:00
|
|
|
DNS_ZONEOPT_CHECKSPF |
|
2009-12-04 21:09:34 +00:00
|
|
|
DNS_ZONEOPT_CHECKDUPRR |
|
2005-06-20 01:05:33 +00:00
|
|
|
DNS_ZONEOPT_CHECKNAMES |
|
|
|
|
DNS_ZONEOPT_CHECKNAMESFAIL |
|
|
|
|
DNS_ZONEOPT_CHECKWILDCARD);
|
2009-12-04 22:06:37 +00:00
|
|
|
} else
|
2013-04-30 13:49:41 +10:00
|
|
|
zone_options |= (DNS_ZONEOPT_CHECKDUPRR |
|
|
|
|
DNS_ZONEOPT_CHECKSPF);
|
2000-12-13 06:05:42 +00:00
|
|
|
|
2006-01-05 23:45:34 +00:00
|
|
|
#define ARGCMP(X) (strcmp(isc_commandline_argument, X) == 0)
|
|
|
|
|
2007-05-21 02:47:25 +00:00
|
|
|
isc_commandline_errprint = ISC_FALSE;
|
|
|
|
|
2005-05-19 04:59:05 +00:00
|
|
|
while ((c = isc_commandline_parse(argc, argv,
|
2014-02-18 23:26:50 -08:00
|
|
|
"c:df:hi:jJ:k:L:l:m:n:qr:s:t:o:vw:DF:M:S:T:W:"))
|
2005-06-20 01:05:33 +00:00
|
|
|
!= 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
|
|
|
|
2005-05-19 04:59:05 +00:00
|
|
|
case 'i':
|
2006-01-05 23:45:34 +00:00
|
|
|
if (ARGCMP("full")) {
|
2005-08-24 23:54:04 +00:00
|
|
|
zone_options |= DNS_ZONEOPT_CHECKINTEGRITY |
|
|
|
|
DNS_ZONEOPT_CHECKSIBLING;
|
|
|
|
docheckmx = ISC_TRUE;
|
|
|
|
docheckns = ISC_TRUE;
|
|
|
|
dochecksrv = ISC_TRUE;
|
2006-01-05 23:45:34 +00:00
|
|
|
} else if (ARGCMP("full-sibling")) {
|
2005-08-24 23:54:04 +00:00
|
|
|
zone_options |= DNS_ZONEOPT_CHECKINTEGRITY;
|
|
|
|
zone_options &= ~DNS_ZONEOPT_CHECKSIBLING;
|
2005-05-19 04:59:05 +00:00
|
|
|
docheckmx = ISC_TRUE;
|
|
|
|
docheckns = ISC_TRUE;
|
|
|
|
dochecksrv = ISC_TRUE;
|
2006-01-05 23:45:34 +00:00
|
|
|
} else if (ARGCMP("local")) {
|
2005-08-24 23:54:04 +00:00
|
|
|
zone_options |= DNS_ZONEOPT_CHECKINTEGRITY;
|
|
|
|
zone_options |= DNS_ZONEOPT_CHECKSIBLING;
|
|
|
|
docheckmx = ISC_FALSE;
|
|
|
|
docheckns = ISC_FALSE;
|
|
|
|
dochecksrv = ISC_FALSE;
|
2006-01-05 23:45:34 +00:00
|
|
|
} else if (ARGCMP("local-sibling")) {
|
2005-08-24 23:54:04 +00:00
|
|
|
zone_options |= DNS_ZONEOPT_CHECKINTEGRITY;
|
|
|
|
zone_options &= ~DNS_ZONEOPT_CHECKSIBLING;
|
2005-05-19 04:59:05 +00:00
|
|
|
docheckmx = ISC_FALSE;
|
|
|
|
docheckns = ISC_FALSE;
|
|
|
|
dochecksrv = ISC_FALSE;
|
2006-01-05 23:45:34 +00:00
|
|
|
} else if (ARGCMP("none")) {
|
2005-08-24 23:54:04 +00:00
|
|
|
zone_options &= ~DNS_ZONEOPT_CHECKINTEGRITY;
|
|
|
|
zone_options &= ~DNS_ZONEOPT_CHECKSIBLING;
|
2005-05-19 04:59:05 +00:00
|
|
|
docheckmx = ISC_FALSE;
|
|
|
|
docheckns = ISC_FALSE;
|
|
|
|
dochecksrv = ISC_FALSE;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "invalid argument to -i: %s\n",
|
|
|
|
isc_commandline_argument);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-06-20 01:05:33 +00:00
|
|
|
case 'f':
|
|
|
|
inputformatstr = isc_commandline_argument;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'F':
|
|
|
|
outputformatstr = isc_commandline_argument;
|
|
|
|
break;
|
|
|
|
|
2002-07-11 04:49:27 +00:00
|
|
|
case 'j':
|
2002-04-02 06:54:07 +00:00
|
|
|
nomerge = ISC_FALSE;
|
|
|
|
break;
|
|
|
|
|
2013-01-09 16:56:46 -08:00
|
|
|
case 'J':
|
|
|
|
journal = isc_commandline_argument;
|
|
|
|
nomerge = ISC_FALSE;
|
|
|
|
break;
|
|
|
|
|
2005-05-19 04:59:05 +00:00
|
|
|
case 'k':
|
2006-01-05 23:45:34 +00:00
|
|
|
if (ARGCMP("warn")) {
|
2005-05-19 04:59:05 +00:00
|
|
|
zone_options |= DNS_ZONEOPT_CHECKNAMES;
|
|
|
|
zone_options &= ~DNS_ZONEOPT_CHECKNAMESFAIL;
|
2006-01-05 23:45:34 +00:00
|
|
|
} else if (ARGCMP("fail")) {
|
2005-05-19 04:59:05 +00:00
|
|
|
zone_options |= DNS_ZONEOPT_CHECKNAMES |
|
|
|
|
DNS_ZONEOPT_CHECKNAMESFAIL;
|
2006-01-05 23:45:34 +00:00
|
|
|
} else if (ARGCMP("ignore")) {
|
2005-05-19 04:59:05 +00:00
|
|
|
zone_options &= ~(DNS_ZONEOPT_CHECKNAMES |
|
|
|
|
DNS_ZONEOPT_CHECKNAMESFAIL);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "invalid argument to -k: %s\n",
|
|
|
|
isc_commandline_argument);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-12-22 07:32:41 +00:00
|
|
|
case 'L':
|
|
|
|
snset = ISC_TRUE;
|
|
|
|
endp = NULL;
|
|
|
|
serialnum = strtol(isc_commandline_argument, &endp, 0);
|
|
|
|
if (*endp != '\0') {
|
|
|
|
fprintf(stderr, "source serial number "
|
|
|
|
"must be numeric");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-02-18 23:26:50 -08:00
|
|
|
case 'l':
|
|
|
|
zone_options2 |= DNS_ZONEOPT2_CHECKTTL;
|
|
|
|
endp = NULL;
|
|
|
|
maxttl = strtol(isc_commandline_argument, &endp, 0);
|
|
|
|
if (*endp != '\0') {
|
|
|
|
fprintf(stderr, "maximum TTL "
|
|
|
|
"must be numeric");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
2002-07-19 02:34:58 +00:00
|
|
|
case 'n':
|
2006-01-05 23:45:34 +00:00
|
|
|
if (ARGCMP("ignore")) {
|
2002-07-19 02:34:58 +00:00
|
|
|
zone_options &= ~(DNS_ZONEOPT_CHECKNS|
|
|
|
|
DNS_ZONEOPT_FATALNS);
|
2006-01-05 23:45:34 +00:00
|
|
|
} else if (ARGCMP("warn")) {
|
2002-07-19 02:34:58 +00:00
|
|
|
zone_options |= DNS_ZONEOPT_CHECKNS;
|
|
|
|
zone_options &= ~DNS_ZONEOPT_FATALNS;
|
2006-01-05 23:45:34 +00:00
|
|
|
} else if (ARGCMP("fail")) {
|
2002-07-19 02:34:58 +00:00
|
|
|
zone_options |= DNS_ZONEOPT_CHECKNS|
|
2008-10-24 01:44:48 +00:00
|
|
|
DNS_ZONEOPT_FATALNS;
|
2005-05-19 04:59:05 +00:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, "invalid argument to -n: %s\n",
|
|
|
|
isc_commandline_argument);
|
|
|
|
exit(1);
|
|
|
|
}
|
2002-07-19 02:34:58 +00:00
|
|
|
break;
|
|
|
|
|
2005-05-19 04:59:05 +00:00
|
|
|
case 'm':
|
2006-01-05 23:45:34 +00:00
|
|
|
if (ARGCMP("warn")) {
|
2005-05-19 04:59:05 +00:00
|
|
|
zone_options |= DNS_ZONEOPT_CHECKMX;
|
|
|
|
zone_options &= ~DNS_ZONEOPT_CHECKMXFAIL;
|
2006-01-05 23:45:34 +00:00
|
|
|
} else if (ARGCMP("fail")) {
|
2005-05-19 04:59:05 +00:00
|
|
|
zone_options |= DNS_ZONEOPT_CHECKMX |
|
|
|
|
DNS_ZONEOPT_CHECKMXFAIL;
|
2006-01-05 23:45:34 +00:00
|
|
|
} else if (ARGCMP("ignore")) {
|
2005-05-19 04:59:05 +00:00
|
|
|
zone_options &= ~(DNS_ZONEOPT_CHECKMX |
|
|
|
|
DNS_ZONEOPT_CHECKMXFAIL);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "invalid argument to -m: %s\n",
|
|
|
|
isc_commandline_argument);
|
|
|
|
exit(1);
|
2004-02-27 20:41:51 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-12-04 21:09:34 +00:00
|
|
|
case 'o':
|
|
|
|
output_filename = isc_commandline_argument;
|
|
|
|
break;
|
|
|
|
|
2000-12-13 06:05:42 +00:00
|
|
|
case 'q':
|
|
|
|
quiet++;
|
|
|
|
break;
|
2001-09-15 02:05:35 +00:00
|
|
|
|
2009-12-04 21:09:34 +00:00
|
|
|
case 'r':
|
|
|
|
if (ARGCMP("warn")) {
|
|
|
|
zone_options |= DNS_ZONEOPT_CHECKDUPRR;
|
|
|
|
zone_options &= ~DNS_ZONEOPT_CHECKDUPRRFAIL;
|
|
|
|
} else if (ARGCMP("fail")) {
|
|
|
|
zone_options |= DNS_ZONEOPT_CHECKDUPRR |
|
|
|
|
DNS_ZONEOPT_CHECKDUPRRFAIL;
|
|
|
|
} else if (ARGCMP("ignore")) {
|
|
|
|
zone_options &= ~(DNS_ZONEOPT_CHECKDUPRR |
|
|
|
|
DNS_ZONEOPT_CHECKDUPRRFAIL);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "invalid argument to -r: %s\n",
|
|
|
|
isc_commandline_argument);
|
2001-09-15 02:05:35 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-06-20 01:05:33 +00:00
|
|
|
case 's':
|
2006-01-05 23:45:34 +00:00
|
|
|
if (ARGCMP("full"))
|
2005-06-20 01:05:33 +00:00
|
|
|
outputstyle = &dns_master_style_full;
|
2006-08-30 22:57:16 +00:00
|
|
|
else if (ARGCMP("relative")) {
|
2005-06-20 01:05:33 +00:00
|
|
|
outputstyle = &dns_master_style_default;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr,
|
|
|
|
"unknown or unsupported style: %s\n",
|
|
|
|
isc_commandline_argument);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-12-04 21:09:34 +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);
|
|
|
|
}
|
2004-01-07 05:27:17 +00:00
|
|
|
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;
|
|
|
|
|
2004-01-07 05:27:17 +00:00
|
|
|
case 'D':
|
|
|
|
dumpzone++;
|
|
|
|
break;
|
|
|
|
|
2006-01-05 23:45:34 +00:00
|
|
|
case 'M':
|
|
|
|
if (ARGCMP("fail")) {
|
|
|
|
zone_options &= ~DNS_ZONEOPT_WARNMXCNAME;
|
|
|
|
zone_options &= ~DNS_ZONEOPT_IGNOREMXCNAME;
|
|
|
|
} else if (ARGCMP("warn")) {
|
|
|
|
zone_options |= DNS_ZONEOPT_WARNMXCNAME;
|
|
|
|
zone_options &= ~DNS_ZONEOPT_IGNOREMXCNAME;
|
|
|
|
} else if (ARGCMP("ignore")) {
|
|
|
|
zone_options |= DNS_ZONEOPT_WARNMXCNAME;
|
|
|
|
zone_options |= DNS_ZONEOPT_IGNOREMXCNAME;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "invalid argument to -M: %s\n",
|
|
|
|
isc_commandline_argument);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'S':
|
|
|
|
if (ARGCMP("fail")) {
|
|
|
|
zone_options &= ~DNS_ZONEOPT_WARNSRVCNAME;
|
|
|
|
zone_options &= ~DNS_ZONEOPT_IGNORESRVCNAME;
|
|
|
|
} else if (ARGCMP("warn")) {
|
|
|
|
zone_options |= DNS_ZONEOPT_WARNSRVCNAME;
|
|
|
|
zone_options &= ~DNS_ZONEOPT_IGNORESRVCNAME;
|
|
|
|
} else if (ARGCMP("ignore")) {
|
|
|
|
zone_options |= DNS_ZONEOPT_WARNSRVCNAME;
|
|
|
|
zone_options |= DNS_ZONEOPT_IGNORESRVCNAME;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "invalid argument to -S: %s\n",
|
|
|
|
isc_commandline_argument);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-04-30 13:49:41 +10:00
|
|
|
case 'T':
|
|
|
|
if (ARGCMP("warn")) {
|
|
|
|
zone_options |= DNS_ZONEOPT_CHECKSPF;
|
|
|
|
} else if (ARGCMP("ignore")) {
|
|
|
|
zone_options &= ~DNS_ZONEOPT_CHECKSPF;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "invalid argument to -T: %s\n",
|
|
|
|
isc_commandline_argument);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-01-09 23:40:04 +00:00
|
|
|
case 'W':
|
2006-01-05 23:45:34 +00:00
|
|
|
if (ARGCMP("warn"))
|
2005-01-09 23:40:04 +00:00
|
|
|
zone_options |= DNS_ZONEOPT_CHECKWILDCARD;
|
2006-01-05 23:45:34 +00:00
|
|
|
else if (ARGCMP("ignore"))
|
2005-01-09 23:40:04 +00:00
|
|
|
zone_options &= ~DNS_ZONEOPT_CHECKWILDCARD;
|
|
|
|
break;
|
|
|
|
|
2007-05-21 02:47:25 +00:00
|
|
|
case '?':
|
|
|
|
if (isc_commandline_option != '?')
|
|
|
|
fprintf(stderr, "%s: invalid argument -%c\n",
|
|
|
|
prog_name, isc_commandline_option);
|
2012-10-23 22:04:06 -07:00
|
|
|
/* FALLTHROUGH */
|
2007-05-21 02:47:25 +00:00
|
|
|
case 'h':
|
2000-12-13 06:05:42 +00:00
|
|
|
usage();
|
|
|
|
|
2007-05-21 02:47:25 +00:00
|
|
|
default:
|
|
|
|
fprintf(stderr, "%s: unhandled option -%c\n",
|
2008-10-24 01:44:48 +00:00
|
|
|
prog_name, isc_commandline_option);
|
2007-05-21 02:47:25 +00:00
|
|
|
exit(1);
|
2005-06-20 01:05:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-20 01:05:33 +00:00
|
|
|
if (inputformatstr != NULL) {
|
|
|
|
if (strcasecmp(inputformatstr, "text") == 0)
|
|
|
|
inputformat = dns_masterformat_text;
|
|
|
|
else if (strcasecmp(inputformatstr, "raw") == 0)
|
|
|
|
inputformat = dns_masterformat_raw;
|
2011-12-08 16:07:22 +00:00
|
|
|
else if (strncasecmp(inputformatstr, "raw=", 4) == 0) {
|
|
|
|
inputformat = dns_masterformat_raw;
|
|
|
|
fprintf(stderr,
|
|
|
|
"WARNING: input format raw, version ignored\n");
|
2013-01-24 14:20:48 -08:00
|
|
|
} else if (strcasecmp(inputformatstr, "map") == 0) {
|
|
|
|
inputformat = dns_masterformat_map;
|
2011-12-08 16:07:22 +00:00
|
|
|
} else {
|
2005-06-20 01:05:33 +00:00
|
|
|
fprintf(stderr, "unknown file format: %s\n",
|
|
|
|
inputformatstr);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (outputformatstr != NULL) {
|
2011-12-08 16:07:22 +00:00
|
|
|
if (strcasecmp(outputformatstr, "text") == 0) {
|
2005-06-20 01:05:33 +00:00
|
|
|
outputformat = dns_masterformat_text;
|
2011-12-08 16:07:22 +00:00
|
|
|
} else if (strcasecmp(outputformatstr, "raw") == 0) {
|
|
|
|
outputformat = dns_masterformat_raw;
|
|
|
|
} else if (strncasecmp(outputformatstr, "raw=", 4) == 0) {
|
|
|
|
char *end;
|
|
|
|
|
2005-06-20 01:05:33 +00:00
|
|
|
outputformat = dns_masterformat_raw;
|
2011-12-08 16:07:22 +00:00
|
|
|
rawversion = strtol(outputformatstr + 4, &end, 10);
|
|
|
|
if (end == outputformatstr + 4 || *end != '\0' ||
|
|
|
|
rawversion > 1U) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"unknown raw format version\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2013-01-24 14:20:48 -08:00
|
|
|
} else if (strcasecmp(outputformatstr, "map") == 0) {
|
|
|
|
outputformat = dns_masterformat_map;
|
2011-12-08 16:07:22 +00:00
|
|
|
} else {
|
2005-06-20 01:05:33 +00:00
|
|
|
fprintf(stderr, "unknown file format: %s\n",
|
|
|
|
outputformatstr);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-21 02:47:25 +00:00
|
|
|
if (progmode == progmode_compile) {
|
|
|
|
dumpzone = 1; /* always dump */
|
2011-12-22 17:29:22 +00:00
|
|
|
logdump = !quiet;
|
2007-05-21 02:47:25 +00:00
|
|
|
if (output_filename == NULL) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"output file required, but not specified\n");
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (output_filename != NULL)
|
|
|
|
dumpzone = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we are outputing to stdout then send the informational
|
|
|
|
* output to stderr.
|
|
|
|
*/
|
|
|
|
if (dumpzone &&
|
|
|
|
(output_filename == NULL ||
|
|
|
|
strcmp(output_filename, "-") == 0 ||
|
|
|
|
strcmp(output_filename, "/dev/fd/1") == 0 ||
|
2011-12-22 17:29:22 +00:00
|
|
|
strcmp(output_filename, "/dev/stdout") == 0)) {
|
2007-05-21 02:47:25 +00:00
|
|
|
errout = stderr;
|
2011-12-22 17:29:22 +00:00
|
|
|
logdump = ISC_FALSE;
|
|
|
|
}
|
2007-05-21 02:47:25 +00:00
|
|
|
|
|
|
|
if (isc_commandline_index + 2 != argc)
|
2000-12-13 06:05:42 +00:00
|
|
|
usage();
|
|
|
|
|
2010-09-07 01:49:08 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
InitSockets();
|
|
|
|
#endif
|
|
|
|
|
2000-12-13 06:05:42 +00:00
|
|
|
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
|
2005-08-22 00:58:18 +00:00
|
|
|
if (!quiet)
|
2007-05-21 02:47:25 +00:00
|
|
|
RUNTIME_CHECK(setup_logging(mctx, errout, &lctx)
|
|
|
|
== ISC_R_SUCCESS);
|
2004-10-25 01:27:54 +00:00
|
|
|
RUNTIME_CHECK(isc_entropy_create(mctx, &ectx) == ISC_R_SUCCESS);
|
|
|
|
RUNTIME_CHECK(isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE)
|
|
|
|
== ISC_R_SUCCESS);
|
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++];
|
2005-06-20 01:05:33 +00:00
|
|
|
result = load_zone(mctx, origin, filename, inputformat, classname,
|
2014-02-18 23:26:50 -08:00
|
|
|
maxttl, &zone);
|
2004-01-07 05:27:17 +00:00
|
|
|
|
2011-12-22 07:32:41 +00:00
|
|
|
if (snset) {
|
|
|
|
dns_master_initrawheader(&header);
|
|
|
|
header.flags = DNS_MASTERRAW_SOURCESERIALSET;
|
|
|
|
header.sourceserial = serialnum;
|
|
|
|
dns_zone_setrawdata(zone, &header);
|
|
|
|
}
|
|
|
|
|
2004-01-07 05:27:17 +00:00
|
|
|
if (result == ISC_R_SUCCESS && dumpzone) {
|
2011-12-22 17:29:22 +00:00
|
|
|
if (logdump) {
|
2007-05-21 02:47:25 +00:00
|
|
|
fprintf(errout, "dump zone to %s...", output_filename);
|
|
|
|
fflush(errout);
|
2005-06-20 01:05:33 +00:00
|
|
|
}
|
|
|
|
result = dump_zone(origin, zone, output_filename,
|
2011-12-08 16:07:22 +00:00
|
|
|
outputformat, outputstyle, rawversion);
|
2011-12-22 17:29:22 +00:00
|
|
|
if (logdump)
|
2007-05-21 02:47:25 +00:00
|
|
|
fprintf(errout, "done\n");
|
2004-01-07 05:27:17 +00:00
|
|
|
}
|
|
|
|
|
2000-12-13 06:05:42 +00:00
|
|
|
if (!quiet && result == ISC_R_SUCCESS)
|
2007-05-21 02:47:25 +00:00
|
|
|
fprintf(errout, "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);
|
2004-10-25 01:27:54 +00:00
|
|
|
isc_hash_destroy();
|
|
|
|
isc_entropy_detach(&ectx);
|
2000-12-13 06:05:42 +00:00
|
|
|
isc_mem_destroy(&mctx);
|
2010-09-07 01:49:08 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
DestroySockets();
|
|
|
|
#endif
|
2000-12-14 01:03:48 +00:00
|
|
|
return ((result == ISC_R_SUCCESS) ? 0 : 1);
|
2000-12-13 06:05:42 +00:00
|
|
|
}
|