SPDX: Mass-update to GPL-2.0-or-later
[exim.git] / src / src / routers / manualroute.c
index af4470655160a00b99448235dd1808d469df84d8..160c866b9bf16fee04bf026ab7685b596a630db6 100644 (file)
@@ -2,8 +2,10 @@
 *     Exim - an Internet mail transport agent    *
 *************************************************/
 
+/* Copyright (c) The Exim Maintainers 2020 - 2022 */
 /* Copyright (c) University of Cambridge 1995 - 2018 */
 /* See the file NOTICE for conditions of use and distribution. */
+/* SPDX-License-Identifier: GPL-2.0-or-later */
 
 
 #include "../exim.h"
 
 optionlist manualroute_router_options[] = {
   { "host_all_ignored", opt_stringptr,
-      (void *)(offsetof(manualroute_router_options_block, host_all_ignored)) },
+      OPT_OFF(manualroute_router_options_block, host_all_ignored) },
   { "host_find_failed", opt_stringptr,
-      (void *)(offsetof(manualroute_router_options_block, host_find_failed)) },
+      OPT_OFF(manualroute_router_options_block, host_find_failed) },
   { "hosts_randomize",  opt_bool,
-      (void *)(offsetof(manualroute_router_options_block, hosts_randomize)) },
+      OPT_OFF(manualroute_router_options_block, hosts_randomize) },
   { "route_data",       opt_stringptr,
-      (void *)(offsetof(manualroute_router_options_block, route_data)) },
+      OPT_OFF(manualroute_router_options_block, route_data) },
   { "route_list",       opt_stringptr,
-      (void *)(offsetof(manualroute_router_options_block, route_list)) },
+      OPT_OFF(manualroute_router_options_block, route_list) },
   { "same_domain_copy_routing", opt_bool|opt_public,
-      (void *)(offsetof(router_instance, same_domain_copy_routing)) }
+      OPT_OFF(router_instance, same_domain_copy_routing) }
 };
 
 /* Size of the options list. An extern variable has to be used so that its
@@ -91,30 +93,25 @@ manualroute_router_init(router_instance *rblock)
 {
 manualroute_router_options_block *ob =
   (manualroute_router_options_block *)(rblock->options_block);
-int i;
 
 /* Host_find_failed must be a recognized word */
 
-for (i = 0; i < hff_count; i++)
-  {
+for (int i = 0; i < hff_count; i++)
   if (Ustrcmp(ob->host_find_failed, hff_names[i]) == 0)
     {
     ob->hff_code = hff_codes[i];
     break;
     }
-  }
 if (ob->hff_code < 0)
   log_write(0, LOG_PANIC_DIE|LOG_CONFIG_FOR, "%s router:\n  "
     "unrecognized setting for host_find_failed option", rblock->name);
 
-for (i = 1; i < hff_count; i++)   /* NB starts at 1 to skip "ignore" */
-  {
+for (int i = 1; i < hff_count; i++)   /* NB starts at 1 to skip "ignore" */
   if (Ustrcmp(ob->host_all_ignored, hff_names[i]) == 0)
     {
     ob->hai_code = hff_codes[i];
     break;
     }
-  }
 if (ob->hai_code < 0)
   log_write(0, LOG_PANIC_DIE|LOG_CONFIG_FOR, "%s router:\n  "
     "unrecognized setting for host_all_ignored option", rblock->name);
@@ -159,15 +156,15 @@ parse_route_item(const uschar *s, const uschar **domain, const uschar **hostlist
 {
 while (*s != 0 && isspace(*s)) s++;
 
-if (domain != NULL)
+if (domain)
   {
-  if (*s == 0) return FALSE;            /* missing data */
+  if (!*s) return FALSE;            /* missing data */
   *domain = string_dequote(&s);
-  while (*s != 0 && isspace(*s)) s++;
+  while (*s && isspace(*s)) s++;
   }
 
 *hostlist = string_dequote(&s);
-while (*s != 0 && isspace(*s)) s++;
+while (*s && isspace(*s)) s++;
 *options = s;
 return TRUE;
 }
@@ -252,21 +249,18 @@ transport_instance *transport = NULL;
 BOOL individual_transport_set = FALSE;
 BOOL randomize = ob->hosts_randomize;
 
-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);
 
 /* The initialization check ensures that either route_list or route_data is
 set. */
 
-if (ob->route_list != NULL)
+if (ob->route_list)
   {
   int sep = -(';');             /* Default is semicolon */
   listptr = ob->route_list;
 
-  while ((route_item = string_nextinlist(&listptr, &sep, NULL, 0)) != NULL)
+  while ((route_item = string_nextinlist(&listptr, &sep, NULL, 0)))
     {
     int rc;
 
@@ -289,7 +283,7 @@ if (ob->route_list != NULL)
       }
     }
 
-  if (route_item == NULL) return DECLINE;  /* No pattern in the list matched */
+  if (!route_item) return DECLINE;  /* No pattern in the list matched */
   }
 
 /* Handle a single routing item in route_data. If it expands to an empty
@@ -297,17 +291,17 @@ string, decline. */
 
 else
   {
-  route_item = rf_expand_data(addr, ob->route_data, &rc);
-  if (route_item == NULL) return rc;
+  if (!(route_item = rf_expand_data(addr, ob->route_data, &rc)))
+    return rc;
   (void) parse_route_item(route_item, NULL, &hostlist, &options);
-  if (hostlist[0] == 0) return DECLINE;
+  if (!hostlist[0]) return DECLINE;
   }
 
 /* Expand the hostlist item. It may then pointing to an empty string, or to a
 single host or a list of hosts; options is pointing to the rest of the
 routelist item, which is either empty or contains various option words. */
 
-DEBUG(D_route) debug_printf("original list of hosts = \"%s\" options = %s\n",
+DEBUG(D_route) debug_printf("original list of hosts = '%s' options = '%s'\n",
   hostlist, options);
 
 newhostlist = expand_string_copy(hostlist);
@@ -317,7 +311,7 @@ expand_nmax = -1;
 /* If the expansion was forced to fail, just decline. Otherwise there is a
 configuration problem. */
 
-if (newhostlist == NULL)
+if (!newhostlist)
   {
   if (f.expand_string_forcedfail) return DECLINE;
   addr->message = string_sprintf("%s router: failed to expand \"%s\": %s",
@@ -326,14 +320,14 @@ if (newhostlist == NULL)
   }
 else hostlist = newhostlist;
 
-DEBUG(D_route) debug_printf("expanded list of hosts = \"%s\" options = %s\n",
+DEBUG(D_route) debug_printf("expanded list of hosts = '%s' options = '%s'\n",
   hostlist, options);
 
 /* Set default lookup type and scan the options */
 
 lookup_type = LK_DEFAULT;
 
-while (*options != 0)
+while (*options)
   {
   unsigned n;
   const uschar *s = options;
@@ -380,7 +374,7 @@ while (*options != 0)
 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->prop.extra_headers,
   &addr->prop.remove_headers);
@@ -403,10 +397,10 @@ single text string that ends up in $host. */
 
 if (transport && transport->info->local)
   {
-  if (hostlist[0] != 0)
+  if (hostlist[0])
     {
     host_item *h;
-    addr->host_list = h = store_get(sizeof(host_item));
+    addr->host_list = h = store_get(sizeof(host_item), GET_UNTAINTED);
     h->name = string_copy(hostlist);
     h->address = NULL;
     h->port = PORT_NONE;
@@ -430,7 +424,7 @@ if (transport && transport->info->local)
 list is mandatory in either case, except when verifying, in which case the
 address is just accepted. */
 
-if (hostlist[0] == 0)
+if (!hostlist[0])
   {
   if (verify != v_none) goto ROUTED;
   addr->message = string_sprintf("error in %s router: no host(s) specified "
@@ -442,7 +436,7 @@ if (hostlist[0] == 0)
 /* Otherwise we finish the routing here by building a chain of host items
 for the list of configured hosts, and then finding their addresses. */
 
-host_build_hostlist(&(addr->host_list), hostlist, randomize);
+host_build_hostlist(&addr->host_list, hostlist, randomize);
 rc = rf_lookup_hostlist(rblock, addr, rblock->ignore_target_hosts, lookup_type,
   ob->hff_code, addr_new);
 if (rc != OK) return rc;
@@ -475,7 +469,7 @@ if (!addr->host_list)
 defined for these hosts. It will be a remote one, as a local transport is
 dealt with above. However, we don't need one if verifying only. */
 
-if (transport == NULL && verify == v_none)
+if (!transport && verify == v_none)
     {
     log_write(0, LOG_MAIN, "Error in %s router: no transport defined",
       rblock->name);