gods

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

commit 8b0dbe931ca515bf8876f9186a3e40aeb16d5ac4
parent 008cdacd3f1d2117cf8e562a17001449205467ce
Author: Naveen Narayanan <zerous@nocebo.space>
Date:   Mon, 27 Sep 2021 22:06:18 +0200

Implement ban logic

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

diff --git a/main.c b/main.c @@ -1,5 +1,6 @@ #include <errno.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <time.h> @@ -8,9 +9,11 @@ #include "parser.h" #include "queue.h" -#define BUFSZ 512 +#define BUFSZ 256 + +static char buf[BUFSZ]; +SLIST_HEAD(lhead, attacker) head = SLIST_HEAD_INITIALIZER(head); -char buf[BUFSZ]; void ban(struct attacker *a) { @@ -50,9 +53,10 @@ init(struct attacker *a) int main(int argc, char **argv) { + struct attacker *a; FILE *fp; char *line; - int c; + int c, found; fp = fopen("./authlog", "r"); if (!fp) @@ -70,10 +74,33 @@ main(int argc, char **argv) if (parse(buf) == -1) { fprintf(stderr, "parse failed\n"); + continue; + } + + a = 0; + found = 0; + if (isattack(statmsg)) { + printf("isattack\n"); + SLIST_FOREACH(a, &head, attackers) { + printf("slist_foreach 1\n"); + printf("a: %p\n", a); + if (!strcmp(a->ip, ip)) { + printf("if 1\n"); + ++found; + break; + } + } + if (!found) { + printf("attacker not found\n"); + a = malloc(sizeof(struct attacker)); + init(a); + SLIST_INSERT_HEAD(&head, a, attackers); + } + ban(a); + } if (c == EOF) break; } - return 0; }