mirror of
https://github.com/kakwa/ldapcherry
synced 2024-11-22 01:14:21 +01:00
better handling of the str/byte mess for python3
* add dedicated methods for python 3 in handling of bytearrays/strings * using them to compare attributes checks in AD backend
This commit is contained in:
parent
12c511b537
commit
18fdeb483e
@ -144,10 +144,10 @@ class Backend(ldapcherry.backend.backendLdap.Backend):
|
||||
for a in attrslist:
|
||||
self.attrlist.append(self._str(a))
|
||||
|
||||
if b'cn' not in self.attrlist:
|
||||
if self._str('cn') not in self.attrlist:
|
||||
raise MissingAttr()
|
||||
|
||||
if b'unicodePwd' not in self.attrlist:
|
||||
if self._str('unicodePwd') not in self.attrlist:
|
||||
raise MissingAttr()
|
||||
|
||||
def _search_group(self, searchfilter, groupdn):
|
||||
|
@ -312,22 +312,35 @@ class Backend(ldapcherry.backend.Backend):
|
||||
else:
|
||||
dn_entry = r[0]
|
||||
return dn_entry
|
||||
|
||||
# python-ldap talks in bytes,
|
||||
# as the rest of ldapcherry talks in unicode utf-8:
|
||||
# * everything passed to python-ldap must be converted to bytes
|
||||
# * everything coming from python-ldap must be converted to unicode
|
||||
if sys.version < '3':
|
||||
def _str(self, s):
|
||||
"""unicode -> bytes conversion"""
|
||||
if s is None:
|
||||
return None
|
||||
return s.encode('utf-8')
|
||||
def _uni(self, s):
|
||||
"""bytes -> unicode conversion"""
|
||||
if s is None:
|
||||
return None
|
||||
return s.decode('utf-8', 'ignore')
|
||||
else:
|
||||
def _str(self, s):
|
||||
"""unicode -> bytes conversion"""
|
||||
return s
|
||||
|
||||
def _str(self, s):
|
||||
"""unicode -> bytes conversion"""
|
||||
if s is None:
|
||||
return None
|
||||
return s.encode('utf-8')
|
||||
|
||||
def _uni(self, s):
|
||||
"""bytes -> unicode conversion"""
|
||||
if s is None:
|
||||
return None
|
||||
return s.decode('utf-8', 'ignore')
|
||||
def _uni(self, s):
|
||||
"""bytes -> unicode conversion"""
|
||||
if s is None:
|
||||
return None
|
||||
if type(s) is not str:
|
||||
return s.decode('utf-8', 'ignore')
|
||||
else:
|
||||
return s
|
||||
|
||||
def auth(self, username, password):
|
||||
"""Authentication of a user"""
|
||||
|
Loading…
Reference in New Issue
Block a user