]>
git.saurik.com Git - apple/system_cmds.git/blob - system_cmds-597.1.1/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@
28 #include <security/pam_appl.h>
29 #include <security/openpam.h> /* for openpam_ttyconv() */
31 extern char* progname
;
32 static pam_handle_t
*pamh
;
33 static struct pam_conv pamc
;
36 pam_passwd(char* uname
)
38 int retval
= PAM_SUCCESS
;
41 pamc
.conv
= &openpam_ttyconv
;
42 pam_start(progname
, uname
, &pamc
, &pamh
);
45 if (PAM_SUCCESS
!= (retval
= pam_authenticate(pamh
, 0)))
49 if (PAM_SUCCESS
!= (retval
= pam_acct_mgmt(pamh
, 0)) && PAM_NEW_AUTHTOK_REQD
!= retval
)
52 printf("Changing password for %s.\n", uname
);
54 /* Change the password. */
55 if (PAM_SUCCESS
!= (retval
= pam_chauthtok(pamh
, 0)))
58 /* Set the credentials. */
59 if (PAM_SUCCESS
!= (retval
= pam_setcred(pamh
, PAM_ESTABLISH_CRED
)))
62 /* Open the session. */
63 if (PAM_SUCCESS
!= (retval
= pam_open_session(pamh
, 0)))
66 /* Close the session. */
67 if (PAM_SUCCESS
!= (retval
= pam_close_session(pamh
, 0)))
71 /* Print an error, if needed. */
72 if (PAM_SUCCESS
!= retval
)
73 fprintf(stderr
, "%s: %s\n", progname
, pam_strerror(pamh
, retval
));
76 pam_end(pamh
, retval
);