]>
git.saurik.com Git - apple/system_cmds.git/blob - chkpasswd.tproj/pam_passwd.c
2 * Copyright (c) 1999-2016 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 #include <security/pam_appl.h>
26 #include <security/openpam.h> /* for openpam_ttyconv() */
30 extern char* progname
;
31 static pam_handle_t
*pamh
;
32 static struct pam_conv pamc
;
34 //-------------------------------------------------------------------------------------
36 //-------------------------------------------------------------------------------------
39 pam_check_passwd(char* uname
)
41 int retval
= PAM_SUCCESS
;
44 pamc
.conv
= &openpam_ttyconv
;
45 pam_start(progname
, uname
, &pamc
, &pamh
);
47 printf("Checking password for %s.\n", uname
);
50 if (PAM_SUCCESS
!= (retval
= pam_authenticate(pamh
, 0)))
54 if (PAM_SUCCESS
!= (retval
= pam_acct_mgmt(pamh
, 0)) && PAM_NEW_AUTHTOK_REQD
!= retval
)
57 /* Change the password. */
58 if (PAM_NEW_AUTHTOK_REQD
== retval
&& PAM_SUCCESS
!= (retval
= pam_chauthtok(pamh
, 0)))
61 /* Set the credentials. */
62 if (PAM_SUCCESS
!= (retval
= pam_setcred(pamh
, PAM_ESTABLISH_CRED
)))
65 /* Open the session. */
66 if (PAM_SUCCESS
!= (retval
= pam_open_session(pamh
, 0)))
69 /* Close the session. */
70 if (PAM_SUCCESS
!= (retval
= pam_close_session(pamh
, 0)))
74 /* Print an error, if needed. */
75 if (PAM_SUCCESS
!= retval
)
76 fprintf(stderr
, "Sorry\n");
79 pam_end(pamh
, retval
);