incubator-ftpserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n..@apache.org
Subject svn commit: r480226 - in /incubator/ftpserver/trunk/core: ./ src/java/org/apache/ftpserver/ src/java/org/apache/ftpserver/interfaces/ src/test/org/apache/ftpserver/clienttests/ src/test/org/apache/ftpserver/test/
Date Tue, 28 Nov 2006 21:52:04 GMT
Author: ngn
Date: Tue Nov 28 13:52:02 2006
New Revision: 480226

URL: http://svn.apache.org/viewvc?view=rev&rev=480226
Log:
Applying patch for bug where the incorrect IP is returned when a server has multiple NICs
and the client issues a PASV command. Thanks to Joseph Ferner for finding the bug and providing
the patch. (FTPSERVER-51)

Also adding a test case to reproduce the bug. The patch fixes makes the test case succeed.

Modified:
    incubator/ftpserver/trunk/core/   (props changed)
    incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/DefaultDataConnectionConfig.java
    incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpDataConnection.java
    incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpWriter.java
    incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/RequestHandler.java
    incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/interfaces/DataConnectionConfig.java
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/ClientTestTemplate.java
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/LoginTest.java
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/test/TestUtil.java

Propchange: incubator/ftpserver/trunk/core/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue Nov 28 13:52:02 2006
@@ -6,3 +6,4 @@
 .wtpmodules
 cobertura.ser
 .lint4jprefs
+res

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/DefaultDataConnectionConfig.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/DefaultDataConnectionConfig.java?view=diff&rev=480226&r1=480225&r2=480226
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/DefaultDataConnectionConfig.java
(original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/DefaultDataConnectionConfig.java
Tue Nov 28 13:52:02 2006
@@ -92,7 +92,7 @@
             
             String pasvAddress = passiveConf.getString("address", null);
             if(pasvAddress == null) {
-                passiveAddress = InetAddress.getLocalHost();
+                passiveAddress = null;
             }
             else {
                 passiveAddress = InetAddress.getByName(pasvAddress);

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpDataConnection.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpDataConnection.java?view=diff&rev=480226&r1=480225&r2=480226
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpDataConnection.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpDataConnection.java Tue
Nov 28 13:52:02 2006
@@ -55,6 +55,8 @@
     
     private boolean secure   = false;
     private boolean isZip    = false;
+
+    private InetAddress serverControlAddress;
     
     
     /**
@@ -134,6 +136,9 @@
         try {
             DataConnectionConfig dataCfg = fconfig.getDataConnectionConfig();
             address = dataCfg.getPassiveAddress();
+            if(address == null) {
+                address = serverControlAddress;
+            }
             if(secure) {
                 Ssl ssl = dataCfg.getSSL();
                 if(ssl == null) {
@@ -283,6 +288,13 @@
      */ 
     public void dispose() {
         closeDataSocket();
+    }
+
+    /**
+     * Sets the server's control address. 
+     */
+    public void setServerControlAddress(InetAddress serverControlAddress) {
+        this.serverControlAddress = serverControlAddress;
     }
 }
     

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpWriter.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpWriter.java?view=diff&rev=480226&r1=480225&r2=480226
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpWriter.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/FtpWriter.java Tue Nov 28
13:52:02 2006
@@ -96,12 +96,14 @@
     private ConnectionObserver observer;
     private ServerFtpConfig fconfig;
     private FtpRequest request;
+    private InetAddress serverAddress;
 
         
     /**
      * Set the control socket.
      */
     public void setControlSocket(Socket soc) throws IOException {
+        serverAddress = soc.getLocalAddress();
         writer = new OutputStreamWriter(soc.getOutputStream(), "UTF-8");
     }
     
@@ -312,6 +314,9 @@
         // server address
         if(varName.equals(SERVER_IP)) {
             InetAddress addr = fconfig.getDataConnectionConfig().getPassiveAddress();
+            if(addr == null) {
+                addr = serverAddress;
+            }
             varVal = addr.getHostAddress();
         }
         

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/RequestHandler.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/RequestHandler.java?view=diff&rev=480226&r1=480225&r2=480226
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/RequestHandler.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/RequestHandler.java Tue Nov
28 13:52:02 2006
@@ -78,6 +78,7 @@
         // data connection object
         FtpDataConnection dataCon = new FtpDataConnection();
         dataCon.setFtpConfig(this.fconfig);
+        dataCon.setServerControlAddress(controlSocket.getLocalAddress());
         
         // reader object
         request = new FtpRequestImpl();

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/interfaces/DataConnectionConfig.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/interfaces/DataConnectionConfig.java?view=diff&rev=480226&r1=480225&r2=480226
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/interfaces/DataConnectionConfig.java
(original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/interfaces/DataConnectionConfig.java
Tue Nov 28 13:52:02 2006
@@ -57,7 +57,7 @@
     int getActiveLocalPort(); 
     
     /**
-     * Get passive server address.
+     * Get passive server address. null, if not set in the configuration.
      */
     InetAddress getPassiveAddress();
     

Modified: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/ClientTestTemplate.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/ClientTestTemplate.java?view=diff&rev=480226&r1=480225&r2=480226
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/ClientTestTemplate.java
(original)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/ClientTestTemplate.java
Tue Nov 28 13:52:02 2006
@@ -140,15 +140,21 @@
                 log.debug("< " + event.getMessage().trim());
             }});
         
-        try{
-            client.connect("localhost", port);
-        } catch(FTPConnectionClosedException e) {
-            // try again
-            Thread.sleep(200);
-            client.connect("localhost", port);
+        if(isConnectClient()) {
+            try{
+                client.connect("localhost", port);
+            } catch(FTPConnectionClosedException e) {
+                // try again
+                Thread.sleep(200);
+                client.connect("localhost", port);
+            }
         }
     }
 
+    protected boolean isConnectClient() {
+        return true;
+    }
+    
     /**
      * Attempts to find a free port or fallback to a default
      * @throws IOException 

Modified: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/LoginTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/LoginTest.java?view=diff&rev=480226&r1=480225&r2=480226
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/LoginTest.java
(original)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/LoginTest.java
Tue Nov 28 13:52:02 2006
@@ -106,22 +106,6 @@
         assertFalse(client.login(UNKNOWN_USERNAME, UNKNOWN_PASSWORD));
     }
     
-    private String[] getHostAddresses() throws Exception {
-        Enumeration nifs = NetworkInterface.getNetworkInterfaces();
-        
-        List hostIps = new ArrayList();
-        while (nifs.hasMoreElements()) {
-            NetworkInterface nif = (NetworkInterface) nifs.nextElement();
-            Enumeration ips = nif.getInetAddresses();
-            
-            while (ips.hasMoreElements()) {
-                InetAddress ip = (InetAddress) ips.nextElement();
-                hostIps.add(ip.getHostAddress());
-            }
-        }
-        
-        return (String[]) hostIps.toArray(new String[0]);
-    }
 /*
     public void testLoginWithMaxConnectionsPerIp() throws Exception {
         String[] ips = getHostAddresses();

Modified: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/test/TestUtil.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/test/TestUtil.java?view=diff&rev=480226&r1=480225&r2=480226
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/test/TestUtil.java (original)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/test/TestUtil.java Tue Nov
28 13:52:02 2006
@@ -23,7 +23,12 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
 import java.net.ServerSocket;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
 
 import junit.framework.TestCase;
 
@@ -89,6 +94,23 @@
         return port;
     }
 
+    public static String[] getHostAddresses() throws Exception {
+        Enumeration nifs = NetworkInterface.getNetworkInterfaces();
+        
+        List hostIps = new ArrayList();
+        while (nifs.hasMoreElements()) {
+            NetworkInterface nif = (NetworkInterface) nifs.nextElement();
+            Enumeration ips = nif.getInetAddresses();
+            
+            while (ips.hasMoreElements()) {
+                InetAddress ip = (InetAddress) ips.nextElement();
+                hostIps.add(ip.getHostAddress());
+            }
+        }
+        
+        return (String[]) hostIps.toArray(new String[0]);
+    }
+    
     public static void assertFileEqual(byte[] expected, File file)
             throws Exception {
         ByteArrayOutputStream baos = null;



Mime
View raw message