diff options
| author | Laurent Bercot <ska-skaware@skarnet.org> | 2026-02-10 11:27:11 +0000 |
|---|---|---|
| committer | Laurent Bercot <ska-skaware@skarnet.org> | 2026-02-10 11:27:11 +0000 |
| commit | 790058e1a89b979dc475be12952132dcc30e6ade (patch) | |
| tree | 09d37e877c9a38055e7272d551aba8a2f949a3fb /src/qmail-remote/qmailr_tcpto.c | |
| parent | ef5f89682886a7ab6cdb5b56d009d839a173b197 (diff) | |
| download | smtpd-starttls-proxy-790058e1a89b979dc475be12952132dcc30e6ade.tar.gz | |
Remove debug instructions; remove cdb wrapper for tcpto
We need to check for size == 0 before mmapping tcpto[6],
because 0 means "no match" for us but failure for mmap.
So the wrapper isn't good enough; toss it and call fstat
and mmap directly.
And with that, we should be good, more or less.
Diffstat (limited to 'src/qmail-remote/qmailr_tcpto.c')
| -rw-r--r-- | src/qmail-remote/qmailr_tcpto.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/qmail-remote/qmailr_tcpto.c b/src/qmail-remote/qmailr_tcpto.c index f90d1d0..3b7ffeb 100644 --- a/src/qmail-remote/qmailr_tcpto.c +++ b/src/qmail-remote/qmailr_tcpto.c @@ -1,15 +1,18 @@ /* ISC license. */ +#include <skalibs/bsdsnowflake.h> + #include <stdint.h> #include <string.h> #include <unistd.h> #include <stdlib.h> #include <errno.h> +#include <sys/mman.h> +#include <skalibs/stat.h> #include <skalibs/uint32.h> #include <skalibs/uint64.h> #include <skalibs/allreadwrite.h> -#include <skalibs/cdb.h> #include <skalibs/tai.h> #include <skalibs/djbunix.h> @@ -41,15 +44,19 @@ int qmailr_tcpto_match (char const *ip, int is6) uint32_t iplen = is6 ? 16 : 4 ; uint32_t width = iplen + 12 ; int r = 0 ; + char const *map ; char const *p ; - cdb c ; /* XXX: not a cdb, we're just using the mmap wrapper */ + struct stat st ; int fd = openc_read(file) ; if (fd == -1) return -1 ; if (fd_lock(fd, 0, 0) == -1) goto err ; - if (!cdb_init_fromfd(&c, fd)) goto err ; - if (c.size % width) goto errproto ; - p = bsearch(ip, c.map, c.size / width, width, is6 ? &qmailr_memcmp16 : &qmailr_memcmp4) ; + if (fstat(fd, &st) == -1) goto err ; + if (!st.st_size) goto end ; + if (st.st_size % width) goto errproto ; + map = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0) ; + if (map == MAP_FAILED) goto err ; + p = bsearch(ip, map, st.st_size / width, width, is6 ? &qmailr_memcmp16 : &qmailr_memcmp4) ; if (p) { if (p[iplen] >= 2) @@ -62,7 +69,7 @@ int qmailr_tcpto_match (char const *ip, int is6) r = tai_sec(&when) < ((60 + (getpid() & 31)) << 6) ; /* don't ask me, ask djb */ } } - cdb_free(&c) ; + end: fd_close(fd) ; return r ; |
