ad7b3b
From ed26f0f0eb4242706d2012e4abe0152071bb305b Mon Sep 17 00:00:00 2001
e665b7
From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>
e665b7
Date: Tue, 25 Sep 2018 18:08:46 +0200
e665b7
Subject: [PATCH] Disable IDN from environment as documented
e665b7
e665b7
Manual page of host contained instructions to disable IDN processing
e665b7
when it was built with libidn2. When refactoring IDN support however,
e665b7
support for disabling IDN in host and nslookup was lost. Use also
e665b7
environment variable and document it for nslookup, host and dig.
e665b7
e665b7
Support variable CHARSET=ASCII to disable IDN, supported in downstream
e665b7
RH patch since RHEL 5.
e665b7
---
e665b7
 bin/dig/dig.docbook      |  4 +++-
e665b7
 bin/dig/dighost.c        |  9 +++++++--
e665b7
 bin/dig/host.docbook     |  2 +-
e665b7
 bin/dig/nslookup.docbook | 15 +++++++++++++++
e665b7
 4 files changed, 26 insertions(+), 4 deletions(-)
e665b7
e665b7
diff --git a/bin/dig/dig.docbook b/bin/dig/dig.docbook
ad7b3b
index bd7510e..5cc696f 100644
e665b7
--- a/bin/dig/dig.docbook
e665b7
+++ b/bin/dig/dig.docbook
e665b7
@@ -1288,7 +1288,9 @@ dig +qr www.isc.org any -x 127.0.0.1 isc.org ns +noqr
e665b7
       reply from the server.
e665b7
       If you'd like to turn off the IDN support for some reason, use
e665b7
       parameters <parameter>+noidnin</parameter> and
e665b7
-      <parameter>+noidnout</parameter>.
e665b7
+      <parameter>+noidnout</parameter> or define
e665b7
+      the <envar>IDN_DISABLE</envar> environment variable.
e665b7
+
e665b7
     </para>
e665b7
   </refsection>
e665b7
 
e665b7
diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c
ad7b3b
index 341ed80..bb8702c 100644
e665b7
--- a/bin/dig/dighost.c
e665b7
+++ b/bin/dig/dighost.c
ad7b3b
@@ -825,12 +825,17 @@ make_empty_lookup(void) {
ad7b3b
 	looknew->seenbadcookie = false;
ad7b3b
 	looknew->badcookie = true;
e665b7
 #ifdef WITH_IDN_SUPPORT
ad7b3b
-	looknew->idnin = true;
e665b7
+	looknew->idnin = (getenv("IDN_DISABLE") == NULL);
e665b7
+	if (looknew->idnin) {
e665b7
+		const char *charset = getenv("CHARSET");
e665b7
+		if (charset && !strcmp(charset, "ASCII"))
ad7b3b
+			looknew->idnin = false;
e665b7
+	}
e665b7
 #else
ad7b3b
 	looknew->idnin = false;
e665b7
 #endif
e665b7
 #ifdef WITH_IDN_OUT_SUPPORT
ad7b3b
-	looknew->idnout = true;
e665b7
+	looknew->idnout = looknew->idnin;
e665b7
 #else
ad7b3b
 	looknew->idnout = false;
e665b7
 #endif
e665b7
diff --git a/bin/dig/host.docbook b/bin/dig/host.docbook
e665b7
index 9c3aeaa..42cbbf9 100644
e665b7
--- a/bin/dig/host.docbook
e665b7
+++ b/bin/dig/host.docbook
e665b7
@@ -378,7 +378,7 @@
e665b7
       <command>host</command> appropriately converts character encoding of
e665b7
       domain name before sending a request to DNS server or displaying a
e665b7
       reply from the server.
e665b7
-      If you'd like to turn off the IDN support for some reason, defines
e665b7
+      If you'd like to turn off the IDN support for some reason, define
e665b7
       the <envar>IDN_DISABLE</envar> environment variable.
e665b7
       The IDN support is disabled if the variable is set when
e665b7
       <command>host</command> runs.
e665b7
diff --git a/bin/dig/nslookup.docbook b/bin/dig/nslookup.docbook
e665b7
index 3aff4e9..86a09c6 100644
e665b7
--- a/bin/dig/nslookup.docbook
e665b7
+++ b/bin/dig/nslookup.docbook
e665b7
@@ -478,6 +478,21 @@ nslookup -query=hinfo  -timeout=10
e665b7
     </para>
e665b7
   </refsection>
e665b7
 
e665b7
+  <refsection><info><title>IDN SUPPORT</title></info>
e665b7
+
e665b7
+    <para>
e665b7
+      If <command>nslookup</command> has been built with IDN (internationalized
e665b7
+      domain name) support, it can accept and display non-ASCII domain names.
e665b7
+      <command>nslookup</command> appropriately converts character encoding of
e665b7
+      domain name before sending a request to DNS server or displaying a
e665b7
+      reply from the server.
e665b7
+      If you'd like to turn off the IDN support for some reason, define
e665b7
+      the <envar>IDN_DISABLE</envar> environment variable.
e665b7
+      The IDN support is disabled if the variable is set when
e665b7
+      <command>nslookup</command> runs.
e665b7
+    </para>
e665b7
+  </refsection>
e665b7
+
e665b7
   <refsection><info><title>FILES</title></info>
e665b7
 
e665b7
     <para><filename>/etc/resolv.conf</filename>
e665b7
-- 
e665b7
2.14.4
e665b7