]>
git.saurik.com Git - apple/security.git/blob - Security/libsecurity_checkpw/lib/checkpw.c
2 * Copyright (c) 2000-2012 Apple Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
18 #include <security/pam_appl.h>
19 #include <security/openpam.h>
25 #define PAM_STACK_NAME "checkpw"
28 int checkpw_internal_pam( const char* uname
, const char* password
)
30 int checkpwret
= CHECKPW_FAILURE
;
32 int pamret
= PAM_SUCCESS
;
35 pamc
.conv
= &openpam_nullconv
;
37 pamret
= pam_start(PAM_STACK_NAME
, uname
, &pamc
, &pamh
);
38 if (PAM_SUCCESS
!= pamret
)
40 syslog(LOG_WARNING
,"PAM: Unable to start pam.");
44 pamret
= pam_set_item(pamh
, PAM_AUTHTOK
, password
);
45 if (PAM_SUCCESS
!= pamret
)
47 syslog(LOG_WARNING
,"PAM: Unable to set password.");
51 pamret
= pam_authenticate(pamh
, 0);
52 if (PAM_SUCCESS
!= pamret
)
54 syslog(LOG_WARNING
,"PAM: Unable to authenticate.");
55 checkpwret
= CHECKPW_BADPASSWORD
;
59 pamret
= pam_acct_mgmt(pamh
, 0);
60 if (PAM_SUCCESS
!= pamret
)
62 if (PAM_NEW_AUTHTOK_REQD
== pamret
)
64 syslog(LOG_WARNING
,"PAM: Unable to authorize, password needs to be changed.");
66 syslog(LOG_WARNING
,"PAM: Unable to authorize.");
72 checkpwret
= CHECKPW_SUCCESS
;
75 pam_end(pamh
, pamret
);
81 #warning TODO: this should be declared in some header.
82 int checkpw_internal( const struct passwd
* pw
, const char* password
);
83 int checkpw_internal( const struct passwd
* pw
, const char* password
)
85 return checkpw(pw
->pw_name
, password
);
88 int checkpw( const char* userName
, const char* password
)
90 int siResult
= CHECKPW_FAILURE
;
91 // workaround for 3965234; I assume the empty string is OK...
92 const char *thePassword
= password
? password
: "";
95 return CHECKPW_UNKNOWNUSER
;
97 siResult
= checkpw_internal_pam(userName
, thePassword
);
100 case CHECKPW_UNKNOWNUSER
:
101 case CHECKPW_BADPASSWORD
:
105 siResult
= checkpw_internal_pam(userName
, thePassword
);