pam-0.1.4/0000755000175000017500000000000011277100251011541 5ustar catleecatleepam-0.1.4/pam.py0000644000175000017500000000753111254253511012701 0ustar catleecatlee# (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", POINTER(c_char)), ] def __repr__(self): return "" % (self.msg_style, self.msg) class PamResponse(Structure): """wrapper class for pam_response structure""" _fields_ = [ ("resp", POINTER(c_char)), ("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_END = LIBPAM.pam_end PAM_END.restpe = c_int PAM_END.argtypes = [PamHandle, c_int] 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 = pw_copy 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 PAM_END(handle, retval) return False retval = PAM_AUTHENTICATE(handle, 0) e = PAM_END(handle, retval) return retval == 0 and e == 0 if __name__ == "__main__": import getpass print authenticate(getpass.getuser(), getpass.getpass()) pam-0.1.4/pam.egg-info/0000755000175000017500000000000011277100251014010 5ustar catleecatleepam-0.1.4/pam.egg-info/zip-safe0000644000175000017500000000000111202255311015434 0ustar catleecatlee pam-0.1.4/pam.egg-info/top_level.txt0000644000175000017500000000000411277100251016534 0ustar catleecatleepam pam-0.1.4/pam.egg-info/PKG-INFO0000644000175000017500000000146211277100251015110 0ustar catleecatleeMetadata-Version: 1.0 Name: pam Version: 0.1.4 Summary: PAM interface using ctypes Home-page: http://atlee.ca/software/pam Author: Chris AtLee Author-email: chris@atlee.ca License: MIT Download-URL: http://atlee.ca/software/pam/dist/0.1.4 Description: An interface to the Pluggable Authentication Modules (PAM) library on linux, written in pure python (using ctypes) Platform: UNKNOWN Classifier: Development Status :: 3 - Alpha Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: MIT License Classifier: Operating System :: POSIX :: Linux Classifier: Operating System :: MacOS :: MacOS X Classifier: Programming Language :: Python Classifier: Topic :: Software Development :: Libraries :: Python Modules Classifier: Topic :: System :: Systems Administration :: Authentication/Directory pam-0.1.4/pam.egg-info/SOURCES.txt0000644000175000017500000000025711277100251015700 0ustar catleecatleepam.py setup.py pam.egg-info/PKG-INFO pam.egg-info/SOURCES.txt pam.egg-info/dependency_links.txt pam.egg-info/entry_points.txt pam.egg-info/top_level.txt pam.egg-info/zip-safepam-0.1.4/pam.egg-info/entry_points.txt0000644000175000017500000000004511277100251017305 0ustar catleecatlee # -*- Entry points: -*- pam-0.1.4/pam.egg-info/dependency_links.txt0000644000175000017500000000000111277100251020056 0ustar catleecatlee pam-0.1.4/PKG-INFO0000644000175000017500000000146211277100251012641 0ustar catleecatleeMetadata-Version: 1.0 Name: pam Version: 0.1.4 Summary: PAM interface using ctypes Home-page: http://atlee.ca/software/pam Author: Chris AtLee Author-email: chris@atlee.ca License: MIT Download-URL: http://atlee.ca/software/pam/dist/0.1.4 Description: An interface to the Pluggable Authentication Modules (PAM) library on linux, written in pure python (using ctypes) Platform: UNKNOWN Classifier: Development Status :: 3 - Alpha Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: MIT License Classifier: Operating System :: POSIX :: Linux Classifier: Operating System :: MacOS :: MacOS X Classifier: Programming Language :: Python Classifier: Topic :: Software Development :: Libraries :: Python Modules Classifier: Topic :: System :: Systems Administration :: Authentication/Directory pam-0.1.4/setup.py0000644000175000017500000000216511254242614013264 0ustar catleecatleefrom setuptools import setup, find_packages import sys, os version = '0.1.4' setup(name='pam', version=version, description="PAM interface using ctypes", long_description="""\ An interface to the Pluggable Authentication Modules (PAM) library on linux, written in pure python (using ctypes)""", classifiers=["Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: POSIX :: Linux", "Operating System :: MacOS :: MacOS X", "Programming Language :: Python", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: System :: Systems Administration :: Authentication/Directory" ], keywords='', author='Chris AtLee', author_email='chris@atlee.ca', url='http://atlee.ca/software/pam', download_url = "http://atlee.ca/software/pam/dist/%s" % version, license='MIT', py_modules=["pam"], zip_safe=True, install_requires=[], entry_points=""" # -*- Entry points: -*- """, ) pam-0.1.4/setup.cfg0000644000175000017500000000007311277100251013362 0ustar catleecatlee[egg_info] tag_build = tag_date = 0 tag_svn_revision = 0