You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ba...@apache.org on 2006/03/30 14:08:47 UTC
svn commit: r390102 - in /james/server/trunk/src: conf/james-config.xml
java/org/apache/james/smtpserver/HeloCmdHandler.java
test/org/apache/james/smtpserver/SMTPServerTest.java
test/org/apache/james/smtpserver/SMTPTestConfiguration.java
Author: bago
Date: Thu Mar 30 04:08:43 2006
New Revision: 390102
URL: http://svn.apache.org/viewcvs?rev=390102&view=rev
Log:
Check for valid domain in HELO - patch by Norman Maurer (JAMES-451)
Modified:
james/server/trunk/src/conf/james-config.xml
james/server/trunk/src/java/org/apache/james/smtpserver/HeloCmdHandler.java
james/server/trunk/src/test/org/apache/james/smtpserver/SMTPServerTest.java
james/server/trunk/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java
Modified: james/server/trunk/src/conf/james-config.xml
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/conf/james-config.xml?rev=390102&r1=390101&r2=390102&view=diff
==============================================================================
--- james/server/trunk/src/conf/james-config.xml (original)
+++ james/server/trunk/src/conf/james-config.xml Thu Mar 30 04:08:43 2006
@@ -706,7 +706,11 @@
-->
<!-- The command handler configuration -->
- <handler command="HELO" class="org.apache.james.smtpserver.HeloCmdHandler"></handler>
+ <handler command="HELO" class="org.apache.james.smtpserver.HeloCmdHandler">
+ <!-- If is set to true helo is only accepted if it can be resolved
+ <checkValidHelo> false </checkValidHelo>
+ -->
+ </handler>
<handler command="EHLO" class="org.apache.james.smtpserver.EhloCmdHandler"></handler>
<handler command="AUTH" class="org.apache.james.smtpserver.AuthCmdHandler"></handler>
<handler command="VRFY" class="org.apache.james.smtpserver.VrfyCmdHandler"></handler>
Modified: james/server/trunk/src/java/org/apache/james/smtpserver/HeloCmdHandler.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/smtpserver/HeloCmdHandler.java?rev=390102&r1=390101&r2=390102&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/smtpserver/HeloCmdHandler.java (original)
+++ james/server/trunk/src/java/org/apache/james/smtpserver/HeloCmdHandler.java Thu Mar 30 04:08:43 2006
@@ -1,78 +1,119 @@
-/***********************************************************************
- * Copyright (c) 1999-2006 The Apache Software Foundation. *
- * All rights reserved. *
- * ------------------------------------------------------------------- *
- * Licensed 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.james.smtpserver;
-
-/**
- * Handles HELO command
- */
-public class HeloCmdHandler implements CommandHandler {
-
- /**
- * The name of the command handled by the command handler
- */
- private final static String COMMAND_NAME = "HELO";
-
- /**
- * The key used to store helo mode
- */
- private final static String CURRENT_HELO_MODE = "CURRENT_HELO_MODE"; // HELO or EHLO
-
- /*
- * process HELO command
- *
- * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
- **/
- public void onCommand(SMTPSession session) {
- doHELO(session, session.getCommandArgument());
-
- }
-
- /**
- * Handler method called upon receipt of a HELO command.
- * Responds with a greeting and informs the client whether
- * client authentication is required.
- *
- * @param session SMTP session object
- * @param argument the argument passed in with the command by the SMTP client
- */
- private void doHELO(SMTPSession session, String argument) {
- String responseString = null;
- if (argument == null) {
- responseString = "501 Domain address required: " + COMMAND_NAME;
- session.writeResponse(responseString);
- } else {
- session.resetState();
- session.getState().put(CURRENT_HELO_MODE, COMMAND_NAME);
- session.getResponseBuffer().append("250 ")
- .append(session.getConfigurationData().getHelloName())
- .append(" Hello ")
- .append(argument)
- .append(" (")
- .append(session.getRemoteHost())
- .append(" [")
- .append(session.getRemoteIPAddress())
- .append("])");
- responseString = session.clearResponseBuffer();
- session.writeResponse(responseString);
- }
- }
-
-
-
-
-}
+/***********************************************************************
+ * Copyright (c) 1999-2006 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.james.smtpserver;
+
+
+import java.net.UnknownHostException;
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+
+
+/**
+ * Handles HELO command
+ */
+public class HeloCmdHandler extends AbstractLogEnabled implements CommandHandler,Configurable {
+
+ /**
+ * The name of the command handled by the command handler
+ */
+ private final static String COMMAND_NAME = "HELO";
+
+ /**
+ * The key used to store helo mode
+ */
+ private final static String CURRENT_HELO_MODE = "CURRENT_HELO_MODE"; // HELO or EHLO
+
+ /**
+ * set checkValidHelo to false as default value
+ */
+ private boolean checkValidHelo = false;
+
+ /**
+ * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
+ */
+ public void configure(Configuration handlerConfiguration) throws ConfigurationException {
+ Configuration configuration = handlerConfiguration.getChild("checkValidHelo",false);
+ if(configuration != null) {
+ checkValidHelo = configuration.getValueAsBoolean();
+ }
+ }
+
+ /*
+ * process HELO command
+ *
+ * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
+ **/
+ public void onCommand(SMTPSession session) {
+ doHELO(session, session.getCommandArgument());
+
+ }
+
+ /**
+ * Handler method called upon receipt of a HELO command.
+ * Responds with a greeting and informs the client whether
+ * client authentication is required.
+ *
+ * @param session SMTP session object
+ * @param argument the argument passed in with the command by the SMTP client
+ */
+ private void doHELO(SMTPSession session, String argument) {
+ String responseString = null;
+ boolean badHelo = false;
+
+
+ // check for helo if its set in config
+ if (checkValidHelo == true) {
+
+ // try to resolv the provided helo. If it can not resolved do not accept it.
+ try {
+ org.apache.james.dnsserver.DNSServer.getByName(argument);
+ } catch (UnknownHostException e) {
+ badHelo = true;
+ responseString = "501 Helo can not resolved";
+ session.writeResponse(responseString);
+ getLogger().info(responseString);
+ }
+ }
+
+ if (argument == null) {
+ responseString = "501 Domain address required: " + COMMAND_NAME;
+ session.writeResponse(responseString);
+ getLogger().info(responseString);
+ } else if (badHelo == false) {
+ session.resetState();
+ session.getState().put(CURRENT_HELO_MODE, COMMAND_NAME);
+ session.getResponseBuffer().append("250 ")
+ .append(session.getConfigurationData().getHelloName())
+ .append(" Hello ")
+ .append(argument)
+ .append(" (")
+ .append(session.getRemoteHost())
+ .append(" [")
+ .append(session.getRemoteIPAddress())
+ .append("])");
+ responseString = session.clearResponseBuffer();
+ session.writeResponse(responseString);
+ }
+ }
+
+
+
+
+}
Modified: james/server/trunk/src/test/org/apache/james/smtpserver/SMTPServerTest.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/smtpserver/SMTPServerTest.java?rev=390102&r1=390101&r2=390102&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/smtpserver/SMTPServerTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/smtpserver/SMTPServerTest.java Thu Mar 30 04:08:43 2006
@@ -266,7 +266,49 @@
smtpProtocol1.quit();
}
+ public void testHeloResolv() throws Exception, SMTPException {
+ m_testConfiguration.setHeloResolv();
+ finishSetUp(m_testConfiguration);
+
+ MySMTPProtocol smtpProtocol1 = new MySMTPProtocol("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol1.openPort();
+
+ assertEquals("first connection taken", 1, smtpProtocol1.getState());
+
+ // no message there, yet
+ assertNull("no mail received by mail server", m_mailServer.getLastMail());
+
+ String[] helo1 = new String[] { "abgsfe3rsf.de"};
+ String[] helo2 = new String[] { "james.apache.org" };
+
+ smtpProtocol1.sendCommand("helo",helo1);
+ SMTPResponse response = smtpProtocol1.getResponse();
+ // this should give a 501 code cause the helo could not resolved
+ assertEquals("expected error: helo could not resolved", 501, response.getCode());
+
+ smtpProtocol1.sendCommand("helo", helo2);
+ SMTPResponse response2 = smtpProtocol1.getResponse();
+ // helo is resolvable. so this should give a 250 code
+ assertEquals("Helo accepted", 250, response2.getCode());
+
+ smtpProtocol1.quit();
+ }
+
+ public void testHeloResolvDefault() throws Exception, SMTPException {
+ finishSetUp(m_testConfiguration);
+
+ MySMTPProtocol smtpProtocol1 = new MySMTPProtocol("127.0.0.1", m_smtpListenerPort);
+ smtpProtocol1.openPort();
+
+ smtpProtocol1.sendCommand("helo",new String[]{"abgsfe3rsf.de"});
+ SMTPResponse response = smtpProtocol1.getResponse();
+ // helo should not be checked. so this should give a 250 code
+ assertEquals("Helo accepted", 250, response.getCode());
+
+ smtpProtocol1.quit();
+ }
+
public void testHeloEnforcement() throws Exception, SMTPException {
finishSetUp(m_testConfiguration);
Modified: james/server/trunk/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java?rev=390102&r1=390101&r2=390102&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java (original)
+++ james/server/trunk/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java Thu Mar 30 04:08:43 2006
@@ -29,6 +29,7 @@
private String m_authorizingMode = "false";
private boolean m_verifyIdentity = false;
private Integer m_connectionLimit = null;
+ private boolean m_heloResolv = false;
public SMTPTestConfiguration(int smtpListenerPort) {
super("smptserver");
@@ -71,6 +72,10 @@
public void setConnectionLimit(int iConnectionLimit) {
m_connectionLimit = new Integer(iConnectionLimit);
}
+
+ public void setHeloResolv() {
+ m_heloResolv = true;
+ }
public void init() {
@@ -86,8 +91,14 @@
handlerConfig.addChild(Util.getValuedConfiguration("maxmessagesize", "" + m_maxMessageSize));
handlerConfig.addChild(Util.getValuedConfiguration("authRequired", m_authorizingMode));
if (m_verifyIdentity) handlerConfig.addChild(Util.getValuedConfiguration("verifyIdentity", "" + m_verifyIdentity));
-
+
handlerConfig.addChild(Util.createRemoteManagerHandlerChainConfiguration());
+
+ // Add Configuration for Helo checks
+
+ DefaultConfiguration heloConfig = (DefaultConfiguration) handlerConfig.getChild("handlerchain").getChild("handler");
+ heloConfig.addChild(Util.getValuedConfiguration("checkValidHelo",m_heloResolv+""));
+
addChild(handlerConfig);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org