Fix python3 compatibility on LDAP search DN from id

In Python 3, python-ldap no longer allows bytes for some fields (DNs,
RDNs, attribute names, queries). Instead, text values are represented
as str, the Unicode text type.

[1] More details about byte/str usage in python-ldap can be found at:
http://www.python-ldap.org/en/latest/bytes_mode.html#bytes-mode

Change-Id: I63e3715032cd8edb11fbff7651f5ba1af506dc9d
Related-Bug: #1798184
(cherry picked from commit 03531a5691)
This commit is contained in:
Raildo Mascena 2019-07-24 10:20:17 -03:00
parent 909cc9fa83
commit 6e8be2a0d6
1 changed files with 2 additions and 3 deletions

View File

@ -1296,9 +1296,8 @@ class BaseLdap(object):
def _dn_to_id(self, dn): def _dn_to_id(self, dn):
# Check if the naming attribute in the DN is the same as keystone's # Check if the naming attribute in the DN is the same as keystone's
# configured 'id' attribute'. If so, extract the ID value from the DN # configured 'id' attribute'. If so, extract the ID value from the DN
if self.id_attr == utf8_decode( if self.id_attr == ldap.dn.str2dn(dn)[0][0][0].lower():
ldap.dn.str2dn(utf8_encode(dn))[0][0][0].lower()): return ldap.dn.str2dn(dn)[0][0][1]
return utf8_decode(ldap.dn.str2dn(utf8_encode(dn))[0][0][1])
else: else:
# The 'ID' attribute is NOT in the DN, so we need to perform an # The 'ID' attribute is NOT in the DN, so we need to perform an
# LDAP search to look it up from the user entry itself. # LDAP search to look it up from the user entry itself.