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 | |
| 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.
| -rw-r--r-- | src/qmail-remote/dns.c | 27 | ||||
| -rw-r--r-- | src/qmail-remote/qmail-remote.c | 21 | ||||
| -rw-r--r-- | src/qmail-remote/qmailr_tcpto.c | 19 |
3 files changed, 14 insertions, 53 deletions
diff --git a/src/qmail-remote/dns.c b/src/qmail-remote/dns.c index 9054b2d..3fb462b 100644 --- a/src/qmail-remote/dns.c +++ b/src/qmail-remote/dns.c @@ -13,7 +13,6 @@ #include <skalibs/ip46.h> #include <skalibs/random.h> #include <skalibs/prog.h> -#include <skalibs/lolstdio.h> #include <s6-dns/s6dns.h> #include <s6-dns/skadns.h> @@ -61,12 +60,10 @@ static unsigned int use_host_as_mx (skadns_t *a, char const *host, genalloc *mxi if (hostlen > 1 && storage->s[storage->len - 2] == '.') storage->s[--storage->len - 1] = 0 ; if (!skadns_send_g(a, &info.id4, &q, S6DNS_T_A, deadline, deadline)) qmailr_tempusys("send ", "A", " DNS query") ; - LOLDEBUG("sending A for %s, id %hu", host, info.id4) ; newreqs++ ; #ifdef SKALIBS_IPV6_ENABLED if (!skadns_send_g(a, &info.id6, &q, S6DNS_T_AAAA, deadline, deadline)) qmailr_tempusys("send ", "AAAA", " DNS query") ; - LOLDEBUG("sending AAAA for %s, id %hu", host, info.id6) ; newreqs++ ; #endif if (!genalloc_catb(mxipinfo, mxip, &info, 1)) dienomem() ; @@ -120,7 +117,6 @@ unsigned int dns_stuff (char const *host, char const *const *eaddr, unsigned int qmailr_tempusys("DNS-encode recipient domain") ; if (!skadns_send_g(&a, &cnames[i].id, &q, S6DNS_T_CNAME, &deadline, &deadline)) qmailr_tempusys("send ", "CNAME", " DNS query") ; - LOLDEBUG("sending CNAME for %s, id %hu", at+1, cnames[i].id) ; cnames[i].count = 1 ; pending++ ; } @@ -139,7 +135,6 @@ unsigned int dns_stuff (char const *host, char const *const *eaddr, unsigned int qmailr_tempusys("DNS-encode host domain") ; if (!skadns_send_g(&a, &mxid, &q, S6DNS_T_MX, &deadline, &deadline)) qmailr_tempusys("send ", "MX", " DNS query") ; - LOLDEBUG("sending MX for %s, id %hu", host, mxid) ; pending++ ; } else @@ -155,7 +150,6 @@ unsigned int dns_stuff (char const *host, char const *const *eaddr, unsigned int int r = iopause_g(&x, 1, &deadline) ; if (r == -1) qmailr_tempusys("iopause") ; if (!r) qmailr_tempsys("Timed out waiting for DNS") ; - LOLDEBUG("looping, pending = %u", pending) ; r = skadns_update(&a) ; if (r == -1) qmailr_tempusys("read DNS answers") ; ids = genalloc_s(uint16_t, &a.list) ; @@ -170,7 +164,6 @@ unsigned int dns_stuff (char const *host, char const *const *eaddr, unsigned int s6dns_message_header_t h ; genalloc mxes = GENALLOC_ZERO ; /* s6dns_message_rr_mx_t */ - LOLDEBUG("received id %hu (MX)", mxid) ; r = s6dns_message_parse(&h, packet, packetlen, &s6dns_message_parse_answer_mx, &mxes) ; if (r == -1) qmailr_tempsys("DNS packet parsing error") ; if (!r) @@ -202,12 +195,10 @@ unsigned int dns_stuff (char const *host, char const *const *eaddr, unsigned int s6dns_domain_encode(&mxs[i].exchange) ; if (!skadns_send_g(&a, &p->id4, &mxs[i].exchange, S6DNS_T_A, &deadline, &deadline)) qmailr_tempusys("send ", "A", " DNS query") ; - LOLDEBUG("sending A for %s, id %hu", storage->s + p->pos, p->id4) ; pending++ ; #ifdef SKALIBS_IPV6_ENABLED if (!skadns_send_g(&a, &p->id6, &mxs[i].exchange, S6DNS_T_AAAA, &deadline, &deadline)) qmailr_tempusys("send ", "AAAA", " DNS query") ; - LOLDEBUG("sending AAAA for %s, id %hu", storage->s + p->pos, p->id6) ; pending++ ; #endif } @@ -225,7 +216,6 @@ unsigned int dns_stuff (char const *host, char const *const *eaddr, unsigned int { s6dns_message_header_t h ; s6dns_dpag_t dlist = { .ds = GENALLOC_ZERO, .rtype = S6DNS_T_CNAME } ; - LOLDEBUG("received id %hu (CNAME)", ids[j]) ; r = s6dns_message_parse(&h, packet, packetlen, &s6dns_message_parse_answer_domain, &dlist) ; if (r == -1) qmailr_tempsys("DNS packet parsing error") ; if (!r) @@ -241,26 +231,13 @@ unsigned int dns_stuff (char const *host, char const *const *eaddr, unsigned int if (cnames[i].count++ >= 100) qmailr_perm("DNS CNAME loop") ; if (!skadns_send_g(&a, &cnames[i].id, domain, S6DNS_T_CNAME, &deadline, &deadline)) qmailr_tempusys("send ", "CNAME", " DNS query") ; -#ifdef DEBUG - { - char s[256] ; - s6dns_domain_t dom = *domain ; - s6dns_domain_decode(&dom) ; - s6dns_domain_tostring(s, 256, &dom) ; - LOLDEBUG("sending CNAME for %s, id %hu", s, cnames[i].id) ; - } -#endif pending++ ; if (!stralloc_ready(&cnames[i].sa, 256)) dienomem() ; s6dns_domain_decode(domain) ; cnames[i].sa.len = s6dns_domain_tostring(cnames[i].sa.s, 256, domain) ; genalloc_free(s6dns_domain_t, &dlist.ds) ; } - else - { - cnames[i].id = UINT16_MAX ; /* we have the canonical host in cnames[i].sa */ - LOLDEBUG("%.*s is not a CNAME", (int)cnames[i].sa.len, cnames[i].sa.s) ; - } + else cnames[i].id = UINT16_MAX ; /* we have the canonical host in cnames[i].sa */ continue ; } @@ -270,7 +247,6 @@ unsigned int dns_stuff (char const *host, char const *const *eaddr, unsigned int if (ids[j] == p->id4) { s6dns_message_header_t h ; - LOLDEBUG("received id %hu (A)", ids[j]) ; r = s6dns_message_parse(&h, packet, packetlen, &s6dns_message_parse_answer_a, &p->ip4) ; if (r == -1) qmailr_tempsys("DNS packet parsing error") ; if (!r) @@ -295,7 +271,6 @@ unsigned int dns_stuff (char const *host, char const *const *eaddr, unsigned int else if (ids[j] == p->id6) { s6dns_message_header_t h ; - LOLDEBUG("received id %hu (AAAA)", ids[j]) ; r = s6dns_message_parse(&h, packet, packetlen, &s6dns_message_parse_answer_aaaa, &p->ip6) ; if (r == -1) qmailr_tempsys("DNS packet parsing error") ; if (!r) diff --git a/src/qmail-remote/qmail-remote.c b/src/qmail-remote/qmail-remote.c index aa9df66..e993493 100644 --- a/src/qmail-remote/qmail-remote.c +++ b/src/qmail-remote/qmail-remote.c @@ -19,9 +19,6 @@ #include <skalibs/ip46.h> #include <skalibs/unix-timed.h> #include <skalibs/lolstdio.h> -#ifdef DEBUG -# include <skalibs/prog.h> -#endif #include <smtpd-starttls-proxy/config.h> #include "qmailr.h" @@ -37,7 +34,6 @@ static inline void exec_notls (int fd, char const *fmtip, unsigned int timeoutre char fmtt[UINT_FMT] ; char const *argv[10 + n] ; - LOLDEBUG("connected to %s, sending without TLS", fmtip) ; fmtfd[uint_fmt(fmtfd, (unsigned int)fd)] = 0 ; fmtt[uint_fmt(fmtt, timeoutremote)] = 0 ; argv[m++] = SMTPD_STARTTLS_PROXY_LIBEXECPREFIX "qmail-remote-io" ; @@ -141,12 +137,6 @@ int main (int argc, char const *const *argv) uint16_t port = 25 ; int r ; -#ifdef DEBUG - char progstr[18 + PID_FMT] = "qmail-remote: pid " ; - progstr[18 + pid_fmt(progstr + 18, getpid())] = 0 ; - PROG = progstr ; -#endif - if (argc-- < 4) dieusage() ; argv++ ; if (chdir(SMTPD_STARTTLS_PROXY_QMAIL_HOME) == -1) qmailr_tempusys("chdir to ", SMTPD_STARTTLS_PROXY_QMAIL_HOME) ; @@ -203,9 +193,6 @@ int main (int argc, char const *const *argv) stralloc_free(&ipme4) ; stralloc_free(&ipme6) ; mxs = genalloc_s(mxip, &mxipind) ; -#ifdef DEBUG - char fmtip[IP6_FMT] ; -#endif for (unsigned int i = 0 ; i < mxn ; i++) ntot += mxs[i].n4 + mxs[i].n6 ; if (!ntot) qmailr_perm("No suitable IP addresses for the MX") ; @@ -224,10 +211,6 @@ int main (int argc, char const *const *argv) if (qmailr_tcpto_match(ip, 1)) continue ; fd = socket_tcp6() ; if (fd == -1) qmailr_tempusys("create socket") ; -#ifdef DEBUG - fmtip[ip6_fmt(fmtip, ip)] = 0 ; - LOLDEBUG("connecting to %s", fmtip) ; -#endif tain_addsec_g(&deadline, timeoutconnect) ; if (!socket_deadlineconnstamp6_g(fd, ip, port, &deadline)) { @@ -250,10 +233,6 @@ int main (int argc, char const *const *argv) if (qmailr_tcpto_match(ip, 0)) continue ; fd = socket_tcp4() ; if (fd == -1) qmailr_tempusys("create socket") ; -#ifdef DEBUG - fmtip[ip4_fmt(fmtip, ip)] = 0 ; - LOLDEBUG("connecting to %s", fmtip) ; -#endif tain_addsec_g(&deadline, timeoutconnect) ; if (!socket_deadlineconnstamp4_g(fd, ip, port, &deadline)) { 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 ; |
