6
6
# | (__| |_| | _ <| |___
7
7
# \___|\___/|_| \_\_____|
9
# Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
9
# Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
11
11
# This software is licensed as described in the file COPYING, which
12
12
# you should have received as part of this distribution. The terms
78
78
my $proto = 'ftp'; # default server protocol
79
79
my $srcdir; # directory where ftpserver.pl is located
80
80
my $srvrname; # server name for presentation purposes
81
my $cwd_testno; # test case numbers extracted from CWD command
83
83
my $logdir = $path .'/log';
123
123
#**********************************************************************
124
124
# global vars which depend on server protocol selection
126
my %commandfunc; # protocol command specific function callbacks
127
my %displaytext; # text returned to client before callback runs
126
my %commandfunc; # protocol command specific function callbacks
127
my %displaytext; # text returned to client before callback runs
129
129
#**********************************************************************
130
130
# global vars customized for each test from the server commands file
558
559
'220- _ _ ____ _ '."\r\n",
559
560
'220- ___| | | | _ \| | '."\r\n",
560
561
'220- / __| | | | |_) | | '."\r\n",
561
'220- | (__| |_| | _ <| |___ '."\r\n",
562
'220- | (__| |_| | _ {| |___ '."\r\n",
562
563
'220 \___|\___/|_| \_\_____|'."\r\n")
584
585
' _ _ ____ _ '."\r\n",
585
586
' ___| | | | _ \| | '."\r\n",
586
587
' / __| | | | |_) | | '."\r\n",
587
' | (__| |_| | _ <| |___ '."\r\n",
588
' | (__| |_| | _ {| |___ '."\r\n",
588
589
' \___|\___/|_| \_\_____|'."\r\n",
589
'+OK cURL POP3 server ready to serve '.$POP3_TIMESTAMP."\r\n")
590
'+OK cURL POP3 server ready to serve '."\r\n")
592
593
elsif($proto eq 'imap') {
618
619
' _ _ ____ _ '."\r\n",
619
620
' ___| | | | _ \| | '."\r\n",
620
621
' / __| | | | |_) | | '."\r\n",
621
' | (__| |_| | _ <| |___ '."\r\n",
622
' | (__| |_| | _ {| |___ '."\r\n",
622
623
' \___|\___/|_| \_\_____|'."\r\n",
623
624
'* OK cURL IMAP server ready to serve'."\r\n")
642
643
'220- _ _ ____ _ '."\r\n",
643
644
'220- ___| | | | _ \| | '."\r\n",
644
645
'220- / __| | | | |_) | | '."\r\n",
645
'220- | (__| |_| | _ <| |___ '."\r\n",
646
'220- | (__| |_| | _ {| |___ '."\r\n",
646
647
'220 \___|\___/|_| \_\_____|'."\r\n")
703
704
my ($client) = @_;
705
if($client eq "verifiedserver") {
706
# This is the secret command that verifies that this actually is
707
# the curl test server
708
sendcontrol "554 WE ROOLZ: $$\r\n";
711
print STDERR "FTPD: We returned proof we are the test server\n";
714
logmsg "return proof we are we\n";
707
# TODO: Get the IP address of the client connection to use in the
708
# EHLO response when the client doesn't specify one but for now use
711
$client = "[127.0.0.1]";
719
# TODO: Get the IP address of the client connection to use in the
720
# EHLO response when the client doesn't specify one but for now use
723
$client = "[127.0.0.1]";
726
# Set the server type to ESMTP
727
$smtp_type = "ESMTP";
729
# Calculate the EHLO response
730
push @data, "$smtp_type pingpong test server Hello $client";
732
if((@capabilities) || (@auth_mechs)) {
735
for my $c (@capabilities) {
739
for my $am (@auth_mechs) {
749
push @data, "AUTH $mechs";
753
# Send the EHLO response
754
for (my $i = 0; $i < @data; $i++) {
758
sendcontrol "250-$d\r\n";
714
# Set the server type to ESMTP
715
$smtp_type = "ESMTP";
717
# Calculate the EHLO response
718
push @data, "$smtp_type pingpong test server Hello $client";
720
if((@capabilities) || (@auth_mechs)) {
723
for my $c (@capabilities) {
727
for my $am (@auth_mechs) {
761
sendcontrol "250 $d\r\n";
765
# Store the client (as it may contain the test number)
766
$smtp_client = $client;
737
push @data, "AUTH $mechs";
741
# Send the EHLO response
742
for(my $i = 0; $i < @data; $i++) {
746
sendcontrol "250-$d\r\n";
749
sendcontrol "250 $d\r\n";
753
# Store the client (as it may contain the test number)
754
$smtp_client = $client;
773
760
my ($client) = @_;
775
if($client eq "verifiedserver") {
776
# This is the secret command that verifies that this actually is
777
# the curl test server
778
sendcontrol "554 WE ROOLZ: $$\r\n";
781
print STDERR "FTPD: We returned proof we are the test server\n";
784
logmsg "return proof we are we\n";
787
# TODO: Get the IP address of the client connection to use in the HELO
788
# response when the client doesn't specify one but for now use 127.0.0.1
790
$client = "[127.0.0.1]";
793
# Set the server type to SMTP
796
# Send the HELO response
797
sendcontrol "250 $smtp_type pingpong test server Hello $client\r\n";
799
# Store the client (as it may contain the test number)
800
$smtp_client = $client;
762
# TODO: Get the IP address of the client connection to use in the HELO
763
# response when the client doesn't specify one but for now use 127.0.0.1
765
$client = "[127.0.0.1]";
768
# Set the server type to SMTP
771
# Send the HELO response
772
sendcontrol "250 $smtp_type pingpong test server Hello $client\r\n";
774
# Store the client (as it may contain the test number)
775
$smtp_client = $client;
996
970
logmsg "HELP_smtp got $args\n";
999
sendcontrol "214-This server supports the following commands:\r\n";
1002
sendcontrol "214 HELO EHLO RCPT DATA RSET MAIL VRFY EXPN QUIT HELP AUTH\r\n";
973
if($smtp_client eq "verifiedserver") {
974
# This is the secret command that verifies that this actually is
975
# the curl test server
976
sendcontrol "214 WE ROOLZ: $$\r\n";
979
print STDERR "FTPD: We returned proof we are the test server\n";
982
logmsg "return proof we are we\n";
1005
sendcontrol "214 HELO EHLO RCPT DATA RSET MAIL VRFY EXPN QUIT HELP\r\n";
985
sendcontrol "214-This server supports the following commands:\r\n";
988
sendcontrol "214 HELO EHLO RCPT DATA RSET MAIL VRFY EXPN QUIT HELP AUTH\r\n";
991
sendcontrol "214 HELO EHLO RCPT DATA RSET MAIL VRFY EXPN QUIT HELP\r\n";
1707
1694
sub CAPA_pop3 {
1708
1695
my ($testno) = @_;
1710
if((!@capabilities) && (!@auth_mechs)) {
1699
# Calculate the capability list based on the specified capabilities
1700
# (except APOP) and any authentication mechanisms
1701
for my $c (@capabilities) {
1702
push @list, "$c\r\n" unless $c eq "APOP";
1705
for my $am (@auth_mechs) {
1715
push @list, "SASL $mechs\r\n";
1711
1719
sendcontrol "-ERR Unrecognized command\r\n";
1717
1724
# Calculate the CAPA response
1718
1725
push @data, "+OK List of capabilities follows\r\n";
1720
for my $c (@capabilities) {
1721
push @data, "$c\r\n";
1724
for my $am (@auth_mechs) {
1734
push @data, "SASL $mechs\r\n";
1728
push @data, "$l\r\n";
1737
1731
push @data, "IMPLEMENTATION POP3 pingpong test server\r\n";
2120
# print "150 ASCII data connection for /bin/ls (193.15.23.1,59196) (0 bytes)\r\n";
2117
# print "150 ASCII data connection for /bin/ls (193.15.23.1,59196) (0 bytes)\r\n";
2122
2119
# this is a built-in fake-dir ;-)
2123
2120
my @ftpdir=("total 20\r\n",
2158
2155
logmsg "pass LIST data on data connection\n";
2158
loadtest("$srcdir/data/test$cwd_testno");
2160
my @data = getpart("reply", "data");
2163
logmsg "send $send as data\n";
2166
$cwd_testno = 0; # forget it again
2169
# old hard-coded style
2162
2174
close_dataconn(0);
2163
2175
sendcontrol "226 ASCII transfer complete\r\n";
2841
2854
logmsg "FTPD: Getting commands from log/ftpserver.cmd\n";
2843
2856
while(<CUSTOM>) {
2844
if($_ =~ /REPLY ([A-Za-z0-9+\/=\*]*) (.*)/) {
2845
$customreply{$1}=eval "qq{$2}";
2857
if($_ =~ /REPLY \"([A-Z]+ [A-Za-z0-9+-\/=\*]+)\" (.*)/) {
2858
$fulltextreply{$1}=eval "qq{$2}";
2859
logmsg "FTPD: set custom reply for $1\n";
2861
elsif($_ =~ /REPLY ([A-Za-z0-9+\/=\*]*) (.*)/) {
2862
$commandreply{$1}=eval "qq{$2}";
2847
logmsg "FTPD: set custom reply for empty response\n";
2864
logmsg "FTPD: set custom reply for empty command\n";
2850
logmsg "FTPD: set custom reply for $1\n";
2867
logmsg "FTPD: set custom reply for $1 command\n";
2853
2870
elsif($_ =~ /COUNT ([A-Z]+) (.*)/) {
2854
# we blank the customreply for this command when having
2871
# we blank the custom reply for this command when having
2855
2872
# been used this number of times
2856
2873
$customcount{$1}=$2;
2857
logmsg "FTPD: blank custom reply for $1 after $2 uses\n";
2874
logmsg "FTPD: blank custom reply for $1 command after $2 uses\n";
2859
2876
elsif($_ =~ /DELAY ([A-Z]+) (\d*)/) {
2860
2877
$delayreply{$1}=$2;
3092
3109
&customize(); # read test control instructions
3094
my $welcome = $customreply{"welcome"};
3111
my $welcome = $commandreply{"welcome"};
3095
3112
if(!$welcome) {
3096
3113
$welcome = $displaytext{"welcome"};
3099
3116
# clear it after use
3100
$customreply{"welcome"}="";
3117
$commandreply{"welcome"}="";
3101
3118
if($welcome !~ /\r\n\z/) {
3102
3119
$welcome .= "\r\n";
3246
3263
my $check = 1; # no response yet
3248
# See if there is a custom reply for our command
3249
my $text = $customreply{$FTPCMD};
3265
# See if there is a custom reply for the full text
3266
my $fulltext = $FTPARG ? $FTPCMD . " " . $FTPARG : $FTPCMD;
3267
my $text = $fulltextreply{$fulltext};
3250
3268
if($text && ($text ne "")) {
3251
if($customcount{$FTPCMD} && (!--$customcount{$FTPCMD})) {
3252
# used enough number of times, now blank the customreply
3253
$customreply{$FTPCMD}="";
3256
3269
sendcontrol "$text\r\n";
3260
# See if there is any display text for our command
3261
$text = $displaytext{$FTPCMD};
3273
# See if there is a custom reply for the command
3274
$text = $commandreply{$FTPCMD};
3262
3275
if($text && ($text ne "")) {
3263
if($proto eq 'imap') {
3264
sendcontrol "$cmdid $text\r\n";
3267
sendcontrol "$text\r\n";
3276
if($customcount{$FTPCMD} && (!--$customcount{$FTPCMD})) {
3277
# used enough times so blank the custom command reply
3278
$commandreply{$FTPCMD}="";
3281
sendcontrol "$text\r\n";
3273
# only perform this if we're not faking a reply
3274
my $func = $commandfunc{$FTPCMD};
3276
&$func($FTPARG, $FTPCMD);
3277
$check=0; # taken care of
3285
# See if there is any display text for the command
3286
$text = $displaytext{$FTPCMD};
3287
if($text && ($text ne "")) {
3288
if($proto eq 'imap') {
3289
sendcontrol "$cmdid $text\r\n";
3292
sendcontrol "$text\r\n";
3298
# only perform this if we're not faking a reply
3299
my $func = $commandfunc{$FTPCMD};
3301
&$func($FTPARG, $FTPCMD);