Report the actual error when ldap fails

This commit is contained in:
Alexandre Aubin 2020-04-09 19:05:20 +02:00
parent 33c3505c47
commit 628ffc9da1
2 changed files with 16 additions and 26 deletions

View file

@ -19,7 +19,6 @@
"invalid_token": "Invalid token - please authenticate",
"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 '{action}' operation",
"ldap_server_down": "Unable to reach LDAP server",
"logged_in": "Logged in",
"logged_out": "Logged out",

View file

@ -148,15 +148,12 @@ class Authenticator(BaseAuthenticator):
try:
result = self.con.search_s(base, ldap.SCOPE_SUBTREE, filter, attrs)
except Exception as e:
logger.exception(
raise MoulinetteError(
"error during LDAP search operation with: base='%s', "
"filter='%s', attrs=%s and exception %s",
base,
filter,
attrs,
e,
"filter='%s', attrs=%s and exception %s"
% (base, filter, attrs, e),
raw_msg=True
)
raise MoulinetteError("ldap_operation_error", action="search")
result_list = []
if not attrs or "dn" not in attrs:
@ -185,14 +182,12 @@ class Authenticator(BaseAuthenticator):
try:
self.con.add_s(dn, ldif)
except Exception as e:
logger.exception(
raise MoulinetteError(
"error during LDAP add operation with: rdn='%s', "
"attr_dict=%s and exception %s",
rdn,
attr_dict,
e,
"attr_dict=%s and exception %s"
% (rdn, attr_dict, e),
raw_msg=True
)
raise MoulinetteError("ldap_operation_error", action="add")
else:
return True
@ -211,12 +206,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(
"error during LDAP delete operation with: rdn='%s' and exception %s"
% (rdn, e),
raw_msg=True
)
raise MoulinetteError("ldap_operation_error", action="remove")
else:
return True
@ -249,15 +243,12 @@ class Authenticator(BaseAuthenticator):
self.con.modify_ext_s(dn, ldif)
except Exception as e:
logger.exception(
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,
"attr_dict=%s, new_rdn=%s and exception: %s"
% (rdn, attr_dict, new_rdn, e),
raw_msg=True
)
raise MoulinetteError("ldap_operation_error", action="update")
else:
return True