From e257b82099e56c80ec3166623221ff6222393e26 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Tue, 20 Jul 2004 23:38:37 +0000 Subject: - Added credits for patches - Trying to stop loop warnings --- AUTHORS | 6 +++++- ChangeLog | 6 ++++++ common/smtppass.c | 60 +++++++++++++++++++++++++++++++++++++++++++------------ src/clamsmtpd.c | 60 +++++++++++++++++++++++++++++++++++++++++++------------ 4 files changed, 105 insertions(+), 27 deletions(-) diff --git a/AUTHORS b/AUTHORS index d2e76d6..0e3be5b 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1 +1,5 @@ -nielsen@memberwebs.com +AUTHOR: +Nate Nielsen + +PATCHES: +Yamamoto Takao diff --git a/ChangeLog b/ChangeLog index b7569ad..6d21a60 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +0.3 + - Small log format changes + - When no port specified for out address, connect back to original IP + - Bug fixes to address parsing and formatting code + - Fixed problem with AV header not being added + - Send our own HELO command to prevent complaints about loops 0.2 - Initial public release diff --git a/common/smtppass.c b/common/smtppass.c index d3a9958..92dc5f5 100644 --- a/common/smtppass.c +++ b/common/smtppass.c @@ -77,16 +77,19 @@ clamsmtp_thread_t; #define KL(s) ((sizeof(s) - 1) / sizeof(char)) -#define SMTP_TOOLONG "500 Line too long\r\n" -#define SMTP_STARTBUSY "554 Server Busy\r\n" -#define SMTP_STARTFAILED "554 Local Error\r\n" -#define SMTP_DATAVIRUS "550 Virus Detected; Content Rejected\r\n" -#define SMTP_DATAINTERMED "354 Start mail input; end with .\r\n" -#define SMTP_FAILED "451 Local Error\r\n" -#define SMTP_NOTSUPP "502 Command not implemented\r\n" -#define SMTP_DATAVIRUSOK "250 Virus Detected; Discarded Email\r\n" - -#define SMTP_DATA "DATA\r\n" +#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_DATAVIRUS "550 Virus Detected; Content Rejected" 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 +#define SMTP_DATAVIRUSOK "250 Virus Detected; Discarded Email" CRLF +#define SMTP_OK "250 Ok" CRLF + +#define SMTP_DATA "DATA" CRLF #define SMTP_HELO "HELO " #define SMTP_DELIMS "\r\n\t :" @@ -97,9 +100,10 @@ clamsmtp_thread_t; #define DATA_CMD "DATA" #define RSET_CMD "RSET" -#define DATA_END_SIG "\r\n.\r\n" +#define DATA_END_SIG CRLF "." CRLF #define DATA_RSP "354" +#define OK_RSP "250" #define CLAM_OK "OK" #define CLAM_ERROR "ERROR" @@ -595,6 +599,7 @@ static int smtp_passthru(clamsmtp_context_t* ctx) char logline[LINE_LENGTH]; int processing = 0; int r, ret = 0; + int helo = 0; fd_set mask; ASSERT(ctx->clam != -1 && ctx->server != -1); @@ -660,6 +665,8 @@ static int smtp_passthru(clamsmtp_context_t* ctx) /* Reset log line */ logline[0] = 0; + + /* Command handled */ continue; } @@ -668,13 +675,14 @@ static int smtp_passthru(clamsmtp_context_t* ctx) * and other nuances aren't implemented here. In order * to keep things reliable we just disable it all. */ - if(is_first_word(ctx->line, EHLO_CMD, KL(EHLO_CMD))) + else if(is_first_word(ctx->line, EHLO_CMD, KL(EHLO_CMD))) { messagex(ctx, LOG_DEBUG, "ESMTP not implemented"); if(write_data(ctx, &(ctx->client), SMTP_NOTSUPP) == -1) RETURN(-1); + /* Command handled */ continue; } @@ -685,18 +693,25 @@ static int smtp_passthru(clamsmtp_context_t* ctx) */ else if(is_first_word(ctx->line, HELO_CMD, KL(HELO_CMD))) { - strlcat(ctx->line, SMTP_HELO, LINE_LENGTH); + messagex(ctx, LOG_DEBUG, "intercepting HELO"); + + strlcpy(ctx->line, SMTP_HELO, LINE_LENGTH); r = KL(SMTP_HELO); if(gethostname(ctx->line + r, LINE_LENGTH - r) == -1) strlcat(ctx->line, "clamsmtp", LINE_LENGTH); + strlcat(ctx->line, CRLF, LINE_LENGTH); ctx->line[LINE_LENGTH - 1] = 0; if(write_data(ctx, &(ctx->server), ctx->line) == -1) RETURN(-1); + /* The 250 response from the server also needs changing */ + helo = 1; + + /* Command handled */ continue; } @@ -731,6 +746,25 @@ static int smtp_passthru(clamsmtp_context_t* ctx) if(LINE_TOO_LONG(ctx)) messagex(ctx, LOG_WARNING, "SMTP response line too long. discarded extra"); + /* + * After we've seen a HELO we need to edit the response that + * gets sent back to the client to prevent the server from + * thinking we're in a wierd loop. + */ + if(helo) + { + helo = 0; + + if(is_first_word(ctx->line, OK_RSP, KL(OK_RSP))) + { + if(write_data(ctx, &(ctx->client), SMTP_OK) == -1) + RETURN(-1); + + /* Command handled */ + continue; + } + } + if(write_data(ctx, &(ctx->client), ctx->line) == -1) RETURN(-1); diff --git a/src/clamsmtpd.c b/src/clamsmtpd.c index d3a9958..92dc5f5 100644 --- a/src/clamsmtpd.c +++ b/src/clamsmtpd.c @@ -77,16 +77,19 @@ clamsmtp_thread_t; #define KL(s) ((sizeof(s) - 1) / sizeof(char)) -#define SMTP_TOOLONG "500 Line too long\r\n" -#define SMTP_STARTBUSY "554 Server Busy\r\n" -#define SMTP_STARTFAILED "554 Local Error\r\n" -#define SMTP_DATAVIRUS "550 Virus Detected; Content Rejected\r\n" -#define SMTP_DATAINTERMED "354 Start mail input; end with .\r\n" -#define SMTP_FAILED "451 Local Error\r\n" -#define SMTP_NOTSUPP "502 Command not implemented\r\n" -#define SMTP_DATAVIRUSOK "250 Virus Detected; Discarded Email\r\n" - -#define SMTP_DATA "DATA\r\n" +#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_DATAVIRUS "550 Virus Detected; Content Rejected" 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 +#define SMTP_DATAVIRUSOK "250 Virus Detected; Discarded Email" CRLF +#define SMTP_OK "250 Ok" CRLF + +#define SMTP_DATA "DATA" CRLF #define SMTP_HELO "HELO " #define SMTP_DELIMS "\r\n\t :" @@ -97,9 +100,10 @@ clamsmtp_thread_t; #define DATA_CMD "DATA" #define RSET_CMD "RSET" -#define DATA_END_SIG "\r\n.\r\n" +#define DATA_END_SIG CRLF "." CRLF #define DATA_RSP "354" +#define OK_RSP "250" #define CLAM_OK "OK" #define CLAM_ERROR "ERROR" @@ -595,6 +599,7 @@ static int smtp_passthru(clamsmtp_context_t* ctx) char logline[LINE_LENGTH]; int processing = 0; int r, ret = 0; + int helo = 0; fd_set mask; ASSERT(ctx->clam != -1 && ctx->server != -1); @@ -660,6 +665,8 @@ static int smtp_passthru(clamsmtp_context_t* ctx) /* Reset log line */ logline[0] = 0; + + /* Command handled */ continue; } @@ -668,13 +675,14 @@ static int smtp_passthru(clamsmtp_context_t* ctx) * and other nuances aren't implemented here. In order * to keep things reliable we just disable it all. */ - if(is_first_word(ctx->line, EHLO_CMD, KL(EHLO_CMD))) + else if(is_first_word(ctx->line, EHLO_CMD, KL(EHLO_CMD))) { messagex(ctx, LOG_DEBUG, "ESMTP not implemented"); if(write_data(ctx, &(ctx->client), SMTP_NOTSUPP) == -1) RETURN(-1); + /* Command handled */ continue; } @@ -685,18 +693,25 @@ static int smtp_passthru(clamsmtp_context_t* ctx) */ else if(is_first_word(ctx->line, HELO_CMD, KL(HELO_CMD))) { - strlcat(ctx->line, SMTP_HELO, LINE_LENGTH); + messagex(ctx, LOG_DEBUG, "intercepting HELO"); + + strlcpy(ctx->line, SMTP_HELO, LINE_LENGTH); r = KL(SMTP_HELO); if(gethostname(ctx->line + r, LINE_LENGTH - r) == -1) strlcat(ctx->line, "clamsmtp", LINE_LENGTH); + strlcat(ctx->line, CRLF, LINE_LENGTH); ctx->line[LINE_LENGTH - 1] = 0; if(write_data(ctx, &(ctx->server), ctx->line) == -1) RETURN(-1); + /* The 250 response from the server also needs changing */ + helo = 1; + + /* Command handled */ continue; } @@ -731,6 +746,25 @@ static int smtp_passthru(clamsmtp_context_t* ctx) if(LINE_TOO_LONG(ctx)) messagex(ctx, LOG_WARNING, "SMTP response line too long. discarded extra"); + /* + * After we've seen a HELO we need to edit the response that + * gets sent back to the client to prevent the server from + * thinking we're in a wierd loop. + */ + if(helo) + { + helo = 0; + + if(is_first_word(ctx->line, OK_RSP, KL(OK_RSP))) + { + if(write_data(ctx, &(ctx->client), SMTP_OK) == -1) + RETURN(-1); + + /* Command handled */ + continue; + } + } + if(write_data(ctx, &(ctx->client), ctx->line) == -1) RETURN(-1); -- cgit v1.2.3