ldap: fix handling of binary data in search filters

This fixes a UnicodeDecodeError when passing non-UTF-8 binary data to
LDAPClient.make_filter() and friends.

https://fedorahosted.org/freeipa/ticket/5381

Reviewed-By: David Kupka <dkupka@redhat.com>
Reviewed-By: Pavel Vomacka <pvomacka@redhat.com>
This commit is contained in:
Jan Cholasta 2016-03-16 13:09:11 +01:00
parent 3edf13cd8a
commit b484667d15

View File

@ -1211,7 +1211,12 @@ class LDAPClient(object):
]
return self.combine_filters(flts, rules)
elif value is not None:
value = ldap.filter.escape_filter_chars(value_to_utf8(value))
if isinstance(value, bytes):
if six.PY3:
value = value.decode('raw_unicode_escape')
else:
value = value_to_utf8(value)
value = ldap.filter.escape_filter_chars(value)
if not exact:
template = '%s'
if leading_wildcard: