dig.c revision 354f4f1ab20ba521818a4bff9ffdbf9e00142b91
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington/*
7d32c065c7bb56f281651ae3dd2888f32ce4f1d9Bob Halley * Copyright (C) 2000, 2001 Internet Software Consortium.
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington *
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * Permission to use, copy, modify, and distribute this software for any
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * purpose with or without fee is hereby granted, provided that the above
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * copyright notice and this permission notice appear in all copies.
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington *
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington/* $Id: dig.c,v 1.136 2001/02/13 23:12:13 tamino Exp $ */
364a82f7c25b62967678027043425201a5e5171aBob Halley
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington#include <config.h>
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington#include <stdlib.h>
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington#include <time.h>
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington#include <ctype.h>
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington#include <isc/app.h>
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington#include <isc/netaddr.h>
10ba7f6f563d68b8f1284847ccce85b706e793feBob Halley#include <isc/print.h>
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington#include <isc/string.h>
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington#include <isc/util.h>
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington#include <isc/task.h>
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington#include <dns/byaddr.h>
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington#include <dns/fixedname.h>
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington#include <dns/message.h>
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington#include <dns/name.h>
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington#include <dns/rdata.h>
d692d9991a731d60b63e6389da1ebf2b2839cfabBrian Wellington#include <dns/rdataset.h>
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington#include <dns/rdatatype.h>
364a82f7c25b62967678027043425201a5e5171aBob Halley#include <dns/rdataclass.h>
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington#include <dig/dig.h>
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonextern ISC_LIST(dig_lookup_t) lookup_list;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonextern dig_serverlist_t server_list;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonextern ISC_LIST(dig_searchlist_t) search_list;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington#define ADD_STRING(b, s) { \
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (strlen(s) >= isc_buffer_availablelength(b)) \
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington return (ISC_R_NOSPACE); \
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington else \
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_buffer_putstr(b, s); \
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington}
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonextern isc_boolean_t have_ipv6, specified_source,
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington usesearch, qr;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonextern in_port_t port;
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellingtonextern unsigned int timeout;
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellingtonextern isc_mem_t *mctx;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonextern dns_messageid_t id;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonextern char *rootspace[BUFSIZE];
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellingtonextern isc_buffer_t rootbuf;
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellingtonextern int sendcount;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonextern int ndots;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonextern int tries;
3f6dc1703f76a24b34ed3bc839447291c33ca837Brian Wellingtonextern int lookup_counter;
ac335315cddc0a42b9235001197dcf719ae737b6Brian Wellingtonextern int exitcode;
fb01226bcd598c36b5edc566489c890c39f03ed3Brian Wellingtonextern isc_sockaddr_t bind_address;
fb01226bcd598c36b5edc566489c890c39f03ed3Brian Wellingtonextern char keynametext[MXNAME];
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellingtonextern char keyfile[MXNAME];
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonextern char keysecret[MXNAME];
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonextern dns_tsigkey_t *key;
0a595c94a4137c3d56d529b86f5b8661513b16c3Brian Wellingtonextern isc_boolean_t validated;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonextern isc_taskmgr_t *taskmgr;
3f6dc1703f76a24b34ed3bc839447291c33ca837Brian Wellingtonextern isc_task_t *global_task;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonextern isc_boolean_t free_now;
0a595c94a4137c3d56d529b86f5b8661513b16c3Brian Wellingtondig_lookup_t *default_lookup = NULL;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonextern isc_uint32_t rr_limit;
e552b980379e3a7ffce1411a939c62e27f953133Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonextern isc_boolean_t debugging, memdebugging;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonchar *batchname = NULL;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian WellingtonFILE *batchfp = NULL;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonchar *argv0;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonchar domainopt[DNS_NAME_MAXTEXT];
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonisc_boolean_t short_form = ISC_FALSE, printcmd = ISC_TRUE,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington nibble = ISC_FALSE, plusquest = ISC_FALSE, pluscomm = ISC_FALSE;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
d92543b36036157e06025c7f44cf870c7e363a23Brian Wellingtonisc_uint16_t bufsize = 0;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonisc_boolean_t forcecomment = ISC_FALSE;
e552b980379e3a7ffce1411a939c62e27f953133Brian Wellington
e552b980379e3a7ffce1411a939c62e27f953133Brian Wellingtonstatic const char *opcodetext[] = {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington "QUERY",
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington "IQUERY",
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington "STATUS",
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington "RESERVED3",
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington "NOTIFY",
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington "UPDATE",
d2524f38d22998efb4196410643280b14f8b6febBob Halley "RESERVED6",
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington "RESERVED7",
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington "RESERVED8",
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington "RESERVED9",
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington "RESERVED10",
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington "RESERVED11",
d2524f38d22998efb4196410643280b14f8b6febBob Halley "RESERVED12",
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington "RESERVED13",
d598338952797df77417e69fcb8782b73651f9a9Brian Wellington "RESERVED14",
d598338952797df77417e69fcb8782b73651f9a9Brian Wellington "RESERVED15"
d598338952797df77417e69fcb8782b73651f9a9Brian Wellington};
d598338952797df77417e69fcb8782b73651f9a9Brian Wellington
d598338952797df77417e69fcb8782b73651f9a9Brian Wellingtonstatic const char *rcodetext[] = {
d598338952797df77417e69fcb8782b73651f9a9Brian Wellington "NOERROR",
d598338952797df77417e69fcb8782b73651f9a9Brian Wellington "FORMERR",
d598338952797df77417e69fcb8782b73651f9a9Brian Wellington "SERVFAIL",
d598338952797df77417e69fcb8782b73651f9a9Brian Wellington "NXDOMAIN",
d598338952797df77417e69fcb8782b73651f9a9Brian Wellington "NOTIMPL",
d598338952797df77417e69fcb8782b73651f9a9Brian Wellington "REFUSED",
d598338952797df77417e69fcb8782b73651f9a9Brian Wellington "YXDOMAIN",
d598338952797df77417e69fcb8782b73651f9a9Brian Wellington "YXRRSET",
4a2f65ad8a26261e758d9682d88eb29395422fb9Brian Wellington "NXRRSET",
4a2f65ad8a26261e758d9682d88eb29395422fb9Brian Wellington "NOTAUTH",
d598338952797df77417e69fcb8782b73651f9a9Brian Wellington "NOTZONE",
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence "RESERVED11",
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington "RESERVED12",
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington "RESERVED13",
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington "RESERVED14",
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington "RESERVED15",
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence "BADVERS"
0a595c94a4137c3d56d529b86f5b8661513b16c3Brian Wellington};
0a595c94a4137c3d56d529b86f5b8661513b16c3Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonextern char *progname;
1a2c699f0eb89fbd776a2dfabb6e197fe36a8c20Brian Wellington
1a2c699f0eb89fbd776a2dfabb6e197fe36a8c20Brian Wellingtonstatic void
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrenceshow_usage(void) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington fputs(
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington"Usage: dig [@global-server] [domain] [q-type] [q-class] {q-opt}\n"
1fd4766e5b732c04c06ef44c0338b3b6bdbf2457Brian Wellington" {global-d-opt} host [@local-server] {local-d-opt}\n"
1fd4766e5b732c04c06ef44c0338b3b6bdbf2457Brian Wellington" [ host [@local-server] {local-d-opt} [...]]\n"
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington"Where: domain are in the Domain Name System\n"
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington" q-class is one of (in,hs,ch,...) [default: in]\n"
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington" q-type is one of (a,any,mx,ns,soa,hinfo,axfr,txt,...) [default:a]\n"
183d6e8b51170e57e7268120d475927fffcf08a5Brian Wellington" (Use ixfr=version for type ixfr)\n"
183d6e8b51170e57e7268120d475927fffcf08a5Brian Wellington" q-opt is one of:\n"
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington" -x dot-notation (shortcut for in-addr lookups)\n"
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington" -n (nibble form for reverse IPv6 lookups)\n"
1a2c699f0eb89fbd776a2dfabb6e197fe36a8c20Brian Wellington" -f filename (batch mode)\n"
b6666e61dc9b91f4ac6af3aa1172bfd8a5f2d6ffBrian Wellington" -p port (specify port number)\n"
b6666e61dc9b91f4ac6af3aa1172bfd8a5f2d6ffBrian Wellington" -t type (specify query type)\n"
b6666e61dc9b91f4ac6af3aa1172bfd8a5f2d6ffBrian Wellington" -c class (specify query class)\n"
1a2c699f0eb89fbd776a2dfabb6e197fe36a8c20Brian Wellington" -y name:key (specify named base64 tsig key)\n"
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington" d-opt is of the form +keyword[=value], where keyword is:\n"
1a2c699f0eb89fbd776a2dfabb6e197fe36a8c20Brian Wellington" +[no]vc (TCP mode)\n"
1a2c699f0eb89fbd776a2dfabb6e197fe36a8c20Brian Wellington" +[no]tcp (TCP mode, alternate syntax)\n"
1a2c699f0eb89fbd776a2dfabb6e197fe36a8c20Brian Wellington" +time=### (Set query timeout) [5]\n"
1a2c699f0eb89fbd776a2dfabb6e197fe36a8c20Brian Wellington" +tries=### (Set number of UDP attempts) [3]\n"
1a2c699f0eb89fbd776a2dfabb6e197fe36a8c20Brian Wellington" +domain=### (Set default domainname)\n"
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington" +bufsize=### (Set EDNS0 Max UDP packet size)\n"
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington" +[no]search (Set whether to use searchlist)\n"
b6666e61dc9b91f4ac6af3aa1172bfd8a5f2d6ffBrian Wellington" +[no]defname (Ditto)\n"
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington" +[no]recursive (Recursive mode)\n"
b6666e61dc9b91f4ac6af3aa1172bfd8a5f2d6ffBrian Wellington" +[no]ignore (Don't revert to TCP for TC responses.)"
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington"\n"
b6666e61dc9b91f4ac6af3aa1172bfd8a5f2d6ffBrian Wellington" +[no]fail (Don't try next server on SERVFAIL)\n"
b6666e61dc9b91f4ac6af3aa1172bfd8a5f2d6ffBrian Wellington" +[no]besteffort (Try to parse even illegal messages)\n"
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington" +[no]aaonly (Set AA flag in query)\n"
949d406b57fe80fabc6a60d36a0dcee927c780b3Brian Wellington" +[no]adflag (Set AD flag in query)\n"
e552b980379e3a7ffce1411a939c62e27f953133Brian Wellington" +[no]cdflag (Set CD flag in query)\n"
e552b980379e3a7ffce1411a939c62e27f953133Brian Wellington" +ndots=### (Set NDOTS value)\n"
ac335315cddc0a42b9235001197dcf719ae737b6Brian Wellington" +[no]cmd (Control display of command line)\n"
fb01226bcd598c36b5edc566489c890c39f03ed3Brian Wellington" +[no]comments (Control display of comment lines)\n"
fb01226bcd598c36b5edc566489c890c39f03ed3Brian Wellington" +[no]question (Control display of question)\n"
949d406b57fe80fabc6a60d36a0dcee927c780b3Brian Wellington" +[no]answer (Control display of answer)\n"
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington" +[no]authority (Control display of authority)\n"
8dd915daf3f75ac9d04395e61157fdea825f3ebaBrian Wellington" +[no]additional (Control display of additional)\n"
8dd915daf3f75ac9d04395e61157fdea825f3ebaBrian Wellington" +[no]short (Disable everything except short\n"
8dd915daf3f75ac9d04395e61157fdea825f3ebaBrian Wellington" form of answer)\n"
8dd915daf3f75ac9d04395e61157fdea825f3ebaBrian Wellington" +[no]all (Set or clear all display flags)\n"
8dd915daf3f75ac9d04395e61157fdea825f3ebaBrian Wellington" +qr (Print question before sending)\n"
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff" +[no]nssearch (Search all authorative nameservers)\n"
8dd915daf3f75ac9d04395e61157fdea825f3ebaBrian Wellington" +[no]identify (ID responders in short answers)\n"
15660bccc162db0a7df281f5d743757c527580d5Brian Wellington" +[no]trace (Trace delegation down from root)\n"
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington" +rrlimit=### (Limit number of rr's in xfr)\n"
b6666e61dc9b91f4ac6af3aa1172bfd8a5f2d6ffBrian Wellington" +namelimit=### (Limit number of names in xfr)\n"
b6666e61dc9b91f4ac6af3aa1172bfd8a5f2d6ffBrian Wellington" +[no]dnssec (Request DNSSEC records)\n"
b6666e61dc9b91f4ac6af3aa1172bfd8a5f2d6ffBrian Wellington" global d-opts and servers (before host name) affect all queries.\n"
b6666e61dc9b91f4ac6af3aa1172bfd8a5f2d6ffBrian Wellington" local d-opts and servers (after host name) affect only that lookup.\n"
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington, stderr);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington}
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington/*
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * Callback from dighost.c to print the received message.
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonvoid
3f6dc1703f76a24b34ed3bc839447291c33ca837Brian Wellingtonreceived(int bytes, isc_sockaddr_t *from, dig_query_t *query) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_uint64_t diff;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_time_t now;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_result_t result;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington time_t tnow;
d0345e08f26267c1d11e02af57a6555868068415Brian Wellington char fromtext[ISC_SOCKADDR_FORMATSIZE];
b6666e61dc9b91f4ac6af3aa1172bfd8a5f2d6ffBrian Wellington
3f6dc1703f76a24b34ed3bc839447291c33ca837Brian Wellington isc_sockaddr_format(from, fromtext, sizeof(fromtext));
b6666e61dc9b91f4ac6af3aa1172bfd8a5f2d6ffBrian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington result = isc_time_now(&now);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington check_result(result, "isc_time_now");
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (query->lookup->stats) {
949d406b57fe80fabc6a60d36a0dcee927c780b3Brian Wellington diff = isc_time_microdiff(&now, &query->time_sent);
b6666e61dc9b91f4ac6af3aa1172bfd8a5f2d6ffBrian Wellington printf(";; Query time: %ld msec\n", (long int)diff/1000);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington printf(";; SERVER: %s(%s)\n", fromtext, query->servname);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington time(&tnow);
183d6e8b51170e57e7268120d475927fffcf08a5Brian Wellington printf(";; WHEN: %s", ctime(&tnow));
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington if (query->lookup->doing_xfr) {
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington printf(";; XFR size: %d records\n",
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington query->rr_count);
183d6e8b51170e57e7268120d475927fffcf08a5Brian Wellington } else {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington printf(";; MSG SIZE rcvd: %d\n", bytes);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (key != NULL) {
d598338952797df77417e69fcb8782b73651f9a9Brian Wellington if (!validated)
d598338952797df77417e69fcb8782b73651f9a9Brian Wellington puts(";; WARNING -- Some TSIG could not "
d598338952797df77417e69fcb8782b73651f9a9Brian Wellington "be validated");
d598338952797df77417e69fcb8782b73651f9a9Brian Wellington }
3f6dc1703f76a24b34ed3bc839447291c33ca837Brian Wellington if ((key == NULL) && (keysecret[0] != 0)) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington puts(";; WARNING -- TSIG key was not used.");
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
d0345e08f26267c1d11e02af57a6555868068415Brian Wellington puts("");
b6666e61dc9b91f4ac6af3aa1172bfd8a5f2d6ffBrian Wellington } else if (query->lookup->identify && !short_form) {
d0345e08f26267c1d11e02af57a6555868068415Brian Wellington diff = isc_time_microdiff(&now, &query->time_sent);
d0345e08f26267c1d11e02af57a6555868068415Brian Wellington printf(";; Received %u bytes from %s(%s) in %d ms\n\n",
d0345e08f26267c1d11e02af57a6555868068415Brian Wellington bytes, fromtext, query->servname,
d0345e08f26267c1d11e02af57a6555868068415Brian Wellington (int)diff/1000);
d0345e08f26267c1d11e02af57a6555868068415Brian Wellington }
d0345e08f26267c1d11e02af57a6555868068415Brian Wellington}
d0345e08f26267c1d11e02af57a6555868068415Brian Wellington
d0345e08f26267c1d11e02af57a6555868068415Brian Wellington/*
b6666e61dc9b91f4ac6af3aa1172bfd8a5f2d6ffBrian Wellington * Callback from dighost.c to print that it is trying a server.
d0345e08f26267c1d11e02af57a6555868068415Brian Wellington * Not used in dig.
b6666e61dc9b91f4ac6af3aa1172bfd8a5f2d6ffBrian Wellington * XXX print_trying
d0345e08f26267c1d11e02af57a6555868068415Brian Wellington */
d0345e08f26267c1d11e02af57a6555868068415Brian Wellingtonvoid
d0345e08f26267c1d11e02af57a6555868068415Brian Wellingtontrying(int frmsize, char *frm, dig_lookup_t *lookup) {
b6666e61dc9b91f4ac6af3aa1172bfd8a5f2d6ffBrian Wellington UNUSED(frmsize);
d0345e08f26267c1d11e02af57a6555868068415Brian Wellington UNUSED(frm);
d0345e08f26267c1d11e02af57a6555868068415Brian Wellington UNUSED(lookup);
949d406b57fe80fabc6a60d36a0dcee927c780b3Brian Wellington}
949d406b57fe80fabc6a60d36a0dcee927c780b3Brian Wellington
949d406b57fe80fabc6a60d36a0dcee927c780b3Brian Wellington/*
15660bccc162db0a7df281f5d743757c527580d5Brian Wellington * Internal print routine used to print short form replies.
949d406b57fe80fabc6a60d36a0dcee927c780b3Brian Wellington */
15660bccc162db0a7df281f5d743757c527580d5Brian Wellingtonstatic isc_result_t
949d406b57fe80fabc6a60d36a0dcee927c780b3Brian Wellingtonsay_message(dns_rdata_t *rdata, dig_query_t *query, isc_buffer_t *buf) {
949d406b57fe80fabc6a60d36a0dcee927c780b3Brian Wellington isc_result_t result;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_uint64_t diff;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_time_t now;
3f6dc1703f76a24b34ed3bc839447291c33ca837Brian Wellington char store[sizeof("12345678901234567890")];
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (query->lookup->trace || query->lookup->ns_search_only) {
3b2b306f47867d0037fb851623fb5a5736d64348Michael Graff result = dns_rdatatype_totext(rdata->type, buf);
4556681e191b7c1654639895ce719d98f2822ee2Michael Graff if (result != ISC_R_SUCCESS)
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington return (result);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington ADD_STRING(buf, " ");
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington result = dns_rdata_totext(rdata, NULL, buf);
2c12fc4d63f1d5f9d55fc0ecb198d582da6fd7d3Brian Wellington check_result(result, "dns_rdata_totext");
d692d9991a731d60b63e6389da1ebf2b2839cfabBrian Wellington if (query->lookup->identify) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington result = isc_time_now(&now);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (result != ISC_R_SUCCESS)
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington return (result);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington diff = isc_time_microdiff(&now, &query->time_sent);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington ADD_STRING(buf, " from server ");
05b6b2e6802d503a9e131415b4720f35ab9f08d1Brian Wellington ADD_STRING(buf, query->servname);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington snprintf(store, 19, " in %d ms.", (int)diff/1000);
05b6b2e6802d503a9e131415b4720f35ab9f08d1Brian Wellington ADD_STRING(buf, store);
05b6b2e6802d503a9e131415b4720f35ab9f08d1Brian Wellington }
452123247dcc4c6d30ea3f33f5174df62d84e9aeBrian Wellington ADD_STRING(buf, "\n");
05b6b2e6802d503a9e131415b4720f35ab9f08d1Brian Wellington return (ISC_R_SUCCESS);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington}
c3a4d8072ccd3b33aa3fc84cdeadd1a6fac87e08Michael Graff
c3a4d8072ccd3b33aa3fc84cdeadd1a6fac87e08Michael Graff/*
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * short_form message print handler. Calls above say_message()
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonstatic isc_result_t
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonshort_answer(dns_message_t *msg, dns_messagetextflag_t flags,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_buffer_t *buf, dig_query_t *query)
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington{
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington dns_name_t *name;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington dns_rdataset_t *rdataset;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_buffer_t target;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_result_t result, loopresult;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington dns_name_t empty_name;
452123247dcc4c6d30ea3f33f5174df62d84e9aeBrian Wellington char t[4096];
452123247dcc4c6d30ea3f33f5174df62d84e9aeBrian Wellington dns_rdata_t rdata = DNS_RDATA_INIT;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington UNUSED(flags);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
58aaab3687aac838542ee4ef65a9c094a5d34ab0Michael Graff dns_name_init(&empty_name, NULL);
d692d9991a731d60b63e6389da1ebf2b2839cfabBrian Wellington result = dns_message_firstname(msg, DNS_SECTION_ANSWER);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (result == ISC_R_NOMORE)
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington return (ISC_R_SUCCESS);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington else if (result != ISC_R_SUCCESS)
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington return (result);
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington for (;;) {
d84ce5d5c69a7e144fb90fd4b3c349e88e4dcdddBrian Wellington name = NULL;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington dns_message_currentname(msg, DNS_SECTION_ANSWER, &name);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_buffer_init(&target, t, sizeof(t));
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington for (rdataset = ISC_LIST_HEAD(name->list);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington rdataset != NULL;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington rdataset = ISC_LIST_NEXT(rdataset, link)) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington loopresult = dns_rdataset_first(rdataset);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington while (loopresult == ISC_R_SUCCESS) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington dns_rdataset_current(rdataset, &rdata);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington result = say_message(&rdata, query,
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence buf);
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence check_result(result, "say_message");
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington loopresult = dns_rdataset_next(rdataset);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington dns_rdata_reset(&rdata);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence result = dns_message_nextname(msg, DNS_SECTION_ANSWER);
83e4218f6c6497eeaec7fb422b5f662cd98b2ba6David Lawrence if (result == ISC_R_NOMORE)
83e4218f6c6497eeaec7fb422b5f662cd98b2ba6David Lawrence break;
83e4218f6c6497eeaec7fb422b5f662cd98b2ba6David Lawrence else if (result != ISC_R_SUCCESS)
83e4218f6c6497eeaec7fb422b5f662cd98b2ba6David Lawrence return (result);
83e4218f6c6497eeaec7fb422b5f662cd98b2ba6David Lawrence }
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington return (ISC_R_SUCCESS);
e552b980379e3a7ffce1411a939c62e27f953133Brian Wellington}
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington/*
d5334bc18380d25e8a7ee804f68f22dc746b9c20Brian Wellington * Callback from dighost.c to print the reply from a server
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington */
d84ce5d5c69a7e144fb90fd4b3c349e88e4dcdddBrian Wellingtonisc_result_t
d84ce5d5c69a7e144fb90fd4b3c349e88e4dcdddBrian Wellingtonprintmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
d84ce5d5c69a7e144fb90fd4b3c349e88e4dcdddBrian Wellington isc_boolean_t did_flag = ISC_FALSE;
d84ce5d5c69a7e144fb90fd4b3c349e88e4dcdddBrian Wellington isc_result_t result;
d84ce5d5c69a7e144fb90fd4b3c349e88e4dcdddBrian Wellington dns_messagetextflag_t flags;
d84ce5d5c69a7e144fb90fd4b3c349e88e4dcdddBrian Wellington isc_buffer_t *buf = NULL;
d84ce5d5c69a7e144fb90fd4b3c349e88e4dcdddBrian Wellington unsigned int len = OUTPUTBUF;
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence
d84ce5d5c69a7e144fb90fd4b3c349e88e4dcdddBrian Wellington if (query->lookup->cmdline[0] != 0) {
d84ce5d5c69a7e144fb90fd4b3c349e88e4dcdddBrian Wellington fputs(query->lookup->cmdline, stdout);
d84ce5d5c69a7e144fb90fd4b3c349e88e4dcdddBrian Wellington query->lookup->cmdline[0]=0;
d84ce5d5c69a7e144fb90fd4b3c349e88e4dcdddBrian Wellington }
d84ce5d5c69a7e144fb90fd4b3c349e88e4dcdddBrian Wellington debug("printmessage(%s %s %s)", headers ? "headers" : "noheaders",
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence query->lookup->comments ? "comments" : "nocomments",
d84ce5d5c69a7e144fb90fd4b3c349e88e4dcdddBrian Wellington short_form ? "short_form" : "long_form");
d84ce5d5c69a7e144fb90fd4b3c349e88e4dcdddBrian Wellington
d84ce5d5c69a7e144fb90fd4b3c349e88e4dcdddBrian Wellington flags = 0;
d84ce5d5c69a7e144fb90fd4b3c349e88e4dcdddBrian Wellington if (!headers) {
d84ce5d5c69a7e144fb90fd4b3c349e88e4dcdddBrian Wellington flags |= DNS_MESSAGETEXTFLAG_NOHEADERS;
d84ce5d5c69a7e144fb90fd4b3c349e88e4dcdddBrian Wellington flags |= DNS_MESSAGETEXTFLAG_NOCOMMENTS;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington }
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence if (!query->lookup->comments)
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington flags |= DNS_MESSAGETEXTFLAG_NOCOMMENTS;
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence
4dc6a937d699f76782c17d58305f6d6cfaa8b55dBrian Wellington result = ISC_R_SUCCESS;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington result = isc_buffer_allocate(mctx, &buf, len);
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington check_result(result, "isc_buffer_allocate");
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence if (query->lookup->comments && !short_form) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (query->lookup->cmdline[0] != 0)
4dc6a937d699f76782c17d58305f6d6cfaa8b55dBrian Wellington printf("; %s\n", query->lookup->cmdline);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (msg == query->lookup->sendmsg)
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington printf(";; Sending:\n");
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington else
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington printf(";; Got answer:\n");
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington if (headers) {
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington printf(";; ->>HEADER<<- opcode: %s, status: %s, "
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington "id: %u\n",
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington opcodetext[msg->opcode], rcodetext[msg->rcode],
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington msg->id);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington printf(";; flags: ");
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington if ((msg->flags & DNS_MESSAGEFLAG_QR) != 0) {
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington printf("qr");
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington did_flag = ISC_TRUE;
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence }
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington if ((msg->flags & DNS_MESSAGEFLAG_AA) != 0) {
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington printf("%saa", did_flag ? " " : "");
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington did_flag = ISC_TRUE; }
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington if ((msg->flags & DNS_MESSAGEFLAG_TC) != 0) {
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington printf("%stc", did_flag ? " " : "");
452123247dcc4c6d30ea3f33f5174df62d84e9aeBrian Wellington did_flag = ISC_TRUE;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington }
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington if ((msg->flags & DNS_MESSAGEFLAG_RD) != 0) {
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington printf("%srd", did_flag ? " " : "");
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington did_flag = ISC_TRUE;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington if ((msg->flags & DNS_MESSAGEFLAG_RA) != 0) {
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington printf("%sra", did_flag ? " " : "");
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington did_flag = ISC_TRUE;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if ((msg->flags & DNS_MESSAGEFLAG_AD) != 0) {
83e4218f6c6497eeaec7fb422b5f662cd98b2ba6David Lawrence printf("%sad", did_flag ? " " : "");
83e4218f6c6497eeaec7fb422b5f662cd98b2ba6David Lawrence did_flag = ISC_TRUE;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
83e4218f6c6497eeaec7fb422b5f662cd98b2ba6David Lawrence if ((msg->flags & DNS_MESSAGEFLAG_CD) != 0) {
83e4218f6c6497eeaec7fb422b5f662cd98b2ba6David Lawrence printf("%scd", did_flag ? " " : "");
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington did_flag = ISC_TRUE;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington printf("; QUERY: %u, ANSWER: %u, "
83e4218f6c6497eeaec7fb422b5f662cd98b2ba6David Lawrence "AUTHORITY: %u, ADDITIONAL: %u\n",
83e4218f6c6497eeaec7fb422b5f662cd98b2ba6David Lawrence msg->counts[DNS_SECTION_QUESTION],
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington msg->counts[DNS_SECTION_ANSWER],
83e4218f6c6497eeaec7fb422b5f662cd98b2ba6David Lawrence msg->counts[DNS_SECTION_AUTHORITY],
83e4218f6c6497eeaec7fb422b5f662cd98b2ba6David Lawrence msg->counts[DNS_SECTION_ADDITIONAL]);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence
4dc6a937d699f76782c17d58305f6d6cfaa8b55dBrian Wellingtonbuftoosmall:
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (query->lookup->comments && headers && !short_form)
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington {
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington result = dns_message_pseudosectiontotext(msg,
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington DNS_PSEUDOSECTION_OPT,
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington flags, buf);
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington check_result(result,
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington "dns_message_pseudosectiontotext");
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington }
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence
4dc6a937d699f76782c17d58305f6d6cfaa8b55dBrian Wellington if (query->lookup->section_question && headers) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (!short_form) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington result = dns_message_sectiontotext(msg,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington DNS_SECTION_QUESTION,
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington flags, buf);
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington if (result == ISC_R_NOSPACE) {
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington len += OUTPUTBUF;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington isc_buffer_free(&buf);
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington result = isc_buffer_allocate(mctx, &buf, len);
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington if (result == ISC_R_SUCCESS)
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington goto buftoosmall;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington }
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington check_result(result, "dns_message_sectiontotext");
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington }
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (query->lookup->section_answer) {
d5334bc18380d25e8a7ee804f68f22dc746b9c20Brian Wellington if (!short_form) {
d5334bc18380d25e8a7ee804f68f22dc746b9c20Brian Wellington result = dns_message_sectiontotext(msg,
d5334bc18380d25e8a7ee804f68f22dc746b9c20Brian Wellington DNS_SECTION_ANSWER,
d5334bc18380d25e8a7ee804f68f22dc746b9c20Brian Wellington flags, buf);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (result == ISC_R_NOSPACE) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington len += OUTPUTBUF;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_buffer_free(&buf);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington result = isc_buffer_allocate(mctx, &buf, len);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (result == ISC_R_SUCCESS)
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington goto buftoosmall;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence check_result(result, "dns_message_sectiontotext");
4dc6a937d699f76782c17d58305f6d6cfaa8b55dBrian Wellington } else {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington result = short_answer(msg, flags, buf, query);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington check_result(result, "short_answer");
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (query->lookup->section_authority) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (!short_form) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington result = dns_message_sectiontotext(msg,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington DNS_SECTION_AUTHORITY,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington flags, buf);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (result == ISC_R_NOSPACE) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington len += OUTPUTBUF;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_buffer_free(&buf);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington result = isc_buffer_allocate(mctx, &buf, len);
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence if (result == ISC_R_SUCCESS)
0dc4e6a6aef01175b8cdd71cb757f09ba1e69c49Brian Wellington goto buftoosmall;
2c12fc4d63f1d5f9d55fc0ecb198d582da6fd7d3Brian Wellington }
c3a4d8072ccd3b33aa3fc84cdeadd1a6fac87e08Michael Graff check_result(result, "dns_message_sectiontotext");
c3a4d8072ccd3b33aa3fc84cdeadd1a6fac87e08Michael Graff }
0dc4e6a6aef01175b8cdd71cb757f09ba1e69c49Brian Wellington }
2c12fc4d63f1d5f9d55fc0ecb198d582da6fd7d3Brian Wellington if (query->lookup->section_additional) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (!short_form) {
c3a4d8072ccd3b33aa3fc84cdeadd1a6fac87e08Michael Graff result = dns_message_sectiontotext(msg,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington DNS_SECTION_ADDITIONAL,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington flags, buf);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (result == ISC_R_NOSPACE) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington len += OUTPUTBUF;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_buffer_free(&buf);
2c12fc4d63f1d5f9d55fc0ecb198d582da6fd7d3Brian Wellington result = isc_buffer_allocate(mctx, &buf, len);
2c12fc4d63f1d5f9d55fc0ecb198d582da6fd7d3Brian Wellington if (result == ISC_R_SUCCESS)
2c12fc4d63f1d5f9d55fc0ecb198d582da6fd7d3Brian Wellington goto buftoosmall;
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence }
2c12fc4d63f1d5f9d55fc0ecb198d582da6fd7d3Brian Wellington check_result(result, "dns_message_sectiontotext");
2c12fc4d63f1d5f9d55fc0ecb198d582da6fd7d3Brian Wellington /*
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence * Only print the signature on the first record.
2c12fc4d63f1d5f9d55fc0ecb198d582da6fd7d3Brian Wellington */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (headers) {
2c12fc4d63f1d5f9d55fc0ecb198d582da6fd7d3Brian Wellington result = dns_message_pseudosectiontotext(
2c12fc4d63f1d5f9d55fc0ecb198d582da6fd7d3Brian Wellington msg,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington DNS_PSEUDOSECTION_TSIG,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington flags, buf);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington check_result(result,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington "dns_message_pseudosectiontotext");
2c12fc4d63f1d5f9d55fc0ecb198d582da6fd7d3Brian Wellington result = dns_message_pseudosectiontotext(
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington msg,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington DNS_PSEUDOSECTION_SIG0,
0dc4e6a6aef01175b8cdd71cb757f09ba1e69c49Brian Wellington flags, buf);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington check_result(result,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington "dns_message_pseudosectiontotext");
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
2c12fc4d63f1d5f9d55fc0ecb198d582da6fd7d3Brian Wellington if (headers && query->lookup->comments && !short_form)
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington printf("\n");
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
5caab9f99d19ab9ebb0a0ba64c09c8de80e89e29Brian Wellington printf("%.*s", (int)isc_buffer_usedlength(buf),
5caab9f99d19ab9ebb0a0ba64c09c8de80e89e29Brian Wellington (char *)isc_buffer_base(buf));
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_buffer_free(&buf);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington return (result);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington}
2c12fc4d63f1d5f9d55fc0ecb198d582da6fd7d3Brian Wellington
2c12fc4d63f1d5f9d55fc0ecb198d582da6fd7d3Brian Wellington/*
2c12fc4d63f1d5f9d55fc0ecb198d582da6fd7d3Brian Wellington * print the greeting message when the program first starts up.
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonstatic void
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonprintgreeting(int argc, char **argv, dig_lookup_t *lookup) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington int i;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington static isc_boolean_t first = ISC_TRUE;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington char append[MXNAME];
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
452123247dcc4c6d30ea3f33f5174df62d84e9aeBrian Wellington if (printcmd) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington snprintf(lookup->cmdline, sizeof(lookup->cmdline),
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington "%s; <<>> DiG " VERSION " <<>>",
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington first?"\n":"");
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington i = 1;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington while (i < argc) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington snprintf(append, sizeof(append), " %s", argv[i++]);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington strncat(lookup->cmdline, append,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington sizeof (lookup->cmdline));
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington }
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington strncat(lookup->cmdline, "\n", sizeof (lookup->cmdline));
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington if (first) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington snprintf(append, sizeof (append),
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington ";; global options: %s %s\n",
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington short_form ? "short_form" : "",
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington printcmd ? "printcmd" : "");
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington first = ISC_FALSE;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington strncat(lookup->cmdline, append,
d692d9991a731d60b63e6389da1ebf2b2839cfabBrian Wellington sizeof (lookup->cmdline));
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
3f6dc1703f76a24b34ed3bc839447291c33ca837Brian Wellington }
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington}
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington/*
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * Reorder an argument list so that server names all come at the end.
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * This is a bit of a hack, to allow batch-mode processing to properly
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * handle the server options.
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington */
a523752c602dc6bdb69a8d9c6267a1e4188a9782Andreas Gustafssonstatic void
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonreorder_args(int argc, char *argv[]) {
05b6b2e6802d503a9e131415b4720f35ab9f08d1Brian Wellington int i, j;
05b6b2e6802d503a9e131415b4720f35ab9f08d1Brian Wellington char *ptr;
05b6b2e6802d503a9e131415b4720f35ab9f08d1Brian Wellington int end;
f7fbd68b1cd96c733140fce938a61faf8b459b6fBrian Wellington
f7fbd68b1cd96c733140fce938a61faf8b459b6fBrian Wellington debug("reorder_args()");
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington end = argc - 1;
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington while (argv[end][0] == '@') {
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington end--;
05b6b2e6802d503a9e131415b4720f35ab9f08d1Brian Wellington if (end == 0)
5caab9f99d19ab9ebb0a0ba64c09c8de80e89e29Brian Wellington return;
05b6b2e6802d503a9e131415b4720f35ab9f08d1Brian Wellington }
05b6b2e6802d503a9e131415b4720f35ab9f08d1Brian Wellington debug("arg[end]=%s", argv[end]);
05b6b2e6802d503a9e131415b4720f35ab9f08d1Brian Wellington for (i = 1; i < end - 1; i++) {
05b6b2e6802d503a9e131415b4720f35ab9f08d1Brian Wellington if (argv[i][0] == '@') {
05b6b2e6802d503a9e131415b4720f35ab9f08d1Brian Wellington debug("arg[%d]=%s", i, argv[i]);
05b6b2e6802d503a9e131415b4720f35ab9f08d1Brian Wellington ptr = argv[i];
05b6b2e6802d503a9e131415b4720f35ab9f08d1Brian Wellington for (j = i + 1; j < end; j++) {
05b6b2e6802d503a9e131415b4720f35ab9f08d1Brian Wellington debug("Moving %s to %d", argv[j], j - 1);
05b6b2e6802d503a9e131415b4720f35ab9f08d1Brian Wellington argv[j - 1] = argv[j];
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington debug("moving %s to end, %d", ptr, end - 1);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington argv[end - 1] = ptr;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington end--;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (end < 1)
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington return;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
5caab9f99d19ab9ebb0a0ba64c09c8de80e89e29Brian Wellington}
5caab9f99d19ab9ebb0a0ba64c09c8de80e89e29Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonstatic isc_uint32_t
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonparse_int(char *arg, const char *desc, isc_uint32_t max) {
5caab9f99d19ab9ebb0a0ba64c09c8de80e89e29Brian Wellington char *endp;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_uint32_t tmp;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington tmp = strtoul(arg, &endp, 10);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (*endp != '\0')
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington fatal("%s '%s' must be numeric", desc, arg);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (tmp > max)
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington fatal("%s '%s' out of range", desc, arg);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington return (tmp);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington}
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington/*
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * We're not using isc_commandline_parse() here since the command line
452123247dcc4c6d30ea3f33f5174df62d84e9aeBrian Wellington * syntax of dig is quite a bit different from that which can be described
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * by that routine.
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * XXX doc options
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonstatic void
fb01226bcd598c36b5edc566489c890c39f03ed3Brian Wellingtonplus_option(char *option, isc_boolean_t is_batchfile,
fb01226bcd598c36b5edc566489c890c39f03ed3Brian Wellington dig_lookup_t *lookup)
fb01226bcd598c36b5edc566489c890c39f03ed3Brian Wellington{
3f6dc1703f76a24b34ed3bc839447291c33ca837Brian Wellington char option_store[256];
0f0162e6297ddf5e4abe848d27f3bcdb373189daBrian Wellington char *cmd, *value, *ptr;
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington isc_boolean_t state = ISC_TRUE;
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington strncpy(option_store, option, sizeof(option_store));
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington option_store[sizeof(option_store)-1]=0;
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington ptr = option_store;
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington cmd=next_token(&ptr,"=");
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington if (cmd == NULL) {
0f0162e6297ddf5e4abe848d27f3bcdb373189daBrian Wellington printf(";; Invalid option %s\n",option_store);
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington return;
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington }
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington value=ptr;
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington if (strncasecmp(cmd,"no",2)==0) {
0f0162e6297ddf5e4abe848d27f3bcdb373189daBrian Wellington cmd += 2;
0f0162e6297ddf5e4abe848d27f3bcdb373189daBrian Wellington state = ISC_FALSE;
0f0162e6297ddf5e4abe848d27f3bcdb373189daBrian Wellington }
0f0162e6297ddf5e4abe848d27f3bcdb373189daBrian Wellington switch (cmd[0]) {
fb01226bcd598c36b5edc566489c890c39f03ed3Brian Wellington case 'a':
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington switch (cmd[1]) {
0f0162e6297ddf5e4abe848d27f3bcdb373189daBrian Wellington case 'a': /* aaflag */
0f0162e6297ddf5e4abe848d27f3bcdb373189daBrian Wellington lookup->aaonly = state;
0f0162e6297ddf5e4abe848d27f3bcdb373189daBrian Wellington break;
0f0162e6297ddf5e4abe848d27f3bcdb373189daBrian Wellington case 'd':
0f0162e6297ddf5e4abe848d27f3bcdb373189daBrian Wellington switch (cmd[2]) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington case 'd': /* additional */
0f0162e6297ddf5e4abe848d27f3bcdb373189daBrian Wellington lookup->section_additional = state;
0f0162e6297ddf5e4abe848d27f3bcdb373189daBrian Wellington break;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington case 'f': /* adflag */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington lookup->adflag = state;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington break;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington default:
d692d9991a731d60b63e6389da1ebf2b2839cfabBrian Wellington goto invalid_option;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington break;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington case 'l': /* all */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington lookup->section_question = state;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington lookup->section_authority = state;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington lookup->section_answer = state;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington lookup->section_additional = state;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington lookup->comments = state;
4dc6a937d699f76782c17d58305f6d6cfaa8b55dBrian Wellington break;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington case 'n': /* answer */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington lookup->section_answer = state;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington break;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington case 'u': /* authority */
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence lookup->section_authority = state;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington break;
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence default:
4dc6a937d699f76782c17d58305f6d6cfaa8b55dBrian Wellington goto invalid_option;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington break;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington case 'b':
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington switch (cmd[1]) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington case 'e':/* besteffort */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington lookup->besteffort = state;
4dc6a937d699f76782c17d58305f6d6cfaa8b55dBrian Wellington break;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington case 'u':/* bufsize */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (value == NULL)
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington goto need_value;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (!state)
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington goto invalid_option;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington lookup->udpsize = parse_int(value, "buffer size",
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington COMMSIZE);
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence if (lookup->udpsize <= 0)
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington lookup->udpsize = 0;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington if (lookup->udpsize > COMMSIZE)
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington lookup->udpsize = COMMSIZE;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington break;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington default:
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington goto invalid_option;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington break;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington case 'c':
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington switch (cmd[1]) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington case 'd':/* cdflag */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington lookup->cdflag = state;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington break;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington case 'm': /* cmd */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington printcmd = state;
4dc6a937d699f76782c17d58305f6d6cfaa8b55dBrian Wellington break;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington case 'o': /* comments */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington lookup->comments = state;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (lookup == default_lookup)
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington pluscomm = state;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington break;
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence default:
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington goto invalid_option;
d598338952797df77417e69fcb8782b73651f9a9Brian Wellington }
4dc6a937d699f76782c17d58305f6d6cfaa8b55dBrian Wellington break;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington case 'd':
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington switch (cmd[1]) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington case 'e': /* defname */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington usesearch = state;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington break;
4dc6a937d699f76782c17d58305f6d6cfaa8b55dBrian Wellington case 'n': /* dnssec */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington lookup->dnssec = state;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington break;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington case 'o': /* domain */
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence if (value == NULL)
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington goto need_value;
5caab9f99d19ab9ebb0a0ba64c09c8de80e89e29Brian Wellington if (!state)
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence goto invalid_option;
4dc6a937d699f76782c17d58305f6d6cfaa8b55dBrian Wellington strncpy(domainopt, value, sizeof(domainopt));
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington domainopt[sizeof(domainopt)-1] = '\0';
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington break;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington default:
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington goto invalid_option;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
4dc6a937d699f76782c17d58305f6d6cfaa8b55dBrian Wellington break;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington case 'f': /* fail */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington lookup->servfail_stops = state;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington break;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington case 'i':
83e4218f6c6497eeaec7fb422b5f662cd98b2ba6David Lawrence switch (cmd[1]) {
83e4218f6c6497eeaec7fb422b5f662cd98b2ba6David Lawrence case 'd': /* identify */
83e4218f6c6497eeaec7fb422b5f662cd98b2ba6David Lawrence lookup->identify = state;
83e4218f6c6497eeaec7fb422b5f662cd98b2ba6David Lawrence break;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington case 'g': /* ignore */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington default: /* Inherets default for compatibility */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington lookup->ignore = ISC_TRUE;
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence }
4dc6a937d699f76782c17d58305f6d6cfaa8b55dBrian Wellington break;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington case 'n':
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington switch (cmd[1]) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington case 'd': /* ndots */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (value == NULL)
4dc6a937d699f76782c17d58305f6d6cfaa8b55dBrian Wellington goto need_value;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (!state)
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington goto invalid_option;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington ndots = parse_int(value, "ndots", MAXNDOTS);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (ndots < 0)
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington ndots = 0;
4dc6a937d699f76782c17d58305f6d6cfaa8b55dBrian Wellington break;
1fd4766e5b732c04c06ef44c0338b3b6bdbf2457Brian Wellington case 's': /* nssearch */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington lookup->ns_search_only = state;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (state) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington lookup->trace_root = ISC_TRUE;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington lookup->recurse = ISC_FALSE;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington lookup->identify = ISC_TRUE;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington lookup->stats = ISC_FALSE;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington lookup->comments = ISC_FALSE;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington lookup->section_additional = ISC_FALSE;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington lookup->section_authority = ISC_FALSE;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington lookup->section_question = ISC_FALSE;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington lookup->rdtype = dns_rdatatype_soa;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington lookup->rdtypeset = ISC_TRUE;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington short_form = ISC_TRUE;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington break;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington default:
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington goto invalid_option;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington break;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington case 'q':
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington switch (cmd[1]) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington case 'r': /* qr */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington qr = state;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington break;
f7fbd68b1cd96c733140fce938a61faf8b459b6fBrian Wellington case 'u': /* question */
f7fbd68b1cd96c733140fce938a61faf8b459b6fBrian Wellington lookup->section_question = state;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (lookup == default_lookup)
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington plusquest = state;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington break;
3f6dc1703f76a24b34ed3bc839447291c33ca837Brian Wellington default:
b6666e61dc9b91f4ac6af3aa1172bfd8a5f2d6ffBrian Wellington goto invalid_option;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington break;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington case 'r':
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington switch (cmd[1]) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington case 'e': /* recurse */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington lookup->recurse = state;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington break;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington case 'r': /* rrlimit */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (value == NULL)
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington goto need_value;
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington if (!state)
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington goto invalid_option;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington rr_limit = parse_int(value, "rrlimit", MAXRRLIMIT);
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington break;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington default:
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington goto invalid_option;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington }
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington break;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington case 's':
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington switch (cmd[1]) {
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington case 'e': /* search */
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington usesearch = state;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington break;
ac335315cddc0a42b9235001197dcf719ae737b6Brian Wellington case 'h': /* short */
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington short_form = state;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington if (state) {
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington printcmd = ISC_FALSE;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington lookup->section_additional = ISC_FALSE;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington lookup->section_authority = ISC_FALSE;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington lookup->section_question = ISC_FALSE;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington lookup->comments = ISC_FALSE;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington lookup->stats = ISC_FALSE;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington }
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington break;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington case 't': /* stats */
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington lookup->stats = state;
5caab9f99d19ab9ebb0a0ba64c09c8de80e89e29Brian Wellington break;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington default:
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington goto invalid_option;
5caab9f99d19ab9ebb0a0ba64c09c8de80e89e29Brian Wellington }
5caab9f99d19ab9ebb0a0ba64c09c8de80e89e29Brian Wellington break;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington case 't':
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington switch (cmd[1]) {
5caab9f99d19ab9ebb0a0ba64c09c8de80e89e29Brian Wellington case 'c': /* tcp */
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington if (!is_batchfile)
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington lookup->tcp_mode = state;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington break;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington case 'i': /* timeout */
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington if (value == NULL)
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington goto need_value;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington if (!state)
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington goto invalid_option;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington timeout = parse_int(value, "timeout", MAXTIMEOUT);
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington if (timeout <= 0)
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington timeout = 1;
452123247dcc4c6d30ea3f33f5174df62d84e9aeBrian Wellington break;
452123247dcc4c6d30ea3f33f5174df62d84e9aeBrian Wellington case 'r':
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington switch (cmd[2]) {
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington case 'a': /* trace */
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington lookup->trace = state;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington lookup->trace_root = state;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington if (state) {
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington lookup->recurse = ISC_FALSE;
58aaab3687aac838542ee4ef65a9c094a5d34ab0Michael Graff lookup->identify = ISC_TRUE;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington lookup->comments = ISC_FALSE;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington lookup->stats = ISC_FALSE;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington lookup->section_additional = ISC_FALSE;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington lookup->section_authority = ISC_TRUE;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington lookup->section_question = ISC_FALSE;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington }
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington break;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington case 'i': /* tries */
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington if (value == NULL)
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington goto need_value;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington if (!state)
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington goto invalid_option;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington lookup->retries = parse_int(value, "retries",
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington MAXTRIES);
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence if (lookup->retries <= 0)
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington lookup->retries = 1;
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence break;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington default:
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington goto invalid_option;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington }
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington break;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington default:
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington goto invalid_option;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington }
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington break;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington case 'v':
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington#ifdef DNS_OPT_NEWCODES_LIVE
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington switch (cmd[1]) {
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington default:
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington case 'c': /* vc, and default */
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington#endif /* DNS_OPT_NEWCODES_LIVE */
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington if (!is_batchfile)
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence lookup->tcp_mode = state;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington break;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington#ifdef DNS_OPT_NEWCODES_LIVE
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington case 'i': /* view */
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington if (value == NULL)
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington goto need_value;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington if (!state)
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington goto invalid_option;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington strncpy(lookup->viewname, value, MXNAME);
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington break;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington }
dc3fc5830a90b170c0a2fbf2e8fe057aad209678Brian Wellington break;
dc3fc5830a90b170c0a2fbf2e8fe057aad209678Brian Wellington case 'z': /* zone */
dc3fc5830a90b170c0a2fbf2e8fe057aad209678Brian Wellington if (value == NULL)
dc3fc5830a90b170c0a2fbf2e8fe057aad209678Brian Wellington goto need_value;
dc3fc5830a90b170c0a2fbf2e8fe057aad209678Brian Wellington if (!state)
dc3fc5830a90b170c0a2fbf2e8fe057aad209678Brian Wellington goto invalid_option;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington strncpy(lookup->zonename, value, MXNAME);
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington break;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington#endif /* DNS_OPT_NEWCODES_LIVE */
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington default:
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington invalid_option:
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington need_value:
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington fprintf(stderr, "Invalid option: +%s\n",
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington option);
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington show_usage();
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington exit(1);
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence }
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington return;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington}
d598338952797df77417e69fcb8782b73651f9a9Brian Wellington
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington/*
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington * ISC_TRUE returned if value was used
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington */
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellingtonstatic isc_boolean_t
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellingtondash_option(char *option, char *next, dig_lookup_t **lookup,
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington isc_boolean_t *open_type_class)
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington{
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington char cmd, *value, *ptr;
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_result_t result;
83e4218f6c6497eeaec7fb422b5f662cd98b2ba6David Lawrence isc_boolean_t value_from_next;
83e4218f6c6497eeaec7fb422b5f662cd98b2ba6David Lawrence isc_textregion_t tr;
83e4218f6c6497eeaec7fb422b5f662cd98b2ba6David Lawrence dns_rdatatype_t rdtype;
83e4218f6c6497eeaec7fb422b5f662cd98b2ba6David Lawrence dns_rdataclass_t rdclass;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington char textname[MXNAME];
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_boolean_t orig_rdtypeset;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington dns_rdatatype_t orig_rdtype;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington isc_uint32_t orig_ixfr_serial;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington isc_boolean_t orig_section_question;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington isc_boolean_t orig_comments;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington dns_rdataclass_t orig_rdclass;
5766ea1011051b4a9f7560041a03d9a562722df3Brian Wellington isc_boolean_t orig_rdclassset;
5766ea1011051b4a9f7560041a03d9a562722df3Brian Wellington
5766ea1011051b4a9f7560041a03d9a562722df3Brian Wellington cmd = option[0];
5766ea1011051b4a9f7560041a03d9a562722df3Brian Wellington if (strlen(option) > 1) {
5766ea1011051b4a9f7560041a03d9a562722df3Brian Wellington value_from_next = ISC_FALSE;
5766ea1011051b4a9f7560041a03d9a562722df3Brian Wellington value = &option[1];
5766ea1011051b4a9f7560041a03d9a562722df3Brian Wellington }
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington else {
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington value_from_next = ISC_TRUE;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington value = next;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington }
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington switch (cmd) {
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington case 'd':
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington debugging = ISC_TRUE;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington return (ISC_FALSE);
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington case 'h':
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington show_usage();
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington exit(0);
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington break;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington case 'm': /* memdebug */
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington /* memdebug is handled in preparse_args() */
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington return (ISC_FALSE);
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington case 'n':
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington nibble = ISC_TRUE;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington return (ISC_FALSE);
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington }
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington if (value == NULL)
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington goto invalid_option;
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington switch (cmd) {
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington case 'b':
c7f13217d11f26739a79f0dab391ec372b49b96bBrian Wellington get_address(value, 0, &bind_address);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington specified_source = ISC_TRUE;
3f6dc1703f76a24b34ed3bc839447291c33ca837Brian Wellington return (value_from_next);
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington case 'c':
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if ((*lookup)->rdclassset) {
3f6dc1703f76a24b34ed3bc839447291c33ca837Brian Wellington fprintf(stderr, ";; Warning, extra class option\n");
fb01226bcd598c36b5edc566489c890c39f03ed3Brian Wellington }
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington *open_type_class = ISC_FALSE;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington tr.base = value;
949d406b57fe80fabc6a60d36a0dcee927c780b3Brian Wellington tr.length = strlen(value);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington result = dns_rdataclass_fromtext(&rdclass,
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington (isc_textregion_t *)&tr);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (result == ISC_R_SUCCESS) {
fb01226bcd598c36b5edc566489c890c39f03ed3Brian Wellington (*lookup)->rdclass = rdclass;
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington (*lookup)->rdclassset = ISC_TRUE;
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington }
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington else
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington fprintf(stderr, ";; Warning, ignoring "
1a2c699f0eb89fbd776a2dfabb6e197fe36a8c20Brian Wellington "invalid class %s\n",
1a2c699f0eb89fbd776a2dfabb6e197fe36a8c20Brian Wellington value);
949d406b57fe80fabc6a60d36a0dcee927c780b3Brian Wellington return (value_from_next);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington case 'f':
fb01226bcd598c36b5edc566489c890c39f03ed3Brian Wellington batchname = value;
fb01226bcd598c36b5edc566489c890c39f03ed3Brian Wellington return (value_from_next);
fb01226bcd598c36b5edc566489c890c39f03ed3Brian Wellington case 'k':
fb01226bcd598c36b5edc566489c890c39f03ed3Brian Wellington strncpy(keyfile, value, sizeof(keyfile));
768125e5e51a2eac913f2afbd85566eb468b412cMark Andrews keyfile[sizeof(keyfile)-1]=0;
fb01226bcd598c36b5edc566489c890c39f03ed3Brian Wellington return (value_from_next);
fb01226bcd598c36b5edc566489c890c39f03ed3Brian Wellington case 'p':
15660bccc162db0a7df281f5d743757c527580d5Brian Wellington port = parse_int(value, "port number", MAXPORT);
949d406b57fe80fabc6a60d36a0dcee927c780b3Brian Wellington return (value_from_next);
15660bccc162db0a7df281f5d743757c527580d5Brian Wellington case 't':
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington *open_type_class = ISC_FALSE;
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington if (strncasecmp(value, "ixfr=", 5) == 0) {
949d406b57fe80fabc6a60d36a0dcee927c780b3Brian Wellington rdtype = dns_rdatatype_ixfr;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington result = ISC_R_SUCCESS;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington else
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington tr.base = value;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington tr.length = strlen(value);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington result = dns_rdatatype_fromtext(&rdtype,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington (isc_textregion_t *)&tr);
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington }
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington if (result == ISC_R_SUCCESS) {
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington if ((*lookup)->rdtypeset) {
859ee7da20989e6c4e3cc4e282135668f15c1419Bob Halley fprintf(stderr, ";; Warning, "
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington "extra type option\n");
859ee7da20989e6c4e3cc4e282135668f15c1419Bob Halley }
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington if (rdtype == dns_rdatatype_ixfr) {
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington (*lookup)->rdtype = dns_rdatatype_ixfr;
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington (*lookup)->rdtypeset = ISC_TRUE;
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington (*lookup)->ixfr_serial =
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington parse_int(&value[5], "serial number",
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington MAXSERIAL);
f93d33e24fdf76eb2558168f018b8992bcfc5681Andreas Gustafsson (*lookup)->section_question = plusquest;
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington (*lookup)->comments = pluscomm;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
f93d33e24fdf76eb2558168f018b8992bcfc5681Andreas Gustafsson else
ffdcf33647eb0345dfe84be2c0e7b28264377436Brian Wellington {
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington (*lookup)->rdtype = rdtype;
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington (*lookup)->rdtypeset = ISC_TRUE;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (rdtype == dns_rdatatype_axfr) {
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington (*lookup)->section_question = plusquest;
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington (*lookup)->comments = pluscomm;
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington }
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington else {
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington (*lookup)->section_question = ISC_TRUE;
8dd915daf3f75ac9d04395e61157fdea825f3ebaBrian Wellington (*lookup)->comments = ISC_TRUE;
8dd915daf3f75ac9d04395e61157fdea825f3ebaBrian Wellington }
8dd915daf3f75ac9d04395e61157fdea825f3ebaBrian Wellington (*lookup)->ixfr_serial = ISC_FALSE;
8dd915daf3f75ac9d04395e61157fdea825f3ebaBrian Wellington }
8dd915daf3f75ac9d04395e61157fdea825f3ebaBrian Wellington } else
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff fprintf(stderr, ";; Warning, ignoring "
8dd915daf3f75ac9d04395e61157fdea825f3ebaBrian Wellington "invalid type %s\n",
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington value);
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington return (value_from_next);
e552b980379e3a7ffce1411a939c62e27f953133Brian Wellington case 'y':
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington ptr = next_token(&value,":");
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (ptr == NULL) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington show_usage();
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington exit(1);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington strncpy(keynametext, ptr, sizeof(keynametext));
f93d33e24fdf76eb2558168f018b8992bcfc5681Andreas Gustafsson keynametext[sizeof(keynametext)-1]=0;
8dd915daf3f75ac9d04395e61157fdea825f3ebaBrian Wellington ptr = next_token(&value, "");
8dd915daf3f75ac9d04395e61157fdea825f3ebaBrian Wellington if (ptr == NULL) {
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington show_usage();
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington exit(1);
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington }
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington strncpy(keysecret, ptr, sizeof(keysecret));
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington keysecret[sizeof(keysecret)-1]=0;
949d406b57fe80fabc6a60d36a0dcee927c780b3Brian Wellington return (value_from_next);
949d406b57fe80fabc6a60d36a0dcee927c780b3Brian Wellington case 'x':
b6666e61dc9b91f4ac6af3aa1172bfd8a5f2d6ffBrian Wellington orig_rdtypeset = (*lookup)->rdtypeset;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington orig_rdtype = (*lookup)->rdtype;
8dd915daf3f75ac9d04395e61157fdea825f3ebaBrian Wellington orig_ixfr_serial = (*lookup)->ixfr_serial;
8dd915daf3f75ac9d04395e61157fdea825f3ebaBrian Wellington orig_section_question = (*lookup)->section_question;
8dd915daf3f75ac9d04395e61157fdea825f3ebaBrian Wellington orig_comments = (*lookup)->comments;
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington orig_rdclassset = (*lookup)->rdclassset;
b984520acca2532d048eae929dc0682dd334c7a3Brian Wellington orig_rdclass = (*lookup)->rdclass;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington *lookup = clone_lookup(default_lookup, ISC_TRUE);
if (get_reverse(textname, value, nibble) == 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)->nibble = nibble;
if (!orig_rdtypeset)
(*lookup)->rdtype = dns_rdatatype_ptr;
else
{
(*lookup)->rdtypeset = orig_rdtypeset;
(*lookup)->rdtype = orig_rdtype;
(*lookup)->ixfr_serial = orig_ixfr_serial;
(*lookup)->section_question = orig_section_question;
(*lookup)->comments = orig_comments;
}
if (!orig_rdclassset)
(*lookup)->rdclass = dns_rdataclass_in;
else
{
(*lookup)->rdclassset = orig_rdclassset;
(*lookup)->rdclass = orig_rdclass;
}
(*lookup)->new_search = ISC_TRUE;
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);
show_usage();
exit(1);
}
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;
rc = argc;
rv = argv;
for (rc--, rv++; rc > 0; rc--, rv++) {
if (strcmp(rv[0], "-m") == 0) {
memdebugging = ISC_TRUE;
isc_mem_debugging = ISC_MEM_DEBUGTRACE |
ISC_MEM_DEBUGRECORD;
return;
}
}
}
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_server_t *srv = NULL;
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;
/*
* 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();
#ifndef NOPOSIX
/*
* Treat .digrc as a special batchfile
*/
homedir = getenv("HOME");
if (homedir != NULL)
snprintf(rcfile, sizeof(rcfile), "%s/.digrc", homedir);
else
strcpy(rcfile, ".digrc");
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];
reorder_args(bargc, (char **)bargv);
parse_args(ISC_TRUE, ISC_TRUE, bargc,
(char **)bargv);
}
fclose(batchfp);
}
#endif
}
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) {
srv = make_server(&rv[0][1]);
ISC_LIST_APPEND(lookup->my_server_list,
srv, link);
} 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)) {
rc--;
rv++;
}
} else {
if (dash_option(&rv[0][1], rv[1],
&lookup, &open_type_class)) {
rc--;
rv++;
}
}
} else {
/*
* Anything which isn't an option
*/
if (open_type_class) {
if (strncmp(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)
{
if (lookup->rdtypeset) {
fprintf(stderr, ";; Warning, "
"extra type option\n");
}
if (rdtype == dns_rdatatype_ixfr) {
lookup->rdtype = dns_rdatatype_ixfr;
lookup->rdtypeset = ISC_TRUE;
lookup->ixfr_serial =
parse_int(&rv[0][5],
"serial number",
MAXSERIAL);
lookup->section_question = plusquest;
lookup->comments = pluscomm;
}
else
{
lookup->rdtype = rdtype;
lookup->rdtypeset = ISC_TRUE;
if (rdtype == dns_rdatatype_axfr) {
lookup->section_question =
plusquest;
lookup->comments = pluscomm;
}
else {
lookup->section_question = ISC_TRUE;
lookup->comments = ISC_TRUE;
}
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) {
lookup = clone_lookup(default_lookup,
ISC_TRUE);
if (firstarg) {
printgreeting(argc, argv, lookup);
firstarg = ISC_FALSE;
}
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;
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];
reorder_args(bargc, (char **)bargv);
parse_args(ISC_TRUE, ISC_FALSE, bargc, (char **)bargv);
}
}
/*
* If no lookup specified, search for root
*/
if ((lookup_list.head == NULL) && !config_only) {
lookup = clone_lookup(default_lookup, 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;
printgreeting(argc, argv, lookup);
firstarg = ISC_FALSE;
ISC_LIST_APPEND(lookup_list, lookup, link);
}
/* If we haven't already printed a greeting, and we have a lookup
* with which to print one, do it now. The reason that we sometimes
* call it earlier than this is that we munge some of the things
* printgreeting() needs under certain circumstances. */
if (lookup && firstarg)
{
printgreeting(argc, argv, lookup);
firstarg = ISC_FALSE;
}
}
/*
* Callback from dighost.c to allow program-specific shutdown code. Here,
* 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;
if (batchname == NULL) {
isc_app_shutdown();
return;
}
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;
reorder_args(bargc, (char **)bargv);
parse_args(ISC_TRUE, ISC_FALSE, bargc, (char **)bargv);
start_lookup();
} else {
batchname = NULL;
if (batchfp != stdin)
fclose(batchfp);
isc_app_shutdown();
return;
}
}
int
main(int argc, char **argv) {
isc_result_t result;
dig_server_t *s, *s2;
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();
s = ISC_LIST_HEAD(default_lookup->my_server_list);
while (s != NULL) {
debug("freeing server %p belonging to %p",
s, default_lookup);
s2 = s;
s = ISC_LIST_NEXT(s, link);
ISC_LIST_DEQUEUE(default_lookup->my_server_list, s2, link);
isc_mem_free(mctx, s2);
}
isc_mem_free(mctx, default_lookup);
if (batchname != NULL) {
if (batchfp != stdin)
fclose(batchfp);
batchname = NULL;
}
cancel_all();
destroy_libs();
isc_app_finish();
return (exitcode);
}