Report the actual error when ldap fails

This commit is contained in:
Alexandre Aubin 2020-04-09 19:05:20 +02:00
parent 6391ef23c4
commit d94832ec3d
2 changed files with 23 additions and 13 deletions

View file

@ -19,7 +19,6 @@
"invalid_password": "Invalid password",
"invalid_usage": "Invalid usage, pass --help to see help",
"ldap_attribute_already_exists": "Attribute '{attribute}' already exists with value '{value}'",
"ldap_operation_error": "An error occurred during LDAP operation",
"ldap_server_down": "Unable to reach LDAP server",
"logged_in": "Logged in",
"logged_out": "Logged out",

View file

@ -141,9 +141,12 @@ class Authenticator(BaseAuthenticator):
try:
result = self.con.search_s(base, ldap.SCOPE_SUBTREE, filter, attrs)
except Exception as e:
logger.exception("error during LDAP search operation with: base='%s', "
"filter='%s', attrs=%s and exception %s", base, filter, attrs, e)
raise MoulinetteError('ldap_operation_error')
raise MoulinetteError(
"error during LDAP search operation with: base='%s', "
"filter='%s', attrs=%s and exception %s"
% (base, filter, attrs, e),
raw_msg=True
)
result_list = []
if not attrs or 'dn' not in attrs:
@ -172,9 +175,12 @@ class Authenticator(BaseAuthenticator):
try:
self.con.add_s(dn, ldif)
except Exception as e:
logger.exception("error during LDAP add operation with: rdn='%s', "
"attr_dict=%s and exception %s", rdn, attr_dict, e)
raise MoulinetteError('ldap_operation_error')
raise MoulinetteError(
"error during LDAP add operation with: rdn='%s', "
"attr_dict=%s and exception %s"
% (rdn, attr_dict, e),
raw_msg=True
)
else:
return True
@ -193,8 +199,11 @@ class Authenticator(BaseAuthenticator):
try:
self.con.delete_s(dn)
except Exception as e:
logger.exception("error during LDAP delete operation with: rdn='%s' and exception %s", rdn, e)
raise MoulinetteError('ldap_operation_error')
raise MoulinetteError(
"error during LDAP delete operation with: rdn='%s' and exception %s"
% (rdn, e),
raw_msg=True
)
else:
return True
@ -226,10 +235,12 @@ class Authenticator(BaseAuthenticator):
self.con.modify_ext_s(dn, ldif)
except Exception as e:
logger.exception("error during LDAP update operation with: rdn='%s', "
"attr_dict=%s, new_rdn=%s and exception: %s", rdn, attr_dict,
new_rdn, e)
raise MoulinetteError('ldap_operation_error')
raise MoulinetteError(
"error during LDAP update operation with: rdn='%s', "
"attr_dict=%s, new_rdn=%s and exception: %s"
% (rdn, attr_dict, new_rdn, e),
raw_msg=True
)
else:
return True