pam_password.c 1.5 KB

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