parameters: (username, password, service='login', tty="console", **kwargs)
return_statement: return retval == 0
docstring: Returns True if the given username and password authenticate for the
      given service.  Returns False otherwise.
  
      :param string username: The username to authenticate.
      :param string password: The password in plain text.
      :param string service:
  
          The PAM service to authenticate against.  Defaults to 'login'.
  
      :param string tty:
  
          Name of the TTY device to use when authenticating.  Defaults to
          'console' (to allow root).
  
      If additional keyword arguments are provided they will be passed to
      PAM_SET_ITEM() like so::
  
          PAM_SET_ITEM(handle, <keyword mapped to PAM_whatever>, <value>)
  
      Where the keyword will be automatically converted to a PAM_whatever constant
      if present in this file.  Example::
  
          authenticate(user, pass, PAM_RHOST="myhost")
  
      ...would result in::
  
          PAM_SET_ITEM(handle, 4, "myhost") # PAM_RHOST (4) taken from the global
docstring_summary: Returns True if the given username and password authenticate for the
      given service.  Returns False otherwise.
docstring_tokens: Returns True if the given username and password authenticate for the given service . Returns False otherwise .
function: def authenticate(username, password, service='login', tty="console", **kwargs):
      """
      Returns True if the given username and password authenticate for the
      given service.  Returns False otherwise.
  
      :param string username: The username to authenticate.
      :param string password: The password in plain text.
      :param string service:
  
          The PAM service to authenticate against.  Defaults to 'login'.
  
      :param string tty:
  
          Name of the TTY device to use when authenticating.  Defaults to
          'console' (to allow root).
  
      If additional keyword arguments are provided they will be passed to
      PAM_SET_ITEM() like so::
  
          PAM_SET_ITEM(handle, <keyword mapped to PAM_whatever>, <value>)
  
      Where the keyword will be automatically converted to a PAM_whatever constant
      if present in this file.  Example::
  
          authenticate(user, pass, PAM_RHOST="myhost")
  
      ...would result in::
  
          PAM_SET_ITEM(handle, 4, "myhost") # PAM_RHOST (4) taken from the global
      """
      encoding = 'utf-8'
      if not isinstance(password, bytes):
          password = password.encode(encoding)
      if not isinstance(username, bytes):
          username = username.encode(encoding)
      if not isinstance(service, bytes):
          service = service.encode(encoding)
      if not isinstance(tty, bytes):
          tty = tty.encode(encoding)
      @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(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))
      PAM_SET_ITEM(handle, PAM_TTY, tty)
      for key, value in kwargs.items():
          if key.startswith('PAM_') and key in globals():
              if isinstance(value, str):
                  value = value.encode(encoding)
              PAM_SET_ITEM(handle, globals()[key], value)
      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
function_tokens: def authenticate ( username , password , service = 'login' , tty = "console" , * * kwargs ) : encoding = 'utf-8' if not isinstance ( password , bytes ) : password = password . encode ( encoding ) if not isinstance ( username , bytes ) : username = username . encode ( encoding ) if not isinstance ( service , bytes ) : service = service . encode ( encoding ) if not isinstance ( tty , bytes ) : tty = tty . encode ( encoding ) @ 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 ( 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 ) ) PAM_SET_ITEM ( handle , PAM_TTY , tty ) for key , value in kwargs . items ( ) : if key . startswith ( 'PAM_' ) and key in globals ( ) : if isinstance ( value , str ) : value = value . encode ( encoding ) PAM_SET_ITEM ( handle , globals ( ) [ key ] , value ) 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