james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r279163 - /james/server/trunk/src/java/org/apache/james/dnsserver/DNSServer.java
Date Tue, 06 Sep 2005 22:30:46 GMT
Author: bago
Date: Tue Sep  6 15:30:39 2005
New Revision: 279163

URL: http://svn.apache.org/viewcvs?rev=279163&view=rev
Log:
James did not resolve CNAME DNS registrations (JAMES-413).
We should carefully test this change.

Modified:
    james/server/trunk/src/java/org/apache/james/dnsserver/DNSServer.java

Modified: james/server/trunk/src/java/org/apache/james/dnsserver/DNSServer.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/dnsserver/DNSServer.java?rev=279163&r1=279162&r2=279163&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/dnsserver/DNSServer.java (original)
+++ james/server/trunk/src/java/org/apache/james/dnsserver/DNSServer.java Tue Sep  6 15:30:39
2005
@@ -23,6 +23,7 @@
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.xbill.DNS.CNAMERecord;
 import org.xbill.DNS.Cache;
 import org.xbill.DNS.Credibility;
 import org.xbill.DNS.DClass;
@@ -163,7 +164,7 @@
         }
 
         cache = new Cache (DClass.IN);
-
+        
         getLogger().debug("DNSServer ...init end");
     }
 
@@ -175,6 +176,7 @@
     public String[] getDNSServers() {
         return (String[])dnsServers.toArray(new String[0]);
     }
+
     
     /**
      * <p>Return a prioritized unmodifiable list of MX records
@@ -182,28 +184,45 @@
      *
      * @param hostname domain name to look up
      *
-     * @return a unmodifiable list of MX records corresponding to
-     *         this mail domain name
+     * @return a list of MX records corresponding to this mail domain
      */
-    public Collection findMXRecords(String hostname) {
+    public List findMXRecordsRaw(String hostname) {
         Record answers[] = lookup(hostname, Type.MX);
         List servers = new ArrayList();
-        try {
-            if (answers == null) {
-                return servers;
-            }
+        if (answers == null) {
+            return servers;
+        }
 
-            MXRecord mxAnswers[] = new MXRecord[answers.length];
-            for (int i = 0; i < answers.length; i++) {
-                mxAnswers[i] = (MXRecord)answers[i];
-            }
+        MXRecord mxAnswers[] = new MXRecord[answers.length];
+        for (int i = 0; i < answers.length; i++) {
+            mxAnswers[i] = (MXRecord)answers[i];
+        }
 
-            Arrays.sort(mxAnswers, mxComparator);
+        Arrays.sort(mxAnswers, mxComparator);
 
-            for (int i = 0; i < mxAnswers.length; i++) {
-                servers.add(mxAnswers[i].getTarget ().toString ());
-                getLogger().debug(new StringBuffer("Found MX record ").append(mxAnswers[i].getTarget
().toString ()).toString());
-            }
+        for (int i = 0; i < mxAnswers.length; i++) {
+            servers.add(mxAnswers[i].getTarget ().toString ());
+            getLogger().debug(new StringBuffer("Found MX record ").append(mxAnswers[i].getTarget
().toString ()).toString());
+        }
+        return servers;
+    }
+    
+    /**
+     * <p>Return a prioritized unmodifiable list of host handling mail
+     * for the domain.</p>
+     * 
+     * <p>First lookup MX hosts, then MX hosts of the CNAME adress, and
+     * if no server is found return the IP of the hostname</p>
+     *
+     * @param hostname domain name to look up
+     *
+     * @return a unmodifiable list of handling servers corresponding to
+     *         this mail domain name
+     */
+    public Collection findMXRecords(String hostname) {
+        List servers = new ArrayList();
+        try {
+            servers = findMXRecordsRaw(hostname);
             return Collections.unmodifiableCollection(servers);
         } finally {
             //If we found no results, we'll add the original domain name if
@@ -215,18 +234,33 @@
                             .append(hostname)
                             .append(".");
                 getLogger().info(logBuffer.toString());
-                try {
-                    getByName(hostname);
-                    servers.add(hostname);
-                } catch (UnknownHostException uhe) {
-                    // The original domain name is not a valid host,
-                    // so we can't add it to the server list.  In this
-                    // case we return an empty list of servers
+                Record cnames[] = lookup(hostname, Type.CNAME);
+                Collection cnameMXrecords = null;
+                if (cnames!=null && cnames.length > 0) {
+                    cnameMXrecords = findMXRecordsRaw(((CNAMERecord) cnames[0]).getTarget().toString());
+                } else {
                     logBuffer = new StringBuffer(128)
-                                .append("Couldn't resolve IP address for host ")
-                                .append(hostname)
-                                .append(".");
-                    getLogger().error(logBuffer.toString());
+                            .append("Couldn't find CNAME records for domain ")
+                            .append(hostname)
+                            .append(".");
+                    getLogger().info(logBuffer.toString());
+                }
+                if (cnameMXrecords==null) {
+                    try {
+                        getByName(hostname);
+                        servers.add(hostname);
+                    } catch (UnknownHostException uhe) {
+                        // The original domain name is not a valid host,
+                        // so we can't add it to the server list.  In this
+                        // case we return an empty list of servers
+                        logBuffer = new StringBuffer(128)
+                                  .append("Couldn't resolve IP address for host ")
+                                  .append(hostname)
+                                  .append(".");
+                        getLogger().error(logBuffer.toString());
+                    }
+                } else {
+                    return cnameMXrecords;
                 }
             }
         }



---------------------------------------------------------------------
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