URL: https://github.com/freeipa/freeipa/pull/408
Author: HonzaCholasta
 Title: #408: ipaldap: properly escape raw binary values in LDAP filters
Action: opened

PR body:
"""
Manually escape each byte in the value, do not use
ldap.filter.escape_filter_chars() as it does not work with bytes in
Python 3.

https://fedorahosted.org/freeipa/ticket/4985
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/408/head:pr408
git checkout pr408
From ffedfcbaae1627c3acbc4bcb82194802d0c2834f Mon Sep 17 00:00:00 2001
From: Jan Cholasta <jchol...@redhat.com>
Date: Mon, 23 Jan 2017 10:26:50 +0100
Subject: [PATCH] ipaldap: properly escape raw binary values in LDAP filters

Manually escape each byte in the value, do not use
ldap.filter.escape_filter_chars() as it does not work with bytes in
Python 3.

https://fedorahosted.org/freeipa/ticket/4985
---
 ipapython/ipaldap.py | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/ipapython/ipaldap.py b/ipapython/ipaldap.py
index daee068..3d4aea4 100644
--- a/ipapython/ipaldap.py
+++ b/ipapython/ipaldap.py
@@ -1245,11 +1245,10 @@ def make_filter_from_attr(
             return cls.combine_filters(flts, rules)
         elif value is not None:
             if isinstance(value, bytes):
-                if six.PY3:
-                    value = value.decode('raw_unicode_escape')
+                value = u''.join(
+                    u'\\{:02x}'.format(i) for i in six.iterbytes(value))
             else:
-                value = value_to_utf8(value)
-            value = ldap.filter.escape_filter_chars(value)
+                value = ldap.filter.escape_filter_chars(value)
             if not exact:
                 template = '%s'
                 if leading_wildcard:
-- 
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