diff --git a/ipa-server/ipaserver/installutils.py b/ipa-server/ipaserver/installutils.py index c261e5302..2624ae141 100644 --- a/ipa-server/ipaserver/installutils.py +++ b/ipa-server/ipaserver/installutils.py @@ -43,58 +43,76 @@ def get_fqdn(): 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": raise RuntimeError("Invalid hostname: " + host_name) + try: + hostaddr = socket.getaddrinfo(host_name, None) + except: + raise RuntimeError("Unable to resolve host name, check /etc/hosts or DNS name resolution") + + if len(hostaddr) == 0: + raise RuntimeError("Unable to resolve host name, check /etc/hosts or DNS name resolution") + + for a in hostaddr: + if a[4][0] == '127.0.0.1' or a[4][0] == '::1': + raise RuntimeError("The IPA Server hostanme cannot resolve to localhost (%s), a routable IP address must be used." % a[4][0]) + try: + revname = socket.gethostbyaddr(a[4][0])[0] + except: + raise RuntimeError("Unable to resolve the reverse ip address, check /etc/hosts or DNS name resolution") + if revname != host_name: + raise RuntimeError("The host name %s does not match the reverse lookup %s" % (host_name, revname)) + + # Verify this is NOT a CNAME + rs = dnsclient.query(host_name+".", dnsclient.DNS_C_IN, dnsclient.DNS_T_CNAME) + if len(rs) != 0: + for rsn in rs: + if rsn.dns_type == dnsclient.DNS_T_CNAME: + raise RuntimeError("The IPA Server Hostname cannot be a CNAME, only A names are allowed.") + # Verify that it is a DNS A record rs = dnsclient.query(host_name+".", dnsclient.DNS_C_IN, dnsclient.DNS_T_A) if len(rs) == 0: - raise RuntimeError("hostname %s is not found or is not a DNS A record" % host_name) + print "Warning: Hostname (%s) not found in DNS" % host_name + return + + rec = None + for rsn in rs: + if rsn.dns_type == dnsclient.DNS_T_A: + rec = rsn + break + + if rec == None: + print "Warning: Hostname (%s) not found in DNS" % host_name + return # Compare the forward and reverse - forward = rs[0].dns_name + forward = rec.dns_name + + addr = socket.inet_ntoa(struct.pack(' 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() + raise RuntimeError("The DNS forward record %s does not match the reverse address %s" % (forward, reverse)) def port_available(port): """Try to bind to a port on the wildcard host