scribo

Email-based phlog generator
git clone git://git.z3bra.org/scribo.git
Log | Files | Refs

commit 0e895bfa4bdd8266b659a9b2cab1c57ab7e1f45c
parent 6d46f8051a81903f4c47f459a2bee9cd79ef7048
Author: Willy Goiffon <dev@z3bra.org>
Date:   Tue,  8 Sep 2020 14:24:49 +0200

Add simple authorisation based on From: field

Diffstat:
Mconfig.def.h | 1+
Mrfc5322.c | 20++++++++++++++++++++
Mrfc5322.h | 2++
Mscribo.c | 11+++++++++++
4 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -1,6 +1,7 @@ char *basedir = "."; char *datefmt = "%c"; +char *author = "contact@z3bra.org"; char *host = "z3bra.org"; int port = 70; diff --git a/rfc5322.c b/rfc5322.c @@ -51,3 +51,23 @@ rfc5322_unfold(char *body, char *line, size_t n) return strlcat(body, strsep(&line, "\r\n"), n); } + +char * +rfc5322_addr(const char *s) +{ + static char addr[HDRSIZ]; + char *p; + + if (!(p = strrchr(s, '<'))) { + strlcpy(addr, s, HDRSIZ); + return addr; + } + + strlcpy(addr, p + 1, HDRSIZ); + if ((p = strchr(addr, '>'))) { + *p = '\0'; + return addr; + } + + return NULL; +} diff --git a/rfc5322.h b/rfc5322.h @@ -1,3 +1,5 @@ char *rfc5322_headername(const char *); char *rfc5322_headerbody(const char *); size_t rfc5322_unfold(char *, char *, size_t); +char *rfc5322_addr(const char *); + diff --git a/scribo.c b/scribo.c @@ -134,6 +134,11 @@ verifyheaders(struct headers *head) if (!head) return -1; + if (!header(head, "From")) { + fprintf(stderr, "Missing header: From\n"); + return -1; + } + if (!header(head, "Date")) { fprintf(stderr, "Missing header: Date\n"); return -1; @@ -155,6 +160,12 @@ verifyheaders(struct headers *head) return -1; } + char *addr = rfc5322_addr(header(head, "From")); + if (strncmp(addr, author, strlen(author))) { + fprintf(stderr, "<%s> is not authorized to publish content\n", addr); + return -1; + } + return 0; }