URL: https://github.com/freeipa/freeipa/pull/1068
Author: stlaz
 Title: #1068: [Backport][ipa-4-6] ldif: handle attribute names as strings
Action: opened

PR body:
"""
This PR was opened automatically because PR #1049 was pushed to master and 
backport to ipa-4-6 is required.
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/1068/head:pr1068
git checkout pr1068
From de125f679d8171eb8cc7c7a9e0039ae2c3d483f8 Mon Sep 17 00:00:00 2001
From: Stanislav Laznicka <slazn...@redhat.com>
Date: Thu, 7 Sep 2017 16:29:14 +0200
Subject: [PATCH] ldif: handle attribute names as strings

ldif.LDIFRecordList handles all attribute names as utf-8 strings
and all attribute values as bytes. If we take the attribute value
and try to search for it in the entry (= dictionary), if it contains
the attribute name as a key (which is a string), their hashes match.
However, even if hashes match, Python needs to make sure those two
are the same in case of a hash collision, so it tries to compare them.
This causes BytesWarning exception when running in strict mode
because `bytes` and `str` instances cannot be compared. KeyError
would be thrown in a non-strict mode.

Also, when later passing the attr to replace_value(), we need for it
to be `str` otherwise the modifications handler fails because it
tries to sort the attributes it's modifying but that's a bit less
poetic issue than the first one.

https://pagure.io/freeipa/issue/7129
---
 ipaserver/install/installutils.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/ipaserver/install/installutils.py b/ipaserver/install/installutils.py
index ff37d8475e..8983718950 100644
--- a/ipaserver/install/installutils.py
+++ b/ipaserver/install/installutils.py
@@ -1434,6 +1434,7 @@ def modifications_from_ldif(self, ldif_file):
 
             if "replace" in entry:
                 for attr in entry["replace"]:
+                    attr = attr.decode('utf-8')
                     try:
                         self.replace_value(dn, attr, entry[attr])
                     except KeyError:
@@ -1441,9 +1442,11 @@ def modifications_from_ldif(self, ldif_file):
                                          "missing".format(dn=dn, attr=attr))
             elif "delete" in entry:
                 for attr in entry["delete"]:
+                    attr = attr.decode('utf-8')
                     self.remove_value(dn, attr, entry.get(attr, None))
             elif "add" in entry:
                 for attr in entry["add"]:
+                    attr = attr.decode('utf-8')
                     try:
                         self.replace_value(dn, attr, entry[attr])
                     except KeyError:
_______________________________________________
FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org

Reply via email to