Author: bago
Date: Fri Apr  7 07:04:10 2006
New Revision: 392293

URL: http://svn.apache.org/viewcvs?rev=392293&view=rev
Log:
Tarpit support (JAMES-471)
Feature provided by Norman Maurer

Modified:
    james/server/trunk/src/conf/james-config.xml
    james/server/trunk/src/java/org/apache/james/smtpserver/RcptCmdHandler.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=392293&r1=392292&r2=392293&view=diff
==============================================================================
--- james/server/trunk/src/conf/james-config.xml (original)
+++ james/server/trunk/src/conf/james-config.xml Fri Apr  7 07:04:10 2006
@@ -729,6 +729,15 @@
                      Default is set to 0.
                 <maxRcpt> 0 </maxRcpt>
                 -->
+                
+                <!-- If is set to a bigger value as 0 you can set the 
recipients after which tarpitting get activated.
+                        Tarpitting is a method to insert a small sleep after 
each rcpt. For more infos read this: 
+                        http://www.palomine.net/qmail/tarpit.html .Default is 
set to 0 (disabled).
+                <tarpitRcptCount> 0 </tarpitRcptCount>
+                -->
+                <!-- See timeout in milliseconds to insert after the rcpt. 
Only is used if tarpitting is activated.
+                <tarpitSleepTime> 5000 </tarpitSleepTime>
+                -->
             </handler>
             <handler command="DATA" 
class="org.apache.james.smtpserver.DataCmdHandler"></handler>
             <handler command="RSET" 
class="org.apache.james.smtpserver.RsetCmdHandler"></handler>

Modified: 
james/server/trunk/src/java/org/apache/james/smtpserver/RcptCmdHandler.java
URL: 
http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/smtpserver/RcptCmdHandler.java?rev=392293&r1=392292&r2=392293&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/smtpserver/RcptCmdHandler.java 
(original)
+++ james/server/trunk/src/java/org/apache/james/smtpserver/RcptCmdHandler.java 
Fri Apr  7 07:04:10 2006
@@ -40,6 +40,8 @@
      */
     private final static String RCPTCOUNT = "RCPT_COUNT";
     private int maxRcpt = 0;
+    private int tarpitRcptCount = 0;
+    private long tarpitSleepTime = 0;
     
     /**
      * @see 
org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
@@ -49,6 +51,16 @@
         if(configuration != null) {
            maxRcpt = configuration.getValueAsInteger();
         }
+        
+        Configuration configTarpitRcptCount = 
handlerConfiguration.getChild("tarpitRcptCount",false);
+        if(configTarpitRcptCount != null) {
+           tarpitRcptCount = configTarpitRcptCount.getValueAsInteger();
+        }
+        
+        Configuration configTarpitSleepTime = 
handlerConfiguration.getChild("tarpitSleepTime",false);
+        if(configTarpitSleepTime != null) {
+           tarpitSleepTime = configTarpitSleepTime.getValueAsLong();
+        }
     }
     
     /*
@@ -73,6 +85,7 @@
         String responseString = null;
         StringBuffer responseBuffer = session.getResponseBuffer();
         boolean maxRcptReached = false;
+        boolean useTarpit = false;
         
         String recipient = null;
         if ((argument != null) && (argument.indexOf(":") > 0)) {
@@ -239,10 +252,7 @@
                 int rcptCount = 0;
             
                 // check if the key exists
-                if (session.getState().get(RCPTCOUNT) != null) {
-                    Integer rcptCountInteger = 
Integer.valueOf(session.getState().get(RCPTCOUNT).toString());
-                    rcptCount = rcptCountInteger.intValue();
-                }
+                rcptCount = getRcptCount(session);
                 
                 rcptCount++;
         
@@ -258,6 +268,21 @@
                 session.getState().put(RCPTCOUNT,Integer.toString(rcptCount));
             }
             
+            // check if we should use tarpit
+            if (tarpitRcptCount > 0) {
+                int rcptCount = 0;
+                rcptCount = getRcptCount(session);
+                rcptCount++;
+                
+                if (rcptCount > tarpitRcptCount) {
+                    useTarpit = true;                   
+                }
+                
+                // put the recipient cound in session hashtable
+                session.getState().put(RCPTCOUNT,Integer.toString(rcptCount));
+                 
+            }
+            
             if (maxRcptReached == false) {
                 rcptColl.add(recipientAddress);
                 session.getState().put(SMTPSession.RCPT_LIST, rcptColl);
@@ -265,6 +290,12 @@
                               .append(recipient)
                               .append("> OK");
                 responseString = session.clearResponseBuffer();
+                
+                if (useTarpit == true) {
+                    try {
+                        sleep(tarpitSleepTime);
+                    } catch (InterruptedException e) { }
+                }
                 session.writeResponse(responseString);
             }
         }
@@ -283,4 +314,22 @@
         }
         return sb.toString();
     } 
+    
+    
+    private int getRcptCount(SMTPSession session) {
+        int startCount = 0;
+        
+        // check if the key exists
+        if (session.getState().get(RCPTCOUNT) != null) {
+            Integer rcptCountInteger = 
Integer.valueOf(session.getState().get(RCPTCOUNT).toString());
+            return rcptCountInteger.intValue();
+        } else {
+            return startCount;
+        }
+    }
+    
+    
+    public void sleep(float timeInMillis) throws InterruptedException {
+        Thread.sleep( (long) timeInMillis );
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

  • svn commit: r392293 - in /james/server/trunk/src: conf/jam... bago

Reply via email to