build: use pkg-config for i18n
[exim.git] / src / src / routers / dnslookup.c
index abc41a3450ed862fb1e0029b5cbf19077027ea47..1520cc376930c656bced6ce468af6c8f115812cd 100644 (file)
@@ -2,11 +2,14 @@
 *     Exim - an Internet mail transport agent    *
 *************************************************/
 
+/* Copyright (c) The Exim Maintainers 2020 - 2024 */
 /* Copyright (c) University of Cambridge 1995 - 2018 */
-/* Copyright (c) The Exim Maintainers 2020 */
 /* See the file NOTICE for conditions of use and distribution. */
+/* SPDX-License-Identifier: GPL-2.0-or-later */
 
 #include "../exim.h"
+
+#ifdef ROUTER_DNSLOOKUP                /* Remainder of file */
 #include "rf_functions.h"
 #include "dnslookup.h"
 
@@ -42,7 +45,7 @@ int dnslookup_router_options_count =
 
 /* Dummy entries */
 dnslookup_router_options_block dnslookup_router_option_defaults = {0};
-void dnslookup_router_init(router_instance *rblock) {}
+void dnslookup_router_init(driver_instance *rblock) {}
 int dnslookup_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,
@@ -80,7 +83,7 @@ dnslookup_router_options_block dnslookup_router_option_defaults = {
 consistency checks to be done, or anything else that needs to be set up. */
 
 void
-dnslookup_router_init(router_instance *rblock)
+dnslookup_router_init(driver_instance *rblock)
 {
 /*
 dnslookup_router_options_block *ob =
@@ -150,36 +153,30 @@ host_item h;
 int rc;
 int widen_sep = 0;
 int whichrrs = HOST_FIND_BY_MX | HOST_FIND_BY_A | HOST_FIND_BY_AAAA;
-dnslookup_router_options_block *ob =
-  (dnslookup_router_options_block *)(rblock->options_block);
-uschar *srv_service = NULL;
-uschar *widen = NULL;
-const uschar *pre_widen = addr->domain;
-const uschar *post_widen = NULL;
-const uschar *fully_qualified_name;
-const uschar *listptr;
+dnslookup_router_options_block * ob =
+  (dnslookup_router_options_block *)(rblock->drinst.options_block);
+uschar * srv_service = NULL, * widen = NULL;
+const uschar * pre_widen = addr->domain, * post_widen = NULL;
+const uschar * fully_qualified_name, * listptr;
 uschar widen_buffer[256];
 
-addr_new = addr_new;          /* Keep picky compilers happy */
-addr_succeed = addr_succeed;
-
 DEBUG(D_route)
   debug_printf("%s router called for %s\n  domain = %s\n",
-    rblock->name, addr->address, addr->domain);
+    rblock->drinst.name, addr->address, addr->domain);
 
 /* If an SRV check is required, expand the service name */
 
+GET_OPTION("check_srv");
 if (ob->check_srv)
-  {
   if (  !(srv_service = expand_string(ob->check_srv))
      && !f.expand_string_forcedfail)
     {
     addr->message = string_sprintf("%s router: failed to expand \"%s\": %s",
-      rblock->name, ob->check_srv, expand_string_message);
+      rblock->drinst.name, ob->check_srv, expand_string_message);
     return DEFER;
     }
-  else whichrrs |= HOST_FIND_BY_SRV;
-  }
+  else
+    whichrrs |= HOST_FIND_BY_SRV;
 
 /* Set up the first of any widening domains. The code further down copes with
 either pre- or post-widening, but at present there is no way to turn on
@@ -207,6 +204,7 @@ if (  ob->widen_domains
    && (verify != v_sender || !ob->rewrite_headers || addr->parent))
   {
   listptr = ob->widen_domains;
+  /* not expanded so should never be tainted */
   widen = string_nextinlist(&listptr, &widen_sep, widen_buffer,
     sizeof(widen_buffer));
 
@@ -236,29 +234,30 @@ for (;;)
   else if (widen)
     {
     h.name = string_sprintf("%s.%s", addr->domain, widen);
+    /* not expanded so should never be tainted */
     widen = string_nextinlist(&listptr, &widen_sep, widen_buffer,
       sizeof(widen_buffer));
-    DEBUG(D_route) debug_printf("%s router widened %s to %s\n", rblock->name,
-      addr->domain, h.name);
+    DEBUG(D_route) debug_printf("%s router widened %s to %s\n",
+      rblock->drinst.name, addr->domain, h.name);
     }
   else if (post_widen)
     {
     h.name = post_widen;
     post_widen = NULL;
     DEBUG(D_route) debug_printf("%s router trying %s after widening failed\n",
-      rblock->name, h.name);
+      rblock->drinst.name, h.name);
     }
   else return DECLINE;
 
   /* Check if we must request only. or prefer, ipv4 */
 
   if (  ob->ipv4_only
-     && expand_check_condition(ob->ipv4_only, rblock->name, US"router"))
+     && expand_check_condition(ob->ipv4_only, rblock->drinst.name, US"router"))
     flags = flags & ~HOST_FIND_BY_AAAA | HOST_FIND_IPV4_ONLY;
   else if (f.search_find_defer)
     return DEFER;
   if (  ob->ipv4_prefer
-     && expand_check_condition(ob->ipv4_prefer, rblock->name, US"router"))
+     && expand_check_condition(ob->ipv4_prefer, rblock->drinst.name, US"router"))
     flags |= HOST_FIND_IPV4_FIRST;
   else if (f.search_find_defer)
     return DEFER;
@@ -287,10 +286,15 @@ for (;;)
     if (ob->search_parents) flags |= HOST_FIND_SEARCH_PARENTS;
     }
 
-  rc = host_find_bydns(&h, CUS rblock->ignore_target_hosts, flags,
-    srv_service, ob->srv_fail_domains, ob->mx_fail_domains,
-    &rblock->dnssec,
-    &fully_qualified_name, &removed);
+  DEBUG(D_route) debug_printf_indent("main lookup for domain\n");
+   {
+    expand_level++;
+    rc = host_find_bydns(&h, CUS rblock->ignore_target_hosts, flags,
+      srv_service, ob->srv_fail_domains, ob->mx_fail_domains,
+      &rblock->dnssec,
+      &fully_qualified_name, &removed);
+    expand_level--;
+   }
 
   if (removed) setflag(addr, af_local_host_removed);
 
@@ -310,7 +314,7 @@ for (;;)
 
       case OK:
       DEBUG(D_route) debug_printf("%s router rejected %s: no MX record(s)\n",
-        rblock->name, fully_qualified_name);
+        rblock->drinst.name, fully_qualified_name);
       continue;
       }
 
@@ -327,7 +331,7 @@ for (;;)
     if (rblock->pass_on_timeout)
       {
       DEBUG(D_route) debug_printf("%s router timed out, and pass_on_timeout is set\n",
-        rblock->name);
+        rblock->drinst.name);
       return PASS;
       }
     addr->message = US"host lookup did not complete";
@@ -347,7 +351,7 @@ for (;;)
 
       case OK:
        DEBUG(D_route) debug_printf("%s router: matched fail_defer_domains\n",
-         rblock->name);
+         rblock->drinst.name);
        addr->message = US"missing MX, or all MXs point to missing A records,"
          " and defer requested";
        return DEFER;
@@ -363,7 +367,7 @@ for (;;)
   As a common cause of this problem is MX records with IP addresses on the
   RHS, give a special message in this case. */
 
-  if (h.mx >= 0 && h.address == NULL)
+  if (h.mx >= 0 && !h.address)
     {
     setflag(addr, af_pass_message);   /* This is not a security risk */
     if (h.name[0] == 0)
@@ -457,22 +461,47 @@ if (rc != OK) return rc;
 /* Get store in which to preserve the original host item, chained on
 to the address. */
 
-addr->host_list = store_get(sizeof(host_item), FALSE);
+addr->host_list = store_get(sizeof(host_item), GET_UNTAINTED);
 addr->host_list[0] = h;
 
 /* Fill in the transport and queue the address for delivery. */
 
 if (!rf_get_transport(rblock->transport_name, &(rblock->transport),
-      addr, rblock->name, NULL))
+      addr, rblock->drinst.name, NULL))
   return DEFER;
 
 addr->transport = rblock->transport;
 
-return rf_queue_add(addr, addr_local, addr_remote, rblock, pw)?
-  OK : DEFER;
+return rf_queue_add(addr, addr_local, addr_remote, rblock, pw) ?  OK : DEFER;
 }
 
-#endif   /*!MACRO_PREDEF*/
+
+
+
+# ifdef DYNLOOKUP
+#  define dnslookup_router_info _router_info
+# endif
+
+router_info dnslookup_router_info =
+{
+.drinfo = {
+  .driver_name =       US"dnslookup",
+  .options =           dnslookup_router_options,
+  .options_count =     &dnslookup_router_options_count,
+  .options_block =     &dnslookup_router_option_defaults,
+  .options_len =       sizeof(dnslookup_router_options_block),
+  .init =              dnslookup_router_init,
+# ifdef DYNLOOKUP
+  .dyn_magic =         ROUTER_MAGIC,
+# endif
+  },
+.code =                        dnslookup_router_entry,
+.tidyup =              NULL,     /* no tidyup entry */
+.ri_flags =            ri_yestransport
+};
+
+#endif /*!MACRO_PREDEF*/
+#endif /*ROUTER_DNSLOOKUP*/
 /* End of routers/dnslookup.c */
 /* vi: aw ai sw=2
 */