incubator-ftpserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n..@apache.org
Subject svn commit: r589178 - in /incubator/ftpserver/trunk/core/src: java/org/apache/ftpserver/command/ test/org/apache/ftpserver/clienttests/
Date Sat, 27 Oct 2007 18:56:22 GMT
Author: ngn
Date: Sat Oct 27 11:56:21 2007
New Revision: 589178

URL: http://svn.apache.org/viewvc?rev=589178&view=rev
Log:
Fixing issue where we don't check for PASV being sent before commands using a data channel
(FTPSERVER-110). Thanks to Rico Neubauer for the patch and test case.

Added:
    incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/ActiveModeReplyTest.java
Modified:
    incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/APPE.java
    incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/LIST.java
    incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/MLSD.java
    incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/NLST.java
    incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/RETR.java
    incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/STOR.java
    incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/STOU.java

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/APPE.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/APPE.java?rev=589178&r1=589177&r2=589178&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/APPE.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/APPE.java Sat Oct
27 11:56:21 2007
@@ -21,9 +21,13 @@
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.net.InetAddress;
 import java.net.SocketException;
 
+import org.apache.ftpserver.DefaultFtpReply;
 import org.apache.ftpserver.FtpSessionImpl;
+import org.apache.ftpserver.IODataConnectionFactory;
+import org.apache.ftpserver.ftplet.DataConnectionFactory;
 import org.apache.ftpserver.ftplet.FileObject;
 import org.apache.ftpserver.ftplet.DataConnection;
 import org.apache.ftpserver.ftplet.FtpException;
@@ -74,6 +78,16 @@
             if(fileName == null) {
                 out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS,
"APPE", null));
                 return;  
+            }
+            
+            // 24-10-2007 - added check if PORT or PASV is issued, see https://issues.apache.org/jira/browse/FTPSERVER-110
+            DataConnectionFactory connFactory = session.getDataConnection();
+            if (connFactory instanceof IODataConnectionFactory) {
+                InetAddress address = ((IODataConnectionFactory)connFactory).getInetAddress();
+                if (address == null) {
+                    out.write(new DefaultFtpReply(FtpReply.REPLY_503_BAD_SEQUENCE_OF_COMMANDS,
"PORT or PASV must be issued first"));
+                    return;
+                }
             }
             
             // call Ftplet.onAppendStart() method

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/LIST.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/LIST.java?rev=589178&r1=589177&r2=589178&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/LIST.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/LIST.java Sat Oct
27 11:56:21 2007
@@ -20,10 +20,14 @@
 package org.apache.ftpserver.command;
 
 import java.io.IOException;
+import java.net.InetAddress;
 import java.net.SocketException;
 
+import org.apache.ftpserver.DefaultFtpReply;
 import org.apache.ftpserver.FtpSessionImpl;
+import org.apache.ftpserver.IODataConnectionFactory;
 import org.apache.ftpserver.ftplet.DataConnection;
+import org.apache.ftpserver.ftplet.DataConnectionFactory;
 import org.apache.ftpserver.ftplet.FtpException;
 import org.apache.ftpserver.ftplet.FtpReply;
 import org.apache.ftpserver.ftplet.FtpReplyOutput;
@@ -69,6 +73,16 @@
         
             // reset state variables
             session.resetState();
+            
+            // 24-10-2007 - added check if PORT or PASV is issued, see https://issues.apache.org/jira/browse/FTPSERVER-110
+            DataConnectionFactory connFactory = session.getDataConnection();
+            if (connFactory instanceof IODataConnectionFactory) {
+                InetAddress address = ((IODataConnectionFactory)connFactory).getInetAddress();
+                if (address == null) {
+                    out.write(new DefaultFtpReply(FtpReply.REPLY_503_BAD_SEQUENCE_OF_COMMANDS,
"PORT or PASV must be issued first"));
+                    return;
+                }
+            }
             
             // get data connection
             out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_150_FILE_STATUS_OKAY,
"LIST", null));

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/MLSD.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/MLSD.java?rev=589178&r1=589177&r2=589178&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/MLSD.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/MLSD.java Sat Oct
27 11:56:21 2007
@@ -20,10 +20,14 @@
 package org.apache.ftpserver.command;
 
 import java.io.IOException;
+import java.net.InetAddress;
 import java.net.SocketException;
 
+import org.apache.ftpserver.DefaultFtpReply;
 import org.apache.ftpserver.FtpSessionImpl;
+import org.apache.ftpserver.IODataConnectionFactory;
 import org.apache.ftpserver.ftplet.DataConnection;
+import org.apache.ftpserver.ftplet.DataConnectionFactory;
 import org.apache.ftpserver.ftplet.FtpException;
 import org.apache.ftpserver.ftplet.FtpReply;
 import org.apache.ftpserver.ftplet.FtpReplyOutput;
@@ -66,6 +70,16 @@
             
             // reset state
             session.resetState();
+
+         // 24-10-2007 - added check if PORT or PASV is issued, see https://issues.apache.org/jira/browse/FTPSERVER-110
+            DataConnectionFactory connFactory = session.getDataConnection();
+            if (connFactory instanceof IODataConnectionFactory) {
+                InetAddress address = ((IODataConnectionFactory)connFactory).getInetAddress();
+                if (address == null) {
+                    out.write(new DefaultFtpReply(FtpReply.REPLY_503_BAD_SEQUENCE_OF_COMMANDS,
"PORT or PASV must be issued first"));
+                    return;
+                }
+            }
             
             // get data connection
             out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_150_FILE_STATUS_OKAY,
"MLSD", null));

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/NLST.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/NLST.java?rev=589178&r1=589177&r2=589178&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/NLST.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/NLST.java Sat Oct
27 11:56:21 2007
@@ -20,10 +20,14 @@
 package org.apache.ftpserver.command;
 
 import java.io.IOException;
+import java.net.InetAddress;
 import java.net.SocketException;
 
+import org.apache.ftpserver.DefaultFtpReply;
 import org.apache.ftpserver.FtpSessionImpl;
+import org.apache.ftpserver.IODataConnectionFactory;
 import org.apache.ftpserver.ftplet.DataConnection;
+import org.apache.ftpserver.ftplet.DataConnectionFactory;
 import org.apache.ftpserver.ftplet.FtpException;
 import org.apache.ftpserver.ftplet.FtpReply;
 import org.apache.ftpserver.ftplet.FtpReplyOutput;
@@ -70,6 +74,16 @@
             
             // reset state
             session.resetState();
+
+            // 24-10-2007 - added check if PORT or PASV is issued, see https://issues.apache.org/jira/browse/FTPSERVER-110
+            DataConnectionFactory connFactory = session.getDataConnection();
+            if (connFactory instanceof IODataConnectionFactory) {
+                InetAddress address = ((IODataConnectionFactory)connFactory).getInetAddress();
+                if (address == null) {
+                    out.write(new DefaultFtpReply(FtpReply.REPLY_503_BAD_SEQUENCE_OF_COMMANDS,
"PORT or PASV must be issued first"));
+                    return;
+                }
+            }
             
             // get data connection
             out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_150_FILE_STATUS_OKAY,
"NLST", null));

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/RETR.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/RETR.java?rev=589178&r1=589177&r2=589178&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/RETR.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/RETR.java Sat Oct
27 11:56:21 2007
@@ -22,9 +22,13 @@
 import java.io.BufferedInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.InetAddress;
 import java.net.SocketException;
 
+import org.apache.ftpserver.DefaultFtpReply;
 import org.apache.ftpserver.FtpSessionImpl;
+import org.apache.ftpserver.IODataConnectionFactory;
+import org.apache.ftpserver.ftplet.DataConnectionFactory;
 import org.apache.ftpserver.ftplet.DataType;
 import org.apache.ftpserver.ftplet.FileObject;
 import org.apache.ftpserver.ftplet.DataConnection;
@@ -123,6 +127,16 @@
             if(!file.hasReadPermission()) {
                 out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
"RETR.permission", fileName));
                 return;
+            }
+
+            // 24-10-2007 - added check if PORT or PASV is issued, see https://issues.apache.org/jira/browse/FTPSERVER-110
+            DataConnectionFactory connFactory = session.getDataConnection();
+            if (connFactory instanceof IODataConnectionFactory) {
+                InetAddress address = ((IODataConnectionFactory)connFactory).getInetAddress();
+                if (address == null) {
+                    out.write(new DefaultFtpReply(FtpReply.REPLY_503_BAD_SEQUENCE_OF_COMMANDS,
"PORT or PASV must be issued first"));
+                    return;
+                }
             }
             
             // get data connection

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/STOR.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/STOR.java?rev=589178&r1=589177&r2=589178&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/STOR.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/STOR.java Sat Oct
27 11:56:21 2007
@@ -21,9 +21,13 @@
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.net.InetAddress;
 import java.net.SocketException;
 
+import org.apache.ftpserver.DefaultFtpReply;
 import org.apache.ftpserver.FtpSessionImpl;
+import org.apache.ftpserver.IODataConnectionFactory;
+import org.apache.ftpserver.ftplet.DataConnectionFactory;
 import org.apache.ftpserver.ftplet.FileObject;
 import org.apache.ftpserver.ftplet.DataConnection;
 import org.apache.ftpserver.ftplet.FtpException;
@@ -75,6 +79,16 @@
             if(fileName == null) {
                 out.write(FtpReplyUtil.translate(session, FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS,
"STOR", null));
                 return;  
+            }
+
+            // 24-10-2007 - added check if PORT or PASV is issued, see https://issues.apache.org/jira/browse/FTPSERVER-110
+            DataConnectionFactory connFactory = session.getDataConnection();
+            if (connFactory instanceof IODataConnectionFactory) {
+                InetAddress address = ((IODataConnectionFactory)connFactory).getInetAddress();
+                if (address == null) {
+                    out.write(new DefaultFtpReply(FtpReply.REPLY_503_BAD_SEQUENCE_OF_COMMANDS,
"PORT or PASV must be issued first"));
+                    return;
+                }
             }
             
             // call Ftplet.onUploadStart() method

Modified: incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/STOU.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/STOU.java?rev=589178&r1=589177&r2=589178&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/STOU.java (original)
+++ incubator/ftpserver/trunk/core/src/java/org/apache/ftpserver/command/STOU.java Sat Oct
27 11:56:21 2007
@@ -21,10 +21,13 @@
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.net.InetAddress;
 import java.net.SocketException;
 
 import org.apache.ftpserver.DefaultFtpReply;
 import org.apache.ftpserver.FtpSessionImpl;
+import org.apache.ftpserver.IODataConnectionFactory;
+import org.apache.ftpserver.ftplet.DataConnectionFactory;
 import org.apache.ftpserver.ftplet.FileObject;
 import org.apache.ftpserver.ftplet.FileSystemView;
 import org.apache.ftpserver.ftplet.DataConnection;
@@ -65,6 +68,15 @@
                         FtpReplyOutput out) throws IOException, FtpException {
         
         try {
+        	// 24-10-2007 - added check if PORT or PASV is issued, see https://issues.apache.org/jira/browse/FTPSERVER-110
+            DataConnectionFactory connFactory = session.getDataConnection();
+            if (connFactory instanceof IODataConnectionFactory) {
+                InetAddress address = ((IODataConnectionFactory)connFactory).getInetAddress();
+                if (address == null) {
+                    out.write(new DefaultFtpReply(FtpReply.REPLY_503_BAD_SEQUENCE_OF_COMMANDS,
"PORT or PASV must be issued first"));
+                    return;
+                }
+            }
         
             // reset state variables
             session.resetState();

Added: incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/ActiveModeReplyTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/ActiveModeReplyTest.java?rev=589178&view=auto
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/ActiveModeReplyTest.java
(added)
+++ incubator/ftpserver/trunk/core/src/test/org/apache/ftpserver/clienttests/ActiveModeReplyTest.java
Sat Oct 27 11:56:21 2007
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ftpserver.clienttests;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.net.ftp.FTPClient;
+import org.apache.commons.net.ftp.FTPClientConfig;
+import org.apache.ftpserver.test.TestUtil;
+
+
+public class ActiveModeReplyTest extends ClientTestTemplate {
+    private static final File TEST_TMP_DIR = new File("test-tmp");
+    private static final File TEST_FILE = new File(ROOT_DIR, "test.txt");
+    private static final File TEST_FILE1 = new File(TEST_TMP_DIR, "test1.txt");
+
+    private static byte[] testData;
+
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        TEST_FILE1.createNewFile();
+        assertTrue(TEST_FILE1.exists());
+
+        testData = ("TESTDATA").getBytes("UTF-8");
+        TestUtil.writeDataToFile(TEST_FILE, testData);
+        assertTrue(TEST_FILE.exists());
+
+
+        FTPClientConfig config = new FTPClientConfig ("UNIX");
+        client.configure(config);
+
+        client.login(ADMIN_USERNAME, ADMIN_PASSWORD);
+    }
+
+
+    public void testStoreInActiveModeIfNotAllowed() throws Exception {
+        assertTrue(client.getDataConnectionMode() == FTPClient.ACTIVE_LOCAL_DATA_CONNECTION_MODE);
+
+        sendCommand("APPE " + TEST_FILE1.getAbsolutePath());
+        sendCommand("LIST");
+        sendCommand("MLSD");
+        sendCommand("NLST");
+        sendCommand("RETR " + TEST_FILE.getName());
+        sendCommand("STOR " + TEST_FILE1.getAbsolutePath());
+        sendCommand("STOU");
+    }
+
+    private void sendCommand(final String command) throws IOException
+    {
+        final int returnCode = client.sendCommand(command);
+        assertEquals(503, returnCode);
+        assertEquals("503 PORT or PASV must be issued first", client.getReplyString().trim());
+    }
+
+}
+ 
\ No newline at end of file



Mime
View raw message