nightmaremail

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 4b667230f5d92b26795f35d3ae27cb7f1eef8e67
parent 5de40d4fe063d43fb834625ef77217489473bb69
Author: Ellenor Bjornsdottir <ellenor@umbrellix.net>
Date:   Sat, 29 Oct 2022 09:28:31 +0000

look, I'm not proud of my work in src/ip.c, and it's still not complete.

Diffstat:
Mconf-cc | 2+-
Mdoc/README.mxf | 3++-
Mdoc/THANKS.mxf | 10+++++-----
Msrc/ip.c | 87++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------
4 files changed, 77 insertions(+), 25 deletions(-)

diff --git a/conf-cc b/conf-cc @@ -1,3 +1,3 @@ -cc -g -ggdb3 -O3 -Wall -Iinclude/ +cc -g -ggdb3 -O0 -Wall -Iinclude/ This will be used to compile .c files. diff --git a/doc/README.mxf b/doc/README.mxf @@ -1,7 +1,8 @@ ...:: Copying Changes to notqmail that make notqmail NightmareMail are licenced to you, the user, as termed in doc/LICENCE.mxf. This is similar to the CDDL, except there -is a resumptibility clause. +is a resumptibility clause. It also used to have an odd choice-of-laws clause, +which has been rendered more standard. Notqmail itself appears to be available under the Unlicense. diff --git a/doc/THANKS.mxf b/doc/THANKS.mxf @@ -36,11 +36,11 @@ Paul Jarc placed this patch into the public domain. Thanks Paul! This should reduce backscatter spam, which is a problem my friend Lightning at Ultradian Club has been experiencing with his mailserver. -Our replacement for qmail-remote, MXF Remote, includes sections lifted -not-quite-verbatim from qmail-remote. Notably, Connector uses the control -file procedure from qmail-remote with few modifications, having split it -to get routes for a protocol and to fetch actual protocols from a new ctrl -file. +Our sold-separately replacement for qmail-remote, MXF Remote, includes +sections lifted not-quite-verbatim from qmail-remote. Notably, Connector +uses the control file procedure from qmail-remote with few modifications, +having split it to get routes for a protocol and to fetch actual protocols +from a new ctrl file. James Craig Burley's (burleyarch.com) ISO C patch is also incorporated into MXF, from its origins in notqmail and netqmail. diff --git a/src/ip.c b/src/ip.c @@ -1,5 +1,9 @@ #include <string.h> #include "ip.h" +#ifdef CAVEMAN_DEBUGGING +#define DEBUGFD 2 +#include <stdio.h> +#endif #include "fmt.h" #include "scan.h" @@ -79,7 +83,7 @@ unsigned int ip6_fmt(char *s, struct ip6_address *ip) } } for (j = 0; j < 8; ++j) { - word = (unsigned long) ((ip->d[(j*2)]) << 8) + (ip->d[(j*2)+1]); + word = (unsigned long) ((ip->d[(j*2)]) << 8)|(ip->d[(j*2)+1]); i = fmt_ulongalphabet(s, word, "0123456789abcdef", 16); len += i; if (s) s += i; @@ -92,50 +96,97 @@ unsigned int ip6_fmt(char *s, struct ip6_address *ip) return len; } +/* as one august programmer once said, + * parsing IPv6 addresses is a real pig, or something. + * This is a horrendous interface. It's only saved because in qmail, + * *s is only ever a buffer full of the desired address. + */ static unsigned int ip6_scan(char *s, struct ip6_address *ip) { - unsigned int i, j, k; + unsigned int i, j; + signed int k, wantrhswords, hasrhswords; unsigned int len; unsigned long u; +#ifdef CAVEMAN_DEBUGGING char *st = s; +#endif unsigned char ebuf[16]; - len = i = j = k = 0; + len = i = j = hasrhswords = 0; k = wantrhswords = -1; /* left side */ for (j = 0; j < 16; ++j) { ip->d[j] = 0; + ebuf[j] = 0; } for (j = 0; j < 8; ++j) { + u = 0x0; i = scan_ulongalphabet(s,&u, "0123456789abcdef", 16); /* if (!i) return 0; this could yet be valid!.. */ if (!i) u = 0x0U; - ip->d[(j*2)] = (u & 0xff00) >> 8; - ip->d[(j*2)+1] = (u & 0x00ff); + ip->d[(j*2)] = (unsigned char)((u & 0xff00) >> 8); + ip->d[(j*2)+1] = (u & 0xff); s += i; len += i; if (*s == ':') if (*(s + 1) == ':') { - ++s; ++len; k = 1; break; +#ifdef CAVEMAN_DEBUGGING + dprintf(DEBUGFD, "Jump to right hand side at step %u of lhs ip6_scan(\"%s\", ipstruct);\n", j, st); +#endif + s += 2; len += 2; wantrhswords = 7 - (k = j); hasrhswords = 0; break; + } + if (j < 7 && *s != ':') { + // invalid data; zero and return + for (j = 0; j < 16; ++j) { + ip->d[j] = 0; + ebuf[j] = 0; + } + return 0; } - if (*s != ':') return 0; ++s; ++len; } /* right side */ - if (k) { - for (j = 0; j < 8; ++j) { - i = scan_ulong(s,&u); - /* if (!i) return 0; this could yet be valid!.. */ - if (!i) u = 0x0U; - ebuf[(j*2)] = (u & 0xff00) >> 8; - ebuf[(j*2)+1] = (u & 0x00ff); + if (k != -1) { + for (j = 0; j < wantrhswords; ++j) { + u = 0x0; + i = scan_ulongalphabet(s,&u, "0123456789abcdef", 16); +#ifdef CAVEMAN_DEBUGGING + dprintf(DEBUGFD, "scanned %u, ebuf[%u] = %lu, ebuf[%u] = %lu\n", i, (j*2), ((u & 0xff00) >> 8), (j*2)+1, (u & 0xff)); +#endif + if (!i) { +#ifdef CAVEMAN_DEBUGGING + dprintf(DEBUGFD, "scan_ulongalphabet died in right hand side step %u of ip6_scan(\"%s\", ipstruct); want %u has %u\n", j, st, wantrhswords, hasrhswords); +#endif + break; + } + if (u != 0) hasrhswords++; + ebuf[(j*2)] = (unsigned char)((u & 0xff00) >> 8); + ebuf[(j*2)+1] = (u & 0xff); s += i; len += i; - if (*s == ':') if (*(s + 1) == ':') { - break; + if (*s == ':') { + if (*(s + 1) == ':') { +#ifdef CAVEMAN_DEBUGGING + dprintf(DEBUGFD, "Aaaack! Double :: - break! in right hand side step %u of ip6_scan(\"%s\", ipstruct); want %u has %u\n", j, st, wantrhswords, hasrhswords); +#endif + for (j = 0; j < 16; ++j) { + ip->d[j] = 0; + ebuf[j] = 0; + } + return 0; /* There should never be double :: */ + } else { + s += 1; + } } } - for (k = 0; k < (j * 2); ++k) { - ip->d[15-k] = ebuf[(j * 2)-k]; +#ifdef CAVEMAN_DEBUGGING + dprintf(DEBUGFD, "Before copying rhswords in right hand side step %u of ip6_scan(\"%s\", ipstruct); want %u has %u\n", j, st, wantrhswords, hasrhswords); +#endif + for (k = 0; k < (hasrhswords * 2); ++k) { +#ifdef CAVEMAN_DEBUGGING + dprintf(DEBUGFD, "Copying rhswords in right hand side step %u of ip6_scan(\"%s\", ipstruct); ebuf reached %u words\n", j, st, hasrhswords); + dprintf(DEBUGFD, "scanned %u, ebuf[%u] = %hhu, to ip->d[%u]\n", i, (j * 2)-1-k, ebuf[(j * 2)-1-k], 15-k); +#endif + ip->d[15-k] = ebuf[(j * 2)-1-k]; } } return len;