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 no...@apache.org on 2003/03/01 01:53:01 UTC
cvs commit: jakarta-james/src/java/org/apache/james/transport/matchers RemoteAddrInNetwork.java RemoteAddrNotInNetwork.java
noel 2003/02/28 16:53:01
Modified: src/java/org/apache/james/transport/matchers
RemoteAddrInNetwork.java
RemoteAddrNotInNetwork.java
Log:
Reverted changes. Accidently checked in CIDR-based matchers when updating the licenses.
Revision Changes Path
1.7 +61 -19 jakarta-james/src/java/org/apache/james/transport/matchers/RemoteAddrInNetwork.java
Index: RemoteAddrInNetwork.java
===================================================================
RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/transport/matchers/RemoteAddrInNetwork.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- RemoteAddrInNetwork.java 27 Feb 2003 06:23:47 -0000 1.6
+++ RemoteAddrInNetwork.java 1 Mar 2003 00:53:01 -0000 1.7
@@ -58,30 +58,72 @@
package org.apache.james.transport.matchers;
+import org.apache.mailet.GenericMatcher;
import org.apache.mailet.Mail;
+
import javax.mail.MessagingException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.util.Collection;
+import java.util.Iterator;
+import java.util.StringTokenizer;
+import java.util.Vector;
/**
- * <P>This implments the CIDR ( slash notation ) method for determining sub-networks.
- * <UL>Networks can be indicated with
- * <LI>wildcards(*) 192.168.*
- * <LI>by name 'domain.tld'
- * <LI>slash notation 192.168.100.0/24
- * </UL>
- * <BR>Note: All representations will be converted to CIDR notation and matches are made
- * based on a target IPAddress against a CIDR string.
- * <BR>Multiple addresses can be indicated, e.g: '127.0.0.1,192.168.*,domain.tld'
- *
- * Checks the IP address of the sending server against the CIDR
- * Collection, returns the list of recipients if there is a match.
- *
- * @see GenericNetworkMatcher.init()
- */
+ * Checks the IP address of the sending server against a comma-
+ * delimited list of IP addresses or domain names.
+ * <P>Networks should be indicated with a wildcard *, e.g. 192.168.*
+ * <br>Note: The wildcard can go at any level, the matcher will match if the
+ * sending host's IP address (as a String based on the octet representation)
+ * starts with the String indicated in the configuration file, excluding the
+ * wildcard.
+ * <p>Multiple addresses can be indicated, e.g: '127.0.0.1,192.168.*,domain.tld'
+ *
+ * @author Serge Knystautas <se...@lokitech.com>
+ */
+public class RemoteAddrInNetwork extends GenericMatcher {
+ private Collection networks = null;
+
+ public void init() throws MessagingException {
+ StringTokenizer st = new StringTokenizer(getCondition(), ", ", false);
+ networks = new Vector();
+ while (st.hasMoreTokens()) {
+ String addr = st.nextToken();
+ if (addr.equals("127.0.0.1")) {
+ //Add address of local machine as a match
+ try {
+ InetAddress localaddr = InetAddress.getLocalHost();
+ networks.add(localaddr.getHostAddress());
+ } catch (UnknownHostException uhe) {
+ }
+ }
+
+ try {
+ if (addr.endsWith("*")) {
+ addr = addr.substring(0, addr.length() - 1);
+ }
+ else {
+ addr = InetAddress.getByName(addr).getHostAddress();
+ }
+ networks.add(addr);
+ } catch (UnknownHostException uhe) {
+ log("Cannot match against invalid domain: " + uhe.getMessage());
+ }
+ }
+ }
-public class RemoteAddrInNetwork extends GenericNetworkMatcher {
- public Collection match(Mail mail) throws MessagingException {
- // if it matches, then we do want to execute the mailet
- return matchNetwork(mail) ? mail.getRecipients() : null;
+ public Collection match(Mail mail) {
+ String host = mail.getRemoteAddr();
+ //Check to see whether it's in any of the networks... needs to be smarter to
+ // support subnets better
+ for (Iterator i = networks.iterator(); i.hasNext(); ) {
+ String networkAddr = i.next().toString();
+ if (host.startsWith(networkAddr)) {
+ //This is in this network... that's all we need for a match
+ return mail.getRecipients();
+ }
+ }
+ //Could not match this to any network
+ return null;
}
}
1.7 +61 -21 jakarta-james/src/java/org/apache/james/transport/matchers/RemoteAddrNotInNetwork.java
Index: RemoteAddrNotInNetwork.java
===================================================================
RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/transport/matchers/RemoteAddrNotInNetwork.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- RemoteAddrNotInNetwork.java 27 Feb 2003 06:23:47 -0000 1.6
+++ RemoteAddrNotInNetwork.java 1 Mar 2003 00:53:01 -0000 1.7
@@ -58,32 +58,72 @@
package org.apache.james.transport.matchers;
+import org.apache.mailet.GenericMatcher;
import org.apache.mailet.Mail;
+
import javax.mail.MessagingException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.util.Collection;
+import java.util.Iterator;
+import java.util.StringTokenizer;
+import java.util.Vector;
/**
- * <P>This implments the CIDR ( slash notation ) method for determining sub-networks.
- * <UL>Networks can be indicated with
- * <LI>wildcards(*) 192.168.*
- * <LI>by name 'domain.tld'
- * <LI>slash notation 192.168.100.0/24
- * </UL>
- * <BR>Note: All representations will be converted to CIDR notation and matches are made
- * based on a target IPAddress against a CIDR string.
- * <BR>Multiple addresses can be indicated, e.g: '127.0.0.1,192.168.*,domain.tld'
- *
- * Checks the IP address of the sending server against the CIDR
- * Collection, returns null if there is a match.
- *
- * @see GenericNetworkMatcher.init()
- */
+ * Checks the IP address of the sending server against a comma-
+ * delimited list of IP addresses or domain names.
+ * <P>Networks should be indicated with a wildcard *, e.g. 192.168.*
+ * <br>Note: The wildcard can go at any level, the matcher will match if the
+ * sending host's IP address (as a String based on the octet representation)
+ * starts with the String indicated in the configuration file, excluding the
+ * wildcard.
+ * <p>Multiple addresses can be indicated, e.g: '127.0.0.1,192.168.*,domain.tld'
+ *
+ * @author Serge Knystautas <se...@lokitech.com>
+ */
+public class RemoteAddrNotInNetwork extends GenericMatcher {
+ private Collection networks = null;
-public class RemoteAddrNotInNetwork extends GenericNetworkMatcher {
- public Collection match(Mail mail) throws MessagingException {
- // if it matches, then we do NOT want to execute the mailet
- return matchNetwork(mail) ? null : mail.getRecipients();
- }
-}
+ public void init() throws MessagingException {
+ StringTokenizer st = new StringTokenizer(getCondition(), ", ", false);
+ networks = new Vector();
+ while (st.hasMoreTokens()) {
+ String addr = st.nextToken();
+ if (addr.equals("127.0.0.1")) {
+ //Add address of local machine as a match
+ try {
+ InetAddress localaddr = InetAddress.getLocalHost();
+ networks.add(localaddr.getHostAddress());
+ } catch (UnknownHostException uhe) {
+ }
+ }
+ try {
+ if (addr.endsWith("*")) {
+ addr = addr.substring(0, addr.length() - 1);
+ }
+ else {
+ addr = InetAddress.getByName(addr).getHostAddress();
+ }
+ networks.add(addr);
+ } catch (UnknownHostException uhe) {
+ log("Cannot match against invalid domain: " + uhe.getMessage());
+ }
+ }
+ }
+ public Collection match(Mail mail) {
+ String host = mail.getRemoteAddr();
+ //Check to see whether it's in any of the networks... needs to be smarter to
+ // support subnets better
+ for (Iterator i = networks.iterator(); i.hasNext(); ) {
+ String invalidNetwork = i.next().toString();
+ if (host.startsWith(invalidNetwork)) {
+ //This is in this network... that's all we need for a failed match
+ return null;
+ }
+ }
+ //Could not match this to any network
+ return mail.getRecipients();
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: james-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: james-dev-help@jakarta.apache.org