Here is a patch for the current trunk to resolv the wish of this report
JAMES-451...

It add support to HeloCmdHandler to only accept helo if its a resolvable
domainname.

It can be configured like:

<handler command="HELO"
class="org.apache.james.smtpserver.HeloCheckCmdHandler">
    <checkValidHelo> true </checkValidHelo>
</handler>


if no <checkValidHelo> parameter is passed it will act as it is set to
false.. Like it work now.

Would be great if someone can have a look.

bye


--- src/java/org/apache/james/smtpserver/HeloCmdHandler.java	2006-01-03 09:51:21.000000000 +0100
+++ src/java/org/apache/james/smtpserver/HeloCheckCmdHandler.java	2006-03-05 19:37:04.000000000 +0100
@@ -17,11 +17,19 @@
 
 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.james.smtpserver.CommandHandler;
+import org.apache.james.smtpserver.SMTPSession;
+
 /**
   * Handles HELO command
   */
-public class HeloCmdHandler implements CommandHandler {
-
+public class HeloCheckCmdHandler implements CommandHandler,Configurable {
+    
     /**
      * The name of the command handled by the command handler
      */
@@ -32,6 +40,22 @@
      */
     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");
+        if(configuration != null) {
+            checkValidHelo = configuration.getValueAsBoolean();
+        }
+    }
+    
     /*
      * process HELO command
      *
@@ -52,10 +76,29 @@
      */
     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);
+           }
+        }
+        
         if (argument == null) {
             responseString = "501 Domain address required: " + COMMAND_NAME;
             session.writeResponse(responseString);
-        } else {
+        } else if (badHelo == false) {
             session.resetState();
             session.getState().put(CURRENT_HELO_MODE, COMMAND_NAME);
             session.getResponseBuffer().append("250 ")
@@ -72,7 +115,4 @@
         }
     }
 
-
-
-
 }

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil

Reply via email to