Module: check_mk
Branch: master
Commit: 50835a50ba5044761964b839193ab8c4c44276c3
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=50835a50ba5044…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Nov 15 10:51:57 2012 +0100
Store last changed pw as string, not list; Catching all exceptions in page handler by
default
---
web/htdocs/userdb.py | 13 ++++++++++++-
web/plugins/userdb/ldap.py | 11 ++++++++---
2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/web/htdocs/userdb.py b/web/htdocs/userdb.py
index 643c048..f64e3c7 100644
--- a/web/htdocs/userdb.py
+++ b/web/htdocs/userdb.py
@@ -194,8 +194,19 @@ def hook_save(users):
# Hook function can be registered here to execute actions on a "regular" base
without
# user triggered action. This hook is called on each page load.
+# Catch all exceptions and log them to apache error log. Let exceptions raise trough
+# when debug mode is enabled.
def hook_page():
for connector in enabled_connectors():
handler = connector.get('page', None)
- if handler:
+ if not handler:
+ continue
+ try:
handler()
+ except:
+ if config.debug:
+ raise
+ else:
+ import traceback
+ html.log('Exception (%s, page handler): %s' %
+ (connector['id'], traceback.format_exc()))
diff --git a/web/plugins/userdb/ldap.py b/web/plugins/userdb/ldap.py
index fec04e0..a6f8669 100644
--- a/web/plugins/userdb/ldap.py
+++ b/web/plugins/userdb/ldap.py
@@ -113,7 +113,12 @@ def ldap_connect():
ldap_connection.protocol_version = config.ldap_connection['version']
ldap_default_bind()
+ except ldap.SERVER_DOWN:
+ ldap_connection = None # Invalidate connection on failure
+ raise MKLDAPException(_('The LDAP connector is unable to connect to the LDAP
server.'))
+
except ldap.LDAPError, e:
+ html.write(repr(e))
ldap_connection = None # Invalidate connection on failure
raise MKLDAPException(e)
@@ -290,12 +295,12 @@ def ldap_convert_auth_expire(user_id, ldap_user, user):
# value has been changed.
if 'ldap_pw_last_changed' not in user:
- return {'ldap_pw_last_changed': ldap_user[changed_attr]} # simply store
+ return {'ldap_pw_last_changed': ldap_user[changed_attr][0]} # simply
store
# Update data (and invalidate auth) if the attribute has changed
- if user['ldap_pw_last_changed'] != ldap_user[changed_attr]:
+ if user['ldap_pw_last_changed'] != ldap_user[changed_attr][0]:
return {
- 'ldap_pw_last_changed': ldap_user[changed_attr],
+ 'ldap_pw_last_changed': ldap_user[changed_attr][0],
'serial': user.get('serial', 0) + 1,
}