Initial import from FreeBSD RELENG_4:
[games.git] / contrib / libpam / libpam / pam_password.c
1 /* pam_password.c - PAM Password Management */
2
3 /*
4  * $Id: pam_password.c,v 1.7 1997/04/05 06:56:45 morgan Exp $
5  * $FreeBSD: src/contrib/libpam/libpam/pam_password.c,v 1.1.1.1.6.2 2001/06/11 15:28:12 markm Exp $
6  *
7  * $Log: pam_password.c,v $
8  */
9
10 #include <stdio.h>
11 #include <stdlib.h>
12
13 #include "pam_private.h"
14
15 int pam_chauthtok(pam_handle_t *pamh, int flags)
16 {
17     int retval;
18
19     D(("called."));
20
21     IF_NO_PAMH("pam_chauthtok", pamh, 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
31     /* first loop through to check if there will be a problem */
32     if (pamh->former.update ||
33         (retval = _pam_dispatch(pamh, flags|PAM_PRELIM_CHECK,
34                                 PAM_CHAUTHTOK)) == PAM_SUCCESS) {
35         pamh->former.update = PAM_TRUE;
36         retval = _pam_dispatch(pamh, flags|PAM_UPDATE_AUTHTOK,
37                                PAM_CHAUTHTOK);
38     }
39
40     /* if we completed we should clean up */
41     if (retval != PAM_INCOMPLETE) {
42         _pam_sanitize(pamh);
43         pamh->former.update = PAM_FALSE;
44         _pam_await_timer(pamh, retval);   /* if unsuccessful then wait now */
45         D(("pam_authenticate exit"));
46     } else {
47         D(("will resume when ready"));
48     }
49
50     return retval;
51 }
52