[PATCH] auth: support both old and new python-pam API

Mads Kiilerich mads at kiilerich.com
Thu Feb 25 13:58:18 UTC 2016


On 02/24/2016 02:10 PM, Andrew Shadura wrote:
> # HG changeset patch
> # User Andrew Shadura <andrew at shadura.me>
> # Date 1456317153 -3600
> #      Wed Feb 24 13:32:33 2016 +0100
> # Node ID 9e0c363ed9eaf72fe0faf0da4a80065dc2faf8da
> # Parent  05a85a6cecba5c8caeb7996590365d5d9bc523c9
> auth: support both old and new python-pam API
>
> python-pam 1.8.* provides a new API replacing the previously
> available authenticate() function. The latest unreleased
> version brings it back, but until it's available, use a
> custom shim instead.

Seems reasonable. Assuming you tested it ;-)

> diff --git a/kallithea/lib/auth_modules/auth_pam.py b/kallithea/lib/auth_modules/auth_pam.py
> --- a/kallithea/lib/auth_modules/auth_pam.py
> +++ b/kallithea/lib/auth_modules/auth_pam.py
> @@ -25,7 +25,13 @@ Original author and date, and relevant c
>   
>   import logging
>   import time
> -import pam
> +
> +try:
> +    from pam import authenticate as pam_authenticate
> +except ImportError:

Here I would expect a comment like:
# work around pam.authenticate that was removed in python-pam 1.8.*

> +    from pam import pam
> +    pam_authenticate = pam().authenticate
> +
>   import pwd
>   import grp
>   import re
> @@ -92,7 +98,7 @@ class KallitheaAuthPlugin(auth_modules.K
>               # Need lock here, as PAM authentication is not thread safe
>               _pam_lock.acquire()
>               try:
> -                auth_result = pam.authenticate(username, password,
> +                auth_result = pam_authenticate(username, password,
>                                                  settings["service"])
>                   # cache result only if we properly authenticated
>                   if auth_result:
>

/Mads


More information about the kallithea-general mailing list