aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmail-remote/qmail-remote.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2026-02-10 06:36:36 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2026-02-10 06:36:36 +0000
commitd0eda7c30bda6901b5bcc8f04ded157626042da8 (patch)
tree06d44a489253b997fa356bb684a972425543b063 /src/qmail-remote/qmail-remote.c
parent38976bbe295bb85305dc4de01c9688f835d35299 (diff)
downloadsmtpd-starttls-proxy-d0eda7c30bda6901b5bcc8f04ded157626042da8.tar.gz
Separate TLS stuff in preparation for wrapping
Diffstat (limited to 'src/qmail-remote/qmail-remote.c')
-rw-r--r--src/qmail-remote/qmail-remote.c66
1 files changed, 1 insertions, 65 deletions
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 <stdint.h>
#include <unistd.h>
#include <errno.h>
-#include <limits.h>
#include <skalibs/types.h>
-#include <skalibs/env.h>
#include <skalibs/exec.h>
#include <skalibs/fmtscan.h>
#include <skalibs/buffer.h>
@@ -25,74 +23,12 @@
# include <skalibs/prog.h>
#endif
-#include <s6-networking/config.h>
#include <smtpd-starttls-proxy/config.h>
#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 ;