Skip to content

Commit

Permalink
Update pam_dc.py
Browse files Browse the repository at this point in the history
Update #265
  • Loading branch information
mar10 committed Sep 14, 2022
1 parent 0a1c362 commit 6c04339
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions wsgidav/dc/pam_dc.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(self, wsgidav_app, config):
super().__init__(wsgidav_app, config)

self.lock = threading.RLock()
self.pam = pam.pam()

dc_conf = util.get_dict_value(config, "pam_dc", as_dict=True)

Expand All @@ -44,23 +45,23 @@ def require_authentication(self, realm, environ):
def basic_auth_user(self, realm, user_name, password, environ):
# Seems that python_pam is not threadsafe (#265)
with self.lock:
is_ok = pam.authenticate(
is_ok = self.pam.authenticate(
user_name,
password,
service=self.pam_service,
resetcreds=self.pam_resetcreds,
encoding=self.pam_encoding,
)
if is_ok:
_logger.debug(f"User '{user_name}' logged on.")
return True

_logger.warning(
"pam.authenticate('{}', '<redacted>', '{}') failed with code {}: {}".format(
user_name, self.pam_service, pam.code, pam.reason
)
)
return False
if not is_ok:
_logger.warning(
"pam.authenticate('{}', '<redacted>', '{}') failed with code {}: {}".format(
user_name, self.pam_service, self.pam.code, self.pam.reason
)
)
return False

_logger.debug(f"User '{user_name}' logged on.")
return True

def supports_http_digest_auth(self):
# We don't have access to a plaintext password (or stored hash)
Expand Down

0 comments on commit 6c04339

Please sign in to comment.