summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Cholasta <jcholast@redhat.com>2011-02-15 17:51:18 +0100
committerRob Crittenden <rcritten@redhat.com>2011-02-15 15:39:26 -0500
commit06be021c72420e0cc382c56b186d51aaf859bbab (patch)
tree403a50826bd67cdf47a816a0f04686694a9df076
parent9c9a5136645a26cafae29ee3626d59767c15a050 (diff)
downloadfreeipa-06be021c72420e0cc382c56b186d51aaf859bbab.tar.gz
freeipa-06be021c72420e0cc382c56b186d51aaf859bbab.tar.xz
freeipa-06be021c72420e0cc382c56b186d51aaf859bbab.zip
Fix handling of /etc/hosts
ticket 971
-rw-r--r--ipaserver/install/installutils.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/ipaserver/install/installutils.py b/ipaserver/install/installutils.py
index 563333bd2..9f4bd615b 100644
--- a/ipaserver/install/installutils.py
+++ b/ipaserver/install/installutils.py
@@ -159,13 +159,22 @@ def verify_ip_address(ip):
def record_in_hosts(ip, host_name, file="/etc/hosts"):
hosts = open(file, 'r').readlines()
for line in hosts:
- hosts_ip = line.split()[0]
- if hosts_ip != ip:
+ line = line.rstrip('\n')
+ fields = line.partition('#')[0].split()
+ if len(fields) == 0:
continue
- names = line.split()[1:]
- if host_name in names:
- return True
+ try:
+ hosts_ip = fields[0]
+ names = fields[1:]
+
+ if hosts_ip != ip:
+ continue
+ if host_name in names:
+ return True
+ except IndexError:
+ print "Warning: Erroneous line '%s' in %s" % (line, file)
+ continue
return False