From baa958c81ff645b2984b64b3122f15d898292654 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Sat, 25 Apr 2015 11:14:04 +0200 Subject: [PATCH] Fix compatibility for PAM auth PR #280 invoked `pam.authenticate().authenticate()` for older versions of python-pam. Also, this version avoids monkeypatching the PAM module. --- radicale/auth/PAM.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/radicale/auth/PAM.py b/radicale/auth/PAM.py index ead7a17..3098169 100644 --- a/radicale/auth/PAM.py +++ b/radicale/auth/PAM.py @@ -33,9 +33,13 @@ from .. import config, log GROUP_MEMBERSHIP = config.get("auth", "pam_group_membership") -# Compatibility patch for old versions of python-pam. -if not hasattr(pam, "pam"): - pam.pam = (lambda *vargs, **kwargs: pam.authenticate(*vargs, **kwards)) +# Compatibility for old versions of python-pam. +if hasattr(pam, "pam"): + def pam_authenticate(*args, **kwargs): + return pam.pam().authenticate(*args, **kwargs) +else: + def pam_authenticate(*args, **kwargs): + return pam.authenticate(*args, **kwargs) def is_authenticated(user, password): @@ -77,7 +81,7 @@ def is_authenticated(user, password): "The PAM user belongs to the required group (%s)" % GROUP_MEMBERSHIP) # Check the password - if pam.pam().authenticate(user, password): + if pam_authenticate(user, password): return True else: log.LOGGER.debug("Wrong PAM password")