[PATCH rhel7-branch] Fix IP / hostname mismatches when showing VNC server address (#1186726)

Radek Vykydal rvykydal at redhat.com
Mon Jun 15 12:58:34 UTC 2015


Resolves: rhbz#1186726
This should fix also #1172858

Fix various cases when two NICs with DNS configured or not come into play.

Using current hostname and trying to check if IP offered for VNC (default route
device) matches it with reverse lookup was an unnecessarily complicated way,
instead just try to resolve the IP.  Also fix host reported in VNC client.
---
 pyanaconda/vnc.py | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/pyanaconda/vnc.py b/pyanaconda/vnc.py
index 2626786..054e25b 100644
--- a/pyanaconda/vnc.py
+++ b/pyanaconda/vnc.py
@@ -107,36 +107,39 @@ class VncServer:
             return
 
         ipstr = self.ip
+        if self.ip.find(':') != -1:
+            ipstr = "[%s]" % (self.ip,)
+        else:
+            ipstr = self.ip
+
         try:
             hinfo = socket.gethostbyaddr(ipstr)
+            if len(hinfo) == 3:
+                # Consider as coming from a valid DNS record only if single IP is returned
+                if len(hinfo[2]) == 1:
+                    self.name = hinfo[0]
         except socket.herror as e:
             log.debug("Exception caught trying to get host name of %s: %s", ipstr, e)
-            self.name = network.getHostname()
-        else:
-            if len(hinfo) == 3:
-                self.name = hinfo[0]
-
-        if self.ip.find(':') != -1:
-            ipstr = "[%s]" % (self.ip,)
 
-        name_ips = [i[4][0] for i in socket.getaddrinfo(self.name, 0)]
-        if self.name is not None and not self.name.startswith('localhost') \
-           and ipstr is not None and self.ip in name_ips:
+        if self.name is not None and not self.name.startswith('localhost'):
             self.connxinfo = "%s:%s (%s:%s)" % \
                     (socket.getfqdn(name=self.name), constants.X_DISPLAY_NUMBER,
                      ipstr, constants.X_DISPLAY_NUMBER)
+            host = self.name
         elif ipstr is not None:
             self.connxinfo = "%s:%s" % (ipstr, constants.X_DISPLAY_NUMBER)
+            host = ipstr
         else:
             self.connxinfo = None
+            host = ""
 
         # figure out product info
-        if self.name is not None:
+        if host:
             self.desktop = _("%(productName)s %(productVersion)s installation "
                              "on host %(name)s") \
                            % {'productName': product.productName,
                               'productVersion': product.productVersion,
-                              'name': self.name}
+                              'name': host}
 
     def openlogfile(self):
         try:
-- 
1.9.3



More information about the anaconda-patches mailing list