(root)/
Linux-PAM-1.5.3/
libpam/
pam_password.c
       1  /* pam_password.c - PAM Password Management */
       2  
       3  /*
       4   * $Id$
       5   */
       6  
       7  #include "pam_private.h"
       8  
       9  #include <stdio.h>
      10  #include <stdlib.h>
      11  
      12  int pam_chauthtok(pam_handle_t *pamh, int flags)
      13  {
      14      int retval;
      15  
      16      D(("called."));
      17  
      18      IF_NO_PAMH("pam_chauthtok", pamh, PAM_SYSTEM_ERR);
      19  
      20      if (__PAM_FROM_MODULE(pamh)) {
      21  	D(("called from module!?"));
      22  	return PAM_SYSTEM_ERR;
      23      }
      24  
      25      /* applications are not allowed to set this flags */
      26      if (flags & (PAM_PRELIM_CHECK | PAM_UPDATE_AUTHTOK)) {
      27        pam_syslog (pamh, LOG_ERR,
      28  		  "PAM_PRELIM_CHECK or PAM_UPDATE_AUTHTOK set by application");
      29        return PAM_SYSTEM_ERR;
      30      }
      31  
      32      if (pamh->former.choice == PAM_NOT_STACKED) {
      33  	_pam_start_timer(pamh);    /* we try to make the time for a failure
      34  				      independent of the time it takes to
      35  				      fail */
      36  	_pam_sanitize(pamh);
      37  	pamh->former.update = PAM_FALSE;
      38      }
      39  
      40      /* first call to check if there will be a problem */
      41      if (pamh->former.update ||
      42  	(retval = _pam_dispatch(pamh, flags|PAM_PRELIM_CHECK,
      43  				PAM_CHAUTHTOK)) == PAM_SUCCESS) {
      44  	D(("completed check ok: former=%d", pamh->former.update));
      45  	pamh->former.update = PAM_TRUE;
      46  	retval = _pam_dispatch(pamh, flags|PAM_UPDATE_AUTHTOK,
      47  			       PAM_CHAUTHTOK);
      48      }
      49  
      50      /* if we completed we should clean up */
      51      if (retval != PAM_INCOMPLETE) {
      52  	_pam_sanitize(pamh);
      53  	pamh->former.update = PAM_FALSE;
      54  	_pam_await_timer(pamh, retval);   /* if unsuccessful then wait now */
      55  	D(("pam_chauthtok exit %d - %d", retval, pamh->former.choice));
      56      } else {
      57  	D(("will resume when ready", retval));
      58      }
      59  
      60      return retval;
      61  }