From 5a77f2d1ff545cb92e57d26e569e01246e75dece Mon Sep 17 00:00:00 2001 From: Martin Kosek Date: Fri, 20 Jan 2012 08:30:40 +0100 Subject: Fix ipa-server-install for dual NICs A server may have 2 or more NICs and its hostname may thus resolve to 2 and more forward addresses. IP address checks in install scripts does not expect this setup and may fail or crash. This script adds a support for multiple forward addresses for a hostname. The install scripts do not crash now. When one IP address is needed, user is asked to choose from all detected server IP addresses. https://fedorahosted.org/freeipa/ticket/2154 --- install/tools/ipa-dns-install | 21 ++++++++++++++++++++- install/tools/ipa-replica-conncheck | 2 +- install/tools/ipa-replica-install | 29 ++++++++++------------------- 3 files changed, 31 insertions(+), 21 deletions(-) (limited to 'install') diff --git a/install/tools/ipa-dns-install b/install/tools/ipa-dns-install index 5c02c20c..98929bdc 100755 --- a/install/tools/ipa-dns-install +++ b/install/tools/ipa-dns-install @@ -147,7 +147,26 @@ def main(): else: hostaddr = resolve_host(api.env.host) try: - ip = hostaddr and ipautil.CheckedIPAddress(hostaddr, match_local=True) + if len(hostaddr) > 1: + print >> sys.stderr, "The server hostname resolves to more than one address:" + for addr in hostaddr: + print >> sys.stderr, " %s" % addr + + if options.ip_address: + if str(options.ip_address) not in hostaddr: + print >> sys.stderr, "Address passed in --ip-address did not match any resolved" + print >> sys.stderr, "address!" + sys.exit(1) + print "Selected IP address:", str(options.ip_address) + ip = options.ip_address + else: + if options.unattended: + print >> sys.stderr, "Please use --ip-address option to specify the address" + sys.exit(1) + else: + ip = read_ip_address(api.env.host, fstore) + else: + ip = hostaddr and ipautil.CheckedIPAddress(hostaddr[0], match_local=True) except Exception, e: print "Error: Invalid IP Address %s: %s" % (ip, e) ip = None diff --git a/install/tools/ipa-replica-conncheck b/install/tools/ipa-replica-conncheck index 882d77d3..2622130e 100755 --- a/install/tools/ipa-replica-conncheck +++ b/install/tools/ipa-replica-conncheck @@ -237,7 +237,7 @@ class PortResponder(threading.Thread): def port_check(host, port_list): ip = installutils.resolve_host(host) - if ip is None: + if not ip: raise RuntimeError("Port check failed! Unable to resolve host name '%s'" % host) failed_ports = [] diff --git a/install/tools/ipa-replica-install b/install/tools/ipa-replica-install index 34c787b1..c1474ecb 100755 --- a/install/tools/ipa-replica-install +++ b/install/tools/ipa-replica-install @@ -200,27 +200,22 @@ def install_bind(config, options): else: forwarders = () bind = bindinstance.BindInstance(dm_password=config.dirman_password) - ip_address = resolve_host(config.host_name) - if not ip_address: - sys.exit("Unable to resolve IP address for host name") - ip = ipautil.CheckedIPAddress(ip_address, match_local=True) - ip_address = str(ip) if options.reverse_zone: - if not bindinstance.verify_reverse_zone(options.reverse_zone, ip): + if not bindinstance.verify_reverse_zone(options.reverse_zone, config.ip): sys.exit(1) reverse_zone = bindinstance.normalize_zone(options.reverse_zone) else: - reverse_zone = bindinstance.find_reverse_zone(ip) + reverse_zone = bindinstance.find_reverse_zone(config.ip) if reverse_zone is None and not options.no_reverse: - reverse_zone = bindinstance.get_reverse_zone_default(ip) + reverse_zone = bindinstance.get_reverse_zone_default(config.ip) if not options.unattended and bindinstance.create_reverse(): - reverse_zone = bindinstance.read_reverse_zone(reverse_zone, ip) + reverse_zone = bindinstance.read_reverse_zone(reverse_zone, config.ip) if reverse_zone is not None: print "Using reverse zone %s" % reverse_zone - bind.setup(config.host_name, ip_address, config.realm_name, + bind.setup(config.host_name, config.ip_address, config.realm_name, config.domain_name, forwarders, options.conf_ntp, reverse_zone) bind.create_instance() @@ -240,14 +235,9 @@ def install_dns_records(config, options): bind_pw=config.dirman_password, tls_cacertfile=CACERT) bind = bindinstance.BindInstance(dm_password=config.dirman_password) - ip_address = resolve_host(config.host_name) - if not ip_address: - sys.exit("Unable to resolve IP address for host name") - ip = ipautil.CheckedIPAddress(ip_address, match_local=True) - ip_address = str(ip) - reverse_zone = bindinstance.find_reverse_zone(ip) - - bind.add_master_dns_records(config.host_name, ip_address, + reverse_zone = bindinstance.find_reverse_zone(config.ip) + + bind.add_master_dns_records(config.host_name, config.ip_address, config.realm_name, config.domain_name, reverse_zone, options.conf_ntp) @@ -341,7 +331,8 @@ def main(): replica_conn_check(config.master_host_name, config.host_name, config.realm_name, options.setup_ca, options.admin_password) # check replica host IP resolution - ip = installutils.get_server_ip_address(config.host_name, fstore, True, options) + config.ip = installutils.get_server_ip_address(config.host_name, fstore, True, options) + config.ip_address = str(config.ip) # Create the management framework config file # Note: We must do this before bootstraping and finalizing ipalib.api -- cgit