U $[@sdZdgZdZdZdZddlZddlmZmZm Z m Z m Z m Z m Z ddlmZmZmZmZmZdd lmZdd lmZGd d d e ZGd dde ZGddde Ze eeeeeeeeeZGddde ZdZdZdZdZdZeedZ eedZ!e j"Z"ee"_#eege"_$e%e!dr:e!j&Z&ee&_#eege&_$e!j'Z'ee'_#eeeeeege'_$e!j(Z(ee(_#eege(_$e!j)Z)ee)_#eege)_$e!j*Z*ee*_#eege*_$GdddZ+ddZ,e-dkrddl.Z.ddl/Z/ddZ0e+Z+e0d e/1Z2e+,e2e//e3d!4e+j5e+j6dS)"z 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. pamz1.8.4z David Ford z 2018 June 15N)CDLLPOINTER Structure CFUNCTYPEcastbyrefsizeof)c_void_pc_size_tc_char_pc_charc_int)memmove) find_libraryc@s"eZdZdZdefgZddZdS) PamHandlez&wrapper class for pam_handle_t pointerhandlecCst|d|_dS)Nr)r__init__rselfr/pam.pyr's zPamHandle.__init__N)__name__ __module__ __qualname____doc__r _fields_rrrrrr#s rc@s(eZdZdZdefdefgZddZdS) PamMessagez'wrapper class for pam_message structure msg_stylemsgcCsd|j|jfS)Nz)rrrrrr__repr__/szPamMessage.__repr__N)rrrrrr rr rrrrr+src@s(eZdZdZdefdefgZddZdS) PamResponsez(wrapper class for pam_response structureresp resp_retcodecCsd|j|jfS)Nz)r#r"rrrrr 6szPamResponse.__repr__N)rrrrr rrr rrrrr!2sr!c@s eZdZdZdefdefgZdS)PamConvz$wrapper class for pam_conv structureconvZ appdata_ptrN)rrrr conv_funcr rrrrrr$;sr$cpam_endc@s&eZdZdZdZddZd dd ZdS) rrNcCsdSNrrrrrrgsz pam.__init__loginutf-8Tc sttfdd}tjdkrZt|tr0||}ttrD|t|tr||}n.my_convr)r*zstrings may not contain NULFrzpam_start() failedr-)r&sys version_info isinstancestrencodeZunicodecodereasonr rr$ pam_startrpam_authenticate pam_setcredPAM_REINITIALIZE_CRED pam_strerrordecodehasattrlibpamr-) rusernamer8ZserviceencodingZ resetcredsr9rr%ZretvalZ auth_successrr7r authenticatejsL                   zpam.authenticate)r/r0T)rrrrArBrrMrrrrrcscOstj||S)zB Compatibility function for older versions of python-pam. )rrM)ZvargsZdargsrrrrMsrM__main__cs>fdd}t|tjdkr*t|}nt|}t|S)NcsttdSr.)readlineZ insert_textZ redisplayrtextrrhooks z input_with_prefill..hookr:)rOZset_pre_input_hookr<r=inputZ raw_input)promptrQrRresultrrPrinput_with_prefills    rVz Username: z{} {})7r__all__ __version__ __author__Z __released__r<Zctypesrrrrrrr r r r r rrZ ctypes.utilrrrr!r&r$r4ZPAM_PROMPT_ECHO_ONZ PAM_ERROR_MSGZ PAM_TEXT_INFOrFZlibcrJr1ZrestypeZargtypesrIr-rCrErGrDrrMrrOZgetpassrVZgetuserrKprintformatrArBrrrrsb $           _