From adf56e63f84e0d52c0453bc0e2ba222b984659cb Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Sat, 15 Dec 2018 09:42:47 +0100 Subject: [PATCH] remove vendored dpam library (fixes #29085) --- MANIFEST.in | 1 - doc/auth_pam.rst | 26 ------ doc/configuration.rst | 2 - doc/installation.rst | 1 - doc/quick_pam.rst | 26 ------ src/authentic2/__init__.py | 6 -- src/authentic2/vendor/__init__.py | 0 src/authentic2/vendor/dpam/LICENSE | 8 -- src/authentic2/vendor/dpam/__init__.py | 0 src/authentic2/vendor/dpam/backends.py | 41 --------- src/authentic2/vendor/dpam/pam.py | 123 ------------------------- 11 files changed, 234 deletions(-) delete mode 100644 doc/auth_pam.rst delete mode 100644 doc/quick_pam.rst delete mode 100644 src/authentic2/vendor/__init__.py delete mode 100644 src/authentic2/vendor/dpam/LICENSE delete mode 100644 src/authentic2/vendor/dpam/__init__.py delete mode 100644 src/authentic2/vendor/dpam/backends.py delete mode 100644 src/authentic2/vendor/dpam/pam.py diff --git a/MANIFEST.in b/MANIFEST.in index b0517243..046ab496 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -59,7 +59,6 @@ include src/authentic2/auth2_auth/auth2_ssl/authentic_ssl.vhost include requirements.txt include test_settings include getlasso.sh -include src/authentic2/vendor/dpam/LICENSE include src/authentic2/nonce/README.rst include doc/conf.py doc/Makefile doc/README.rst.bak include local_settings.py.example diff --git a/doc/auth_pam.rst b/doc/auth_pam.rst deleted file mode 100644 index aea8c4bb..00000000 --- a/doc/auth_pam.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. _auth_pam: - -====================================== -Authentication on Authentic 2 with PAM -====================================== - -This module is copied from https://bitbucket.org/wnielson/django-pam/ by Weston -Nielson and the pam ctype module by Chris Atlee http://atlee.ca/software/pam/. - -Add 'authentic2.vendor.dpam.backends.PAMBackend' to your -``settings.py``:: - - AUTHENTICATION_BACKENDS = ( - ... - 'authentic2.vendor.dpam.backends.PAMBackend', - ... - ) - -Now you can login via the system-login credentials. If the user is -successfully authenticated but has never logged-in before, a new ``User`` -object is created. By default this new ``User`` has both ``is_staff`` and -``is_superuser`` set to ``False``. You can change this behavior by adding -``PAM_IS_STAFF=True`` and ``PAM_IS_SUPERUSER`` in your ``settings.py`` file. - -The default PAM service used is ``login`` but you can change it by setting the -``PAM_SERVICE`` variable in your ``settings.py`` file. diff --git a/doc/configuration.rst b/doc/configuration.rst index 91d16271..d3ae832c 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -35,8 +35,6 @@ Authentication backends auth_ldap - auth_pam - SAML2 ----- diff --git a/doc/installation.rst b/doc/installation.rst index d13e23a0..d94be804 100644 --- a/doc/installation.rst +++ b/doc/installation.rst @@ -51,4 +51,3 @@ ___________ quick_saml2_sp quick_cas_idp quick_ldap_backend - quick_pam diff --git a/doc/quick_pam.rst b/doc/quick_pam.rst deleted file mode 100644 index 5352088f..00000000 --- a/doc/quick_pam.rst +++ /dev/null @@ -1,26 +0,0 @@ -.. _quick_pam: - -================================= -Quickstart for PAM Authentication -================================= - -This module is copied from https://bitbucket.org/wnielson/django-pam/ by Weston -Nielson and the pam ctype module by Chris Atlee http://atlee.ca/software/pam/. - -Add 'authentic2.vendor.dpam.backends.PAMBackend' to your -``settings.py``:: - - AUTHENTICATION_BACKENDS = ( - ... - 'authentic2.vendor.dpam.backends.PAMBackend', - ... - ) - -Now you can login via the system-login credentials. If the user is -successfully authenticated but has never logged-in before, a new ``User`` -object is created. By default this new ``User`` has both ``is_staff`` and -``is_superuser`` set to ``False``. You can change this behavior by adding -``PAM_IS_STAFF=True`` and ``PAM_IS_SUPERUSER`` in your ``settings.py`` file. - -The default PAM service used is ``login`` but you can change it by setting the -``PAM_SERVICE`` variable in your ``settings.py`` file. diff --git a/src/authentic2/__init__.py b/src/authentic2/__init__.py index c835e0af..53bc83d2 100644 --- a/src/authentic2/__init__.py +++ b/src/authentic2/__init__.py @@ -1,7 +1 @@ -import sys -import os - -# vendor contains incorporated dependencies -sys.path.append(os.path.join(os.path.dirname(__file__), 'vendor')) - default_app_config = 'authentic2.apps.Authentic2Config' diff --git a/src/authentic2/vendor/__init__.py b/src/authentic2/vendor/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/authentic2/vendor/dpam/LICENSE b/src/authentic2/vendor/dpam/LICENSE deleted file mode 100644 index e12c250e..00000000 --- a/src/authentic2/vendor/dpam/LICENSE +++ /dev/null @@ -1,8 +0,0 @@ -Copyright (c) 2011, Weston Nielson -2All rights reserved. -3 -4Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: -5 -6Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. -7Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -8THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/src/authentic2/vendor/dpam/__init__.py b/src/authentic2/vendor/dpam/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/authentic2/vendor/dpam/backends.py b/src/authentic2/vendor/dpam/backends.py deleted file mode 100644 index cf9749b4..00000000 --- a/src/authentic2/vendor/dpam/backends.py +++ /dev/null @@ -1,41 +0,0 @@ -import pam -import logging - -from django.conf import settings - -from authentic2.backends import is_user_authenticable -from authentic2.compat import get_user_model - -logger = logging.getLogger(__name__) - - -class PAMBackend: - def authenticate(self, username=None, password=None): - User = get_user_model() - service = getattr(settings, 'PAM_SERVICE', 'login') - if pam.authenticate(username, password, service=service): - try: - user = User.objects.get(username=username) - except: - user = User(username=username, password='not stored here') - - if getattr(settings, 'PAM_IS_SUPERUSER', False): - user.is_superuser = True - - if getattr(settings, 'PAM_IS_STAFF', user.is_superuser): - user.is_staff = True - - user.save() - if not is_user_authenticable(user): - logger.info(u'auth_pam: authentication refused by user filters') - return None - - return user - return None - - def get_user(self, user_id): - User = get_user_model() - try: - return User.objects.get(pk=user_id) - except User.DoesNotExist: - return None diff --git a/src/authentic2/vendor/dpam/pam.py b/src/authentic2/vendor/dpam/pam.py deleted file mode 100644 index d2a12bc4..00000000 --- a/src/authentic2/vendor/dpam/pam.py +++ /dev/null @@ -1,123 +0,0 @@ -# (c) 2007 Chris AtLee -# Licensed under the MIT license: -# http://www.opensource.org/licenses/mit-license.php -""" -PAM module for python - -Provides an authenticate function that will allow the caller to authenticate -a user against the Pluggable Authentication Modules (PAM) on the system. - -Implemented using ctypes, so no compilation is necessary. -""" -__all__ = ['authenticate'] - -from ctypes import CDLL, POINTER, Structure, CFUNCTYPE, cast, pointer, sizeof -from ctypes import c_void_p, c_uint, c_char_p, c_char, c_int -from ctypes.util import find_library - -LIBPAM = CDLL(find_library("pam")) -LIBC = CDLL(find_library("c")) - -CALLOC = LIBC.calloc -CALLOC.restype = c_void_p -CALLOC.argtypes = [c_uint, c_uint] - -STRDUP = LIBC.strdup -STRDUP.argstypes = [c_char_p] -STRDUP.restype = POINTER(c_char) # NOT c_char_p !!!! - -# Various constants -PAM_PROMPT_ECHO_OFF = 1 -PAM_PROMPT_ECHO_ON = 2 -PAM_ERROR_MSG = 3 -PAM_TEXT_INFO = 4 - -class PamHandle(Structure): - """wrapper class for pam_handle_t""" - _fields_ = [ - ("handle", c_void_p) - ] - - def __init__(self): - Structure.__init__(self) - self.handle = 0 - -class PamMessage(Structure): - """wrapper class for pam_message structure""" - _fields_ = [ - ("msg_style", c_int), - ("msg", c_char_p), - ] - - def __repr__(self): - return "" % (self.msg_style, self.msg) - -class PamResponse(Structure): - """wrapper class for pam_response structure""" - _fields_ = [ - ("resp", c_char_p), - ("resp_retcode", c_int), - ] - - def __repr__(self): - return "" % (self.resp_retcode, self.resp) - -CONV_FUNC = CFUNCTYPE(c_int, - c_int, POINTER(POINTER(PamMessage)), - POINTER(POINTER(PamResponse)), c_void_p) - -class PamConv(Structure): - """wrapper class for pam_conv structure""" - _fields_ = [ - ("conv", CONV_FUNC), - ("appdata_ptr", c_void_p) - ] - -PAM_START = LIBPAM.pam_start -PAM_START.restype = c_int -PAM_START.argtypes = [c_char_p, c_char_p, POINTER(PamConv), - POINTER(PamHandle)] - -PAM_AUTHENTICATE = LIBPAM.pam_authenticate -PAM_AUTHENTICATE.restype = c_int -PAM_AUTHENTICATE.argtypes = [PamHandle, c_int] - -def authenticate(username, password, service='login'): - """Returns True if the given username and password authenticate for the - given service. Returns False otherwise - - ``username``: the username to authenticate - - ``password``: the password in plain text - - ``service``: the PAM service to authenticate against. - Defaults to 'login'""" - @CONV_FUNC - def my_conv(n_messages, messages, p_response, app_data): - """Simple conversation function that responds to any - prompt where the echo is off with the supplied password""" - # Create an array of n_messages response objects - addr = CALLOC(n_messages, sizeof(PamResponse)) - p_response[0] = cast(addr, POINTER(PamResponse)) - for i in range(n_messages): - if messages[i].contents.msg_style == PAM_PROMPT_ECHO_OFF: - pw_copy = STRDUP(str(password)) - p_response.contents[i].resp = cast(pw_copy, c_char_p) - p_response.contents[i].resp_retcode = 0 - return 0 - - handle = PamHandle() - conv = PamConv(my_conv, 0) - retval = PAM_START(service, username, pointer(conv), pointer(handle)) - - if retval != 0: - # TODO: This is not an authentication error, something - # has gone wrong starting up PAM - return False - - retval = PAM_AUTHENTICATE(handle, 0) - return retval == 0 - -if __name__ == "__main__": - import getpass - print authenticate(getpass.getuser(), getpass.getpass()) -- 2.18.0