]>
git.saurik.com Git - apple/system_cmds.git/blob - passwd.tproj/pam_passwd.c
2 * Copyright (c) 1999-2008 Apple Computer, 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() */
28 extern char* progname
;
29 static pam_handle_t
*pamh
;
30 static struct pam_conv pamc
;
33 pam_passwd(char* uname
)
35 int retval
= PAM_SUCCESS
;
38 pamc
.conv
= &openpam_ttyconv
;
39 pam_start(progname
, uname
, &pamc
, &pamh
);
42 if (PAM_SUCCESS
!= (retval
= pam_authenticate(pamh
, 0)))
46 if (PAM_SUCCESS
!= (retval
= pam_acct_mgmt(pamh
, 0)) && PAM_NEW_AUTHTOK_REQD
!= retval
)
49 printf("Changing password for %s.\n", uname
);
51 /* Change the password. */
52 if (PAM_SUCCESS
!= (retval
= pam_chauthtok(pamh
, 0)))
55 /* Set the credentials. */
56 if (PAM_SUCCESS
!= (retval
= pam_setcred(pamh
, PAM_ESTABLISH_CRED
)))
59 /* Open the session. */
60 if (PAM_SUCCESS
!= (retval
= pam_open_session(pamh
, 0)))
63 /* Close the session. */
64 if (PAM_SUCCESS
!= (retval
= pam_close_session(pamh
, 0)))
68 /* Print an error, if needed. */
69 if (PAM_SUCCESS
!= retval
)
70 fprintf(stderr
, "%s: %s\n", progname
, pam_strerror(pamh
, retval
));
73 pam_end(pamh
, retval
);