From 20c526682962f4e14e4a22dcf9238ad50b099c3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Thu, 11 Sep 2014 14:32:18 +0200 Subject: [PATCH] Fixed LDAP Authenticator (unicode related issue) --- server/src/uds/auths/SimpleLDAP/Authenticator.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/server/src/uds/auths/SimpleLDAP/Authenticator.py b/server/src/uds/auths/SimpleLDAP/Authenticator.py index 5b5cc1cfa..5b701a768 100644 --- a/server/src/uds/auths/SimpleLDAP/Authenticator.py +++ b/server/src/uds/auths/SimpleLDAP/Authenticator.py @@ -33,6 +33,8 @@ @author: Adolfo Gómez, dkmaster at dkmon dot com ''' +from __future__ import unicode_literals + from django.utils.translation import ugettext_noop as _ from uds.core.ui.UserInterface import gui from uds.core.auths import Authenticator @@ -41,7 +43,7 @@ from uds.core.auths.Exceptions import AuthenticatorException import ldap import logging -__updated__ = '2014-03-19' +__updated__ = '2014-09-11' logger = logging.getLogger(__name__) @@ -177,7 +179,7 @@ class SimpleLDAPAuthenticator(Authenticator): try: con = self.__connection() filter_ = '(&(objectClass=%s)(%s=%s))' % (self._userClass, self._userIdAttr, username) - attrlist = self._userNameAttr.split(',') + [self._userIdAttr] + attrlist = [i.encode('utf-8') for i in self._userNameAttr.split(',') + [self._userIdAttr]] logger.debug('Getuser filter_: {0}, attr list: {1}'.format(filter_, attrlist)) res = con.search_ext_s(base=self._ldapBase, scope=ldap.SCOPE_SUBTREE, filterstr=filter_, attrlist=attrlist, sizelimit=LDAP_RESULT_LIMIT)[0] @@ -194,7 +196,7 @@ class SimpleLDAPAuthenticator(Authenticator): try: con = self.__connection() filter_ = '(&(objectClass=%s)(%s=%s))' % (self._groupClass, self._groupIdAttr, groupName) - attrlist = [self._memberAttr] + attrlist = [self._memberAttr.encode('utf-8')] logger.debug('Getgroup filter_: {0}, attr list {1}'.format(filter_, attrlist)) res = con.search_ext_s(base=self._ldapBase, scope=ldap.SCOPE_SUBTREE, filterstr=filter_, attrlist=attrlist, sizelimit=LDAP_RESULT_LIMIT)[0] @@ -410,7 +412,7 @@ class SimpleLDAPAuthenticator(Authenticator): # And group part, with membership try: - res = con.search_ext_s(base=self._ldapBase, scope=ldap.SCOPE_SUBTREE, filterstr='(&(objectClass=%s)(%s=*))' % (self._groupClass, self._groupIdAttr), attrlist=[self._memberAttr]) + res = con.search_ext_s(base=self._ldapBase, scope=ldap.SCOPE_SUBTREE, filterstr='(&(objectClass=%s)(%s=*))' % (self._groupClass, self._groupIdAttr), attrlist=[self._memberAttr.encode('utf-8')]) if len(res) == 0: raise Exception(_('Ldap group class or group id attr is probably wrong (can\'t find any group with both conditions)')) ok = False