james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject cvs commit: james-server/src/java/org/apache/james/util NetMatcher.java
Date Sun, 02 May 2004 06:08:37 GMT
noel        2004/05/01 23:08:37

  Modified:    src/java/org/apache/james/dnsserver Tag: branch_2_1_fcs
                        DNSServer.java
               src/java/org/apache/james/fetchmail Tag: branch_2_1_fcs
                        MessageProcessor.java
               src/java/org/apache/james/transport/mailets Tag:
                        branch_2_1_fcs RemoteDelivery.java
               src/java/org/apache/james/transport/matchers Tag:
                        branch_2_1_fcs InSpammerBlacklist.java
               src/java/org/apache/james/util Tag: branch_2_1_fcs
                        NetMatcher.java
  Log:
  Fix for JAMES-271.  Allow get[All]ByName(String host) when the host is actually an IP literal
with a trailing '.'.  java.net.InetAddress permits this, but org.xbill.DNS.Address does not.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.9.4.18  +40 -0     james-server/src/java/org/apache/james/dnsserver/DNSServer.java
  
  Index: DNSServer.java
  ===================================================================
  RCS file: /home/cvs/james-server/src/java/org/apache/james/dnsserver/DNSServer.java,v
  retrieving revision 1.9.4.17
  retrieving revision 1.9.4.18
  diff -u -r1.9.4.17 -r1.9.4.18
  --- DNSServer.java	21 Apr 2004 03:36:56 -0000	1.9.4.17
  +++ DNSServer.java	2 May 2004 06:08:37 -0000	1.9.4.18
  @@ -429,6 +429,46 @@
           };
       }
   
  +    /* java.net.InetAddress.get[All]ByName(String) allows an IP literal
  +     * to be passed, and will recognize it even with a trailing '.'.
  +     * However, org.xbill.DNS.Address does not recognize an IP literal
  +     * with a trailing '.' character.  The problem is that when we
  +     * lookup an MX record for some domains, we may find an IP address,
  +     * which will have had the trailing '.' appended by the time we get
  +     * it back from dnsjava.  An MX record is not allowed to have an IP
  +     * address as the right-hand-side, but there are still plenty of
  +     * such records on the Internet.  Since java.net.InetAddress can
  +     * handle them, for the time being we've decided to support them.
  +     *
  +     * These methods are NOT intended for use outside of James, and are
  +     * NOT declared by the org.apache.james.services.DNSServer.  This is
  +     * currently a stopgap measure to be revisited for the next release.
  +     */
  +
  +    private static String allowIPLiteral(String host) {
  +        if ((host.charAt(host.length() - 1) == '.')) {
  +            String possible_ip_literal = host.substring(0, host.length() - 1);
  +            if (org.xbill.DNS.Address.isDottedQuad(possible_ip_literal)) {
  +                host = possible_ip_literal;
  +            }
  +        }
  +        return host;
  +    }
  +
  +    /**
  +     * @see java.net.InetAddress#getByName(String)
  +     */
  +    public static InetAddress getByName(String host) throws UnknownHostException {
  +        return org.xbill.DNS.Address.getByName(allowIPLiteral(host));
  +    }
  +
  +    /**
  +     * @see java.net.InetAddress#getByAllName(String)
  +     */
  +    public static InetAddress[] getAllByName(String host) throws UnknownHostException {
  +        return org.xbill.DNS.Address.getAllByName(allowIPLiteral(host));
  +    }
  +
       /**
        * A way to get mail hosts to try.  If any MX hosts are found for the
        * domain name with which this is constructed, then these MX hostnames
  
  
  
  No                   revision
  No                   revision
  1.1.2.10  +3 -3      james-server/src/java/org/apache/james/fetchmail/MessageProcessor.java
  
  Index: MessageProcessor.java
  ===================================================================
  RCS file: /home/cvs/james-server/src/java/org/apache/james/fetchmail/MessageProcessor.java,v
  retrieving revision 1.1.2.9
  retrieving revision 1.1.2.10
  diff -u -r1.1.2.9 -r1.1.2.10
  --- MessageProcessor.java	22 Apr 2004 00:19:26 -0000	1.1.2.9
  +++ MessageProcessor.java	2 May 2004 06:08:37 -0000	1.1.2.10
  @@ -1362,7 +1362,7 @@
                   hostNameEnd = domain.length();
               address = domain.substring(0, hostNameEnd);
           }
  -        validatedAddress = org.xbill.DNS.Address.getByName(address).getHostAddress();
  +        validatedAddress = org.apache.james.dnsserver.DNSServer.getByName(address).getHostAddress();
   
           return validatedAddress;
       }
  @@ -1380,8 +1380,8 @@
           // These shenanigans are required to get the fully qualified
           // hostname prior to JDK 1.4 in which get getCanonicalHostName()
           // does the job for us
  -        InetAddress addr1 = org.xbill.DNS.Address.getByName(getRemoteAddress());
  -        InetAddress addr2 = org.xbill.DNS.Address.getByName(addr1.getHostAddress());
  +        InetAddress addr1 = org.apache.james.dnsserver.DNSServer.getByName(getRemoteAddress());
  +        InetAddress addr2 = org.apache.james.dnsserver.DNSServer.getByName(addr1.getHostAddress());
           return addr2.getHostName();
       }        
   
  
  
  
  No                   revision
  No                   revision
  1.33.4.21 +2 -2      james-server/src/java/org/apache/james/transport/mailets/RemoteDelivery.java
  
  Index: RemoteDelivery.java
  ===================================================================
  RCS file: /home/cvs/james-server/src/java/org/apache/james/transport/mailets/RemoteDelivery.java,v
  retrieving revision 1.33.4.20
  retrieving revision 1.33.4.21
  diff -u -r1.33.4.20 -r1.33.4.21
  --- RemoteDelivery.java	13 Apr 2004 01:39:44 -0000	1.33.4.20
  +++ RemoteDelivery.java	2 May 2004 06:08:37 -0000	1.33.4.21
  @@ -1112,7 +1112,7 @@
                       final String nextGateway = server;
                       final String nextGatewayPort = port;
                       try {
  -                        final InetAddress[] ips = org.xbill.DNS.Address.getAllByName(nextGateway);
  +                        final InetAddress[] ips = org.apache.james.dnsserver.DNSServer.getAllByName(nextGateway);
                           addresses = new Iterator() {
                               private InetAddress[] ipAddresses = ips;
                               int i = 0;
  
  
  
  No                   revision
  No                   revision
  1.3.4.5   +1 -1      james-server/src/java/org/apache/james/transport/matchers/InSpammerBlacklist.java
  
  Index: InSpammerBlacklist.java
  ===================================================================
  RCS file: /home/cvs/james-server/src/java/org/apache/james/transport/matchers/InSpammerBlacklist.java,v
  retrieving revision 1.3.4.4
  retrieving revision 1.3.4.5
  diff -u -r1.3.4.4 -r1.3.4.5
  --- InSpammerBlacklist.java	13 Apr 2004 01:39:44 -0000	1.3.4.4
  +++ InSpammerBlacklist.java	2 May 2004 06:08:37 -0000	1.3.4.5
  @@ -63,7 +63,7 @@
               sb.append(network);
   
               //Try to look it up
  -            org.xbill.DNS.Address.getByName(sb.toString());
  +            org.apache.james.dnsserver.DNSServer.getByName(sb.toString());
   
               //If we got here, that's bad... it means the host
               //  was found in the blacklist
  
  
  
  No                   revision
  No                   revision
  1.1.2.10  +4 -4      james-server/src/java/org/apache/james/util/NetMatcher.java
  
  Index: NetMatcher.java
  ===================================================================
  RCS file: /home/cvs/james-server/src/java/org/apache/james/util/NetMatcher.java,v
  retrieving revision 1.1.2.9
  retrieving revision 1.1.2.10
  diff -u -r1.1.2.9 -r1.1.2.10
  --- NetMatcher.java	20 Apr 2004 20:42:18 -0000	1.1.2.9
  +++ NetMatcher.java	2 May 2004 06:08:37 -0000	1.1.2.10
  @@ -62,7 +62,7 @@
   
           try
           {
  -            ip = org.xbill.DNS.Address.getByName(hostIP);
  +            ip = org.apache.james.dnsserver.DNSServer.getByName(hostIP);
           }
           catch (java.net.UnknownHostException uhe)
           {
  @@ -130,7 +130,7 @@
   
       public boolean contains(final String name) throws java.net.UnknownHostException
       {
  -        return network.equals(maskIP(org.xbill.DNS.Address.getByName(name), netmask));
  +        return network.equals(maskIP(org.apache.james.dnsserver.DNSServer.getByName(name),
netmask));
       }
   
       public boolean contains(final InetAddress ip)
  @@ -164,8 +164,8 @@
               else if (netspec.indexOf('.', iSlash) == -1) netspec = normalizeFromCIDR(netspec);
           }
   
  -        return new InetNetwork(org.xbill.DNS.Address.getByName(netspec.substring(0, netspec.indexOf('/'))),
  -                               org.xbill.DNS.Address.getByName(netspec.substring(netspec.indexOf('/')
+ 1)));
  +        return new InetNetwork(org.apache.james.dnsserver.DNSServer.getByName(netspec.substring(0,
netspec.indexOf('/'))),
  +                               org.apache.james.dnsserver.DNSServer.getByName(netspec.substring(netspec.indexOf('/')
+ 1)));
       }
   
       public static InetAddress maskIP(final byte[] ip, final byte[] mask)
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message