From 49341628b50007c290d669ce3f51c562aad9708c Mon Sep 17 00:00:00 2001 From: Steve Holme Date: Sun, 29 Sep 2013 09:53:49 +0100 Subject: [PATCH] ftpserver.pl: Moved specifying the test number from the RCPT address ...to the client address as this frees the RCPT strings to contain just an email address and by passing the test number into curl as the client address remains consistent with POP3 and IMAP tests as they are specified in the URL. --- tests/data/test1320 | 4 ++-- tests/data/test1406 | 6 +++--- tests/data/test1507 | 4 ++-- tests/data/test900 | 4 ++-- tests/data/test901 | 4 ++-- tests/data/test902 | 6 +++--- tests/data/test903 | 4 ++-- tests/data/test904 | 4 ++-- tests/data/test905 | 4 ++-- tests/data/test906 | 4 ++-- tests/data/test907 | 4 ++-- tests/data/test908 | 4 ++-- tests/data/test909 | 4 ++-- tests/data/test910 | 4 ++-- tests/data/test911 | 4 ++-- tests/data/test912 | 4 ++-- tests/data/test913 | 4 ++-- tests/data/test914 | 4 ++-- tests/data/test915 | 4 ++-- tests/data/test916 | 4 ++-- tests/data/test917 | 4 ++-- tests/data/test918 | 4 ++-- tests/ftpserver.pl | 24 +++++++++++++++--------- 23 files changed, 61 insertions(+), 55 deletions(-) diff --git a/tests/data/test1320 b/tests/data/test1320 index 7fbefc9d0..4d6c8ea85 100644 --- a/tests/data/test1320 +++ b/tests/data/test1320 @@ -35,7 +35,7 @@ To: another body -smtp://smtp.1320:%SMTPPORT/user --mail-rcpt 1320@example.com --mail-from 1320@example.com -T - -p -x %HOSTIP:%PROXYPORT +smtp://smtp.1320:%SMTPPORT/1320 --mail-rcpt 1320@example.com --mail-from 1320@example.com -T - -p -x %HOSTIP:%PROXYPORT @@ -46,7 +46,7 @@ smtp://smtp.1320:%SMTPPORT/user --mail-rcpt 1320@example.com --mail-from 1320@ex ^User-Agent: curl/.* -EHLO user +EHLO 1320 MAIL FROM:<1320@example.com> RCPT TO:<1320@example.com> DATA diff --git a/tests/data/test1406 b/tests/data/test1406 index b330691fa..819e44313 100644 --- a/tests/data/test1406 +++ b/tests/data/test1406 @@ -32,7 +32,7 @@ To: another body -smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 1406@example.com --mail-rcpt 1406@foobar.example.com --mail-from 1406@example.com -T log/test1406.eml --libcurl log/test1406.c +smtp://%HOSTIP:%SMTPPORT/1406 --mail-rcpt 1406@example.com --mail-rcpt 1406@foobar.example.com --mail-from 1406@example.com -T log/test1406.eml --libcurl log/test1406.c @@ -40,7 +40,7 @@ smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 1406@example.com --mail-rcpt 1406@foob # Verify data after the test has been "shot" -EHLO user +EHLO 1406 MAIL FROM:<1406@example.com> SIZE=38 RCPT TO:<1406@example.com> RCPT TO:<1406@foobar.example.com> @@ -73,7 +73,7 @@ int main(int argc, char *argv[]) hnd = curl_easy_init(); curl_easy_setopt(hnd, CURLOPT_INFILESIZE_LARGE, (curl_off_t)38); - curl_easy_setopt(hnd, CURLOPT_URL, "smtp://%HOSTIP:%SMTPPORT/user"); + curl_easy_setopt(hnd, CURLOPT_URL, "smtp://%HOSTIP:%SMTPPORT/1406"); curl_easy_setopt(hnd, CURLOPT_HEADER, 1L); curl_easy_setopt(hnd, CURLOPT_UPLOAD, 1L); curl_easy_setopt(hnd, CURLOPT_USERAGENT, "stripped"); diff --git a/tests/data/test1507 b/tests/data/test1507 index 76ec5320d..ab7b47eb3 100644 --- a/tests/data/test1507 +++ b/tests/data/test1507 @@ -32,7 +32,7 @@ To: another body -smtp://%HOSTIP:%SMTPPORT/user +smtp://%HOSTIP:%SMTPPORT/1507 @@ -40,7 +40,7 @@ smtp://%HOSTIP:%SMTPPORT/user # Verify data after the test has been "shot" -EHLO user +EHLO 1507 MAIL FROM:<1507-realuser@example.com> RCPT TO:<1507-recipient@example.com> DATA diff --git a/tests/data/test900 b/tests/data/test900 index 5c30ec620..36f063388 100644 --- a/tests/data/test900 +++ b/tests/data/test900 @@ -26,7 +26,7 @@ To: another body -smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 900@example.com --mail-from 900@example.com -T - +smtp://%HOSTIP:%SMTPPORT/900 --mail-rcpt 900@example.com --mail-from 900@example.com -T - @@ -34,7 +34,7 @@ smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 900@example.com --mail-from 900@exampl # Verify data after the test has been "shot" -EHLO user +EHLO 900 MAIL FROM:<900@example.com> RCPT TO:<900@example.com> DATA diff --git a/tests/data/test901 b/tests/data/test901 index 7d660868f..7836dcfb3 100644 --- a/tests/data/test901 +++ b/tests/data/test901 @@ -32,7 +32,7 @@ To: another body -smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 901@example.com --mail-from 901@example.com -T - +smtp://%HOSTIP:%SMTPPORT/901 --mail-rcpt 901@example.com --mail-from 901@example.com -T - @@ -40,7 +40,7 @@ smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 901@example.com --mail-from 901@exampl # Verify data after the test has been "shot" -EHLO user +EHLO 901 MAIL FROM:<901@example.com> RCPT TO:<901@example.com> DATA diff --git a/tests/data/test902 b/tests/data/test902 index e18550139..2994eeff3 100644 --- a/tests/data/test902 +++ b/tests/data/test902 @@ -31,7 +31,7 @@ To: another body -smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 902@example.com --mail-from 902@example.com -T - +smtp://%HOSTIP:%SMTPPORT/902 --mail-rcpt 902@example.com --mail-from 902@example.com -T - @@ -39,8 +39,8 @@ smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 902@example.com --mail-from 902@exampl # Verify data after the test has been "shot" -EHLO user -HELO user +EHLO 902 +HELO 902 MAIL FROM:<902@example.com> RCPT TO:<902@example.com> DATA diff --git a/tests/data/test903 b/tests/data/test903 index 56ab36ebb..1b4530dc1 100644 --- a/tests/data/test903 +++ b/tests/data/test903 @@ -31,7 +31,7 @@ SMTP plain authentication mail body -smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 903@example.com --mail-from 903@example.com -u test:1234 -T - +smtp://%HOSTIP:%SMTPPORT/903 --mail-rcpt 903@example.com --mail-from 903@example.com -u test:1234 -T - @@ -39,7 +39,7 @@ smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 903@example.com --mail-from 903@exampl # Verify data after the test has been "shot" -EHLO user +EHLO 903 AUTH PLAIN dGVzdAB0ZXN0ADEyMzQ= MAIL FROM:<903@example.com> diff --git a/tests/data/test904 b/tests/data/test904 index a1d47ba5e..cb4014a5e 100644 --- a/tests/data/test904 +++ b/tests/data/test904 @@ -31,7 +31,7 @@ SMTP login authentication mail body -smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 904@example.com --mail-from 904@example.com -u test:1234 -T - +smtp://%HOSTIP:%SMTPPORT/904 --mail-rcpt 904@example.com --mail-from 904@example.com -u test:1234 -T - @@ -39,7 +39,7 @@ smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 904@example.com --mail-from 904@exampl # Verify data after the test has been "shot" -EHLO user +EHLO 904 AUTH LOGIN dGVzdA== MTIzNA== diff --git a/tests/data/test905 b/tests/data/test905 index e6c4864ea..214bc1822 100644 --- a/tests/data/test905 +++ b/tests/data/test905 @@ -34,7 +34,7 @@ SMTP CRAM-MD5 authentication mail body -smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 905@example.com --mail-from 905@example.com -u tim:tanstaaftanstaaf -T - +smtp://%HOSTIP:%SMTPPORT/905 --mail-rcpt 905@example.com --mail-from 905@example.com -u tim:tanstaaftanstaaf -T - @@ -42,7 +42,7 @@ smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 905@example.com --mail-from 905@exampl # Verify data after the test has been "shot" -EHLO user +EHLO 905 AUTH CRAM-MD5 dGltIGI5MTNhNjAyYzdlZGE3YTQ5NWI0ZTZlNzMzNGQzODkw MAIL FROM:<905@example.com> diff --git a/tests/data/test906 b/tests/data/test906 index d87f70e57..f60cec3f7 100644 --- a/tests/data/test906 +++ b/tests/data/test906 @@ -39,7 +39,7 @@ LD_PRELOAD=%PWD/libtest/.libs/libhostname.so mail body -smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 906@example.com --mail-from 906@example.com -u testuser:testpass -T - +smtp://%HOSTIP:%SMTPPORT/906 --mail-rcpt 906@example.com --mail-from 906@example.com -u testuser:testpass -T - @@ -47,7 +47,7 @@ smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 906@example.com --mail-from 906@exampl # Verify data after the test has been "shot" -EHLO user +EHLO 906 AUTH NTLM TlRMTVNTUAABAAAABoIIAAAAAAAAAAAAAAAAAAAAAAA= TlRMTVNTUAADAAAAGAAYAEAAAAAYABgAWAAAAAAAAABwAAAACAAIAHAAAAAIAAgAeAAAAAAAAAAAAAAABoKBAFpkQwKRCZFMhjj0tw47wEjKHRHlvzfxQamFcheMuv8v+xeqphEO5V41xRd7R9deOXRlc3R1c2VyY3VybGhvc3Q= diff --git a/tests/data/test907 b/tests/data/test907 index 0265f2605..7bdde410e 100644 --- a/tests/data/test907 +++ b/tests/data/test907 @@ -30,7 +30,7 @@ SMTP plain authentication with initial response mail body -smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 907@example.com --mail-from 907@example.com -u test:1234 --sasl-ir -T - +smtp://%HOSTIP:%SMTPPORT/907 --mail-rcpt 907@example.com --mail-from 907@example.com -u test:1234 --sasl-ir -T - @@ -38,7 +38,7 @@ smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 907@example.com --mail-from 907@exampl # Verify data after the test has been "shot" -EHLO user +EHLO 907 AUTH PLAIN dGVzdAB0ZXN0ADEyMzQ= MAIL FROM:<907@example.com> RCPT TO:<907@example.com> diff --git a/tests/data/test908 b/tests/data/test908 index f77a61a78..0c1667a3b 100644 --- a/tests/data/test908 +++ b/tests/data/test908 @@ -30,7 +30,7 @@ SMTP login authentication with initial response mail body -smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 908@example.com --mail-from 908@example.com -u test:1234 --sasl-ir -T - +smtp://%HOSTIP:%SMTPPORT/908 --mail-rcpt 908@example.com --mail-from 908@example.com -u test:1234 --sasl-ir -T - @@ -38,7 +38,7 @@ smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 908@example.com --mail-from 908@exampl # Verify data after the test has been "shot" -EHLO user +EHLO 908 AUTH LOGIN dGVzdA== MTIzNA== MAIL FROM:<908@example.com> diff --git a/tests/data/test909 b/tests/data/test909 index b92a872dd..ffe42ba42 100644 --- a/tests/data/test909 +++ b/tests/data/test909 @@ -30,7 +30,7 @@ To: another body -smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 909@example.com --mail-from 909@example.com -T log/test909.eml +smtp://%HOSTIP:%SMTPPORT/909 --mail-rcpt 909@example.com --mail-from 909@example.com -T log/test909.eml @@ -38,7 +38,7 @@ smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 909@example.com --mail-from 909@exampl # Verify data after the test has been "shot" -EHLO user +EHLO 909 MAIL FROM:<909@example.com> RCPT TO:<909@example.com> DATA diff --git a/tests/data/test910 b/tests/data/test910 index ecf7557e5..a3bf480bd 100644 --- a/tests/data/test910 +++ b/tests/data/test910 @@ -26,7 +26,7 @@ To: another body -smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 910@example.com --mail-from 910@example.com -T - +smtp://%HOSTIP:%SMTPPORT/910 --mail-rcpt 910@example.com --mail-from 910@example.com -T - @@ -34,7 +34,7 @@ smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 910@example.com --mail-from 910@exampl # Verify data after the test has been "shot" -EHLO user +EHLO 910 MAIL FROM:<910@example.com> RCPT TO:<910@example.com> DATA diff --git a/tests/data/test911 b/tests/data/test911 index 18a8fc62a..206f8afe0 100644 --- a/tests/data/test911 +++ b/tests/data/test911 @@ -25,7 +25,7 @@ SMTP with no mail data -smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 911@example.com --mail-from 911@example.com -T - +smtp://%HOSTIP:%SMTPPORT/911 --mail-rcpt 911@example.com --mail-from 911@example.com -T - @@ -33,7 +33,7 @@ smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 911@example.com --mail-from 911@exampl # Verify data after the test has been "shot" -EHLO user +EHLO 911 MAIL FROM:<911@example.com> RCPT TO:<911@example.com> DATA diff --git a/tests/data/test912 b/tests/data/test912 index 5e3718400..04abfd79a 100644 --- a/tests/data/test912 +++ b/tests/data/test912 @@ -30,7 +30,7 @@ To: another body -smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 912@example.com --mail-from 912@example.com -T log/test912.eml +smtp://%HOSTIP:%SMTPPORT/912 --mail-rcpt 912@example.com --mail-from 912@example.com -T log/test912.eml @@ -38,7 +38,7 @@ smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 912@example.com --mail-from 912@exampl # Verify data after the test has been "shot" -EHLO user +EHLO 912 MAIL FROM:<912@example.com> SIZE=38 RCPT TO:<912@example.com> DATA diff --git a/tests/data/test913 b/tests/data/test913 index ceabe1182..8c016e930 100644 --- a/tests/data/test913 +++ b/tests/data/test913 @@ -30,7 +30,7 @@ To: another body -smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 913@example.com --mail-from 913@example.com -T log/test913.eml +smtp://%HOSTIP:%SMTPPORT/913 --mail-rcpt 913@example.com --mail-from 913@example.com -T log/test913.eml @@ -41,7 +41,7 @@ smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 913@example.com --mail-from 913@exampl 55 -EHLO user +EHLO 913 MAIL FROM:<913@example.com> SIZE=38 QUIT diff --git a/tests/data/test914 b/tests/data/test914 index c2599f64a..cc97bdd9f 100644 --- a/tests/data/test914 +++ b/tests/data/test914 @@ -26,7 +26,7 @@ To: another body -smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 914@example.com --mail-from invalid -T log/test914.eml +smtp://%HOSTIP:%SMTPPORT/914 --mail-rcpt 914@example.com --mail-from invalid -T log/test914.eml @@ -37,7 +37,7 @@ smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 914@example.com --mail-from invalid -T 55 -EHLO user +EHLO 914 MAIL FROM: QUIT diff --git a/tests/data/test915 b/tests/data/test915 index da851c34c..3b5b62e16 100644 --- a/tests/data/test915 +++ b/tests/data/test915 @@ -26,7 +26,7 @@ To: another body -smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 915@example.com -T - +smtp://%HOSTIP:%SMTPPORT/915 --mail-rcpt 915@example.com -T - @@ -34,7 +34,7 @@ smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 915@example.com -T - # Verify data after the test has been "shot" -EHLO user +EHLO 915 MAIL FROM:<> RCPT TO:<915@example.com> DATA diff --git a/tests/data/test916 b/tests/data/test916 index 3a9ccea18..f2e0aedd0 100644 --- a/tests/data/test916 +++ b/tests/data/test916 @@ -26,7 +26,7 @@ To: another body -smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt invalid --mail-from 916@example.com -T - +smtp://%HOSTIP:%SMTPPORT/916 --mail-rcpt invalid --mail-from 916@example.com -T - @@ -37,7 +37,7 @@ smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt invalid --mail-from 916@example.com -T 55 -EHLO user +EHLO 916 MAIL FROM:<916@example.com> RCPT TO: QUIT diff --git a/tests/data/test917 b/tests/data/test917 index d5dc4f8ef..23a05ecb1 100644 --- a/tests/data/test917 +++ b/tests/data/test917 @@ -26,7 +26,7 @@ To: another body -smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 917@example.com --mail-rcpt 917@foo.example.com --mail-rcpt 917@bar.example.com --mail-rcpt 917@foobar.example.com --mail-rcpt 917@another.example.com --mail-from 917@example.com -T - +smtp://%HOSTIP:%SMTPPORT/917 --mail-rcpt 917@example.com --mail-rcpt 917@foo.example.com --mail-rcpt 917@bar.example.com --mail-rcpt 917@foobar.example.com --mail-rcpt 917@another.example.com --mail-from 917@example.com -T - @@ -34,7 +34,7 @@ smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 917@example.com --mail-rcpt 917@foo.ex # Verify data after the test has been "shot" -EHLO user +EHLO 917 MAIL FROM:<917@example.com> RCPT TO:<917@example.com> RCPT TO:<917@foo.example.com> diff --git a/tests/data/test918 b/tests/data/test918 index be9ec853f..4817e2814 100644 --- a/tests/data/test918 +++ b/tests/data/test918 @@ -26,7 +26,7 @@ To: another body -smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 918@example.com --mail-rcpt invalid --mail-rcpt 918@bar.example.com --mail-rcpt sTrAnGe --mail-rcpt 918@another.example.com --mail-from 918@example.com -T - +smtp://%HOSTIP:%SMTPPORT/918 --mail-rcpt 918@example.com --mail-rcpt invalid --mail-rcpt 918@bar.example.com --mail-rcpt sTrAnGe --mail-rcpt 918@another.example.com --mail-from 918@example.com -T - @@ -37,7 +37,7 @@ smtp://%HOSTIP:%SMTPPORT/user --mail-rcpt 918@example.com --mail-rcpt invalid -- 55 -EHLO user +EHLO 918 MAIL FROM:<918@example.com> RCPT TO:<918@example.com> RCPT TO: diff --git a/tests/ftpserver.pl b/tests/ftpserver.pl index 838d849a0..907846ab9 100755 --- a/tests/ftpserver.pl +++ b/tests/ftpserver.pl @@ -685,12 +685,12 @@ sub close_dataconn { ################ SMTP commands ################ -# what set by "RCPT" -my $smtp_rcpt; - # The type of server (SMTP or ESMTP) my $smtp_type; +# The client (which normally contains the test number) +my $smtp_client; + sub EHLO_smtp { my ($client) = @_; @@ -753,6 +753,9 @@ sub EHLO_smtp { sendcontrol "250 $d\r\n"; } } + + # Store the client (as it may contain the test number) + $smtp_client = $client; } return 0; @@ -784,6 +787,9 @@ sub HELO_smtp { # Send the HELO response sendcontrol "250 $smtp_type pingpong test server Hello $client\r\n"; + + # Store the client (as it may contain the test number) + $smtp_client = $client; } return 0; @@ -854,11 +860,11 @@ sub RCPT_smtp { sendcontrol "501 Unrecognized parameter\r\n"; } else { - $smtp_rcpt = $1; + my $to = $1; # Validate the to address (only a valid email address inside <> is # allowed, such as ) - if ($smtp_rcpt !~ + if ($to !~ /^<([a-zA-Z0-9._%+-]+)\@([a-zA-Z0-9.-]+).([a-zA-Z]{2,4})>$/) { sendcontrol "501 Invalid address\r\n"; } @@ -872,17 +878,17 @@ sub RCPT_smtp { sub DATA_smtp { my ($args) = @_; - my $testno = $smtp_rcpt; if ($args) { sendcontrol "501 Unrecognized parameter\r\n"; } + elsif ($smtp_client !~ /^(\d*)$/) + sendcontrol "501 Invalid arguments\r\n"; + } else { - $testno =~ s/^([^0-9]*)([0-9]+).*/$2/; sendcontrol "354 Show me the mail\r\n"; - logmsg "===> rcpt $testno was $smtp_rcpt\n"; - + my $testno = $smtp_client; my $filename = "log/upload.$testno"; logmsg "Store test number $testno in $filename\n";