mina-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r725059 - in /mina/ftpserver/trunk/core/src: main/java/org/apache/ftpserver/command/impl/ main/java/org/apache/ftpserver/filesystem/nativefs/impl/ main/resources/org/apache/ftpserver/message/ test/java/org/apache/ftpserver/clienttests/
Date Wed, 10 Dec 2008 11:51:36 GMT
Author: dlat
Date: Wed Dec 10 03:51:35 2008
New Revision: 725059

URL: http://svn.apache.org/viewvc?rev=725059&view=rev
Log:
FTPSERVER-227 RMD command should not delete the current working directory or the any parent
of current working directory.  Report, patch & Test case provided by Sai Pullabhotla.


Modified:
    mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/RMD.java
    mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/impl/NativeFtpFile.java
    mina/ftpserver/trunk/core/src/main/resources/org/apache/ftpserver/message/FtpStatus.properties
    mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/RmDirTest.java

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/RMD.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/RMD.java?rev=725059&r1=725058&r2=725059&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/RMD.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/RMD.java Wed
Dec 10 03:51:35 2008
@@ -82,20 +82,31 @@
             return;
         }
 
-        // check permission
         fileName = file.getAbsolutePath();
-        if (!file.isRemovable()) {
+
+        // first let's make sure the path is a directory 
+        if (!file.isDirectory()) {
             session.write(LocalizedFtpReply.translate(session, request, context,
                     FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
-                    "RMD.permission", fileName));
+                    "RMD.invalid", fileName));
             return;
         }
 
-        // check file
-        if (!file.isDirectory()) {
+        // then make sure that the client did not request the deletion of 
+        // current working directory.   
+        FtpFile cwd = session.getFileSystemView().getWorkingDirectory();
+        if(file.equals(cwd)) {
+            session.write(LocalizedFtpReply.translate(session, request, context,
+                FtpReply.REPLY_450_REQUESTED_FILE_ACTION_NOT_TAKEN, "RMD.busy",
+                fileName));
+            return;
+        }
+        
+        // now check to see if the user have permission to delete this directory 
+        if (!file.isRemovable()) {
             session.write(LocalizedFtpReply.translate(session, request, context,
                     FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
-                    "RMD.invalid", fileName));
+                    "RMD.permission", fileName));
             return;
         }
 
@@ -115,6 +126,7 @@
             ftpStat.setRmdir(session, file);
 
         } else {
+        	 
             session.write(LocalizedFtpReply.translate(session, request, context,
                     FtpReply.REPLY_450_REQUESTED_FILE_ACTION_NOT_TAKEN, "RMD",
                     fileName));

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/impl/NativeFtpFile.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/impl/NativeFtpFile.java?rev=725059&r1=725058&r2=725059&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/impl/NativeFtpFile.java
(original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/impl/NativeFtpFile.java
Wed Dec 10 03:51:35 2008
@@ -517,4 +517,12 @@
 
         return resArg;
     }
+    
+    @Override
+    public boolean equals(Object obj) {
+    	if(obj != null && obj instanceof NativeFtpFile) {
+    		return this.file.equals(((NativeFtpFile) obj).file);
+    	}
+    	return false;
+    }
 }

Modified: mina/ftpserver/trunk/core/src/main/resources/org/apache/ftpserver/message/FtpStatus.properties
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/resources/org/apache/ftpserver/message/FtpStatus.properties?rev=725059&r1=725058&r2=725059&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/resources/org/apache/ftpserver/message/FtpStatus.properties
(original)
+++ mina/ftpserver/trunk/core/src/main/resources/org/apache/ftpserver/message/FtpStatus.properties
Wed Dec 10 03:51:35 2008
@@ -203,9 +203,10 @@
 550.RMD.permission=No permission to remove {output.msg}.
 550.RMD.invalid=Not a valid directory \"{output.msg}\".
 250.RMD=\"{output.msg}\" removed.
+450.RMD=Can't remove directory {output.msg}.
+450.RMD.busy=Can't remove directory {output.msg}: resource busy.
 550.RMD=Can't remove directory {output.msg}.
 
-
 501.RNFR=Syntax error in parameters or arguments.
 550.RNFR={output.msg}\: File unavailable.
 350.RNFR=Requested file action pending further information.

Modified: mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/RmDirTest.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/RmDirTest.java?rev=725059&r1=725058&r2=725059&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/RmDirTest.java
(original)
+++ mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/RmDirTest.java
Wed Dec 10 03:51:35 2008
@@ -16,21 +16,21 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
 package org.apache.ftpserver.clienttests;
 
 import java.io.File;
 
 /**
-*
-* @author The Apache MINA Project (dev@mina.apache.org)
-* @version $Rev$, $Date$
-*
-*/
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
+ *
+ */
 public class RmDirTest extends ClientTestTemplate {
-    private static final File TEST_DIR1 = new File(ROOT_DIR, "dir1");
 
+    private static final File TEST_DIR1 = new File(ROOT_DIR, "dir1");
     private static final File TEST_DIR_IN_DIR1 = new File(TEST_DIR1, "dir3");
+    private static final File TEST_CWD = new File(ROOT_DIR, "dir4");
 
     /*
      * (non-Javadoc)
@@ -52,8 +52,7 @@
 
     public void testRmdirNestedDir() throws Exception {
         assertTrue(TEST_DIR_IN_DIR1.mkdirs());
-        assertTrue(client.removeDirectory(TEST_DIR1.getName() + "/"
-                + TEST_DIR_IN_DIR1.getName()));
+        assertTrue(client.removeDirectory(TEST_DIR1.getName() + "/" + TEST_DIR_IN_DIR1.getName()));
 
         assertTrue(TEST_DIR1.exists());
         assertFalse(TEST_DIR_IN_DIR1.exists());
@@ -85,4 +84,39 @@
 
         assertTrue(TEST_DIR1.exists());
     }
+
+    public void testRmdirCurrentWorkingDirectory() throws Exception {
+        assertTrue(TEST_CWD.mkdirs());
+
+        assertTrue(client.changeWorkingDirectory("/" + TEST_CWD.getName()));
+
+        assertEquals(450, client.sendCommand("RMD ."));
+        assertTrue(TEST_CWD.exists());
+
+        assertEquals(false, client.removeDirectory("."));
+        assertTrue(TEST_CWD.exists());
+
+        assertEquals(450, client.sendCommand("RMD " + "/" + TEST_CWD.getName()));
+        assertTrue(TEST_CWD.exists());
+
+        assertEquals(false, client.removeDirectory("/" + TEST_CWD.getName()));
+        assertTrue(TEST_CWD.exists());
+
+        assertEquals(450, client.sendCommand("RMD " + "../" + TEST_CWD.getName()));
+        assertTrue(TEST_CWD.exists());
+
+        assertEquals(false, client.removeDirectory("../" + TEST_CWD.getName()));
+        assertTrue(TEST_CWD.exists());
+
+        assertEquals(450, client.sendCommand("RMD " + "././."));
+        assertTrue(TEST_CWD.exists());
+
+        assertEquals(false, client.removeDirectory("././."));
+        assertTrue(TEST_CWD.exists());
+
+        // Test for case-insensitive servers. In case it is case sensitive we'll receive
a 550 response
+        // so this test should  end successfully in both cases.
+        assertEquals(false, client.removeDirectory("/" + TEST_CWD.getName().toUpperCase()));
+        assertTrue(TEST_CWD.exists());
+    }
 }



Mime
View raw message