9511 printf family isn't aware of multibyte decimal point characters (fix regression)
[unleashed.git] / usr / src / lib / passwdutil / __failed_count.c
blob6d5b19992ac1fecc0cfd04421e1969ff9ee0d43f
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <string.h>
27 #include <syslog.h>
28 #include "passwdutil.h"
30 int
31 __incr_failed_count(char *username, char *repname, int max_failures)
33 int ret;
34 void *buf;
35 attrlist items[1];
36 int repnum = name_to_int(repname);
37 repops_t *ops;
39 /* account locking only defined for files and ldap */
40 if ((repnum != REP_FILES) &&
41 (repnum != REP_LDAP)) {
42 return (PWU_SUCCESS);
45 ops = rops[repnum];
46 if ((ops->lock != NULL) &&
47 (ret = ops->lock()) != PWU_SUCCESS) {
48 return (ret);
51 items[0].type = ATTR_INCR_FAILED_LOGINS;
52 items[0].next = NULL;
53 if ((ret = ops->getpwnam(username, items, NULL, &buf)) != PWU_SUCCESS) {
54 goto out;
57 /* We increment the failed count by one */
58 if ((ret = ops->update(items, NULL, buf)) != PWU_SUCCESS) {
59 goto out;
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)
70 goto out;
72 if (((ret = ops->putpwnam(username, NULL, NULL, buf)) ==
73 PWU_SUCCESS) &&
74 (items[0].type == ATTR_LOCK_ACCOUNT))
75 ret = PWU_ACCOUNT_LOCKED;
77 out:
78 if (ops->unlock != NULL) {
79 ops->unlock();
82 return (ret);
86 * reset the failed count.
87 * returns the number of failed logins before the reset, or an error (< 0)
89 int
90 __rst_failed_count(char *username, char *repname)
92 int ret;
93 void *buf;
94 attrlist items[1];
95 int repnum = name_to_int(repname);
96 repops_t *ops;
98 /* account locking only defined for files and ldap */
99 if ((repnum != REP_FILES) &&
100 (repnum != REP_LDAP)) {
101 return (PWU_SUCCESS);
104 ops = rops[repnum];
105 if ((ops->lock != NULL) &&
106 (ret = ops->lock()) != PWU_SUCCESS) {
107 return (ret);
110 items[0].type = ATTR_RST_FAILED_LOGINS;
111 items[0].next = NULL;
112 if ((ret = ops->getpwnam(username, items, NULL, &buf)) != PWU_SUCCESS)
113 goto out;
114 if ((ret = ops->update(items, NULL, buf)) != PWU_SUCCESS)
115 goto out;
116 ret = ops->putpwnam(username, NULL, NULL, buf);
117 out:
118 if (ops->unlock != NULL) {
119 ops->unlock();
122 return (ret != PWU_SUCCESS ? ret : items[0].data.val_i);