You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by ng...@apache.org on 2009/11/30 10:51:33 UTC
svn commit: r885367 - in /mina/ftpserver:
branches/1.0.x/core/src/main/java/org/apache/ftpserver/command/impl/
branches/1.0.x/core/src/main/resources/org/apache/ftpserver/message/
branches/1.0.x/core/src/test/java/org/apache/ftpserver/clienttests/ trun...
Author: ngn
Date: Mon Nov 30 09:51:33 2009
New Revision: 885367
URL: http://svn.apache.org/viewvc?rev=885367&view=rev
Log:
Add check for non-zero port for the PORT command (FTPSERVER-341)
Fix incorrect reply codes for the PORT and EPRT commands (FTPSERVER-342)
Added:
mina/ftpserver/branches/1.0.x/core/src/test/java/org/apache/ftpserver/clienttests/PortTest.java
mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/PortTest.java
Modified:
mina/ftpserver/branches/1.0.x/core/src/main/java/org/apache/ftpserver/command/impl/EPRT.java
mina/ftpserver/branches/1.0.x/core/src/main/java/org/apache/ftpserver/command/impl/PORT.java
mina/ftpserver/branches/1.0.x/core/src/main/resources/org/apache/ftpserver/message/FtpStatus.properties
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/EPRT.java
mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/PORT.java
mina/ftpserver/trunk/core/src/main/resources/org/apache/ftpserver/message/FtpStatus.properties
Modified: mina/ftpserver/branches/1.0.x/core/src/main/java/org/apache/ftpserver/command/impl/EPRT.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/branches/1.0.x/core/src/main/java/org/apache/ftpserver/command/impl/EPRT.java?rev=885367&r1=885366&r2=885367&view=diff
==============================================================================
--- mina/ftpserver/branches/1.0.x/core/src/main/java/org/apache/ftpserver/command/impl/EPRT.java (original)
+++ mina/ftpserver/branches/1.0.x/core/src/main/java/org/apache/ftpserver/command/impl/EPRT.java Mon Nov 30 09:51:33 2009
@@ -73,7 +73,7 @@
.getDataConnectionConfiguration();
if (!dataCfg.isActiveEnabled()) {
session.write(LocalizedFtpReply.translate(session, request, context,
- 510, "EPRT.disabled", null));
+ FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "EPRT.disabled", null));
return;
}
@@ -88,7 +88,7 @@
} catch (Exception ex) {
LOG.debug("Exception parsing host and port: " + arg, ex);
session.write(LocalizedFtpReply.translate(session, request, context,
- 510, "EPRT", null));
+ FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "EPRT", null));
return;
}
@@ -104,7 +104,7 @@
session,
request,
context,
- FtpReply.REPLY_553_REQUESTED_ACTION_NOT_TAKEN_FILE_NAME_NOT_ALLOWED,
+ FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS,
"EPRT.host", null));
return;
}
@@ -116,7 +116,7 @@
.getRemoteAddress()).getAddress();
if (!dataAddr.equals(clientAddr)) {
session.write(LocalizedFtpReply.translate(session, request,
- context, 510, "EPRT.mismatch", null));
+ context, FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "EPRT.mismatch", null));
return;
}
}
@@ -134,7 +134,7 @@
session,
request,
context,
- FtpReply.REPLY_552_REQUESTED_FILE_ACTION_ABORTED_EXCEEDED_STORAGE,
+ FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS,
"EPRT.invalid", null));
return;
}
Modified: mina/ftpserver/branches/1.0.x/core/src/main/java/org/apache/ftpserver/command/impl/PORT.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/branches/1.0.x/core/src/main/java/org/apache/ftpserver/command/impl/PORT.java?rev=885367&r1=885366&r2=885367&view=diff
==============================================================================
--- mina/ftpserver/branches/1.0.x/core/src/main/java/org/apache/ftpserver/command/impl/PORT.java (original)
+++ mina/ftpserver/branches/1.0.x/core/src/main/java/org/apache/ftpserver/command/impl/PORT.java Mon Nov 30 09:51:33 2009
@@ -84,16 +84,21 @@
.getDataConnectionConfiguration();
if (!dataCfg.isActiveEnabled()) {
session.write(LocalizedFtpReply.translate(session, request, context,
- 510, "PORT.disabled", null));
+ FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "PORT.disabled", null));
return;
}
InetSocketAddress address;
try {
address = SocketAddressEncoder.decode(request.getArgument());
+
+ // port must not be 0
+ if(address.getPort() == 0) {
+ throw new IllegalPortException("PORT port must not be 0");
+ }
} catch (IllegalInetAddressException e) {
session.write(LocalizedFtpReply.translate(session, request, context,
- 510, "PORT", null));
+ FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "PORT", null));
return;
} catch (IllegalPortException e) {
LOG.debug("Invalid data port: " + request.getArgument(), e);
@@ -103,7 +108,7 @@
session,
request,
context,
- FtpReply.REPLY_552_REQUESTED_FILE_ACTION_ABORTED_EXCEEDED_STORAGE,
+ FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS,
"PORT.invalid", null));
return;
} catch (UnknownHostException e) {
@@ -114,7 +119,7 @@
session,
request,
context,
- FtpReply.REPLY_553_REQUESTED_ACTION_NOT_TAKEN_FILE_NAME_NOT_ALLOWED,
+ FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS,
"PORT.host", null));
return;
}
@@ -126,7 +131,7 @@
.getRemoteAddress()).getAddress();
if (!address.getAddress().equals(clientAddr)) {
session.write(LocalizedFtpReply.translate(session, request,
- context, 510, "PORT.mismatch", null));
+ context, FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "PORT.mismatch", null));
return;
}
}
Modified: mina/ftpserver/branches/1.0.x/core/src/main/resources/org/apache/ftpserver/message/FtpStatus.properties
URL: http://svn.apache.org/viewvc/mina/ftpserver/branches/1.0.x/core/src/main/resources/org/apache/ftpserver/message/FtpStatus.properties?rev=885367&r1=885366&r2=885367&view=diff
==============================================================================
--- mina/ftpserver/branches/1.0.x/core/src/main/resources/org/apache/ftpserver/message/FtpStatus.properties (original)
+++ mina/ftpserver/branches/1.0.x/core/src/main/resources/org/apache/ftpserver/message/FtpStatus.properties Mon Nov 30 09:51:33 2009
@@ -57,11 +57,10 @@
450.DELE=Can't delete file {output.msg}.
501.EPRT=Syntax error in parameters or arguments.
-510.EPRT=Syntax error in parameters.
-510.EPRT.disabled=EPRT is disabled.
-510.EPRT.mismatch=EPRT IP is not same as {client.ip}.
-553.EPRT.host=Host unknown.
-552.EPRT.invalid=Not a valid port number.
+501.EPRT.disabled=EPRT is disabled.
+501.EPRT.mismatch=EPRT IP is not same as {client.ip}.
+501.EPRT.host=Host unknown.
+501.EPRT.invalid=Not a valid port number.
200.EPRT=Command EPRT okay.
425.EPSV=Can't open passive connection.
@@ -167,11 +166,10 @@
200.PBSZ=Command PBSZ okay.
501.PORT=Syntax error in parameters or arguments.
-510.PORT=Syntax error in parameters.
-510.PORT.disabled=PORT is disabled.
-510.PORT.mismatch=PORT IP is not same as {client.ip}.
-553.PORT.host=Host unknown.
-552.PORT.invalid=Not a valid port number.
+501.PORT.disabled=PORT is disabled.
+501.PORT.mismatch=PORT IP is not same as {client.ip}.
+501.PORT.host=Host unknown.
+501.PORT.invalid=Not a valid port number.
200.PORT=Command PORT okay.
501.PROT=Syntax error in parameters or arguments.
Added: mina/ftpserver/branches/1.0.x/core/src/test/java/org/apache/ftpserver/clienttests/PortTest.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/branches/1.0.x/core/src/test/java/org/apache/ftpserver/clienttests/PortTest.java?rev=885367&view=auto
==============================================================================
--- mina/ftpserver/branches/1.0.x/core/src/test/java/org/apache/ftpserver/clienttests/PortTest.java (added)
+++ mina/ftpserver/branches/1.0.x/core/src/test/java/org/apache/ftpserver/clienttests/PortTest.java Mon Nov 30 09:51:33 2009
@@ -0,0 +1,41 @@
+/*
+ * 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.net.InetAddress;
+
+/**
+*
+* @author <a href="http://mina.apache.org">Apache MINA Project</a>
+*
+*/
+public class PortTest extends ClientTestTemplate {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ client.login(ADMIN_USERNAME, ADMIN_PASSWORD);
+ }
+
+ public void testInvalidIpAndPort() throws Exception {
+ assertEquals(501, client.port(InetAddress.getByName("0.0.0.0"), 0));
+ }
+
+}
Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/EPRT.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/EPRT.java?rev=885367&r1=885366&r2=885367&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/EPRT.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/EPRT.java Mon Nov 30 09:51:33 2009
@@ -73,7 +73,7 @@
.getDataConnectionConfiguration();
if (!dataCfg.isActiveEnabled()) {
session.write(LocalizedFtpReply.translate(session, request, context,
- 510, "EPRT.disabled", null));
+ FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "EPRT.disabled", null));
return;
}
@@ -88,7 +88,7 @@
} catch (Exception ex) {
LOG.debug("Exception parsing host and port: " + arg, ex);
session.write(LocalizedFtpReply.translate(session, request, context,
- 510, "EPRT", null));
+ FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "EPRT", null));
return;
}
@@ -104,7 +104,7 @@
session,
request,
context,
- FtpReply.REPLY_553_REQUESTED_ACTION_NOT_TAKEN_FILE_NAME_NOT_ALLOWED,
+ FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS,
"EPRT.host", null));
return;
}
@@ -116,7 +116,7 @@
.getRemoteAddress()).getAddress();
if (!dataAddr.equals(clientAddr)) {
session.write(LocalizedFtpReply.translate(session, request,
- context, 510, "EPRT.mismatch", null));
+ context, FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "EPRT.mismatch", null));
return;
}
}
@@ -134,7 +134,7 @@
session,
request,
context,
- FtpReply.REPLY_552_REQUESTED_FILE_ACTION_ABORTED_EXCEEDED_STORAGE,
+ FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS,
"EPRT.invalid", null));
return;
}
Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/PORT.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/PORT.java?rev=885367&r1=885366&r2=885367&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/PORT.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/PORT.java Mon Nov 30 09:51:33 2009
@@ -84,16 +84,21 @@
.getDataConnectionConfiguration();
if (!dataCfg.isActiveEnabled()) {
session.write(LocalizedFtpReply.translate(session, request, context,
- 510, "PORT.disabled", null));
+ FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "PORT.disabled", null));
return;
}
InetSocketAddress address;
try {
address = SocketAddressEncoder.decode(request.getArgument());
+
+ // port must not be 0
+ if(address.getPort() == 0) {
+ throw new IllegalPortException("PORT port must not be 0");
+ }
} catch (IllegalInetAddressException e) {
session.write(LocalizedFtpReply.translate(session, request, context,
- 510, "PORT", null));
+ FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "PORT", null));
return;
} catch (IllegalPortException e) {
LOG.debug("Invalid data port: " + request.getArgument(), e);
@@ -103,7 +108,7 @@
session,
request,
context,
- FtpReply.REPLY_552_REQUESTED_FILE_ACTION_ABORTED_EXCEEDED_STORAGE,
+ FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS,
"PORT.invalid", null));
return;
} catch (UnknownHostException e) {
@@ -114,7 +119,7 @@
session,
request,
context,
- FtpReply.REPLY_553_REQUESTED_ACTION_NOT_TAKEN_FILE_NAME_NOT_ALLOWED,
+ FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS,
"PORT.host", null));
return;
}
@@ -126,7 +131,7 @@
.getRemoteAddress()).getAddress();
if (!address.getAddress().equals(clientAddr)) {
session.write(LocalizedFtpReply.translate(session, request,
- context, 510, "PORT.mismatch", null));
+ context, FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "PORT.mismatch", null));
return;
}
}
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=885367&r1=885366&r2=885367&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 Mon Nov 30 09:51:33 2009
@@ -57,11 +57,10 @@
450.DELE=Can't delete file {output.msg}.
501.EPRT=Syntax error in parameters or arguments.
-510.EPRT=Syntax error in parameters.
-510.EPRT.disabled=EPRT is disabled.
-510.EPRT.mismatch=EPRT IP is not same as {client.ip}.
-553.EPRT.host=Host unknown.
-552.EPRT.invalid=Not a valid port number.
+501.EPRT.disabled=EPRT is disabled.
+501.EPRT.mismatch=EPRT IP is not same as {client.ip}.
+501.EPRT.host=Host unknown.
+501.EPRT.invalid=Not a valid port number.
200.EPRT=Command EPRT okay.
425.EPSV=Can't open passive connection.
@@ -167,11 +166,10 @@
200.PBSZ=Command PBSZ okay.
501.PORT=Syntax error in parameters or arguments.
-510.PORT=Syntax error in parameters.
-510.PORT.disabled=PORT is disabled.
-510.PORT.mismatch=PORT IP is not same as {client.ip}.
-553.PORT.host=Host unknown.
-552.PORT.invalid=Not a valid port number.
+501.PORT.disabled=PORT is disabled.
+501.PORT.mismatch=PORT IP is not same as {client.ip}.
+501.PORT.host=Host unknown.
+501.PORT.invalid=Not a valid port number.
200.PORT=Command PORT okay.
501.PROT=Syntax error in parameters or arguments.
Added: mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/PortTest.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/PortTest.java?rev=885367&view=auto
==============================================================================
--- mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/PortTest.java (added)
+++ mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/PortTest.java Mon Nov 30 09:51:33 2009
@@ -0,0 +1,41 @@
+/*
+ * 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.net.InetAddress;
+
+/**
+*
+* @author <a href="http://mina.apache.org">Apache MINA Project</a>
+*
+*/
+public class PortTest extends ClientTestTemplate {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ client.login(ADMIN_USERNAME, ADMIN_PASSWORD);
+ }
+
+ public void testInvalidIpAndPort() throws Exception {
+ assertEquals(501, client.port(InetAddress.getByName("0.0.0.0"), 0));
+ }
+
+}