4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
28 #include "passwdutil.h"
31 __incr_failed_count(char *username
, char *repname
, int max_failures
)
36 int repnum
= name_to_int(repname
);
39 /* account locking only defined for files and ldap */
40 if ((repnum
!= REP_FILES
) &&
41 (repnum
!= REP_LDAP
)) {
46 if ((ops
->lock
!= NULL
) &&
47 (ret
= ops
->lock()) != PWU_SUCCESS
) {
51 items
[0].type
= ATTR_INCR_FAILED_LOGINS
;
53 if ((ret
= ops
->getpwnam(username
, items
, NULL
, &buf
)) != PWU_SUCCESS
) {
57 /* We increment the failed count by one */
58 if ((ret
= ops
->update(items
, NULL
, buf
)) != PWU_SUCCESS
) {
62 /* Did we just exceed "max_failures" ? */
63 if (items
[0].data
.val_i
>= max_failures
) {
64 syslog(LOG_AUTH
|LOG_NOTICE
,
65 "Excessive (%d) login failures for %s: locking account.",
66 max_failures
, username
);
68 items
[0].type
= ATTR_LOCK_ACCOUNT
;
69 if ((ret
= ops
->update(items
, NULL
, buf
)) != PWU_SUCCESS
)
72 if (((ret
= ops
->putpwnam(username
, NULL
, NULL
, buf
)) ==
74 (items
[0].type
== ATTR_LOCK_ACCOUNT
))
75 ret
= PWU_ACCOUNT_LOCKED
;
78 if (ops
->unlock
!= NULL
) {
86 * reset the failed count.
87 * returns the number of failed logins before the reset, or an error (< 0)
90 __rst_failed_count(char *username
, char *repname
)
95 int repnum
= name_to_int(repname
);
98 /* account locking only defined for files and ldap */
99 if ((repnum
!= REP_FILES
) &&
100 (repnum
!= REP_LDAP
)) {
101 return (PWU_SUCCESS
);
105 if ((ops
->lock
!= NULL
) &&
106 (ret
= ops
->lock()) != PWU_SUCCESS
) {
110 items
[0].type
= ATTR_RST_FAILED_LOGINS
;
111 items
[0].next
= NULL
;
112 if ((ret
= ops
->getpwnam(username
, items
, NULL
, &buf
)) != PWU_SUCCESS
)
114 if ((ret
= ops
->update(items
, NULL
, buf
)) != PWU_SUCCESS
)
116 ret
= ops
->putpwnam(username
, NULL
, NULL
, buf
);
118 if (ops
->unlock
!= NULL
) {
122 return (ret
!= PWU_SUCCESS
? ret
: items
[0].data
.val_i
);