remove needless dead.letter function (at least on embedded devices) backport debian fixes (slightly modified) compile tested. Please apply to upstream - thank you! Signed-off-by: Dirk Brenken <dirk@brenken.org>lilik-openwrt-22.03
@ -0,0 +1,94 @@ | |||
--- a/ssmtp.c | |||
+++ b/ssmtp.c | |||
@@ -138,71 +138,7 @@ int smtp_read_all(int fd, char *response | |||
int smtp_okay(int fd, char *response); | |||
/* | |||
-dead_letter() -- Save stdin to ~/dead.letter if possible | |||
-*/ | |||
-void dead_letter(void) | |||
-{ | |||
- char *path; | |||
- char buf[(BUF_SZ + 1)]; | |||
- struct passwd *pw; | |||
- uid_t uid; | |||
- FILE *fp; | |||
- | |||
- uid = getuid(); | |||
- pw = getpwuid(uid); | |||
- | |||
- if(isatty(fileno(stdin))) { | |||
- if(log_level > 0) { | |||
- log_event(LOG_ERR, | |||
- "stdin is a TTY - not saving to %s/dead.letter", pw->pw_dir); | |||
- } | |||
- return; | |||
- } | |||
- | |||
- if(pw == (struct passwd *)NULL) { | |||
- /* Far to early to save things */ | |||
- if(log_level > 0) { | |||
- log_event(LOG_ERR, "No sender failing horribly!"); | |||
- } | |||
- return; | |||
- } | |||
- | |||
-#define DEAD_LETTER "/dead.letter" | |||
- path = malloc (strlen (pw->pw_dir) + sizeof (DEAD_LETTER)); | |||
- if (!path) { | |||
- /* Can't use die() here since dead_letter() is called from die() */ | |||
- exit(1); | |||
- } | |||
- memcpy (path, pw->pw_dir, strlen (pw->pw_dir)); | |||
- memcpy (path + strlen (pw->pw_dir), DEAD_LETTER, sizeof (DEAD_LETTER)); | |||
- | |||
- if((fp = fopen(path, "a")) == (FILE *)NULL) { | |||
- /* Perhaps the person doesn't have a homedir... */ | |||
- if(log_level > 0) { | |||
- log_event(LOG_ERR, "Can't open %s failing horribly!", path); | |||
- } | |||
- free(path); | |||
- return; | |||
- } | |||
- | |||
- /* We start on a new line with a blank line separating messages */ | |||
- (void)fprintf(fp, "\n\n"); | |||
- | |||
- while(fgets(buf, sizeof(buf), stdin)) { | |||
- (void)fputs(buf, fp); | |||
- } | |||
- | |||
- if(fclose(fp) == -1) { | |||
- if(log_level > 0) { | |||
- log_event(LOG_ERR, | |||
- "Can't close %s/dead.letter, possibly truncated", pw->pw_dir); | |||
- } | |||
- } | |||
- free(path); | |||
-} | |||
- | |||
-/* | |||
-die() -- Write error message, dead.letter and exit | |||
+die() -- Write error message and exit | |||
*/ | |||
void die(char *format, ...) | |||
{ | |||
@@ -216,9 +152,6 @@ void die(char *format, ...) | |||
(void)fprintf(stderr, "%s: %s\n", prog, buf); | |||
log_event(LOG_ERR, "%s", buf); | |||
- /* Send message to dead.letter */ | |||
- (void)dead_letter(); | |||
- | |||
exit(1); | |||
} | |||
@@ -1640,7 +1573,7 @@ int ssmtp(char *argv[]) | |||
sleep(1); | |||
/* don't hang forever when reading from stdin */ | |||
if (++timeout >= MEDWAIT) { | |||
- log_event(LOG_ERR, "killed: timeout on stdin while reading body -- message saved to dead.letter."); | |||
+ log_event(LOG_ERR, "killed: timeout on stdin while reading body."); | |||
die("Timeout on stdin while reading body"); | |||
} | |||
continue; |
@ -0,0 +1,21 @@ | |||
--- a/ssmtp.c | |||
+++ b/ssmtp.c | |||
@@ -1338,6 +1338,7 @@ ssmtp() -- send the message (exactly one | |||
int ssmtp(char *argv[]) | |||
{ | |||
char b[(BUF_SZ + 2)], *buf = b+1, *p, *q; | |||
+ char *remote_addr; | |||
#ifdef MD5AUTH | |||
char challenge[(BUF_SZ + 1)]; | |||
#endif | |||
@@ -1541,6 +1542,10 @@ int ssmtp(char *argv[]) | |||
outbytes += smtp_write(sock, "From: %s", from); | |||
} | |||
+ if(remote_addr=getenv("REMOTE_ADDR")) { | |||
+ outbytes += smtp_write(sock, "X-Originating-IP: %s", remote_addr); | |||
+ } | |||
+ | |||
if(have_date == False) { | |||
outbytes += smtp_write(sock, "Date: %s", arpadate); | |||
} |
@ -0,0 +1,18 @@ | |||
--- a/ssmtp.c | |||
+++ b/ssmtp.c | |||
@@ -1591,12 +1591,12 @@ int ssmtp(char *argv[]) | |||
outbytes += smtp_write(sock, "%s", leadingdot ? b : buf); | |||
} else { | |||
if (log_level > 0) { | |||
- log_event(LOG_INFO, "Sent a very long line in chunks"); | |||
+ log_event(LOG_INFO, "Sending a partial line"); | |||
} | |||
if (leadingdot) { | |||
- outbytes += fd_puts(sock, b, sizeof(b)); | |||
+ outbytes += fd_puts(sock, b, strlen(b)); | |||
} else { | |||
- outbytes += fd_puts(sock, buf, bufsize); | |||
+ outbytes += fd_puts(sock, buf, strlen(buf)); | |||
} | |||
} | |||
(void)alarm((unsigned) MEDWAIT); |
@ -0,0 +1,92 @@ | |||
--- a/ssmtp.c | |||
+++ b/ssmtp.c | |||
@@ -282,6 +282,7 @@ standardise() -- Trim off '\n's and doub | |||
*/ | |||
bool_t standardise(char *str, bool_t *linestart) | |||
{ | |||
+ size_t sl; | |||
char *p; | |||
bool_t leadingdot = False; | |||
@@ -297,6 +298,12 @@ bool_t standardise(char *str, bool_t *li | |||
if((p = strchr(str, '\n'))) { | |||
*p = '\0'; | |||
*linestart = True; | |||
+ | |||
+ /* If the line ended in "\r\n", then drop the '\r' too */ | |||
+ sl = strlen(str); | |||
+ if(sl >= 1 && str[sl - 1] == '\r') { | |||
+ str[sl - 1] = '\0'; | |||
+ } | |||
} | |||
return(leadingdot); | |||
} | |||
@@ -690,6 +697,14 @@ void header_parse(FILE *stream) | |||
} | |||
len++; | |||
+ if(l == '\r' && c == '\n') { | |||
+ /* Properly handle input that already has "\r\n" | |||
+ line endings; see https://bugs.debian.org/584162 */ | |||
+ l = (len >= 2 ? *(q - 2) : '\n'); | |||
+ q--; | |||
+ len--; | |||
+ } | |||
+ | |||
if(l == '\n') { | |||
switch(c) { | |||
case ' ': | |||
@@ -712,8 +727,9 @@ void header_parse(FILE *stream) | |||
if((q = strrchr(p, '\n'))) { | |||
*q = '\0'; | |||
} | |||
- header_save(p); | |||
- | |||
+ if(len > 0) { | |||
+ header_save(p); | |||
+ } | |||
q = p; | |||
len = 0; | |||
} | |||
@@ -722,35 +738,12 @@ void header_parse(FILE *stream) | |||
l = c; | |||
} | |||
- if(in_header) { | |||
- if(l == '\n') { | |||
- switch(c) { | |||
- case ' ': | |||
- case '\t': | |||
- /* Must insert '\r' before '\n's embedded in header | |||
- fields otherwise qmail won't accept our mail | |||
- because a bare '\n' violates some RFC */ | |||
- | |||
- *(q - 1) = '\r'; /* Replace previous \n with \r */ | |||
- *q++ = '\n'; /* Insert \n */ | |||
- len++; | |||
- | |||
- break; | |||
- | |||
- case '\n': | |||
- in_header = False; | |||
- | |||
- default: | |||
- *q = '\0'; | |||
- if((q = strrchr(p, '\n'))) { | |||
- *q = '\0'; | |||
- } | |||
- header_save(p); | |||
- | |||
- q = p; | |||
- len = 0; | |||
- } | |||
- } | |||
+ if(in_header && l == '\n') { | |||
+ /* Got EOF while reading the header */ | |||
+ if((q = strrchr(p, '\n'))) { | |||
+ *q = '\0'; | |||
+ } | |||
+ header_save(p); | |||
} | |||
(void)free(p); | |||
} |