fix: use ldap3 context in order to reconnect to LDAP server (fixes #64)

parent 3a37d48c
......@@ -56,7 +56,10 @@ class LdapLoader:
self.server = Server(, port=self.port, use_ssl=self.ssl, get_info=ALL, tls=self.tls)
self.ldap = Connection(self.server, user=self.binddn, password=self.bindpw, raise_exceptions=True)
if self.ldap.bind():
binded = False
with self.ldap:
binded = True
if binded:'OK, connected to LDAP')
raise Exception('Not connected')
......@@ -70,7 +73,7 @@ class LdapLoader:
:func:`burpui.misc.auth.ldap.LdapLoader.__exit__` closes the connection to the
LDAP server.
if self.ldap:
if self.ldap and self.ldap.bound:
def fetch(self, searchval=None):
......@@ -90,8 +93,12 @@ class LdapLoader:
query = '{0}={1}'.format(self.attr, searchval)'filter: %s | base: %s', query, self.base), query, attributes=['cn', self.attr])
r = self.ldap.response
r = None
with self.ldap:, query, attributes=['cn', self.attr])
r = self.ldap.response
if not r:
raise Exception('no results')
except Exception as e:'Ooops, LDAP lookup failed: {0}'.format(str(e)))
return None
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment