gods

a simple blocklist for ssh
Log | Files | Refs | README | LICENSE

commit 1d79047162f78ce0c0002049ab01fb6bd9de32b8
parent 7b74cc2166ad8898ccb854dceddf8a49f9c3fb67
Author: Naveen Narayanan <zerous@nocebo.space>
Date:   Sun, 24 Oct 2021 17:19:17 +0200

Check for duplicates in black/whitelist

Diffstat:
Mmain.c | 16++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/main.c b/main.c @@ -219,6 +219,12 @@ main(int argc, char **argv) ret = fscanf(fp, "%s\n", bf); if (ret == EOF) break; + if (!isip(bf)) + errx(1, "malformed ip in blacklist"); + SLIST_FOREACH(a, &head, attackers) + if (!strcmp(a->ip, bf)) + errx(1, "duplicate entry found in %s", + black_list); a = malloc(sizeof(struct attacker)); if (!a) err(1, "malloc failed"); @@ -226,8 +232,6 @@ main(int argc, char **argv) * Attackers generated from blacklist * will have nban and last set to 0 */ - if (!isip(bf)) - errx(1, "malformed ip in blacklist"); strcpy(a->ip, bf); a->list = BLACK; fw_block(a->ip); @@ -242,6 +246,12 @@ main(int argc, char **argv) ret = fscanf(fp, "%s\n", bf); if (ret == EOF) break; + if (!isip(bf)) + errx(1, "malformed ip in whitelist"); + SLIST_FOREACH(a, &head, attackers) + if (!strcmp(a->ip, bf)) + errx(1, "duplicate entry found in %s", + white_list); a = malloc(sizeof(struct attacker)); if (!a) err(1, "malloc failed"); @@ -249,8 +259,6 @@ main(int argc, char **argv) * Attackers generated from whitelist * will have nban and last set to 0 */ - if (!isip(bf)) - errx(1, "malformed ip in whitelist"); strcpy(a->ip, bf); a->list = WHITE; SLIST_INSERT_HEAD(&head, a, attackers);