diff options
| author | manuel <manuel@mausz.at> | 2020-11-20 11:46:57 +0100 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2020-11-20 11:46:57 +0100 |
| commit | 8415020b0391fdfb500f95ce6cf30e7628556e3f (patch) | |
| tree | 2b586eb61e6d8b3c011b1dbe3a8684d6cc47b081 | |
| parent | ddb3069bf287af8f0a634110b7bb95203f147b51 (diff) | |
| download | qmail-8415020b0391fdfb500f95ce6cf30e7628556e3f.tar.gz qmail-8415020b0391fdfb500f95ce6cf30e7628556e3f.tar.bz2 qmail-8415020b0391fdfb500f95ce6cf30e7628556e3f.zip | |
Add X-UD-Smtp-Session to qmail-inject
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | qmail-inject.c | 51 |
2 files changed, 53 insertions, 2 deletions
| @@ -1179,12 +1179,12 @@ qmail-inject: \ | |||
| 1179 | load qmail-inject.o headerbody.o hfield.o newfield.o quote.o now.o \ | 1179 | load qmail-inject.o headerbody.o hfield.o newfield.o quote.o now.o \ |
| 1180 | control.o date822fmt.o constmap.o qmail.o case.a fd.a wait.a open.a \ | 1180 | control.o date822fmt.o constmap.o qmail.o case.a fd.a wait.a open.a \ |
| 1181 | getln.a sig.a getopt.a datetime.a token822.o env.a stralloc.a alloc.a \ | 1181 | getln.a sig.a getopt.a datetime.a token822.o env.a stralloc.a alloc.a \ |
| 1182 | substdio.a error.a str.a fs.a auto_qmail.o | 1182 | substdio.a error.a str.a fs.a auto_qmail.o base64.o |
| 1183 | ./load qmail-inject headerbody.o hfield.o newfield.o \ | 1183 | ./load qmail-inject headerbody.o hfield.o newfield.o \ |
| 1184 | quote.o now.o control.o date822fmt.o constmap.o qmail.o \ | 1184 | quote.o now.o control.o date822fmt.o constmap.o qmail.o \ |
| 1185 | case.a fd.a wait.a open.a getln.a sig.a getopt.a datetime.a \ | 1185 | case.a fd.a wait.a open.a getln.a sig.a getopt.a datetime.a \ |
| 1186 | token822.o env.a stralloc.a alloc.a substdio.a error.a \ | 1186 | token822.o env.a stralloc.a alloc.a substdio.a error.a \ |
| 1187 | str.a fs.a auto_qmail.o | 1187 | str.a fs.a auto_qmail.o base64.o |
| 1188 | 1188 | ||
| 1189 | qmail-inject.0: \ | 1189 | qmail-inject.0: \ |
| 1190 | qmail-inject.8 | 1190 | 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 @@ | |||
| 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 | ||
| 523 | static 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 | |||
| 518 | int flagmft = 0; | 559 | int flagmft = 0; |
| 519 | stralloc mft = {0}; | 560 | stralloc mft = {0}; |
| 520 | struct constmap mapmft; | 561 | struct 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 | ||
