]> granicus.if.org Git - curl/commitdiff
ftpserver.pl: Added CAPA & AUTH directive support to the SMTP EHLO handler
authorSteve Holme <steve_holme@hotmail.com>
Sun, 15 Sep 2013 15:53:20 +0000 (16:53 +0100)
committerSteve Holme <steve_holme@hotmail.com>
Sun, 15 Sep 2013 15:53:20 +0000 (16:53 +0100)
tests/FILEFORMAT
tests/ftpserver.pl

index ba31614967a0b15a05db43659f62b137fea7b79f..0815556b16b6f82d8e8902c529db69946f224d07 100644 (file)
@@ -127,10 +127,11 @@ PASVBADIP
  - makes PASV send back an illegal IP in its 227 response
 CAPA [capabilities]
  - Enables support for and specifies a list of space separated capabilities to
-   return to the client for the IMAP CAPABILITY and POP3 CAPA commands
+   return to the client for the IMAP CAPABILITY, POP3 CAPA and SMTP EHLO
+   commands
 AUTH [mechanisms]
  - Enables support for SASL authentication and specifies a list of space
-   separated mechanisms for IMAP and POP3
+   separated mechanisms for IMAP, POP3 and SMTP
 
 For HTTP/HTTPS:
 auth_required   if this is set and a POST/PUT is made without auth, the
index ab8d069b27f0295400156b1f55a747a3ec82d09a..1e58eee4110ee67447a6db1a05a6a2f5876f70c3 100755 (executable)
@@ -689,6 +689,55 @@ sub close_dataconn {
 # what set by "RCPT"
 my $smtp_rcpt;
 
+sub EHLO_smtp {
+    my ($client) = @_;
+    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]";
+    }
+
+    # Calculate the EHLO response
+    push @data, "ESMTP 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";
+        }
+        else {
+            sendcontrol "250 $d\r\n";
+        }
+    }
+
+    return 0;
+}
+
 sub DATA_smtp {
     my $testno;
 
@@ -787,13 +836,6 @@ sub HELO_smtp {
     return 0;
 }
 
-sub EHLO_smtp {
-    sendcontrol "250-SIZE\r\n";
-    sendcontrol "250 Welcome visitor, stay a while staaaaaay forever\r\n";
-
-    return 0;
-}
-
 sub QUIT_smtp {
     sendcontrol "200 byebye\r\n";