From 35ee674e379e9642f3c7e85fcf9e2df8e78044cb Mon Sep 17 00:00:00 2001 From: Patrick Uiterwijk Date: Apr 04 2016 21:50:55 +0000 Subject: [PATCH 1/2] info: infoldap: allow anonymous binding This patch will make it possible to bind anonymously. python-ldap wants no arguments to simple_bind_s for anonymous binds, and passing None for bind_dn and password does not imply anonymous binding. Fixes: #205 Signed-off-by: Patrick Uiterwijk Reviewed-by: Rob Crittenden --- diff --git a/ipsilon/info/infoldap.py b/ipsilon/info/infoldap.py index a197157..50da880 100644 --- a/ipsilon/info/infoldap.py +++ b/ipsilon/info/infoldap.py @@ -105,7 +105,11 @@ Info plugin that uses LDAP to retrieve user data. """ if not self.server_url.startswith("ldaps"): conn.start_tls_s() - conn.simple_bind_s(self.bind_dn, self.bind_password) + if (self.bind_dn is None and self.bind_password is None) or + (self.bind_dn == '' and self.bind_password == ''): + conn.simple_bind_s() + else: + conn.simple_bind_s(self.bind_dn, self.bind_password) return conn From 26c4e68ec9b15de133d83f0d38f8c78afb834c98 Mon Sep 17 00:00:00 2001 From: Patrick Uiterwijk Date: Apr 05 2016 08:27:20 +0000 Subject: [PATCH 2/2] info: infoldap: prevent NameError in case bind fails In case the bind failed, we had no base defined, but the error handler did expect this to be defined. We move the definition of base up so this is always defined, even if the error binding fails. Fixes: #204 Signed-off-by: Patrick Uiterwijk Reviewed-by: Rob Crittenden --- diff --git a/ipsilon/info/infoldap.py b/ipsilon/info/infoldap.py index 50da880..6466d30 100644 --- a/ipsilon/info/infoldap.py +++ b/ipsilon/info/infoldap.py @@ -105,8 +105,8 @@ Info plugin that uses LDAP to retrieve user data. """ if not self.server_url.startswith("ldaps"): conn.start_tls_s() - if (self.bind_dn is None and self.bind_password is None) or - (self.bind_dn == '' and self.bind_password == ''): + if ((self.bind_dn is None and self.bind_password is None) or + (self.bind_dn == '' and self.bind_password == '')): conn.simple_bind_s() else: conn.simple_bind_s(self.bind_dn, self.bind_password) @@ -171,8 +171,8 @@ Info plugin that uses LDAP to retrieve user data. """ return {} try: - conn = self._ldap_bind() base = self.base_dn + conn = self._ldap_bind() return self.get_user_data_from_conn(conn, dn, base, user) except ldap.LDAPError as e: self.error(