mirror of
https://github.com/kakwa/ldapcherry
synced 2024-11-25 18:54:29 +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:
|
for a in attrslist:
|
||||||
self.attrlist.append(self._str(a))
|
self.attrlist.append(self._str(a))
|
||||||
|
|
||||||
if b'cn' not in self.attrlist:
|
if self._str('cn') not in self.attrlist:
|
||||||
raise MissingAttr()
|
raise MissingAttr()
|
||||||
|
|
||||||
if b'unicodePwd' not in self.attrlist:
|
if self._str('unicodePwd') not in self.attrlist:
|
||||||
raise MissingAttr()
|
raise MissingAttr()
|
||||||
|
|
||||||
def _search_group(self, searchfilter, groupdn):
|
def _search_group(self, searchfilter, groupdn):
|
||||||
|
@ -312,22 +312,35 @@ class Backend(ldapcherry.backend.Backend):
|
|||||||
else:
|
else:
|
||||||
dn_entry = r[0]
|
dn_entry = r[0]
|
||||||
return dn_entry
|
return dn_entry
|
||||||
|
|
||||||
# python-ldap talks in bytes,
|
# python-ldap talks in bytes,
|
||||||
# as the rest of ldapcherry talks in unicode utf-8:
|
# as the rest of ldapcherry talks in unicode utf-8:
|
||||||
# * everything passed to python-ldap must be converted to bytes
|
# * everything passed to python-ldap must be converted to bytes
|
||||||
# * everything coming from python-ldap must be converted to unicode
|
# * everything coming from python-ldap must be converted to unicode
|
||||||
|
if sys.version < '3':
|
||||||
def _str(self, s):
|
def _str(self, s):
|
||||||
"""unicode -> bytes conversion"""
|
"""unicode -> bytes conversion"""
|
||||||
if s is None:
|
if s is None:
|
||||||
return None
|
return None
|
||||||
return s.encode('utf-8')
|
return s.encode('utf-8')
|
||||||
|
|
||||||
def _uni(self, s):
|
def _uni(self, s):
|
||||||
"""bytes -> unicode conversion"""
|
"""bytes -> unicode conversion"""
|
||||||
if s is None:
|
if s is None:
|
||||||
return None
|
return None
|
||||||
return s.decode('utf-8', 'ignore')
|
return s.decode('utf-8', 'ignore')
|
||||||
|
else:
|
||||||
|
def _str(self, s):
|
||||||
|
"""unicode -> bytes conversion"""
|
||||||
|
return s
|
||||||
|
|
||||||
|
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):
|
def auth(self, username, password):
|
||||||
"""Authentication of a user"""
|
"""Authentication of a user"""
|
||||||
|
Loading…
Reference in New Issue
Block a user