diff options
author | Rob Crittenden <rcritten@redhat.com> | 2008-03-06 13:17:28 -0500 |
---|---|---|
committer | Rob Crittenden <rcritten@redhat.com> | 2008-03-06 13:17:28 -0500 |
commit | 03d7125eacb5c0fc15d416349f6ad48d22ef5acb (patch) | |
tree | 5679ca4ad85ad96b0df882adbbf7105113416fb5 | |
parent | 546155c3af5fd034369f38be97f8c4e1fa41aede (diff) | |
download | freeipa-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
-rw-r--r-- | ipa-server/ipa-install/ipa-server-install | 5 | ||||
-rw-r--r-- | ipa-server/ipaserver/installutils.py | 30 |
2 files changed, 32 insertions, 3 deletions
diff --git a/ipa-server/ipa-install/ipa-server-install b/ipa-server/ipa-install/ipa-server-install index 43c20791a..926b00358 100644 --- a/ipa-server/ipa-install/ipa-server-install +++ b/ipa-server/ipa-install/ipa-server-install @@ -123,9 +123,8 @@ def read_host_name(host_default): host_name = host_input try: verify_fqdn(host_name) - except: - host_name = "" - continue + except Exception, e: + raise e else: host_ok = True return host_name diff --git a/ipa-server/ipaserver/installutils.py b/ipa-server/ipaserver/installutils.py index dd4104042..3d09e85c5 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 |