From: Mark Andrews Date: Mon, 10 Oct 2016 00:55:59 +0000 (+1100) Subject: 4481. [func] dig: make +class, +crypto, +multiline, +rrcomments, X-Git-Tag: v9.12.0a1~739 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=3b6aba8dcb92900feecc3040d8741dc46f620e74;p=thirdparty%2Fbind9.git 4481. [func] dig: make +class, +crypto, +multiline, +rrcomments, +onesoa, +qr, +ttlid, +ttlunits and -u per lookup rather than global. [RT #42450] --- diff --git a/CHANGES b/CHANGES index bfea89436e7..bc5fb9a6d5e 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +4481. [func] dig: make +class, +crypto, +multiline, +rrcomments, + +onesoa, +qr, +ttlid, +ttlunits and -u per lookup + rather than global. [RT #42450] + 4480. [placeholder] 4479. [placeholder] diff --git a/bin/dig/dig.c b/bin/dig/dig.c index 9570187413d..55b5a87aefe 100644 --- a/bin/dig/dig.c +++ b/bin/dig/dig.c @@ -59,14 +59,17 @@ static char hexcookie[81]; static isc_boolean_t short_form = ISC_FALSE, printcmd = ISC_TRUE, ip6_int = ISC_FALSE, plusquest = ISC_FALSE, pluscomm = ISC_FALSE, +#ifdef DIG_SIGCHASE multiline = ISC_FALSE, nottl = ISC_FALSE, noclass = ISC_FALSE, - onesoa = ISC_FALSE, use_usec = ISC_FALSE, nocrypto = ISC_FALSE, ttlunits = ISC_FALSE, +#endif ipv4only = ISC_FALSE, ipv6only = ISC_FALSE; static isc_uint32_t splitwidth = 0xffffffff; /*% rrcomments are neither explicitly enabled nor disabled by default */ +#ifdef DIG_SIGCHASE static int rrcomments = 0; +#endif /*% opcode text */ static const char * const opcodetext[] = { @@ -249,7 +252,7 @@ received(int bytes, isc_sockaddr_t *from, dig_query_t *query) { if (query->lookup->stats && !short_form) { diff = isc_time_microdiff(&query->time_recv, &query->time_sent); - if (use_usec) + if (query->lookup->use_usec) printf(";; Query time: %ld usec\n", (long) diff); else printf(";; Query time: %ld msec\n", (long) diff / 1000); @@ -278,7 +281,7 @@ received(int bytes, isc_sockaddr_t *from, dig_query_t *query) { puts(""); } else if (query->lookup->identify && !short_form) { diff = isc_time_microdiff(&query->time_recv, &query->time_sent); - if (use_usec) + if (query->lookup->use_usec) printf(";; Received %" ISC_PRINT_QUADFORMAT "u bytes " "from %s(%s) in %ld us\n\n", query->lookup->doing_xfr @@ -324,9 +327,9 @@ say_message(dns_rdata_t *rdata, dig_query_t *query, isc_buffer_t *buf) { } /* Turn on rrcomments if explicitly enabled */ - if (rrcomments > 0) + if (query->lookup->rrcomments > 0) styleflags |= DNS_STYLEFLAG_RRCOMMENT; - if (nocrypto) + if (query->lookup->nocrypto) styleflags |= DNS_STYLEFLAG_NOCRYPTO; if (query->lookup->print_unknown_format) styleflags |= DNS_STYLEFLAG_UNKNOWNFORMAT; @@ -339,7 +342,7 @@ say_message(dns_rdata_t *rdata, dig_query_t *query, isc_buffer_t *buf) { diff = isc_time_microdiff(&query->time_recv, &query->time_sent); ADD_STRING(buf, " from server "); ADD_STRING(buf, query->servname); - if (use_usec) + if (query->lookup->use_usec) snprintf(store, 19, " in %ld us.", (long) diff); else snprintf(store, 19, " in %ld ms.", (long) diff / 1000); @@ -477,17 +480,17 @@ printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) { if (query->lookup->print_unknown_format) styleflags |= DNS_STYLEFLAG_UNKNOWNFORMAT; /* Turn on rrcomments if explicitly enabled */ - if (rrcomments > 0) + if (query->lookup->rrcomments > 0) styleflags |= DNS_STYLEFLAG_RRCOMMENT; - if (ttlunits) + if (query->lookup->ttlunits) styleflags |= DNS_STYLEFLAG_TTL_UNITS; - if (nottl) + if (query->lookup->nottl) styleflags |= DNS_STYLEFLAG_NO_TTL; - if (noclass) + if (query->lookup->noclass) styleflags |= DNS_STYLEFLAG_NO_CLASS; - if (nocrypto) + if (query->lookup->nocrypto) styleflags |= DNS_STYLEFLAG_NOCRYPTO; - if (multiline) { + if (query->lookup->multiline) { styleflags |= DNS_STYLEFLAG_OMIT_OWNER; styleflags |= DNS_STYLEFLAG_OMIT_CLASS; styleflags |= DNS_STYLEFLAG_REL_DATA; @@ -495,14 +498,15 @@ printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) { styleflags |= DNS_STYLEFLAG_TTL; styleflags |= DNS_STYLEFLAG_MULTILINE; /* Turn on rrcomments unless explicitly disabled */ - if (rrcomments >= 0) + if (query->lookup->rrcomments >= 0) styleflags |= DNS_STYLEFLAG_RRCOMMENT; } - if (multiline || (nottl && noclass)) + if (query->lookup->multiline || + (query->lookup->nottl && query->lookup->noclass)) result = dns_master_stylecreate2(&style, styleflags, 24, 24, 24, 32, 80, 8, splitwidth, mctx); - else if (nottl || noclass) + else if (query->lookup->nottl || query->lookup->noclass) result = dns_master_stylecreate2(&style, styleflags, 24, 24, 32, 40, 80, 8, splitwidth, mctx); @@ -526,7 +530,8 @@ printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) { flags |= DNS_MESSAGETEXTFLAG_NOHEADERS; flags |= DNS_MESSAGETEXTFLAG_NOCOMMENTS; } - if (onesoa && query->lookup->rdtype == dns_rdatatype_axfr) + if (query->lookup->onesoa && + query->lookup->rdtype == dns_rdatatype_axfr) flags |= (query->msg_count == 0) ? DNS_MESSAGETEXTFLAG_ONESOA : DNS_MESSAGETEXTFLAG_OMITSOA; if (!query->lookup->comments) @@ -872,7 +877,10 @@ plus_option(const char *option, isc_boolean_t is_batchfile, case 'l': /* class */ /* keep +cl for backwards compatibility */ FULLCHECK2("cl", "class"); + lookup->noclass = ISC_TF(!state); +#ifdef DIG_SIGCHASE noclass = ISC_TF(!state); +#endif break; case 'm': /* cmd */ FULLCHECK("cmd"); @@ -906,7 +914,10 @@ plus_option(const char *option, isc_boolean_t is_batchfile, break; case 'r': FULLCHECK("crypto"); + lookup->nocrypto = ISC_TF(!state); +#ifdef DIG_SIGCHASE nocrypto = ISC_TF(!state); +#endif break; default: goto invalid_option; @@ -1069,7 +1080,10 @@ plus_option(const char *option, isc_boolean_t is_batchfile, break; case 'u': FULLCHECK("multiline"); + lookup->multiline = state; +#ifdef DIG_SIGCHASE multiline = state; +#endif break; default: goto invalid_option; @@ -1111,7 +1125,10 @@ plus_option(const char *option, isc_boolean_t is_batchfile, lookup->rdtype = dns_rdatatype_ns; lookup->rdtypeset = ISC_TRUE; short_form = ISC_TRUE; + lookup->rrcomments = 0; +#ifdef DIG_SIGCHASE rrcomments = 0; +#endif } break; default: @@ -1126,7 +1143,7 @@ plus_option(const char *option, isc_boolean_t is_batchfile, switch (cmd[1]) { case 'n': FULLCHECK("onesoa"); - onesoa = state; + lookup->onesoa = state; break; case 'p': FULLCHECK("opcode"); @@ -1159,7 +1176,7 @@ plus_option(const char *option, isc_boolean_t is_batchfile, switch (cmd[1]) { case 'r': /* qr */ FULLCHECK("qr"); - qr = state; + lookup->qr = state; break; case 'u': /* question */ FULLCHECK("question"); @@ -1201,7 +1218,10 @@ plus_option(const char *option, isc_boolean_t is_batchfile, break; case 'r': /* rrcomments */ FULLCHECK("rrcomments"); + lookup->rrcomments = state ? 1 : -1; +#ifdef DIG_SIGCHASE rrcomments = state ? 1 : -1; +#endif break; default: goto invalid_option; @@ -1230,7 +1250,10 @@ plus_option(const char *option, isc_boolean_t is_batchfile, lookup->section_question = ISC_FALSE; lookup->comments = ISC_FALSE; lookup->stats = ISC_FALSE; + lookup->rrcomments = -1; +#ifdef DIG_SIGCHASE rrcomments = -1; +#endif } break; case 'w': /* showsearch */ @@ -1346,7 +1369,10 @@ plus_option(const char *option, isc_boolean_t is_batchfile, lookup->recurse = ISC_FALSE; lookup->identify = ISC_TRUE; lookup->comments = ISC_FALSE; + lookup->rrcomments = 0; +#ifdef DIG_SIGCHASE rrcomments = 0; +#endif lookup->stats = ISC_FALSE; lookup->section_additional = ISC_FALSE; lookup->section_authority = ISC_TRUE; @@ -1393,12 +1419,19 @@ plus_option(const char *option, isc_boolean_t is_batchfile, case 0: case 'i': /* ttlid */ FULLCHECK2("ttl", "ttlid"); + lookup->nottl = ISC_TF(!state); +#ifdef DIG_SIGCHASE nottl = ISC_TF(!state); +#endif break; case 'u': /* ttlunits */ FULLCHECK("ttlunits"); + lookup->nottl = ISC_FALSE; + lookup->ttlunits = ISC_TF(state); +#ifdef DIG_SIGCHASE nottl = ISC_FALSE; ttlunits = ISC_TF(state); +#endif break; default: goto invalid_option; @@ -1513,7 +1546,7 @@ dash_option(char *option, char *next, dig_lookup_t **lookup, /* deprecated */ break; case 'u': - use_usec = ISC_TRUE; + (*lookup)->use_usec = ISC_TRUE; break; case 'v': version(); diff --git a/bin/dig/dig.docbook b/bin/dig/dig.docbook index 994d579fec1..2a711a8fefd 100644 --- a/bin/dig/dig.docbook +++ b/bin/dig/dig.docbook @@ -1205,8 +1205,9 @@ can also be supplied. These global query options must precede the first tuple of name, class, type, options, flags, and query options supplied on the command line. Any global query options (except - the option) can be - overridden by a query-specific set of query options. For example: + and options) + can be overridden by a query-specific set of query options. + For example: dig +qr www.isc.org any -x 127.0.0.1 isc.org ns +noqr diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index 74cdcb36b6d..5384358bf19 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -121,7 +121,6 @@ isc_boolean_t cancel_now = ISC_FALSE, usesearch = ISC_FALSE, showsearch = ISC_FALSE, - qr = ISC_FALSE, is_dst_up = ISC_FALSE, keep_open = ISC_FALSE, verbose = ISC_FALSE; @@ -781,6 +780,15 @@ make_empty_lookup(void) { looknew->sendcookie = ISC_FALSE; looknew->seenbadcookie = ISC_FALSE; looknew->badcookie = ISC_TRUE; + looknew->multiline = ISC_FALSE; + looknew->nottl = ISC_FALSE; + looknew->noclass = ISC_FALSE; + looknew->onesoa = ISC_FALSE; + looknew->use_usec = ISC_FALSE; + looknew->nocrypto = ISC_FALSE; + looknew->ttlunits = ISC_FALSE; + looknew->ttlunits = ISC_FALSE; + looknew->qr = ISC_FALSE; #ifdef DIG_SIGCHASE looknew->sigchase = ISC_FALSE; #if DIG_SIGCHASE_TD @@ -826,6 +834,7 @@ make_empty_lookup(void) { looknew->ednsneg = ISC_TRUE; looknew->mapped = ISC_TRUE; looknew->dscp = -1; + looknew->rrcomments = 0; dns_fixedname_init(&looknew->fdomain); ISC_LINK_INIT(looknew, link); ISC_LIST_INIT(looknew->q); @@ -885,6 +894,14 @@ clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers) { looknew->ednsoptscnt = lookold->ednsoptscnt; looknew->ednsneg = lookold->ednsneg; looknew->mapped = lookold->mapped; + looknew->multiline = lookold->multiline; + looknew->nottl = lookold->nottl; + looknew->noclass = lookold->noclass; + looknew->onesoa = lookold->onesoa; + looknew->use_usec = lookold->use_usec; + looknew->nocrypto = lookold->nocrypto; + looknew->ttlunits = lookold->ttlunits; + looknew->qr = lookold->qr; #ifdef DIG_SIGCHASE looknew->sigchase = lookold->sigchase; #if DIG_SIGCHASE_TD @@ -919,6 +936,7 @@ clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers) { looknew->need_search = lookold->need_search; looknew->done_as_is = lookold->done_as_is; looknew->dscp = lookold->dscp; + looknew->rrcomments = lookold->rrcomments; if (lookold->ecs_addr != NULL) { size_t len = sizeof(isc_sockaddr_t); @@ -2702,7 +2720,7 @@ setup_lookup(dig_lookup_t *lookup) { } /* XXX qrflag, print_query, etc... */ - if (!ISC_LIST_EMPTY(lookup->q) && qr) { + if (!ISC_LIST_EMPTY(lookup->q) && lookup->qr) { extrabytes = 0; printmessage(ISC_LIST_HEAD(lookup->q), lookup->sendmsg, ISC_TRUE); diff --git a/bin/dig/include/dig/dig.h b/bin/dig/include/dig/dig.h index 63a5782a9a4..23d63b259ad 100644 --- a/bin/dig/include/dig/dig.h +++ b/bin/dig/include/dig/dig.h @@ -129,7 +129,15 @@ struct dig_lookup { header_only, ednsneg, mapped, - print_unknown_format; + print_unknown_format, + multiline, + nottl, + noclass, + onesoa, + use_usec, + nocrypto, + ttlunits, + qr; #ifdef DIG_SIGCHASE isc_boolean_t sigchase; #if DIG_SIGCHASE_TD @@ -190,6 +198,7 @@ isc_boolean_t sigchase; isc_dscp_t dscp; unsigned int ednsflags; dns_opcode_t opcode; + int rrcomments; }; /*% The dig_query structure */ @@ -260,7 +269,7 @@ extern dig_searchlistlist_t search_list; extern unsigned int extrabytes; extern isc_boolean_t check_ra, have_ipv4, have_ipv6, specified_source, - usesearch, showsearch, qr; + usesearch, showsearch; extern in_port_t port; extern unsigned int timeout; extern isc_mem_t *mctx; diff --git a/bin/tests/system/digdelv/clean.sh b/bin/tests/system/digdelv/clean.sh index 268f75b86d8..f016c0c13c4 100644 --- a/bin/tests/system/digdelv/clean.sh +++ b/bin/tests/system/digdelv/clean.sh @@ -6,8 +6,12 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -rm -f dig.out.*test* -rm -f delv.out.test* rm -f */named.memstats rm -f */named.run +rm -f delv.out.test* +rm -f dig.out.*test* +rm -f dig.out.mm.* +rm -f dig.out.mn.* +rm -f dig.out.nm.* +rm -f dig.out.nn.* rm -f ns*/named.lock diff --git a/bin/tests/system/digdelv/tests.sh b/bin/tests/system/digdelv/tests.sh index 3a827373b0a..2cd845a217c 100644 --- a/bin/tests/system/digdelv/tests.sh +++ b/bin/tests/system/digdelv/tests.sh @@ -102,6 +102,24 @@ if [ -x ${DIG} ] ; then if [ $ret != 0 ]; then echo "I:failed"; fi status=`expr $status + $ret` + n=`expr $n + 1` + echo "I:checking dig multi flag is local($n)" + ret=0 + $DIG $DIGOPTS +tcp @10.53.0.3 -t DNSKEY dnskey.example +nomulti dnskey.example +nomulti > dig.out.nn.$n || ret=1 + $DIG $DIGOPTS +tcp @10.53.0.3 -t DNSKEY dnskey.example +multi dnskey.example +nomulti > dig.out.mn.$n || ret=1 + $DIG $DIGOPTS +tcp @10.53.0.3 -t DNSKEY dnskey.example +nomulti dnskey.example +multi > dig.out.nm.$n || ret=1 + $DIG $DIGOPTS +tcp @10.53.0.3 -t DNSKEY dnskey.example +multi dnskey.example +multi > dig.out.mm.$n || ret=1 + lcnn=`wc -l < dig.out.nn.$n` + lcmn=`wc -l < dig.out.mn.$n` + lcnm=`wc -l < dig.out.nm.$n` + lcmm=`wc -l < dig.out.mm.$n` + test $lcmm -ge $lcnm || ret=1 + test $lcmm -ge $lcmn || ret=1 + test $lcnm -ge $lcnn || ret=1 + test $lcmn -ge $lcnn || ret=1 + if [ $ret != 0 ]; then echo "I:failed"; fi + status=`expr $status + $ret` + n=`expr $n + 1` echo "I:checking dig +noheader-only works ($n)" ret=0