803fb7
From 6e5117b83af5998359916f276a9b32f755c0e6f4 Mon Sep 17 00:00:00 2001
803fb7
From: Jan Synacek <jsynacek@redhat.com>
803fb7
Date: Fri, 20 May 2016 12:33:48 +0200
803fb7
Subject: [PATCH] myhostname: fix timeout if ipv6 is disabled
803fb7
803fb7
rhel-only
803fb7
Resolves: #1330973
803fb7
---
803fb7
 src/nss-myhostname/nss-myhostname.c |  9 +++++++--
803fb7
 src/shared/socket-util.c            | 10 ++++++++++
803fb7
 2 files changed, 17 insertions(+), 2 deletions(-)
803fb7
803fb7
diff --git a/src/nss-myhostname/nss-myhostname.c b/src/nss-myhostname/nss-myhostname.c
803fb7
index a939bb267..e197cc752 100644
803fb7
--- a/src/nss-myhostname/nss-myhostname.c
803fb7
+++ b/src/nss-myhostname/nss-myhostname.c
803fb7
@@ -33,6 +33,7 @@
803fb7
 #include "local-addresses.h"
803fb7
 #include "macro.h"
803fb7
 #include "nss-util.h"
803fb7
+#include "socket-util.h"
803fb7
 #include "util.h"
803fb7
 
803fb7
 /* We use 127.0.0.2 as IPv4 address. This has the advantage over
803fb7
@@ -380,9 +381,13 @@ enum nss_status _nss_myhostname_gethostbyname3_r(
803fb7
                         return NSS_STATUS_NOTFOUND;
803fb7
                 }
803fb7
 
803fb7
-                n_addresses = local_addresses(NULL, 0, af, &addresses);
803fb7
-                if (n_addresses < 0)
803fb7
+                if (af == AF_INET6 && !socket_ipv6_is_supported()) {
803fb7
                         n_addresses = 0;
803fb7
+                } else {
803fb7
+                        n_addresses = local_addresses(NULL, 0, af, &addresses);
803fb7
+                        if (n_addresses < 0)
803fb7
+                                n_addresses = 0;
803fb7
+                }
803fb7
 
803fb7
                 canonical = hn;
803fb7
                 additional = n_addresses <= 0 && af == AF_INET6 ? "localhost" : NULL;
803fb7
diff --git a/src/shared/socket-util.c b/src/shared/socket-util.c
803fb7
index a21251014..79d1582d4 100644
803fb7
--- a/src/shared/socket-util.c
803fb7
+++ b/src/shared/socket-util.c
803fb7
@@ -435,6 +435,16 @@ bool socket_ipv6_is_supported(void) {
803fb7
                 return true;
803fb7
 
803fb7
         /* If module was loaded with disable=1 no IPv6 available */
803fb7
+        if (l[0] == '1')
803fb7
+                return false;
803fb7
+
803fb7
+        free(l);
803fb7
+        l = NULL;
803fb7
+
803fb7
+        if (read_one_line_file("/proc/sys/net/ipv6/conf/all/disable_ipv6", &l) < 0)
803fb7
+                return true;
803fb7
+
803fb7
+        /* If IPv6 was disabled via sysctl during runtime */
803fb7
         return l[0] == '0';
803fb7
 }
803fb7