summaryrefslogtreecommitdiffstats
path: root/ipaclient/ipadiscovery.py
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2016-02-19 17:26:57 +0100
committerJan Cholasta <jcholast@redhat.com>2016-03-03 10:31:55 +0100
commitcec7df5c54122c4ca2d7cee681f2e16b81fd6040 (patch)
tree44e6c7af83287a616f492258864fd04ab1179316 /ipaclient/ipadiscovery.py
parent8df86d5bffdccd4f9e4d16fbd439f23903ec25af (diff)
downloadfreeipa-cec7df5c54122c4ca2d7cee681f2e16b81fd6040.tar.gz
freeipa-cec7df5c54122c4ca2d7cee681f2e16b81fd6040.tar.xz
freeipa-cec7df5c54122c4ca2d7cee681f2e16b81fd6040.zip
ipadiscovery: Decode to unicode in ipacheckldap(), get_ipa_basedn()
ipacheckldap uses a schema-less connection with decode_attrs=False, so bytes need to be decoded manually. This was not a problem in Python2 where bytes and unicode could be mixed freely. Part of the work for https://fedorahosted.org/freeipa/ticket/5638 Reviewed-By: Jan Cholasta <jcholast@redhat.com>
Diffstat (limited to 'ipaclient/ipadiscovery.py')
-rw-r--r--ipaclient/ipadiscovery.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/ipaclient/ipadiscovery.py b/ipaclient/ipadiscovery.py
index bf82eac3a..ed59529fb 100644
--- a/ipaclient/ipadiscovery.py
+++ b/ipaclient/ipadiscovery.py
@@ -19,6 +19,8 @@
import socket
+import six
+
from ipapython.ipa_log_manager import root_logger
from dns import resolver, rdatatype
from dns.exception import DNSException
@@ -62,13 +64,11 @@ def get_ipa_basedn(conn):
entry = conn.get_entry(
DN(), attrs_list=['defaultnamingcontext', 'namingcontexts'])
- # FIXME: import ipalib here to prevent import loops
- from ipalib import errors
-
- contexts = entry['namingcontexts']
+ contexts = [c.decode('utf-8') for c in entry.raw['namingcontexts']]
if 'defaultnamingcontext' in entry:
# If there is a defaultNamingContext examine that one first
- default = entry.single_value['defaultnamingcontext']
+ [default] = entry.raw['defaultnamingcontext']
+ default = default.decode('utf-8')
if default in contexts:
contexts.remove(default)
contexts.insert(0, default)
@@ -81,7 +81,8 @@ def get_ipa_basedn(conn):
root_logger.debug("LDAP server did not return info attribute to "
"check for IPA version")
continue
- info = entry.single_value['info'].lower()
+ [info] = entry.raw['info']
+ info = info.decode('utf-8').lower()
if info != IPA_BASEDN_INFO:
root_logger.debug("Detected IPA server version (%s) did not match the client (%s)" \
% (info, IPA_BASEDN_INFO))
@@ -424,7 +425,10 @@ class IPADiscovery(object):
for lres in lret:
root_logger.debug("Found: %s", lres.dn)
- lrealms.append(lres.single_value['cn'])
+ [cn] = lres.raw['cn']
+ if six.PY3:
+ cn = cn.decode('utf-8')
+ lrealms.append(cn)
if trealm:
for r in lrealms: