Canonicize IPv6 addresses that are supplied via -bh or -bhc.
[exim.git] / src / src / verify.c
index 45a4c819db7a1276d61e9a9136850c3552e35897..cd2ae666c8f15b4661ed92a89c1d9f7b197bb65c 100644 (file)
@@ -1,4 +1,4 @@
-/* $Cambridge: exim/src/src/verify.c,v 1.3 2004/11/05 16:53:28 ph10 Exp $ */
+/* $Cambridge: exim/src/src/verify.c,v 1.6 2004/11/18 11:17:33 ph10 Exp $ */
 
 /*************************************************
 *     Exim - an Internet mail transport agent    *
@@ -1037,14 +1037,18 @@ while (addr_new != NULL)
           else
             {
             uschar *canonical_name;
-            host_item *host;
+            host_item *host, *nexthost;
             host_build_hostlist(&host_list, s, tf.hosts_randomize);
 
             /* Just ignore failures to find a host address. If we don't manage
-            to find any addresses, the callout will defer. */
+            to find any addresses, the callout will defer. Note that more than 
+            one address may be found for a single host, which will result in 
+            additional host items being inserted into the chain. Hence we must 
+            save the next host first. */
 
-            for (host = host_list; host != NULL; host = host->next)
+            for (host = host_list; host != NULL; host = nexthost)
               {
+              nexthost = host->next;
               if (tf.gethostbyname || string_is_ip_address(host->name, NULL))
                 (void)host_find_byname(host, NULL, &canonical_name, TRUE);
               else
@@ -1862,7 +1866,8 @@ if (Ustrncmp(ss, "net", 3) == 0 && (semicolon = Ustrchr(ss, ';')) != NULL)
     /* Adjust parameters for the type of lookup. For a query-style
     lookup, there is no file name, and the "key" is just the query. For
     a single-key lookup, the key is the current IP address, masked
-    appropriately, and reconverted to text form, with the mask appended. */
+    appropriately, and reconverted to text form, with the mask appended. 
+    For IPv6 addresses, specify dot separators instead of colons. */
 
     if (mac_islookup(search_type, lookup_querystyle))
       {
@@ -1873,7 +1878,7 @@ if (Ustrncmp(ss, "net", 3) == 0 && (semicolon = Ustrchr(ss, ';')) != NULL)
       {
       insize = host_aton(cb->host_address, incoming);
       host_mask(insize, incoming, mlen);
-      (void)host_nmtoa(insize, incoming, mlen, buffer);
+      (void)host_nmtoa(insize, incoming, mlen, buffer, '.');
       key = buffer;
       filename = semicolon + 1;
       }
@@ -2050,7 +2055,9 @@ int
 verify_check_this_host(uschar **listptr, unsigned int *cache_bits,
   uschar *host_name, uschar *host_address, uschar **valueptr)
 {
+int rc;
 unsigned int *local_cache_bits = cache_bits;
+uschar *save_host_address = deliver_host_address;
 check_host_block cb;
 cb.host_name = host_name;
 cb.host_address = host_address;
@@ -2064,9 +2071,26 @@ addresses. */
 cb.host_ipv4 = (Ustrncmp(host_address, "::ffff:", 7) == 0)?
   host_address + 7 : host_address;
 
-return match_check_list(listptr, 0, &hostlist_anchor, &local_cache_bits,
-  check_host, &cb, MCL_HOST,
-  (host_address == sender_host_address)? US"host" : host_address, valueptr);
+/* During the running of the check, put the IP address into $host_address. In 
+the case of calls from the smtp transport, it will already be there. However, 
+in other calls (e.g. when testing ignore_target_hosts), it won't. Just to be on 
+the safe side, any existing setting is preserved, though as I write this
+(November 2004) I can't see any cases where it is actually needed. */
+
+deliver_host_address = host_address;
+rc = match_check_list(
+       listptr,                                /* the list */
+       0,                                      /* separator character */
+       &hostlist_anchor,                       /* anchor pointer */
+       &local_cache_bits,                      /* cache pointer */
+       check_host,                             /* function for testing */
+       &cb,                                    /* argument for function */
+       MCL_HOST,                               /* type of check */
+       (host_address == sender_host_address)? 
+         US"host" : host_address,              /* text for debugging */
+       valueptr);                              /* where to pass back data */
+deliver_host_address = save_host_address;
+return rc; 
 }