From 14b24db532ba8009c026e6e66a70f4d080d4e539 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Thu, 11 Sep 2014 16:14:33 +0200 Subject: [PATCH] Fix mistake on merge Ldap authenticator fix on 1.5 :-) --- server/.settings/org.eclipse.core.resources.prefs | 2 -- server/src/uds/auths/SimpleLDAP/Authenticator.py | 15 +++++---------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/server/.settings/org.eclipse.core.resources.prefs b/server/.settings/org.eclipse.core.resources.prefs index c5b76c390..87cb5df18 100644 --- a/server/.settings/org.eclipse.core.resources.prefs +++ b/server/.settings/org.eclipse.core.resources.prefs @@ -216,9 +216,7 @@ encoding//src/uds/services/Xen/xen_client/__init__.py=utf-8 encoding//src/uds/services/__init__.py=utf-8 encoding//src/uds/templatetags/REST.py=utf-8 encoding//src/uds/templatetags/html5.py=utf-8 -encoding//src/uds/tests/__init__.py=utf-8 encoding//src/uds/tests/core/util/cache.py=utf-8 -encoding//src/uds/tests/core/util/net.py=utf-8 encoding//src/uds/tests/core/util/storage.py=utf-8 encoding//src/uds/tests/enterprise/__init__.py=utf-8 encoding//src/uds/tests/enterprise/serials/__init__.py=utf-8 diff --git a/server/src/uds/auths/SimpleLDAP/Authenticator.py b/server/src/uds/auths/SimpleLDAP/Authenticator.py index b0bf38f34..5b701a768 100644 --- a/server/src/uds/auths/SimpleLDAP/Authenticator.py +++ b/server/src/uds/auths/SimpleLDAP/Authenticator.py @@ -43,7 +43,7 @@ from uds.core.auths.Exceptions import AuthenticatorException import ldap import logging -__updated__ = '2014-06-02' +__updated__ = '2014-09-11' logger = logging.getLogger(__name__) @@ -145,9 +145,6 @@ class SimpleLDAPAuthenticator(Authenticator): l = None cache = False try: - if password is not None: - password = password.encode('utf-8') - # ldap.set_option(ldap.OPT_DEBUG_LEVEL, 9) ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER) schema = self._ssl and 'ldaps' or 'ldap' @@ -182,11 +179,10 @@ class SimpleLDAPAuthenticator(Authenticator): try: con = self.__connection() filter_ = '(&(objectClass=%s)(%s=%s))' % (self._userClass, self._userIdAttr, username) - attrlist = [x.encode('utf-8') for x in self._userNameAttr.split(',')] + [self._userIdAttr.encode('utf-8')] + 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] - logger.debug('res: {0}'.format(res[1])) usr = dict((k, '') for k in attrlist) usr.update(res[1]) usr.update({'dn': res[0], '_id': username}) @@ -204,7 +200,6 @@ class SimpleLDAPAuthenticator(Authenticator): 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] - logger.debug('res: {0}'.format(res[1])) grp = dict((k, ['']) for k in attrlist) grp.update(res[1]) grp.update({'dn': res[0], '_id': groupName}) @@ -219,7 +214,7 @@ class SimpleLDAPAuthenticator(Authenticator): con = self.__connection() filter_ = '(&(objectClass=%s)(|(%s=%s)(%s=%s)))' % (self._groupClass, self._memberAttr, usr['_id'], self._memberAttr, usr['dn']) logger.debug('Filter: {0}'.format(filter_)) - res = con.search_ext_s(base=self._ldapBase, scope=ldap.SCOPE_SUBTREE, filterstr=filter_, attrlist=[self._groupIdAttr.encode('utf-8')], + res = con.search_ext_s(base=self._ldapBase, scope=ldap.SCOPE_SUBTREE, filterstr=filter_, attrlist=[self._groupIdAttr], sizelimit=LDAP_RESULT_LIMIT) groups = {} for g in res: @@ -239,7 +234,7 @@ class SimpleLDAPAuthenticator(Authenticator): Tries to extract the real name for this user. Will return all atttributes (joint) specified in _userNameAttr (comma separated). ''' - return ' '.join([(type(usr.get(id_, '')) is list and ' '.join((k.decode('utf-8') for k in usr.get(id_, ''))) or usr.get(id_, '')) for id_ in self._userNameAttr.split(',')]).strip() + return ' '.join([(type(usr.get(id_, '')) is list and ' '.join((str(k) for k in usr.get(id_, ''))) or str(usr.get(id_, ''))) for id_ in self._userNameAttr.split(',')]).strip() def authenticate(self, username, credentials, groupsManager): ''' @@ -417,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