From fb269bcd784ca431340cf47e7b515f64688bd55e Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Wed, 19 Oct 2005 05:46:36 +0000 Subject: Fixes from Loic Le Loarer --- ChangeLog | 3 +++ common/smtppass.c | 16 +++++++--------- common/smtppass.h | 2 +- common/spio.c | 4 ++-- src/proxsmtpd.c | 12 ++++++++++-- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 54cbd5b..667bd7d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,9 @@ - Fix problem with binding to certain 'long' addresses - Support embedded NULLs in email data. - Fix problems with empty addresses in logs. + - Don't let exchange send it's strange binary data through the proxy + - Don't reject emails when server is overloaded or errors. + - Don't reject emails when starting the filter command fails. 1.2.1 [2005-04-15] - Fixed bug (introduced in 1.2) when 'Header' option is not present. diff --git a/common/smtppass.c b/common/smtppass.c index c9bc6d8..f8129ed 100644 --- a/common/smtppass.c +++ b/common/smtppass.c @@ -87,8 +87,8 @@ spthread_t; #define CRLF "\r\n" #define SMTP_TOOLONG "500 Line too long" CRLF -#define SMTP_STARTBUSY "554 Server Busy" CRLF -#define SMTP_STARTFAILED "554 Local Error" CRLF +#define SMTP_STARTBUSY "421 Server busy, too many connections" CRLF +#define SMTP_STARTFAILED "421 Local Error, cannot start thread" CRLF #define SMTP_DATAINTERMED "354 Start mail input; end with ." CRLF #define SMTP_FAILED "451 Local Error" CRLF #define SMTP_NOTSUPP "502 Command not implemented" CRLF @@ -1490,10 +1490,9 @@ static int make_header(spctx_t* ctx, const char* format_str, char* header) int sp_done_data(spctx_t* ctx) { FILE* file = 0; - int had_header = 0; int ret = 0; char *line; - char header[MAX_HEADER_LENGTH]; + char header[MAX_HEADER_LENGTH] = ""; size_t header_len, line_len; ssize_t rc; @@ -1539,12 +1538,12 @@ int sp_done_data(spctx_t* ctx) header_len = make_header(ctx, g_state.header, header); /* If we have to prepend the header, do it */ - if(header[0] && g_state.header_prepend) + if(header[0] != '\0' && g_state.header_prepend) { if(spio_write_data_raw(ctx, &(ctx->server), (unsigned char*)header, header_len) == -1 || spio_write_data_raw(ctx, &(ctx->server), (unsigned char*)CRLF, KL(CRLF)) == -1) RETURN(-1); - had_header = 1; + header[0] = '\0'; } /* Transfer actual file data */ @@ -1559,7 +1558,7 @@ int sp_done_data(spctx_t* ctx) if(strcmp(line, "." CRLF) == 0) strncpy(line, ". " CRLF, SP_LINE_LENGTH); - if(header[0] && !had_header) + if(header[0] != '\0') { /* * The first blank line we see means the headers are done. @@ -1570,8 +1569,7 @@ int sp_done_data(spctx_t* ctx) if(spio_write_data_raw(ctx, &(ctx->server), (unsigned char*)header, header_len) == -1 || spio_write_data_raw(ctx, &(ctx->server), (unsigned char*)CRLF, KL(CRLF)) == -1) RETURN(-1); - - had_header = 1; + header[0] = '\0'; } } diff --git a/common/smtppass.h b/common/smtppass.h index d10bed1..701ecb9 100644 --- a/common/smtppass.h +++ b/common/smtppass.h @@ -101,7 +101,7 @@ int spio_read_line(struct spctx* ctx, spio_t* io, int opts); * Guaranteed to accept all data or fail. */ int spio_write_data(struct spctx* ctx, spio_t* io, const char* data); int spio_write_dataf(struct spctx* ctx, spio_t* io, const char* fmt, ...); -int spio_write_data_raw(struct spctx* ctx, spio_t* io, unsigned char* buf, int len); +int spio_write_data_raw(struct spctx* ctx, spio_t* io, const unsigned char* buf, int len); /* Empty the given socket */ void spio_read_junk(struct spctx* sp, spio_t* io); diff --git a/common/spio.c b/common/spio.c index 5ee58ee..f2198c0 100644 --- a/common/spio.c +++ b/common/spio.c @@ -441,7 +441,7 @@ int read_raw(spctx_t* ctx, spio_t* io, int opts) { /* * K, basically the logic is that we're discarding - * data ond the data will be screwed up. So overwriting + * data and the data will be screwed up. So overwriting * some valid data in order to flush the line and * keep the buffering simple is a price we pay gladly :) */ @@ -544,7 +544,7 @@ int spio_write_dataf(struct spctx* ctx, spio_t* io, const char* fmt, ...) return spio_write_data(ctx, io, buf); } -int spio_write_data_raw(spctx_t* ctx, spio_t* io, unsigned char* buf, int len) +int spio_write_data_raw(spctx_t* ctx, spio_t* io, const unsigned char* buf, int len) { int r; diff --git a/src/proxsmtpd.c b/src/proxsmtpd.c index 6afc975..288e3d4 100644 --- a/src/proxsmtpd.c +++ b/src/proxsmtpd.c @@ -300,6 +300,14 @@ void cb_del_context(spctx_t* ctx) * IMPLEMENTATION */ +static void kill_myself() +{ + while (1) { + kill(getpid(), SIGKILL); + sleep(1); + } +} + static pid_t fork_filter(spctx_t* sp, int* infd, int* outfd, int* errfd) { pid_t pid; @@ -360,7 +368,7 @@ static pid_t fork_filter(spctx_t* sp, int* infd, int* outfd, int* errfd) if(r < 0) { sp_message(sp, LOG_ERR, "couldn't dup descriptors for filter command"); - _exit(1); + kill_myself(); } /* All the necessary environment vars */ @@ -371,7 +379,7 @@ static pid_t fork_filter(spctx_t* sp, int* infd, int* outfd, int* errfd) /* If that returned then there was an error */ sp_message(sp, LOG_ERR, "error executing the shell for filter command"); - _exit(1); + kill_myself(); break; }; -- cgit v1.2.3