LDAP should only show logs when asked.

This commit is contained in:
Joseph Schorr 2015-05-11 13:01:49 -04:00
parent de6267700e
commit 1c83def15b

View file

@ -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: