Update all copyright messages to cover 1995 - 2009. Remove tab from exim_checkaccess.src
[exim.git] / src / src / routers / rf_lookup_hostlist.c
index cea4c3d6f5929b43bac762358a47b097bca10d2f..b47d3283581f62e78e2f73cb96bfc05aa711f8c1 100644 (file)
@@ -1,10 +1,10 @@
-/* $Cambridge: exim/src/src/routers/rf_lookup_hostlist.c,v 1.6 2006/02/07 11:19:02 ph10 Exp $ */
+/* $Cambridge: exim/src/src/routers/rf_lookup_hostlist.c,v 1.11 2009/11/16 19:50:38 nm4 Exp $ */
 
 /*************************************************
 *     Exim - an Internet mail transport agent    *
 *************************************************/
 
-/* Copyright (c) University of Cambridge 1995 - 2006 */
+/* Copyright (c) University of Cambridge 1995 - 2009 */
 /* See the file NOTICE for conditions of use and distribution. */
 
 
@@ -64,13 +64,13 @@ list of MX hosts. If the first host is the local host, act according to the
 "self" option in the configuration. */
 
 prev = NULL;
-for (h = addr->host_list; h != NULL; prev = h, h = next_h)
+for (h = addr->host_list; h != NULL; h = next_h)
   {
   uschar *canonical_name;
   int rc, len, port;
 
   next_h = h->next;
-  if (h->address != NULL) continue;
+  if (h->address != NULL) { prev = h; continue; }
 
   DEBUG(D_route|D_host_lookup)
     debug_printf("finding IP address for %s\n", h->name);
@@ -106,7 +106,8 @@ for (h = addr->host_list; h != NULL; prev = h, h = next_h)
   else if (lookup_type == lk_byname || string_is_ip_address(h->name, NULL) != 0)
     {
     DEBUG(D_route|D_host_lookup) debug_printf("calling host_find_byname\n");
-    rc = host_find_byname(h, ignore_target_hosts, &canonical_name, TRUE);
+    rc = host_find_byname(h, ignore_target_hosts, HOST_FIND_QUALIFY_SINGLE,
+      &canonical_name, TRUE);
     }
 
   /* Otherwise, do a DNS lookup. If that yields "host not found", and the
@@ -129,7 +130,8 @@ for (h = addr->host_list; h != NULL; prev = h, h = next_h)
         {
         DEBUG(D_route|D_host_lookup)
           debug_printf("DNS lookup failed: trying getipnodebyname\n");
-        rc = host_find_byname(h, ignore_target_hosts, &canonical_name, TRUE);
+        rc = host_find_byname(h, ignore_target_hosts, HOST_FIND_QUALIFY_SINGLE,
+          &canonical_name, TRUE);
         }
       }
     }
@@ -155,6 +157,12 @@ for (h = addr->host_list; h != NULL; prev = h, h = next_h)
 
   if (rc == HOST_FIND_FAILED)
     {
+    if (hff_code == hff_ignore)
+      {
+      if (prev == NULL) addr->host_list = next_h; else prev->next = next_h;
+      continue;   /* With the next host, leave prev unchanged */
+      }
+
     if (hff_code == hff_pass) return PASS;
     if (hff_code == hff_decline) return DECLINE;
 
@@ -204,6 +212,12 @@ for (h = addr->host_list; h != NULL; prev = h, h = next_h)
       }
     self_send = TRUE;
     }
+
+  /* Ensure that prev is the host before next_h; this will not be h if a lookup
+  found multiple addresses or multiple MX records. */
+
+  prev = h;
+  while (prev->next != next_h) prev = prev->next;
   }
 
 return OK;