summaryrefslogtreecommitdiffstats
path: root/ipa-server/ipaserver/installutils.py
diff options
context:
space:
mode:
authorRob Crittenden <rcritten@redhat.com>2008-03-06 13:17:28 -0500
committerRob Crittenden <rcritten@redhat.com>2008-03-06 13:17:28 -0500
commit03d7125eacb5c0fc15d416349f6ad48d22ef5acb (patch)
tree5679ca4ad85ad96b0df882adbbf7105113416fb5 /ipa-server/ipaserver/installutils.py
parent546155c3af5fd034369f38be97f8c4e1fa41aede (diff)
downloadfreeipa-03d7125eacb5c0fc15d416349f6ad48d22ef5acb.tar.gz
freeipa-03d7125eacb5c0fc15d416349f6ad48d22ef5acb.tar.xz
freeipa-03d7125eacb5c0fc15d416349f6ad48d22ef5acb.zip
Verify that the hostname is correct in /etc/hosts
Don't ignore exceptions when getting the hostname from the user 433515
Diffstat (limited to 'ipa-server/ipaserver/installutils.py')
-rw-r--r--ipa-server/ipaserver/installutils.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/ipa-server/ipaserver/installutils.py b/ipa-server/ipaserver/installutils.py
index dd410404..3d09e85c 100644
--- a/ipa-server/ipaserver/installutils.py
+++ b/ipa-server/ipaserver/installutils.py
@@ -41,6 +41,11 @@ def get_fqdn():
except:
fqdn = ""
return fqdn
+
+def reverse_ip(ipaddr):
+ i = ipaddr.split('.')
+ i.reverse()
+ return '.'.join(i)
def verify_fqdn(host_name):
if len(host_name.split(".")) < 2 or host_name == "localhost.localdomain":
@@ -65,6 +70,31 @@ def verify_fqdn(host_name):
if forward != reverse:
raise RuntimeError("The DNS forward record %s does not match the reverse lookup %s" % (forward, reverse))
+ # Look in /etc/hosts for this IP
+ try:
+ fd = open("/etc/hosts", "r")
+ except:
+ raise RuntimeError("Unable to open /etc/hosts for reading. Check file permissions.")
+
+ p = re.compile('([a-zA-Z0-9\.:]+)\s+([a-zA-Z0-9\.\-]+)')
+ while True:
+ line = fd.readline()
+ if not line: break
+ if len(line) > 0 and line[0] == "#":
+ continue
+ m = p.match(line)
+ hname = None
+ try:
+ if m.group(1) == ipaddr:
+ hname = m.group(2) + "."
+ except:
+ pass
+ if hname and hname != forward:
+ fd.close()
+ raise RuntimeError("The IP address in /etc/hosts defines the hostname as '%s' but DNS says it is '%s'. The fully-qualified hostname needs to appear on the list first in /etc/hosts" % (hname, forward))
+
+ fd.close()
+
def port_available(port):
"""Try to bind to a port on the wildcard host
Return 1 if the port is available