mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-26 08:51:50 -06:00
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 Reviewed-By: Michal Reznik <mreznik@redhat.com>
This commit is contained in:
parent
16909a128b
commit
0f13e663ca
@ -1434,6 +1434,7 @@ class ModifyLDIF(ldif.LDIFParser):
|
||||
|
||||
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 @@ class ModifyLDIF(ldif.LDIFParser):
|
||||
"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:
|
||||
|
Loading…
Reference in New Issue
Block a user