#NEWLINE# def authenticate( username , password ) : #NEWLINE# #INDENT# '\n    Returns True if the given username and password authenticate for the\n    given service.  Returns False otherwise\n\n    ``username``: the username to authenticate\n\n    ``password``: the password in plain text\n    ' #NEWLINE# service = __opts__ . get ( 'auth.pam.service' , 'login' ) #NEWLINE# @ CONV_FUNC #NEWLINE# def my_conv( n_messages , messages , p_response , app_data ) : #NEWLINE# #INDENT# '\n        Simple conversation function that responds to any\n        prompt where the echo is off with the supplied password\n        ' #NEWLINE# addr = CALLOC ( n_messages , sizeof ( PamResponse ) ) #NEWLINE# p_response [ 0 ] = cast ( addr , POINTER ( PamResponse ) ) #NEWLINE# for i in range ( n_messages ) : #NEWLINE# #INDENT# if ( messages [ i ] . contents . msg_style == PAM_PROMPT_ECHO_OFF ) : #NEWLINE# #INDENT# pw_copy = STRDUP ( str ( password ) ) #NEWLINE# p_response . contents [ i ] . resp = cast ( pw_copy , c_char_p ) #NEWLINE# p_response . contents [ i ] . resp_retcode = 0 #NEWLINE# #UNINDENT# #UNINDENT# return 0 #NEWLINE# #UNINDENT# handle = PamHandle ( ) #NEWLINE# conv = PamConv ( my_conv , 0 ) #NEWLINE# retval = PAM_START ( service , my_conv , pointer ( conv ) , pointer ( handle ) ) #NEWLINE# if ( retval != 0 ) : #NEWLINE# #INDENT# PAM_END ( handle , retval ) #NEWLINE# return False #NEWLINE# #UNINDENT# retval = PAM_AUTHENTICATE ( handle , 0 ) #NEWLINE# PAM_END ( handle , 0 ) #NEWLINE# return ( retval == 0 )