dig.c revision fed846067d265db1037483d81d01f3651c8a3f28
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington/*
5fa46bc91672ef5737aee6f99763161511566c24Tinderbox User * Copyright (C) 2000, 2001 Internet Software Consortium.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews *
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Permission to use, copy, modify, and distribute this software for any
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * purpose with or without fee is hereby granted, provided that the above
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * copyright notice and this permission notice appear in all copies.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
28a8f5b0de57d269cf2845c69cb6abe18cbd3b3aMark Andrews/* $Id: dig.c,v 1.147 2001/06/29 06:06:00 bwelling Exp $ */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <config.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <stdlib.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <time.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <ctype.h>
f4b4e7c16211137332e50bcad3fef0d15639a4f1Brian Wellington
f4b4e7c16211137332e50bcad3fef0d15639a4f1Brian Wellington#include <isc/app.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/netaddr.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/print.h>
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington#include <isc/string.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/util.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/task.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/byaddr.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/fixedname.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/masterdump.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/message.h>
229ce407c359b0b641759ba1fc4a5fa2054a44daBrian Wellington#include <dns/name.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/rdata.h>
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington#include <dns/rdataset.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/rdatatype.h>
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington#include <dns/rdataclass.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/result.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dig/dig.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern ISC_LIST(dig_lookup_t) lookup_list;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern dig_serverlist_t server_list;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern ISC_LIST(dig_searchlist_t) search_list;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define ADD_STRING(b, s) { \
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (strlen(s) >= isc_buffer_availablelength(b)) \
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOSPACE); \
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington else \
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington isc_buffer_putstr(b, s); \
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellingtonextern isc_boolean_t have_ipv4, have_ipv6, specified_source,
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington usesearch, qr;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonextern in_port_t port;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern unsigned int timeout;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern isc_mem_t *mctx;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern dns_messageid_t id;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern char *rootspace[BUFSIZE];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern isc_buffer_t rootbuf;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonextern int sendcount;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern int ndots;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern int tries;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern int lookup_counter;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern int exitcode;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern isc_sockaddr_t bind_address;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern char keynametext[MXNAME];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern char keyfile[MXNAME];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern char keysecret[MXNAME];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern dns_tsigkey_t *key;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern isc_boolean_t validated;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern isc_taskmgr_t *taskmgr;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern isc_task_t *global_task;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonextern isc_boolean_t free_now;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondig_lookup_t *default_lookup = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
229ce407c359b0b641759ba1fc4a5fa2054a44daBrian Wellingtonextern isc_boolean_t debugging, memdebugging;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonchar *batchname = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian WellingtonFILE *batchfp = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonchar *argv0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonchar domainopt[DNS_NAME_MAXTEXT];
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonisc_boolean_t short_form = ISC_FALSE, printcmd = ISC_TRUE,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington nibble = ISC_FALSE, plusquest = ISC_FALSE, pluscomm = ISC_FALSE,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington multiline = ISC_FALSE;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonisc_uint16_t bufsize = 0;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonisc_boolean_t forcecomment = ISC_FALSE;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic const char *opcodetext[] = {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "QUERY",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "IQUERY",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "STATUS",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "RESERVED3",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "NOTIFY",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "UPDATE",
92ef1a9b9dbd48ecb507b42ac62c15afefdaf838David Lawrence "RESERVED6",
571688b02f955f6304649866e768b1f81739cbedBrian Wellington "RESERVED7",
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "RESERVED8",
571688b02f955f6304649866e768b1f81739cbedBrian Wellington "RESERVED9",
571688b02f955f6304649866e768b1f81739cbedBrian Wellington "RESERVED10",
571688b02f955f6304649866e768b1f81739cbedBrian Wellington "RESERVED11",
571688b02f955f6304649866e768b1f81739cbedBrian Wellington "RESERVED12",
571688b02f955f6304649866e768b1f81739cbedBrian Wellington "RESERVED13",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "RESERVED14",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "RESERVED15"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington};
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic const char *rcodetext[] = {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "NOERROR",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "FORMERR",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "SERVFAIL",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "NXDOMAIN",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "NOTIMPL",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "REFUSED",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "YXDOMAIN",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "YXRRSET",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "NXRRSET",
557bcc2092642b2d4668c9b08872c9f2bb88bddbMark Andrews "NOTAUTH",
557bcc2092642b2d4668c9b08872c9f2bb88bddbMark Andrews "NOTZONE",
557bcc2092642b2d4668c9b08872c9f2bb88bddbMark Andrews "RESERVED11",
557bcc2092642b2d4668c9b08872c9f2bb88bddbMark Andrews "RESERVED12",
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington "RESERVED13",
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington "RESERVED14",
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington "RESERVED15",
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington "BADVERS"
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington};
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellingtonextern char *progname;
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellingtonstatic void
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellingtonprint_usage(FILE *fp) {
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington fputs(
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington"Usage: dig [@global-server] [domain] [q-type] [q-class] {q-opt}\n"
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington" {global-d-opt} host [@local-server] {local-d-opt}\n"
557bcc2092642b2d4668c9b08872c9f2bb88bddbMark Andrews" [ host [@local-server] {local-d-opt} [...]]\n", fp);
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic void
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonusage() {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington print_usage(stderr);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington fputs("\nUse \"dig -h\" (or \"dig -h | more\") "
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington "for complete list of options\n", stderr);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington exit(1);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic void
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonhelp(void) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington print_usage(stdout);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington fputs(
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington"Where: domain are in the Domain Name System\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" q-class is one of (in,hs,ch,...) [default: in]\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" q-type is one of (a,any,mx,ns,soa,hinfo,axfr,txt,...) [default:a]\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" (Use ixfr=version for type ixfr)\n"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington" q-opt is one of:\n"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington" -x dot-notation (shortcut for in-addr lookups)\n"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington" -n (nibble form for reverse IPv6 lookups)\n"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington" -f filename (batch mode)\n"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington" -p port (specify port number)\n"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington" -t type (specify query type)\n"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington" -c class (specify query class)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" -y name:key (specify named base64 tsig key)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" d-opt is of the form +keyword[=value], where keyword is:\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]vc (TCP mode)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]tcp (TCP mode, alternate syntax)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +time=### (Set query timeout) [5]\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +tries=### (Set number of UDP attempts) [3]\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +domain=### (Set default domainname)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +bufsize=### (Set EDNS0 Max UDP packet size)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]search (Set whether to use searchlist)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]defname (Ditto)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]recursive (Recursive mode)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]ignore (Don't revert to TCP for TC responses.)"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington"\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]fail (Don't try next server on SERVFAIL)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]besteffort (Try to parse even illegal messages)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]aaonly (Set AA flag in query)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]adflag (Set AD flag in query)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]cdflag (Set CD flag in query)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +ndots=### (Set NDOTS value)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]cmd (Control display of command line)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]comments (Control display of comment lines)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]question (Control display of question)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]answer (Control display of answer)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]authority (Control display of authority)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]additional (Control display of additional)\n"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington" +[no]short (Disable everything except short\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" form of answer)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]all (Set or clear all display flags)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +qr (Print question before sending)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]nssearch (Search all authoritative nameservers)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]identify (ID responders in short answers)\n"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington" +[no]trace (Trace delegation down from root)\n"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington" +[no]dnssec (Request DNSSEC records)\n"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington" +[no]multiline (Print records in an expanded format)\n"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington" global d-opts and servers (before host name) affect all queries.\n"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington" local d-opts and servers (after host name) affect only that lookup.\n",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington stdout);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington/*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Callback from dighost.c to print the received message.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonvoid
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellingtonreceived(int bytes, isc_sockaddr_t *from, dig_query_t *query) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_uint64_t diff;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_time_t now;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_result_t result;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington time_t tnow;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington char fromtext[ISC_SOCKADDR_FORMATSIZE];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_sockaddr_format(from, fromtext, sizeof(fromtext));
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews result = isc_time_now(&now);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington check_result(result, "isc_time_now");
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington if (query->lookup->stats) {
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington diff = isc_time_microdiff(&now, &query->time_sent);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews printf(";; Query time: %ld msec\n", (long int)diff/1000);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews printf(";; SERVER: %s(%s)\n", fromtext, query->servname);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington time(&tnow);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington printf(";; WHEN: %s", ctime(&tnow));
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington if (query->lookup->doing_xfr) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington printf(";; XFR size: %d records\n",
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington query->rr_count);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington } else {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington printf(";; MSG SIZE rcvd: %d\n", bytes);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington }
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington if (key != NULL) {
18d0b5e54be891a1aa938c165b6d439859121ec8Mark Andrews if (!validated)
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington puts(";; WARNING -- Some TSIG could not "
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington "be validated");
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington }
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington if ((key == NULL) && (keysecret[0] != 0)) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington puts(";; WARNING -- TSIG key was not used.");
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington }
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington puts("");
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington } else if (query->lookup->identify && !short_form) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington diff = isc_time_microdiff(&now, &query->time_sent);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printf(";; Received %u bytes from %s(%s) in %d ms\n\n",
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington bytes, fromtext, query->servname,
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington (int)diff/1000);
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington }
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington}
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington/*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Callback from dighost.c to print that it is trying a server.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Not used in dig.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * XXX print_trying
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington */
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonvoid
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtontrying(int frmsize, char *frm, dig_lookup_t *lookup) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(frmsize);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington UNUSED(frm);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington UNUSED(lookup);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington}
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington/*
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington * Internal print routine used to print short form replies.
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington */
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonstatic isc_result_t
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonsay_message(dns_rdata_t *rdata, dig_query_t *query, isc_buffer_t *buf) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_result_t result;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_uint64_t diff;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_time_t now;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char store[sizeof("12345678901234567890")];
d2aebe24c477c70e79dc33ea0507e8886eb7d626Brian Wellington
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (query->lookup->trace || query->lookup->ns_search_only) {
de32cbd34e78bdd276e69cff239846760d4ee16eBrian Wellington result = dns_rdatatype_totext(rdata->type, buf);
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews if (result != ISC_R_SUCCESS)
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews return (result);
d2aebe24c477c70e79dc33ea0507e8886eb7d626Brian Wellington ADD_STRING(buf, " ");
d2aebe24c477c70e79dc33ea0507e8886eb7d626Brian Wellington }
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews result = dns_rdata_totext(rdata, NULL, buf);
d2aebe24c477c70e79dc33ea0507e8886eb7d626Brian Wellington check_result(result, "dns_rdata_totext");
d2aebe24c477c70e79dc33ea0507e8886eb7d626Brian Wellington if (query->lookup->identify) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = isc_time_now(&now);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews if (result != ISC_R_SUCCESS)
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews return (result);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews diff = isc_time_microdiff(&now, &query->time_sent);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ADD_STRING(buf, " from server ");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ADD_STRING(buf, query->servname);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington snprintf(store, 19, " in %d ms.", (int)diff/1000);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson ADD_STRING(buf, store);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ADD_STRING(buf, "\n");
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson return (ISC_R_SUCCESS);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington/*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * short_form message print handler. Calls above say_message()
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonshort_answer(dns_message_t *msg, dns_messagetextflag_t flags,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_t *buf, dig_query_t *query)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_t *name;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_t *rdataset;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_t target;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_result_t result, loopresult;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_t empty_name;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char t[4096];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_t rdata = DNS_RDATA_INIT;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(flags);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_init(&empty_name, NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_message_firstname(msg, DNS_SECTION_ANSWER);
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater if (result == ISC_R_NOMORE)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_SUCCESS);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington else if (result != ISC_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington for (;;) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington name = NULL;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_message_currentname(msg, DNS_SECTION_ANSWER, &name);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_buffer_init(&target, t, sizeof(t));
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson for (rdataset = ISC_LIST_HEAD(name->list);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson rdataset != NULL;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson rdataset = ISC_LIST_NEXT(rdataset, link)) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson loopresult = dns_rdataset_first(rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington while (loopresult == ISC_R_SUCCESS) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_rdataset_current(rdataset, &rdata);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = say_message(&rdata, query,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson buf);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson check_result(result, "say_message");
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson loopresult = dns_rdataset_next(rdataset);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_rdata_reset(&rdata);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson }
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson }
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = dns_message_nextname(msg, DNS_SECTION_ANSWER);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (result == ISC_R_NOMORE)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson break;
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater else if (result != ISC_R_SUCCESS)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson return (result);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson }
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson return (ISC_R_SUCCESS);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson}
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
daa73eae708d568d453e6082e0890d35886a9e0fMark Andrews/*
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson * Callback from dighost.c to print the reply from a server
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson */
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssonisc_result_t
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssonprintmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_boolean_t did_flag = ISC_FALSE;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_result_t result;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_messagetextflag_t flags;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_buffer_t *buf = NULL;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson unsigned int len = OUTPUTBUF;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson const dns_master_style_t *style;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (multiline)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson style = &dns_master_style_default;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson else
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson style = &dns_master_style_debug;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
daa73eae708d568d453e6082e0890d35886a9e0fMark Andrews if (query->lookup->cmdline[0] != 0) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson fputs(query->lookup->cmdline, stdout);
daa73eae708d568d453e6082e0890d35886a9e0fMark Andrews query->lookup->cmdline[0]=0;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson }
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson debug("printmessage(%s %s %s)", headers ? "headers" : "noheaders",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington query->lookup->comments ? "comments" : "nocomments",
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington short_form ? "short_form" : "long_form");
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington flags = 0;
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington if (!headers) {
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington flags |= DNS_MESSAGETEXTFLAG_NOHEADERS;
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington flags |= DNS_MESSAGETEXTFLAG_NOCOMMENTS;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (!query->lookup->comments)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington flags |= DNS_MESSAGETEXTFLAG_NOCOMMENTS;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = ISC_R_SUCCESS;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
6c7f722d31d12cf83964c8132f0a59ef70e34cb5Mark Andrews result = isc_buffer_allocate(mctx, &buf, len);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson check_result(result, "isc_buffer_allocate");
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (query->lookup->comments && !short_form) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (query->lookup->cmdline[0] != 0)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printf("; %s\n", query->lookup->cmdline);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (msg == query->lookup->sendmsg)
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews printf(";; Sending:\n");
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews else
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson printf(";; Got answer:\n");
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (headers) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printf(";; ->>HEADER<<- opcode: %s, status: %s, "
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson "id: %u\n",
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson opcodetext[msg->opcode], rcodetext[msg->rcode],
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson msg->id);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson printf(";; flags: ");
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if ((msg->flags & DNS_MESSAGEFLAG_QR) != 0) {
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews printf("qr");
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson did_flag = ISC_TRUE;
229ce407c359b0b641759ba1fc4a5fa2054a44daBrian Wellington }
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if ((msg->flags & DNS_MESSAGEFLAG_AA) != 0) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson printf("%saa", did_flag ? " " : "");
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson did_flag = ISC_TRUE; }
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews if ((msg->flags & DNS_MESSAGEFLAG_TC) != 0) {
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews printf("%stc", did_flag ? " " : "");
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews did_flag = ISC_TRUE;
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews }
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews if ((msg->flags & DNS_MESSAGEFLAG_RD) != 0) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson printf("%srd", did_flag ? " " : "");
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson did_flag = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if ((msg->flags & DNS_MESSAGEFLAG_RA) != 0) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printf("%sra", did_flag ? " " : "");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington did_flag = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if ((msg->flags & DNS_MESSAGEFLAG_AD) != 0) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson printf("%sad", did_flag ? " " : "");
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson did_flag = ISC_TRUE;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if ((msg->flags & DNS_MESSAGEFLAG_CD) != 0) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson printf("%scd", did_flag ? " " : "");
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson did_flag = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printf("; QUERY: %u, ANSWER: %u, "
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "AUTHORITY: %u, ADDITIONAL: %u\n",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington msg->counts[DNS_SECTION_QUESTION],
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington msg->counts[DNS_SECTION_ANSWER],
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson msg->counts[DNS_SECTION_AUTHORITY],
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson msg->counts[DNS_SECTION_ADDITIONAL]);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonrepopulate_buffer:
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (query->lookup->comments && headers && !short_form)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = dns_message_pseudosectiontotext(msg,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington DNS_PSEUDOSECTION_OPT,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington style, flags, buf);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (result == ISC_R_NOSPACE) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonbuftoosmall:
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington len += OUTPUTBUF;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_buffer_free(&buf);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = isc_buffer_allocate(mctx, &buf, len);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (result == ISC_R_SUCCESS)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington goto repopulate_buffer;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington else
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (result);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington check_result(result,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "dns_message_pseudosectiontotext");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (query->lookup->section_question && headers) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (!short_form) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = dns_message_sectiontotext(msg,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington DNS_SECTION_QUESTION,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington style, flags, buf);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (result == ISC_R_NOSPACE)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington goto buftoosmall;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington check_result(result, "dns_message_sectiontotext");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (query->lookup->section_answer) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (!short_form) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = dns_message_sectiontotext(msg,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington DNS_SECTION_ANSWER,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington style, flags, buf);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (result == ISC_R_NOSPACE)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington goto buftoosmall;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington check_result(result, "dns_message_sectiontotext");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington } else {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = short_answer(msg, flags, buf, query);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (result == ISC_R_NOSPACE)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington goto buftoosmall;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington check_result(result, "short_answer");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (query->lookup->section_authority) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (!short_form) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = dns_message_sectiontotext(msg,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson DNS_SECTION_AUTHORITY,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson style, flags, buf);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (result == ISC_R_NOSPACE)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson goto buftoosmall;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson check_result(result, "dns_message_sectiontotext");
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson }
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson }
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (query->lookup->section_additional) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (!short_form) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = dns_message_sectiontotext(msg,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson DNS_SECTION_ADDITIONAL,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson style, flags, buf);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (result == ISC_R_NOSPACE)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington goto buftoosmall;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson check_result(result, "dns_message_sectiontotext");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington /*
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson * Only print the signature on the first record.
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson */
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (headers) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = dns_message_pseudosectiontotext(
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson msg,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson DNS_PSEUDOSECTION_TSIG,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson style, flags, buf);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (result == ISC_R_NOSPACE)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson goto buftoosmall;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson check_result(result,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson "dns_message_pseudosectiontotext");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = dns_message_pseudosectiontotext(
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington msg,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington DNS_PSEUDOSECTION_SIG0,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington style, flags, buf);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result == ISC_R_NOSPACE)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto buftoosmall;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington check_result(result,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "dns_message_pseudosectiontotext");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (headers && query->lookup->comments && !short_form)
f3ca27e9fe307b55e35ea8d7b37351650630e5a3Andreas Gustafsson printf("\n");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printf("%.*s", (int)isc_buffer_usedlength(buf),
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (char *)isc_buffer_base(buf));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_free(&buf);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington/*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * print the greeting message when the program first starts up.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic void
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonprintgreeting(int argc, char **argv, dig_lookup_t *lookup) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington int i;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington int remaining;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington static isc_boolean_t first = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char append[MXNAME];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (printcmd) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->cmdline[sizeof(lookup->cmdline) - 1] = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington snprintf(lookup->cmdline, sizeof(lookup->cmdline),
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "%s; <<>> DiG " VERSION " <<>>",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington first?"\n":"");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington i = 1;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington while (i < argc) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington snprintf(append, sizeof(append), " %s", argv[i++]);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington remaining = sizeof(lookup->cmdline) -
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strlen(lookup->cmdline) - 1;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncat(lookup->cmdline, append, remaining);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington remaining = sizeof(lookup->cmdline) -
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strlen(lookup->cmdline) - 1;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncat(lookup->cmdline, "\n", remaining);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (first) {
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington snprintf(append, sizeof (append),
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington ";; global options: %s %s\n",
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington short_form ? "short_form" : "",
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington printcmd ? "printcmd" : "");
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington first = ISC_FALSE;
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington remaining = sizeof(lookup->cmdline) -
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strlen(lookup->cmdline) - 1;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncat(lookup->cmdline, append, remaining);
5e387b9ce6bafdfadedb5b34e4c33a4404e5d589Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington/*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Reorder an argument list so that server names all come at the end.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * This is a bit of a hack, to allow batch-mode processing to properly
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * handle the server options.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic void
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonreorder_args(int argc, char *argv[]) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington int i, j;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char *ptr;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington int end;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington debug("reorder_args()");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington end = argc - 1;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington while (argv[end][0] == '@') {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington end--;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (end == 0)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington debug("arg[end]=%s", argv[end]);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington for (i = 1; i < end - 1; i++) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (argv[i][0] == '@') {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington debug("arg[%d]=%s", i, argv[i]);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ptr = argv[i];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington for (j = i + 1; j < end; j++) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington debug("Moving %s to %d", argv[j], j - 1);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington argv[j - 1] = argv[j];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington debug("moving %s to end, %d", ptr, end - 1);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington argv[end - 1] = ptr;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington end--;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (end < 1)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_uint32_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonparse_int(char *arg, const char *desc, isc_uint32_t max) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char *endp;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_uint32_t tmp;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington tmp = strtoul(arg, &endp, 10);
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews if (*endp != '\0')
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews fatal("%s '%s' must be numeric", desc, arg);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (tmp > max)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington fatal("%s '%s' out of range", desc, arg);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (tmp);
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington/*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * We're not using isc_commandline_parse() here since the command line
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * syntax of dig is quite a bit different from that which can be described
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * by that routine.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * XXX doc options
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic void
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonplus_option(char *option, isc_boolean_t is_batchfile,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dig_lookup_t *lookup)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char option_store[256];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char *cmd, *value, *ptr;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_boolean_t state = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncpy(option_store, option, sizeof(option_store));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington option_store[sizeof(option_store)-1]=0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ptr = option_store;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington cmd=next_token(&ptr,"=");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (cmd == NULL) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printf(";; Invalid option %s\n",option_store);
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater return;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington value=ptr;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (strncasecmp(cmd,"no",2)==0) {
c0d2891f6e08fcf5379dfb9a1bf8fbbb63f1952aMark Andrews cmd += 2;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington state = ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
c0d2891f6e08fcf5379dfb9a1bf8fbbb63f1952aMark Andrews switch (cmd[0]) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'a':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington switch (cmd[1]) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'a': /* aaflag */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->aaonly = state;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'd':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington switch (cmd[2]) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'd': /* additional */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->section_additional = state;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'f': /* adflag */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->adflag = state;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington default:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto invalid_option;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'l': /* all */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->section_question = state;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->section_authority = state;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->section_answer = state;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->section_additional = state;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->comments = state;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'n': /* answer */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->section_answer = state;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington case 'u': /* authority */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington lookup->section_authority = state;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington default:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto invalid_option;
18d0b5e54be891a1aa938c165b6d439859121ec8Mark Andrews }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
229ce407c359b0b641759ba1fc4a5fa2054a44daBrian Wellington case 'b':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington switch (cmd[1]) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'e':/* besteffort */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->besteffort = state;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'u':/* bufsize */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (value == NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto need_value;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (!state)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto invalid_option;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->udpsize = parse_int(value, "buffer size",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington COMMSIZE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (lookup->udpsize <= 0)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->udpsize = 0;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (lookup->udpsize > COMMSIZE)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington lookup->udpsize = COMMSIZE;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington break;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington default:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto invalid_option;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'c':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington switch (cmd[1]) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'd':/* cdflag */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington lookup->cdflag = state;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'm': /* cmd */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington printcmd = state;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'o': /* comments */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->comments = state;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (lookup == default_lookup)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington pluscomm = state;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington default:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto invalid_option;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington break;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington case 'd':
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington switch (cmd[1]) {
5e387b9ce6bafdfadedb5b34e4c33a4404e5d589Brian Wellington case 'e': /* defname */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington usesearch = state;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington break;
daa73eae708d568d453e6082e0890d35886a9e0fMark Andrews case 'n': /* dnssec */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->dnssec = state;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'o': /* domain */
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt if (value == NULL)
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt goto need_value;
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt if (!state)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto invalid_option;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncpy(domainopt, value, sizeof(domainopt));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington domainopt[sizeof(domainopt)-1] = '\0';
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington default:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto invalid_option;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington break;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews case 'f': /* fail */
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews lookup->servfail_stops = state;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'i':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington switch (cmd[1]) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'd': /* identify */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->identify = state;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
7a6f285bc933d08353d2f18290c85def575b6e57Andreas Gustafsson case 'g': /* ignore */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington default: /* Inherets default for compatibility */
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington lookup->ignore = ISC_TRUE;
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington }
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews break;
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington case 'm': /* multiline */
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews multiline = state;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews break;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews case 'n':
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews switch (cmd[1]) {
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews case 'd': /* ndots */
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews if (value == NULL)
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews goto need_value;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews if (!state)
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington goto invalid_option;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews ndots = parse_int(value, "ndots", MAXNDOTS);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews if (ndots < 0)
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews ndots = 0;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews break;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews case 's': /* nssearch */
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews lookup->ns_search_only = state;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews if (state) {
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews lookup->trace_root = ISC_TRUE;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews lookup->recurse = ISC_FALSE;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews lookup->identify = ISC_TRUE;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews lookup->stats = ISC_FALSE;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews lookup->comments = ISC_FALSE;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews lookup->section_additional = ISC_FALSE;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews lookup->section_authority = ISC_FALSE;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews lookup->section_question = ISC_FALSE;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews lookup->rdtype = dns_rdatatype_soa;
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington lookup->rdtypeset = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington short_form = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington default:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto invalid_option;
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington }
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews break;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews case 'q':
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews switch (cmd[1]) {
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews case 'r': /* qr */
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews qr = state;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews break;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews case 'u': /* question */
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington lookup->section_question = state;
6e93e6ea4557291e847aced6a88adcdf39f06843Andreas Gustafsson if (lookup == default_lookup)
6e93e6ea4557291e847aced6a88adcdf39f06843Andreas Gustafsson plusquest = state;
6e93e6ea4557291e847aced6a88adcdf39f06843Andreas Gustafsson break;
6e93e6ea4557291e847aced6a88adcdf39f06843Andreas Gustafsson default:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto invalid_option;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'r': /* recurse */
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington lookup->recurse = state;
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington break;
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington case 's':
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington switch (cmd[1]) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'e': /* search */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington usesearch = state;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'h': /* short */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington short_form = state;
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater if (state) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printcmd = ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->section_additional = ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->section_authority = ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->section_question = ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->comments = ISC_FALSE;
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt lookup->stats = ISC_FALSE;
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt }
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt break;
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt case 't': /* stats */
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt lookup->stats = state;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington default:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto invalid_option;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 't':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington switch (cmd[1]) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'c': /* tcp */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (!is_batchfile)
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews lookup->tcp_mode = state;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'i': /* timeout */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (value == NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto need_value;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (!state)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto invalid_option;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington timeout = parse_int(value, "timeout", MAXTIMEOUT);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (timeout <= 0)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington timeout = 1;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'r':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington switch (cmd[2]) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'a': /* trace */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->trace = state;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->trace_root = state;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (state) {
fefe1106d96d3a89b21315f665b36a67cdea3840Mark Andrews lookup->recurse = ISC_FALSE;
fefe1106d96d3a89b21315f665b36a67cdea3840Mark Andrews lookup->identify = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->comments = ISC_FALSE;
fefe1106d96d3a89b21315f665b36a67cdea3840Mark Andrews lookup->stats = ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->section_additional = ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->section_authority = ISC_TRUE;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews lookup->section_question = ISC_FALSE;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews }
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'i': /* tries */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (value == NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto need_value;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (!state)
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt goto invalid_option;
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt lookup->retries = parse_int(value, "retries",
85fcd0b9b2d80be4646187d7094e5644a52e3263Mark Andrews MAXTRIES);
85fcd0b9b2d80be4646187d7094e5644a52e3263Mark Andrews if (lookup->retries <= 0)
85fcd0b9b2d80be4646187d7094e5644a52e3263Mark Andrews lookup->retries = 1;
85fcd0b9b2d80be4646187d7094e5644a52e3263Mark Andrews break;
85fcd0b9b2d80be4646187d7094e5644a52e3263Mark Andrews default:
85fcd0b9b2d80be4646187d7094e5644a52e3263Mark Andrews goto invalid_option;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington default:
85fcd0b9b2d80be4646187d7094e5644a52e3263Mark Andrews goto invalid_option;
85fcd0b9b2d80be4646187d7094e5644a52e3263Mark Andrews }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews case 'v':
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews#ifdef DNS_OPT_NEWCODES_LIVE
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews switch (cmd[1]) {
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews default:
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews case 'c': /* vc, and default */
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews#endif /* DNS_OPT_NEWCODES_LIVE */
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews if (!is_batchfile)
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews lookup->tcp_mode = state;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews break;
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews#ifdef DNS_OPT_NEWCODES_LIVE
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews case 'i': /* view */
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews if (value == NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto need_value;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (!state)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto invalid_option;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncpy(lookup->viewname, value, MXNAME);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'z': /* zone */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (value == NULL)
c302b021cc65cc9a358a9a1cbe48de12364f4cb6Brian Wellington goto need_value;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (!state)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto invalid_option;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncpy(lookup->zonename, value, MXNAME);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#endif /* DNS_OPT_NEWCODES_LIVE */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington default:
0a45f098e446a7f41c2a71d9dd0fd8f459b49c34Brian Wellington invalid_option:
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington need_value:
0a45f098e446a7f41c2a71d9dd0fd8f459b49c34Brian Wellington fprintf(stderr, "Invalid option: +%s\n",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington option);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington usage();
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return;
c302b021cc65cc9a358a9a1cbe48de12364f4cb6Brian Wellington}
c302b021cc65cc9a358a9a1cbe48de12364f4cb6Brian Wellington
c302b021cc65cc9a358a9a1cbe48de12364f4cb6Brian Wellington/*
c302b021cc65cc9a358a9a1cbe48de12364f4cb6Brian Wellington * ISC_TRUE returned if value was used
b1b0dca1464a11b8a63623e8567e744dccfbcb41Tatuya JINMEI 神明達哉 */
b1b0dca1464a11b8a63623e8567e744dccfbcb41Tatuya JINMEI 神明達哉static isc_boolean_t
ab381c1e22e0ed732170428937d20d13146d863aAutomatic Updaterdash_option(char *option, char *next, dig_lookup_t **lookup,
c302b021cc65cc9a358a9a1cbe48de12364f4cb6Brian Wellington isc_boolean_t *open_type_class,
c302b021cc65cc9a358a9a1cbe48de12364f4cb6Brian Wellington isc_boolean_t *firstarg,
b1b0dca1464a11b8a63623e8567e744dccfbcb41Tatuya JINMEI 神明達哉 int argc, char **argv)
c302b021cc65cc9a358a9a1cbe48de12364f4cb6Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char cmd, *value, *ptr;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_result_t result;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_boolean_t value_from_next;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_textregion_t tr;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatatype_t rdtype;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataclass_t rdclass;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char textname[MXNAME];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington struct in_addr in4;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington struct in6_addr in6;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington cmd = option[0];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (strlen(option) > 1) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington value_from_next = ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington value = &option[1];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington } else {
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews value_from_next = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington value = next;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington switch (cmd) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'd':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington debugging = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_FALSE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'h':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington help();
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington exit(0);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'm': /* memdebug */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /* memdebug is handled in preparse_args() */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_FALSE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'n':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington nibble = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_FALSE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (value == NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto invalid_option;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington switch (cmd) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'b':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (have_ipv6 && inet_pton(AF_INET6, value, &in6) == 1)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_sockaddr_fromin6(&bind_address, &in6, 0);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington else if (have_ipv4 && inet_pton(AF_INET, value, &in4) == 1)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_sockaddr_fromin(&bind_address, &in4, 0);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington else
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington fatal("invalid address %s", value);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington specified_source = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (value_from_next);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'c':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if ((*lookup)->rdclassset) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington fprintf(stderr, ";; Warning, extra class option\n");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *open_type_class = ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington tr.base = value;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington tr.length = strlen(value);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdataclass_fromtext(&rdclass,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (isc_textregion_t *)&tr);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result == ISC_R_SUCCESS) {
b7cd261f2fca2c7138cdc6ae8ee434e9c0031303Brian Wellington (*lookup)->rdclass = rdclass;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (*lookup)->rdclassset = ISC_TRUE;
cfcb0881d12db2b7cb33475b7d20ac6c9015203bMark Andrews } else
cfcb0881d12db2b7cb33475b7d20ac6c9015203bMark Andrews fprintf(stderr, ";; Warning, ignoring "
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "invalid class %s\n",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington value);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (value_from_next);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'f':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington batchname = value;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (value_from_next);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'k':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncpy(keyfile, value, sizeof(keyfile));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington keyfile[sizeof(keyfile)-1]=0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (value_from_next);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'p':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington port = parse_int(value, "port number", MAXPORT);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (value_from_next);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 't':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *open_type_class = ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (strncasecmp(value, "ixfr=", 5) == 0) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdtype = dns_rdatatype_ixfr;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = ISC_R_SUCCESS;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington } else {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington tr.base = value;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington tr.length = strlen(value);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdatatype_fromtext(&rdtype,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (isc_textregion_t *)&tr);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result == ISC_R_SUCCESS &&
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdtype == dns_rdatatype_ixfr)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = DNS_R_UNKNOWN;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result == ISC_R_SUCCESS) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if ((*lookup)->rdtypeset) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington fprintf(stderr, ";; Warning, "
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "extra type option\n");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (rdtype == dns_rdatatype_ixfr) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (*lookup)->rdtype = dns_rdatatype_ixfr;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (*lookup)->rdtypeset = ISC_TRUE;
7a6f285bc933d08353d2f18290c85def575b6e57Andreas Gustafsson (*lookup)->ixfr_serial =
7a6f285bc933d08353d2f18290c85def575b6e57Andreas Gustafsson parse_int(&value[5], "serial number",
7a6f285bc933d08353d2f18290c85def575b6e57Andreas Gustafsson MAXSERIAL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (*lookup)->section_question = plusquest;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (*lookup)->comments = pluscomm;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington } else {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (*lookup)->rdtype = rdtype;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (*lookup)->rdtypeset = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (rdtype == dns_rdatatype_axfr) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (*lookup)->section_question = plusquest;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (*lookup)->comments = pluscomm;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (*lookup)->ixfr_serial = ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington } else
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington fprintf(stderr, ";; Warning, ignoring "
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "invalid type %s\n",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington value);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (value_from_next);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'y':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ptr = next_token(&value,":");
7a6f285bc933d08353d2f18290c85def575b6e57Andreas Gustafsson if (ptr == NULL) {
7a6f285bc933d08353d2f18290c85def575b6e57Andreas Gustafsson usage();
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncpy(keynametext, ptr, sizeof(keynametext));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington keynametext[sizeof(keynametext)-1]=0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ptr = next_token(&value, "");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (ptr == NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington usage();
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncpy(keysecret, ptr, sizeof(keysecret));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington keysecret[sizeof(keysecret)-1]=0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (value_from_next);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington case 'x':
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *lookup = clone_lookup(default_lookup, ISC_TRUE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (get_reverse(textname, value, nibble) == ISC_R_SUCCESS) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncpy((*lookup)->textname, textname,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sizeof((*lookup)->textname));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington debug("looking up %s", (*lookup)->textname);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (*lookup)->trace_root = ISC_TF((*lookup)->trace ||
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (*lookup)->ns_search_only);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (*lookup)->nibble = nibble;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (!(*lookup)->rdtypeset)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (*lookup)->rdtype = dns_rdatatype_ptr;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (!(*lookup)->rdclassset)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (*lookup)->rdclass = dns_rdataclass_in;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (*lookup)->new_search = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (*lookup && *firstarg)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printgreeting(argc, argv, *lookup);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *firstarg = ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_APPEND(lookup_list, *lookup, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington } else {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington fprintf(stderr, "Invalid IP address %s\n", value);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington exit(1);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews return (value_from_next);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington invalid_option:
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington default:
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington fprintf(stderr, "Invalid option: -%s\n", option);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington usage();
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (ISC_FALSE);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington}
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington/*
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * Because we may be trying to do memory allocation recording, we're going
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * to need to parse the arguments for the -m *before* we start the main
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * argument parsing routine.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * I'd prefer not to have to do this, but I am not quite sure how else to
6e2871232f7ede047799480370aff444be1f5a13Automatic Updater * fix the problem. Argument parsing in dig involves memory allocation
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * by its nature, so it can't be done in the main argument parser.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic void
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonpreparse_args(int argc, char **argv) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington int rc;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington char **rv;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington rc = argc;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews rv = argv;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington for (rc--, rv++; rc > 0; rc--, rv++) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (strcmp(rv[0], "-m") == 0) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington memdebugging = ISC_TRUE;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_mem_debugging = ISC_MEM_DEBUGTRACE |
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington ISC_MEM_DEBUGRECORD;
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington return;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington}
daa73eae708d568d453e6082e0890d35886a9e0fMark Andrews
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic void
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonparse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington int argc, char **argv) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_result_t result;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_textregion_t tr;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_boolean_t firstarg = ISC_TRUE;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dig_server_t *srv = NULL;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dig_lookup_t *lookup = NULL;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_rdatatype_t rdtype;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_rdataclass_t rdclass;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_boolean_t open_type_class = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char batchline[MXNAME];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington int bargc;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char *bargv[64];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington int rc;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char **rv;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#ifndef NOPOSIX
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char *homedir;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char rcfile[256];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#endif
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char *input;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * The semantics for parsing the args is a bit complex; if
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * we don't have a host yet, make the arg apply globally,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * otherwise make it apply to the latest host. This is
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * a bit different than the previous versions, but should
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * form a consistent user interface.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews * First, create a "default lookup" which won't actually be used
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * anywhere, except for cloning into new lookups
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington debug("parse_args()");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (!is_batchfile) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington debug("making new lookup");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington default_lookup = make_empty_lookup();
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#ifndef NOPOSIX
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Treat .digrc as a special batchfile
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington homedir = getenv("HOME");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (homedir != NULL)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington snprintf(rcfile, sizeof(rcfile), "%s/.digrc", homedir);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington else
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strcpy(rcfile, ".digrc");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington batchfp = fopen(rcfile, "r");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (batchfp != NULL) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington while (fgets(batchline, sizeof(batchline),
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington batchfp) != 0) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington debug("config line %s", batchline);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington bargc = 1;
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater input = batchline;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington bargv[bargc] = next_token(&input, " \t\r\n");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington while ((bargv[bargc] != NULL) &&
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (bargc < 62)) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington bargc++;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington bargv[bargc] = next_token(&input, " \t\r\n");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington bargv[0] = argv[0];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington argv0 = argv[0];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington reorder_args(bargc, (char **)bargv);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington parse_args(ISC_TRUE, ISC_TRUE, bargc,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (char **)bargv);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington fclose(batchfp);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#endif
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup = default_lookup;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rc = argc;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rv = argv;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington for (rc--, rv++; rc > 0; rc--, rv++) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington debug("main parsing %s", rv[0]);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (strncmp(rv[0], "%", 1) == 0)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (strncmp(rv[0], "@", 1) == 0) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington srv = make_server(&rv[0][1]);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_APPEND(lookup->my_server_list,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington srv, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington } else if (rv[0][0] == '+') {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington plus_option(&rv[0][1], is_batchfile,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington } else if (rv[0][0] == '-') {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (rc <= 1) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (dash_option(&rv[0][1], NULL,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington &lookup, &open_type_class,
f8abaa0fae7f75d9601c10b6a4af8dd907494d45Mark Andrews &firstarg, argc, argv)) {
b55c30f2de6e1baaa3a9ba69b92f428f2c255ac3Mark Andrews rc--;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rv++;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington } else {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (dash_option(&rv[0][1], rv[1],
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington &lookup, &open_type_class,
f8abaa0fae7f75d9601c10b6a4af8dd907494d45Mark Andrews &firstarg, argc, argv)) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rc--;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rv++;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington } else {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Anything which isn't an option
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (open_type_class) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (strncmp(rv[0], "ixfr=", 5) == 0) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdtype = dns_rdatatype_ixfr;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = ISC_R_SUCCESS;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington } else {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington tr.base = rv[0];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington tr.length = strlen(rv[0]);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdatatype_fromtext(&rdtype,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (isc_textregion_t *)&tr);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result == ISC_R_SUCCESS &&
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdtype == dns_rdatatype_ixfr)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = DNS_R_UNKNOWN;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington fprintf(stderr, ";; Warning, "
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "ixfr requires a "
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "serial number\n");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington continue;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result == ISC_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (lookup->rdtypeset) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington fprintf(stderr, ";; Warning, "
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "extra type option\n");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (rdtype == dns_rdatatype_ixfr) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->rdtype = dns_rdatatype_ixfr;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->rdtypeset = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->ixfr_serial =
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington parse_int(&rv[0][5],
4a30ede93d59137009db734661cde17612e8ffbeMark Andrews "serial number",
4a30ede93d59137009db734661cde17612e8ffbeMark Andrews MAXSERIAL);
4a30ede93d59137009db734661cde17612e8ffbeMark Andrews lookup->section_question = plusquest;
4a30ede93d59137009db734661cde17612e8ffbeMark Andrews lookup->comments = pluscomm;
4a30ede93d59137009db734661cde17612e8ffbeMark Andrews } else {
4a30ede93d59137009db734661cde17612e8ffbeMark Andrews lookup->rdtype = rdtype;
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrews lookup->rdtypeset = ISC_TRUE;
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrews if (rdtype == dns_rdatatype_axfr) {
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrews lookup->section_question =
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrews plusquest;
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrews lookup->comments = pluscomm;
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrews }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->ixfr_serial = ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington continue;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdataclass_fromtext(&rdclass,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (isc_textregion_t *)&tr);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result == ISC_R_SUCCESS) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (lookup->rdclassset) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington fprintf(stderr, ";; Warning, "
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "extra class option\n");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt lookup->rdclass = rdclass;
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt lookup->rdclassset = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington continue;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (!config_only) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup = clone_lookup(default_lookup,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_TRUE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (firstarg) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printgreeting(argc, argv, lookup);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington firstarg = ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncpy(lookup->textname, rv[0],
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sizeof(lookup->textname));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->textname[sizeof(lookup->textname)-1]=0;
4a30ede93d59137009db734661cde17612e8ffbeMark Andrews lookup->trace_root = ISC_TF(lookup->trace ||
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrews lookup->ns_search_only);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 lookup->new_search = ISC_TRUE;
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt ISC_LIST_APPEND(lookup_list, lookup, link);
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt debug("looking up %s", lookup->textname);
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt }
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt /* XXX Error message */
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt }
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt }
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt /*
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt * If we have a batchfile, seed the lookup list with the
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt * first entry, then trust the callback in dighost_shutdown
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt * to get the rest
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt */
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt if ((batchname != NULL) && !(is_batchfile)) {
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt if (strcmp(batchname, "-") == 0)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington batchfp = stdin;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington else
6fd4ab217ef8e37703b029eac5ab7ae4f7a663c9Brian Wellington batchfp = fopen(batchname, "r");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (batchfp == NULL) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington perror(batchname);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington if (exitcode < 8)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington exitcode = 8;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington fatal("Couldn't open specified batch file");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /* XXX Remove code dup from shutdown code */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington next_line:
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington if (fgets(batchline, sizeof(batchline), batchfp) != 0) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington bargc = 1;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington debug("batch line %s", batchline);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (batchline[0] == '\r' || batchline[0] == '\n'
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington || batchline[0] == '#' || batchline[0] == ';')
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto next_line;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington input = batchline;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington bargv[bargc] = next_token(&input, " \t\r\n");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington while ((bargv[bargc] != NULL) && (bargc < 14)) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington bargc++;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington bargv[bargc] = next_token(&input, " \t\r\n");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington bargv[0] = argv[0];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington argv0 = argv[0];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington reorder_args(bargc, (char **)bargv);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington parse_args(ISC_TRUE, ISC_FALSE, bargc, (char **)bargv);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * If no lookup specified, search for root
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if ((lookup_list.head == NULL) && !config_only) {
18d0b5e54be891a1aa938c165b6d439859121ec8Mark Andrews lookup = clone_lookup(default_lookup, ISC_TRUE);
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington lookup->trace_root = ISC_TF(lookup->trace ||
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->ns_search_only);
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington lookup->new_search = ISC_TRUE;
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington strcpy(lookup->textname, ".");
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington lookup->rdtype = dns_rdatatype_ns;
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington lookup->rdtypeset = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (firstarg) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printgreeting(argc, argv, lookup);
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington firstarg = ISC_FALSE;
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_APPEND(lookup_list, lookup, link);
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington/*
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington * Callback from dighost.c to allow program-specific shutdown code. Here,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Here, we're possibly reading from a batch file, then shutting down for
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington * real if there's nothing in the batch file to read.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellingtonvoid
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellingtondighost_shutdown(void) {
34f991028382079af7c2b53bac6768803ff28f8cBrian Wellington char batchline[MXNAME];
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington int bargc;
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington char *bargv[16];
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington char *input;
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (batchname == NULL) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_app_shutdown();
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (feof(batchfp)) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington batchname = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_app_shutdown();
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (batchfp != stdin)
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington fclose(batchfp);
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington return;
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington }
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington if (fgets(batchline, sizeof(batchline), batchfp) != 0) {
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington debug("batch line %s", batchline);
0a25550b464ad40e4d90ebff8ecf23595b05ae3bFrancis Dupont bargc = 1;
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington input = batchline;
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington bargv[bargc] = next_token(&input, " \t\r\n");
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington while ((bargv[bargc] != NULL) && (bargc < 14)) {
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington bargc++;
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington bargv[bargc] = next_token(&input, " \t\r\n");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington bargv[0] = argv0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington reorder_args(bargc, (char **)bargv);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington parse_args(ISC_TRUE, ISC_FALSE, bargc, (char **)bargv);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington start_lookup();
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington } else {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington batchname = NULL;
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington if (batchfp != stdin)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington fclose(batchfp);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_app_shutdown();
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonint
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellingtonmain(int argc, char **argv) {
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington isc_result_t result;
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington dig_server_t *s, *s2;
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington ISC_LIST_INIT(lookup_list);
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington ISC_LIST_INIT(server_list);
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington ISC_LIST_INIT(search_list);
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington debug("main()");
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington preparse_args(argc, argv);
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington progname = argv[0];
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington result = isc_app_start();
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington check_result(result, "isc_app_start");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington setup_libs();
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington parse_args(ISC_FALSE, ISC_FALSE, argc, argv);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington setup_system();
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (domainopt[0] != '\0') {
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington set_search_domain(domainopt);
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews usesearch = ISC_TRUE;
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews }
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = isc_app_onrun(mctx, global_task, onrun_callback, NULL);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 check_result(result, "isc_app_onrun");
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 isc_app_run();
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews s = ISC_LIST_HEAD(default_lookup->my_server_list);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews while (s != NULL) {
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews debug("freeing server %p belonging to %p",
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews s, default_lookup);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 s2 = s;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington s = ISC_LIST_NEXT(s, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_DEQUEUE(default_lookup->my_server_list, s2, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_free(mctx, s2);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_mem_free(mctx, default_lookup);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (batchname != NULL) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (batchfp != stdin)
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington fclose(batchfp);
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington batchname = NULL;
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington }
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington cancel_all();
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington destroy_libs();
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington isc_app_finish();
a012d6dbfb100390efa7d0d4be64ada0210b09ddBrian Wellington return (exitcode);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington