summaryrefslogtreecommitdiffstats
path: root/ipaserver/plugins
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2013-01-21 06:35:38 -0500
committerMartin Kosek <mkosek@redhat.com>2013-03-01 16:59:44 +0100
commit1960945e28e467c18454f27e0839d124473a68cc (patch)
treeeb662262aa5890080bffbb307e4c1ea770a13ed4 /ipaserver/plugins
parentd11c337541a7e1f105ee55ccd268f010413e9a23 (diff)
downloadfreeipa.git-1960945e28e467c18454f27e0839d124473a68cc.tar.gz
freeipa.git-1960945e28e467c18454f27e0839d124473a68cc.tar.xz
freeipa.git-1960945e28e467c18454f27e0839d124473a68cc.zip
Turn the LDAPError handler into a context manager
This has the advantage that the traceback is left intact if an error other than LDAPError is raised. Part of the work for: https://fedorahosted.org/freeipa/ticket/2660
Diffstat (limited to 'ipaserver/plugins')
-rw-r--r--ipaserver/plugins/ldap2.py17
1 files changed, 4 insertions, 13 deletions
diff --git a/ipaserver/plugins/ldap2.py b/ipaserver/plugins/ldap2.py
index 2852c4d4..85e4787d 100644
--- a/ipaserver/plugins/ldap2.py
+++ b/ipaserver/plugins/ldap2.py
@@ -128,7 +128,7 @@ class ldap2(LDAPConnection, CrudBackend):
if debug_level:
_ldap.set_option(_ldap.OPT_DEBUG_LEVEL, debug_level)
- try:
+ with self.error_handler():
force_updates = api.env.context in ('installer', 'updates')
conn = IPASimpleLDAPObject(
self.ldap_uri, force_schema_updates=force_updates)
@@ -167,9 +167,6 @@ class ldap2(LDAPConnection, CrudBackend):
else:
conn.simple_bind_s(bind_dn, bind_pw)
- except _ldap.LDAPError, e:
- self.handle_errors(e)
-
return conn
def destroy_connection(self):
@@ -346,18 +343,14 @@ class ldap2(LDAPConnection, CrudBackend):
# The python-ldap passwd command doesn't verify the old password
# so we'll do a simple bind to validate it.
if old_pass != '':
- try:
+ with self.error_handler():
conn = IPASimpleLDAPObject(
self.ldap_uri, force_schema_updates=False)
conn.simple_bind_s(dn, old_pass)
conn.unbind()
- except _ldap.LDAPError, e:
- self.handle_errors(e)
- try:
+ with self.error_handler():
self.conn.passwd_s(dn, old_pass, new_pass)
- except _ldap.LDAPError, e:
- self.handle_errors(e)
def add_entry_to_group(self, dn, group_dn, member_attr='member', allow_same=False):
"""
@@ -473,10 +466,8 @@ class ldap2(LDAPConnection, CrudBackend):
mod = [(_ldap.MOD_REPLACE, 'krbprincipalkey', None),
(_ldap.MOD_REPLACE, 'krblastpwdchange', None)]
- try:
+ with self.error_handler():
self.conn.modify_s(dn, mod)
- except _ldap.LDAPError, e:
- self.handle_errors(e)
# CrudBackend methods