17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
58010d9e5Srm  * Common Development and Distribution License (the "License").
68010d9e5Srm  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22b9175c69SKenjiro Tsuji  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #include <stdlib.h>
287c478bd9Sstevel@tonic-gate #include <pwd.h>
297c478bd9Sstevel@tonic-gate #include <shadow.h>
307c478bd9Sstevel@tonic-gate #include <syslog.h>
317c478bd9Sstevel@tonic-gate #include <errno.h>
327c478bd9Sstevel@tonic-gate #include <string.h>
337c478bd9Sstevel@tonic-gate #include <crypt.h>
347c478bd9Sstevel@tonic-gate #include <unistd.h>
357c478bd9Sstevel@tonic-gate #include <user_attr.h>
367c478bd9Sstevel@tonic-gate #include <auth_attr.h>
377c478bd9Sstevel@tonic-gate #include <userdefs.h>
387c478bd9Sstevel@tonic-gate #include <deflt.h>
397c478bd9Sstevel@tonic-gate #include <sys/stat.h>
407c478bd9Sstevel@tonic-gate #include <sys/param.h>
417c478bd9Sstevel@tonic-gate #include <stdarg.h>
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #include <security/pam_appl.h>
447c478bd9Sstevel@tonic-gate #include <security/pam_modules.h>
457c478bd9Sstevel@tonic-gate #include <security/pam_impl.h>
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate #include <libintl.h>
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate #include <passwdutil.h>
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate #define	LOGINADMIN	"/etc/default/login"
527c478bd9Sstevel@tonic-gate #define	MAXTRYS		5
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /*PRINTFLIKE2*/
557c478bd9Sstevel@tonic-gate void
error(pam_handle_t * pamh,char * fmt,...)567c478bd9Sstevel@tonic-gate error(pam_handle_t *pamh, char *fmt, ...)
577c478bd9Sstevel@tonic-gate {
587c478bd9Sstevel@tonic-gate 	va_list ap;
597c478bd9Sstevel@tonic-gate 	char messages[1][PAM_MAX_MSG_SIZE];
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate 	va_start(ap, fmt);
627c478bd9Sstevel@tonic-gate 	(void) vsnprintf(messages[0], sizeof (messages[0]), fmt, ap);
637c478bd9Sstevel@tonic-gate 	(void) __pam_display_msg(pamh, PAM_ERROR_MSG, 1, messages, NULL);
647c478bd9Sstevel@tonic-gate 	va_end(ap);
657c478bd9Sstevel@tonic-gate }
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate static int
get_max_failed(char * user)687c478bd9Sstevel@tonic-gate get_max_failed(char *user)
697c478bd9Sstevel@tonic-gate {
707c478bd9Sstevel@tonic-gate 	char *val = NULL;
717c478bd9Sstevel@tonic-gate 	userattr_t *uattr;
727c478bd9Sstevel@tonic-gate 	int do_lock = 0;
737c478bd9Sstevel@tonic-gate 	int retval = 0;
747c478bd9Sstevel@tonic-gate 	char *p;
75b9175c69SKenjiro Tsuji 	void	*defp;
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate 	if ((uattr = getusernam(user)) != NULL)
787c478bd9Sstevel@tonic-gate 		val = kva_match(uattr->attr, USERATTR_LOCK_AFTER_RETRIES_KW);
797c478bd9Sstevel@tonic-gate 
80b9175c69SKenjiro Tsuji 	if (val != NULL) {
817c478bd9Sstevel@tonic-gate 		do_lock = (strcasecmp(val, "yes") == 0);
82b9175c69SKenjiro Tsuji 	} else if ((defp = defopen_r(AUTH_POLICY)) != NULL) {
837c478bd9Sstevel@tonic-gate 		int flags;
84b9175c69SKenjiro Tsuji 		flags = defcntl_r(DC_GETFLAGS, 0, defp);
857c478bd9Sstevel@tonic-gate 		TURNOFF(flags, DC_CASE);
86b9175c69SKenjiro Tsuji 		(void) defcntl_r(DC_SETFLAGS, flags, defp);
87b9175c69SKenjiro Tsuji 		if ((p = defread_r("LOCK_AFTER_RETRIES=", defp)) != NULL)
887c478bd9Sstevel@tonic-gate 			do_lock = (strcasecmp(p, "yes") == 0);
89b9175c69SKenjiro Tsuji 		defclose_r(defp);
907c478bd9Sstevel@tonic-gate 	}
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate 	if (uattr != NULL)
937c478bd9Sstevel@tonic-gate 		free_userattr(uattr);
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate 	if (do_lock) {
967c478bd9Sstevel@tonic-gate 		retval = MAXTRYS;
97b9175c69SKenjiro Tsuji 		if ((defp = defopen_r(LOGINADMIN)) != NULL) {
98b9175c69SKenjiro Tsuji 			if ((p = defread_r("RETRIES=", defp)) != NULL)
997c478bd9Sstevel@tonic-gate 				retval = atoi(p);
100b9175c69SKenjiro Tsuji 			defclose_r(defp);
1017c478bd9Sstevel@tonic-gate 		}
1027c478bd9Sstevel@tonic-gate 	}
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate 	return (retval);
1057c478bd9Sstevel@tonic-gate }
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate static void
display_warning(pam_handle_t * pamh,int failures,char * homedir)1087c478bd9Sstevel@tonic-gate display_warning(pam_handle_t *pamh, int failures, char *homedir)
1097c478bd9Sstevel@tonic-gate {
1107c478bd9Sstevel@tonic-gate 	char hushpath[MAXPATHLEN];
1117c478bd9Sstevel@tonic-gate 	struct stat buf;
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate 	(void) snprintf(hushpath, sizeof (hushpath), "%s/.hushlogin", homedir);
1147c478bd9Sstevel@tonic-gate 	if (stat(hushpath, &buf) == 0)
1157c478bd9Sstevel@tonic-gate 		return;
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate 	if (failures == 1)
1187c478bd9Sstevel@tonic-gate 		error(pamh, "Warning: 1 failed login attempt since last "
1197c478bd9Sstevel@tonic-gate 		    "successful login.");
1207c478bd9Sstevel@tonic-gate 	else if (failures < FAILCOUNT_MASK)
1217c478bd9Sstevel@tonic-gate 		error(pamh, "Warning: %d failed login attempts since last "
1227c478bd9Sstevel@tonic-gate 		    "successful login.", failures);
1237c478bd9Sstevel@tonic-gate 	else
1247c478bd9Sstevel@tonic-gate 		error(pamh, "Warning: at least %d failed login attempts since "
1257c478bd9Sstevel@tonic-gate 		    "last successful login.", failures);
1267c478bd9Sstevel@tonic-gate }
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate /*
1297c478bd9Sstevel@tonic-gate  * int pam_sm_authenticate(pamh, flags, arc, argv)
1307c478bd9Sstevel@tonic-gate  *
1317c478bd9Sstevel@tonic-gate  * This routine verifies that the password as stored in the
1327c478bd9Sstevel@tonic-gate  * PAM_AUTHTOK item is indeed the password that belongs to the user
1337c478bd9Sstevel@tonic-gate  * as stored in PAM_USER.
1347c478bd9Sstevel@tonic-gate  *
135*36e852a1SRaja Andra  * This routine will not establish Secure RPC Credentials, the pam_dhkeys
136*36e852a1SRaja Andra  * module should be stacked before us if Secure RPC Credentials are needed
137*36e852a1SRaja Andra  * to obtain passwords.
1387c478bd9Sstevel@tonic-gate  */
1397c478bd9Sstevel@tonic-gate int
pam_sm_authenticate(pam_handle_t * pamh,int flags,int argc,const char ** argv)1407c478bd9Sstevel@tonic-gate pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char **argv)
1417c478bd9Sstevel@tonic-gate {
1427c478bd9Sstevel@tonic-gate 	int	i;
1437c478bd9Sstevel@tonic-gate 	int	debug = 0;
1447c478bd9Sstevel@tonic-gate 	int	nowarn = (flags & PAM_SILENT) != 0;
1457c478bd9Sstevel@tonic-gate 	char	*user;
1467c478bd9Sstevel@tonic-gate 	char	*passwd;
1477c478bd9Sstevel@tonic-gate 	char	*rep_passwd;
1488010d9e5Srm 	char	*crypt_passwd;
1497c478bd9Sstevel@tonic-gate 	char	*repository_name;
1507c478bd9Sstevel@tonic-gate 	struct pam_repository *auth_rep;
1517c478bd9Sstevel@tonic-gate 	pwu_repository_t *pwu_rep;
1527c478bd9Sstevel@tonic-gate 	attrlist attr_pw[4];
1537c478bd9Sstevel@tonic-gate 	int	result;
1547c478bd9Sstevel@tonic-gate 	int	server_policy = 0;
1557c478bd9Sstevel@tonic-gate 	int	old_failed_count;
1567c478bd9Sstevel@tonic-gate 	char	*homedir = NULL;
1577c478bd9Sstevel@tonic-gate 	int	dolock = 1;
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate 	for (i = 0; i < argc; i++) {
1607c478bd9Sstevel@tonic-gate 		if (strcmp(argv[i], "debug") == 0)
1617c478bd9Sstevel@tonic-gate 			debug = 1;
1627c478bd9Sstevel@tonic-gate 		else if (strcmp(argv[i], "nowarn") == 0)
1637c478bd9Sstevel@tonic-gate 			nowarn = 1;
1647c478bd9Sstevel@tonic-gate 		else if (strcmp(argv[i], "server_policy") == 0)
1657c478bd9Sstevel@tonic-gate 			server_policy = 1;
1667c478bd9Sstevel@tonic-gate 		else if (strcmp(argv[i], "nolock") == 0)
1677c478bd9Sstevel@tonic-gate 			dolock = 0;
1687c478bd9Sstevel@tonic-gate 	}
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 	if (debug)
17157c40785SJoep Vesseur 		__pam_log(LOG_AUTH | LOG_DEBUG,
1727c478bd9Sstevel@tonic-gate 		    "pam_unix_auth: entering pam_sm_authenticate()");
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate 	if (pam_get_item(pamh, PAM_USER, (void **)&user) != PAM_SUCCESS) {
17557c40785SJoep Vesseur 		__pam_log(LOG_AUTH | LOG_DEBUG, "pam_unix_auth: USER not set");
1767c478bd9Sstevel@tonic-gate 		return (PAM_SYSTEM_ERR);
1777c478bd9Sstevel@tonic-gate 	}
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate 	if (user == NULL || *user == '\0') {
18057c40785SJoep Vesseur 		__pam_log(LOG_AUTH | LOG_DEBUG,
18157c40785SJoep Vesseur 		    "pam_unix_auth: USER NULL or empty!\n");
1827c478bd9Sstevel@tonic-gate 		return (PAM_USER_UNKNOWN);
1837c478bd9Sstevel@tonic-gate 	}
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate 	if (pam_get_item(pamh, PAM_AUTHTOK, (void **)&passwd) != PAM_SUCCESS) {
18657c40785SJoep Vesseur 		__pam_log(LOG_AUTH | LOG_DEBUG,
18757c40785SJoep Vesseur 		    "pam_unix_auth: AUTHTOK not set!\n");
1887c478bd9Sstevel@tonic-gate 		return (PAM_SYSTEM_ERR);
1897c478bd9Sstevel@tonic-gate 	}
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate 	result = pam_get_item(pamh, PAM_REPOSITORY, (void **)&auth_rep);
1927c478bd9Sstevel@tonic-gate 	if (result == PAM_SUCCESS && auth_rep != NULL) {
1937c478bd9Sstevel@tonic-gate 		if ((pwu_rep = calloc(1, sizeof (*pwu_rep))) == NULL)
1947c478bd9Sstevel@tonic-gate 			return (PAM_BUF_ERR);
1957c478bd9Sstevel@tonic-gate 		pwu_rep->type = auth_rep->type;
1967c478bd9Sstevel@tonic-gate 		pwu_rep->scope = auth_rep->scope;
1977c478bd9Sstevel@tonic-gate 		pwu_rep->scope_len = auth_rep->scope_len;
1987c478bd9Sstevel@tonic-gate 	} else {
1997c478bd9Sstevel@tonic-gate 		pwu_rep = PWU_DEFAULT_REP;
2007c478bd9Sstevel@tonic-gate 	}
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate 	/*
2037c478bd9Sstevel@tonic-gate 	 * Get password and the name of the repository where the
2047c478bd9Sstevel@tonic-gate 	 * password resides.
2057c478bd9Sstevel@tonic-gate 	 */
2067c478bd9Sstevel@tonic-gate 	attr_pw[0].type = ATTR_PASSWD;		attr_pw[0].next = &attr_pw[1];
2077c478bd9Sstevel@tonic-gate 	attr_pw[1].type = ATTR_REP_NAME;	attr_pw[1].next = &attr_pw[2];
2087c478bd9Sstevel@tonic-gate 	/*
2097c478bd9Sstevel@tonic-gate 	 * Also get the current number of failed logins; we use
2107c478bd9Sstevel@tonic-gate 	 * this later to determine whether we need to reset the count
2117c478bd9Sstevel@tonic-gate 	 * on a succesful authentication. We use the home-directory
2127c478bd9Sstevel@tonic-gate 	 * to look for .hushlogin in order to optionaly surpress the
2137c478bd9Sstevel@tonic-gate 	 * "failed attempts" message.
2147c478bd9Sstevel@tonic-gate 	 */
2157c478bd9Sstevel@tonic-gate 	attr_pw[2].type = ATTR_FAILED_LOGINS;	attr_pw[2].next = &attr_pw[3];
2167c478bd9Sstevel@tonic-gate 	attr_pw[3].type = ATTR_HOMEDIR;		attr_pw[3].next = NULL;
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 	result = __get_authtoken_attr(user, pwu_rep, attr_pw);
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate 	if (pwu_rep != PWU_DEFAULT_REP)
2217c478bd9Sstevel@tonic-gate 		free(pwu_rep);
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate 	if (result == PWU_NOT_FOUND) {
22457c40785SJoep Vesseur 		__pam_log(LOG_AUTH | LOG_DEBUG,
22557c40785SJoep Vesseur 		    "pam_unix_auth: user %s not found\n", user);
2267c478bd9Sstevel@tonic-gate 		return (PAM_USER_UNKNOWN);
2277c478bd9Sstevel@tonic-gate 	}
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 	if (result == PWU_DENIED) {
23057c40785SJoep Vesseur 		__pam_log(LOG_AUTH | LOG_DEBUG,
23157c40785SJoep Vesseur 		    "pam_unix_auth: failed to obtain attributes");
2327c478bd9Sstevel@tonic-gate 		return (PAM_PERM_DENIED);
2337c478bd9Sstevel@tonic-gate 	}
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate 	if (result != PWU_SUCCESS)
2367c478bd9Sstevel@tonic-gate 		return (PAM_SYSTEM_ERR);
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate 	rep_passwd = attr_pw[0].data.val_s;
2397c478bd9Sstevel@tonic-gate 	repository_name = attr_pw[1].data.val_s;
2407c478bd9Sstevel@tonic-gate 	old_failed_count = attr_pw[2].data.val_i;
2417c478bd9Sstevel@tonic-gate 	homedir = attr_pw[3].data.val_s;
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate 	/*
2447c478bd9Sstevel@tonic-gate 	 * Chop off old SunOS-style password aging information.
2457c478bd9Sstevel@tonic-gate 	 *
2467c478bd9Sstevel@tonic-gate 	 * Note: old style password aging is only defined for UNIX-style
2477c478bd9Sstevel@tonic-gate 	 *	 crypt strings, hence the comma will always be at position 14.
2487c478bd9Sstevel@tonic-gate 	 * Note: This code is here because some other vendors might still
2497c478bd9Sstevel@tonic-gate 	 *	 support this style of password aging. If we don't remove
2507c478bd9Sstevel@tonic-gate 	 *	 the age field, no one will be able to login.
2517c478bd9Sstevel@tonic-gate 	 * XXX   yank this code when we're certain this "compatibility"
2527c478bd9Sstevel@tonic-gate 	 *	 isn't needed anymore.
2537c478bd9Sstevel@tonic-gate 	 */
2547c478bd9Sstevel@tonic-gate 	if (rep_passwd != NULL && rep_passwd[0] != '$' &&
2557c478bd9Sstevel@tonic-gate 	    strlen(rep_passwd) > 13 && rep_passwd[13] == ',')
2567c478bd9Sstevel@tonic-gate 		rep_passwd[13] = '\0';
2577c478bd9Sstevel@tonic-gate 
2587c478bd9Sstevel@tonic-gate 	/* Is a password check required? */
2597c478bd9Sstevel@tonic-gate 	if (rep_passwd == NULL || *rep_passwd == '\0') {
2607c478bd9Sstevel@tonic-gate 		if (flags & PAM_DISALLOW_NULL_AUTHTOK) {
2617c478bd9Sstevel@tonic-gate 			result = PAM_AUTH_ERR;
26257c40785SJoep Vesseur 			__pam_log(LOG_AUTH | LOG_NOTICE,
26357c40785SJoep Vesseur 			    "pam_unix_auth: empty password for %s not allowed.",
26457c40785SJoep Vesseur 			    user);
2657c478bd9Sstevel@tonic-gate 			goto out;
2667c478bd9Sstevel@tonic-gate 		} else {
2677c478bd9Sstevel@tonic-gate 			result = PAM_SUCCESS;
2687c478bd9Sstevel@tonic-gate 			goto out;
2697c478bd9Sstevel@tonic-gate 		}
2707c478bd9Sstevel@tonic-gate 	}
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate 	/*
2737c478bd9Sstevel@tonic-gate 	 * Password check *is* required. Make sure we have a valid
2747c478bd9Sstevel@tonic-gate 	 * pointer in PAM_AUTHTOK
2757c478bd9Sstevel@tonic-gate 	 */
2767c478bd9Sstevel@tonic-gate 	if (passwd == NULL) {
2777c478bd9Sstevel@tonic-gate 		result = PAM_AUTH_ERR;
2787c478bd9Sstevel@tonic-gate 		goto out;
2797c478bd9Sstevel@tonic-gate 	}
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate 	if (server_policy &&
2827c478bd9Sstevel@tonic-gate 	    strcmp(repository_name, "files") != 0 &&
283*36e852a1SRaja Andra 	    strcmp(repository_name, "nis") != 0) {
2847c478bd9Sstevel@tonic-gate 		result = PAM_IGNORE;
2857c478bd9Sstevel@tonic-gate 		goto out;
2867c478bd9Sstevel@tonic-gate 	}
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate 	/* Now check the entered password */
2898010d9e5Srm 	if ((crypt_passwd = crypt(passwd, rep_passwd)) == NULL) {
2908010d9e5Srm 		switch (errno) {
2918010d9e5Srm 		case ENOMEM:
2928010d9e5Srm 			result = PAM_BUF_ERR;
2938010d9e5Srm 			break;
2948010d9e5Srm 		case ELIBACC:
2958010d9e5Srm 			result = PAM_OPEN_ERR;
2968010d9e5Srm 			break;
2978010d9e5Srm 		default:
2988010d9e5Srm 			result = PAM_SYSTEM_ERR;
2998010d9e5Srm 		}
3008010d9e5Srm 		goto out;
3018010d9e5Srm 	}
3028010d9e5Srm 
3038010d9e5Srm 	if (strcmp(crypt_passwd, rep_passwd) == 0)
3047c478bd9Sstevel@tonic-gate 		result = PAM_SUCCESS;
3057c478bd9Sstevel@tonic-gate 	else
3067c478bd9Sstevel@tonic-gate 		result = PAM_AUTH_ERR;
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate 	/* Clear or increment failed failed count */
3097c478bd9Sstevel@tonic-gate 	if (dolock && (result == PAM_SUCCESS && old_failed_count > 0)) {
3107c478bd9Sstevel@tonic-gate 		old_failed_count = __rst_failed_count(user, repository_name);
3117c478bd9Sstevel@tonic-gate 		if (nowarn == 0 && old_failed_count > 0)
3127c478bd9Sstevel@tonic-gate 			display_warning(pamh, old_failed_count, homedir);
3137c478bd9Sstevel@tonic-gate 	} else if (dolock && result == PAM_AUTH_ERR) {
3147c478bd9Sstevel@tonic-gate 		int max_failed = get_max_failed(user);
31547d0cd5cSgww 		if (max_failed != 0) {
31647d0cd5cSgww 			if (__incr_failed_count(user, repository_name,
31747d0cd5cSgww 			    max_failed) == PWU_ACCOUNT_LOCKED)
31847d0cd5cSgww 				result = PAM_MAXTRIES;
31947d0cd5cSgww 		}
3207c478bd9Sstevel@tonic-gate 	}
3217c478bd9Sstevel@tonic-gate out:
3227c478bd9Sstevel@tonic-gate 	if (rep_passwd)
3237c478bd9Sstevel@tonic-gate 		free(rep_passwd);
3247c478bd9Sstevel@tonic-gate 	if (repository_name)
3257c478bd9Sstevel@tonic-gate 		free(repository_name);
3267c478bd9Sstevel@tonic-gate 	if (homedir)
3277c478bd9Sstevel@tonic-gate 		free(homedir);
3287c478bd9Sstevel@tonic-gate 	return (result);
3297c478bd9Sstevel@tonic-gate }
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3327c478bd9Sstevel@tonic-gate int
pam_sm_setcred(pam_handle_t * pamh,int flags,int argc,const char ** argv)3337c478bd9Sstevel@tonic-gate pam_sm_setcred(pam_handle_t *pamh, int flags, int argc, const char **argv)
3347c478bd9Sstevel@tonic-gate {
3357c478bd9Sstevel@tonic-gate 	return (PAM_IGNORE);
3367c478bd9Sstevel@tonic-gate }
337