diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2010-06-11 17:00:30 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2010-06-11 17:00:30 +0400 |
commit | c4aab3053d2839e6d3b99f8a542b0a4f54f2b856 (patch) | |
tree | 852f6c9afe65aadafad2176e7acd4e4ac4c07c81 | |
parent | 07082741605e8e048a129bec28695f57263de1e8 (diff) | |
download | rspamd-c4aab3053d2839e6d3b99f8a542b0a4f54f2b856.tar.gz rspamd-c4aab3053d2839e6d3b99f8a542b0a4f54f2b856.zip |
* Fix SMTP
-rw-r--r-- | src/smtp.c | 33 | ||||
-rw-r--r-- | src/smtp.h | 1 | ||||
-rw-r--r-- | src/smtp_proto.c | 8 |
3 files changed, 22 insertions, 20 deletions
diff --git a/src/smtp.c b/src/smtp.c index 3f366f7fd..709df3a7f 100644 --- a/src/smtp.c +++ b/src/smtp.c @@ -94,6 +94,9 @@ free_smtp_session (gpointer arg) } memory_pool_delete (session->pool); close (session->sock); + if (session->temp_name != NULL) { + unlink (session->temp_name); + } if (session->temp_fd != -1) { close (session->temp_fd); } @@ -294,11 +297,11 @@ smtp_send_upstream_message (struct smtp_session *session) rspamd_dispatcher_pause (session->dispatcher); rspamd_dispatcher_restore (session->upstream_dispatcher); + session->upstream_state = SMTP_STATE_IN_SENDFILE; + session->state = SMTP_STATE_WAIT_UPSTREAM; if (! rspamd_dispatcher_sendfile (session->upstream_dispatcher, session->temp_fd, session->temp_size)) { goto err; } - session->upstream_state = SMTP_STATE_IN_SENDFILE; - session->state = SMTP_STATE_WAIT_UPSTREAM; return TRUE; err: @@ -413,7 +416,7 @@ smtp_read_socket (f_str_t * in, void *arg) destroy_session (session->s); return FALSE; } - memcpy (session->data_end, p - sizeof (session->data_end) + 1, sizeof (session->data_end)); + memcpy (session->data_end, p - sizeof (session->data_end), sizeof (session->data_end)); session->data_idx = 5; } else if (session->data_idx + in->len < sizeof (session->data_end)){ @@ -439,22 +442,20 @@ smtp_read_socket (f_str_t * in, void *arg) session->data_idx = 5; } if (do_write) { + if (session->data_idx < in->len) { + if (in->len - session->data_idx != 0 && + write (session->temp_fd, in->begin, in->len - session->data_idx) != in->len - session->data_idx) { + msg_err ("cannot write to temp file: %s", strerror (errno)); + session->error = SMTP_ERROR_FILE; + session->state = SMTP_STATE_CRITICAL_ERROR; + rspamd_dispatcher_write (session->dispatcher, session->error, 0, FALSE, TRUE); + destroy_session (session->s); + return FALSE; + } + } if (memcmp (session->data_end, DATA_END_TRAILER, sizeof (session->data_end)) == 0) { return process_smtp_data (session); } - else { - if (session->data_idx < in->len) { - if (in->len - session->data_idx != 0 && - write (session->temp_fd, in->begin, in->len - session->data_idx) != in->len - session->data_idx) { - msg_err ("cannot write to temp file: %s", strerror (errno)); - session->error = SMTP_ERROR_FILE; - session->state = SMTP_STATE_CRITICAL_ERROR; - rspamd_dispatcher_write (session->dispatcher, session->error, 0, FALSE, TRUE); - destroy_session (session->s); - return FALSE; - } - } - } } break; case SMTP_STATE_WAIT_UPSTREAM: diff --git a/src/smtp.h b/src/smtp.h index 4208df4f2..598526a6b 100644 --- a/src/smtp.h +++ b/src/smtp.h @@ -65,6 +65,7 @@ struct smtp_session { struct in_addr client_addr; char *hostname; char *error; + char *temp_name; int sock; int upstream_sock; int temp_fd; diff --git a/src/smtp_proto.c b/src/smtp_proto.c index bef52b6b5..0eef4ec17 100644 --- a/src/smtp_proto.c +++ b/src/smtp_proto.c @@ -390,7 +390,7 @@ gboolean smtp_upstream_read_socket (f_str_t * in, void *arg) { struct smtp_session *session = arg; - char outbuf[BUFSIZ], *tmppattern; + char outbuf[BUFSIZ]; int r; switch (session->upstream_state) { @@ -551,9 +551,9 @@ smtp_upstream_read_socket (f_str_t * in, void *arg) } else if (r == 1) { r = strlen (session->cfg->temp_dir) + sizeof ("/rspamd-XXXXXX.tmp"); - tmppattern = alloca (r); - snprintf (tmppattern, r, "%s/rspamd-XXXXXX.tmp", session->cfg->temp_dir); - session->temp_fd = g_mkstemp_full (tmppattern, O_RDWR, S_IWUSR | S_IRUSR); + session->temp_name = memory_pool_alloc (session->pool, r); + snprintf (session->temp_name, r, "%s%crspamd-XXXXXX.tmp", session->cfg->temp_dir, G_DIR_SEPARATOR); + session->temp_fd = g_mkstemp_full (session->temp_name, O_RDWR, S_IWUSR | S_IRUSR); if (session->temp_fd == -1) { session->error = SMTP_ERROR_FILE; session->state = SMTP_STATE_CRITICAL_ERROR; |