Author: bago
Date: Tue Apr 11 11:16:55 2006
New Revision: 393281
URL: http://svn.apache.org/viewcvs?rev=393281&view=rev
Log:
Applied patches to sender domain validity check by Norman Maurer (JAMES-465)
We probably should choose a different option that "ignoreRelayClient".
Modified:
james/server/trunk/src/conf/james-config.xml
james/server/trunk/src/java/org/apache/james/smtpserver/MailCmdHandler.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=393281&r1=393280&r2=393281&view=diff
==============================================================================
--- james/server/trunk/src/conf/james-config.xml (original)
+++ james/server/trunk/src/conf/james-config.xml Tue Apr 11 11:16:55 2006
@@ -720,22 +720,34 @@
<handler command="VRFY"
class="org.apache.james.smtpserver.VrfyCmdHandler"></handler>
<handler command="EXPN"
class="org.apache.james.smtpserver.ExpnCmdHandler"></handler>
<handler command="MAIL"
class="org.apache.james.smtpserver.MailCmdHandler">
- <!-- If is set to true mail is only accepted if the sender
contains a resolvable domain
+ <!-- If is set to true mail is only accepted if the sender
contains -->
+ <!-- a resolvable domain having a valid MX Record associated!
-->
<checkValidSenderDomain> false </checkValidSenderDomain>
-->
+ <!-- If is set to true sender domain from clients that are
allowed to -->
+ <!-- relay will not checked. Default is true. -->
+ <!--
+ <ignoreRelayClients> true </ignoreRelayClients>
+ -->
</handler>
<handler command="RCPT"
class="org.apache.james.smtpserver.RcptCmdHandler">
- <!-- If is set to a bigger value as 0 you can limit the
maximal recipients per email.
- Default is set to 0.
+ <!-- If is set to a bigger value as 0 you can limit the
maximal recipients -->
+ <!-- per email. 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).
+ <!-- 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.
+ <!-- See timeout in milliseconds to insert after the rcpt.
Only is used if -->
+ <!-- tarpitting is activated. -->
+ <!--
<tarpitSleepTime> 5000 </tarpitSleepTime>
-->
</handler>
Modified:
james/server/trunk/src/java/org/apache/james/smtpserver/MailCmdHandler.java
URL:
http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/smtpserver/MailCmdHandler.java?rev=393281&r1=393280&r2=393281&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/smtpserver/MailCmdHandler.java
(original)
+++ james/server/trunk/src/java/org/apache/james/smtpserver/MailCmdHandler.java
Tue Apr 11 11:16:55 2006
@@ -45,6 +45,8 @@
private boolean checkValidSenderDomain = false;
+ private boolean ignoreRelay = true;
+
private DNSServer dnsServer = null;
/**
@@ -58,6 +60,11 @@
throw new ConfigurationException("checkValidSenderDomain
enabled but no DNSServer service provided to SMTPServer");
}
}
+
+ Configuration configRelay =
handlerConfiguration.getChild("ignoreRelayClients",false);
+ if(configRelay != null) {
+ ignoreRelay = configRelay.getValueAsBoolean();
+ }
}
/**
@@ -191,20 +198,26 @@
}
if (checkValidSenderDomain == true) {
+
+ /**
+ * don't check if the ip address is allowed to relay. Only
check if it is set in the config.
+ */
+ if (!session.isRelayingAllowed() || !ignoreRelay) {
- // Maybe we should build a static method in
org.apache.james.dnsserver.DNSServer ?
- Collection records;
+ // Maybe we should build a static method in
org.apache.james.dnsserver.DNSServer ?
+ Collection records;
- records = dnsServer.findMXRecords(senderAddress.getHost());
- if (records == null || records.size() == 0) {
- badSenderDomain = true;
- }
+ records = dnsServer.findMXRecords(senderAddress.getHost());
+ if (records == null || records.size() == 0) {
+ badSenderDomain = true;
+ }
- // try to resolv the provided domain in the senderaddress. If
it can not resolved do not accept it.
- if (badSenderDomain) {
- responseString = "501
"+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.ADDRESS_SYNTAX_SENDER)+ "
sender " + senderAddress + " contains a domain with no valid MX records";
- session.writeResponse(responseString);
- getLogger().info(responseString);
+ // try to resolv the provided domain in the senderaddress.
If it can not resolved do not accept it.
+ if (badSenderDomain) {
+ responseString = "501
"+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.ADDRESS_SYNTAX_SENDER)+ "
sender " + senderAddress + " contains a domain with no valid MX records";
+ session.writeResponse(responseString);
+ getLogger().info(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=393281&r1=393280&r2=393281&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
Tue Apr 11 11:16:55 2006
@@ -335,12 +335,13 @@
public void testSenderDomainResolv() throws Exception, SMTPException {
m_testConfiguration.setSenderDomainResolv();
+ m_testConfiguration.setAuthorizedAddresses("192.168.0.1/32");
finishSetUp(m_testConfiguration);
-
SMTPProtocol smtpProtocol1 = new SMTPProtocol("127.0.0.1",
m_smtpListenerPort);
smtpProtocol1.openPort();
+
assertEquals("first connection taken", 1, smtpProtocol1.getState());
// no message there, yet
@@ -377,6 +378,62 @@
smtpProtocol1.mail(new Address(sender1));
smtpProtocol1.quit();
+ }
+
+ public void testSenderDomainResolvRelayClientDefault() throws Exception,
SMTPException {
+ m_testConfiguration.setSenderDomainResolv();
+ finishSetUp(m_testConfiguration);
+
+ SMTPProtocol smtpProtocol1 = new SMTPProtocol("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());
+
+ smtpProtocol1.helo(InetAddress.getLocalHost());
+
+ String sender1 = "[EMAIL PROTECTED]";
+
+ // Both mail shold
+ smtpProtocol1.mail(new Address(sender1));
+
+ smtpProtocol1.quit();
+
+ }
+
+ public void testSenderDomainResolvRelayClient() throws Exception,
SMTPException {
+ m_testConfiguration.setSenderDomainResolv();
+ m_testConfiguration.setIgnoreRelayClients(false);
+ finishSetUp(m_testConfiguration);
+
+ SMTPProtocol smtpProtocol1 = new SMTPProtocol("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());
+
+ smtpProtocol1.helo(InetAddress.getLocalHost());
+
+ String sender1 = "[EMAIL PROTECTED]";
+ String sender2 = "[EMAIL PROTECTED]";
+
+ try {
+ smtpProtocol1.mail(new Address(sender1));
+ fail("sender should not accept");
+ } catch (SMTPException e) {
+ assertEquals("expected 501 error", 501, e.getCode());
+ }
+
+ smtpProtocol1.mail(new Address(sender2));
+
+ smtpProtocol1.quit();
+
}
public void testMaxRcpt() throws Exception, SMTPException {
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=393281&r1=393280&r2=393281&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
Tue Apr 11 11:16:55 2006
@@ -34,7 +34,9 @@
private boolean m_heloResolv = false;
private boolean m_ehloResolv = false;
private boolean m_senderDomainResolv = false;
+ private boolean m_ignoreRelayClients = true;
private int m_maxRcpt = 0;
+
public SMTPTestConfiguration(int smtpListenerPort) {
super("smptserver");
@@ -90,6 +92,10 @@
m_senderDomainResolv = true;
}
+ public void setIgnoreRelayClients(boolean ignore) {
+ m_ignoreRelayClients = ignore;
+ }
+
public void setMaxRcpt(int maxRcpt) {
m_maxRcpt = maxRcpt;
}
@@ -123,6 +129,7 @@
((DefaultConfiguration)
heloConfig[i]).addChild(Util.getValuedConfiguration("checkValidEhlo",m_ehloResolv+""));
} else if ("MAIL".equals(cmd)) {
((DefaultConfiguration)
heloConfig[i]).addChild(Util.getValuedConfiguration("checkValidSenderDomain",m_senderDomainResolv+""));
+ ((DefaultConfiguration)
heloConfig[i]).addChild(Util.getValuedConfiguration("ignoreRelayClients",m_ignoreRelayClients+""));
} else if ("RCPT".equals(cmd)) {
((DefaultConfiguration)
heloConfig[i]).addChild(Util.getValuedConfiguration("maxRcpt",m_maxRcpt+""));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]