gods

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

commit a781c13eb0db048261862e6792284c86ecc12286
parent 47b619d9e3d61a804854b1c4c67314dc7a30e19f
Author: Naveen Narayanan <zerous@nocebo.space>
Date:   Mon, 27 Sep 2021 22:43:27 +0200

Remove debug printf

Diffstat:
Mmain.c | 2--
Mparser.c | 54++++++++++++++++++++----------------------------------
2 files changed, 20 insertions(+), 36 deletions(-)

diff --git a/main.c b/main.c @@ -29,8 +29,6 @@ main(int argc, char **argv) *line++ = c; } - printf("line: %s\n", buf); - if (!parse(buf)) fprintf(stderr, "parse failed\n"); if (c == EOF) diff --git a/parser.c b/parser.c @@ -52,9 +52,7 @@ range(char *s, int min, int max) return -1; errno = 0; - printf("range str: %s\n", s); t = atoi(s); - printf("range t: %d\n", t); if (errno) { fprintf(stderr, "atoi failed: %s\n", strerror(errno)); return -1; @@ -78,10 +76,9 @@ mon(struct tm *tm) for (i = 0; i < n; ++i) str[i] = toupper(*tp++); str[i] = '\0'; - printf("month: %s\n", str); + for (int i = 0; i < 12; ++i) if (!strcmp(month[i], str)) { - printf("mon found\n"); tm->tm_mon = i; return 1; } @@ -102,10 +99,10 @@ day(struct tm *tm) for (int i = 0; i < n; ++i) str[i] = *tp++; str[i] = '\0'; - printf("day str: %s\n", str); + if ((d = range(str, 1, 31)) == -1) return 0; - printf("day: %d\n", d); + tm->tm_mday = d; return 1; @@ -118,30 +115,23 @@ hms(struct tm *tm) char str[2]; - printf("tp: %s\n", tp); if ((n = strlen(tp)) != 8) return 0; - printf("strlen == 8\n"); - for (i = 0; i < 2; ++i) { - printf("%c:", *tp); + + for (i = 0; i < 2; ++i) str[i] = *tp++; - printf("%c ", str[i]); - } str[i] = '\0'; - printf("\nh: %s\n", str); + if ((h = range(str, 0, 23)) == -1) return 0; tm->tm_hour = h; if (!accept(':')) return 0; - for (i = 0; i < 2; ++i) { - printf("%c:", *tp); + for (i = 0; i < 2; ++i) str[i] = *tp++; - printf("%c ", str[i]); - } str[i] = '\0'; - printf("\nm: %s\n", str); + if ((m = range(str, 0, 59)) == -1) return 0; tm->tm_min = m; @@ -175,7 +165,6 @@ word() token[n] = '\0'; tp = token; - printf("word: %s \n", token); return 1; } @@ -193,18 +182,14 @@ timestamp() struct tm tm; int n; - printf("timestamp\n"); if (!word() || !mon(&tm)) return 0; - printf("mon ok\n"); + if (!word() || !day(&tm)) return 0; - printf("day ok\n"); + if (!word() || !hms(&tm)) return 0; - printf("hms ok\n"); - printf("timestamp: %d %d %d:%d:%d\n", tm.tm_mon, tm.tm_mday, tm.tm_hour, - tm.tm_min, tm.tm_sec); return 1; } @@ -216,12 +201,12 @@ hostname() if (gethostname(str, MAXHOSTNAMELEN) == -1) return 0; - printf("gethostname: %s\n", str); + if (!word()) return 0; if (strcmp(token, str)) return 0; - printf("hostname ok\n"); + return 1; } @@ -239,7 +224,6 @@ procid() memcpy(str, k+1, n); str[n] = '\0'; - printf("procid ok: %s\n", str); return 1; } @@ -279,7 +263,6 @@ isip(char *s) if ((t = range(o, 0, 255)) == -1) return 0; - printf("isip ok\n"); return 1; } @@ -291,7 +274,6 @@ constat() while (word()) { if (*tp) { - printf("tp: %c\n", *tp); if (isdigit(*tp) && isip(tp)) { undoword(); break; @@ -305,7 +287,7 @@ constat() if (sp == str) return 0; - printf("constat ok: %s\n", str); + return 1; } @@ -318,7 +300,6 @@ ipaddr() if (isip(token)) strcpy(ip, token); - printf("ipaddr ok: %s\n", ip); return 1; } @@ -336,7 +317,6 @@ portnum() if ((p = range(token, 1, 65535)) == -1) return 0; - printf("portnum ok: %d\n", p); return 1; } @@ -351,19 +331,25 @@ parse(char *line) { lp = line; tp = token; - printf("parse: line: %s\n", lp); + if (!timestamp()) return 0; + if (!hostname()) return 0; + if (!procid()) return 0; + if (!constat()) return 0; + if (!ipaddr()) return 0; + if (!portnum()) return 0; + if (!misc()) return 0;