dig.c revision 31d95f1095c5bf7794c487ecb6fe62b53a802e96
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer/*
499b34cea04a46823d003d4c0520c8b03e8513cbBrian Wellington * Copyright (C) 2004-2013 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Copyright (C) 2000-2003 Internet Software Consortium.
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer *
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer * Permission to use, copy, modify, and/or distribute this software for any
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer * purpose with or without fee is hereby granted, provided that the above
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * copyright notice and this permission notice appear in all copies.
15a44745412679c30a6d022733925af70a38b715David Lawrence *
15a44745412679c30a6d022733925af70a38b715David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
15a44745412679c30a6d022733925af70a38b715David Lawrence * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15a44745412679c30a6d022733925af70a38b715David Lawrence * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
15a44745412679c30a6d022733925af70a38b715David Lawrence * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15a44745412679c30a6d022733925af70a38b715David Lawrence * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15a44745412679c30a6d022733925af70a38b715David Lawrence * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15a44745412679c30a6d022733925af70a38b715David Lawrence * PERFORMANCE OF THIS SOFTWARE.
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer */
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson/* $Id: dig.c,v 1.245 2011/12/07 17:23:28 each Exp $ */
47058d17266420179fa294de6b82d8fb5b918df4Michael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer/*! \file */
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer#include <config.h>
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer#include <stdlib.h>
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer#include <time.h>
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer#include <ctype.h>
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer#include <isc/app.h>
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer#include <isc/netaddr.h>
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington#include <isc/parseint.h>
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer#include <isc/print.h>
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer#include <isc/string.h>
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer#include <isc/util.h>
1893b56ef9f5f2bc2a0fbe80d3c6b69df1bdc7c2Michael Sawyer#include <isc/task.h>
55bf97a1b4b7f78b669b1179df1422cb9789c484Michael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer#include <dns/byaddr.h>
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer#include <dns/fixedname.h>
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer#include <dns/masterdump.h>
55bf97a1b4b7f78b669b1179df1422cb9789c484Michael Sawyer#include <dns/message.h>
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer#include <dns/name.h>
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer#include <dns/rdata.h>
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer#include <dns/rdataset.h>
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson#include <dns/rdatatype.h>
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer#include <dns/rdataclass.h>
55bf97a1b4b7f78b669b1179df1422cb9789c484Michael Sawyer#include <dns/result.h>
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer#include <dns/tsig.h>
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer#include <dig/dig.h>
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer#define ADD_STRING(b, s) { \
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer if (strlen(s) >= isc_buffer_availablelength(b)) \
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer return (ISC_R_NOSPACE); \
056aaae3e2399b2c1df8f82be52d9bd43ceda50cMichael Sawyer else \
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer isc_buffer_putstr(b, s); \
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer}
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer#define DIG_MAX_ADDRESSES 20
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerdig_lookup_t *default_lookup = NULL;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerstatic char *batchname = NULL;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerstatic FILE *batchfp = NULL;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerstatic char *argv0;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerstatic int addresscount = 0;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerstatic char domainopt[DNS_NAME_MAXTEXT];
1893b56ef9f5f2bc2a0fbe80d3c6b69df1bdc7c2Michael Sawyer
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellingtonstatic isc_boolean_t short_form = ISC_FALSE, printcmd = ISC_TRUE,
38cf6e52ce4b33795713388824b69d78e430b115Michael Sawyer ip6_int = ISC_FALSE, plusquest = ISC_FALSE, pluscomm = ISC_FALSE,
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer multiline = ISC_FALSE, nottl = ISC_FALSE, noclass = ISC_FALSE,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer onesoa = ISC_FALSE, rrcomments = ISC_FALSE, use_usec = ISC_FALSE;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerstatic isc_uint32_t splitwidth = 0xffffffff;
6c6a62933dda281cb9193de1d54d4c9e74515f5aMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer/*% opcode text */
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerstatic const char * const opcodetext[] = {
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "QUERY",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "IQUERY",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "STATUS",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "RESERVED3",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "NOTIFY",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "UPDATE",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "RESERVED6",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "RESERVED7",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "RESERVED8",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "RESERVED9",
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington "RESERVED10",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "RESERVED11",
a5ed46c9fd270775c39770bfd0250a52d374ebf2Michael Sawyer "RESERVED12",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "RESERVED13",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "RESERVED14",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "RESERVED15"
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer};
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer/*% return code text */
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerstatic const char * const rcodetext[] = {
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "NOERROR",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "FORMERR",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "SERVFAIL",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "NXDOMAIN",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "NOTIMP",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "REFUSED",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "YXDOMAIN",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "YXRRSET",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "NXRRSET",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "NOTAUTH",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "NOTZONE",
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer "RESERVED11",
a5ed46c9fd270775c39770bfd0250a52d374ebf2Michael Sawyer "RESERVED12",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "RESERVED13",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "RESERVED14",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "RESERVED15",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "BADVERS"
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer};
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington/*% safe rcodetext[] */
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellingtonstatic char *
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellingtonrcode_totext(dns_rcode_t rcode)
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington{
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington static char buf[sizeof("?65535")];
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer union {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer const char *consttext;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer char *deconsttext;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } totext;
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (rcode >= (sizeof(rcodetext)/sizeof(rcodetext[0]))) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer snprintf(buf, sizeof(buf), "?%u", rcode);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer totext.deconsttext = buf;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer totext.consttext = rcodetext[rcode];
e32394a2ac3466a2235f79ee32c247a11be42a8dAndreas Gustafsson return totext.deconsttext;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer}
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer/*% print usage */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerstatic void
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellingtonprint_usage(FILE *fp) {
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington fputs(
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington"Usage: dig [@global-server] [domain] [q-type] [q-class] {q-opt}\n"
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington" {global-d-opt} host [@local-server] {local-d-opt}\n"
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer" [ host [@local-server] {local-d-opt} [...]]\n", fp);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer}
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
78838d3e0cd62423c23de5503910e01884d2104bBrian WellingtonISC_PLATFORM_NORETURN_PRE static void
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerusage(void) ISC_PLATFORM_NORETURN_POST;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerstatic void
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerusage(void) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer print_usage(stderr);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer fputs("\nUse \"dig -h\" (or \"dig -h | more\") "
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington "for complete list of options\n", stderr);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer exit(1);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer}
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington/*% version */
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellingtonstatic void
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellingtonversion(void) {
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer fputs("DiG " VERSION "\n", stderr);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer}
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington/*% help */
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellingtonstatic void
cc48bb397fa6ba889f25157840492e68114dec8fBrian Wellingtonhelp(void) {
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington print_usage(stdout);
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington fputs(
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington"Where: domain is in the Domain Name System\n"
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington" q-class is one of (in,hs,ch,...) [default: in]\n"
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington" q-type is one of (a,any,mx,ns,soa,hinfo,axfr,txt,...) [default:a]\n"
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington" (Use ixfr=version for type ixfr)\n"
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington" q-opt is one of:\n"
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer" -x dot-notation (shortcut for reverse lookups)\n"
cc48bb397fa6ba889f25157840492e68114dec8fBrian Wellington" -i (use IP6.INT for IPv6 reverse lookups)\n"
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer" -f filename (batch mode)\n"
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer" -b address[#port] (bind to source address/port)\n"
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson" -p port (specify port number)\n"
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson" -q name (specify query name)\n"
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson" -t type (specify query type)\n"
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson" -c class (specify query class)\n"
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer" -u (display times in usec instead of msec)\n"
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer" -k keyfile (specify tsig key file)\n"
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer" -y [hmac:]name:key (specify named base64 tsig key)\n"
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer" -4 (use IPv4 query transport only)\n"
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson" -6 (use IPv6 query transport only)\n"
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson" -m (enable memory usage debugging)\n"
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson" d-opt is of the form +keyword[=value], where keyword is:\n"
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer" +[no]vc (TCP mode)\n"
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer" +[no]tcp (TCP mode, alternate syntax)\n"
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer" +time=### (Set query timeout) [5]\n"
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer" +tries=### (Set number of UDP attempts) [3]\n"
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer" +retry=### (Set number of UDP retries) [2]\n"
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer" +domain=### (Set default domainname)\n"
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer" +bufsize=### (Set EDNS0 Max UDP packet size)\n"
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer" +ndots=### (Set NDOTS value)\n"
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer" +[no]edns[=###] (Set EDNS version) [0]\n"
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer" +[no]search (Set whether to use searchlist)\n"
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews" +[no]showsearch (Search with intermediate results)\n"
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson" +[no]defname (Ditto)\n"
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson" +[no]recurse (Recursive mode)\n"
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer" +[no]ignore (Don't revert to TCP for TC responses.)"
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson"\n"
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson" +[no]fail (Don't try next server on SERVFAIL)\n"
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer" +[no]besteffort (Try to parse even illegal messages)\n"
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer" +[no]aaonly (Set AA flag in query (+[no]aaflag))\n"
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer" +[no]adflag (Set AD flag in query)\n"
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer" +[no]cdflag (Set CD flag in query)\n"
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer" +[no]cl (Control display of class in records)\n"
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer" +[no]cmd (Control display of command line)\n"
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer" +[no]comments (Control display of comment lines)\n"
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer" +[no]rrcomments (Control display of per-record "
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "comments)\n"
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer" +[no]question (Control display of question)\n"
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer" +[no]answer (Control display of answer)\n"
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer" +[no]authority (Control display of authority)\n"
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence" +[no]additional (Control display of additional)\n"
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer" +[no]stats (Control display of statistics)\n"
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer" +[no]short (Disable everything except short\n"
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer" form of answer)\n"
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer" +[no]ttlid (Control display of ttls in records)\n"
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer" +[no]all (Set or clear all display flags)\n"
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer" +[no]qr (Print question before sending)\n"
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson" +[no]nssearch (Search all authoritative nameservers)\n"
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson" +[no]identify (ID responders in short answers)\n"
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer" +[no]trace (Trace delegation down from root [+dnssec])\n"
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer" +[no]dnssec (Request DNSSEC records)\n"
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer" +[no]nsid (Request Name Server ID)\n"
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer#ifdef DIG_SIGCHASE
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer" +[no]sigchase (Chase DNSSEC signatures)\n"
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer" +trusted-key=#### (Trusted Key when chasing DNSSEC sigs)\n"
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer#if DIG_SIGCHASE_TD
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer" +[no]topdown (Do DNSSEC validation top down mode)\n"
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer#endif
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer#endif
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer" +[no]split=## (Split hex/base64 fields into chunks)\n"
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer" +[no]multiline (Print records in an expanded format)\n"
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer" +[no]onesoa (AXFR prints only one soa record)\n"
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer" global d-opts and servers (before host name) affect all queries.\n"
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer" local d-opts and servers (after host name) affect only that lookup.\n"
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer" -h (print help and exit)\n"
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer" -v (print version and exit)\n",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer stdout);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer}
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer/*%
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer * Callback from dighost.c to print the received message.
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyervoid
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerreceived(int bytes, isc_sockaddr_t *from, dig_query_t *query) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_uint64_t diff;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_time_t now;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer time_t tnow;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer struct tm tmnow;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer char time_str[100];
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer char fromtext[ISC_SOCKADDR_FORMATSIZE];
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson isc_sockaddr_format(from, fromtext, sizeof(fromtext));
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson TIME_NOW(&now);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson if (query->lookup->stats && !short_form) {
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson diff = isc_time_microdiff(&now, &query->time_sent);
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson if (use_usec)
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson printf(";; Query time: %ld usec\n", (long) diff);
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson else
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson printf(";; Query time: %ld msec\n", (long) diff / 1000);
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson printf(";; SERVER: %s(%s)\n", fromtext, query->servname);
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson time(&tnow);
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson tmnow = *localtime(&tnow);
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson if (strftime(time_str, sizeof(time_str),
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson "%a %b %d %H:%M:%S %Z %Y", &tmnow) > 0U)
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson printf(";; WHEN: %s\n", time_str);
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson if (query->lookup->doing_xfr) {
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson printf(";; XFR size: %u records (messages %u, "
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson "bytes %" ISC_PRINT_QUADFORMAT "u)\n",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer query->rr_count, query->msg_count,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer query->byte_count);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer printf(";; MSG SIZE rcvd: %u\n", bytes);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (key != NULL) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (!validated)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer puts(";; WARNING -- Some TSIG could not "
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "be validated");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson if ((key == NULL) && (keysecret[0] != 0)) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer puts(";; WARNING -- TSIG key was not used.");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer puts("");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else if (query->lookup->identify && !short_form) {
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson diff = isc_time_microdiff(&now, &query->time_sent);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (use_usec)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer printf(";; Received %" ISC_PRINT_QUADFORMAT "u bytes "
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "from %s(%s) in %ld us\n\n",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer query->lookup->doing_xfr
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence ? query->byte_count
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer : (isc_uint64_t)bytes,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer fromtext, query->userarg, (long) diff);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer else
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer printf(";; Received %" ISC_PRINT_QUADFORMAT "u bytes "
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "from %s(%s) in %ld ms\n\n",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer query->lookup->doing_xfr
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence ? query->byte_count
368b37b616234fce3d23099eb180f1dd38e1fb62Mark Andrews : (isc_uint64_t)bytes,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer fromtext, query->userarg, (long) diff / 1000);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer }
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer}
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer/*
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer * Callback from dighost.c to print that it is trying a server.
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer * Not used in dig.
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer * XXX print_trying
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyervoid
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyertrying(char *frm, dig_lookup_t *lookup) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer UNUSED(frm);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer UNUSED(lookup);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer}
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer/*%
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer * Internal print routine used to print short form replies.
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer */
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyerstatic isc_result_t
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyersay_message(dns_rdata_t *rdata, dig_query_t *query, isc_buffer_t *buf) {
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer isc_result_t result;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer isc_uint64_t diff;
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews isc_time_t now;
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer char store[sizeof("12345678901234567890")];
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson if (query->lookup->trace || query->lookup->ns_search_only) {
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer result = dns_rdatatype_totext(rdata->type, buf);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson if (result != ISC_R_SUCCESS)
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer return (result);
38cf6e52ce4b33795713388824b69d78e430b115Michael Sawyer ADD_STRING(buf, " ");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer }
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer result = dns_rdata_totext(rdata, NULL, buf);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (result == ISC_R_NOSPACE)
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer return (result);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson check_result(result, "dns_rdata_totext");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (query->lookup->identify) {
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer TIME_NOW(&now);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson diff = isc_time_microdiff(&now, &query->time_sent);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer ADD_STRING(buf, " from server ");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer ADD_STRING(buf, query->servname);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson if (use_usec)
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer snprintf(store, 19, " in %ld us.", (long) diff);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer else
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson snprintf(store, 19, " in %ld ms.", (long) diff / 1000);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer ADD_STRING(buf, store);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer }
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer ADD_STRING(buf, "\n");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer return (ISC_R_SUCCESS);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer}
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer/*%
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer * short_form message print handler. Calls above say_message()
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer */
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyerstatic isc_result_t
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyershort_answer(dns_message_t *msg, dns_messagetextflag_t flags,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer isc_buffer_t *buf, dig_query_t *query)
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer{
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence dns_name_t *name;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer dns_rdataset_t *rdataset;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer isc_result_t result, loopresult;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer dns_name_t empty_name;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer dns_rdata_t rdata = DNS_RDATA_INIT;
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer UNUSED(flags);
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer dns_name_init(&empty_name, NULL);
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer result = dns_message_firstname(msg, DNS_SECTION_ANSWER);
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer if (result == ISC_R_NOMORE)
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer return (ISC_R_SUCCESS);
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer else if (result != ISC_R_SUCCESS)
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer return (result);
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer for (;;) {
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer name = NULL;
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer dns_message_currentname(msg, DNS_SECTION_ANSWER, &name);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer for (rdataset = ISC_LIST_HEAD(name->list);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer rdataset != NULL;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer rdataset = ISC_LIST_NEXT(rdataset, link)) {
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer loopresult = dns_rdataset_first(rdataset);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer while (loopresult == ISC_R_SUCCESS) {
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer dns_rdataset_current(rdataset, &rdata);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer result = say_message(&rdata, query,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer buf);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (result == ISC_R_NOSPACE)
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer return (result);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer check_result(result, "say_message");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer loopresult = dns_rdataset_next(rdataset);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer dns_rdata_reset(&rdata);
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson }
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson }
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer result = dns_message_nextname(msg, DNS_SECTION_ANSWER);
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson if (result == ISC_R_NOMORE)
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson break;
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson else if (result != ISC_R_SUCCESS)
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson return (result);
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson }
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson return (ISC_R_SUCCESS);
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson}
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson#ifdef DIG_SIGCHASE
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafssonisc_result_t
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafssonprintrdataset(dns_name_t *owner_name, dns_rdataset_t *rdataset,
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson isc_buffer_t *target)
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson{
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson isc_result_t result;
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson dns_master_style_t *style = NULL;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer unsigned int styleflags = 0;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (rdataset == NULL || owner_name == NULL || target == NULL)
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer return(ISC_FALSE);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer styleflags |= DNS_STYLEFLAG_REL_OWNER;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (nottl)
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson styleflags |= DNS_STYLEFLAG_NO_TTL;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (noclass)
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer styleflags |= DNS_STYLEFLAG_NO_CLASS;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence if (rrcomments)
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer styleflags |= DNS_STYLEFLAG_RRCOMMENT;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (multiline) {
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer styleflags |= DNS_STYLEFLAG_OMIT_OWNER;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer styleflags |= DNS_STYLEFLAG_OMIT_CLASS;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer styleflags |= DNS_STYLEFLAG_REL_DATA;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer styleflags |= DNS_STYLEFLAG_OMIT_TTL;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence styleflags |= DNS_STYLEFLAG_TTL;
368b37b616234fce3d23099eb180f1dd38e1fb62Mark Andrews styleflags |= DNS_STYLEFLAG_MULTILINE;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer styleflags |= DNS_STYLEFLAG_COMMENT;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer styleflags |= DNS_STYLEFLAG_RRCOMMENT;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer }
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (multiline || (nottl && noclass))
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer result = dns_master_stylecreate2(&style, styleflags,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer 24, 24, 24, 32, 80, 8,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer splitwidth, mctx);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer else if (nottl || noclass)
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer result = dns_master_stylecreate2(&style, styleflags,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer 24, 24, 32, 40, 80, 8,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer splitwidth, mctx);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer else
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer result = dns_master_stylecreate2(&style, styleflags,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer 24, 32, 40, 48, 80, 8,
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer splitwidth, mctx);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer check_result(result, "dns_master_stylecreate");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer result = dns_master_rdatasettotext(owner_name, rdataset, style, target);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer if (style != NULL)
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson dns_master_styledestroy(&style, mctx);
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer return(result);
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer}
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer#endif
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer/*
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer * Callback from dighost.c to print the reply from a server
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer */
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyerisc_result_t
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyerprintmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_result_t result;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_messagetextflag_t flags;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_t *buf = NULL;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer unsigned int len = OUTPUTBUF;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_master_style_t *style = NULL;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer unsigned int styleflags = 0;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer styleflags |= DNS_STYLEFLAG_REL_OWNER;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (query->lookup->comments)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer styleflags |= DNS_STYLEFLAG_COMMENT;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (rrcomments)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer styleflags |= DNS_STYLEFLAG_RRCOMMENT;
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson if (nottl)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer styleflags |= DNS_STYLEFLAG_NO_TTL;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer if (noclass)
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer styleflags |= DNS_STYLEFLAG_NO_CLASS;
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson if (multiline) {
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer styleflags |= DNS_STYLEFLAG_OMIT_OWNER;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer styleflags |= DNS_STYLEFLAG_OMIT_CLASS;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer styleflags |= DNS_STYLEFLAG_REL_DATA;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer styleflags |= DNS_STYLEFLAG_OMIT_TTL;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer styleflags |= DNS_STYLEFLAG_TTL;
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson styleflags |= DNS_STYLEFLAG_MULTILINE;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer styleflags |= DNS_STYLEFLAG_RRCOMMENT;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (multiline || (nottl && noclass))
7804502532d6e2eee80083431a22eb5d957f52a0Michael Sawyer result = dns_master_stylecreate2(&style, styleflags,
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer 24, 24, 24, 32, 80, 8,
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer splitwidth, mctx);
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer else if (nottl || noclass)
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer result = dns_master_stylecreate2(&style, styleflags,
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer 24, 24, 32, 40, 80, 8,
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence splitwidth, mctx);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer else
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer result = dns_master_stylecreate2(&style, styleflags,
7804502532d6e2eee80083431a22eb5d957f52a0Michael Sawyer 24, 32, 40, 48, 80, 8,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer splitwidth, mctx);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer check_result(result, "dns_master_stylecreate");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (query->lookup->cmdline[0] != 0) {
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer if (!short_form)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer fputs(query->lookup->cmdline, stdout);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer query->lookup->cmdline[0]=0;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer }
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer debug("printmessage(%s %s %s)", headers ? "headers" : "noheaders",
f900be21902d02418c2c71ffed754fb3f9f54cffMichael Sawyer query->lookup->comments ? "comments" : "nocomments",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer short_form ? "short_form" : "long_form");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer flags = 0;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (!headers) {
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer flags |= DNS_MESSAGETEXTFLAG_NOHEADERS;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence flags |= DNS_MESSAGETEXTFLAG_NOCOMMENTS;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (onesoa && query->lookup->rdtype == dns_rdatatype_axfr)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer flags |= (query->msg_count == 0) ? DNS_MESSAGETEXTFLAG_ONESOA :
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer DNS_MESSAGETEXTFLAG_OMITSOA;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (!query->lookup->comments)
53e7d12ab53e74650c00ea4c0d6568bf675d8b17Michael Sawyer flags |= DNS_MESSAGETEXTFLAG_NOCOMMENTS;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer result = isc_buffer_allocate(mctx, &buf, len);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson check_result(result, "isc_buffer_allocate");
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (query->lookup->comments && !short_form) {
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (query->lookup->cmdline[0] != 0)
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer printf("; %s\n", query->lookup->cmdline);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (msg == query->lookup->sendmsg)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer printf(";; Sending:\n");
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer else
f900be21902d02418c2c71ffed754fb3f9f54cffMichael Sawyer printf(";; Got answer:\n");
f900be21902d02418c2c71ffed754fb3f9f54cffMichael Sawyer
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson if (headers) {
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson printf(";; ->>HEADER<<- opcode: %s, status: %s, "
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "id: %u\n",
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyer opcodetext[msg->opcode],
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson rcode_totext(msg->rcode),
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer msg->id);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer printf(";; flags:");
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyer if ((msg->flags & DNS_MESSAGEFLAG_QR) != 0)
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson printf(" qr");
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyer if ((msg->flags & DNS_MESSAGEFLAG_AA) != 0)
32e783c745299f838dd7cf8ffe2032775a80f1d0Andreas Gustafsson printf(" aa");
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer if ((msg->flags & DNS_MESSAGEFLAG_TC) != 0)
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer printf(" tc");
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer if ((msg->flags & DNS_MESSAGEFLAG_RD) != 0)
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer printf(" rd");
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer if ((msg->flags & DNS_MESSAGEFLAG_RA) != 0)
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer printf(" ra");
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer if ((msg->flags & DNS_MESSAGEFLAG_AD) != 0)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer printf(" ad");
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer if ((msg->flags & DNS_MESSAGEFLAG_CD) != 0)
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer printf(" cd");
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer if ((msg->flags & 0x0040U) != 0)
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer printf("; MBZ: 0x4");
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer printf("; QUERY: %u, ANSWER: %u, "
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer "AUTHORITY: %u, ADDITIONAL: %u\n",
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer msg->counts[DNS_SECTION_QUESTION],
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer msg->counts[DNS_SECTION_ANSWER],
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer msg->counts[DNS_SECTION_AUTHORITY],
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer msg->counts[DNS_SECTION_ADDITIONAL]);
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer if (msg != query->lookup->sendmsg &&
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer (msg->flags & DNS_MESSAGEFLAG_RD) != 0 &&
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer (msg->flags & DNS_MESSAGEFLAG_RA) == 0)
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer printf(";; WARNING: recursion requested "
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer "but not available\n");
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer }
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer if (msg != query->lookup->sendmsg &&
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer query->lookup->edns != -1 && msg->opt == NULL &&
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer (msg->rcode == dns_rcode_formerr ||
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer msg->rcode == dns_rcode_notimp))
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer printf("\n;; WARNING: EDNS query returned status "
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer "%s - retry with '+noedns'\n",
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer rcode_totext(msg->rcode));
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer if (msg != query->lookup->sendmsg && extrabytes != 0U)
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer printf(";; WARNING: Message has %u extra byte%s at "
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer "end\n", extrabytes, extrabytes != 0 ? "s" : "");
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer }
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyerrepopulate_buffer:
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer if (query->lookup->comments && headers && !short_form) {
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer result = dns_message_pseudosectiontotext(msg,
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer DNS_PSEUDOSECTION_OPT,
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer style, flags, buf);
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer if (result == ISC_R_NOSPACE) {
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyerbuftoosmall:
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer len += OUTPUTBUF;
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer isc_buffer_free(&buf);
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer result = isc_buffer_allocate(mctx, &buf, len);
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer if (result == ISC_R_SUCCESS)
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer goto repopulate_buffer;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer else
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer goto cleanup;
32e783c745299f838dd7cf8ffe2032775a80f1d0Andreas Gustafsson }
f900be21902d02418c2c71ffed754fb3f9f54cffMichael Sawyer check_result(result,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "dns_message_pseudosectiontotext");
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer }
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (query->lookup->section_question && headers) {
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer if (!short_form) {
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer result = dns_message_sectiontotext(msg,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer DNS_SECTION_QUESTION,
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer style, flags, buf);
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer if (result == ISC_R_NOSPACE)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer goto buftoosmall;
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer check_result(result, "dns_message_sectiontotext");
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer if (query->lookup->section_answer) {
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer if (!short_form) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer result = dns_message_sectiontotext(msg,
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer DNS_SECTION_ANSWER,
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer style, flags, buf);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (result == ISC_R_NOSPACE)
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer goto buftoosmall;
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer check_result(result, "dns_message_sectiontotext");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else {
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer result = short_answer(msg, flags, buf, query);
8e61de2efdc23d1248cff0abf4cadec3325a929cMichael Sawyer if (result == ISC_R_NOSPACE)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer goto buftoosmall;
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer check_result(result, "short_answer");
8e61de2efdc23d1248cff0abf4cadec3325a929cMichael Sawyer }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (query->lookup->section_authority) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (!short_form) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer result = dns_message_sectiontotext(msg,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer DNS_SECTION_AUTHORITY,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer style, flags, buf);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (result == ISC_R_NOSPACE)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer goto buftoosmall;
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer check_result(result, "dns_message_sectiontotext");
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer }
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer }
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer if (query->lookup->section_additional) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (!short_form) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer result = dns_message_sectiontotext(msg,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer DNS_SECTION_ADDITIONAL,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer style, flags, buf);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (result == ISC_R_NOSPACE)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer goto buftoosmall;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer check_result(result, "dns_message_sectiontotext");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer /*
8e61de2efdc23d1248cff0abf4cadec3325a929cMichael Sawyer * Only print the signature on the first record.
8e61de2efdc23d1248cff0abf4cadec3325a929cMichael Sawyer */
8e61de2efdc23d1248cff0abf4cadec3325a929cMichael Sawyer if (headers) {
8e61de2efdc23d1248cff0abf4cadec3325a929cMichael Sawyer result = dns_message_pseudosectiontotext(
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer msg,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer DNS_PSEUDOSECTION_TSIG,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer style, flags, buf);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (result == ISC_R_NOSPACE)
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyer goto buftoosmall;
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyer check_result(result,
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyer "dns_message_pseudosectiontotext");
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyer result = dns_message_pseudosectiontotext(
aa2c453d3c6e416b56b29247bedd9a0af2721e93Mark Andrews msg,
aa2c453d3c6e416b56b29247bedd9a0af2721e93Mark Andrews DNS_PSEUDOSECTION_SIG0,
aa2c453d3c6e416b56b29247bedd9a0af2721e93Mark Andrews style, flags, buf);
aa2c453d3c6e416b56b29247bedd9a0af2721e93Mark Andrews if (result == ISC_R_NOSPACE)
f8fec75ee8f429821137aee090f56ab678404a56Michael Sawyer goto buftoosmall;
6c6a62933dda281cb9193de1d54d4c9e74515f5aMichael Sawyer check_result(result,
48674819ebf9176b5d5582ae851e485c324c1159Michael Sawyer "dns_message_pseudosectiontotext");
1416cae3f614faf4067e8b5a6b4732e132958bbaAndreas Gustafsson }
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer }
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer }
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
869f65bea49f8d65ab9bb14c4551215529bd7419David Lawrence if (headers && query->lookup->comments && !short_form)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer printf("\n");
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer printf("%.*s", (int)isc_buffer_usedlength(buf),
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer (char *)isc_buffer_base(buf));
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer isc_buffer_free(&buf);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer
5d20773abcdf9ff3afe14a349413174f94594188Michael Sawyercleanup:
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (style != NULL)
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson dns_master_styledestroy(&style, mctx);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer return (result);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer}
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer/*%
32e783c745299f838dd7cf8ffe2032775a80f1d0Andreas Gustafsson * print the greeting message when the program first starts up.
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer */
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyerstatic void
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyerprintgreeting(int argc, char **argv, dig_lookup_t *lookup) {
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer int i;
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer int remaining;
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer static isc_boolean_t first = ISC_TRUE;
32e783c745299f838dd7cf8ffe2032775a80f1d0Andreas Gustafsson char append[MXNAME];
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer if (printcmd) {
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer lookup->cmdline[sizeof(lookup->cmdline) - 1] = 0;
5d20773abcdf9ff3afe14a349413174f94594188Michael Sawyer snprintf(lookup->cmdline, sizeof(lookup->cmdline),
5d20773abcdf9ff3afe14a349413174f94594188Michael Sawyer "%s; <<>> DiG " VERSION " <<>>",
55bf97a1b4b7f78b669b1179df1422cb9789c484Michael Sawyer first?"\n":"");
cc7732e1299042bff430dfdfbc2624fb340047b2Michael Sawyer i = 1;
55bf97a1b4b7f78b669b1179df1422cb9789c484Michael Sawyer while (i < argc) {
5d20773abcdf9ff3afe14a349413174f94594188Michael Sawyer snprintf(append, sizeof(append), " %s", argv[i++]);
55bf97a1b4b7f78b669b1179df1422cb9789c484Michael Sawyer remaining = sizeof(lookup->cmdline) -
cc7732e1299042bff430dfdfbc2624fb340047b2Michael Sawyer strlen(lookup->cmdline) - 1;
55bf97a1b4b7f78b669b1179df1422cb9789c484Michael Sawyer strncat(lookup->cmdline, append, remaining);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer }
cc7732e1299042bff430dfdfbc2624fb340047b2Michael Sawyer remaining = sizeof(lookup->cmdline) -
cd720113a2fc8a781d4e33350b8a2b62857b31d8David Lawrence strlen(lookup->cmdline) - 1;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer strncat(lookup->cmdline, "\n", remaining);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (first && addresscount != 0) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer snprintf(append, sizeof(append),
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "; (%d server%s found)\n",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer addresscount,
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer addresscount > 1 ? "s" : "");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer remaining = sizeof(lookup->cmdline) -
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer strlen(lookup->cmdline) - 1;
9fe3676b8490319aa65182f2072cbf5086097979Michael Sawyer strncat(lookup->cmdline, append, remaining);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (first) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer snprintf(append, sizeof(append),
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ";; global options:%s%s\n",
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer short_form ? " +short" : "",
17747cd5ee98901b435cd2b3019c52937955a981Michael Sawyer printcmd ? " +cmd" : "");
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer first = ISC_FALSE;
8e61de2efdc23d1248cff0abf4cadec3325a929cMichael Sawyer remaining = sizeof(lookup->cmdline) -
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer strlen(lookup->cmdline) - 1;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer strncat(lookup->cmdline, append, remaining);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer }
38cf6e52ce4b33795713388824b69d78e430b115Michael Sawyer }
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer}
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer/*%
cd720113a2fc8a781d4e33350b8a2b62857b31d8David Lawrence * We're not using isc_commandline_parse() here since the command line
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer * syntax of dig is quite a bit different from that which can be described
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer * by that routine.
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington * XXX doc options
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerstatic void
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerplus_option(char *option, isc_boolean_t is_batchfile,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dig_lookup_t *lookup)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer{
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_result_t result;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer char option_store[256];
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer char *cmd, *value, *ptr;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence isc_uint32_t num;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_boolean_t state = ISC_TRUE;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer#ifdef DIG_SIGCHASE
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer size_t n;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer#endif
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer strncpy(option_store, option, sizeof(option_store));
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer option_store[sizeof(option_store)-1]=0;
f900be21902d02418c2c71ffed754fb3f9f54cffMichael Sawyer ptr = option_store;
f900be21902d02418c2c71ffed754fb3f9f54cffMichael Sawyer cmd = next_token(&ptr,"=");
f900be21902d02418c2c71ffed754fb3f9f54cffMichael Sawyer if (cmd == NULL) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer printf(";; Invalid option %s\n", option_store);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer return;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer value = ptr;
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer if (strncasecmp(cmd, "no", 2)==0) {
6fda1577669dca9e0d8e4832e407bac34cc12de6Mark Andrews cmd += 2;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer state = ISC_FALSE;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
cd720113a2fc8a781d4e33350b8a2b62857b31d8David Lawrence#define FULLCHECK(A) \
07a926724c0a91d85b85a94441938d0094e88cffMark Andrews do { \
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer size_t _l = strlen(cmd); \
07a926724c0a91d85b85a94441938d0094e88cffMark Andrews if (_l >= sizeof(A) || strncasecmp(cmd, A, _l) != 0) \
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer goto invalid_option; \
07a926724c0a91d85b85a94441938d0094e88cffMark Andrews } while (0)
07a926724c0a91d85b85a94441938d0094e88cffMark Andrews#define FULLCHECK2(A, B) \
07a926724c0a91d85b85a94441938d0094e88cffMark Andrews do { \
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer size_t _l = strlen(cmd); \
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer if ((_l >= sizeof(A) || strncasecmp(cmd, A, _l) != 0) && \
07a926724c0a91d85b85a94441938d0094e88cffMark Andrews (_l >= sizeof(B) || strncasecmp(cmd, B, _l) != 0)) \
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer goto invalid_option; \
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } while (0)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
07a926724c0a91d85b85a94441938d0094e88cffMark Andrews switch (cmd[0]) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer case 'a':
07a926724c0a91d85b85a94441938d0094e88cffMark Andrews switch (cmd[1]) {
e412ae947df6de858883564b8676a9650df70d9aMark Andrews case 'a': /* aaonly / aaflag */
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington FULLCHECK2("aaonly", "aaflag");
07a926724c0a91d85b85a94441938d0094e88cffMark Andrews lookup->aaonly = state;
e412ae947df6de858883564b8676a9650df70d9aMark Andrews break;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer case 'd':
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer switch (cmd[2]) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer case 'd': /* additional */
f900be21902d02418c2c71ffed754fb3f9f54cffMichael Sawyer FULLCHECK("additional");
f900be21902d02418c2c71ffed754fb3f9f54cffMichael Sawyer lookup->section_additional = state;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer break;
f900be21902d02418c2c71ffed754fb3f9f54cffMichael Sawyer case 'f': /* adflag */
6e3a8e17fdf108f47bbba17474fd3d120d356b2fBrian Wellington case '\0': /* +ad is a synonym for +adflag */
6e3a8e17fdf108f47bbba17474fd3d120d356b2fBrian Wellington FULLCHECK("adflag");
07a926724c0a91d85b85a94441938d0094e88cffMark Andrews lookup->adflag = state;
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington break;
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington default:
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington goto invalid_option;
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington }
07a926724c0a91d85b85a94441938d0094e88cffMark Andrews break;
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington case 'l': /* all */
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington FULLCHECK("all");
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington lookup->section_question = state;
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington lookup->section_authority = state;
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington lookup->section_answer = state;
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington lookup->section_additional = state;
07a926724c0a91d85b85a94441938d0094e88cffMark Andrews lookup->comments = state;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence rrcomments = state;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer lookup->stats = state;
07a926724c0a91d85b85a94441938d0094e88cffMark Andrews printcmd = state;
07a926724c0a91d85b85a94441938d0094e88cffMark Andrews break;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer case 'n': /* answer */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer FULLCHECK("answer");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer lookup->section_answer = state;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer break;
19c8df90f1f23c3df870c1771c89c1acdb15020eMichael Sawyer case 'u': /* authority */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer FULLCHECK("authority");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer lookup->section_authority = state;
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson break;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer default:
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer goto invalid_option;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
19c8df90f1f23c3df870c1771c89c1acdb15020eMichael Sawyer break;
19c8df90f1f23c3df870c1771c89c1acdb15020eMichael Sawyer case 'b':
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer switch (cmd[1]) {
19c8df90f1f23c3df870c1771c89c1acdb15020eMichael Sawyer case 'e':/* besteffort */
19c8df90f1f23c3df870c1771c89c1acdb15020eMichael Sawyer FULLCHECK("besteffort");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer lookup->besteffort = state;
869f65bea49f8d65ab9bb14c4551215529bd7419David Lawrence break;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer case 'u':/* bufsize */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer FULLCHECK("bufsize");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (value == NULL)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer goto need_value;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (!state)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer goto invalid_option;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer result = parse_uint(&num, value, COMMSIZE,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer "buffer size");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (result != ISC_R_SUCCESS)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer fatal("Couldn't parse buffer size");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer lookup->udpsize = num;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer break;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer default:
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer goto invalid_option;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer break;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer case 'c':
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer switch (cmd[1]) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer case 'd':/* cdflag */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer switch (cmd[2]) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer case 'f': /* cdflag */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer case '\0': /* +cd is a synonym for +cdflag */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer FULLCHECK("cdflag");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer lookup->cdflag = state;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer break;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer default:
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer goto invalid_option;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer break;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer case 'l': /* cl */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer FULLCHECK("cl");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer noclass = ISC_TF(!state);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer break;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer case 'm': /* cmd */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer FULLCHECK("cmd");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer printcmd = state;
e715e011788a529446b8013239c33599542ece32Michael Sawyer break;
e715e011788a529446b8013239c33599542ece32Michael Sawyer case 'o': /* comments */
e715e011788a529446b8013239c33599542ece32Michael Sawyer FULLCHECK("comments");
e715e011788a529446b8013239c33599542ece32Michael Sawyer lookup->comments = state;
e715e011788a529446b8013239c33599542ece32Michael Sawyer if (lookup == default_lookup)
e715e011788a529446b8013239c33599542ece32Michael Sawyer pluscomm = state;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence break;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer default:
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer goto invalid_option;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer break;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer case 'd':
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer switch (cmd[1]) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer case 'e': /* defname */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer FULLCHECK("defname");
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (!lookup->trace) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer usesearch = state;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer break;
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington case 'n': /* dnssec */
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington FULLCHECK("dnssec");
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington if (state && lookup->edns == -1)
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington lookup->edns = 0;
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington lookup->dnssec = state;
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer break;
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer case 'o': /* domain */
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer FULLCHECK("domain");
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer if (value == NULL)
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer goto need_value;
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer if (!state)
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer goto invalid_option;
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer strncpy(domainopt, value, sizeof(domainopt));
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington domainopt[sizeof(domainopt)-1] = '\0';
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington break;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer default:
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer goto invalid_option;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer }
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer break;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer case 'e':
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer FULLCHECK("edns");
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer if (!state) {
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer lookup->edns = -1;
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington break;
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington }
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington if (value == NULL) {
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer lookup->edns = 0;
38cf6e52ce4b33795713388824b69d78e430b115Michael Sawyer break;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer result = parse_uint(&num, value, 255, "edns");
f8fec75ee8f429821137aee090f56ab678404a56Michael Sawyer if (result != ISC_R_SUCCESS)
6c6a62933dda281cb9193de1d54d4c9e74515f5aMichael Sawyer fatal("Couldn't parse edns");
88301f84d1391e96ec87a9a308aa18f45553a56bAndreas Gustafsson lookup->edns = num;
6c6a62933dda281cb9193de1d54d4c9e74515f5aMichael Sawyer break;
ad7bb5bff3e796f5648835bf87a203d23d8319e4David Lawrence case 'f': /* fail */
88301f84d1391e96ec87a9a308aa18f45553a56bAndreas Gustafsson FULLCHECK("fail");
f8fec75ee8f429821137aee090f56ab678404a56Michael Sawyer lookup->servfail_stops = state;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer break;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer case 'i':
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington switch (cmd[1]) {
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington case 'd': /* identify */
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington FULLCHECK("identify");
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington lookup->identify = state;
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington break;
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington case 'g': /* ignore */
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington default: /* Inherits default for compatibility */
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer FULLCHECK("ignore");
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington lookup->ignore = ISC_TRUE;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer }
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson break;
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson case 'm': /* multiline */
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington FULLCHECK("multiline");
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington multiline = state;
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer break;
db8b100cae62de849ecf4ba9ad3be811fb375b53Michael Sawyer case 'n':
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence switch (cmd[1]) {
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer case 'd': /* ndots */
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer FULLCHECK("ndots");
if (value == NULL)
goto need_value;
if (!state)
goto invalid_option;
result = parse_uint(&num, value, MAXNDOTS, "ndots");
if (result != ISC_R_SUCCESS)
fatal("Couldn't parse ndots");
ndots = num;
break;
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;
rrcomments = ISC_FALSE;
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;
}
break;
default:
goto invalid_option;
}
break;
case 'o':
FULLCHECK("onesoa");
onesoa = state;
break;
case 'q':
switch (cmd[1]) {
case 'r': /* qr */
FULLCHECK("qr");
qr = state;
break;
case 'u': /* question */
FULLCHECK("question");
lookup->section_question = state;
if (lookup == default_lookup)
plusquest = state;
break;
default:
goto invalid_option;
}
break;
case 'r':
switch (cmd[1]) {
case 'e':
switch (cmd[2]) {
case 'c': /* recurse */
FULLCHECK("recurse");
lookup->recurse = state;
break;
case 't': /* retry / retries */
FULLCHECK2("retry", "retries");
if (value == NULL)
goto need_value;
if (!state)
goto invalid_option;
result = parse_uint(&lookup->retries, value,
MAXTRIES - 1, "retries");
if (result != ISC_R_SUCCESS)
fatal("Couldn't parse retries");
lookup->retries++;
break;
default:
goto invalid_option;
}
break;
case 'r': /* rrcomments */
FULLCHECK("rrcomments");
rrcomments = state;
break;
default:
goto invalid_option;
}
break;
case 's':
switch (cmd[1]) {
case 'e': /* search */
FULLCHECK("search");
if (!lookup->trace) {
usesearch = state;
}
break;
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;
rrcomments = ISC_FALSE;
lookup->stats = ISC_FALSE;
}
break;
case 'w': /* showsearch */
FULLCHECK("showsearch");
if (!lookup->trace) {
showsearch = state;
usesearch = state;
}
break;
default:
goto invalid_option;
}
break;
#ifdef DIG_SIGCHASE
case 'i': /* sigchase */
FULLCHECK("sigchase");
lookup->sigchase = state;
if (lookup->sigchase)
lookup->dnssec = ISC_TRUE;
break;
#endif
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)
fatal("Couldn't parse retries");
break;
case 't': /* stats */
FULLCHECK("stats");
lookup->stats = state;
break;
default:
goto invalid_option;
}
break;
case 't':
switch (cmd[1]) {
case 'c': /* tcp */
FULLCHECK("tcp");
if (!is_batchfile)
lookup->tcp_mode = state;
break;
case 'i': /* timeout */
FULLCHECK("timeout");
if (value == NULL)
goto need_value;
if (!state)
goto invalid_option;
result = parse_uint(&timeout, value, MAXTIMEOUT,
"timeout");
if (result != ISC_R_SUCCESS)
fatal("Couldn't parse timeout");
if (timeout == 0)
timeout = 1;
break;
#if DIG_SIGCHASE_TD
case 'o': /* topdown */
FULLCHECK("topdown");
lookup->do_topdown = state;
break;
#endif
case 'r':
switch (cmd[2]) {
case 'a': /* trace */
FULLCHECK("trace");
lookup->trace = state;
lookup->trace_root = state;
if (state) {
lookup->recurse = ISC_FALSE;
lookup->identify = ISC_TRUE;
lookup->comments = ISC_FALSE;
rrcomments = ISC_FALSE;
lookup->stats = ISC_FALSE;
lookup->section_additional = ISC_FALSE;
lookup->section_authority = ISC_TRUE;
lookup->section_question = ISC_FALSE;
lookup->dnssec = ISC_TRUE;
usesearch = ISC_FALSE;
}
break;
case 'i': /* tries */
FULLCHECK("tries");
if (value == NULL)
goto need_value;
if (!state)
goto invalid_option;
result = parse_uint(&lookup->retries, value,
MAXTRIES, "tries");
if (result != ISC_R_SUCCESS)
fatal("Couldn't parse tries");
if (lookup->retries == 0)
lookup->retries = 1;
break;
#ifdef DIG_SIGCHASE
case 'u': /* trusted-key */
FULLCHECK("trusted-key");
if (value == NULL)
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
default:
goto invalid_option;
}
break;
case 't': /* ttlid */
FULLCHECK("ttlid");
nottl = ISC_TF(!state);
break;
default:
goto invalid_option;
}
break;
case 'v':
FULLCHECK("vc");
if (!is_batchfile)
lookup->tcp_mode = state;
break;
default:
invalid_option:
need_value:
fprintf(stderr, "Invalid option: +%s\n",
option);
usage();
}
return;
}
/*%
* #ISC_TRUE returned if value was used
*/
static const char *single_dash_opts = "46dhimnuv";
static const char *dash_opts = "46bcdfhikmnptvyx";
static isc_boolean_t
dash_option(char *option, char *next, dig_lookup_t **lookup,
isc_boolean_t *open_type_class, isc_boolean_t *need_clone,
isc_boolean_t config_only, int argc, char **argv,
isc_boolean_t *firstarg)
{
char opt, *value, *ptr, *ptr2, *ptr3;
isc_result_t result;
isc_boolean_t value_from_next;
isc_textregion_t tr;
dns_rdatatype_t rdtype;
dns_rdataclass_t rdclass;
char textname[MXNAME];
struct in_addr in4;
struct in6_addr in6;
in_port_t srcport;
char *hash, *cmd;
isc_uint32_t num;
while (strpbrk(option, single_dash_opts) == &option[0]) {
/*
* Since the -[46dhimnuv] options do not take an argument,
* 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");
/* NOTREACHED */
return (ISC_FALSE);
}
break;
case '6':
if (have_ipv6) {
isc_net_disableipv4();
have_ipv4 = ISC_FALSE;
} else {
fatal("can't find IPv6 networking");
/* NOTREACHED */
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;
case 'u':
use_usec = ISC_TRUE;
break;
case 'v':
version();
exit(0);
break;
}
if (strlen(option) > 1U)
option = &option[1];
else
return (ISC_FALSE);
}
opt = option[0];
if (strlen(option) > 1U) {
value_from_next = ISC_FALSE;
value = &option[1];
} else {
value_from_next = ISC_TRUE;
value = next;
}
if (value == NULL)
goto invalid_option;
switch (opt) {
case 'b':
hash = strchr(value, '#');
if (hash != NULL) {
result = parse_uint(&num, hash + 1, MAXPORT,
"port number");
if (result != ISC_R_SUCCESS)
fatal("Couldn't parse port number");
srcport = num;
*hash = '\0';
} else
srcport = 0;
if (have_ipv6 && inet_pton(AF_INET6, value, &in6) == 1) {
isc_sockaddr_fromin6(&bind_address, &in6, srcport);
isc_net_disableipv4();
} else if (have_ipv4 && inet_pton(AF_INET, value, &in4) == 1) {
isc_sockaddr_fromin(&bind_address, &in4, srcport);
isc_net_disableipv6();
} else {
if (hash != NULL)
*hash = '#';
fatal("invalid address %s", value);
}
if (hash != NULL)
*hash = '#';
specified_source = ISC_TRUE;
return (value_from_next);
case 'c':
if ((*lookup)->rdclassset) {
fprintf(stderr, ";; Warning, extra class option\n");
}
*open_type_class = ISC_FALSE;
tr.base = value;
tr.length = strlen(value);
result = dns_rdataclass_fromtext(&rdclass,
(isc_textregion_t *)&tr);
if (result == ISC_R_SUCCESS) {
(*lookup)->rdclass = rdclass;
(*lookup)->rdclassset = ISC_TRUE;
} else
fprintf(stderr, ";; Warning, ignoring "
"invalid class %s\n",
value);
return (value_from_next);
case 'f':
batchname = value;
return (value_from_next);
case 'k':
strncpy(keyfile, value, sizeof(keyfile));
keyfile[sizeof(keyfile)-1]=0;
return (value_from_next);
case 'p':
result = parse_uint(&num, value, MAXPORT, "port number");
if (result != ISC_R_SUCCESS)
fatal("Couldn't parse port number");
port = num;
return (value_from_next);
case 'q':
if (!config_only) {
if (*need_clone)
(*lookup) = clone_lookup(default_lookup,
ISC_TRUE);
*need_clone = ISC_TRUE;
strncpy((*lookup)->textname, value,
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;
if (*firstarg) {
printgreeting(argc, argv, *lookup);
*firstarg = ISC_FALSE;
}
ISC_LIST_APPEND(lookup_list, (*lookup), link);
debug("looking up %s", (*lookup)->textname);
}
return (value_from_next);
case 't':
*open_type_class = ISC_FALSE;
if (strncasecmp(value, "ixfr=", 5) == 0) {
rdtype = dns_rdatatype_ixfr;
result = ISC_R_SUCCESS;
} else {
tr.base = value;
tr.length = strlen(value);
result = dns_rdatatype_fromtext(&rdtype,
(isc_textregion_t *)&tr);
if (result == ISC_R_SUCCESS &&
rdtype == dns_rdatatype_ixfr) {
result = DNS_R_UNKNOWN;
}
}
if (result == ISC_R_SUCCESS) {
if ((*lookup)->rdtypeset) {
fprintf(stderr, ";; Warning, "
"extra type option\n");
}
if (rdtype == dns_rdatatype_ixfr) {
isc_uint32_t serial;
(*lookup)->rdtype = dns_rdatatype_ixfr;
(*lookup)->rdtypeset = ISC_TRUE;
result = parse_uint(&serial, &value[5],
MAXSERIAL, "serial number");
if (result != ISC_R_SUCCESS)
fatal("Couldn't parse serial number");
(*lookup)->ixfr_serial = serial;
(*lookup)->section_question = plusquest;
(*lookup)->comments = pluscomm;
(*lookup)->tcp_mode = ISC_TRUE;
} else {
(*lookup)->rdtype = rdtype;
(*lookup)->rdtypeset = ISC_TRUE;
if (rdtype == dns_rdatatype_axfr) {
(*lookup)->section_question = plusquest;
(*lookup)->comments = pluscomm;
}
(*lookup)->ixfr_serial = ISC_FALSE;
}
} else
fprintf(stderr, ";; Warning, ignoring "
"invalid type %s\n",
value);
return (value_from_next);
case 'y':
ptr = next_token(&value,":"); /* hmac type or name */
if (ptr == NULL) {
usage();
}
ptr2 = next_token(&value, ":"); /* name or secret */
if (ptr2 == NULL)
usage();
ptr3 = next_token(&value,":"); /* secret or NULL */
if (ptr3 != NULL) {
parse_hmac(ptr);
ptr = ptr2;
ptr2 = ptr3;
} else {
hmacname = DNS_TSIG_HMACMD5_NAME;
digestbits = 0;
}
strncpy(keynametext, ptr, sizeof(keynametext));
keynametext[sizeof(keynametext)-1]=0;
strncpy(keysecret, ptr2, sizeof(keysecret));
keysecret[sizeof(keysecret)-1]=0;
return (value_from_next);
case 'x':
if (*need_clone)
*lookup = clone_lookup(default_lookup, ISC_TRUE);
*need_clone = ISC_TRUE;
if (get_reverse(textname, sizeof(textname), value,
ip6_int, ISC_FALSE) == ISC_R_SUCCESS) {
strncpy((*lookup)->textname, textname,
sizeof((*lookup)->textname));
debug("looking up %s", (*lookup)->textname);
(*lookup)->trace_root = ISC_TF((*lookup)->trace ||
(*lookup)->ns_search_only);
(*lookup)->ip6_int = ip6_int;
if (!(*lookup)->rdtypeset)
(*lookup)->rdtype = dns_rdatatype_ptr;
if (!(*lookup)->rdclassset)
(*lookup)->rdclass = dns_rdataclass_in;
(*lookup)->new_search = ISC_TRUE;
if (*firstarg) {
printgreeting(argc, argv, *lookup);
*firstarg = ISC_FALSE;
}
ISC_LIST_APPEND(lookup_list, *lookup, link);
} else {
fprintf(stderr, "Invalid IP address %s\n", value);
exit(1);
}
return (value_from_next);
invalid_option:
default:
fprintf(stderr, "Invalid option: -%s\n", option);
usage();
}
/* NOTREACHED */
return (ISC_FALSE);
}
/*%
* 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.
*
* 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;
char *option;
rc = argc;
rv = argv;
for (rc--, rv++; rc > 0; rc--, rv++) {
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];
}
}
}
static void
parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
int argc, char **argv) {
isc_result_t result;
isc_textregion_t tr;
isc_boolean_t firstarg = ISC_TRUE;
dig_lookup_t *lookup = NULL;
dns_rdatatype_t rdtype;
dns_rdataclass_t rdclass;
isc_boolean_t open_type_class = ISC_TRUE;
char batchline[MXNAME];
int bargc;
char *bargv[64];
int rc;
char **rv;
#ifndef NOPOSIX
char *homedir;
char rcfile[256];
#endif
char *input;
int i;
isc_boolean_t need_clone = ISC_TRUE;
/*
* 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.
*
* First, create a "default lookup" which won't actually be used
* anywhere, except for cloning into new lookups
*/
debug("parse_args()");
if (!is_batchfile) {
debug("making new lookup");
default_lookup = make_empty_lookup();
default_lookup->adflag = ISC_TRUE;
default_lookup->edns = 0;
#ifndef NOPOSIX
/*
* Treat ${HOME}/.digrc as a special batchfile
*/
INSIST(batchfp == NULL);
homedir = getenv("HOME");
if (homedir != NULL) {
unsigned int n;
n = snprintf(rcfile, sizeof(rcfile), "%s/.digrc",
homedir);
if (n < sizeof(rcfile))
batchfp = fopen(rcfile, "r");
}
if (batchfp != NULL) {
while (fgets(batchline, sizeof(batchline),
batchfp) != 0) {
debug("config line %s", batchline);
bargc = 1;
input = batchline;
bargv[bargc] = next_token(&input, " \t\r\n");
while ((bargv[bargc] != NULL) &&
(bargc < 62)) {
bargc++;
bargv[bargc] =
next_token(&input, " \t\r\n");
}
bargv[0] = argv[0];
argv0 = argv[0];
for(i = 0; i < bargc; i++)
debug(".digrc argv %d: %s",
i, bargv[i]);
parse_args(ISC_TRUE, ISC_TRUE, bargc,
(char **)bargv);
}
fclose(batchfp);
}
#endif
}
if (is_batchfile && !config_only) {
/* Processing '-f batchfile'. */
lookup = clone_lookup(default_lookup, ISC_TRUE);
need_clone = ISC_FALSE;
} else
lookup = default_lookup;
rc = argc;
rv = argv;
for (rc--, rv++; rc > 0; rc--, rv++) {
debug("main parsing %s", rv[0]);
if (strncmp(rv[0], "%", 1) == 0)
break;
if (strncmp(rv[0], "@", 1) == 0) {
addresscount = getaddresses(lookup, &rv[0][1], NULL);
} 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,
&lookup, &open_type_class,
&need_clone, config_only,
argc, argv, &firstarg)) {
rc--;
rv++;
}
} else {
if (dash_option(&rv[0][1], rv[1],
&lookup, &open_type_class,
&need_clone, config_only,
argc, argv, &firstarg)) {
rc--;
rv++;
}
}
} else {
/*
* Anything which isn't an option
*/
if (open_type_class) {
if (strncasecmp(rv[0], "ixfr=", 5) == 0) {
rdtype = dns_rdatatype_ixfr;
result = ISC_R_SUCCESS;
} else {
tr.base = rv[0];
tr.length = strlen(rv[0]);
result = dns_rdatatype_fromtext(&rdtype,
(isc_textregion_t *)&tr);
if (result == ISC_R_SUCCESS &&
rdtype == dns_rdatatype_ixfr) {
fprintf(stderr, ";; Warning, "
"ixfr requires a "
"serial number\n");
continue;
}
}
if (result == ISC_R_SUCCESS) {
if (lookup->rdtypeset) {
fprintf(stderr, ";; Warning, "
"extra type option\n");
}
if (rdtype == dns_rdatatype_ixfr) {
isc_uint32_t serial;
lookup->rdtype =
dns_rdatatype_ixfr;
lookup->rdtypeset = ISC_TRUE;
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;
lookup->section_question =
plusquest;
lookup->comments = pluscomm;
lookup->tcp_mode = ISC_TRUE;
} else {
lookup->rdtype = rdtype;
lookup->rdtypeset = ISC_TRUE;
if (rdtype ==
dns_rdatatype_axfr) {
lookup->section_question =
plusquest;
lookup->comments = pluscomm;
}
lookup->ixfr_serial = ISC_FALSE;
}
continue;
}
result = dns_rdataclass_fromtext(&rdclass,
(isc_textregion_t *)&tr);
if (result == ISC_R_SUCCESS) {
if (lookup->rdclassset) {
fprintf(stderr, ";; Warning, "
"extra class option\n");
}
lookup->rdclass = rdclass;
lookup->rdclassset = ISC_TRUE;
continue;
}
}
if (!config_only) {
if (need_clone)
lookup = clone_lookup(default_lookup,
ISC_TRUE);
need_clone = ISC_TRUE;
strncpy(lookup->textname, rv[0],
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;
if (firstarg) {
printgreeting(argc, argv, lookup);
firstarg = ISC_FALSE;
}
ISC_LIST_APPEND(lookup_list, lookup, link);
debug("looking up %s", lookup->textname);
}
/* XXX Error message */
}
}
/*
* 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)) {
if (strcmp(batchname, "-") == 0)
batchfp = stdin;
else
batchfp = fopen(batchname, "r");
if (batchfp == NULL) {
perror(batchname);
if (exitcode < 8)
exitcode = 8;
fatal("couldn't open specified batch file");
}
/* XXX Remove code dup from shutdown code */
next_line:
if (fgets(batchline, sizeof(batchline), batchfp) != 0) {
bargc = 1;
debug("batch line %s", batchline);
if (batchline[0] == '\r' || batchline[0] == '\n'
|| batchline[0] == '#' || batchline[0] == ';')
goto next_line;
input = batchline;
bargv[bargc] = next_token(&input, " \t\r\n");
while ((bargv[bargc] != NULL) && (bargc < 14)) {
bargc++;
bargv[bargc] = next_token(&input, " \t\r\n");
}
bargv[0] = argv[0];
argv0 = argv[0];
for(i = 0; i < bargc; i++)
debug("batch argv %d: %s", i, bargv[i]);
parse_args(ISC_TRUE, ISC_FALSE, bargc, (char **)bargv);
return;
}
return;
}
/*
* If no lookup specified, search for root
*/
if ((lookup_list.head == NULL) && !config_only) {
if (need_clone)
lookup = clone_lookup(default_lookup, ISC_TRUE);
need_clone = ISC_TRUE;
lookup->trace_root = ISC_TF(lookup->trace ||
lookup->ns_search_only);
lookup->new_search = ISC_TRUE;
strcpy(lookup->textname, ".");
lookup->rdtype = dns_rdatatype_ns;
lookup->rdtypeset = ISC_TRUE;
if (firstarg) {
printgreeting(argc, argv, lookup);
firstarg = ISC_FALSE;
}
ISC_LIST_APPEND(lookup_list, lookup, link);
}
if (!need_clone)
destroy_lookup(lookup);
}
/*
* 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.
*/
void
dighost_shutdown(void) {
char batchline[MXNAME];
int bargc;
char *bargv[16];
char *input;
int i;
if (batchname == NULL) {
isc_app_shutdown();
return;
}
fflush(stdout);
if (feof(batchfp)) {
batchname = NULL;
isc_app_shutdown();
if (batchfp != stdin)
fclose(batchfp);
return;
}
if (fgets(batchline, sizeof(batchline), batchfp) != 0) {
debug("batch line %s", batchline);
bargc = 1;
input = batchline;
bargv[bargc] = next_token(&input, " \t\r\n");
while ((bargv[bargc] != NULL) && (bargc < 14)) {
bargc++;
bargv[bargc] = next_token(&input, " \t\r\n");
}
bargv[0] = argv0;
for(i = 0; i < bargc; i++)
debug("batch argv %d: %s", i, bargv[i]);
parse_args(ISC_TRUE, ISC_FALSE, bargc, (char **)bargv);
start_lookup();
} else {
batchname = NULL;
if (batchfp != stdin)
fclose(batchfp);
isc_app_shutdown();
return;
}
}
/*% Main processing routine for dig */
int
main(int argc, char **argv) {
isc_result_t result;
ISC_LIST_INIT(lookup_list);
ISC_LIST_INIT(server_list);
ISC_LIST_INIT(search_list);
debug("main()");
preparse_args(argc, argv);
progname = argv[0];
result = isc_app_start();
check_result(result, "isc_app_start");
setup_libs();
parse_args(ISC_FALSE, ISC_FALSE, argc, argv);
setup_system();
if (domainopt[0] != '\0') {
set_search_domain(domainopt);
usesearch = ISC_TRUE;
}
result = isc_app_onrun(mctx, global_task, onrun_callback, NULL);
check_result(result, "isc_app_onrun");
isc_app_run();
destroy_lookup(default_lookup);
if (batchname != NULL) {
if (batchfp != stdin)
fclose(batchfp);
batchname = NULL;
}
#ifdef DIG_SIGCHASE
clean_trustedkey();
#endif
cancel_all();
destroy_libs();
isc_app_finish();
return (exitcode);
}