Changeset 179
- Timestamp:
- 01/10/08 17:39:22 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/jsmtpd/src/org/jsmtpd/core/common/smtpExtension/IProtocolHandler.java
r175 r179 39 39 40 40 public void setSock(Socket sock) throws IOException; 41 41 42 public int getErrorCount(); 43 42 44 public boolean isSecured(); 43 45 trunk/jsmtpd/src/org/jsmtpd/core/receive/ProtocolHandler.java
r176 r179 157 157 private int maxRcpt =ReadConfig.getInstance().getIntegerProperty("maxRcpt"); 158 158 159 public void init(Socket sock,boolean secured) { 159 private int errorCount=0; 160 161 public int getErrorCount() { 162 return errorCount; 163 } 164 165 public void init(Socket sock,boolean secured) { 160 166 commandHistory=new LinkedList<String>(); 161 167 remote = ((InetSocketAddress) sock.getRemoteSocketAddress()).getAddress().getHostAddress(); // get client hostname … … 189 195 // Count errors, if it exceeds a threshold, the connection is droped because someone 190 196 // is probably trying to do something not allowed 191 int errors= 0;197 errorCount = 0; 192 198 // The last command issued 193 199 int lastCommand = -1; … … 209 215 while ((commandString = csp.readLine()) != null) 210 216 { 217 if (errorCount > 10) { 218 log.error("Max err count reached, ciao"); 219 return; 220 } 211 221 command = getCommand(commandString); 212 222 log.debug("Command: " + commandString); … … 288 298 send(MSG_INVALID_CMD); 289 299 log.error("Invalid command: " + commandString + " from " + remote); 290 errors++; 291 if (errors > 10) 292 return; 300 errorCount++; 293 301 break; 294 302 } … … 297 305 } catch (SmtpExtensionException e) { 298 306 log.error("Error executing SMTP Extensions"); 299 error s++;307 errorCount++; 300 308 } 301 309 } trunk/jsmtpd/src/org/jsmtpd/plugins/smtpExtension/SmtpAuthenticator.java
r136 r179 123 123 if (login == null) { 124 124 log.info("LOGIN Remote host issued a null login"); 125 throttle( );125 throttle(protocol); 126 126 send(wr, MSG_INVALID_CMD); 127 127 throw new SmtpExtensionException(); … … 132 132 if (pass == null) { 133 133 log.info("LOGIN Remote host issued a null password"); 134 throttle( );134 throttle(protocol); 135 135 send(wr, MSG_INVALID_CMD); 136 136 throw new SmtpExtensionException(); … … 146 146 } else { 147 147 log.info("Remote host authentication failed"); 148 throttle( );148 throttle(protocol); 149 149 send(wr, MSG_AUTH_FAILED); 150 150 throw new SmtpExtensionException(); … … 187 187 } 188 188 189 private void throttle() { 190 log.info("Waiting 5 secs before retry"); 189 private void throttle(IProtocolHandler handler) { 190 long waitTime = Math.round(Math.exp(handler.getErrorCount())); 191 log.info("Waiting "+waitTime+" secs before retry"); 191 192 Object o = new Object(); 192 193 synchronized (o) { 193 194 try { 194 195 o.wait(5000); 195 o.wait(waitTime*1000); 196 196 } catch (InterruptedException e) { 197 197 }
