Skip to content
Permalink
Browse files

Add qmail-qfilter-addtlsheader: record TLS params.

  • Loading branch information...
schmonz committed Nov 26, 2018
1 parent 60e3197 commit fe7e5fa08a675e82fa38629a2470d520008109aa
Showing with 117 additions and 1 deletion.
  1. +12 −1 Makefile
  2. +2 −0 TARGETS
  3. +56 −0 qmail-qfilter-addtlsheader.8
  4. +47 −0 qmail-qfilter-addtlsheader.c
@@ -5,7 +5,7 @@ SHELL=/bin/sh
default: it

acceptutils: \
reup authup checknotroot fixsmtpio
reup authup checknotroot fixsmtpio qmail-qfilter-addtlsheader

acceptutils_base64.o: \
compile99 acceptutils_base64.c acceptutils_base64.h
@@ -216,6 +216,17 @@ reup.o: \
compile99 reup.c acceptutils_unistd.h env.h fmt.h readwrite.h scan.h sgetopt.h str.h substdio.h wait.h
./compile99 reup.c

qmail-qfilter-addtlsheader: \
load qmail-qfilter-addtlsheader.o date822fmt.o now.o \
datetime.a substdio.a env.a error.a str.a fs.a
./load qmail-qfilter-addtlsheader date822fmt.o now.o \
datetime.a substdio.a env.a error.a str.a fs.a

qmail-qfilter-addtlsheader.o: \
compile99 qmail-qfilter-addtlsheader.c datetime.h date822fmt.h env.h \
now.h readwrite.h substdio.h
./compile99 qmail-qfilter-addtlsheader.c

rt.lib: \
compile load
( ( echo 'main() { ; }' > tryrt.c && ./compile tryrt.c && \
@@ -420,3 +420,5 @@ test_fixsmtpio_filter.o
test_fixsmtpio_glob.o
test_fixsmtpio_munge.o
test_fixsmtpio_proxy.o
qmail-qfilter-addtlsheader
qmail-qfilter-addtlsheader.o
@@ -0,0 +1,56 @@
.TH QMAIL-QFILTER-ADDTLSHEADER 8 2018-11-26
.SH NAME
qmail-qfilter-addtlsheader \- Add Received: header with TLS parameters
.SH SYNOPSIS
.B qmail-qfilter-addtlsheader
.SH DESCRIPTION
.B qmail-qfilter-addtlsheader
takes a message (headers and body) on standard input
and prints it to standard output.
If
.B UCSPITLS
connection details are available, it prepends a
.B Received:
header.
.PP
.B qmail-qfilter-addtlsheader
is intended to be invoked by
.BR qmail-qfilter .
It is typically used under
.B authup
(via
.BR qmail-ofmipfilter-queue )
or
.B fixsmtpio
(via
.BR qmail-smtpfilter-queue ).
.SH "ENVIRONMENT VARIABLES"
If both
.B SSL_CIPHER
and
.B SSL_PROTOCOL
are set,
.B qmail-qfilter-addtlsheader
will add its header.
.PP
If either
.B FIXSMTPIOTLS
or
.B AUTHUP_USER
is set, the header will mention
.BR fixsmtpio (8)
or
.BR authup (8),
respectively.
.SH "EXAMPLES"
See
.IR https://schmonz.com/qmail/acceptutils .
.SH "AUTHOR"
.B Amitai Schleier <schmonz-web-acceptutils@schmonz.com>
.SH "SEE ALSO"
.BR ucspi-tls(2),
.BR qmail-qfilter(1),
.BR authup(8),
.BR qmail-ofmipfilter-queue(8),
.BR fixsmtpio(8),
.BR qmail-smtpfilter-queue(8).
@@ -0,0 +1,47 @@
#include "datetime.h"
#include "date822fmt.h"
#include "env.h"
#include "now.h"
#include "readwrite.h"
#include "substdio.h"

static char datebuf[DATE822FMT];

static void set_now(char *datebuf) {
struct datetime dt;
datetime_tai(&dt,now());
date822fmt(datebuf,&dt);
}

static char inbuf[SUBSTDIO_INSIZE];
static substdio ssin = SUBSTDIO_FDBUF(read,0,inbuf,sizeof(inbuf));
static char outbuf[SUBSTDIO_OUTSIZE];
static substdio ssout = SUBSTDIO_FDBUF(write,1,outbuf,sizeof(outbuf));

static void out(char *s) { substdio_puts(&ssout,s); }

int main(void) {
char *ssl_cipher, *ssl_protocol, *authup_user;
int i;

if ((ssl_cipher = env_get("SSL_CIPHER"))
&& (ssl_protocol = env_get("SSL_PROTOCOL"))) {
out("Received: (ucspitls");
if (env_get("FIXSMTPIOTLS")) {
out(" acceptutils fixsmtpio");
} else if ((authup_user = env_get("AUTHUP_USER"))) {
out(" acceptutils authup ");
out(authup_user);
}
out( " "); out(ssl_protocol);
out( " "); out(ssl_cipher);
set_now(datebuf);
out("); "); out(datebuf);
substdio_flush(&ssout);
}

while ((i = substdio_get(&ssin,inbuf,sizeof(inbuf))) > 0)
substdio_putflush(&ssout,inbuf,i);

return 0;
}

0 comments on commit fe7e5fa

Please sign in to comment.
You can’t perform that action at this time.