summaryrefslogtreecommitdiffstats
path: root/qmail-inject.c
diff options
context:
space:
mode:
Diffstat (limited to 'qmail-inject.c')
-rw-r--r--qmail-inject.c51
1 files changed, 51 insertions, 0 deletions
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 @@
1#include <sys/time.h>
2#include <sys/types.h>
1#include <unistd.h> 3#include <unistd.h>
4#include <stdint.h>
5#include <pwd.h>
2#include "sig.h" 6#include "sig.h"
3#include "substdio.h" 7#include "substdio.h"
4#include "stralloc.h" 8#include "stralloc.h"
@@ -23,6 +27,7 @@
23#include "auto_qmail.h" 27#include "auto_qmail.h"
24#include "newfield.h" 28#include "newfield.h"
25#include "constmap.h" 29#include "constmap.h"
30#include "base64.h"
26 31
27#define LINELEN 80 32#define LINELEN 80
28 33
@@ -515,6 +520,42 @@ void dodefaultreturnpath()
515 if (token822_unparse(&defaultreturnpath,&hfrewrite,LINELEN) != 1) die_nomem(); 520 if (token822_unparse(&defaultreturnpath,&hfrewrite,LINELEN) != 1) die_nomem();
516} 521}
517 522
523static const stralloc *client_get_session_id()
524{
525 static stralloc buf = {0}, base64_buf = {0};
526 const char *tmp;
527 struct timeval tv;
528 uint64_t timestamp;
529 unsigned int i;
530
531 if (base64_buf.s)
532 return &base64_buf;
533
534 if (!stralloc_ready(&buf, 24)) die_nomem();
535
536 /* add lowest 48 bits of the timestamp. this gives us a bit less than
537 9 years until it wraps */
538 gettimeofday(&tv, NULL);
539 timestamp = tv.tv_usec + (long long)tv.tv_sec * 1000ULL*1000ULL;
540 for (i = 0; i < 48; i += 8)
541 buf.s[buf.len++] = (timestamp >> i) & 0xff;
542
543 /* port */
544 buf.s[buf.len] = 0;
545 buf.s[buf.len+1] = 0;
546 buf.len += 2;
547
548 buf.s[buf.len] = 127;
549 buf.s[buf.len+1] = 0;
550 buf.s[buf.len+2] = 0;
551 buf.s[buf.len+3] = 1;
552 buf.len += 4;
553
554 if (b64encode(&buf, &base64_buf) < 0) die_nomem();
555 if (!stralloc_0(&base64_buf)) die_nomem();
556 return &base64_buf;
557}
558
518int flagmft = 0; 559int flagmft = 0;
519stralloc mft = {0}; 560stralloc mft = {0};
520struct constmap mapmft; 561struct constmap mapmft;
@@ -635,6 +676,16 @@ void finishheader()
635 finishmft(); 676 finishmft();
636 } 677 }
637 678
679 const uid_t uid = geteuid();
680 const struct passwd *pw = getpwuid(uid);
681 if (pw) {
682 puts("X-UD-Smtp-Session: ");
683 puts(pw->pw_name);
684 puts("@");
685 puts(client_get_session_id()->s);
686 puts("\n");
687 }
688
638 savedh_print(); 689 savedh_print();
639} 690}
640 691