FTP test server: NODATACONN commands follow-up

Make NODATACONN custom commands apply to both active and passive FTP,
and ensure 425 and 421 are not returned unless data channel usage is
attempted.
This commit is contained in:
Yang Tse 2011-11-01 14:11:36 +01:00
parent 9cfc0c73a7
commit af425efe83
1 changed files with 38 additions and 8 deletions

View File

@ -831,7 +831,15 @@ my @ftpdir=("total 20\r\n",
"dr-xr-xr-x 5 0 1 512 Oct 1 1997 usr\r\n");
if($datasockf_conn eq 'no') {
sendcontrol "503 data channel not established\r\n";
if($nodataconn425) {
sendcontrol "425 Can't open data connection\r\n";
}
elsif($nodataconn421) {
sendcontrol "421 Connection timed out\r\n";
}
else {
sendcontrol "503 data channel not established\r\n";
}
return 0;
}
@ -852,7 +860,15 @@ sub NLST_ftp {
my @ftpdir=("file", "with space", "fake", "..", " ..", "funny", "README");
if($datasockf_conn eq 'no') {
sendcontrol "503 data channel not established\r\n";
if($nodataconn425) {
sendcontrol "425 Can't open data connection\r\n";
}
elsif($nodataconn421) {
sendcontrol "421 Connection timed out\r\n";
}
else {
sendcontrol "503 data channel not established\r\n";
}
return 0;
}
@ -960,7 +976,15 @@ sub RETR_ftp {
my ($testno) = @_;
if($datasockf_conn eq 'no') {
sendcontrol "503 data channel not established\r\n";
if($nodataconn425) {
sendcontrol "425 Can't open data connection\r\n";
}
elsif($nodataconn421) {
sendcontrol "421 Connection timed out\r\n";
}
else {
sendcontrol "503 data channel not established\r\n";
}
return 0;
}
@ -1059,7 +1083,15 @@ sub STOR_ftp {
my $filename = "log/upload.$testno";
if($datasockf_conn eq 'no') {
sendcontrol "503 data channel not established\r\n";
if($nodataconn425) {
sendcontrol "425 Can't open data connection\r\n";
}
elsif($nodataconn421) {
sendcontrol "421 Connection timed out\r\n";
}
else {
sendcontrol "503 data channel not established\r\n";
}
return 0;
}
@ -1347,7 +1379,6 @@ sub PORT_ftp {
"(NODATACONN425)\n";
datasockf_state('ACTIVE_NODATACONN');
logmsg "====> Active DATA channel not established\n";
sendcontrol "425 Can't open data connection\r\n";
return;
}
elsif($nodataconn421) {
@ -1355,7 +1386,6 @@ sub PORT_ftp {
"(NODATACONN421)\n";
datasockf_state('ACTIVE_NODATACONN');
logmsg "====> Active DATA channel not established\n";
sendcontrol "421 Connection timed out\r\n";
return;
}
@ -1513,12 +1543,12 @@ sub customize {
$pasvbadip=1;
}
elsif($_ =~ /NODATACONN425/) {
# applies only to active FTP mode
# applies to both active and passive FTP modes
logmsg "FTPD: instructed to use NODATACONN425\n";
$nodataconn425=1;
}
elsif($_ =~ /NODATACONN421/) {
# applies only to active FTP mode
# applies to both active and passive FTP modes
logmsg "FTPD: instructed to use NODATACONN421\n";
$nodataconn421=1;
}