]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Add EPRT and EPSV commands to FTP FEAT response if not already there
authorChristos Tsantilas <chtsanti@users.sourceforge.net>
Wed, 13 Nov 2013 22:20:55 +0000 (15:20 -0700)
committerAlex Rousskov <rousskov@measurement-factory.com>
Wed, 13 Nov 2013 22:20:55 +0000 (15:20 -0700)
because Squid FTP gw supports both even if the FTP origin server does not.

src/client_side.cc

index e900168bc395a91946be67cfdc8617aa2e338a58..627cb847e2c63114fc92938c6aabf5b1d25904c6 100644 (file)
@@ -5287,6 +5287,8 @@ FtpHandleFeatReply(ClientSocketContext *context, const HttpReply *reply, StoreIO
     // Remove all unsupported commands from the response wrapper.
     int deletedCount = 0;
     HttpHeaderPos pos = HttpHeaderInitPos;
+    bool hasEPRT = false;
+    bool hasEPSV = false;
     while (const HttpHeaderEntry *e = filteredHeader.getEntry(&pos)) {
         if (e->id == HDR_FTP_PRE) {
             // assume RFC 2389 FEAT response format, quoted by Squid:
@@ -5303,12 +5305,27 @@ FtpHandleFeatReply(ClientSocketContext *context, const HttpReply *reply, StoreIO
 
             if (!FtpSupportedCommand(cmd))
                 filteredHeader.delAt(pos, deletedCount);
+
+            if (cmd == "EPRT")
+                hasEPRT = true;
+            else if (cmd == "EPSV")
+                hasEPSV = true;
         }
     }
 
-    if (deletedCount) {
+    int insertedCount = 0;
+    if (!hasEPRT) {
+        filteredHeader.putStr(HDR_FTP_PRE, "\" EPRT\"");
+        ++insertedCount;
+    }
+    if (!hasEPSV) {
+        filteredHeader.putStr(HDR_FTP_PRE, "\" EPSV\"");
+        ++insertedCount;
+    }
+
+    if (deletedCount || insertedCount) {
         filteredHeader.refreshMask();
-        debugs(33, 5, "deleted " << deletedCount);
+        debugs(33, 5, "deleted " << deletedCount << " inserted " << insertedCount);
     }
 
     FtpWriteForwardedReply(context, filteredReply);