From 06be021c72420e0cc382c56b186d51aaf859bbab Mon Sep 17 00:00:00 2001 From: Jan Cholasta Date: Feb 15 2011 20:39:26 +0000 Subject: Fix handling of /etc/hosts ticket 971 --- diff --git a/ipaserver/install/installutils.py b/ipaserver/install/installutils.py index 563333b..9f4bd61 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