Skip to content

Commit 15931c7

Browse files
committed
Catch ldap exceptions
1 parent 140e52f commit 15931c7

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

ldapauthd.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import base64
44
import json
55
import ldap3
6+
from ldap3.core.exceptions import LDAPException
67
import logging
78
import mmh3
89
import os
@@ -148,13 +149,21 @@ def check_auth(self, username, password):
148149
return True
149150

150151
def authenticate(self, username, password):
151-
userinfo = self.fetch_user_info(username)
152+
try:
153+
userinfo = self.fetch_user_info(username)
154+
except LDAPException as err:
155+
log.error("Failed to fetch user informations: %s", err)
156+
return None
152157
if not userinfo:
153158
# user not found
154159
return None
155160

156-
if not self.check_auth(userinfo.entry_dn, password):
157-
# invalid password
161+
try:
162+
if not self.check_auth(userinfo.entry_dn, password):
163+
# invalid password
164+
return None
165+
except LDAPException as err:
166+
log.debug("Failed to check users password: %s", err)
158167
return None
159168

160169
allowed, role = self.user_to_role(username)

0 commit comments

Comments
 (0)