Hello,
These fixes are needed for the "happy path" of ipa-client-install
--server on Python 3.

-- 
Petr Viktorin
From d51ff822165f434ed7c87cde44f64b8f05e33797 Mon Sep 17 00:00:00 2001
From: Petr Viktorin <pvikt...@redhat.com>
Date: Fri, 19 Feb 2016 17:26:57 +0100
Subject: [PATCH] ipadiscovery: Decode to unicode in ipacheckldap()

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
---
 ipaclient/ipadiscovery.py | 2 +-
 ipapython/ipautil.py      | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/ipaclient/ipadiscovery.py b/ipaclient/ipadiscovery.py
index 45a71e190e56d33d51d37f16ae61a7b4c28df521..e1a565bd4bf82c07bf2e52ddab1669209919249d 100644
--- a/ipaclient/ipadiscovery.py
+++ b/ipaclient/ipadiscovery.py
@@ -381,7 +381,7 @@ class IPADiscovery(object):
 
             for lres in lret:
                 root_logger.debug("Found: %s", lres.dn)
-                lrealms.append(lres.single_value['cn'])
+                lrealms.append(lres.single_value['cn'].decode('utf-8'))
 
             if trealm:
                 for r in lrealms:
diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py
index 6d07e07a08260995fb78e2ac23c825f734a4cd09..1d2a213cd28ea18712df19770f89edc288de5ac8 100644
--- a/ipapython/ipautil.py
+++ b/ipapython/ipautil.py
@@ -1141,6 +1141,8 @@ def get_ipa_basedn(conn):
     None is returned if the suffix is not found
 
     :param conn: Bound LDAPClient that will be used for searching
+
+    May be called with a connection with decode_attrs set to False
     """
     entry = conn.get_entry(
         DN(), attrs_list=['defaultnamingcontext', 'namingcontexts'])
@@ -1156,6 +1158,9 @@ def get_ipa_basedn(conn):
             contexts.remove(default)
         contexts.insert(0, default)
     for context in contexts:
+        if isinstance(context, bytes):
+            # connection's decode_attrs is turned off, decode manually
+            context = context.decode('utf-8')
         root_logger.debug("Check if naming context '%s' is for IPA" % context)
         try:
             [entry] = conn.get_entries(
@@ -1165,6 +1170,9 @@ def get_ipa_basedn(conn):
                               "check for IPA version")
             continue
         info = entry.single_value['info'].lower()
+        if isinstance(info, bytes):
+            # connection's decode_attrs is turned off, decode manually
+            info = info.decode('utf-8')
         if info != IPA_BASEDN_INFO:
             root_logger.debug("Detected IPA server version (%s) did not match the client (%s)" \
                 % (info, IPA_BASEDN_INFO))
-- 
2.5.0

From b066a348d859d244428f6a9c618450a44ff705ae Mon Sep 17 00:00:00 2001
From: Petr Viktorin <pvikt...@redhat.com>
Date: Fri, 19 Feb 2016 17:38:30 +0100
Subject: [PATCH] ipapython.sysrestore: Use str methods instead of functions
 from the string module

For historical reasons, the string module contained some functions
that mirror methods of the str type. These are eremoved in Python 3.

Use str methods instead.

Part of the work for https://fedorahosted.org/freeipa/ticket/5638
---
 ipapython/sysrestore.py | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/ipapython/sysrestore.py b/ipapython/sysrestore.py
index c43948db536574453923bb69d49d6c9ed00f57dc..c1c2bce8764d6b343a9c14736dd969be2f975c17 100644
--- a/ipapython/sysrestore.py
+++ b/ipapython/sysrestore.py
@@ -28,7 +28,6 @@ import os.path
 import shutil
 from ipapython.ipa_log_manager import root_logger
 import random
-import string
 
 import six
 from six.moves.configparser import SafeConfigParser
@@ -133,7 +132,8 @@ class FileStore:
 
         stat = os.stat(path)
 
-        self.files[filename] = string.join([str(stat.st_mode),str(stat.st_uid),str(stat.st_gid),path], ',')
+        template = '{stat.st_mode},{stat.st_uid},{stat.st_gid},{path}'
+        self.files[filename] = template.format(stat=stat, path=path)
         self.save()
 
     def has_file(self, path):
@@ -143,7 +143,7 @@ class FileStore:
         """
         result = False
         for (key, value) in self.files.items():
-            (mode,uid,gid,filepath) = string.split(value, ',', 3)
+            (mode,uid,gid,filepath) = value.split(',', 3)
             if (filepath == path):
                 result = True
                 break
@@ -176,7 +176,7 @@ class FileStore:
         filename = None
 
         for (key, value) in self.files.items():
-            (mode,uid,gid,filepath) = string.split(value, ',', 3)
+            (mode,uid,gid,filepath) = value.split(',', 3)
             if (filepath == path):
                 filename = key
                 break
@@ -218,7 +218,7 @@ class FileStore:
 
         for (filename, value) in self.files.items():
 
-            (mode,uid,gid,path) = string.split(value, ',', 3)
+            (mode,uid,gid,path) = value.split(',', 3)
 
             backup_path = os.path.join(self._path, filename)
             if not os.path.exists(backup_path):
@@ -267,7 +267,7 @@ class FileStore:
         filename = None
 
         for (key, value) in self.files.items():
-            (mode,uid,gid,filepath) = string.split(value, ',', 3)
+            (mode,uid,gid,filepath) = value.split(',', 3)
             if (filepath == path):
                 filename = key
                 break
-- 
2.5.0

From 9a4c7811a1896f6a196b93fa07fef62602c72269 Mon Sep 17 00:00:00 2001
From: Petr Viktorin <pvikt...@redhat.com>
Date: Fri, 19 Feb 2016 17:51:27 +0100
Subject: [PATCH] ipalib.x809: Accept bytes for make_pem

Part of the work for https://fedorahosted.org/freeipa/ticket/5638
---
 ipalib/x509.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/ipalib/x509.py b/ipalib/x509.py
index 2d28876de6ba7963417ef1505558a1d7b52a429f..2edd3fef2f89fa8956359eeb99b4c7ae3bd65775 100644
--- a/ipalib/x509.py
+++ b/ipalib/x509.py
@@ -272,6 +272,8 @@ def make_pem(data):
     Convert a raw base64-encoded blob into something that looks like a PE
     file with lines split to 64 characters and proper headers.
     """
+    if isinstance(data, bytes):
+        data = data.decode('ascii')
     pemcert = '\r\n'.join([data[x:x+64] for x in range(0, len(data), 64)])
     return '-----BEGIN CERTIFICATE-----\n' + \
     pemcert + \
-- 
2.5.0

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to