diff --git a/data/users.py b/data/users.py index 4a4c9832f..fd3263a0a 100644 --- a/data/users.py +++ b/data/users.py @@ -4,6 +4,7 @@ import json import itertools import uuid import struct +import os from util.aes import AESCipher from util.validation import generate_valid_usernames @@ -29,7 +30,8 @@ class LDAPConnection(object): self._conn = None def __enter__(self): - self._conn = ldap.initialize(self._ldap_uri, trace_level=1) + trace_level = 2 if os.environ.get('LDAP_DEBUG') else 0 + self._conn = ldap.initialize(self._ldap_uri, trace_level=trace_level) self._conn.simple_bind_s(self._user_dn, self._user_pw) return self._conn @@ -54,7 +56,11 @@ class LDAPUsers(object): username_or_email) logger.debug('Conducting user search: %s => %s', user_search_dn, query) - user = conn.search_s(user_search_dn, ldap.SCOPE_SUBTREE, query.encode('utf-8')) + try: + user = conn.search_s(user_search_dn, ldap.SCOPE_SUBTREE, query.encode('utf-8')) + except ldap.LDAPError: + logger.exception('LDAP search exception') + return None logger.debug('Found user data: %s', user) if len(user) != 1: