Copyright updates:
[exim.git] / src / src / routers / ipliteral.c
index fa41cc41152cbab6c5a2cf26a3d2352858f359a1..0c13673064b86542a226a820a00192173134e84a 100644 (file)
@@ -1,10 +1,9 @@
-/* $Cambridge: exim/src/src/routers/ipliteral.c,v 1.1 2004/10/07 13:10:02 ph10 Exp $ */
-
 /*************************************************
 *     Exim - an Internet mail transport agent    *
 *************************************************/
 
-/* Copyright (c) University of Cambridge 1995 - 2004 */
+/* Copyright (c) University of Cambridge 1995 - 2018 */
+/* Copyright (c) The Exim Maintainers 2020 */
 /* See the file NOTICE for conditions of use and distribution. */
 
 
@@ -17,7 +16,7 @@
 empty declarations ("undefined" in the Standard) we put in a dummy value. */
 
 optionlist ipliteral_router_options[] = {
-  { "", opt_hidden, NULL }
+  { "", opt_hidden, {NULL} }
 };
 
 /* Size of the options list. An extern variable has to be used so that its
@@ -32,6 +31,17 @@ value is present to keep some compilers happy. */
 ipliteral_router_options_block ipliteral_router_option_defaults = { 0 };
 
 
+#ifdef MACRO_PREDEF
+
+/* Dummy entries */
+void ipliteral_router_init(router_instance *rblock) {}
+int ipliteral_router_entry(router_instance *rblock, address_item *addr,
+  struct passwd *pw, int verify, address_item **addr_local,
+  address_item **addr_remote, address_item **addr_new,
+  address_item **addr_succeed) {return 0;}
+
+#else   /*!MACRO_PREDEF*/
+
 
 /*************************************************
 *          Initialization entry point            *
@@ -90,7 +100,7 @@ ipliteral_router_entry(
   router_instance *rblock,        /* data for this instantiation */
   address_item *addr,             /* address we are working on */
   struct passwd *pw,              /* passwd entry after check_local_user */
-  BOOL verify,                    /* TRUE when verifying */
+  int verify,                     /* v_none/v_recipient/v_sender/v_expn */
   address_item **addr_local,      /* add it to this if it's local */
   address_item **addr_remote,     /* add it to this if it's remote */
   address_item **addr_new,        /* put new addresses on here */
@@ -101,9 +111,10 @@ ipliteral_router_options_block *ob =
   (ipliteral_router_options_block *)(rblock->options_block);
 */
 host_item *h;
-uschar *domain = addr->domain;
+const uschar *domain = addr->domain;
+const uschar *ip;
 int len = Ustrlen(domain);
-int rc;
+int rc, ipv;
 
 addr_new = addr_new;         /* Keep picky compilers happy */
 addr_succeed = addr_succeed;
@@ -111,41 +122,40 @@ addr_succeed = addr_succeed;
 DEBUG(D_route) debug_printf("%s router called for %s: domain = %s\n",
   rblock->name, addr->address, addr->domain);
 
-/* Check that the domain is an IP address enclosed in square brackets. If
-not, the router declines. Otherwise route to the single IP address, setting the
-host name to "(unnamed)". */
+/* Check that the domain is an IP address enclosed in square brackets. Remember
+to allow for the "official" form of IPv6 addresses. If not, the router
+declines. Otherwise route to the single IP address, setting the host name to
+"(unnamed)". */
 
 if (domain[0] != '[' || domain[len-1] != ']') return DECLINE;
-domain[len-1] = 0;  /* temporarily */
+ip = string_copyn(domain+1, len-2);
+if (strncmpic(ip, US"IPV6:", 5) == 0 || strncmpic(ip, US"IPV4:", 5) == 0)
+  ip += 5;
 
-if (!string_is_ip_address(domain+1, NULL))
-  {
-  domain[len-1] = ']';
+ipv = string_is_ip_address(ip, NULL);
+if (ipv == 0 || (disable_ipv6 && ipv == 6))
   return DECLINE;
-  }
 
 /* It seems unlikely that ignore_target_hosts will be used with this router,
 but if it is set, it should probably work. */
 
-if (verify_check_this_host(&(rblock->ignore_target_hosts), NULL, NULL,
-      domain + 1, NULL) == OK)
+if (verify_check_this_host(CUSS&rblock->ignore_target_hosts,
+               NULL, domain, ip, NULL) == OK)
   {
   DEBUG(D_route)
-      debug_printf("%s is in ignore_target_hosts\n", domain+1);
+      debug_printf("%s is in ignore_target_hosts\n", ip);
   addr->message = US"IP literal host explicitly ignored";
-  domain[len-1] = ']';
   return DECLINE;
   }
 
 /* Set up a host item */
 
-h = store_get(sizeof(host_item));
+h = store_get(sizeof(host_item), FALSE);
 
 h->next = NULL;
-h->address = string_copy(domain+1);
+h->address = string_copy(ip);
 h->port = PORT_NONE;
-domain[len-1] = ']';   /* restore */
-h->name = string_copy(domain);
+h->name = domain;
 h->mx = MX_NONE;
 h->status = hstatus_unknown;
 h->why = hwhy_unknown;
@@ -167,13 +177,13 @@ addr->host_list = h;
 
 /* Set up the errors address, if any. */
 
-rc = rf_get_errors_address(addr, rblock, verify, &(addr->p.errors_address));
+rc = rf_get_errors_address(addr, rblock, verify, &addr->prop.errors_address);
 if (rc != OK) return rc;
 
-/* Set up the additional and removeable headers for this address. */
+/* Set up the additional and removable headers for this address. */
 
-rc = rf_get_munge_headers(addr, rblock, &(addr->p.extra_headers),
-  &(addr->p.remove_headers));
+rc = rf_get_munge_headers(addr, rblock, &addr->prop.extra_headers,
+  &addr->prop.remove_headers);
 if (rc != OK) return rc;
 
 /* Fill in the transport, queue the address for local or remote delivery, and
@@ -192,4 +202,5 @@ return rf_queue_add(addr, addr_local, addr_remote, rblock, pw)?
   OK : DEFER;
 }
 
+#endif   /*!MACRO_PREDEF*/
 /* End of routers/ipliteral.c */