2001-07-01 23:47:49 +00:00
|
|
|
/*
|
2014-02-16 23:46:32 +00:00
|
|
|
* Copyright (C) 2004-2014 Internet Systems Consortium, Inc. ("ISC")
|
2004-03-05 05:14:21 +00:00
|
|
|
* Copyright (C) 2000-2003 Internet Software Consortium.
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2007-06-18 23:47:57 +00:00
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
2000-04-19 23:23:31 +00:00
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
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-04-19 23:23:31 +00:00
|
|
|
*/
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*! \file */
|
2000-06-06 18:49:06 +00:00
|
|
|
|
2000-04-19 23:23:31 +00:00
|
|
|
#include <config.h>
|
|
|
|
#include <stdlib.h>
|
2000-08-26 01:51:37 +00:00
|
|
|
#include <time.h>
|
2000-09-22 23:21:32 +00:00
|
|
|
#include <ctype.h>
|
2000-04-19 23:23:31 +00:00
|
|
|
|
2000-06-22 01:26:38 +00:00
|
|
|
#include <isc/app.h>
|
2000-08-14 20:23:39 +00:00
|
|
|
#include <isc/netaddr.h>
|
2001-11-30 01:02:18 +00:00
|
|
|
#include <isc/parseint.h>
|
2000-11-20 13:02:18 +00:00
|
|
|
#include <isc/print.h>
|
2000-06-22 01:26:38 +00:00
|
|
|
#include <isc/string.h>
|
2000-06-30 14:11:49 +00:00
|
|
|
#include <isc/task.h>
|
2014-04-18 09:52:12 +10:00
|
|
|
#include <isc/util.h>
|
2000-06-22 01:26:38 +00:00
|
|
|
|
2000-08-14 20:23:39 +00:00
|
|
|
#include <dns/byaddr.h>
|
|
|
|
#include <dns/fixedname.h>
|
2001-03-28 02:42:56 +00:00
|
|
|
#include <dns/masterdump.h>
|
2000-04-19 23:23:31 +00:00
|
|
|
#include <dns/message.h>
|
2000-05-30 22:27:27 +00:00
|
|
|
#include <dns/name.h>
|
2000-04-19 23:23:31 +00:00
|
|
|
#include <dns/rdata.h>
|
|
|
|
#include <dns/rdataset.h>
|
|
|
|
#include <dns/rdatatype.h>
|
2000-07-18 01:28:20 +00:00
|
|
|
#include <dns/rdataclass.h>
|
2001-06-29 06:06:02 +00:00
|
|
|
#include <dns/result.h>
|
2006-01-27 02:35:15 +00:00
|
|
|
#include <dns/tsig.h>
|
2000-04-19 23:23:31 +00:00
|
|
|
|
2004-04-13 02:54:15 +00:00
|
|
|
#include <dig/dig.h>
|
|
|
|
|
2000-07-05 19:31:26 +00:00
|
|
|
#define ADD_STRING(b, s) { \
|
|
|
|
if (strlen(s) >= isc_buffer_availablelength(b)) \
|
2008-02-05 23:47:08 +00:00
|
|
|
return (ISC_R_NOSPACE); \
|
2000-07-05 19:31:26 +00:00
|
|
|
else \
|
|
|
|
isc_buffer_putstr(b, s); \
|
|
|
|
}
|
2000-05-24 19:27:01 +00:00
|
|
|
|
2004-09-06 01:24:44 +00:00
|
|
|
#define DIG_MAX_ADDRESSES 20
|
2000-05-24 19:27:01 +00:00
|
|
|
|
2000-07-18 01:28:20 +00:00
|
|
|
dig_lookup_t *default_lookup = NULL;
|
2000-04-26 18:34:17 +00:00
|
|
|
|
2001-07-27 06:11:10 +00:00
|
|
|
static char *batchname = NULL;
|
|
|
|
static FILE *batchfp = NULL;
|
|
|
|
static char *argv0;
|
2004-09-06 01:24:44 +00:00
|
|
|
static int addresscount = 0;
|
2000-06-06 22:50:44 +00:00
|
|
|
|
2001-07-27 06:11:10 +00:00
|
|
|
static char domainopt[DNS_NAME_MAXTEXT];
|
2014-02-19 12:53:42 +11:00
|
|
|
#ifdef ISC_PLATFORM_USESIT
|
|
|
|
static char sitvalue[256];
|
|
|
|
#endif
|
2001-01-18 05:12:44 +00:00
|
|
|
|
2001-07-27 06:11:10 +00:00
|
|
|
static isc_boolean_t short_form = ISC_FALSE, printcmd = ISC_TRUE,
|
2002-07-25 05:46:07 +00:00
|
|
|
ip6_int = ISC_FALSE, plusquest = ISC_FALSE, pluscomm = ISC_FALSE,
|
2010-03-04 05:18:04 +00:00
|
|
|
multiline = ISC_FALSE, nottl = ISC_FALSE, noclass = ISC_FALSE,
|
2013-08-12 15:37:51 +10:00
|
|
|
onesoa = ISC_FALSE, rrcomments = ISC_FALSE, use_usec = ISC_FALSE,
|
2014-04-29 16:58:36 -07:00
|
|
|
nocrypto = ISC_FALSE, ttlunits = ISC_FALSE;
|
2011-03-05 19:39:07 +00:00
|
|
|
static isc_uint32_t splitwidth = 0xffffffff;
|
2000-05-08 22:51:08 +00:00
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*% opcode text */
|
2008-10-15 02:16:51 +00:00
|
|
|
static const char * const opcodetext[] = {
|
2000-04-26 18:34:17 +00:00
|
|
|
"QUERY",
|
|
|
|
"IQUERY",
|
|
|
|
"STATUS",
|
|
|
|
"RESERVED3",
|
|
|
|
"NOTIFY",
|
|
|
|
"UPDATE",
|
|
|
|
"RESERVED6",
|
|
|
|
"RESERVED7",
|
|
|
|
"RESERVED8",
|
|
|
|
"RESERVED9",
|
|
|
|
"RESERVED10",
|
|
|
|
"RESERVED11",
|
|
|
|
"RESERVED12",
|
|
|
|
"RESERVED13",
|
|
|
|
"RESERVED14",
|
|
|
|
"RESERVED15"
|
|
|
|
};
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*% return code text */
|
2008-10-15 02:16:51 +00:00
|
|
|
static const char * const rcodetext[] = {
|
2000-04-26 18:34:17 +00:00
|
|
|
"NOERROR",
|
|
|
|
"FORMERR",
|
|
|
|
"SERVFAIL",
|
|
|
|
"NXDOMAIN",
|
2001-12-19 12:16:47 +00:00
|
|
|
"NOTIMP",
|
2000-04-26 18:34:17 +00:00
|
|
|
"REFUSED",
|
|
|
|
"YXDOMAIN",
|
|
|
|
"YXRRSET",
|
|
|
|
"NXRRSET",
|
|
|
|
"NOTAUTH",
|
|
|
|
"NOTZONE",
|
|
|
|
"RESERVED11",
|
|
|
|
"RESERVED12",
|
|
|
|
"RESERVED13",
|
|
|
|
"RESERVED14",
|
|
|
|
"RESERVED15",
|
|
|
|
"BADVERS"
|
|
|
|
};
|
2000-04-19 23:23:31 +00:00
|
|
|
|
2009-05-06 10:16:32 +00:00
|
|
|
/*% safe rcodetext[] */
|
|
|
|
static char *
|
|
|
|
rcode_totext(dns_rcode_t rcode)
|
|
|
|
{
|
|
|
|
static char buf[sizeof("?65535")];
|
|
|
|
union {
|
|
|
|
const char *consttext;
|
|
|
|
char *deconsttext;
|
|
|
|
} totext;
|
|
|
|
|
|
|
|
if (rcode >= (sizeof(rcodetext)/sizeof(rcodetext[0]))) {
|
|
|
|
snprintf(buf, sizeof(buf), "?%u", rcode);
|
|
|
|
totext.deconsttext = buf;
|
|
|
|
} else
|
|
|
|
totext.consttext = rcodetext[rcode];
|
|
|
|
return totext.deconsttext;
|
|
|
|
}
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*% print usage */
|
2000-04-20 19:09:11 +00:00
|
|
|
static void
|
2001-05-08 15:56:01 +00:00
|
|
|
print_usage(FILE *fp) {
|
2000-07-05 19:31:26 +00:00
|
|
|
fputs(
|
2000-05-12 18:45:38 +00:00
|
|
|
"Usage: dig [@global-server] [domain] [q-type] [q-class] {q-opt}\n"
|
2004-06-07 03:56:02 +00:00
|
|
|
" {global-d-opt} host [@local-server] {local-d-opt}\n"
|
|
|
|
" [ host [@local-server] {local-d-opt} [...]]\n", fp);
|
2001-05-08 15:56:01 +00:00
|
|
|
}
|
|
|
|
|
2009-09-29 15:06:07 +00:00
|
|
|
ISC_PLATFORM_NORETURN_PRE static void
|
|
|
|
usage(void) ISC_PLATFORM_NORETURN_POST;
|
|
|
|
|
2001-05-08 15:56:01 +00:00
|
|
|
static void
|
2001-09-13 01:42:21 +00:00
|
|
|
usage(void) {
|
2001-05-08 15:56:01 +00:00
|
|
|
print_usage(stderr);
|
|
|
|
fputs("\nUse \"dig -h\" (or \"dig -h | more\") "
|
|
|
|
"for complete list of options\n", stderr);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*% version */
|
2001-09-13 01:42:21 +00:00
|
|
|
static void
|
|
|
|
version(void) {
|
|
|
|
fputs("DiG " VERSION "\n", stderr);
|
|
|
|
}
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*% help */
|
2001-05-08 15:56:01 +00:00
|
|
|
static void
|
|
|
|
help(void) {
|
|
|
|
print_usage(stdout);
|
|
|
|
fputs(
|
2004-06-07 03:56:02 +00:00
|
|
|
"Where: domain is in the Domain Name System\n"
|
2000-09-22 17:36:02 +00:00
|
|
|
" q-class is one of (in,hs,ch,...) [default: in]\n"
|
2000-05-02 23:23:12 +00:00
|
|
|
" q-type is one of (a,any,mx,ns,soa,hinfo,axfr,txt,...) [default:a]\n"
|
2000-06-06 00:43:17 +00:00
|
|
|
" (Use ixfr=version for type ixfr)\n"
|
2000-05-02 23:23:12 +00:00
|
|
|
" q-opt is one of:\n"
|
2008-02-05 06:57:52 +00:00
|
|
|
" -x dot-notation (shortcut for reverse lookups)\n"
|
|
|
|
" -i (use IP6.INT for IPv6 reverse lookups)\n"
|
2000-05-02 23:23:12 +00:00
|
|
|
" -f filename (batch mode)\n"
|
2004-06-03 04:23:01 +00:00
|
|
|
" -b address[#port] (bind to source address/port)\n"
|
2000-05-02 23:23:12 +00:00
|
|
|
" -p port (specify port number)\n"
|
2005-08-25 00:17:46 +00:00
|
|
|
" -q name (specify query name)\n"
|
2000-05-03 20:27:13 +00:00
|
|
|
" -t type (specify query type)\n"
|
|
|
|
" -c class (specify query class)\n"
|
2013-03-04 12:09:28 -08:00
|
|
|
" -u (display times in usec instead of msec)\n"
|
2001-11-28 02:46:21 +00:00
|
|
|
" -k keyfile (specify tsig key file)\n"
|
2006-01-27 02:35:15 +00:00
|
|
|
" -y [hmac:]name:key (specify named base64 tsig key)\n"
|
2004-04-13 01:09:37 +00:00
|
|
|
" -4 (use IPv4 query transport only)\n"
|
|
|
|
" -6 (use IPv6 query transport only)\n"
|
2008-10-13 21:18:56 +00:00
|
|
|
" -m (enable memory usage debugging)\n"
|
2000-05-02 23:23:12 +00:00
|
|
|
" d-opt is of the form +keyword[=value], where keyword is:\n"
|
|
|
|
" +[no]vc (TCP mode)\n"
|
2000-05-03 20:27:13 +00:00
|
|
|
" +[no]tcp (TCP mode, alternate syntax)\n"
|
|
|
|
" +time=### (Set query timeout) [5]\n"
|
|
|
|
" +tries=### (Set number of UDP attempts) [3]\n"
|
2001-09-20 17:15:03 +00:00
|
|
|
" +retry=### (Set number of UDP retries) [2]\n"
|
2000-05-03 20:27:13 +00:00
|
|
|
" +domain=### (Set default domainname)\n"
|
2000-05-08 22:51:08 +00:00
|
|
|
" +bufsize=### (Set EDNS0 Max UDP packet size)\n"
|
2001-11-28 02:46:21 +00:00
|
|
|
" +ndots=### (Set NDOTS value)\n"
|
2014-02-19 15:51:02 -08:00
|
|
|
" +subnet=addr (Set edns-client-subnet option)\n"
|
2013-05-01 14:53:16 +10:00
|
|
|
" +[no]edns[=###] (Set EDNS version) [0]\n"
|
2014-07-10 16:19:33 +10:00
|
|
|
" +ednsopt=###[:value] (Send specified EDNS option)\n"
|
|
|
|
" +noednsopt (Clear list of +ednsopt options)\n"
|
2000-05-03 20:27:13 +00:00
|
|
|
" +[no]search (Set whether to use searchlist)\n"
|
2005-08-25 00:17:46 +00:00
|
|
|
" +[no]showsearch (Search with intermediate results)\n"
|
2001-01-18 05:12:44 +00:00
|
|
|
" +[no]defname (Ditto)\n"
|
2002-08-29 07:45:04 +00:00
|
|
|
" +[no]recurse (Recursive mode)\n"
|
2000-09-13 00:03:28 +00:00
|
|
|
" +[no]ignore (Don't revert to TCP for TC responses.)"
|
|
|
|
"\n"
|
2000-09-28 23:02:28 +00:00
|
|
|
" +[no]fail (Don't try next server on SERVFAIL)\n"
|
2000-10-18 22:11:20 +00:00
|
|
|
" +[no]besteffort (Try to parse even illegal messages)\n"
|
2004-06-23 04:07:29 +00:00
|
|
|
" +[no]aaonly (Set AA flag in query (+[no]aaflag))\n"
|
2000-07-12 17:44:03 +00:00
|
|
|
" +[no]adflag (Set AD flag in query)\n"
|
|
|
|
" +[no]cdflag (Set CD flag in query)\n"
|
2002-05-22 04:58:30 +00:00
|
|
|
" +[no]cl (Control display of class in records)\n"
|
2000-09-29 23:42:15 +00:00
|
|
|
" +[no]cmd (Control display of command line)\n"
|
2000-05-02 23:23:12 +00:00
|
|
|
" +[no]comments (Control display of comment lines)\n"
|
2011-03-05 19:39:07 +00:00
|
|
|
" +[no]rrcomments (Control display of per-record "
|
|
|
|
"comments)\n"
|
2013-08-12 15:37:51 +10:00
|
|
|
" +[no]crypto (Control display of cryptographic "
|
|
|
|
"fields in records)\n"
|
2000-05-02 23:23:12 +00:00
|
|
|
" +[no]question (Control display of question)\n"
|
|
|
|
" +[no]answer (Control display of answer)\n"
|
2000-05-03 23:07:30 +00:00
|
|
|
" +[no]authority (Control display of authority)\n"
|
2000-05-02 23:23:12 +00:00
|
|
|
" +[no]additional (Control display of additional)\n"
|
2001-09-11 00:58:15 +00:00
|
|
|
" +[no]stats (Control display of statistics)\n"
|
2000-05-04 21:40:47 +00:00
|
|
|
" +[no]short (Disable everything except short\n"
|
|
|
|
" form of answer)\n"
|
2002-05-22 04:58:30 +00:00
|
|
|
" +[no]ttlid (Control display of ttls in records)\n"
|
2014-04-29 16:58:36 -07:00
|
|
|
" +[no]ttlunits (Display TTLs in human-readable units)\n"
|
2000-07-12 17:44:03 +00:00
|
|
|
" +[no]all (Set or clear all display flags)\n"
|
2001-11-28 02:46:21 +00:00
|
|
|
" +[no]qr (Print question before sending)\n"
|
2001-03-14 18:08:17 +00:00
|
|
|
" +[no]nssearch (Search all authoritative nameservers)\n"
|
2000-05-04 21:40:47 +00:00
|
|
|
" +[no]identify (ID responders in short answers)\n"
|
2011-11-04 14:19:17 +00:00
|
|
|
" +[no]trace (Trace delegation down from root [+dnssec])\n"
|
2000-11-13 21:34:03 +00:00
|
|
|
" +[no]dnssec (Request DNSSEC records)\n"
|
2014-02-20 14:56:20 +11:00
|
|
|
" +[no]expire (Request time to expire)\n"
|
2008-04-03 02:01:08 +00:00
|
|
|
" +[no]nsid (Request Name Server ID)\n"
|
2014-02-19 12:53:42 +11:00
|
|
|
#ifdef ISC_PLATFORM_USESIT
|
|
|
|
" +[no]sit (Request a Source Identity Token)\n"
|
|
|
|
#endif
|
2004-04-13 02:39:35 +00:00
|
|
|
#ifdef DIG_SIGCHASE
|
|
|
|
" +[no]sigchase (Chase DNSSEC signatures)\n"
|
|
|
|
" +trusted-key=#### (Trusted Key when chasing DNSSEC sigs)\n"
|
|
|
|
#if DIG_SIGCHASE_TD
|
|
|
|
" +[no]topdown (Do DNSSEC validation top down mode)\n"
|
|
|
|
#endif
|
|
|
|
#endif
|
2011-03-05 19:39:07 +00:00
|
|
|
" +[no]split=## (Split hex/base64 fields into chunks)\n"
|
2001-03-28 02:42:56 +00:00
|
|
|
" +[no]multiline (Print records in an expanded format)\n"
|
2010-03-04 05:18:04 +00:00
|
|
|
" +[no]onesoa (AXFR prints only one soa record)\n"
|
2013-11-07 10:50:01 +11:00
|
|
|
" +[no]keepopen (Keep the TCP socket open between queries)\n"
|
2014-07-15 23:27:14 +10:00
|
|
|
" +[no]dscp[=###] (Set the DSCP value to ### [0..63])\n"
|
2000-05-12 18:45:38 +00:00
|
|
|
" global d-opts and servers (before host name) affect all queries.\n"
|
2001-09-13 01:42:21 +00:00
|
|
|
" local d-opts and servers (after host name) affect only that lookup.\n"
|
|
|
|
" -h (print help and exit)\n"
|
|
|
|
" -v (print version and exit)\n",
|
2001-05-08 15:56:01 +00:00
|
|
|
stdout);
|
2000-08-01 01:33:37 +00:00
|
|
|
}
|
2000-04-20 19:09:11 +00:00
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*%
|
2000-07-18 18:51:40 +00:00
|
|
|
* Callback from dighost.c to print the received message.
|
|
|
|
*/
|
2000-05-02 23:23:12 +00:00
|
|
|
void
|
2001-01-24 19:28:34 +00:00
|
|
|
received(int bytes, isc_sockaddr_t *from, dig_query_t *query) {
|
2000-05-02 23:23:12 +00:00
|
|
|
isc_uint64_t diff;
|
|
|
|
time_t tnow;
|
2012-11-29 09:07:28 -08:00
|
|
|
struct tm tmnow;
|
|
|
|
char time_str[100];
|
2001-01-24 19:28:34 +00:00
|
|
|
char fromtext[ISC_SOCKADDR_FORMATSIZE];
|
|
|
|
|
|
|
|
isc_sockaddr_format(from, fromtext, sizeof(fromtext));
|
2000-05-02 23:23:12 +00:00
|
|
|
|
2001-07-18 21:03:54 +00:00
|
|
|
if (query->lookup->stats && !short_form) {
|
2014-07-31 07:39:59 +10:00
|
|
|
diff = isc_time_microdiff(&query->time_recv, &query->time_sent);
|
2013-03-04 12:09:28 -08:00
|
|
|
if (use_usec)
|
|
|
|
printf(";; Query time: %ld usec\n", (long) diff);
|
|
|
|
else
|
|
|
|
printf(";; Query time: %ld msec\n", (long) diff / 1000);
|
2001-01-24 19:28:34 +00:00
|
|
|
printf(";; SERVER: %s(%s)\n", fromtext, query->servname);
|
2000-07-05 19:31:26 +00:00
|
|
|
time(&tnow);
|
2012-11-29 09:07:28 -08:00
|
|
|
tmnow = *localtime(&tnow);
|
|
|
|
if (strftime(time_str, sizeof(time_str),
|
2013-03-06 15:34:10 +11:00
|
|
|
"%a %b %d %H:%M:%S %Z %Y", &tmnow) > 0U)
|
2012-11-29 09:07:28 -08:00
|
|
|
printf(";; WHEN: %s\n", time_str);
|
2000-07-20 19:41:44 +00:00
|
|
|
if (query->lookup->doing_xfr) {
|
2004-10-21 01:44:24 +00:00
|
|
|
printf(";; XFR size: %u records (messages %u, "
|
|
|
|
"bytes %" ISC_PRINT_QUADFORMAT "u)\n",
|
|
|
|
query->rr_count, query->msg_count,
|
|
|
|
query->byte_count);
|
2000-07-20 19:41:44 +00:00
|
|
|
} else {
|
2004-10-21 01:44:24 +00:00
|
|
|
printf(";; MSG SIZE rcvd: %u\n", bytes);
|
2000-07-20 19:41:44 +00:00
|
|
|
}
|
2000-06-06 18:49:06 +00:00
|
|
|
if (key != NULL) {
|
2000-06-07 00:13:57 +00:00
|
|
|
if (!validated)
|
2000-07-05 19:31:26 +00:00
|
|
|
puts(";; WARNING -- Some TSIG could not "
|
|
|
|
"be validated");
|
2000-06-06 18:49:06 +00:00
|
|
|
}
|
|
|
|
if ((key == NULL) && (keysecret[0] != 0)) {
|
2000-07-05 19:31:26 +00:00
|
|
|
puts(";; WARNING -- TSIG key was not used.");
|
2000-06-06 00:43:17 +00:00
|
|
|
}
|
2000-07-05 19:31:26 +00:00
|
|
|
puts("");
|
2000-05-06 01:16:07 +00:00
|
|
|
} else if (query->lookup->identify && !short_form) {
|
2014-07-31 07:39:59 +10:00
|
|
|
diff = isc_time_microdiff(&query->time_recv, &query->time_sent);
|
2013-03-04 12:09:28 -08:00
|
|
|
if (use_usec)
|
|
|
|
printf(";; Received %" ISC_PRINT_QUADFORMAT "u bytes "
|
|
|
|
"from %s(%s) in %ld us\n\n",
|
|
|
|
query->lookup->doing_xfr
|
2013-03-04 23:46:20 +00:00
|
|
|
? query->byte_count
|
|
|
|
: (isc_uint64_t)bytes,
|
2013-03-04 12:09:28 -08:00
|
|
|
fromtext, query->userarg, (long) diff);
|
|
|
|
else
|
|
|
|
printf(";; Received %" ISC_PRINT_QUADFORMAT "u bytes "
|
|
|
|
"from %s(%s) in %ld ms\n\n",
|
|
|
|
query->lookup->doing_xfr
|
2013-03-04 23:46:20 +00:00
|
|
|
? query->byte_count
|
|
|
|
: (isc_uint64_t)bytes,
|
2013-03-04 12:09:28 -08:00
|
|
|
fromtext, query->userarg, (long) diff / 1000);
|
2000-05-02 23:23:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-18 18:51:40 +00:00
|
|
|
/*
|
|
|
|
* Callback from dighost.c to print that it is trying a server.
|
|
|
|
* Not used in dig.
|
2000-08-01 00:53:20 +00:00
|
|
|
* XXX print_trying
|
2000-07-18 18:51:40 +00:00
|
|
|
*/
|
2000-05-02 23:23:12 +00:00
|
|
|
void
|
2001-07-27 05:26:38 +00:00
|
|
|
trying(char *frm, dig_lookup_t *lookup) {
|
2000-07-05 19:31:26 +00:00
|
|
|
UNUSED(frm);
|
|
|
|
UNUSED(lookup);
|
2000-05-08 22:51:08 +00:00
|
|
|
}
|
2000-05-02 23:23:12 +00:00
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*%
|
2000-07-18 18:51:40 +00:00
|
|
|
* Internal print routine used to print short form replies.
|
|
|
|
*/
|
2000-05-24 19:49:51 +00:00
|
|
|
static isc_result_t
|
2000-05-24 19:27:01 +00:00
|
|
|
say_message(dns_rdata_t *rdata, dig_query_t *query, isc_buffer_t *buf) {
|
2000-05-04 21:40:47 +00:00
|
|
|
isc_result_t result;
|
2000-05-06 01:16:07 +00:00
|
|
|
isc_uint64_t diff;
|
2000-05-24 19:27:01 +00:00
|
|
|
char store[sizeof("12345678901234567890")];
|
2013-08-12 15:37:51 +10:00
|
|
|
unsigned int styleflags = 0;
|
2000-05-04 21:40:47 +00:00
|
|
|
|
2000-05-24 19:27:01 +00:00
|
|
|
if (query->lookup->trace || query->lookup->ns_search_only) {
|
|
|
|
result = dns_rdatatype_totext(rdata->type, buf);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
ADD_STRING(buf, " ");
|
2000-05-06 01:16:07 +00:00
|
|
|
}
|
2013-08-12 15:37:51 +10:00
|
|
|
|
|
|
|
if (nocrypto)
|
|
|
|
styleflags |= DNS_STYLEFLAG_NOCRYPTO;
|
|
|
|
result = dns_rdata_tofmttext(rdata, NULL, styleflags, 0, 60, " ", buf);
|
2010-05-12 01:31:37 +00:00
|
|
|
if (result == ISC_R_NOSPACE)
|
|
|
|
return (result);
|
2000-05-24 19:27:01 +00:00
|
|
|
check_result(result, "dns_rdata_totext");
|
2000-05-04 21:40:47 +00:00
|
|
|
if (query->lookup->identify) {
|
2014-07-31 07:39:59 +10:00
|
|
|
diff = isc_time_microdiff(&query->time_recv, &query->time_sent);
|
2000-05-24 19:27:01 +00:00
|
|
|
ADD_STRING(buf, " from server ");
|
|
|
|
ADD_STRING(buf, query->servname);
|
2013-03-04 12:09:28 -08:00
|
|
|
if (use_usec)
|
|
|
|
snprintf(store, 19, " in %ld us.", (long) diff);
|
|
|
|
else
|
|
|
|
snprintf(store, 19, " in %ld ms.", (long) diff / 1000);
|
2000-05-24 19:27:01 +00:00
|
|
|
ADD_STRING(buf, store);
|
2000-05-04 21:40:47 +00:00
|
|
|
}
|
2000-07-05 19:31:26 +00:00
|
|
|
ADD_STRING(buf, "\n");
|
2000-05-24 19:27:01 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
2000-05-04 21:40:47 +00:00
|
|
|
}
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*%
|
2000-07-18 18:51:40 +00:00
|
|
|
* short_form message print handler. Calls above say_message()
|
|
|
|
*/
|
2000-05-24 19:49:51 +00:00
|
|
|
static isc_result_t
|
2000-05-24 19:27:01 +00:00
|
|
|
short_answer(dns_message_t *msg, dns_messagetextflag_t flags,
|
|
|
|
isc_buffer_t *buf, dig_query_t *query)
|
2000-04-26 18:34:17 +00:00
|
|
|
{
|
2000-05-25 00:01:30 +00:00
|
|
|
dns_name_t *name;
|
2000-04-26 18:34:17 +00:00
|
|
|
dns_rdataset_t *rdataset;
|
2000-05-04 21:40:47 +00:00
|
|
|
isc_result_t result, loopresult;
|
2000-04-26 18:34:17 +00:00
|
|
|
dns_name_t empty_name;
|
2000-10-25 04:26:57 +00:00
|
|
|
dns_rdata_t rdata = DNS_RDATA_INIT;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-07-05 19:31:26 +00:00
|
|
|
UNUSED(flags);
|
2000-05-24 19:49:51 +00:00
|
|
|
|
2000-04-26 18:34:17 +00:00
|
|
|
dns_name_init(&empty_name, NULL);
|
2000-05-24 19:27:01 +00:00
|
|
|
result = dns_message_firstname(msg, DNS_SECTION_ANSWER);
|
2000-04-26 18:34:17 +00:00
|
|
|
if (result == ISC_R_NOMORE)
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
else if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
name = NULL;
|
2000-05-24 19:27:01 +00:00
|
|
|
dns_message_currentname(msg, DNS_SECTION_ANSWER, &name);
|
2000-04-26 18:34:17 +00:00
|
|
|
|
|
|
|
for (rdataset = ISC_LIST_HEAD(name->list);
|
|
|
|
rdataset != NULL;
|
|
|
|
rdataset = ISC_LIST_NEXT(rdataset, link)) {
|
2000-05-24 19:27:01 +00:00
|
|
|
loopresult = dns_rdataset_first(rdataset);
|
|
|
|
while (loopresult == ISC_R_SUCCESS) {
|
|
|
|
dns_rdataset_current(rdataset, &rdata);
|
|
|
|
result = say_message(&rdata, query,
|
|
|
|
buf);
|
2010-05-12 01:31:37 +00:00
|
|
|
if (result == ISC_R_NOSPACE)
|
|
|
|
return (result);
|
2000-07-05 19:31:26 +00:00
|
|
|
check_result(result, "say_message");
|
|
|
|
loopresult = dns_rdataset_next(rdataset);
|
2000-10-31 03:22:05 +00:00
|
|
|
dns_rdata_reset(&rdata);
|
2000-05-04 21:40:47 +00:00
|
|
|
}
|
2000-04-26 18:34:17 +00:00
|
|
|
}
|
2000-05-24 19:27:01 +00:00
|
|
|
result = dns_message_nextname(msg, DNS_SECTION_ANSWER);
|
2000-04-26 18:34:17 +00:00
|
|
|
if (result == ISC_R_NOMORE)
|
|
|
|
break;
|
|
|
|
else if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
2000-04-20 19:09:11 +00:00
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-04-26 18:34:17 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
2000-04-20 19:09:11 +00:00
|
|
|
}
|
2004-04-13 02:39:35 +00:00
|
|
|
#ifdef DIG_SIGCHASE
|
|
|
|
isc_result_t
|
|
|
|
printrdataset(dns_name_t *owner_name, dns_rdataset_t *rdataset,
|
|
|
|
isc_buffer_t *target)
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
|
|
|
dns_master_style_t *style = NULL;
|
|
|
|
unsigned int styleflags = 0;
|
|
|
|
|
|
|
|
if (rdataset == NULL || owner_name == NULL || target == NULL)
|
|
|
|
return(ISC_FALSE);
|
|
|
|
|
|
|
|
styleflags |= DNS_STYLEFLAG_REL_OWNER;
|
2014-04-29 16:58:36 -07:00
|
|
|
if (ttlunits)
|
|
|
|
styleflags |= DNS_STYLEFLAG_TTL_UNITS;
|
2004-04-13 02:39:35 +00:00
|
|
|
if (nottl)
|
|
|
|
styleflags |= DNS_STYLEFLAG_NO_TTL;
|
|
|
|
if (noclass)
|
|
|
|
styleflags |= DNS_STYLEFLAG_NO_CLASS;
|
2011-03-05 19:39:07 +00:00
|
|
|
if (rrcomments)
|
|
|
|
styleflags |= DNS_STYLEFLAG_RRCOMMENT;
|
2013-08-12 15:37:51 +10:00
|
|
|
if (nocrypto)
|
|
|
|
styleflags |= DNS_STYLEFLAG_NOCRYPTO;
|
2004-04-13 02:39:35 +00:00
|
|
|
if (multiline) {
|
|
|
|
styleflags |= DNS_STYLEFLAG_OMIT_OWNER;
|
|
|
|
styleflags |= DNS_STYLEFLAG_OMIT_CLASS;
|
|
|
|
styleflags |= DNS_STYLEFLAG_REL_DATA;
|
|
|
|
styleflags |= DNS_STYLEFLAG_OMIT_TTL;
|
|
|
|
styleflags |= DNS_STYLEFLAG_TTL;
|
|
|
|
styleflags |= DNS_STYLEFLAG_MULTILINE;
|
|
|
|
styleflags |= DNS_STYLEFLAG_COMMENT;
|
2011-03-05 19:39:07 +00:00
|
|
|
styleflags |= DNS_STYLEFLAG_RRCOMMENT;
|
2004-04-13 02:39:35 +00:00
|
|
|
}
|
2011-03-05 19:39:07 +00:00
|
|
|
|
2004-04-13 02:39:35 +00:00
|
|
|
if (multiline || (nottl && noclass))
|
2011-03-05 19:39:07 +00:00
|
|
|
result = dns_master_stylecreate2(&style, styleflags,
|
|
|
|
24, 24, 24, 32, 80, 8,
|
|
|
|
splitwidth, mctx);
|
2004-04-13 02:39:35 +00:00
|
|
|
else if (nottl || noclass)
|
2011-03-05 19:39:07 +00:00
|
|
|
result = dns_master_stylecreate2(&style, styleflags,
|
|
|
|
24, 24, 32, 40, 80, 8,
|
|
|
|
splitwidth, mctx);
|
2008-02-05 23:47:08 +00:00
|
|
|
else
|
2011-03-05 19:39:07 +00:00
|
|
|
result = dns_master_stylecreate2(&style, styleflags,
|
|
|
|
24, 32, 40, 48, 80, 8,
|
|
|
|
splitwidth, mctx);
|
2004-04-13 02:39:35 +00:00
|
|
|
check_result(result, "dns_master_stylecreate");
|
|
|
|
|
|
|
|
result = dns_master_rdatasettotext(owner_name, rdataset, style, target);
|
|
|
|
|
|
|
|
if (style != NULL)
|
|
|
|
dns_master_styledestroy(&style, mctx);
|
2008-02-05 23:47:08 +00:00
|
|
|
|
2004-04-13 02:39:35 +00:00
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
#endif
|
2000-04-20 19:09:11 +00:00
|
|
|
|
2000-07-18 18:51:40 +00:00
|
|
|
/*
|
|
|
|
* Callback from dighost.c to print the reply from a server
|
|
|
|
*/
|
2000-04-26 18:34:17 +00:00
|
|
|
isc_result_t
|
2000-04-28 21:41:19 +00:00
|
|
|
printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
|
2000-04-26 18:34:17 +00:00
|
|
|
isc_result_t result;
|
2000-05-24 19:27:01 +00:00
|
|
|
dns_messagetextflag_t flags;
|
2000-05-25 17:24:57 +00:00
|
|
|
isc_buffer_t *buf = NULL;
|
2000-06-23 16:53:53 +00:00
|
|
|
unsigned int len = OUTPUTBUF;
|
2002-05-22 04:58:30 +00:00
|
|
|
dns_master_style_t *style = NULL;
|
|
|
|
unsigned int styleflags = 0;
|
|
|
|
|
|
|
|
styleflags |= DNS_STYLEFLAG_REL_OWNER;
|
2011-03-05 19:39:07 +00:00
|
|
|
if (query->lookup->comments)
|
|
|
|
styleflags |= DNS_STYLEFLAG_COMMENT;
|
|
|
|
if (rrcomments)
|
|
|
|
styleflags |= DNS_STYLEFLAG_RRCOMMENT;
|
2014-04-29 16:58:36 -07:00
|
|
|
if (ttlunits)
|
|
|
|
styleflags |= DNS_STYLEFLAG_TTL_UNITS;
|
2002-05-22 04:58:30 +00:00
|
|
|
if (nottl)
|
|
|
|
styleflags |= DNS_STYLEFLAG_NO_TTL;
|
|
|
|
if (noclass)
|
|
|
|
styleflags |= DNS_STYLEFLAG_NO_CLASS;
|
2013-08-12 15:37:51 +10:00
|
|
|
if (nocrypto)
|
|
|
|
styleflags |= DNS_STYLEFLAG_NOCRYPTO;
|
2002-05-22 04:58:30 +00:00
|
|
|
if (multiline) {
|
|
|
|
styleflags |= DNS_STYLEFLAG_OMIT_OWNER;
|
|
|
|
styleflags |= DNS_STYLEFLAG_OMIT_CLASS;
|
|
|
|
styleflags |= DNS_STYLEFLAG_REL_DATA;
|
|
|
|
styleflags |= DNS_STYLEFLAG_OMIT_TTL;
|
|
|
|
styleflags |= DNS_STYLEFLAG_TTL;
|
|
|
|
styleflags |= DNS_STYLEFLAG_MULTILINE;
|
2011-03-05 19:39:07 +00:00
|
|
|
styleflags |= DNS_STYLEFLAG_RRCOMMENT;
|
2002-05-22 04:58:30 +00:00
|
|
|
}
|
|
|
|
if (multiline || (nottl && noclass))
|
2011-03-05 19:39:07 +00:00
|
|
|
result = dns_master_stylecreate2(&style, styleflags,
|
2011-03-05 23:52:31 +00:00
|
|
|
24, 24, 24, 32, 80, 8,
|
2011-03-05 19:39:07 +00:00
|
|
|
splitwidth, mctx);
|
2002-05-22 04:58:30 +00:00
|
|
|
else if (nottl || noclass)
|
2011-03-05 19:39:07 +00:00
|
|
|
result = dns_master_stylecreate2(&style, styleflags,
|
|
|
|
24, 24, 32, 40, 80, 8,
|
|
|
|
splitwidth, mctx);
|
2008-02-05 23:47:08 +00:00
|
|
|
else
|
2011-03-05 19:39:07 +00:00
|
|
|
result = dns_master_stylecreate2(&style, styleflags,
|
|
|
|
24, 32, 40, 48, 80, 8,
|
|
|
|
splitwidth, mctx);
|
2002-05-22 04:58:30 +00:00
|
|
|
check_result(result, "dns_master_stylecreate");
|
2000-04-26 18:34:17 +00:00
|
|
|
|
2000-09-29 23:42:15 +00:00
|
|
|
if (query->lookup->cmdline[0] != 0) {
|
2001-07-18 21:03:54 +00:00
|
|
|
if (!short_form)
|
|
|
|
fputs(query->lookup->cmdline, stdout);
|
2000-09-29 23:42:15 +00:00
|
|
|
query->lookup->cmdline[0]=0;
|
|
|
|
}
|
2000-10-17 00:35:18 +00:00
|
|
|
debug("printmessage(%s %s %s)", headers ? "headers" : "noheaders",
|
|
|
|
query->lookup->comments ? "comments" : "nocomments",
|
|
|
|
short_form ? "short_form" : "long_form");
|
2000-05-24 19:27:01 +00:00
|
|
|
|
|
|
|
flags = 0;
|
|
|
|
if (!headers) {
|
|
|
|
flags |= DNS_MESSAGETEXTFLAG_NOHEADERS;
|
|
|
|
flags |= DNS_MESSAGETEXTFLAG_NOCOMMENTS;
|
|
|
|
}
|
2010-03-04 05:18:04 +00:00
|
|
|
if (onesoa && query->lookup->rdtype == dns_rdatatype_axfr)
|
|
|
|
flags |= (query->msg_count == 0) ? DNS_MESSAGETEXTFLAG_ONESOA :
|
|
|
|
DNS_MESSAGETEXTFLAG_OMITSOA;
|
2000-05-24 19:27:01 +00:00
|
|
|
if (!query->lookup->comments)
|
|
|
|
flags |= DNS_MESSAGETEXTFLAG_NOCOMMENTS;
|
|
|
|
|
2000-06-23 16:53:53 +00:00
|
|
|
result = isc_buffer_allocate(mctx, &buf, len);
|
2000-07-05 19:31:26 +00:00
|
|
|
check_result(result, "isc_buffer_allocate");
|
2000-05-24 19:27:01 +00:00
|
|
|
|
|
|
|
if (query->lookup->comments && !short_form) {
|
2000-10-17 00:35:18 +00:00
|
|
|
if (query->lookup->cmdline[0] != 0)
|
2000-10-19 22:49:34 +00:00
|
|
|
printf("; %s\n", query->lookup->cmdline);
|
2000-10-17 00:35:18 +00:00
|
|
|
if (msg == query->lookup->sendmsg)
|
|
|
|
printf(";; Sending:\n");
|
|
|
|
else
|
|
|
|
printf(";; Got answer:\n");
|
2000-10-19 22:49:34 +00:00
|
|
|
|
2000-05-24 19:27:01 +00:00
|
|
|
if (headers) {
|
2000-05-02 23:23:12 +00:00
|
|
|
printf(";; ->>HEADER<<- opcode: %s, status: %s, "
|
|
|
|
"id: %u\n",
|
2009-05-06 10:16:32 +00:00
|
|
|
opcodetext[msg->opcode],
|
|
|
|
rcode_totext(msg->rcode),
|
2000-05-02 23:23:12 +00:00
|
|
|
msg->id);
|
2001-07-27 06:45:20 +00:00
|
|
|
printf(";; flags:");
|
|
|
|
if ((msg->flags & DNS_MESSAGEFLAG_QR) != 0)
|
|
|
|
printf(" qr");
|
|
|
|
if ((msg->flags & DNS_MESSAGEFLAG_AA) != 0)
|
|
|
|
printf(" aa");
|
|
|
|
if ((msg->flags & DNS_MESSAGEFLAG_TC) != 0)
|
|
|
|
printf(" tc");
|
|
|
|
if ((msg->flags & DNS_MESSAGEFLAG_RD) != 0)
|
|
|
|
printf(" rd");
|
|
|
|
if ((msg->flags & DNS_MESSAGEFLAG_RA) != 0)
|
|
|
|
printf(" ra");
|
|
|
|
if ((msg->flags & DNS_MESSAGEFLAG_AD) != 0)
|
|
|
|
printf(" ad");
|
|
|
|
if ((msg->flags & DNS_MESSAGEFLAG_CD) != 0)
|
|
|
|
printf(" cd");
|
2010-05-13 00:40:46 +00:00
|
|
|
if ((msg->flags & 0x0040U) != 0)
|
|
|
|
printf("; MBZ: 0x4");
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-05-17 18:36:31 +00:00
|
|
|
printf("; QUERY: %u, ANSWER: %u, "
|
|
|
|
"AUTHORITY: %u, ADDITIONAL: %u\n",
|
|
|
|
msg->counts[DNS_SECTION_QUESTION],
|
|
|
|
msg->counts[DNS_SECTION_ANSWER],
|
|
|
|
msg->counts[DNS_SECTION_AUTHORITY],
|
|
|
|
msg->counts[DNS_SECTION_ADDITIONAL]);
|
2005-08-25 00:40:50 +00:00
|
|
|
|
2006-01-06 00:13:30 +00:00
|
|
|
if (msg != query->lookup->sendmsg &&
|
|
|
|
(msg->flags & DNS_MESSAGEFLAG_RD) != 0 &&
|
2005-08-25 00:40:50 +00:00
|
|
|
(msg->flags & DNS_MESSAGEFLAG_RA) == 0)
|
2006-05-15 06:10:58 +00:00
|
|
|
printf(";; WARNING: recursion requested "
|
2005-08-25 00:40:50 +00:00
|
|
|
"but not available\n");
|
2000-04-26 18:34:17 +00:00
|
|
|
}
|
2013-05-01 14:53:16 +10:00
|
|
|
if (msg != query->lookup->sendmsg &&
|
|
|
|
query->lookup->edns != -1 && msg->opt == NULL &&
|
|
|
|
(msg->rcode == dns_rcode_formerr ||
|
|
|
|
msg->rcode == dns_rcode_notimp))
|
|
|
|
printf("\n;; WARNING: EDNS query returned status "
|
2013-11-14 22:38:29 +11:00
|
|
|
"%s - retry with '%s+noedns'\n",
|
|
|
|
rcode_totext(msg->rcode),
|
|
|
|
query->lookup->dnssec ? "+nodnssec ": "");
|
2005-07-04 03:03:21 +00:00
|
|
|
if (msg != query->lookup->sendmsg && extrabytes != 0U)
|
2013-06-19 15:21:20 -07:00
|
|
|
printf(";; WARNING: Message has %u extra byte%s at "
|
2005-07-04 03:03:21 +00:00
|
|
|
"end\n", extrabytes, extrabytes != 0 ? "s" : "");
|
2000-04-19 23:23:31 +00:00
|
|
|
}
|
2000-05-24 19:27:01 +00:00
|
|
|
|
2001-02-15 23:44:08 +00:00
|
|
|
repopulate_buffer:
|
2001-02-13 23:12:17 +00:00
|
|
|
|
2004-04-13 02:39:35 +00:00
|
|
|
if (query->lookup->comments && headers && !short_form) {
|
2001-02-13 23:12:17 +00:00
|
|
|
result = dns_message_pseudosectiontotext(msg,
|
|
|
|
DNS_PSEUDOSECTION_OPT,
|
2001-03-28 02:42:56 +00:00
|
|
|
style, flags, buf);
|
2001-02-14 01:46:03 +00:00
|
|
|
if (result == ISC_R_NOSPACE) {
|
2001-02-15 23:44:08 +00:00
|
|
|
buftoosmall:
|
2001-02-14 01:46:03 +00:00
|
|
|
len += OUTPUTBUF;
|
|
|
|
isc_buffer_free(&buf);
|
|
|
|
result = isc_buffer_allocate(mctx, &buf, len);
|
|
|
|
if (result == ISC_R_SUCCESS)
|
2001-02-15 23:44:08 +00:00
|
|
|
goto repopulate_buffer;
|
|
|
|
else
|
2002-05-22 04:58:30 +00:00
|
|
|
goto cleanup;
|
2001-02-14 01:46:03 +00:00
|
|
|
}
|
2001-02-13 23:12:17 +00:00
|
|
|
check_result(result,
|
|
|
|
"dns_message_pseudosectiontotext");
|
|
|
|
}
|
|
|
|
|
2000-05-24 19:27:01 +00:00
|
|
|
if (query->lookup->section_question && headers) {
|
|
|
|
if (!short_form) {
|
|
|
|
result = dns_message_sectiontotext(msg,
|
|
|
|
DNS_SECTION_QUESTION,
|
2001-03-28 02:42:56 +00:00
|
|
|
style, flags, buf);
|
2001-02-17 01:05:30 +00:00
|
|
|
if (result == ISC_R_NOSPACE)
|
2001-02-15 23:44:08 +00:00
|
|
|
goto buftoosmall;
|
2000-05-24 19:27:01 +00:00
|
|
|
check_result(result, "dns_message_sectiontotext");
|
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
}
|
2000-05-24 19:27:01 +00:00
|
|
|
if (query->lookup->section_answer) {
|
|
|
|
if (!short_form) {
|
|
|
|
result = dns_message_sectiontotext(msg,
|
|
|
|
DNS_SECTION_ANSWER,
|
2001-03-28 02:42:56 +00:00
|
|
|
style, flags, buf);
|
2001-02-17 01:05:30 +00:00
|
|
|
if (result == ISC_R_NOSPACE)
|
2001-02-15 23:44:08 +00:00
|
|
|
goto buftoosmall;
|
2000-05-24 19:27:01 +00:00
|
|
|
check_result(result, "dns_message_sectiontotext");
|
2000-07-05 19:31:26 +00:00
|
|
|
} else {
|
2000-05-24 19:27:01 +00:00
|
|
|
result = short_answer(msg, flags, buf, query);
|
2001-02-17 01:05:30 +00:00
|
|
|
if (result == ISC_R_NOSPACE)
|
2001-02-15 23:44:08 +00:00
|
|
|
goto buftoosmall;
|
2000-07-05 19:31:26 +00:00
|
|
|
check_result(result, "short_answer");
|
2000-05-24 19:27:01 +00:00
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
}
|
2000-05-24 19:27:01 +00:00
|
|
|
if (query->lookup->section_authority) {
|
|
|
|
if (!short_form) {
|
|
|
|
result = dns_message_sectiontotext(msg,
|
|
|
|
DNS_SECTION_AUTHORITY,
|
2001-03-28 02:42:56 +00:00
|
|
|
style, flags, buf);
|
2001-02-17 01:05:30 +00:00
|
|
|
if (result == ISC_R_NOSPACE)
|
2001-02-15 23:44:08 +00:00
|
|
|
goto buftoosmall;
|
2000-05-24 19:27:01 +00:00
|
|
|
check_result(result, "dns_message_sectiontotext");
|
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
}
|
2000-05-24 19:27:01 +00:00
|
|
|
if (query->lookup->section_additional) {
|
|
|
|
if (!short_form) {
|
|
|
|
result = dns_message_sectiontotext(msg,
|
|
|
|
DNS_SECTION_ADDITIONAL,
|
2001-03-28 02:42:56 +00:00
|
|
|
style, flags, buf);
|
2001-02-17 01:05:30 +00:00
|
|
|
if (result == ISC_R_NOSPACE)
|
2001-02-15 23:44:08 +00:00
|
|
|
goto buftoosmall;
|
2000-05-24 19:27:01 +00:00
|
|
|
check_result(result, "dns_message_sectiontotext");
|
2000-07-05 19:31:26 +00:00
|
|
|
/*
|
|
|
|
* Only print the signature on the first record.
|
|
|
|
*/
|
2000-06-06 00:43:17 +00:00
|
|
|
if (headers) {
|
|
|
|
result = dns_message_pseudosectiontotext(
|
|
|
|
msg,
|
|
|
|
DNS_PSEUDOSECTION_TSIG,
|
2001-03-28 02:42:56 +00:00
|
|
|
style, flags, buf);
|
2001-02-17 01:05:30 +00:00
|
|
|
if (result == ISC_R_NOSPACE)
|
2001-02-15 23:44:08 +00:00
|
|
|
goto buftoosmall;
|
2000-06-06 00:43:17 +00:00
|
|
|
check_result(result,
|
|
|
|
"dns_message_pseudosectiontotext");
|
|
|
|
result = dns_message_pseudosectiontotext(
|
|
|
|
msg,
|
|
|
|
DNS_PSEUDOSECTION_SIG0,
|
2001-03-28 02:42:56 +00:00
|
|
|
style, flags, buf);
|
2001-02-17 01:05:30 +00:00
|
|
|
if (result == ISC_R_NOSPACE)
|
2001-02-15 23:44:08 +00:00
|
|
|
goto buftoosmall;
|
2000-06-06 00:43:17 +00:00
|
|
|
check_result(result,
|
|
|
|
"dns_message_pseudosectiontotext");
|
|
|
|
}
|
2000-05-24 19:27:01 +00:00
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
}
|
2005-07-04 03:03:21 +00:00
|
|
|
|
2000-05-06 01:16:07 +00:00
|
|
|
if (headers && query->lookup->comments && !short_form)
|
2000-04-26 18:34:17 +00:00
|
|
|
printf("\n");
|
2000-04-19 23:23:31 +00:00
|
|
|
|
2000-07-05 19:31:26 +00:00
|
|
|
printf("%.*s", (int)isc_buffer_usedlength(buf),
|
|
|
|
(char *)isc_buffer_base(buf));
|
2000-05-24 19:27:01 +00:00
|
|
|
isc_buffer_free(&buf);
|
2002-05-22 04:58:30 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (style != NULL)
|
|
|
|
dns_master_styledestroy(&style, mctx);
|
2000-04-26 18:34:17 +00:00
|
|
|
return (result);
|
|
|
|
}
|
2000-04-19 23:23:31 +00:00
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*%
|
2000-07-18 18:51:40 +00:00
|
|
|
* print the greeting message when the program first starts up.
|
|
|
|
*/
|
2000-05-08 22:51:08 +00:00
|
|
|
static void
|
2000-09-29 23:42:15 +00:00
|
|
|
printgreeting(int argc, char **argv, dig_lookup_t *lookup) {
|
|
|
|
int i;
|
2001-02-15 23:57:22 +00:00
|
|
|
int remaining;
|
2000-09-29 23:42:15 +00:00
|
|
|
static isc_boolean_t first = ISC_TRUE;
|
|
|
|
char append[MXNAME];
|
2000-05-08 22:51:08 +00:00
|
|
|
|
|
|
|
if (printcmd) {
|
2001-02-15 23:57:22 +00:00
|
|
|
lookup->cmdline[sizeof(lookup->cmdline) - 1] = 0;
|
2000-09-29 23:42:15 +00:00
|
|
|
snprintf(lookup->cmdline, sizeof(lookup->cmdline),
|
|
|
|
"%s; <<>> DiG " VERSION " <<>>",
|
|
|
|
first?"\n":"");
|
|
|
|
i = 1;
|
2000-05-08 22:51:08 +00:00
|
|
|
while (i < argc) {
|
2000-09-29 23:42:15 +00:00
|
|
|
snprintf(append, sizeof(append), " %s", argv[i++]);
|
2001-02-15 23:57:22 +00:00
|
|
|
remaining = sizeof(lookup->cmdline) -
|
|
|
|
strlen(lookup->cmdline) - 1;
|
|
|
|
strncat(lookup->cmdline, append, remaining);
|
2000-09-29 23:42:15 +00:00
|
|
|
}
|
2001-02-15 23:57:22 +00:00
|
|
|
remaining = sizeof(lookup->cmdline) -
|
|
|
|
strlen(lookup->cmdline) - 1;
|
|
|
|
strncat(lookup->cmdline, "\n", remaining);
|
2004-09-06 01:24:44 +00:00
|
|
|
if (first && addresscount != 0) {
|
|
|
|
snprintf(append, sizeof(append),
|
|
|
|
"; (%d server%s found)\n",
|
|
|
|
addresscount,
|
|
|
|
addresscount > 1 ? "s" : "");
|
|
|
|
remaining = sizeof(lookup->cmdline) -
|
|
|
|
strlen(lookup->cmdline) - 1;
|
2004-09-16 02:12:37 +00:00
|
|
|
strncat(lookup->cmdline, append, remaining);
|
2004-09-06 01:24:44 +00:00
|
|
|
}
|
2000-09-29 23:42:15 +00:00
|
|
|
if (first) {
|
2008-02-05 23:47:08 +00:00
|
|
|
snprintf(append, sizeof(append),
|
2008-10-28 03:32:59 +00:00
|
|
|
";; global options:%s%s\n",
|
2008-10-28 23:47:06 +00:00
|
|
|
short_form ? " +short" : "",
|
|
|
|
printcmd ? " +cmd" : "");
|
2000-09-29 23:42:15 +00:00
|
|
|
first = ISC_FALSE;
|
2001-02-15 23:57:22 +00:00
|
|
|
remaining = sizeof(lookup->cmdline) -
|
|
|
|
strlen(lookup->cmdline) - 1;
|
|
|
|
strncat(lookup->cmdline, append, remaining);
|
2000-05-08 22:51:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*%
|
2000-05-03 23:07:30 +00:00
|
|
|
* We're not using isc_commandline_parse() here since the command line
|
|
|
|
* syntax of dig is quite a bit different from that which can be described
|
2001-01-18 05:12:44 +00:00
|
|
|
* by that routine.
|
2000-08-01 00:53:20 +00:00
|
|
|
* XXX doc options
|
2000-05-03 23:07:30 +00:00
|
|
|
*/
|
2000-09-22 23:21:32 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
plus_option(char *option, isc_boolean_t is_batchfile,
|
|
|
|
dig_lookup_t *lookup)
|
|
|
|
{
|
2009-09-15 03:13:44 +00:00
|
|
|
isc_result_t result;
|
2000-09-22 23:21:32 +00:00
|
|
|
char option_store[256];
|
2014-04-18 09:52:12 +10:00
|
|
|
char *cmd, *value, *ptr, *code;
|
2009-09-15 03:13:44 +00:00
|
|
|
isc_uint32_t num;
|
2000-09-22 23:21:32 +00:00
|
|
|
isc_boolean_t state = ISC_TRUE;
|
2014-06-12 07:57:19 +10:00
|
|
|
#if defined(DIG_SIGCHASE) || defined(ISC_PLATFORM_USESIT)
|
2004-04-13 02:39:35 +00:00
|
|
|
size_t n;
|
|
|
|
#endif
|
2000-09-22 23:21:32 +00:00
|
|
|
|
|
|
|
strncpy(option_store, option, sizeof(option_store));
|
2000-10-19 22:49:34 +00:00
|
|
|
option_store[sizeof(option_store)-1]=0;
|
2000-09-25 16:14:20 +00:00
|
|
|
ptr = option_store;
|
2001-10-31 20:39:39 +00:00
|
|
|
cmd = next_token(&ptr,"=");
|
2000-09-22 23:21:32 +00:00
|
|
|
if (cmd == NULL) {
|
2004-04-13 02:39:35 +00:00
|
|
|
printf(";; Invalid option %s\n", option_store);
|
2000-09-22 23:21:32 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-10-31 20:39:39 +00:00
|
|
|
value = ptr;
|
2004-04-13 02:39:35 +00:00
|
|
|
if (strncasecmp(cmd, "no", 2)==0) {
|
2000-09-22 23:21:32 +00:00
|
|
|
cmd += 2;
|
|
|
|
state = ISC_FALSE;
|
|
|
|
}
|
2001-11-07 05:40:48 +00:00
|
|
|
|
|
|
|
#define FULLCHECK(A) \
|
|
|
|
do { \
|
|
|
|
size_t _l = strlen(cmd); \
|
|
|
|
if (_l >= sizeof(A) || strncasecmp(cmd, A, _l) != 0) \
|
|
|
|
goto invalid_option; \
|
|
|
|
} while (0)
|
|
|
|
#define FULLCHECK2(A, B) \
|
|
|
|
do { \
|
|
|
|
size_t _l = strlen(cmd); \
|
|
|
|
if ((_l >= sizeof(A) || strncasecmp(cmd, A, _l) != 0) && \
|
|
|
|
(_l >= sizeof(B) || strncasecmp(cmd, B, _l) != 0)) \
|
|
|
|
goto invalid_option; \
|
|
|
|
} while (0)
|
|
|
|
|
2000-10-17 00:35:18 +00:00
|
|
|
switch (cmd[0]) {
|
2000-09-22 23:21:32 +00:00
|
|
|
case 'a':
|
2000-10-17 00:35:18 +00:00
|
|
|
switch (cmd[1]) {
|
2004-06-23 04:07:29 +00:00
|
|
|
case 'a': /* aaonly / aaflag */
|
|
|
|
FULLCHECK2("aaonly", "aaflag");
|
2000-09-22 23:21:32 +00:00
|
|
|
lookup->aaonly = state;
|
|
|
|
break;
|
2008-02-05 23:47:08 +00:00
|
|
|
case 'd':
|
2000-10-17 00:35:18 +00:00
|
|
|
switch (cmd[2]) {
|
2000-09-22 23:21:32 +00:00
|
|
|
case 'd': /* additional */
|
2001-11-07 05:40:48 +00:00
|
|
|
FULLCHECK("additional");
|
2000-09-22 23:21:32 +00:00
|
|
|
lookup->section_additional = state;
|
|
|
|
break;
|
|
|
|
case 'f': /* adflag */
|
2009-09-23 06:21:36 +00:00
|
|
|
case '\0': /* +ad is a synonym for +adflag */
|
2001-11-07 05:40:48 +00:00
|
|
|
FULLCHECK("adflag");
|
2000-09-25 23:10:00 +00:00
|
|
|
lookup->adflag = state;
|
2000-09-22 23:21:32 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto invalid_option;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'l': /* all */
|
2001-11-07 05:40:48 +00:00
|
|
|
FULLCHECK("all");
|
2000-09-22 23:21:32 +00:00
|
|
|
lookup->section_question = state;
|
|
|
|
lookup->section_authority = state;
|
|
|
|
lookup->section_answer = state;
|
|
|
|
lookup->section_additional = state;
|
|
|
|
lookup->comments = state;
|
2011-03-05 19:39:07 +00:00
|
|
|
rrcomments = state;
|
2001-09-11 00:58:15 +00:00
|
|
|
lookup->stats = state;
|
|
|
|
printcmd = state;
|
2000-09-22 23:21:32 +00:00
|
|
|
break;
|
|
|
|
case 'n': /* answer */
|
2001-11-07 05:40:48 +00:00
|
|
|
FULLCHECK("answer");
|
2000-09-22 23:21:32 +00:00
|
|
|
lookup->section_answer = state;
|
|
|
|
break;
|
|
|
|
case 'u': /* authority */
|
2001-11-07 05:40:48 +00:00
|
|
|
FULLCHECK("authority");
|
2000-09-22 23:21:32 +00:00
|
|
|
lookup->section_authority = state;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto invalid_option;
|
|
|
|
}
|
|
|
|
break;
|
2000-10-13 17:54:00 +00:00
|
|
|
case 'b':
|
2000-10-17 00:35:18 +00:00
|
|
|
switch (cmd[1]) {
|
2000-10-13 17:54:00 +00:00
|
|
|
case 'e':/* besteffort */
|
2001-11-07 05:40:48 +00:00
|
|
|
FULLCHECK("besteffort");
|
2000-10-13 17:54:00 +00:00
|
|
|
lookup->besteffort = state;
|
|
|
|
break;
|
|
|
|
case 'u':/* bufsize */
|
2001-11-07 05:40:48 +00:00
|
|
|
FULLCHECK("bufsize");
|
2000-10-13 17:54:00 +00:00
|
|
|
if (value == NULL)
|
|
|
|
goto need_value;
|
|
|
|
if (!state)
|
|
|
|
goto invalid_option;
|
2009-09-15 03:13:44 +00:00
|
|
|
result = parse_uint(&num, value, COMMSIZE,
|
|
|
|
"buffer size");
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("Couldn't parse buffer size");
|
|
|
|
lookup->udpsize = num;
|
2000-10-13 17:54:00 +00:00
|
|
|
break;
|
|
|
|
default:
|
2000-09-22 23:21:32 +00:00
|
|
|
goto invalid_option;
|
2000-10-13 17:54:00 +00:00
|
|
|
}
|
2000-09-22 23:21:32 +00:00
|
|
|
break;
|
|
|
|
case 'c':
|
2000-10-17 00:35:18 +00:00
|
|
|
switch (cmd[1]) {
|
2000-09-22 23:21:32 +00:00
|
|
|
case 'd':/* cdflag */
|
2009-09-23 06:21:36 +00:00
|
|
|
switch (cmd[2]) {
|
|
|
|
case 'f': /* cdflag */
|
|
|
|
case '\0': /* +cd is a synonym for +cdflag */
|
|
|
|
FULLCHECK("cdflag");
|
|
|
|
lookup->cdflag = state;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto invalid_option;
|
|
|
|
}
|
2000-09-22 23:21:32 +00:00
|
|
|
break;
|
2002-05-22 04:58:30 +00:00
|
|
|
case 'l': /* cl */
|
|
|
|
FULLCHECK("cl");
|
2005-10-14 01:14:08 +00:00
|
|
|
noclass = ISC_TF(!state);
|
2002-05-22 04:58:30 +00:00
|
|
|
break;
|
2000-09-22 23:21:32 +00:00
|
|
|
case 'm': /* cmd */
|
2001-11-07 05:40:48 +00:00
|
|
|
FULLCHECK("cmd");
|
2000-09-22 23:21:32 +00:00
|
|
|
printcmd = state;
|
|
|
|
break;
|
|
|
|
case 'o': /* comments */
|
2001-11-07 05:40:48 +00:00
|
|
|
FULLCHECK("comments");
|
2000-09-22 23:21:32 +00:00
|
|
|
lookup->comments = state;
|
2000-10-17 00:35:18 +00:00
|
|
|
if (lookup == default_lookup)
|
|
|
|
pluscomm = state;
|
2000-09-22 23:21:32 +00:00
|
|
|
break;
|
2013-08-12 15:37:51 +10:00
|
|
|
case 'r':
|
|
|
|
FULLCHECK("crypto");
|
|
|
|
nocrypto = ISC_TF(!state);
|
|
|
|
break;
|
2000-09-22 23:21:32 +00:00
|
|
|
default:
|
|
|
|
goto invalid_option;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'd':
|
2000-10-17 00:35:18 +00:00
|
|
|
switch (cmd[1]) {
|
2000-11-13 21:34:03 +00:00
|
|
|
case 'e': /* defname */
|
2001-11-07 05:40:48 +00:00
|
|
|
FULLCHECK("defname");
|
2009-01-22 05:06:33 +00:00
|
|
|
if (!lookup->trace) {
|
|
|
|
usesearch = state;
|
|
|
|
}
|
2000-09-22 23:21:32 +00:00
|
|
|
break;
|
2008-02-05 23:47:08 +00:00
|
|
|
case 'n': /* dnssec */
|
2001-11-07 05:40:48 +00:00
|
|
|
FULLCHECK("dnssec");
|
2005-06-07 00:16:01 +00:00
|
|
|
if (state && lookup->edns == -1)
|
|
|
|
lookup->edns = 0;
|
2000-11-13 21:34:03 +00:00
|
|
|
lookup->dnssec = state;
|
|
|
|
break;
|
2008-02-05 23:47:08 +00:00
|
|
|
case 'o': /* domain */
|
2001-11-07 05:40:48 +00:00
|
|
|
FULLCHECK("domain");
|
2000-09-22 23:21:32 +00:00
|
|
|
if (value == NULL)
|
|
|
|
goto need_value;
|
|
|
|
if (!state)
|
|
|
|
goto invalid_option;
|
2001-01-18 05:12:44 +00:00
|
|
|
strncpy(domainopt, value, sizeof(domainopt));
|
|
|
|
domainopt[sizeof(domainopt)-1] = '\0';
|
2000-09-22 23:21:32 +00:00
|
|
|
break;
|
2014-07-15 23:27:14 +10:00
|
|
|
case 's': /* dscp */
|
|
|
|
FULLCHECK("dscp");
|
|
|
|
if (!state) {
|
|
|
|
lookup->dscp = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (value == NULL)
|
|
|
|
goto need_value;
|
|
|
|
result = parse_uint(&num, value, 0x3f, "DSCP");
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("Couldn't parse DSCP value");
|
|
|
|
lookup->dscp = num;
|
|
|
|
break;
|
2000-09-22 23:21:32 +00:00
|
|
|
default:
|
|
|
|
goto invalid_option;
|
|
|
|
}
|
|
|
|
break;
|
2005-06-07 00:16:01 +00:00
|
|
|
case 'e':
|
2014-02-20 14:56:20 +11:00
|
|
|
switch (cmd[1]) {
|
|
|
|
case 'd':
|
2014-04-18 09:52:12 +10:00
|
|
|
switch(cmd[2]) {
|
|
|
|
case 'n':
|
|
|
|
switch (cmd[3]) {
|
|
|
|
case 's':
|
|
|
|
switch (cmd[4]) {
|
|
|
|
case 0:
|
|
|
|
FULLCHECK("edns");
|
|
|
|
if (!state) {
|
|
|
|
lookup->edns = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (value == NULL) {
|
|
|
|
lookup->edns = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
result = parse_uint(&num,
|
|
|
|
value,
|
|
|
|
255,
|
|
|
|
"edns");
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("Couldn't parse "
|
|
|
|
"edns");
|
|
|
|
lookup->edns = num;
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
FULLCHECK("ednsopt");
|
|
|
|
if (!state) {
|
|
|
|
lookup->ednsoptscnt = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (value == NULL)
|
|
|
|
fatal("ednsopt no "
|
|
|
|
"code point "
|
|
|
|
"specified");
|
|
|
|
code = next_token(&value, ":");
|
|
|
|
save_opt(lookup, code, value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto invalid_option;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto invalid_option;
|
|
|
|
}
|
2014-02-20 14:56:20 +11:00
|
|
|
break;
|
2014-04-18 09:52:12 +10:00
|
|
|
default:
|
|
|
|
goto invalid_option;
|
2014-02-20 14:56:20 +11:00
|
|
|
}
|
2005-06-07 00:16:01 +00:00
|
|
|
break;
|
2014-02-20 14:56:20 +11:00
|
|
|
case 'x':
|
|
|
|
FULLCHECK("expire");
|
|
|
|
lookup->expire = state;
|
2013-05-01 14:53:16 +10:00
|
|
|
break;
|
2014-02-20 14:56:20 +11:00
|
|
|
default:
|
|
|
|
goto invalid_option;
|
2013-05-01 14:53:16 +10:00
|
|
|
}
|
2005-06-07 00:16:01 +00:00
|
|
|
break;
|
2000-09-25 23:10:00 +00:00
|
|
|
case 'f': /* fail */
|
2001-11-07 05:40:48 +00:00
|
|
|
FULLCHECK("fail");
|
2000-09-28 23:02:28 +00:00
|
|
|
lookup->servfail_stops = state;
|
2000-09-25 23:10:00 +00:00
|
|
|
break;
|
2000-09-22 23:21:32 +00:00
|
|
|
case 'i':
|
2000-10-17 00:35:18 +00:00
|
|
|
switch (cmd[1]) {
|
2000-09-22 23:21:32 +00:00
|
|
|
case 'd': /* identify */
|
2001-11-07 05:40:48 +00:00
|
|
|
FULLCHECK("identify");
|
2000-09-22 23:21:32 +00:00
|
|
|
lookup->identify = state;
|
|
|
|
break;
|
|
|
|
case 'g': /* ignore */
|
2009-01-17 09:58:29 +00:00
|
|
|
default: /* Inherits default for compatibility */
|
2001-11-07 05:40:48 +00:00
|
|
|
FULLCHECK("ignore");
|
2000-09-22 23:21:32 +00:00
|
|
|
lookup->ignore = ISC_TRUE;
|
|
|
|
}
|
|
|
|
break;
|
2013-11-07 10:50:01 +11:00
|
|
|
case 'k':
|
|
|
|
FULLCHECK("keepopen");
|
|
|
|
keep_open = state;
|
|
|
|
break;
|
2001-03-28 02:42:56 +00:00
|
|
|
case 'm': /* multiline */
|
2001-11-07 05:40:48 +00:00
|
|
|
FULLCHECK("multiline");
|
2001-03-28 02:42:56 +00:00
|
|
|
multiline = state;
|
|
|
|
break;
|
2000-09-22 23:21:32 +00:00
|
|
|
case 'n':
|
2000-10-17 00:35:18 +00:00
|
|
|
switch (cmd[1]) {
|
2000-09-22 23:21:32 +00:00
|
|
|
case 'd': /* ndots */
|
2001-11-07 05:40:48 +00:00
|
|
|
FULLCHECK("ndots");
|
2000-09-22 23:21:32 +00:00
|
|
|
if (value == NULL)
|
|
|
|
goto need_value;
|
|
|
|
if (!state)
|
|
|
|
goto invalid_option;
|
2009-09-15 03:13:44 +00:00
|
|
|
result = parse_uint(&num, value, MAXNDOTS, "ndots");
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("Couldn't parse ndots");
|
|
|
|
ndots = num;
|
2000-09-22 23:21:32 +00:00
|
|
|
break;
|
2008-04-03 02:01:08 +00:00
|
|
|
case 's':
|
|
|
|
switch (cmd[2]) {
|
|
|
|
case 'i': /* nsid */
|
|
|
|
FULLCHECK("nsid");
|
|
|
|
if (state && lookup->edns == -1)
|
|
|
|
lookup->edns = 0;
|
|
|
|
lookup->nsid = state;
|
|
|
|
break;
|
|
|
|
case 's': /* nssearch */
|
|
|
|
FULLCHECK("nssearch");
|
|
|
|
lookup->ns_search_only = state;
|
|
|
|
if (state) {
|
|
|
|
lookup->trace_root = ISC_TRUE;
|
|
|
|
lookup->recurse = ISC_TRUE;
|
|
|
|
lookup->identify = ISC_TRUE;
|
|
|
|
lookup->stats = ISC_FALSE;
|
|
|
|
lookup->comments = ISC_FALSE;
|
2011-03-05 19:39:07 +00:00
|
|
|
rrcomments = ISC_FALSE;
|
2008-04-03 02:01:08 +00:00
|
|
|
lookup->section_additional = ISC_FALSE;
|
|
|
|
lookup->section_authority = ISC_FALSE;
|
|
|
|
lookup->section_question = ISC_FALSE;
|
|
|
|
lookup->rdtype = dns_rdatatype_ns;
|
|
|
|
lookup->rdtypeset = ISC_TRUE;
|
|
|
|
short_form = ISC_TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto invalid_option;
|
2000-09-22 23:21:32 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto invalid_option;
|
|
|
|
}
|
|
|
|
break;
|
2010-03-04 05:18:04 +00:00
|
|
|
case 'o':
|
|
|
|
FULLCHECK("onesoa");
|
|
|
|
onesoa = state;
|
|
|
|
break;
|
2008-02-05 23:47:08 +00:00
|
|
|
case 'q':
|
2000-10-17 00:35:18 +00:00
|
|
|
switch (cmd[1]) {
|
2000-09-22 23:21:32 +00:00
|
|
|
case 'r': /* qr */
|
2001-11-07 05:40:48 +00:00
|
|
|
FULLCHECK("qr");
|
2000-09-22 23:21:32 +00:00
|
|
|
qr = state;
|
|
|
|
break;
|
|
|
|
case 'u': /* question */
|
2001-11-07 05:40:48 +00:00
|
|
|
FULLCHECK("question");
|
2000-09-22 23:21:32 +00:00
|
|
|
lookup->section_question = state;
|
2000-10-17 00:35:18 +00:00
|
|
|
if (lookup == default_lookup)
|
|
|
|
plusquest = state;
|
2000-09-22 23:21:32 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto invalid_option;
|
|
|
|
}
|
|
|
|
break;
|
2001-09-18 18:25:14 +00:00
|
|
|
case 'r':
|
|
|
|
switch (cmd[1]) {
|
|
|
|
case 'e':
|
|
|
|
switch (cmd[2]) {
|
|
|
|
case 'c': /* recurse */
|
2001-11-07 05:40:48 +00:00
|
|
|
FULLCHECK("recurse");
|
2001-09-18 18:25:14 +00:00
|
|
|
lookup->recurse = state;
|
|
|
|
break;
|
2001-09-20 17:15:03 +00:00
|
|
|
case 't': /* retry / retries */
|
2001-11-07 05:40:48 +00:00
|
|
|
FULLCHECK2("retry", "retries");
|
2001-09-18 18:25:14 +00:00
|
|
|
if (value == NULL)
|
|
|
|
goto need_value;
|
|
|
|
if (!state)
|
|
|
|
goto invalid_option;
|
2009-09-15 03:13:44 +00:00
|
|
|
result = parse_uint(&lookup->retries, value,
|
|
|
|
MAXTRIES - 1, "retries");
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("Couldn't parse retries");
|
2001-09-18 18:25:14 +00:00
|
|
|
lookup->retries++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto invalid_option;
|
|
|
|
}
|
2011-03-05 23:52:31 +00:00
|
|
|
break;
|
2011-03-05 19:39:07 +00:00
|
|
|
case 'r': /* rrcomments */
|
|
|
|
FULLCHECK("rrcomments");
|
|
|
|
rrcomments = state;
|
2001-09-20 19:11:59 +00:00
|
|
|
break;
|
2001-09-18 18:25:14 +00:00
|
|
|
default:
|
|
|
|
goto invalid_option;
|
|
|
|
}
|
2000-09-22 23:21:32 +00:00
|
|
|
break;
|
|
|
|
case 's':
|
2000-10-17 00:35:18 +00:00
|
|
|
switch (cmd[1]) {
|
2000-09-22 23:21:32 +00:00
|
|
|
case 'e': /* search */
|
2001-11-07 05:40:48 +00:00
|
|
|
FULLCHECK("search");
|
2009-01-22 05:06:33 +00:00
|
|
|
if (!lookup->trace) {
|
|
|
|
usesearch = state;
|
|
|
|
}
|
2000-09-22 23:21:32 +00:00
|
|
|
break;
|
2005-08-25 00:17:46 +00:00
|
|
|
case 'h':
|
|
|
|
if (cmd[2] != 'o')
|
|
|
|
goto invalid_option;
|
|
|
|
switch (cmd[3]) {
|
|
|
|
case 'r': /* short */
|
|
|
|
FULLCHECK("short");
|
|
|
|
short_form = state;
|
|
|
|
if (state) {
|
|
|
|
printcmd = ISC_FALSE;
|
|
|
|
lookup->section_additional = ISC_FALSE;
|
|
|
|
lookup->section_answer = ISC_TRUE;
|
|
|
|
lookup->section_authority = ISC_FALSE;
|
|
|
|
lookup->section_question = ISC_FALSE;
|
|
|
|
lookup->comments = ISC_FALSE;
|
2011-03-05 19:39:07 +00:00
|
|
|
rrcomments = ISC_FALSE;
|
2005-08-25 00:17:46 +00:00
|
|
|
lookup->stats = ISC_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'w': /* showsearch */
|
|
|
|
FULLCHECK("showsearch");
|
2009-01-22 05:06:33 +00:00
|
|
|
if (!lookup->trace) {
|
|
|
|
showsearch = state;
|
|
|
|
usesearch = state;
|
|
|
|
}
|
2005-08-25 00:17:46 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto invalid_option;
|
2000-09-22 23:21:32 +00:00
|
|
|
}
|
|
|
|
break;
|
2014-02-20 00:24:56 +11:00
|
|
|
#if defined(DIG_SIGCHASE) || defined(ISC_PLATFORM_USESIT)
|
2014-02-19 12:53:42 +11:00
|
|
|
case 'i':
|
|
|
|
switch (cmd[2]) {
|
2004-04-13 02:39:35 +00:00
|
|
|
#ifdef DIG_SIGCHASE
|
2014-02-19 12:53:42 +11:00
|
|
|
case 'g': /* sigchase */
|
|
|
|
FULLCHECK("sigchase");
|
|
|
|
lookup->sigchase = state;
|
|
|
|
if (lookup->sigchase)
|
|
|
|
lookup->dnssec = ISC_TRUE;
|
|
|
|
break;
|
2004-04-13 02:39:35 +00:00
|
|
|
#endif
|
2014-02-19 12:53:42 +11:00
|
|
|
#ifdef ISC_PLATFORM_USESIT
|
|
|
|
case 't': /* sit */
|
|
|
|
FULLCHECK("sit");
|
|
|
|
if (state && lookup->edns == -1)
|
|
|
|
lookup->edns = 0;
|
|
|
|
lookup->sit = state;
|
|
|
|
if (value != NULL) {
|
2014-06-12 07:57:19 +10:00
|
|
|
n = strlcpy(sitvalue, value,
|
|
|
|
sizeof(sitvalue));
|
|
|
|
if (n >= sizeof(sitvalue))
|
|
|
|
fatal("SIT data too large");
|
2014-02-19 12:53:42 +11:00
|
|
|
lookup->sitvalue = sitvalue;
|
|
|
|
} else
|
|
|
|
lookup->sitvalue = NULL;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
goto invalid_option;
|
|
|
|
}
|
|
|
|
break;
|
2014-02-20 00:24:56 +11:00
|
|
|
#endif
|
2011-03-05 19:39:07 +00:00
|
|
|
case 'p': /* split */
|
|
|
|
FULLCHECK("split");
|
|
|
|
if (value != NULL && !state)
|
|
|
|
goto invalid_option;
|
|
|
|
if (!state) {
|
|
|
|
splitwidth = 0;
|
|
|
|
break;
|
|
|
|
} else if (value == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
result = parse_uint(&splitwidth, value,
|
|
|
|
1023, "split");
|
|
|
|
if (splitwidth % 4 != 0) {
|
|
|
|
splitwidth = ((splitwidth + 3) / 4) * 4;
|
|
|
|
fprintf(stderr, ";; Warning, split must be "
|
|
|
|
"a multiple of 4; adjusting "
|
|
|
|
"to %d\n", splitwidth);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* There is an adjustment done in the
|
|
|
|
* totext_<rrtype>() functions which causes
|
|
|
|
* splitwidth to shrink. This is okay when we're
|
|
|
|
* using the default width but incorrect in this
|
|
|
|
* case, so we correct for it
|
|
|
|
*/
|
|
|
|
if (splitwidth)
|
|
|
|
splitwidth += 3;
|
|
|
|
if (result != ISC_R_SUCCESS)
|
2014-02-16 02:08:55 +01:00
|
|
|
fatal("Couldn't parse split");
|
2011-03-05 19:39:07 +00:00
|
|
|
break;
|
2000-09-22 23:21:32 +00:00
|
|
|
case 't': /* stats */
|
2001-11-07 05:40:48 +00:00
|
|
|
FULLCHECK("stats");
|
2000-09-22 23:21:32 +00:00
|
|
|
lookup->stats = state;
|
|
|
|
break;
|
2014-02-19 15:51:02 -08:00
|
|
|
case 'u': /* subnet */
|
|
|
|
FULLCHECK("subnet");
|
|
|
|
if (state && value == NULL)
|
|
|
|
goto need_value;
|
|
|
|
if (!state) {
|
|
|
|
if (lookup->ecs_addr != NULL) {
|
|
|
|
isc_mem_free(mctx, lookup->ecs_addr);
|
|
|
|
lookup->ecs_addr = NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (lookup->edns == -1)
|
|
|
|
lookup->edns = 0;
|
|
|
|
result = parse_netprefix(&lookup->ecs_addr, value);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("Couldn't parse client");
|
|
|
|
break;
|
2000-09-22 23:21:32 +00:00
|
|
|
default:
|
|
|
|
goto invalid_option;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 't':
|
2000-10-17 00:35:18 +00:00
|
|
|
switch (cmd[1]) {
|
2000-09-22 23:21:32 +00:00
|
|
|
case 'c': /* tcp */
|
2001-11-07 05:40:48 +00:00
|
|
|
FULLCHECK("tcp");
|
2014-05-14 09:59:02 +10:00
|
|
|
if (!is_batchfile) {
|
2000-09-22 23:21:32 +00:00
|
|
|
lookup->tcp_mode = state;
|
2014-05-14 09:59:02 +10:00
|
|
|
lookup->tcp_mode_set = ISC_TRUE;
|
|
|
|
}
|
2000-09-22 23:21:32 +00:00
|
|
|
break;
|
|
|
|
case 'i': /* timeout */
|
2001-11-07 05:40:48 +00:00
|
|
|
FULLCHECK("timeout");
|
2000-09-22 23:21:32 +00:00
|
|
|
if (value == NULL)
|
|
|
|
goto need_value;
|
|
|
|
if (!state)
|
|
|
|
goto invalid_option;
|
2009-09-15 03:13:44 +00:00
|
|
|
result = parse_uint(&timeout, value, MAXTIMEOUT,
|
|
|
|
"timeout");
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("Couldn't parse timeout");
|
2001-08-23 04:39:31 +00:00
|
|
|
if (timeout == 0)
|
2000-09-22 23:21:32 +00:00
|
|
|
timeout = 1;
|
|
|
|
break;
|
2004-04-13 02:39:35 +00:00
|
|
|
#if DIG_SIGCHASE_TD
|
2008-02-05 23:47:08 +00:00
|
|
|
case 'o': /* topdown */
|
2004-04-13 02:39:35 +00:00
|
|
|
FULLCHECK("topdown");
|
|
|
|
lookup->do_topdown = state;
|
|
|
|
break;
|
|
|
|
#endif
|
2000-09-22 23:21:32 +00:00
|
|
|
case 'r':
|
2000-10-17 00:35:18 +00:00
|
|
|
switch (cmd[2]) {
|
2000-09-22 23:21:32 +00:00
|
|
|
case 'a': /* trace */
|
2001-11-07 05:40:48 +00:00
|
|
|
FULLCHECK("trace");
|
2000-09-22 23:21:32 +00:00
|
|
|
lookup->trace = state;
|
|
|
|
lookup->trace_root = state;
|
|
|
|
if (state) {
|
|
|
|
lookup->recurse = ISC_FALSE;
|
|
|
|
lookup->identify = ISC_TRUE;
|
|
|
|
lookup->comments = ISC_FALSE;
|
2011-03-05 19:39:07 +00:00
|
|
|
rrcomments = ISC_FALSE;
|
2000-09-22 23:21:32 +00:00
|
|
|
lookup->stats = ISC_FALSE;
|
|
|
|
lookup->section_additional = ISC_FALSE;
|
|
|
|
lookup->section_authority = ISC_TRUE;
|
2004-09-06 06:22:35 +00:00
|
|
|
lookup->section_question = ISC_FALSE;
|
2011-11-04 10:41:38 +00:00
|
|
|
lookup->dnssec = ISC_TRUE;
|
2009-01-22 05:06:33 +00:00
|
|
|
usesearch = ISC_FALSE;
|
2000-09-22 23:21:32 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'i': /* tries */
|
2001-11-07 05:40:48 +00:00
|
|
|
FULLCHECK("tries");
|
2000-09-22 23:21:32 +00:00
|
|
|
if (value == NULL)
|
|
|
|
goto need_value;
|
|
|
|
if (!state)
|
|
|
|
goto invalid_option;
|
2009-09-15 03:13:44 +00:00
|
|
|
result = parse_uint(&lookup->retries, value,
|
|
|
|
MAXTRIES, "tries");
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("Couldn't parse tries");
|
2001-08-23 04:39:31 +00:00
|
|
|
if (lookup->retries == 0)
|
2000-09-22 23:21:32 +00:00
|
|
|
lookup->retries = 1;
|
|
|
|
break;
|
2004-04-13 02:39:35 +00:00
|
|
|
#ifdef DIG_SIGCHASE
|
|
|
|
case 'u': /* trusted-key */
|
2004-09-03 03:55:20 +00:00
|
|
|
FULLCHECK("trusted-key");
|
2008-02-05 23:47:08 +00:00
|
|
|
if (value == NULL)
|
2004-04-13 02:39:35 +00:00
|
|
|
goto need_value;
|
|
|
|
if (!state)
|
|
|
|
goto invalid_option;
|
|
|
|
n = strlcpy(trustedkey, ptr,
|
|
|
|
sizeof(trustedkey));
|
|
|
|
if (n >= sizeof(trustedkey))
|
|
|
|
fatal("trusted key too large");
|
|
|
|
break;
|
|
|
|
#endif
|
2000-09-22 23:21:32 +00:00
|
|
|
default:
|
|
|
|
goto invalid_option;
|
|
|
|
}
|
2000-09-25 23:10:00 +00:00
|
|
|
break;
|
2014-04-29 16:58:36 -07:00
|
|
|
case 't':
|
2014-04-30 16:09:16 +10:00
|
|
|
switch (cmd[2]) {
|
|
|
|
case 'l':
|
|
|
|
switch (cmd[3]) {
|
|
|
|
case 0:
|
|
|
|
case 'i': /* ttlid */
|
|
|
|
FULLCHECK2("ttl", "ttlid");
|
|
|
|
nottl = ISC_TF(!state);
|
|
|
|
break;
|
|
|
|
case 'u': /* ttlunits */
|
|
|
|
FULLCHECK("ttlunits");
|
|
|
|
nottl = ISC_FALSE;
|
|
|
|
ttlunits = ISC_TF(state);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto invalid_option;
|
|
|
|
}
|
2014-04-29 16:58:36 -07:00
|
|
|
break;
|
2014-04-30 15:59:15 +10:00
|
|
|
default:
|
|
|
|
goto invalid_option;
|
2014-04-29 16:58:36 -07:00
|
|
|
}
|
2002-05-22 04:58:30 +00:00
|
|
|
break;
|
2000-09-22 23:21:32 +00:00
|
|
|
default:
|
|
|
|
goto invalid_option;
|
|
|
|
}
|
2000-09-25 23:10:00 +00:00
|
|
|
break;
|
2000-10-11 17:44:18 +00:00
|
|
|
case 'v':
|
2001-11-07 05:40:48 +00:00
|
|
|
FULLCHECK("vc");
|
2014-05-14 09:59:02 +10:00
|
|
|
if (!is_batchfile) {
|
2001-10-01 18:54:05 +00:00
|
|
|
lookup->tcp_mode = state;
|
2014-05-14 09:59:02 +10:00
|
|
|
lookup->tcp_mode_set = ISC_TRUE;
|
|
|
|
}
|
2000-09-22 23:21:32 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
invalid_option:
|
|
|
|
need_value:
|
2000-09-22 23:58:32 +00:00
|
|
|
fprintf(stderr, "Invalid option: +%s\n",
|
2000-09-25 16:14:20 +00:00
|
|
|
option);
|
2001-05-08 15:56:01 +00:00
|
|
|
usage();
|
2000-09-22 23:21:32 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*%
|
|
|
|
* #ISC_TRUE returned if value was used
|
2000-09-22 23:21:32 +00:00
|
|
|
*/
|
2013-03-04 12:09:28 -08:00
|
|
|
static const char *single_dash_opts = "46dhimnuv";
|
2004-06-07 03:56:02 +00:00
|
|
|
static const char *dash_opts = "46bcdfhikmnptvyx";
|
2000-09-22 23:21:32 +00:00
|
|
|
static isc_boolean_t
|
2000-10-02 16:16:50 +00:00
|
|
|
dash_option(char *option, char *next, dig_lookup_t **lookup,
|
2007-04-03 23:06:39 +00:00
|
|
|
isc_boolean_t *open_type_class, isc_boolean_t *need_clone,
|
|
|
|
isc_boolean_t config_only, int argc, char **argv,
|
|
|
|
isc_boolean_t *firstarg)
|
2000-09-22 23:21:32 +00:00
|
|
|
{
|
2006-01-27 02:35:15 +00:00
|
|
|
char opt, *value, *ptr, *ptr2, *ptr3;
|
2000-09-22 23:21:32 +00:00
|
|
|
isc_result_t result;
|
|
|
|
isc_boolean_t value_from_next;
|
|
|
|
isc_textregion_t tr;
|
|
|
|
dns_rdatatype_t rdtype;
|
|
|
|
dns_rdataclass_t rdclass;
|
2000-10-23 23:13:21 +00:00
|
|
|
char textname[MXNAME];
|
2001-02-17 20:27:24 +00:00
|
|
|
struct in_addr in4;
|
|
|
|
struct in6_addr in6;
|
2003-02-26 05:05:16 +00:00
|
|
|
in_port_t srcport;
|
2004-06-07 03:56:02 +00:00
|
|
|
char *hash, *cmd;
|
2009-09-15 03:13:44 +00:00
|
|
|
isc_uint32_t num;
|
2000-09-22 23:21:32 +00:00
|
|
|
|
2004-06-07 03:56:02 +00:00
|
|
|
while (strpbrk(option, single_dash_opts) == &option[0]) {
|
|
|
|
/*
|
2013-03-04 12:09:28 -08:00
|
|
|
* Since the -[46dhimnuv] options do not take an argument,
|
2004-06-07 03:56:02 +00:00
|
|
|
* account for them (in any number and/or combination)
|
|
|
|
* if they appear as the first character(s) of a q-opt.
|
|
|
|
*/
|
|
|
|
opt = option[0];
|
|
|
|
switch (opt) {
|
|
|
|
case '4':
|
|
|
|
if (have_ipv4) {
|
|
|
|
isc_net_disableipv6();
|
|
|
|
have_ipv6 = ISC_FALSE;
|
|
|
|
} else {
|
|
|
|
fatal("can't find IPv4 networking");
|
2009-10-03 18:03:54 +00:00
|
|
|
/* NOTREACHED */
|
2004-06-07 03:56:02 +00:00
|
|
|
return (ISC_FALSE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '6':
|
|
|
|
if (have_ipv6) {
|
|
|
|
isc_net_disableipv4();
|
|
|
|
have_ipv4 = ISC_FALSE;
|
|
|
|
} else {
|
|
|
|
fatal("can't find IPv6 networking");
|
2009-10-03 18:03:54 +00:00
|
|
|
/* NOTREACHED */
|
2004-06-07 03:56:02 +00:00
|
|
|
return (ISC_FALSE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
ptr = strpbrk(&option[1], dash_opts);
|
|
|
|
if (ptr != &option[1]) {
|
|
|
|
cmd = option;
|
|
|
|
FULLCHECK("debug");
|
|
|
|
debugging = ISC_TRUE;
|
|
|
|
return (ISC_FALSE);
|
|
|
|
} else
|
|
|
|
debugging = ISC_TRUE;
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
help();
|
|
|
|
exit(0);
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
ip6_int = ISC_TRUE;
|
|
|
|
break;
|
|
|
|
case 'm': /* memdebug */
|
|
|
|
/* memdebug is handled in preparse_args() */
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
/* deprecated */
|
|
|
|
break;
|
2013-03-04 12:09:28 -08:00
|
|
|
case 'u':
|
|
|
|
use_usec = ISC_TRUE;
|
|
|
|
break;
|
2004-06-07 03:56:02 +00:00
|
|
|
case 'v':
|
|
|
|
version();
|
|
|
|
exit(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (strlen(option) > 1U)
|
|
|
|
option = &option[1];
|
|
|
|
else
|
|
|
|
return (ISC_FALSE);
|
|
|
|
}
|
|
|
|
opt = option[0];
|
2003-07-25 00:01:16 +00:00
|
|
|
if (strlen(option) > 1U) {
|
2000-09-22 23:21:32 +00:00
|
|
|
value_from_next = ISC_FALSE;
|
|
|
|
value = &option[1];
|
2001-06-11 18:08:16 +00:00
|
|
|
} else {
|
2000-09-22 23:21:32 +00:00
|
|
|
value_from_next = ISC_TRUE;
|
|
|
|
value = next;
|
|
|
|
}
|
2000-09-22 23:58:32 +00:00
|
|
|
if (value == NULL)
|
|
|
|
goto invalid_option;
|
2004-06-07 03:56:02 +00:00
|
|
|
switch (opt) {
|
2000-09-22 23:21:32 +00:00
|
|
|
case 'b':
|
2004-03-16 05:52:24 +00:00
|
|
|
hash = strchr(value, '#');
|
2003-02-26 05:05:16 +00:00
|
|
|
if (hash != NULL) {
|
2009-09-15 03:13:44 +00:00
|
|
|
result = parse_uint(&num, hash + 1, MAXPORT,
|
|
|
|
"port number");
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("Couldn't parse port number");
|
|
|
|
srcport = num;
|
2003-02-26 05:05:16 +00:00
|
|
|
*hash = '\0';
|
|
|
|
} else
|
|
|
|
srcport = 0;
|
2004-04-15 06:47:08 +00:00
|
|
|
if (have_ipv6 && inet_pton(AF_INET6, value, &in6) == 1) {
|
2003-02-26 05:05:16 +00:00
|
|
|
isc_sockaddr_fromin6(&bind_address, &in6, srcport);
|
2004-04-15 06:47:08 +00:00
|
|
|
isc_net_disableipv4();
|
|
|
|
} else if (have_ipv4 && inet_pton(AF_INET, value, &in4) == 1) {
|
2003-02-26 05:05:16 +00:00
|
|
|
isc_sockaddr_fromin(&bind_address, &in4, srcport);
|
2004-04-15 06:47:08 +00:00
|
|
|
isc_net_disableipv6();
|
|
|
|
} else {
|
2003-02-26 05:05:16 +00:00
|
|
|
if (hash != NULL)
|
|
|
|
*hash = '#';
|
2001-02-17 20:27:24 +00:00
|
|
|
fatal("invalid address %s", value);
|
2003-02-26 05:05:16 +00:00
|
|
|
}
|
|
|
|
if (hash != NULL)
|
|
|
|
*hash = '#';
|
2000-09-22 23:21:32 +00:00
|
|
|
specified_source = ISC_TRUE;
|
|
|
|
return (value_from_next);
|
|
|
|
case 'c':
|
2000-12-08 17:06:52 +00:00
|
|
|
if ((*lookup)->rdclassset) {
|
2001-02-13 23:12:17 +00:00
|
|
|
fprintf(stderr, ";; Warning, extra class option\n");
|
2000-12-08 17:06:52 +00:00
|
|
|
}
|
2000-10-02 16:16:50 +00:00
|
|
|
*open_type_class = ISC_FALSE;
|
2000-09-22 23:21:32 +00:00
|
|
|
tr.base = value;
|
|
|
|
tr.length = strlen(value);
|
|
|
|
result = dns_rdataclass_fromtext(&rdclass,
|
|
|
|
(isc_textregion_t *)&tr);
|
2000-12-08 17:06:52 +00:00
|
|
|
if (result == ISC_R_SUCCESS) {
|
2000-09-22 23:21:32 +00:00
|
|
|
(*lookup)->rdclass = rdclass;
|
2000-12-08 17:06:52 +00:00
|
|
|
(*lookup)->rdclassset = ISC_TRUE;
|
2001-06-11 18:08:16 +00:00
|
|
|
} else
|
2000-09-26 17:17:39 +00:00
|
|
|
fprintf(stderr, ";; Warning, ignoring "
|
|
|
|
"invalid class %s\n",
|
|
|
|
value);
|
2000-09-22 23:21:32 +00:00
|
|
|
return (value_from_next);
|
|
|
|
case 'f':
|
|
|
|
batchname = value;
|
|
|
|
return (value_from_next);
|
|
|
|
case 'k':
|
2000-10-19 22:49:34 +00:00
|
|
|
strncpy(keyfile, value, sizeof(keyfile));
|
|
|
|
keyfile[sizeof(keyfile)-1]=0;
|
2000-09-22 23:21:32 +00:00
|
|
|
return (value_from_next);
|
|
|
|
case 'p':
|
2009-09-15 03:13:44 +00:00
|
|
|
result = parse_uint(&num, value, MAXPORT, "port number");
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("Couldn't parse port number");
|
|
|
|
port = num;
|
2000-09-22 23:21:32 +00:00
|
|
|
return (value_from_next);
|
2005-08-25 00:17:46 +00:00
|
|
|
case 'q':
|
|
|
|
if (!config_only) {
|
2007-04-03 23:06:39 +00:00
|
|
|
if (*need_clone)
|
|
|
|
(*lookup) = clone_lookup(default_lookup,
|
|
|
|
ISC_TRUE);
|
|
|
|
*need_clone = ISC_TRUE;
|
2008-02-05 23:47:08 +00:00
|
|
|
strncpy((*lookup)->textname, value,
|
2005-08-25 00:17:46 +00:00
|
|
|
sizeof((*lookup)->textname));
|
|
|
|
(*lookup)->textname[sizeof((*lookup)->textname)-1]=0;
|
|
|
|
(*lookup)->trace_root = ISC_TF((*lookup)->trace ||
|
|
|
|
(*lookup)->ns_search_only);
|
|
|
|
(*lookup)->new_search = ISC_TRUE;
|
2007-04-03 23:06:39 +00:00
|
|
|
if (*firstarg) {
|
|
|
|
printgreeting(argc, argv, *lookup);
|
|
|
|
*firstarg = ISC_FALSE;
|
|
|
|
}
|
2005-08-25 00:17:46 +00:00
|
|
|
ISC_LIST_APPEND(lookup_list, (*lookup), link);
|
|
|
|
debug("looking up %s", (*lookup)->textname);
|
|
|
|
}
|
|
|
|
return (value_from_next);
|
2000-09-22 23:21:32 +00:00
|
|
|
case 't':
|
2000-10-02 16:16:50 +00:00
|
|
|
*open_type_class = ISC_FALSE;
|
2000-09-22 23:21:32 +00:00
|
|
|
if (strncasecmp(value, "ixfr=", 5) == 0) {
|
2001-02-13 23:12:17 +00:00
|
|
|
rdtype = dns_rdatatype_ixfr;
|
|
|
|
result = ISC_R_SUCCESS;
|
2001-06-11 18:08:16 +00:00
|
|
|
} else {
|
2001-02-13 23:12:17 +00:00
|
|
|
tr.base = value;
|
|
|
|
tr.length = strlen(value);
|
|
|
|
result = dns_rdatatype_fromtext(&rdtype,
|
2000-09-22 23:21:32 +00:00
|
|
|
(isc_textregion_t *)&tr);
|
2001-06-29 06:06:02 +00:00
|
|
|
if (result == ISC_R_SUCCESS &&
|
2004-04-13 02:39:35 +00:00
|
|
|
rdtype == dns_rdatatype_ixfr) {
|
2001-06-29 06:06:02 +00:00
|
|
|
result = DNS_R_UNKNOWN;
|
|
|
|
}
|
2001-02-13 23:12:17 +00:00
|
|
|
}
|
2000-10-17 00:35:18 +00:00
|
|
|
if (result == ISC_R_SUCCESS) {
|
2001-02-13 23:12:17 +00:00
|
|
|
if ((*lookup)->rdtypeset) {
|
|
|
|
fprintf(stderr, ";; Warning, "
|
|
|
|
"extra type option\n");
|
|
|
|
}
|
|
|
|
if (rdtype == dns_rdatatype_ixfr) {
|
2009-09-15 03:13:44 +00:00
|
|
|
isc_uint32_t serial;
|
2001-02-13 23:12:17 +00:00
|
|
|
(*lookup)->rdtype = dns_rdatatype_ixfr;
|
|
|
|
(*lookup)->rdtypeset = ISC_TRUE;
|
2009-09-15 03:13:44 +00:00
|
|
|
result = parse_uint(&serial, &value[5],
|
|
|
|
MAXSERIAL, "serial number");
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("Couldn't parse serial number");
|
|
|
|
(*lookup)->ixfr_serial = serial;
|
2000-10-17 00:35:18 +00:00
|
|
|
(*lookup)->section_question = plusquest;
|
|
|
|
(*lookup)->comments = pluscomm;
|
2014-05-14 09:59:02 +10:00
|
|
|
if (!(*lookup)->tcp_mode_set)
|
|
|
|
(*lookup)->tcp_mode = ISC_TRUE;
|
2001-06-11 18:08:16 +00:00
|
|
|
} else {
|
2001-02-13 23:12:17 +00:00
|
|
|
(*lookup)->rdtype = rdtype;
|
2014-07-07 23:45:21 +00:00
|
|
|
if (!config_only)
|
2014-07-08 02:00:28 +10:00
|
|
|
(*lookup)->rdtypeset = ISC_TRUE;
|
2001-02-13 23:12:17 +00:00
|
|
|
if (rdtype == dns_rdatatype_axfr) {
|
|
|
|
(*lookup)->section_question = plusquest;
|
|
|
|
(*lookup)->comments = pluscomm;
|
|
|
|
}
|
|
|
|
(*lookup)->ixfr_serial = ISC_FALSE;
|
|
|
|
}
|
2000-10-17 00:35:18 +00:00
|
|
|
} else
|
2000-09-22 23:58:32 +00:00
|
|
|
fprintf(stderr, ";; Warning, ignoring "
|
2000-09-22 23:21:32 +00:00
|
|
|
"invalid type %s\n",
|
|
|
|
value);
|
|
|
|
return (value_from_next);
|
|
|
|
case 'y':
|
2006-01-27 02:35:15 +00:00
|
|
|
ptr = next_token(&value,":"); /* hmac type or name */
|
2000-09-22 23:21:32 +00:00
|
|
|
if (ptr == NULL) {
|
2001-05-08 15:56:01 +00:00
|
|
|
usage();
|
2000-09-22 23:21:32 +00:00
|
|
|
}
|
2006-01-27 02:35:15 +00:00
|
|
|
ptr2 = next_token(&value, ":"); /* name or secret */
|
|
|
|
if (ptr2 == NULL)
|
|
|
|
usage();
|
|
|
|
ptr3 = next_token(&value,":"); /* secret or NULL */
|
2008-02-05 23:47:08 +00:00
|
|
|
if (ptr3 != NULL) {
|
2009-09-15 03:13:44 +00:00
|
|
|
parse_hmac(ptr);
|
2006-01-27 02:35:15 +00:00
|
|
|
ptr = ptr2;
|
|
|
|
ptr2 = ptr3;
|
|
|
|
} else {
|
|
|
|
hmacname = DNS_TSIG_HMACMD5_NAME;
|
|
|
|
digestbits = 0;
|
|
|
|
}
|
2000-10-19 22:49:34 +00:00
|
|
|
strncpy(keynametext, ptr, sizeof(keynametext));
|
|
|
|
keynametext[sizeof(keynametext)-1]=0;
|
2006-01-27 02:35:15 +00:00
|
|
|
strncpy(keysecret, ptr2, sizeof(keysecret));
|
2000-10-19 22:49:34 +00:00
|
|
|
keysecret[sizeof(keysecret)-1]=0;
|
2000-09-22 23:21:32 +00:00
|
|
|
return (value_from_next);
|
|
|
|
case 'x':
|
2007-04-03 23:06:39 +00:00
|
|
|
if (*need_clone)
|
|
|
|
*lookup = clone_lookup(default_lookup, ISC_TRUE);
|
|
|
|
*need_clone = ISC_TRUE;
|
2003-07-25 04:02:54 +00:00
|
|
|
if (get_reverse(textname, sizeof(textname), value,
|
2004-04-13 02:39:35 +00:00
|
|
|
ip6_int, ISC_FALSE) == ISC_R_SUCCESS) {
|
2000-10-23 23:13:21 +00:00
|
|
|
strncpy((*lookup)->textname, textname,
|
|
|
|
sizeof((*lookup)->textname));
|
2014-06-16 15:30:11 -07:00
|
|
|
(*lookup)->textname[sizeof((*lookup)->textname)-1] = 0;
|
2000-10-23 23:13:21 +00:00
|
|
|
debug("looking up %s", (*lookup)->textname);
|
|
|
|
(*lookup)->trace_root = ISC_TF((*lookup)->trace ||
|
2000-12-11 19:24:30 +00:00
|
|
|
(*lookup)->ns_search_only);
|
2002-07-25 05:46:07 +00:00
|
|
|
(*lookup)->ip6_int = ip6_int;
|
2001-02-15 23:44:08 +00:00
|
|
|
if (!(*lookup)->rdtypeset)
|
2001-02-13 23:12:17 +00:00
|
|
|
(*lookup)->rdtype = dns_rdatatype_ptr;
|
2001-02-15 23:44:08 +00:00
|
|
|
if (!(*lookup)->rdclassset)
|
2001-02-13 23:12:17 +00:00
|
|
|
(*lookup)->rdclass = dns_rdataclass_in;
|
2001-02-15 23:44:08 +00:00
|
|
|
(*lookup)->new_search = ISC_TRUE;
|
2007-04-03 23:06:39 +00:00
|
|
|
if (*firstarg) {
|
|
|
|
printgreeting(argc, argv, *lookup);
|
|
|
|
*firstarg = ISC_FALSE;
|
|
|
|
}
|
2000-10-23 23:13:21 +00:00
|
|
|
ISC_LIST_APPEND(lookup_list, *lookup, link);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Invalid IP address %s\n", value);
|
|
|
|
exit(1);
|
2000-09-22 23:21:32 +00:00
|
|
|
}
|
|
|
|
return (value_from_next);
|
2000-09-22 23:58:32 +00:00
|
|
|
invalid_option:
|
2000-09-22 23:21:32 +00:00
|
|
|
default:
|
2000-09-22 23:58:32 +00:00
|
|
|
fprintf(stderr, "Invalid option: -%s\n", option);
|
2001-05-08 15:56:01 +00:00
|
|
|
usage();
|
2000-09-22 23:21:32 +00:00
|
|
|
}
|
2009-10-03 18:03:54 +00:00
|
|
|
/* NOTREACHED */
|
2000-09-22 23:21:32 +00:00
|
|
|
return (ISC_FALSE);
|
|
|
|
}
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*%
|
2000-10-16 19:00:01 +00:00
|
|
|
* Because we may be trying to do memory allocation recording, we're going
|
|
|
|
* to need to parse the arguments for the -m *before* we start the main
|
|
|
|
* argument parsing routine.
|
2005-04-27 04:57:32 +00:00
|
|
|
*
|
2000-10-16 19:00:01 +00:00
|
|
|
* I'd prefer not to have to do this, but I am not quite sure how else to
|
|
|
|
* fix the problem. Argument parsing in dig involves memory allocation
|
|
|
|
* by its nature, so it can't be done in the main argument parser.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
preparse_args(int argc, char **argv) {
|
|
|
|
int rc;
|
|
|
|
char **rv;
|
2004-06-07 03:56:02 +00:00
|
|
|
char *option;
|
2000-10-16 19:00:01 +00:00
|
|
|
|
|
|
|
rc = argc;
|
|
|
|
rv = argv;
|
|
|
|
for (rc--, rv++; rc > 0; rc--, rv++) {
|
2004-06-07 03:56:02 +00:00
|
|
|
if (rv[0][0] != '-')
|
|
|
|
continue;
|
|
|
|
option = &rv[0][1];
|
|
|
|
while (strpbrk(option, single_dash_opts) == &option[0]) {
|
|
|
|
if (option[0] == 'm') {
|
|
|
|
memdebugging = ISC_TRUE;
|
|
|
|
isc_mem_debugging = ISC_MEM_DEBUGTRACE |
|
|
|
|
ISC_MEM_DEBUGRECORD;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
option = &option[1];
|
2000-10-16 19:00:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-12 01:02:37 +00:00
|
|
|
static void
|
2000-07-24 20:46:55 +00:00
|
|
|
parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
|
2014-08-22 15:40:43 +10:00
|
|
|
int argc, char **argv)
|
|
|
|
{
|
2000-07-18 01:28:20 +00:00
|
|
|
isc_result_t result;
|
|
|
|
isc_textregion_t tr;
|
2000-09-29 23:42:15 +00:00
|
|
|
isc_boolean_t firstarg = ISC_TRUE;
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
dig_lookup_t *lookup = NULL;
|
2000-07-18 01:28:20 +00:00
|
|
|
dns_rdatatype_t rdtype;
|
|
|
|
dns_rdataclass_t rdclass;
|
2000-10-02 16:16:50 +00:00
|
|
|
isc_boolean_t open_type_class = ISC_TRUE;
|
2000-04-19 23:23:31 +00:00
|
|
|
char batchline[MXNAME];
|
|
|
|
int bargc;
|
2000-10-19 23:31:56 +00:00
|
|
|
char *bargv[64];
|
2000-05-08 22:51:08 +00:00
|
|
|
int rc;
|
|
|
|
char **rv;
|
2000-07-24 23:13:44 +00:00
|
|
|
#ifndef NOPOSIX
|
|
|
|
char *homedir;
|
2000-10-20 00:54:01 +00:00
|
|
|
char rcfile[256];
|
2000-07-24 23:13:44 +00:00
|
|
|
#endif
|
2000-09-21 11:53:16 +00:00
|
|
|
char *input;
|
2007-03-30 03:46:13 +00:00
|
|
|
int i;
|
2007-04-03 23:06:39 +00:00
|
|
|
isc_boolean_t need_clone = ISC_TRUE;
|
2000-05-08 22:51:08 +00:00
|
|
|
|
2000-05-12 18:45:38 +00:00
|
|
|
/*
|
|
|
|
* The semantics for parsing the args is a bit complex; if
|
|
|
|
* we don't have a host yet, make the arg apply globally,
|
|
|
|
* otherwise make it apply to the latest host. This is
|
|
|
|
* a bit different than the previous versions, but should
|
|
|
|
* form a consistent user interface.
|
2000-07-13 18:52:58 +00:00
|
|
|
*
|
|
|
|
* First, create a "default lookup" which won't actually be used
|
|
|
|
* anywhere, except for cloning into new lookups
|
2000-05-12 18:45:38 +00:00
|
|
|
*/
|
|
|
|
|
2000-07-20 17:56:20 +00:00
|
|
|
debug("parse_args()");
|
|
|
|
if (!is_batchfile) {
|
|
|
|
debug("making new lookup");
|
2000-07-13 18:52:58 +00:00
|
|
|
default_lookup = make_empty_lookup();
|
2011-11-04 10:41:38 +00:00
|
|
|
default_lookup->adflag = ISC_TRUE;
|
|
|
|
default_lookup->edns = 0;
|
2000-07-24 20:46:55 +00:00
|
|
|
|
2000-07-24 23:13:44 +00:00
|
|
|
#ifndef NOPOSIX
|
2000-07-24 20:46:55 +00:00
|
|
|
/*
|
2001-09-13 03:02:59 +00:00
|
|
|
* Treat ${HOME}/.digrc as a special batchfile
|
2000-07-24 20:46:55 +00:00
|
|
|
*/
|
2001-09-13 03:02:59 +00:00
|
|
|
INSIST(batchfp == NULL);
|
2000-07-24 23:13:44 +00:00
|
|
|
homedir = getenv("HOME");
|
2001-09-13 03:02:59 +00:00
|
|
|
if (homedir != NULL) {
|
|
|
|
unsigned int n;
|
|
|
|
n = snprintf(rcfile, sizeof(rcfile), "%s/.digrc",
|
2008-02-05 23:47:08 +00:00
|
|
|
homedir);
|
2001-09-13 03:02:59 +00:00
|
|
|
if (n < sizeof(rcfile))
|
|
|
|
batchfp = fopen(rcfile, "r");
|
|
|
|
}
|
2000-07-24 20:46:55 +00:00
|
|
|
if (batchfp != NULL) {
|
|
|
|
while (fgets(batchline, sizeof(batchline),
|
|
|
|
batchfp) != 0) {
|
|
|
|
debug("config line %s", batchline);
|
|
|
|
bargc = 1;
|
2000-09-21 11:53:16 +00:00
|
|
|
input = batchline;
|
2000-09-21 12:25:43 +00:00
|
|
|
bargv[bargc] = next_token(&input, " \t\r\n");
|
2000-07-24 20:46:55 +00:00
|
|
|
while ((bargv[bargc] != NULL) &&
|
2000-10-19 23:31:56 +00:00
|
|
|
(bargc < 62)) {
|
2000-07-24 20:46:55 +00:00
|
|
|
bargc++;
|
2001-09-12 21:48:41 +00:00
|
|
|
bargv[bargc] =
|
|
|
|
next_token(&input, " \t\r\n");
|
2000-07-24 20:46:55 +00:00
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-07-24 20:46:55 +00:00
|
|
|
bargv[0] = argv[0];
|
|
|
|
argv0 = argv[0];
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2007-03-30 03:46:13 +00:00
|
|
|
for(i = 0; i < bargc; i++)
|
2007-04-03 23:06:39 +00:00
|
|
|
debug(".digrc argv %d: %s",
|
2007-03-30 03:46:13 +00:00
|
|
|
i, bargv[i]);
|
2000-07-24 20:46:55 +00:00
|
|
|
parse_args(ISC_TRUE, ISC_TRUE, bargc,
|
|
|
|
(char **)bargv);
|
|
|
|
}
|
|
|
|
fclose(batchfp);
|
|
|
|
}
|
2000-07-24 23:13:44 +00:00
|
|
|
#endif
|
2000-07-20 17:56:20 +00:00
|
|
|
}
|
2000-07-13 18:52:58 +00:00
|
|
|
|
2007-04-03 23:06:39 +00:00
|
|
|
if (is_batchfile && !config_only) {
|
|
|
|
/* Processing '-f batchfile'. */
|
|
|
|
lookup = clone_lookup(default_lookup, ISC_TRUE);
|
|
|
|
need_clone = ISC_FALSE;
|
|
|
|
} else
|
|
|
|
lookup = default_lookup;
|
2000-07-13 18:52:58 +00:00
|
|
|
|
2000-05-08 22:51:08 +00:00
|
|
|
rc = argc;
|
|
|
|
rv = argv;
|
|
|
|
for (rc--, rv++; rc > 0; rc--, rv++) {
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("main parsing %s", rv[0]);
|
2000-08-01 01:33:37 +00:00
|
|
|
if (strncmp(rv[0], "%", 1) == 0)
|
2000-06-21 01:40:42 +00:00
|
|
|
break;
|
2014-02-16 13:42:42 -08:00
|
|
|
if (rv[0][0] == '@') {
|
2014-08-22 15:40:43 +10:00
|
|
|
|
|
|
|
if (is_batchfile && !config_only) {
|
|
|
|
addresscount = getaddresses(lookup, &rv[0][1],
|
|
|
|
&result);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fprintf(stderr, "couldn't get address "
|
|
|
|
"for '%s': %s: skipping "
|
|
|
|
"lookup\n", &rv[0][1],
|
|
|
|
isc_result_totext(result));
|
|
|
|
if (ISC_LINK_LINKED(lookup, link))
|
|
|
|
ISC_LIST_DEQUEUE(lookup_list,
|
|
|
|
lookup, link);
|
|
|
|
destroy_lookup(lookup);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
addresscount = getaddresses(lookup, &rv[0][1],
|
|
|
|
NULL);
|
2000-09-22 23:21:32 +00:00
|
|
|
} else if (rv[0][0] == '+') {
|
|
|
|
plus_option(&rv[0][1], is_batchfile,
|
|
|
|
lookup);
|
|
|
|
} else if (rv[0][0] == '-') {
|
|
|
|
if (rc <= 1) {
|
|
|
|
if (dash_option(&rv[0][1], NULL,
|
2005-08-25 00:17:46 +00:00
|
|
|
&lookup, &open_type_class,
|
2007-04-03 23:06:39 +00:00
|
|
|
&need_clone, config_only,
|
|
|
|
argc, argv, &firstarg)) {
|
2000-09-22 23:21:32 +00:00
|
|
|
rc--;
|
|
|
|
rv++;
|
2000-07-25 00:51:14 +00:00
|
|
|
}
|
2000-07-13 18:52:58 +00:00
|
|
|
} else {
|
2000-09-22 23:21:32 +00:00
|
|
|
if (dash_option(&rv[0][1], rv[1],
|
2005-08-25 00:17:46 +00:00
|
|
|
&lookup, &open_type_class,
|
2007-04-03 23:06:39 +00:00
|
|
|
&need_clone, config_only,
|
|
|
|
argc, argv, &firstarg)) {
|
2000-09-22 23:21:32 +00:00
|
|
|
rc--;
|
|
|
|
rv++;
|
2000-07-25 00:51:14 +00:00
|
|
|
}
|
2000-05-03 20:27:13 +00:00
|
|
|
}
|
2000-04-19 23:23:31 +00:00
|
|
|
} else {
|
2000-08-01 00:53:20 +00:00
|
|
|
/*
|
2000-08-01 01:33:37 +00:00
|
|
|
* Anything which isn't an option
|
2000-08-01 00:53:20 +00:00
|
|
|
*/
|
2000-10-02 16:16:50 +00:00
|
|
|
if (open_type_class) {
|
2006-07-21 23:50:15 +00:00
|
|
|
if (strncasecmp(rv[0], "ixfr=", 5) == 0) {
|
2001-02-13 23:12:17 +00:00
|
|
|
rdtype = dns_rdatatype_ixfr;
|
|
|
|
result = ISC_R_SUCCESS;
|
2001-06-11 18:08:16 +00:00
|
|
|
} else {
|
2001-02-13 23:12:17 +00:00
|
|
|
tr.base = rv[0];
|
|
|
|
tr.length = strlen(rv[0]);
|
|
|
|
result = dns_rdatatype_fromtext(&rdtype,
|
2008-02-05 23:47:08 +00:00
|
|
|
(isc_textregion_t *)&tr);
|
2001-06-29 06:06:02 +00:00
|
|
|
if (result == ISC_R_SUCCESS &&
|
2004-04-13 02:39:35 +00:00
|
|
|
rdtype == dns_rdatatype_ixfr) {
|
2001-06-29 06:06:02 +00:00
|
|
|
fprintf(stderr, ";; Warning, "
|
|
|
|
"ixfr requires a "
|
|
|
|
"serial number\n");
|
|
|
|
continue;
|
|
|
|
}
|
2001-02-13 23:12:17 +00:00
|
|
|
}
|
2001-11-22 01:59:02 +00:00
|
|
|
if (result == ISC_R_SUCCESS) {
|
2000-12-08 17:06:52 +00:00
|
|
|
if (lookup->rdtypeset) {
|
|
|
|
fprintf(stderr, ";; Warning, "
|
2001-02-13 23:12:17 +00:00
|
|
|
"extra type option\n");
|
2000-12-08 17:06:52 +00:00
|
|
|
}
|
2001-02-13 23:12:17 +00:00
|
|
|
if (rdtype == dns_rdatatype_ixfr) {
|
2009-09-15 03:13:44 +00:00
|
|
|
isc_uint32_t serial;
|
2001-09-12 21:48:41 +00:00
|
|
|
lookup->rdtype =
|
|
|
|
dns_rdatatype_ixfr;
|
2001-02-13 23:12:17 +00:00
|
|
|
lookup->rdtypeset = ISC_TRUE;
|
2009-09-15 03:13:44 +00:00
|
|
|
result = parse_uint(&serial,
|
|
|
|
&rv[0][5],
|
|
|
|
MAXSERIAL,
|
|
|
|
"serial number");
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("Couldn't parse "
|
|
|
|
"serial number");
|
|
|
|
lookup->ixfr_serial = serial;
|
2001-09-12 21:48:41 +00:00
|
|
|
lookup->section_question =
|
|
|
|
plusquest;
|
2000-10-17 00:35:18 +00:00
|
|
|
lookup->comments = pluscomm;
|
2014-05-14 09:59:02 +10:00
|
|
|
if (!lookup->tcp_mode_set)
|
|
|
|
lookup->tcp_mode = ISC_TRUE;
|
2001-06-11 18:08:16 +00:00
|
|
|
} else {
|
2001-02-13 23:12:17 +00:00
|
|
|
lookup->rdtype = rdtype;
|
|
|
|
lookup->rdtypeset = ISC_TRUE;
|
2001-09-12 21:48:41 +00:00
|
|
|
if (rdtype ==
|
|
|
|
dns_rdatatype_axfr) {
|
|
|
|
lookup->section_question =
|
2001-02-13 23:12:17 +00:00
|
|
|
plusquest;
|
2001-09-12 21:48:41 +00:00
|
|
|
lookup->comments = pluscomm;
|
2001-02-13 23:12:17 +00:00
|
|
|
}
|
|
|
|
lookup->ixfr_serial = ISC_FALSE;
|
|
|
|
}
|
2000-10-02 16:16:50 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
result = dns_rdataclass_fromtext(&rdclass,
|
|
|
|
(isc_textregion_t *)&tr);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
2000-12-08 17:06:52 +00:00
|
|
|
if (lookup->rdclassset) {
|
|
|
|
fprintf(stderr, ";; Warning, "
|
2001-02-13 23:12:17 +00:00
|
|
|
"extra class option\n");
|
2000-12-08 17:06:52 +00:00
|
|
|
}
|
2000-10-02 16:16:50 +00:00
|
|
|
lookup->rdclass = rdclass;
|
2000-12-08 17:06:52 +00:00
|
|
|
lookup->rdclassset = ISC_TRUE;
|
2000-10-02 16:16:50 +00:00
|
|
|
continue;
|
|
|
|
}
|
2000-04-19 23:23:31 +00:00
|
|
|
}
|
2007-04-03 23:06:39 +00:00
|
|
|
|
2000-07-24 20:46:55 +00:00
|
|
|
if (!config_only) {
|
2007-04-03 23:06:39 +00:00
|
|
|
if (need_clone)
|
|
|
|
lookup = clone_lookup(default_lookup,
|
|
|
|
ISC_TRUE);
|
|
|
|
need_clone = ISC_TRUE;
|
2008-02-05 23:47:08 +00:00
|
|
|
strncpy(lookup->textname, rv[0],
|
2000-10-19 22:49:34 +00:00
|
|
|
sizeof(lookup->textname));
|
|
|
|
lookup->textname[sizeof(lookup->textname)-1]=0;
|
2000-07-24 20:46:55 +00:00
|
|
|
lookup->trace_root = ISC_TF(lookup->trace ||
|
|
|
|
lookup->ns_search_only);
|
|
|
|
lookup->new_search = ISC_TRUE;
|
2007-04-03 23:06:39 +00:00
|
|
|
if (firstarg) {
|
|
|
|
printgreeting(argc, argv, lookup);
|
|
|
|
firstarg = ISC_FALSE;
|
|
|
|
}
|
2000-07-24 20:46:55 +00:00
|
|
|
ISC_LIST_APPEND(lookup_list, lookup, link);
|
|
|
|
debug("looking up %s", lookup->textname);
|
|
|
|
}
|
2000-08-01 00:53:20 +00:00
|
|
|
/* XXX Error message */
|
2000-04-19 23:23:31 +00:00
|
|
|
}
|
|
|
|
}
|
2007-04-03 23:06:39 +00:00
|
|
|
|
2000-08-01 01:33:37 +00:00
|
|
|
/*
|
2000-07-18 01:28:20 +00:00
|
|
|
* If we have a batchfile, seed the lookup list with the
|
|
|
|
* first entry, then trust the callback in dighost_shutdown
|
|
|
|
* to get the rest
|
|
|
|
*/
|
|
|
|
if ((batchname != NULL) && !(is_batchfile)) {
|
2000-08-02 17:58:07 +00:00
|
|
|
if (strcmp(batchname, "-") == 0)
|
|
|
|
batchfp = stdin;
|
|
|
|
else
|
|
|
|
batchfp = fopen(batchname, "r");
|
2000-07-18 01:28:20 +00:00
|
|
|
if (batchfp == NULL) {
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
perror(batchname);
|
2000-08-03 17:43:06 +00:00
|
|
|
if (exitcode < 8)
|
|
|
|
exitcode = 8;
|
2001-09-26 00:38:39 +00:00
|
|
|
fatal("couldn't open specified batch file");
|
2000-04-19 23:23:31 +00:00
|
|
|
}
|
2000-08-01 00:53:20 +00:00
|
|
|
/* XXX Remove code dup from shutdown code */
|
2000-09-29 23:42:15 +00:00
|
|
|
next_line:
|
2000-07-18 01:28:20 +00:00
|
|
|
if (fgets(batchline, sizeof(batchline), batchfp) != 0) {
|
2000-05-24 03:05:58 +00:00
|
|
|
bargc = 1;
|
2000-09-29 23:42:15 +00:00
|
|
|
debug("batch line %s", batchline);
|
|
|
|
if (batchline[0] == '\r' || batchline[0] == '\n'
|
|
|
|
|| batchline[0] == '#' || batchline[0] == ';')
|
|
|
|
goto next_line;
|
2000-09-21 11:53:16 +00:00
|
|
|
input = batchline;
|
2000-09-21 12:25:43 +00:00
|
|
|
bargv[bargc] = next_token(&input, " \t\r\n");
|
2000-07-21 21:21:26 +00:00
|
|
|
while ((bargv[bargc] != NULL) && (bargc < 14)) {
|
2000-04-26 18:34:17 +00:00
|
|
|
bargc++;
|
2000-09-21 12:25:43 +00:00
|
|
|
bargv[bargc] = next_token(&input, " \t\r\n");
|
2000-04-26 18:34:17 +00:00
|
|
|
}
|
2000-06-01 18:49:22 +00:00
|
|
|
|
2000-07-13 18:52:58 +00:00
|
|
|
bargv[0] = argv[0];
|
2000-07-18 01:28:20 +00:00
|
|
|
argv0 = argv[0];
|
2000-06-01 18:49:22 +00:00
|
|
|
|
2007-03-30 03:46:13 +00:00
|
|
|
for(i = 0; i < bargc; i++)
|
|
|
|
debug("batch argv %d: %s", i, bargv[i]);
|
2000-07-24 20:46:55 +00:00
|
|
|
parse_args(ISC_TRUE, ISC_FALSE, bargc, (char **)bargv);
|
2007-04-03 23:06:39 +00:00
|
|
|
return;
|
2000-04-19 23:23:31 +00:00
|
|
|
}
|
2007-04-03 23:06:39 +00:00
|
|
|
return;
|
2000-04-19 23:23:31 +00:00
|
|
|
}
|
2000-08-01 00:53:20 +00:00
|
|
|
/*
|
|
|
|
* If no lookup specified, search for root
|
|
|
|
*/
|
2000-07-24 20:46:55 +00:00
|
|
|
if ((lookup_list.head == NULL) && !config_only) {
|
2007-04-03 23:06:39 +00:00
|
|
|
if (need_clone)
|
|
|
|
lookup = clone_lookup(default_lookup, ISC_TRUE);
|
|
|
|
need_clone = ISC_TRUE;
|
2000-07-13 18:52:58 +00:00
|
|
|
lookup->trace_root = ISC_TF(lookup->trace ||
|
|
|
|
lookup->ns_search_only);
|
2000-05-24 19:49:51 +00:00
|
|
|
lookup->new_search = ISC_TRUE;
|
2000-05-03 23:07:30 +00:00
|
|
|
strcpy(lookup->textname, ".");
|
2000-07-18 01:28:20 +00:00
|
|
|
lookup->rdtype = dns_rdatatype_ns;
|
2000-12-08 17:06:52 +00:00
|
|
|
lookup->rdtypeset = ISC_TRUE;
|
2001-02-15 23:44:08 +00:00
|
|
|
if (firstarg) {
|
|
|
|
printgreeting(argc, argv, lookup);
|
|
|
|
firstarg = ISC_FALSE;
|
|
|
|
}
|
2000-04-19 23:23:31 +00:00
|
|
|
ISC_LIST_APPEND(lookup_list, lookup, link);
|
|
|
|
}
|
2007-04-03 23:06:39 +00:00
|
|
|
if (!need_clone)
|
|
|
|
destroy_lookup(lookup);
|
2000-07-18 01:28:20 +00:00
|
|
|
}
|
|
|
|
|
2000-07-18 18:51:40 +00:00
|
|
|
/*
|
2004-06-07 03:56:02 +00:00
|
|
|
* Callback from dighost.c to allow program-specific shutdown code.
|
|
|
|
* Here, we're possibly reading from a batch file, then shutting down
|
|
|
|
* for real if there's nothing in the batch file to read.
|
2000-07-18 18:51:40 +00:00
|
|
|
*/
|
2000-07-18 01:28:20 +00:00
|
|
|
void
|
|
|
|
dighost_shutdown(void) {
|
|
|
|
char batchline[MXNAME];
|
|
|
|
int bargc;
|
|
|
|
char *bargv[16];
|
2000-09-21 11:53:16 +00:00
|
|
|
char *input;
|
2007-03-30 03:46:13 +00:00
|
|
|
int i;
|
2000-07-18 01:28:20 +00:00
|
|
|
|
|
|
|
if (batchname == NULL) {
|
|
|
|
isc_app_shutdown();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-06-07 03:56:02 +00:00
|
|
|
fflush(stdout);
|
2000-07-18 01:28:20 +00:00
|
|
|
if (feof(batchfp)) {
|
|
|
|
batchname = NULL;
|
|
|
|
isc_app_shutdown();
|
2000-08-02 17:58:07 +00:00
|
|
|
if (batchfp != stdin)
|
|
|
|
fclose(batchfp);
|
2000-07-18 01:28:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fgets(batchline, sizeof(batchline), batchfp) != 0) {
|
|
|
|
debug("batch line %s", batchline);
|
|
|
|
bargc = 1;
|
2000-09-21 11:53:16 +00:00
|
|
|
input = batchline;
|
2000-09-21 12:25:43 +00:00
|
|
|
bargv[bargc] = next_token(&input, " \t\r\n");
|
2000-07-21 21:21:26 +00:00
|
|
|
while ((bargv[bargc] != NULL) && (bargc < 14)) {
|
2000-07-18 01:28:20 +00:00
|
|
|
bargc++;
|
2000-09-21 12:25:43 +00:00
|
|
|
bargv[bargc] = next_token(&input, " \t\r\n");
|
2000-07-18 01:28:20 +00:00
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-07-18 01:28:20 +00:00
|
|
|
bargv[0] = argv0;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2007-03-30 03:46:13 +00:00
|
|
|
for(i = 0; i < bargc; i++)
|
|
|
|
debug("batch argv %d: %s", i, bargv[i]);
|
2000-07-24 20:46:55 +00:00
|
|
|
parse_args(ISC_TRUE, ISC_FALSE, bargc, (char **)bargv);
|
2000-07-18 01:28:20 +00:00
|
|
|
start_lookup();
|
|
|
|
} else {
|
|
|
|
batchname = NULL;
|
2000-08-02 17:58:07 +00:00
|
|
|
if (batchfp != stdin)
|
|
|
|
fclose(batchfp);
|
2000-07-18 01:28:20 +00:00
|
|
|
isc_app_shutdown();
|
|
|
|
return;
|
2000-07-14 17:57:27 +00:00
|
|
|
}
|
2000-04-19 23:23:31 +00:00
|
|
|
}
|
2000-05-09 18:05:13 +00:00
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*% Main processing routine for dig */
|
2000-05-09 18:05:13 +00:00
|
|
|
int
|
|
|
|
main(int argc, char **argv) {
|
2000-07-10 18:02:31 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
2000-05-09 18:05:13 +00:00
|
|
|
ISC_LIST_INIT(lookup_list);
|
|
|
|
ISC_LIST_INIT(server_list);
|
|
|
|
ISC_LIST_INIT(search_list);
|
|
|
|
|
2000-07-05 23:28:32 +00:00
|
|
|
debug("main()");
|
2000-10-16 19:00:01 +00:00
|
|
|
preparse_args(argc, argv);
|
2000-07-05 23:28:32 +00:00
|
|
|
progname = argv[0];
|
2000-07-19 17:52:27 +00:00
|
|
|
result = isc_app_start();
|
|
|
|
check_result(result, "isc_app_start");
|
2000-05-09 18:05:13 +00:00
|
|
|
setup_libs();
|
|
|
|
setup_system();
|
2014-04-17 17:04:51 -07:00
|
|
|
parse_args(ISC_FALSE, ISC_FALSE, argc, argv);
|
2014-04-18 07:27:50 -07:00
|
|
|
if (keyfile[0] != 0)
|
|
|
|
setup_file_key();
|
|
|
|
else if (keysecret[0] != 0)
|
|
|
|
setup_text_key();
|
2001-01-18 05:12:44 +00:00
|
|
|
if (domainopt[0] != '\0') {
|
|
|
|
set_search_domain(domainopt);
|
|
|
|
usesearch = ISC_TRUE;
|
|
|
|
}
|
2000-07-10 18:02:31 +00:00
|
|
|
result = isc_app_onrun(mctx, global_task, onrun_callback, NULL);
|
|
|
|
check_result(result, "isc_app_onrun");
|
2000-05-09 18:05:13 +00:00
|
|
|
isc_app_run();
|
2007-04-03 23:06:39 +00:00
|
|
|
destroy_lookup(default_lookup);
|
2000-07-18 01:28:20 +00:00
|
|
|
if (batchname != NULL) {
|
2000-08-02 17:58:07 +00:00
|
|
|
if (batchfp != stdin)
|
|
|
|
fclose(batchfp);
|
2000-07-18 01:28:20 +00:00
|
|
|
batchname = NULL;
|
|
|
|
}
|
2004-04-13 02:39:35 +00:00
|
|
|
#ifdef DIG_SIGCHASE
|
|
|
|
clean_trustedkey();
|
|
|
|
#endif
|
2000-07-14 17:57:27 +00:00
|
|
|
cancel_all();
|
|
|
|
destroy_libs();
|
2000-07-05 23:28:32 +00:00
|
|
|
isc_app_finish();
|
2000-05-16 17:53:35 +00:00
|
|
|
return (exitcode);
|
2000-05-09 18:05:13 +00:00
|
|
|
}
|