From d0eda7c30bda6901b5bcc8f04ded157626042da8 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Tue, 10 Feb 2026 06:36:36 +0000 Subject: Separate TLS stuff in preparation for wrapping --- src/qmail-remote/qmail-remote.c | 66 +---------------------------------------- 1 file changed, 1 insertion(+), 65 deletions(-) (limited to 'src/qmail-remote/qmail-remote.c') diff --git a/src/qmail-remote/qmail-remote.c b/src/qmail-remote/qmail-remote.c index 057f6f1..9c9bc15 100644 --- a/src/qmail-remote/qmail-remote.c +++ b/src/qmail-remote/qmail-remote.c @@ -5,10 +5,8 @@ #include #include #include -#include #include -#include #include #include #include @@ -25,74 +23,12 @@ # include #endif -#include #include #include "qmailr.h" #include "qmail-remote.h" #define dieusage() qmailr_perm("qmail-remote was invoked improperly") -static inline void exec_tls (int fdr, char const *fmtip, unsigned int timeoutconnect, unsigned int timeoutremote, qmailr_tls const *qtls, size_t helopos, size_t const *eaddrpos, unsigned int n, char const *storage) gccattr_noreturn ; -static inline void exec_tls (int fdr, char const *fmtip, unsigned int timeoutconnect, unsigned int timeoutremote, qmailr_tls const *qtls, size_t helopos, size_t const *eaddrpos, unsigned int n, char const *storage) -{ - int fdw = dup(fdr) ; - unsigned int m = 0 ; - char fmtr[UINT_FMT] ; - char fmtw[UINT_FMT] ; - char fmtt[UINT_FMT] ; - char fmtk[UINT_FMT] ; - char const *argv[20 + n] ; - LOLDEBUG("connected to %s, sending with TLS", fmtip) ; - - if (fdw == -1) qmailr_tempusys("duplicate file descriptor") ; - if (!env_mexec("TLS_UID", 0) || !env_mexec("TLS_GID", 0) - || !env_mexec(qtls->flagtadir ? "CADIR" : "CAFILE", storage + qtls->tapos)) dienomem() ; - if (qtls->flagclientcert) - { - if (!env_mexec("CERTFILE", storage + qtls->certpos) - || !env_mexec("KEYFILE", storage + qtls->keypos)) dienomem() ; - } - - { - int devnull = open_readb("/dev/null") ; - if (devnull >= 0) - { - if (devnull < 3) qmailr_temp("weird fd configuration") ; - fd_move(2, devnull) ; - } - } - - fmtr[uint_fmt(fmtr, (unsigned int)fdr)] = 0 ; - fmtw[uint_fmt(fmtw, (unsigned int)fdw)] = 0 ; - fmtt[uint_fmt(fmtt, timeoutremote)] = 0 ; - fmtk[uint_fmt(fmtk, timeoutconnect > UINT_MAX/1000 ? UINT_MAX : timeoutconnect * 1000)] = 0 ; - - argv[m++] = S6_NETWORKING_EXTBINPREFIX "s6-tlsc" ; - argv[m++] = "-Sjzv0" ; - argv[m++] = "-K" ; - argv[m++] = fmtk ; - argv[m++] = "-6" ; - argv[m++] = fmtr ; - argv[m++] = "-7" ; - argv[m++] = fmtw ; - argv[m++] = "--" ; - - argv[m++] = SMTPD_STARTTLS_PROXY_LIBEXECPREFIX "qmail-remote-io" ; - argv[m++] = "-t" ; - argv[m++] = fmtt ; - argv[m++] = "-6" ; - argv[m++] = fmtr ; - argv[m++] = "-7" ; - argv[m++] = fmtw ; - argv[m++] = "--" ; - argv[m++] = fmtip ; - argv[m++] = storage + helopos ; - for (unsigned int i = 0 ; i < n ; i++) argv[m++] = storage + eaddrpos[i] ; - argv[m++] = 0 ; - mexec(argv) ; - qmailr_tempusys("exec ", argv[0]) ; -} - static inline void exec_notls (int fd, char const *fmtip, unsigned int timeoutremote, size_t helopos, size_t const *eaddrpos, unsigned int n, char const *storage) gccattr_noreturn ; static inline void exec_notls (int fd, char const *fmtip, unsigned int timeoutremote, size_t helopos, size_t const *eaddrpos, unsigned int n, char const *storage) { @@ -185,7 +121,7 @@ static void attempt_smtp (int fd, char const *ip, int is6, unsigned int timeoutc qmailr_smtp_quit(&out, timeoutremote) ; qmailr_temp("Connected to ", fmtip, " but connection died") ; } - else if (r == 220) exec_tls(fd, fmtip, timeoutconnect, timeoutremote, qtls, helopos, eaddrpos, n, storage) ; + else if (r == 220) run_tls(fd, fmtip, timeoutconnect, timeoutremote, qtls, helopos, eaddrpos, n, storage) ; if (qtls->strictness) return ; } else if (qtls->strictness >= 2) return ; -- cgit v1.3.1