1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 08:08:50 -05:00

ftpserver.pl: Reworked SMTP verified server detection

Following the addition of informational commands to the SMTP protocol,
the test server is no longer required to return the verified server
information in responses that curl only outputs in verbose mode.

Instead, a similar detection mechanism to that used by FTP, IMAP and
POP3 can now be used.
This commit is contained in:
Steve Holme 2013-12-27 18:12:06 +00:00
parent c9dd4022f4
commit 263616202b
2 changed files with 67 additions and 88 deletions

View File

@ -702,104 +702,78 @@ my $smtp_client;
sub EHLO_smtp {
my ($client) = @_;
my @data;
if($client eq "verifiedserver") {
# This is the secret command that verifies that this actually is
# the curl test server
sendcontrol "554 WE ROOLZ: $$\r\n";
if($verbose) {
print STDERR "FTPD: We returned proof we are the test server\n";
}
logmsg "return proof we are we\n";
# TODO: Get the IP address of the client connection to use in the
# EHLO response when the client doesn't specify one but for now use
# 127.0.0.1
if(!$client) {
$client = "[127.0.0.1]";
}
else {
my @data;
# TODO: Get the IP address of the client connection to use in the
# EHLO response when the client doesn't specify one but for now use
# 127.0.0.1
if (!$client) {
$client = "[127.0.0.1]";
# Set the server type to ESMTP
$smtp_type = "ESMTP";
# Calculate the EHLO response
push @data, "$smtp_type pingpong test server Hello $client";
if((@capabilities) || (@auth_mechs)) {
my $mechs;
for my $c (@capabilities) {
push @data, $c;
}
# Set the server type to ESMTP
$smtp_type = "ESMTP";
# Calculate the EHLO response
push @data, "$smtp_type pingpong test server Hello $client";
if((@capabilities) || (@auth_mechs)) {
my $mechs;
for my $c (@capabilities) {
push @data, $c;
}
for my $am (@auth_mechs) {
if(!$mechs) {
$mechs = "$am";
}
else {
$mechs .= " $am";
}
}
if($mechs) {
push @data, "AUTH $mechs";
}
}
# Send the EHLO response
for (my $i = 0; $i < @data; $i++) {
my $d = $data[$i];
if($i < @data - 1) {
sendcontrol "250-$d\r\n";
for my $am (@auth_mechs) {
if(!$mechs) {
$mechs = "$am";
}
else {
sendcontrol "250 $d\r\n";
$mechs .= " $am";
}
}
# Store the client (as it may contain the test number)
$smtp_client = $client;
if($mechs) {
push @data, "AUTH $mechs";
}
}
# Send the EHLO response
for(my $i = 0; $i < @data; $i++) {
my $d = $data[$i];
if($i < @data - 1) {
sendcontrol "250-$d\r\n";
}
else {
sendcontrol "250 $d\r\n";
}
}
# Store the client (as it may contain the test number)
$smtp_client = $client;
}
return 0;
}
sub HELO_smtp {
my ($client) = @_;
if($client eq "verifiedserver") {
# This is the secret command that verifies that this actually is
# the curl test server
sendcontrol "554 WE ROOLZ: $$\r\n";
if($verbose) {
print STDERR "FTPD: We returned proof we are the test server\n";
}
logmsg "return proof we are we\n";
# TODO: Get the IP address of the client connection to use in the HELO
# response when the client doesn't specify one but for now use 127.0.0.1
if(!$client) {
$client = "[127.0.0.1]";
}
else {
# TODO: Get the IP address of the client connection to use in the HELO
# response when the client doesn't specify one but for now use 127.0.0.1
if (!$client) {
$client = "[127.0.0.1]";
}
# Set the server type to SMTP
$smtp_type = "SMTP";
# Set the server type to SMTP
$smtp_type = "SMTP";
# Send the HELO response
sendcontrol "250 $smtp_type pingpong test server Hello $client\r\n";
# 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;
}
# Store the client (as it may contain the test number)
$smtp_client = $client;
return 0;
}
@ -997,13 +971,26 @@ sub HELP_smtp {
logmsg "HELP_smtp got $args\n";
}
sendcontrol "214-This server supports the following commands:\r\n";
if($smtp_client eq "verifiedserver") {
# This is the secret command that verifies that this actually is
# the curl test server
sendcontrol "214 WE ROOLZ: $$\r\n";
if(@auth_mechs) {
sendcontrol "214 HELO EHLO RCPT DATA RSET MAIL VRFY EXPN QUIT HELP AUTH\r\n";
if($verbose) {
print STDERR "FTPD: We returned proof we are the test server\n";
}
logmsg "return proof we are we\n";
}
else {
sendcontrol "214 HELO EHLO RCPT DATA RSET MAIL VRFY EXPN QUIT HELP\r\n";
sendcontrol "214-This server supports the following commands:\r\n";
if(@auth_mechs) {
sendcontrol "214 HELO EHLO RCPT DATA RSET MAIL VRFY EXPN QUIT HELP AUTH\r\n";
}
else {
sendcontrol "214 HELO EHLO RCPT DATA RSET MAIL VRFY EXPN QUIT HELP\r\n";
}
}
return 0;

View File

@ -790,14 +790,6 @@ sub verifyftp {
if($proto eq "ftps") {
$extra .= "--insecure --ftp-ssl-control ";
}
elsif($proto eq "smtp") {
# SMTP is a bit different since it requires more options and it
# has _no_ output!
$extra .= "--mail-rcpt verifiedserver ";
$extra .= "--mail-from fake\@example.com ";
$extra .= "--upload /dev/null ";
$extra .= "--stderr - "; # move stderr to parse the verbose stuff
}
my $flags = "--max-time $server_response_maxtime ";
$flags .= "--silent ";