From d677b2f22abb3eb268e5cb15e4710ff5063049fe Mon Sep 17 00:00:00 2001 From: Philip Hazel Date: Fri, 22 Jun 2007 14:38:58 +0000 Subject: [PATCH] Added $max_received_linelength. --- doc/doc-txt/ChangeLog | 4 ++- doc/doc-txt/NewStuff | 6 ++++- src/exim_monitor/em_globals.c | 3 ++- src/src/expand.c | 3 ++- src/src/globals.c | 3 ++- src/src/globals.h | 3 ++- src/src/receive.c | 50 ++++++++++++++++++++++++++++++----- src/src/spool_in.c | 5 +++- src/src/spool_out.c | 3 ++- test/scripts/0000-Basic/0542 | 4 ++- test/stdout/0035 | 7 +++++ test/stdout/0245 | 1 + test/stdout/0250 | 3 +++ test/stdout/0254 | 3 +++ test/stdout/0311 | 2 ++ test/stdout/0338 | 1 + test/stdout/0377 | 1 + test/stdout/0378 | 1 + test/stdout/0379 | 1 + test/stdout/0389 | 1 + test/stdout/0488 | 1 + test/stdout/0490 | 1 + test/stdout/0514 | 1 + test/stdout/0542 | 6 +++-- test/stdout/3415 | 5 ++++ 25 files changed, 101 insertions(+), 18 deletions(-) diff --git a/doc/doc-txt/ChangeLog b/doc/doc-txt/ChangeLog index b8b1e9609..7c7409430 100644 --- a/doc/doc-txt/ChangeLog +++ b/doc/doc-txt/ChangeLog @@ -1,4 +1,4 @@ -$Cambridge: exim/doc/doc-txt/ChangeLog,v 1.516 2007/06/20 14:13:39 ph10 Exp $ +$Cambridge: exim/doc/doc-txt/ChangeLog,v 1.517 2007/06/22 14:38:58 ph10 Exp $ Change log file for Exim from version 4.21 ------------------------------------------- @@ -67,6 +67,8 @@ PH/09 Tidied the code for creating ratelimiting keys, creating them explicitly PH/10 Added the /noupdate option to the ratelimit ACL condition. +PH/11 Added $max_received_linelength. + Exim version 4.67 ----------------- diff --git a/doc/doc-txt/NewStuff b/doc/doc-txt/NewStuff index f6cbf54c3..547534ad6 100644 --- a/doc/doc-txt/NewStuff +++ b/doc/doc-txt/NewStuff @@ -1,4 +1,4 @@ -$Cambridge: exim/doc/doc-txt/NewStuff,v 1.151 2007/06/20 14:13:39 ph10 Exp $ +$Cambridge: exim/doc/doc-txt/NewStuff,v 1.152 2007/06/22 14:38:58 ph10 Exp $ New Features in Exim -------------------- @@ -74,6 +74,10 @@ Version 4.68 accept + 6. The variable $max_received_linelength contains the number of bytes in the + longest line that was received as part of the message, not counting the + line termination character(s). + Version 4.67 ------------ diff --git a/src/exim_monitor/em_globals.c b/src/exim_monitor/em_globals.c index ffd3b1973..f71014997 100644 --- a/src/exim_monitor/em_globals.c +++ b/src/exim_monitor/em_globals.c @@ -1,4 +1,4 @@ -/* $Cambridge: exim/src/exim_monitor/em_globals.c,v 1.11 2007/01/08 10:50:17 ph10 Exp $ */ +/* $Cambridge: exim/src/exim_monitor/em_globals.c,v 1.12 2007/06/22 14:38:58 ph10 Exp $ */ /************************************************* * Exim Monitor * @@ -163,6 +163,7 @@ BOOL log_timezone = FALSE; uschar *spam_score_int = NULL; #endif +int max_received_linelength= 0; int message_age = 0; uschar *message_id; uschar *message_id_external; diff --git a/src/src/expand.c b/src/src/expand.c index abff94996..e56f86678 100644 --- a/src/src/expand.c +++ b/src/src/expand.c @@ -1,4 +1,4 @@ -/* $Cambridge: exim/src/src/expand.c,v 1.86 2007/06/14 14:18:19 ph10 Exp $ */ +/* $Cambridge: exim/src/src/expand.c,v 1.87 2007/06/22 14:38:58 ph10 Exp $ */ /************************************************* * Exim - an Internet mail transport agent * @@ -453,6 +453,7 @@ static var_entry var_table[] = { #ifdef WITH_CONTENT_SCAN { "malware_name", vtype_stringptr, &malware_name }, #endif + { "max_received_linelength", vtype_int, &max_received_linelength }, { "message_age", vtype_int, &message_age }, { "message_body", vtype_msgbody, &message_body }, { "message_body_end", vtype_msgbody_end, &message_body_end }, diff --git a/src/src/globals.c b/src/src/globals.c index 7d34c6699..f12e8eb34 100644 --- a/src/src/globals.c +++ b/src/src/globals.c @@ -1,4 +1,4 @@ -/* $Cambridge: exim/src/src/globals.c,v 1.74 2007/06/18 13:57:50 ph10 Exp $ */ +/* $Cambridge: exim/src/src/globals.c,v 1.75 2007/06/22 14:38:58 ph10 Exp $ */ /************************************************* * Exim - an Internet mail transport agent * @@ -743,6 +743,7 @@ uschar *mailstore_basename = NULL; #ifdef WITH_CONTENT_SCAN uschar *malware_name = NULL; /* Virus Name */ #endif +int max_received_linelength= 0; int max_username_length = 0; int message_age = 0; uschar *message_body = NULL; diff --git a/src/src/globals.h b/src/src/globals.h index ce43922c0..f80e88b7b 100644 --- a/src/src/globals.h +++ b/src/src/globals.h @@ -1,4 +1,4 @@ -/* $Cambridge: exim/src/src/globals.h,v 1.54 2007/06/14 14:18:19 ph10 Exp $ */ +/* $Cambridge: exim/src/src/globals.h,v 1.55 2007/06/22 14:38:58 ph10 Exp $ */ /************************************************* * Exim - an Internet mail transport agent * @@ -432,6 +432,7 @@ extern uschar *mailstore_basename; /* For mailstore deliveries */ #ifdef WITH_CONTENT_SCAN extern uschar *malware_name; /* Name of virus or malware ("W32/Klez-H") */ #endif +extern int max_received_linelength;/* What it says */ extern int max_username_length; /* For systems with broken getpwnam() */ extern int message_age; /* In seconds */ extern uschar *message_body; /* Start of message body for filter */ diff --git a/src/src/receive.c b/src/src/receive.c index e4c82d2fa..ee95cc981 100644 --- a/src/src/receive.c +++ b/src/src/receive.c @@ -1,4 +1,4 @@ -/* $Cambridge: exim/src/src/receive.c,v 1.37 2007/04/16 10:31:58 ph10 Exp $ */ +/* $Cambridge: exim/src/src/receive.c,v 1.38 2007/06/22 14:38:58 ph10 Exp $ */ /************************************************* * Exim - an Internet mail transport agent * @@ -564,6 +564,7 @@ read_message_data(FILE *fout) { int ch_state; register int ch; +register int linelength = 0; /* Handle the case when only EOF terminates the message */ @@ -576,6 +577,9 @@ if (!dot_ends) if (ch == 0) body_zerocount++; if (last_ch == '\r' && ch != '\n') { + if (linelength > max_received_linelength) + max_received_linelength = linelength; + linelength = 0; if (fputc('\n', fout) == EOF) return END_WERROR; message_size++; body_linecount++; @@ -583,12 +587,21 @@ if (!dot_ends) if (ch == '\r') continue; if (fputc(ch, fout) == EOF) return END_WERROR; - if (ch == '\n') body_linecount++; + if (ch == '\n') + { + if (linelength > max_received_linelength) + max_received_linelength = linelength; + linelength = 0; + body_linecount++; + } + else linelength++; if (++message_size > thismessage_size_limit) return END_SIZE; } if (last_ch != '\n') { + if (linelength > max_received_linelength) + max_received_linelength = linelength; if (fputc('\n', fout) == EOF) return END_WERROR; message_size++; body_linecount++; @@ -608,25 +621,37 @@ while ((ch = (RECEIVE_GETC)()) != EOF) { case 0: /* Normal state (previous char written) */ if (ch == '\n') - { body_linecount++; ch_state = 1; } + { + body_linecount++; + if (linelength > max_received_linelength) + max_received_linelength = linelength; + linelength = -1; + ch_state = 1; + } else if (ch == '\r') { ch_state = 2; continue; } break; case 1: /* After written "\n" */ if (ch == '.') { ch_state = 3; continue; } - if (ch != '\n') ch_state = 0; + if (ch != '\n') ch_state = 0; else linelength = -1; break; case 2: body_linecount++; /* After unwritten "\r" */ + if (linelength > max_received_linelength) + max_received_linelength = linelength; if (ch == '\n') - { ch_state = 1; } + { + ch_state = 1; + linelength = -1; + } else { if (message_size++, fputc('\n', fout) == EOF) return END_WERROR; if (ch == '\r') continue; ch_state = 0; + linelength = 0; } break; @@ -634,6 +659,7 @@ while ((ch = (RECEIVE_GETC)()) != EOF) if (ch == '\n') return END_DOT; if (ch == '\r') { ch_state = 4; continue; } message_size++; + linelength++; if (fputc('.', fout) == EOF) return END_WERROR; ch_state = 0; break; @@ -648,6 +674,7 @@ while ((ch = (RECEIVE_GETC)()) != EOF) break; } + linelength++; if (fputc(ch, fout) == EOF) return END_WERROR; if (++message_size > thismessage_size_limit) return END_SIZE; } @@ -1263,6 +1290,7 @@ int header_size = 256; int start, end, domain, size, sptr; int id_resolution; int had_zero = 0; +int prevlines_length = 0; register int ptr = 0; @@ -1343,13 +1371,14 @@ data_fd = -1; spool_name[0] = 0; message_size = 0; warning_count = 0; -received_count = 1; /* For the one we will add */ +received_count = 1; /* For the one we will add */ if (thismessage_size_limit <= 0) thismessage_size_limit = INT_MAX; /* While reading the message, the following counts are computed. */ -message_linecount = body_linecount = body_zerocount = 0; +message_linecount = body_linecount = body_zerocount = + max_received_linelength = 0; #ifdef EXPERIMENTAL_DOMAINKEYS /* Call into DK to set up the context. Check if DK is to be run are carried out @@ -1585,6 +1614,12 @@ for (;;) receive_linecount++; message_linecount++; + /* Keep track of maximum line length */ + + if (ptr - prevlines_length > max_received_linelength) + max_received_linelength = ptr - prevlines_length; + prevlines_length = ptr + 1; + /* Now put in the terminating newline. There is always space for at least two more characters. */ @@ -1813,6 +1848,7 @@ for (;;) next->text = store_get(header_size); ptr = 0; had_zero = 0; + prevlines_length = 0; } /* Continue, starting to read the next header */ /* At this point, we have read all the headers into a data structure in main diff --git a/src/src/spool_in.c b/src/src/spool_in.c index b4506c8af..a0fdcf96c 100644 --- a/src/src/spool_in.c +++ b/src/src/spool_in.c @@ -1,4 +1,4 @@ -/* $Cambridge: exim/src/src/spool_in.c,v 1.19 2007/01/08 10:50:18 ph10 Exp $ */ +/* $Cambridge: exim/src/src/spool_in.c,v 1.20 2007/06/22 14:38:58 ph10 Exp $ */ /************************************************* * Exim - an Internet mail transport agent * @@ -255,6 +255,7 @@ interface_address = NULL; interface_port = 0; local_error_message = FALSE; local_scan_data = NULL; +max_received_linelength = 0; message_linecount = 0; received_protocol = NULL; received_count = 0; @@ -518,6 +519,8 @@ for (;;) case 'm': if (Ustrcmp(p, "anual_thaw") == 0) deliver_manual_thaw = TRUE; + else if (Ustrncmp(p, "ax_received_linelength", 22) == 0) + max_received_linelength = Uatoi(big_buffer + 24); break; case 'N': diff --git a/src/src/spool_out.c b/src/src/spool_out.c index 724b00e44..b2119f834 100644 --- a/src/src/spool_out.c +++ b/src/src/spool_out.c @@ -1,4 +1,4 @@ -/* $Cambridge: exim/src/src/spool_out.c,v 1.13 2007/01/22 16:29:54 ph10 Exp $ */ +/* $Cambridge: exim/src/src/spool_out.c,v 1.14 2007/06/22 14:38:58 ph10 Exp $ */ /************************************************* * Exim - an Internet mail transport agent * @@ -198,6 +198,7 @@ tree_walk(acl_var_m, &acl_var_write, f); /* Now any other data that needs to be remembered. */ fprintf(f, "-body_linecount %d\n", body_linecount); +fprintf(f, "-max_received_linelength %d\n", max_received_linelength); if (body_zerocount > 0) fprintf(f, "-body_zerocount %d\n", body_zerocount); diff --git a/test/scripts/0000-Basic/0542 b/test/scripts/0000-Basic/0542 index da2b9e768..92f1f607e 100644 --- a/test/scripts/0000-Basic/0542 +++ b/test/scripts/0000-Basic/0542 @@ -4,7 +4,7 @@ From: Himself To: Yourself Subject: The subject is not the object -This is the body of the message. +This is the body of the message. Make the line longer than any header. **** sudo exim -be -Mset $msg1 From: $h_from: @@ -13,6 +13,7 @@ message_body_size=$message_body_size message_size=$message_size message_id=$message_id message_exim_id=$message_exim_id +max_received_linelength=$max_received_linelength recipients=$recipients **** write test-data @@ -32,6 +33,7 @@ message_body_size=$message_body_size message_exim_id=$message_exim_id message_linecount=$message_linecount message_body_linecount=$body_linecount +max_received_linelength=$max_received_linelength headers ----------------- $message_headers diff --git a/test/stdout/0035 b/test/stdout/0035 index 15cac0b0f..6b5928b77 100644 --- a/test/stdout/0035 +++ b/test/stdout/0035 @@ -143,6 +143,7 @@ ddddddddd 0 -interface_address 127.0.0.1.1225 -received_protocol esmtp -body_linecount 0 +-max_received_linelength 0 -deliver_firsttime XX 1 @@ -162,6 +163,7 @@ ddddddddd 0 -interface_address 127.0.0.1.1225 -received_protocol esmtp -body_linecount 0 +-max_received_linelength 0 -deliver_firsttime XX 1 @@ -184,6 +186,7 @@ ddddddddd 0 -interface_address 127.0.0.1.1225 -received_protocol esmtp -body_linecount 0 +-max_received_linelength 0 -deliver_firsttime XX 1 @@ -204,6 +207,7 @@ ddddddddd 0 -interface_address 127.0.0.1.1225 -received_protocol esmtp -body_linecount 0 +-max_received_linelength 25 -deliver_firsttime XX 1 @@ -224,6 +228,7 @@ ddddddddd 0 -interface_address 127.0.0.1.1225 -received_protocol esmtp -body_linecount 0 +-max_received_linelength 25 -deliver_firsttime XX 1 @@ -247,6 +252,7 @@ ddddddddd 0 -interface_address 127.0.0.1.1225 -received_protocol esmtp -body_linecount 0 +-max_received_linelength 25 -deliver_firsttime XX 1 @@ -270,6 +276,7 @@ ddddddddd 0 -interface_address 127.0.0.1.1225 -received_protocol esmtp -body_linecount 0 +-max_received_linelength 25 -deliver_firsttime XX 1 diff --git a/test/stdout/0245 b/test/stdout/0245 index a29cad618..36332a61b 100644 --- a/test/stdout/0245 +++ b/test/stdout/0245 @@ -10,6 +10,7 @@ ddddddddd 0 -ident CALLER -received_protocol local -body_linecount 1 +-max_received_linelength 25 -auth_id CALLER -auth_sender CALLER@myhost.test.ex -allow_unqualified_recipient diff --git a/test/stdout/0250 b/test/stdout/0250 index 30fc9dc44..1d364b4e9 100644 --- a/test/stdout/0250 +++ b/test/stdout/0250 @@ -5,6 +5,7 @@ ddddddddd 0 -ident CALLER -received_protocol local -body_linecount 0 +-max_received_linelength 19 -auth_id CALLER -auth_sender CALLER@test.ex -allow_unqualified_recipient @@ -34,6 +35,7 @@ ddddddddd 0 -ident CALLER -received_protocol local -body_linecount 0 +-max_received_linelength 19 -auth_id CALLER -auth_sender CALLER@test.ex -allow_unqualified_recipient @@ -63,6 +65,7 @@ ddddddddd 0 -ident CALLER -received_protocol local -body_linecount 0 +-max_received_linelength 0 -auth_id CALLER -auth_sender CALLER@test.ex -allow_unqualified_recipient diff --git a/test/stdout/0254 b/test/stdout/0254 index 00a654640..947c4e0c5 100644 --- a/test/stdout/0254 +++ b/test/stdout/0254 @@ -5,6 +5,7 @@ ddddddddd 0 -ident CALLER -received_protocol local -body_linecount 0 +-max_received_linelength 32 -auth_id CALLER -auth_sender CALLER@myhost.test.ex -allow_unqualified_recipient @@ -40,6 +41,7 @@ ddddddddd 0 -ident CALLER -received_protocol local -body_linecount 0 +-max_received_linelength 14 -auth_id CALLER -auth_sender CALLER@myhost.test.ex -allow_unqualified_recipient @@ -68,6 +70,7 @@ ddddddddd 0 -ident CALLER -received_protocol local -body_linecount 0 +-max_received_linelength 18 -auth_id CALLER -auth_sender CALLER@myhost.test.ex -allow_unqualified_recipient diff --git a/test/stdout/0311 b/test/stdout/0311 index b563d1cd4..45190072f 100644 --- a/test/stdout/0311 +++ b/test/stdout/0311 @@ -5,6 +5,7 @@ ddddddddd 0 -ident CALLER -received_protocol local -body_linecount 0 +-max_received_linelength 46 -auth_id CALLER -auth_sender CALLER@myhost.test.ex -allow_unqualified_recipient @@ -32,6 +33,7 @@ ddddddddd 0 -ident CALLER -received_protocol local -body_linecount 0 +-max_received_linelength 46 -auth_id CALLER -auth_sender CALLER@myhost.test.ex -allow_unqualified_recipient diff --git a/test/stdout/0338 b/test/stdout/0338 index 870dc3b55..a97751353 100644 --- a/test/stdout/0338 +++ b/test/stdout/0338 @@ -9,6 +9,7 @@ ddddddddd 0 -ident CALLER -received_protocol local -body_linecount 0 +-max_received_linelength 0 -auth_id CALLER -auth_sender CALLER@test.ex -allow_unqualified_recipient diff --git a/test/stdout/0377 b/test/stdout/0377 index 140f53b9a..59742e666 100644 --- a/test/stdout/0377 +++ b/test/stdout/0377 @@ -5,6 +5,7 @@ ddddddddd 0 -ident CALLER -received_protocol local -body_linecount 0 +-max_received_linelength 0 -auth_id CALLER -auth_sender CALLER@myhost.test.ex -allow_unqualified_recipient diff --git a/test/stdout/0378 b/test/stdout/0378 index bbaa49a14..e64fdef16 100644 --- a/test/stdout/0378 +++ b/test/stdout/0378 @@ -5,6 +5,7 @@ ddddddddd 0 -ident CALLER -received_protocol local -body_linecount 0 +-max_received_linelength 0 -auth_id CALLER -auth_sender CALLER@myhost.test.ex -allow_unqualified_recipient diff --git a/test/stdout/0379 b/test/stdout/0379 index 00857b734..7bfea116f 100644 --- a/test/stdout/0379 +++ b/test/stdout/0379 @@ -5,6 +5,7 @@ ddddddddd 0 -ident CALLER -received_protocol local -body_linecount 0 +-max_received_linelength 0 -auth_id CALLER -auth_sender CALLER@myhost.test.ex -allow_unqualified_recipient diff --git a/test/stdout/0389 b/test/stdout/0389 index b361850cf..69b1bfc00 100644 --- a/test/stdout/0389 +++ b/test/stdout/0389 @@ -13,6 +13,7 @@ ddddddddd 0 -aclm 0 22 >Sender verify failed< -body_linecount 0 +-max_received_linelength 0 -auth_id CALLER -allow_unqualified_recipient -allow_unqualified_sender diff --git a/test/stdout/0488 b/test/stdout/0488 index 6acd7cee3..ff89ff2f7 100644 --- a/test/stdout/0488 +++ b/test/stdout/0488 @@ -11,6 +11,7 @@ ddddddddd 0 -ident CALLER -received_protocol local-smtp -body_linecount 0 +-max_received_linelength 0 -auth_id CALLER -allow_unqualified_recipient -allow_unqualified_sender diff --git a/test/stdout/0490 b/test/stdout/0490 index d5a87dabb..f9cb83d19 100644 --- a/test/stdout/0490 +++ b/test/stdout/0490 @@ -15,6 +15,7 @@ ddddddddd 0 -ident CALLER -received_protocol local-smtp -body_linecount 2 +-max_received_linelength 6 -auth_id CALLER -allow_unqualified_recipient -allow_unqualified_sender diff --git a/test/stdout/0514 b/test/stdout/0514 index dd078c1c9..83111ea92 100644 --- a/test/stdout/0514 +++ b/test/stdout/0514 @@ -8,6 +8,7 @@ ddddddddd 0 -ident spaced user -received_protocol local -body_linecount 1 +-max_received_linelength 7 -auth_id spaced user -auth_sender spaced user@myhost.test.ex -allow_unqualified_recipient diff --git a/test/stdout/0542 b/test/stdout/0542 index 03dd58a20..3e42bc19d 100644 --- a/test/stdout/0542 +++ b/test/stdout/0542 @@ -1,9 +1,10 @@ > From: Himself > Subject: The subject is not the object -> message_body_size=33 -> message_size=369 +> message_body_size=71 +> message_size=407 > message_id=10HmaX-0005vi-00 > message_exim_id=10HmaX-0005vi-00 +> max_received_linelength=70 > recipients=userx@test.x, usery@test.ex > > from: A Person @@ -14,6 +15,7 @@ > message_exim_id=10HmaY-0005vi-00 > message_linecount=6 > message_body_linecount=2 +> max_received_linelength=50 > headers ----------------- > From: A Person To: First , Second diff --git a/test/stdout/3415 b/test/stdout/3415 index bc9555c02..7bbd8061e 100644 --- a/test/stdout/3415 +++ b/test/stdout/3415 @@ -153,6 +153,7 @@ ddddddddd 0 -interface_address 127.0.0.1.1225 -received_protocol esmtpa -body_linecount 0 +-max_received_linelength 0 -auth_id username -deliver_firsttime XX @@ -178,6 +179,7 @@ ddddddddd 0 -interface_address 127.0.0.1.1225 -received_protocol esmtpa -body_linecount 0 +-max_received_linelength 0 -auth_id username -deliver_firsttime XX @@ -201,6 +203,7 @@ ddddddddd 0 -interface_address 127.0.0.1.1225 -received_protocol esmtpa -body_linecount 0 +-max_received_linelength 0 -auth_id username -deliver_firsttime XX @@ -224,6 +227,7 @@ ddddddddd 0 -interface_address 127.0.0.1.1225 -received_protocol esmtpa -body_linecount 0 +-max_received_linelength 0 -auth_id username@auth.id.domain -deliver_firsttime XX @@ -247,6 +251,7 @@ ddddddddd 0 -interface_address 127.0.0.1.1225 -received_protocol esmtpa -body_linecount 0 +-max_received_linelength 15 -auth_id username@auth.id.domain -deliver_firsttime XX -- 2.25.1