Be more verbose when logging errors in info LDAP plugin
authorRob Crittenden <rcritten@redhat.com>
Tue, 3 Nov 2015 22:02:04 +0000 (17:02 -0500)
committerPatrick Uiterwijk <puiterwijk@redhat.com>
Sat, 14 Nov 2015 00:04:53 +0000 (01:04 +0100)
The infoldap plugin was logging raw exceptions but not providing
any context to them.

This breaks some of the calls into separate try/except to provide
more precise failure reasons.

Also fix a typo in the authldap plugin and handle ValueError
when validating the template syntax.

https://fedorahosted.org/ipsilon/ticket/39

Signed-off-by: Rob Crittenden <rcritten@redhat.com>
Reviewed-by: Simo Sorce <simo@redhat.com>
Reviewed-by: John Dennis <jdennis@redhat.com>
ipsilon/info/infoldap.py
ipsilon/login/authldap.py

index 66e8d50..a197157 100644 (file)
@@ -139,25 +139,48 @@ Info plugin that uses LDAP to retrieve user data. """
         reply = dict()
         try:
             ldapattrs = self._get_user_data(conn, dn)
-            self.debug(ldapattrs)
+            self.debug('LDAP attrs for %s: %s' % (dn, ldapattrs))
             userattrs, extras = self.mapper.map_attributes(ldapattrs)
             groups = self._get_user_groups(conn, base, username)
             reply = userattrs
             reply['_groups'] = groups
             reply['_extras'] = {'ldap': extras}
         except Exception, e:  # pylint: disable=broad-except
-            self.error(e)
+            self.error('Error fetching/mapping LDAP user data: %s' % e)
 
         return reply
 
     def get_user_attrs(self, user):
         try:
-            conn = self._ldap_bind()
             dn = self.user_dn_tmpl % {'username': user}
+        except ValueError as e:
+            self.error(
+                'DN generation failed with template %s, user %s: %s'
+                % (self.user_dn_tmpl, user, e)
+            )
+            return {}
+        except Exception as e:  # pylint: disable=broad-except
+            self.error(
+                'Unhandled error generating DN from %s, user %s: %s'
+                % (self.user_dn_tmpl, user, e)
+            )
+            return {}
+
+        try:
+            conn = self._ldap_bind()
             base = self.base_dn
             return self.get_user_data_from_conn(conn, dn, base, user)
-        except Exception, e:  # pylint: disable=broad-except
-            self.error(e)
+        except ldap.LDAPError as e:
+            self.error(
+                'LDAP search failed for DN %s on base %s: %s' %
+                (dn, base, e)
+            )
+            return {}
+        except Exception as e:  # pylint: disable=broad-except
+            self.error(
+                'Unhandled LDAP error for DN %s on base %s: %s' %
+                (dn, base, e)
+            )
             return {}
 
 
index 1986490..6e9afd3 100644 (file)
@@ -233,7 +233,13 @@ class Installer(LoginManagerInstaller):
                 opts['ldap_bind_dn_template'] % {'username': 'test'}
             except KeyError:
                 logging.error(
-                    'Bind DN template does not container %(username)s'
+                    'Bind DN template does not contain %(username)s'
+                )
+                return False
+            except ValueError as e:
+                logging.error(
+                    'Invalid syntax in Bind DN template: %s ',
+                    e
                 )
                 return False
             config['bind dn template'] = opts['ldap_bind_dn_template']