4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include "ldap_headers.h"
33 * LDAP module for pam_sm_authenticate.
42 * pam_sm_authenticate():
56 int result
= PAM_AUTH_ERR
;
59 char *password
= NULL
;
60 ns_cred_t
*credp
= NULL
;
63 /* Get the service and user */
64 if ((err
= pam_get_item(pamh
, PAM_SERVICE
, (void **)&service
))
66 (err
= pam_get_item(pamh
, PAM_USER
, (void **)&user
)) != PAM_SUCCESS
)
70 * Check options passed to this module.
71 * Silently ignore try_first_pass and use_first_pass options
74 for (i
= 0; i
< argc
; i
++) {
75 if (strcmp(argv
[i
], "debug") == 0)
77 else if (strcmp(argv
[i
], "nowarn") == 0)
79 else if ((strcmp(argv
[i
], "try_first_pass") != 0) &&
80 (strcmp(argv
[i
], "use_first_pass") != 0))
81 syslog(LOG_AUTH
| LOG_DEBUG
,
82 "ldap pam_sm_authenticate(%s), "
83 "illegal scheme option %s", service
, argv
[i
]);
87 syslog(LOG_AUTH
| LOG_DEBUG
,
88 "ldap pam_sm_authenticate(%s %s), flags = %x %s",
89 service
, (user
&& *user
!= '\0')?user
:"no-user", flags
,
90 (nowarn
)? ", nowarn": "");
92 if (!user
|| *user
== '\0')
93 return (PAM_USER_UNKNOWN
);
95 /* Get the password entered in the first scheme if any */
96 (void) pam_get_item(pamh
, PAM_AUTHTOK
, (void **) &password
);
97 if (password
== NULL
) {
99 syslog(LOG_AUTH
| LOG_DEBUG
,
100 "ldap pam_sm_authenticate(%s %s), "
101 "AUTHTOK not set", service
, user
);
102 return (PAM_AUTH_ERR
);
106 * Authenticate user using the password from PAM_AUTHTOK.
107 * If no password available or if authentication fails
108 * return the appropriate error.
110 result
= authenticate(&credp
, user
, password
, NULL
);
111 if (result
== PAM_NEW_AUTHTOK_REQD
) {
113 * PAM_NEW_AUTHTOK_REQD means the
114 * user's password is good but needs
115 * to change immediately. If the service
116 * is login or similar programs, the
117 * user will be asked to change the
118 * password after the account management
119 * module is called and determined that
120 * the password has expired.
121 * So change the rc to PAM_SUCCESS here.
123 result
= PAM_SUCCESS
;
124 } else if (result
== PAM_AUTHTOK_EXPIRED
) {
126 * Authentication token is the right one but
127 * expired. Consider this as pass.
128 * Change rc to PAM_SUCCESS.
130 result
= PAM_SUCCESS
;
134 (void) __ns_ldap_freeCred(&credp
);