]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
[master] Ensure consistent handling of -4/-6 command line options in all tools
authorMichał Kępień <michal@isc.org>
Wed, 16 Aug 2017 09:10:24 +0000 (11:10 +0200)
committerMichał Kępień <michal@isc.org>
Tue, 29 Aug 2017 08:19:38 +0000 (10:19 +0200)
4690. [bug] Command line options -4/-6 were handled inconsistently
between tools. [RT #45632]

CHANGES
bin/delv/delv.c
bin/delv/delv.docbook
bin/dig/dig.docbook
bin/dig/host.docbook
bin/named/lwresd.docbook
bin/named/named.docbook
bin/tests/system/digdelv/tests.sh
bin/tests/system/pipelined/tests.sh
bin/tools/mdig.c
bin/tools/mdig.docbook

diff --git a/CHANGES b/CHANGES
index 2ded71a41965a649a770f9155602163dab845e4d..a45d476b4691212683842c108d1d159374d94d20 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+4690.  [bug]           Command line options -4/-6 were handled inconsistently
+                       between tools. [RT #45632]
+
 4689.  [cleanup]       Turn on minimal responses for CDNSKEY and CDS in
                        addition to DNSKEY and DS. Thanks to Tony Finch.
                        [RT #45690]
index bc3cc04cc42264fcbc10d8c85b2b1d24542b99b3..9b96154ec3d1a08e59d2380984ed107beed1d0d8 100644 (file)
@@ -1374,6 +1374,7 @@ dash_option(char *option, char *next, isc_boolean_t *open_type_class) {
  */
 static void
 preparse_args(int argc, char **argv) {
+       isc_boolean_t ipv4only = ISC_FALSE, ipv6only = ISC_FALSE;
        char *option;
 
        for (argc--, argv++; argc > 0; argc--, argv++) {
@@ -1381,10 +1382,23 @@ preparse_args(int argc, char **argv) {
                        continue;
                option = &argv[0][1];
                while (strpbrk(option, single_dash_opts) == &option[0]) {
-                       if (option[0] == 'm') {
+                       switch (option[0]) {
+                       case 'm':
                                isc_mem_debugging = ISC_MEM_DEBUGTRACE |
                                        ISC_MEM_DEBUGRECORD;
-                               return;
+                               break;
+                       case '4':
+                               if (ipv6only) {
+                                       fatal("only one of -4 and -6 allowed");
+                               }
+                               ipv4only = ISC_TRUE;
+                               break;
+                       case '6':
+                               if (ipv4only) {
+                                       fatal("only one of -4 and -6 allowed");
+                               }
+                               ipv6only = ISC_TRUE;
+                               break;
                        }
                        option = &option[1];
                }
@@ -1572,8 +1586,8 @@ main(int argc, char *argv[]) {
        struct sigaction sa;
 #endif
 
-       preparse_args(argc, argv);
        progname = argv[0];
+       preparse_args(argc, argv);
 
        argc--;
        argv++;
index 9ef59db0b9e7f0113299b60b1628ac4c514f893a..e2af68474f37ffd31e640826b74cc747c3dd83df 100644 (file)
     <cmdsynopsis sepchar=" ">
       <command>delv</command>
       <arg choice="opt" rep="norepeat">@server</arg>
-      <arg choice="opt" rep="norepeat"><option>-4</option></arg>
-      <arg choice="opt" rep="norepeat"><option>-6</option></arg>
+      <group choice="opt" rep="norepeat">
+       <arg choice="opt" rep="norepeat"><option>-4</option></arg>
+       <arg choice="opt" rep="norepeat"><option>-6</option></arg>
+      </group>
       <arg choice="opt" rep="norepeat"><option>-a <replaceable class="parameter">anchor-file</replaceable></option></arg>
       <arg choice="opt" rep="norepeat"><option>-b <replaceable class="parameter">address</replaceable></option></arg>
       <arg choice="opt" rep="norepeat"><option>-c <replaceable class="parameter">class</replaceable></option></arg>
index b3a70fb22d206c7b96e68c517d9d293dc7fadb27..29bf8335ffd05aaf208059217e9e48a8ec448585 100644 (file)
       <arg choice="opt" rep="norepeat"><option>-v</option></arg>
       <arg choice="opt" rep="norepeat"><option>-x <replaceable class="parameter">addr</replaceable></option></arg>
       <arg choice="opt" rep="norepeat"><option>-y <replaceable class="parameter"><optional>hmac:</optional>name:key</replaceable></option></arg>
-      <arg choice="opt" rep="norepeat"><option>-4</option></arg>
-      <arg choice="opt" rep="norepeat"><option>-6</option></arg>
+      <group choice="opt" rep="norepeat">
+       <arg choice="opt" rep="norepeat"><option>-4</option></arg>
+       <arg choice="opt" rep="norepeat"><option>-6</option></arg>
+      </group>
       <arg choice="opt" rep="norepeat">name</arg>
       <arg choice="opt" rep="norepeat">type</arg>
       <arg choice="opt" rep="norepeat">class</arg>
index 18fc605faf400dd856187af109e221c181804e1f..9aa0ad3d556044547b8402253b7aa2824599ef1f 100644 (file)
       <arg choice="opt" rep="norepeat"><option>-t <replaceable class="parameter">type</replaceable></option></arg>
       <arg choice="opt" rep="norepeat"><option>-W <replaceable class="parameter">wait</replaceable></option></arg>
       <arg choice="opt" rep="norepeat"><option>-m <replaceable class="parameter">flag</replaceable></option></arg>
-      <arg choice="opt" rep="norepeat"><option>-4</option></arg>
-      <arg choice="opt" rep="norepeat"><option>-6</option></arg>
+      <group choice="opt" rep="norepeat">
+       <arg choice="opt" rep="norepeat"><option>-4</option></arg>
+       <arg choice="opt" rep="norepeat"><option>-6</option></arg>
+      </group>
       <arg choice="opt" rep="norepeat"><option>-v</option></arg>
       <arg choice="opt" rep="norepeat"><option>-V</option></arg>
       <arg choice="req" rep="norepeat">name</arg>
index 48dda31e69c04edd79bf8358c3890c802ce38d36..81d0290060ab13337222679d904e4fce26903a14 100644 (file)
       <arg choice="opt" rep="norepeat"><option>-t <replaceable class="parameter">directory</replaceable></option></arg>
       <arg choice="opt" rep="norepeat"><option>-u <replaceable class="parameter">user</replaceable></option></arg>
       <arg choice="opt" rep="norepeat"><option>-v</option></arg>
-      <arg choice="opt" rep="norepeat"><option>-4</option></arg>
-      <arg choice="opt" rep="norepeat"><option>-6</option></arg>
+      <group choice="opt" rep="norepeat">
+       <arg choice="opt" rep="norepeat"><option>-4</option></arg>
+       <arg choice="opt" rep="norepeat"><option>-6</option></arg>
+      </group>
     </cmdsynopsis>
   </refsynopsisdiv>
 
index 79fe9f17da68f24b472b4f3a49c7d331ad021123..311ddfd6e2201b00600a10a2aa33a720f916075d 100644 (file)
   <refsynopsisdiv>
     <cmdsynopsis sepchar=" ">
       <command>named</command>
-      <arg choice="opt" rep="norepeat"><option>-4</option></arg>
-      <arg choice="opt" rep="norepeat"><option>-6</option></arg>
+      <group choice="opt" rep="norepeat">
+       <arg choice="opt" rep="norepeat"><option>-4</option></arg>
+       <arg choice="opt" rep="norepeat"><option>-6</option></arg>
+      </group>
       <arg choice="opt" rep="norepeat"><option>-c <replaceable class="parameter">config-file</replaceable></option></arg>
       <arg choice="opt" rep="norepeat"><option>-d <replaceable class="parameter">debug-level</replaceable></option></arg>
       <arg choice="opt" rep="norepeat"><option>-D <replaceable class="parameter">string</replaceable></option></arg>
index ffdb5714d5b53623725a78cb01d1f8565c7aa6fb..71cce27e982a813ba82483d97fbe0f08cbe0f9ea 100644 (file)
@@ -490,6 +490,14 @@ if [ -x ${DELV} ] ; then
   if [ $ret != 0 ]; then echo "I:failed"; fi
   status=`expr $status + $ret`
 
+  n=`expr $n + 1`
+  echo "I:checking delv -4 -6 ($n)"
+  ret=0
+  $DELV $DELVOPTS @10.53.0.3 -4 -6 A a.example > delv.out.test$n 2>&1 && ret=1
+  grep "only one of -4 and -6 allowed" < delv.out.test$n > /dev/null || ret=1
+  if [ $ret != 0 ]; then echo "I:failed"; fi
+  status=`expr $status + $ret`
+
   n=`expr $n + 1`
   echo "I:checking delv with IPv6 on IPv4 does not work ($n)"
   if $TESTSOCK6 fd92:7065:b8e:ffff::3 2>/dev/null
index 0eb46a21ca784634f69db861b7b7b6c339c5b0da..3ab9ad9f414e2bbce203485dec477fe7acf74f60 100644 (file)
@@ -51,5 +51,19 @@ diff refb outputb.mdig || ret=1
 if [ $ret != 0 ]; then echo "I:failed"; fi
 status=`expr $status + $ret`
 
+echo "I:check mdig -4 -6"
+ret=0
+$MDIG -4 -6 -f input @10.53.0.4 > output46.mdig 2>&1 && ret=1
+grep "only one of -4 and -6 allowed" output46.mdig > /dev/null || ret=1
+if [ $ret != 0 ]; then echo "I:failed"; fi
+status=`expr $status + $ret`
+
+echo "I:check mdig -4 with an IPv6 server address"
+ret=0
+$MDIG -4 -f input @fd92:7065:b8e:ffff::2 > output4.mdig 2>&1 && ret=1
+grep "address family not supported" output4.mdig > /dev/null || ret=1
+if [ $ret != 0 ]; then echo "I:failed"; fi
+status=`expr $status + $ret`
+
 echo "I:exit status: $status"
 [ $status -eq 0 ] || exit 1
index 2c9229f287420e53ba1cf55e849b02071d6e2720..c1204495a234f93859e100abb560d60b17de0b12 100644 (file)
@@ -1714,6 +1714,7 @@ preparse_args(int argc, char **argv) {
        int rc;
        char **rv;
        char *option;
+       isc_boolean_t ipv4only = ISC_FALSE, ipv6only = ISC_FALSE;
 
        rc = argc;
        rv = argv;
@@ -1727,6 +1728,18 @@ preparse_args(int argc, char **argv) {
                                isc_mem_debugging = ISC_MEM_DEBUGTRACE |
                                        ISC_MEM_DEBUGRECORD;
                                break;
+                       case '4':
+                               if (ipv6only) {
+                                       fatal("only one of -4 and -6 allowed");
+                               }
+                               ipv4only = ISC_TRUE;
+                               break;
+                       case '6':
+                               if (ipv4only) {
+                                       fatal("only one of -4 and -6 allowed");
+                               }
+                               ipv6only = ISC_TRUE;
+                               break;
                        }
                        option = &option[1];
                }
@@ -1884,6 +1897,7 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv)
 int
 main(int argc, char *argv[]) {
        struct query *query;
+       isc_result_t result;
        isc_sockaddr_t bind_any;
        isc_log_t *lctx;
        isc_logconfig_t *lcfg;
@@ -1932,7 +1946,12 @@ main(int argc, char *argv[]) {
                fatal("a server '@xxx' is required");
 
        ns = 0;
-       RUNCHECK(bind9_getaddresses(server, port, &dstaddr, 1, &ns));
+       result = bind9_getaddresses(server, port, &dstaddr, 1, &ns);
+       if (result != ISC_R_SUCCESS) {
+               fatal("couldn't get address for '%s': %s",
+                     server, isc_result_totext(result));
+       }
+
        if (isc_sockaddr_pf(&dstaddr) == PF_INET && have_ipv6) {
                isc_net_disableipv6();
                have_ipv6 = ISC_FALSE;
index 0d8dc025cfbeea1e1d6d842f79f21866d52e8baf..587e097188dc598e350ddf604a1f7f4cc8982eb1 100644 (file)
       <arg choice="opt" rep="norepeat"><option>-f <replaceable class="parameter">filename</replaceable></option></arg>
       <arg choice="opt" rep="norepeat"><option>-h</option></arg>
       <arg choice="opt" rep="norepeat"><option>-v</option></arg>
-      <arg choice="opt" rep="norepeat"><option>-4</option></arg>
-      <arg choice="opt" rep="norepeat"><option>-6</option></arg>
+      <group choice="opt" rep="norepeat">
+       <arg choice="opt" rep="norepeat"><option>-4</option></arg>
+       <arg choice="opt" rep="norepeat"><option>-6</option></arg>
+      </group>
       <arg choice="opt" rep="norepeat"><option>-m</option></arg>
       <arg choice="opt" rep="norepeat"><option>-b <replaceable class="parameter">address</replaceable></option></arg>
       <arg choice="opt" rep="norepeat"><option>-p <replaceable class="parameter">port#</replaceable></option></arg>