ldap_acct_mgmt.c revision 47789246278f5a31cca77e9dff187c916ada68ac
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "ldap_headers.h"
/*ARGSUSED*/
static void
void *data,
int pam_status)
{
}
/*
* warn_user_passwd_will_expire - warn the user when the password will
* expire.
*/
static void
int sec_until_expired)
{
"Your password will expire within one hour."));
else
"Your password will expire in %d hours."),
} else {
"Your password will expire in %d days."),
}
}
/*
* display_acct_unlock_time - Display the time left for the account to
* get auto unlocked after the maximum login failures has reached.
*/
static void
{
/* Account is locked forever */
if (sec_b4_unlock == -1) {
"Your account is locked, please contact administrator."));
return;
}
"Your account is locked and will be unlocked"
" within one hour."));
else
"Your account is locked and will be unlocked"
" in %d hours."),
} else {
"Your account is locked and will be unlocked"
" in %d days."),
}
}
/*
* warn_user_passwd_expired - warn the user that the password has expired
*/
static void
{
if (grace)
"Your password has expired. "
"Number of grace logins allowed are %d."),
grace);
else
"Your password has expired."));
}
/*
* display_passwd_reset_msg - tell user that password has been reset by
* administrator
*/
static void
{
"Your password has been reset by administrator."));
}
/*
* Retreives account management related attributes for the user using
* default binding and does local account checks .
*
* Return Value: PAM_SUCCESS - If account is valid, seconds param will have
* seconds left for password to expire
* PAM_ACCT_EXPIRED - If account is inactive
* PAM_NEW_AUTHTOK_REQD - Password is reset by admin
* PAM_AUTHTOK_EXPIRED - User password has expired, grace
* param will have no. of grace logins allowed
* PAM_MAXTRIES - If maximum failure of wrong password has reached
* seconds param will have no. of seconds for the
* account to get unlocked
* PAM_AUTH_ERR - Failure return code
*/
static int
{
int rc = PAM_AUTH_ERR;
/* get the values for local account checking */
!= NS_LDAP_SUCCESS) {
"__ns_ldap_getAcctMgmt() failed for %s with error %d",
return (PAM_AUTH_ERR);
}
/* should be able to login */
*seconds =
return (PAM_SUCCESS);
/* cannot login */
/* entry inactive */
return (PAM_ACCT_EXPIRED);
/* password reset by administrator */
return (PAM_NEW_AUTHTOK_REQD);
/*
* password expired, check for grace logins.
*/
*grace =
return (PAM_AUTHTOK_EXPIRED);
}
/* max failures reached, seconds before unlock */
*seconds =
return (PAM_MAXTRIES);
}
}
return (PAM_AUTH_ERR);
}
/*
* pam_sm_acct_mgmt main account managment routine.
* This routine relies on the LDAP
* directory server to provide the
* password aging and account lockout
* information. This is done by first
* trying to authenticate the user and
* then checking the password status
* returned.
*
* Returns: module error or specific
* error on failure.
*/
int
int flags,
int argc,
const char **argv)
{
int result = PAM_AUTH_ERR;
int debug = 0;
int i;
int nowarn = 0;
for (i = 0; i < argc; i++) {
debug = 1;
nowarn = 1;
}
else
"pam_ldap pam_sm_acct_mgmt: "
"illegal option %s",
argv[i]);
}
!= PAM_SUCCESS)
goto out;
if (debug)
"ldap pam_sm_acct_mgmt(%s), flags = %x %s",
goto out;
}
/* retrieve the password from the PAM handle */
if (debug)
"no password for user %s", user);
/* Do local account checking */
} else {
/* Try to authenticate to get password management info */
}
/*
* process the password management info.
* If user needs to change the password immediately,
* just return the rc.
* Otherwise, reset rc to the appropriate PAM error or
* warn the user about password expiration.
*/
if (result == PAM_MAXTRIES) {
/* exceed retry limit, denied access to account */
if (!(flags & PAM_SILENT))
} else if (result == PAM_ACCT_EXPIRED)
/* account is inactivated */
else if (result == PAM_AUTHTOK_EXPIRED) {
if (!(flags & PAM_SILENT))
/* password expired, check for grace logins */
if (grace > 0)
else
} else if (result == PAM_NEW_AUTHTOK_REQD) {
/* password has been reset by administrator */
if (!(flags & PAM_SILENT))
} else if (result == PAM_SUCCESS) {
/*
* warn the user if the password
* is about to expire.
*/
if (!(flags & PAM_SILENT) &&
seconds > 0)
seconds);
}
out:
(void) __ns_ldap_freeCred(&credp);
/* store the password aging status in the pam handle */
if (result != PAM_SUCCESS) {
int pam_res;
return (PAM_BUF_ERR);
}
if (pam_res == PAM_SUCCESS)
sizeof (ldap_authtok_data));
!= PAM_SUCCESS) {
return (PAM_SERVICE_ERR);
}
}
return (result);
}