From 087251c88b3a6da9c2b6953bf21188a31d8f9d37 Mon Sep 17 00:00:00 2001 From: Jan Cholasta Date: Fri, 30 Sep 2011 10:09:55 +0200 Subject: Add a function for formatting network locations of the form host:port for use in URLs. If the host part is a literal IPv6 address, it must be enclosed in square brackets (RFC 2732). ticket 1869 --- ipa-client/ipa-install/ipa-client-install | 14 +++++++------- ipa-client/ipaclient/ipadiscovery.py | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'ipa-client') diff --git a/ipa-client/ipa-install/ipa-client-install b/ipa-client/ipa-install/ipa-client-install index f89056416..e5153709d 100755 --- a/ipa-client/ipa-install/ipa-client-install +++ b/ipa-client/ipa-install/ipa-client-install @@ -352,7 +352,7 @@ def configure_ipa_conf(fstore, cli_basedn, cli_realm, cli_domain, cli_server): {'name':'realm', 'type':'option', 'value':cli_realm}, {'name':'domain', 'type':'option', 'value':cli_domain}, {'name':'server', 'type':'option', 'value':cli_server}, - {'name':'xmlrpc_uri', 'type':'option', 'value':'https://%s/ipa/xml' % cli_server}, + {'name':'xmlrpc_uri', 'type':'option', 'value':'https://%s/ipa/xml' % ipautil.format_netloc(cli_server)}, {'name':'enable_ra', 'type':'option', 'value':'True'}] opts.append({'name':'global', 'type':'section', 'value':defopts}) @@ -389,7 +389,7 @@ def configure_ldap_conf(fstore, cli_basedn, cli_realm, cli_domain, cli_server, d if options.on_master: opts.append({'name':'uri', 'type':'option', 'value':'ldap://localhost'}) else: - opts.append({'name':'uri', 'type':'option', 'value':'ldap://'+cli_server}) + opts.append({'name':'uri', 'type':'option', 'value':'ldap://'+ipautil.format_netloc(cli_server)}) else: opts.append({'name':'nss_srv_domain', 'type':'option', 'value':cli_domain}) @@ -428,7 +428,7 @@ def configure_nslcd_conf(fstore, cli_basedn, cli_realm, cli_domain, cli_server, if options.on_master: opts.append({'name':'uri', 'type':'option', 'value':'ldap://localhost'}) else: - opts.append({'name':'uri', 'type':'option', 'value':'ldap://'+cli_server}) + opts.append({'name':'uri', 'type':'option', 'value':'ldap://'+ipautil.format_netloc(cli_server)}) else: opts.append({'name':'uri', 'type':'option', 'value':'DNS'}) @@ -471,7 +471,7 @@ def hardcode_ldap_server(cli_server): ldapconf = ipaclient.ipachangeconf.IPAChangeConf("IPA Installer") ldapconf.setOptionAssignment(" ") - opts = [{'name':'uri', 'type':'option', 'action':'set', 'value':'ldap://'+cli_server}, + opts = [{'name':'uri', 'type':'option', 'action':'set', 'value':'ldap://'+ipautil.format_netloc(cli_server)}, {'name':'empty', 'type':'empty'}] # Errors raised by this should be caught by the caller @@ -509,8 +509,8 @@ def configure_krb5_conf(fstore, cli_basedn, cli_realm, cli_domain, cli_server, c #the following are necessary only if DNS discovery does not work if not dnsok or not cli_kdc or options.force: #[realms] - kropts =[{'name':'kdc', 'type':'option', 'value':cli_server+':88'}, - {'name':'admin_server', 'type':'option', 'value':cli_server+':749'}, + kropts =[{'name':'kdc', 'type':'option', 'value':ipautil.format_netloc(cli_server, 88)}, + {'name':'admin_server', 'type':'option', 'value':ipautil.format_netloc(cli_server, 749)}, {'name':'default_domain', 'type':'option', 'value':cli_domain}] else: kropts = [] @@ -887,7 +887,7 @@ def install(options, env, fstore, statestore): pass try: - run(["/usr/bin/wget", "-O", "/etc/ipa/ca.crt", "http://%s/ipa/config/ca.crt" % cli_server]) + run(["/usr/bin/wget", "-O", "/etc/ipa/ca.crt", "http://%s/ipa/config/ca.crt" % ipautil.format_netloc(cli_server)]) except CalledProcessError, e: print 'Retrieving CA from %s failed.\n%s' % (cli_server, str(e)) return CLIENT_INSTALL_ERROR diff --git a/ipa-client/ipaclient/ipadiscovery.py b/ipa-client/ipaclient/ipadiscovery.py index f6c13fb67..3e31cad37 100644 --- a/ipa-client/ipaclient/ipadiscovery.py +++ b/ipa-client/ipaclient/ipadiscovery.py @@ -25,7 +25,7 @@ import tempfile import ldap from ldap import LDAPError from ipapython.ipautil import run, CalledProcessError, valid_ip, get_ipa_basedn, \ - realm_to_suffix + realm_to_suffix, format_netloc NOT_FQDN = -1 @@ -220,15 +220,15 @@ class IPADiscovery: raise RuntimeError("Creating temporary directory failed: %s" % str(e)) try: - run(["/usr/bin/wget", "-O", "%s/ca.crt" % temp_ca_dir, "http://%s/ipa/config/ca.crt" % thost]) + run(["/usr/bin/wget", "-O", "%s/ca.crt" % temp_ca_dir, "http://%s/ipa/config/ca.crt" % format_netloc(thost)]) except CalledProcessError, e: logging.debug('Retrieving CA from %s failed.\n%s' % (thost, str(e))) return [NOT_IPA_SERVER] #now verify the server is really an IPA server try: - logging.debug("Init ldap with: ldap://"+thost+":389") - lh = ldap.initialize("ldap://"+thost+":389") + logging.debug("Init ldap with: ldap://"+format_netloc(thost, 389)) + lh = ldap.initialize("ldap://"+format_netloc(thost, 389)) ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, True) ldap.set_option(ldap.OPT_X_TLS_CACERTFILE, "%s/ca.crt" % temp_ca_dir) lh.set_option(ldap.OPT_PROTOCOL_VERSION, 3) -- cgit