From 8415020b0391fdfb500f95ce6cf30e7628556e3f Mon Sep 17 00:00:00 2001 From: manuel Date: Fri, 20 Nov 2020 11:46:57 +0100 Subject: Add X-UD-Smtp-Session to qmail-inject --- Makefile | 4 ++-- qmail-inject.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 9ffde73..595f47b 100644 --- a/Makefile +++ b/Makefile @@ -1179,12 +1179,12 @@ qmail-inject: \ load qmail-inject.o headerbody.o hfield.o newfield.o quote.o now.o \ control.o date822fmt.o constmap.o qmail.o case.a fd.a wait.a open.a \ getln.a sig.a getopt.a datetime.a token822.o env.a stralloc.a alloc.a \ -substdio.a error.a str.a fs.a auto_qmail.o +substdio.a error.a str.a fs.a auto_qmail.o base64.o ./load qmail-inject headerbody.o hfield.o newfield.o \ quote.o now.o control.o date822fmt.o constmap.o qmail.o \ case.a fd.a wait.a open.a getln.a sig.a getopt.a datetime.a \ token822.o env.a stralloc.a alloc.a substdio.a error.a \ - str.a fs.a auto_qmail.o + str.a fs.a auto_qmail.o base64.o qmail-inject.0: \ qmail-inject.8 diff --git a/qmail-inject.c b/qmail-inject.c index 43b53fe..59212d4 100644 --- a/qmail-inject.c +++ b/qmail-inject.c @@ -1,4 +1,8 @@ +#include +#include #include +#include +#include #include "sig.h" #include "substdio.h" #include "stralloc.h" @@ -23,6 +27,7 @@ #include "auto_qmail.h" #include "newfield.h" #include "constmap.h" +#include "base64.h" #define LINELEN 80 @@ -515,6 +520,42 @@ void dodefaultreturnpath() if (token822_unparse(&defaultreturnpath,&hfrewrite,LINELEN) != 1) die_nomem(); } +static const stralloc *client_get_session_id() +{ + static stralloc buf = {0}, base64_buf = {0}; + const char *tmp; + struct timeval tv; + uint64_t timestamp; + unsigned int i; + + if (base64_buf.s) + return &base64_buf; + + if (!stralloc_ready(&buf, 24)) die_nomem(); + + /* add lowest 48 bits of the timestamp. this gives us a bit less than + 9 years until it wraps */ + gettimeofday(&tv, NULL); + timestamp = tv.tv_usec + (long long)tv.tv_sec * 1000ULL*1000ULL; + for (i = 0; i < 48; i += 8) + buf.s[buf.len++] = (timestamp >> i) & 0xff; + + /* port */ + buf.s[buf.len] = 0; + buf.s[buf.len+1] = 0; + buf.len += 2; + + buf.s[buf.len] = 127; + buf.s[buf.len+1] = 0; + buf.s[buf.len+2] = 0; + buf.s[buf.len+3] = 1; + buf.len += 4; + + if (b64encode(&buf, &base64_buf) < 0) die_nomem(); + if (!stralloc_0(&base64_buf)) die_nomem(); + return &base64_buf; +} + int flagmft = 0; stralloc mft = {0}; struct constmap mapmft; @@ -635,6 +676,16 @@ void finishheader() finishmft(); } + const uid_t uid = geteuid(); + const struct passwd *pw = getpwuid(uid); + if (pw) { + puts("X-UD-Smtp-Session: "); + puts(pw->pw_name); + puts("@"); + puts(client_get_session_id()->s); + puts("\n"); + } + savedh_print(); } -- cgit v1.2.3