aboutsummaryrefslogtreecommitdiff
path: root/contrib/blacklist
diff options
context:
space:
mode:
authorKurt Lidl <lidl@FreeBSD.org>2017-02-23 05:40:59 +0000
committerKurt Lidl <lidl@FreeBSD.org>2017-02-23 05:40:59 +0000
commit2495a63064050ff360ce2482d8b01179f9c5d48b (patch)
treedf403ea6ccf04f6b6252ce5cd9f18a596c018c87 /contrib/blacklist
parentdd165efb5a3b14767ed093d41bdd1c4cc8c86b98 (diff)
downloadsrc-2495a63064050ff360ce2482d8b01179f9c5d48b.tar.gz
src-2495a63064050ff360ce2482d8b01179f9c5d48b.zip
Reset failed login count to zero when removing a blocked address
The blacklistd daemon keeps records of failed login attempts for each address:port that is flagged as a failed login. When a successful login occurs for that address:port combination, the record's last update time is set to zero, to indicate no current failed login attempts. Reset the failed login count to zero, so that at the next failed login attempt, the counting will restart properly at zero. Without this reset to zero, the first failed login after a successful login will cause the address to be blocked immediately. When debugging is turned on, output more information about database state before and after the database updates have occured. A similar patch has already been upstreamed to NetBSD. MFC after: 3 days Sponsored by: The FreeBSD Foundation
Notes
Notes: svn path=/head/; revision=314120
Diffstat (limited to 'contrib/blacklist')
-rw-r--r--contrib/blacklist/bin/blacklistd.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/contrib/blacklist/bin/blacklistd.c b/contrib/blacklist/bin/blacklistd.c
index a497f9d74543..256ae68b61b0 100644
--- a/contrib/blacklist/bin/blacklistd.c
+++ b/contrib/blacklist/bin/blacklistd.c
@@ -207,7 +207,7 @@ process(bl_t bl)
if (debug) {
char b1[128], b2[128];
- (*lfun)(LOG_DEBUG, "%s: db state info for %s: count=%d/%d "
+ (*lfun)(LOG_DEBUG, "%s: initial db state for %s: count=%d/%d "
"last=%s now=%s", __func__, rbuf, dbi.count, c.c_nfail,
fmttime(b1, sizeof(b1), dbi.last),
fmttime(b2, sizeof(b2), ts.tv_sec));
@@ -246,15 +246,24 @@ process(bl_t bl)
case BL_DELETE:
if (dbi.last == 0)
goto out;
+ dbi.count = 0;
dbi.last = 0;
break;
default:
(*lfun)(LOG_ERR, "unknown message %d", bi->bi_type);
}
- if (state_put(state, &c, &dbi) == -1)
- goto out;
+ state_put(state, &c, &dbi);
+
out:
close(bi->bi_fd);
+
+ if (debug) {
+ char b1[128], b2[128];
+ (*lfun)(LOG_DEBUG, "%s: final db state for %s: count=%d/%d "
+ "last=%s now=%s", __func__, rbuf, dbi.count, c.c_nfail,
+ fmttime(b1, sizeof(b1), dbi.last),
+ fmttime(b2, sizeof(b2), ts.tv_sec));
+ }
}
static void
@@ -393,7 +402,7 @@ rules_restore(void)
int
main(int argc, char *argv[])
{
- int c, tout, flags, flush, restore;
+ int c, tout, flags, flush, restore, ret;
const char *spath, *blsock;
setprogname(argv[0]);
@@ -512,7 +521,10 @@ main(int argc, char *argv[])
readconf = 0;
conf_parse(configfile);
}
- switch (poll(pfd, (nfds_t)nfd, tout)) {
+ ret = poll(pfd, (nfds_t)nfd, tout);
+ if (debug)
+ (*lfun)(LOG_DEBUG, "received %d from poll()", ret);
+ switch (ret) {
case -1:
if (errno == EINTR)
continue;