Hopefully the final lot of test files.
[exim.git] / src / src / host.c
index f3652c3090e0907d3d6ab9c15ab0fb7913425b9f..3807ad45861fe1119f8d5f54d78cbbea79efeb49 100644 (file)
@@ -1,4 +1,4 @@
-/* $Cambridge: exim/src/src/host.c,v 1.17 2005/11/11 10:02:04 ph10 Exp $ */
+/* $Cambridge: exim/src/src/host.c,v 1.19 2005/12/06 10:25:59 ph10 Exp $ */
 
 /*************************************************
 *     Exim - an Internet mail transport agent    *
@@ -774,11 +774,16 @@ ip_address_item *next;
 
 while ((s = string_nextinlist(&list, &sep, buffer, sizeof(buffer))) != NULL)
   {
+  int ipv;
   int port = host_address_extract_port(s);            /* Leaves just the IP address */
-  if (string_is_ip_address(s, NULL) == 0)
+  if ((ipv = string_is_ip_address(s, NULL)) == 0)
     log_write(0, LOG_MAIN|LOG_PANIC_DIE, "Malformed IP address \"%s\" in %s",
       s, name);
 
+  /* Skip IPv6 addresses if IPv6 is disabled. */
+
+  if (disable_ipv6 && ipv == 6) continue;
+
   /* This use of strcpy() is OK because we have checked that s is a valid IP
   address above. The field in the ip_address_item is large enough to hold an
   IPv6 address. */
@@ -1836,13 +1841,10 @@ for (hname = sender_host_name; hname != NULL; hname = *aliases++)
   if ((rc = host_find_byname(&h, NULL, NULL, FALSE)) == HOST_FOUND)
     {
     host_item *hh;
-    uschar *address_ipv4 = (Ustrncmp(sender_host_address, "::ffff:", 7) == 0)?
-      sender_host_address + 7 : sender_host_address;
     HDEBUG(D_host_lookup) debug_printf("checking addresses for %s\n", hname);
     for (hh = &h; hh != NULL; hh = hh->next)
       {
-      if ((Ustrcmp(hh->address, (Ustrchr(hh->address, ':') == NULL)?
-          address_ipv4 : sender_host_address)) == 0)
+      if (host_is_in_net(hh->address, sender_host_address, 0))
         {
         HDEBUG(D_host_lookup) debug_printf("  %s OK\n", hh->address);
         ok = TRUE;
@@ -1968,17 +1970,17 @@ if (running_in_test_harness)
     return HOST_FIND_AGAIN;
   }
 
-/* In an IPv6 world, we need to scan for both kinds of address, so go round the
-loop twice. Note that we have ensured that AF_INET6 is defined even in an IPv4
-world, which makes for slightly tidier code. However, if dns_ipv4_lookup
-matches the domain, we also just do IPv4 lookups here (except when testing
-standalone). */
+/* In an IPv6 world, unless IPv6 has been disabled, we need to scan for both
+kinds of address, so go round the loop twice. Note that we have ensured that
+AF_INET6 is defined even in an IPv4 world, which makes for slightly tidier
+code. However, if dns_ipv4_lookup matches the domain, we also just do IPv4
+lookups here (except when testing standalone). */
 
 #if HAVE_IPV6
   #ifndef STAND_ALONE
-  if (dns_ipv4_lookup != NULL &&
+  if (disable_ipv6 || (dns_ipv4_lookup != NULL &&
         match_isinlist(host->name, &dns_ipv4_lookup, 0, NULL, NULL, MCL_DOMAIN,
-          TRUE, NULL) == OK)
+          TRUE, NULL) == OK))
     { af = AF_INET; times = 1; }
   else
   #endif  /* STAND_ALONE */
@@ -2252,18 +2254,18 @@ if (allow_ip && string_is_ip_address(host->name, NULL) != 0)
   return HOST_FOUND;
   }
 
-/* On an IPv6 system, go round the loop up to three times, looking for A6 and
-AAAA records the first two times. However, unless doing standalone testing, we
-force an IPv4 lookup if the domain matches dns_ipv4_lookup is set. Since A6
-records look like being abandoned, support them only if explicitly configured
-to do so. On an IPv4 system, go round the loop once only, looking only for A
-records. */
+/* On an IPv6 system, unless IPv6 is disabled, go round the loop up to three
+times, looking for A6 and AAAA records the first two times. However, unless
+doing standalone testing, we force an IPv4 lookup if the domain matches
+dns_ipv4_lookup is set. Since A6 records look like being abandoned, support
+them only if explicitly configured to do so. On an IPv4 system, go round the
+loop once only, looking only for A records. */
 
 #if HAVE_IPV6
   #ifndef STAND_ALONE
-    if (dns_ipv4_lookup != NULL &&
+    if (disable_ipv6 || (dns_ipv4_lookup != NULL &&
         match_isinlist(host->name, &dns_ipv4_lookup, 0, NULL, NULL, MCL_DOMAIN,
-        TRUE, NULL) == OK)
+        TRUE, NULL) == OK))
       i = 0;    /* look up A records only */
     else
   #endif        /* STAND_ALONE */
@@ -2896,10 +2898,14 @@ for (rr = dns_next_rr(&dnsa, &dnss, RESET_ADDITIONAL);
 
   if (rr->type != T_A
   #if HAVE_IPV6
-    && rr->type != T_AAAA
-    #ifdef SUPPORT_A6
-    && rr->type != T_A6
-    #endif
+    && ( disable_ipv6 ||
+         (
+         rr->type != T_AAAA
+         #ifdef SUPPORT_A6
+         && rr->type != T_A6
+         #endif
+         )
+       )
   #endif
     ) continue;