tidying
[exim.git] / src / src / verify.c
index d080ddd631bd8f2985b1c26f71bc2a92f51ad298..4f3bafb04cfd085aca640a76837cee6ff3259a84 100644 (file)
@@ -368,6 +368,7 @@ if (addr->transport == cutthrough.addr.transport)
 
       host_af = Ustrchr(host->address, ':') ? AF_INET6 : AF_INET;
 
+      GET_OPTION("interface");
       if (  !smtp_get_interface(tf->interface, host_af, addr, &interface,
              US"callout")
         || !smtp_get_port(tf->port, addr, &port, US"callout")
@@ -579,10 +580,14 @@ else
   with a random local part, ensure that such a local part is available. If not,
   log the fact, but carry on without randomising. */
 
-  if (options & vopt_callout_random  &&  callout_random_local_part)
-    if (!(random_local_part = expand_string(callout_random_local_part)))
+  if (options & vopt_callout_random)
+    {
+    GET_OPTION("callout_random_local_part");
+    if (  callout_random_local_part
+       && !(random_local_part = expand_string(callout_random_local_part)))
       log_write(0, LOG_MAIN|LOG_PANIC, "failed to expand "
         "callout_random_local_part: %s", expand_string_message);
+    }
 
   /* Compile regex' used by client-side smtp */
 
@@ -660,6 +665,7 @@ coding means skipping this whole loop and doing the append separately.  */
     deliver_domain = addr->domain;
     transport_name = addr->transport->name;
 
+    GET_OPTION("interface");
     if (  !smtp_get_interface(tf->interface, host_af, addr, &interface,
             US"callout")
        || !smtp_get_port(tf->port, addr, &port, US"callout")
@@ -823,7 +829,7 @@ tls_retry_connection:
       /* Remember when we last did a random test */
       new_domain_record.random_stamp = time(NULL);
 
-      if (smtp_write_mail_and_rcpt_cmds(sx, &yield) == 0)
+      if (smtp_write_mail_and_rcpt_cmds(sx, &yield) == sw_mrc_ok)
        switch(addr->transport_return)
          {
          case PENDING_OK:      /* random was accepted, unfortunately */
@@ -891,33 +897,34 @@ tls_retry_connection:
       done = FALSE;
       switch(smtp_write_mail_and_rcpt_cmds(sx, &yield))
        {
-       case 0:  switch(addr->transport_return) /* ok so far */
-                   {
-                   case PENDING_OK:  done = TRUE;
-                                     new_address_record.result = ccache_accept;
-                                     break;
-                   case FAIL:        done = TRUE;
-                                     yield = FAIL;
-                                     *failure_ptr = US"recipient";
-                                     new_address_record.result = ccache_reject;
-                                     break;
-                   default:          break;
-                   }
-                 break;
+       case sw_mrc_ok:
+         switch(addr->transport_return)        /* ok so far */
+           {
+           case PENDING_OK:  done = TRUE;
+                             new_address_record.result = ccache_accept;
+                             break;
+           case FAIL:        done = TRUE;
+                             yield = FAIL;
+                             *failure_ptr = US"recipient";
+                             new_address_record.result = ccache_reject;
+                             break;
+           default:          break;
+           }
+         break;
 
-       case -1:                                /* MAIL response error */
-                 *failure_ptr = US"mail";
-                 if (errno == 0 && sx->buffer[0] == '5')
-                   {
-                   setflag(addr, af_verify_nsfail);
-                   if (from_address[0] == 0)
-                     new_domain_record.result = ccache_reject_mfnull;
-                   }
-                 break;
-                                               /* non-MAIL read i/o error */
-                                               /* non-MAIL response timeout */
-                                               /* internal error; channel still usable */
-       default:  break;                        /* transmit failed */
+       case sw_mrc_bad_mail:                   /* MAIL response error */
+         *failure_ptr = US"mail";
+         if (errno == 0 && sx->buffer[0] == '5')
+           {
+           setflag(addr, af_verify_nsfail);
+           if (from_address[0] == 0)
+             new_domain_record.result = ccache_reject_mfnull;
+           }
+         break;
+                                       /* non-MAIL read i/o error */
+                                       /* non-MAIL response timeout */
+                                       /* internal error; channel still usable */
+       default:  break;                /* transmit failed */
        }
       }
 
@@ -955,7 +962,7 @@ tls_retry_connection:
        sx->completed_addr = FALSE;
        sx->avoid_option = OPTION_SIZE;
 
-       if(  smtp_write_mail_and_rcpt_cmds(sx, &yield) == 0
+       if(  smtp_write_mail_and_rcpt_cmds(sx, &yield) == sw_mrc_ok
          && addr->transport_return == PENDING_OK
          )
          done = TRUE;
@@ -2605,12 +2612,12 @@ for (int i = 0; i < 3 && !done; i++)
 
     f.parse_allow_group = TRUE;
 
-    while (*s != 0)
+    while (*s)
       {
-      address_item *vaddr;
+      address_item * vaddr;
 
       while (isspace(*s) || *s == ',') s++;
-      if (*s == 0) break;        /* End of header */
+      if (!*s) break;                  /* End of header */
 
       ss = parse_find_address_end(s, FALSE);
 
@@ -2621,7 +2628,7 @@ for (int i = 0; i < 3 && !done; i++)
 
       while (isspace(ss[-1])) ss--;
       terminator = *ss;
-      *ss = 0;
+      *ss = '\0';
 
       HDEBUG(D_verify) debug_printf("verifying %.*s header address %s\n",
         (int)(endname - h->text), h->text, s);
@@ -2866,17 +2873,17 @@ if (sscanf(CS buffer + qlen, "%d , %d%n", &received_sender_port,
   goto END_OFF;
 
 p = buffer + qlen + n;
-while(isspace(*p)) p++;
+Uskip_whitespace(&p);
 if (*p++ != ':') goto END_OFF;
-while(isspace(*p)) p++;
+Uskip_whitespace(&p);
 if (Ustrncmp(p, "USERID", 6) != 0) goto END_OFF;
 p += 6;
-while(isspace(*p)) p++;
+Uskip_whitespace(&p);
 if (*p++ != ':') goto END_OFF;
-while (*p != 0 && *p != ':') p++;
-if (*p++ == 0) goto END_OFF;
-while(isspace(*p)) p++;
-if (*p == 0) goto END_OFF;
+while (*p && *p != ':') p++;
+if (!*p++) goto END_OFF;
+Uskip_whitespace(&p);
+if (!*p) goto END_OFF;
 
 /* The rest of the line is the data we want. We turn it into printing
 characters when we save it, so that it cannot mess up the format of any logging
@@ -2971,7 +2978,7 @@ if (*ss == '@')
 a (possibly masked) comparison with the current IP address. */
 
 if (string_is_ip_address(ss, &maskoffset) != 0)
-  return (host_is_in_net(cb->host_address, ss, maskoffset)? OK : FAIL);
+  return host_is_in_net(cb->host_address, ss, maskoffset) ? OK : FAIL;
 
 /* The pattern is not an IP address. A common error that people make is to omit
 one component of an IPv4 address, either by accident, or believing that, for
@@ -2982,13 +2989,25 @@ ancient specification.) To aid in debugging these cases, we give a specific
 error if the pattern contains only digits and dots or contains a slash preceded
 only by digits and dots (a slash at the start indicates a file name and of
 course slashes may be present in lookups, but not preceded only by digits and
-dots). */
+dots).  Then the equivalent for IPv6 (roughly). */
 
-for (t = ss; isdigit(*t) || *t == '.'; ) t++;
-if (!*t  || (*t == '/' && t != ss))
+if (Ustrchr(ss, ':'))
   {
-  *error = string_sprintf("malformed IPv4 address or address mask: %.*s", (int)(t - ss), ss);
-  return ERROR;
+  for (t = ss; isxdigit(*t) || *t == ':' || *t == '.'; ) t++;
+  if (!*t  ||  (*t == '/' || *t == '%') && t != ss)
+    {
+    *error = string_sprintf("malformed IPv6 address or address mask: %.*s", (int)(t - ss), ss);
+    return ERROR;
+    }
+  }
+else
+  {
+  for (t = ss; isdigit(*t) || *t == '.'; ) t++;
+  if (!*t  || (*t == '/' && t != ss))
+    {
+    *error = string_sprintf("malformed IPv4 address or address mask: %.*s", (int)(t - ss), ss);
+    return ERROR;
+    }
   }
 
 /* See if there is a semicolon in the pattern, separating a searchtype
@@ -3064,7 +3083,7 @@ if (iplookup)
     key = filename;
     while (*key != 0 && !isspace(*key)) key++;
     filename = string_copyn(filename, key - filename);
-    while (isspace(*key)) key++;
+    Uskip_whitespace(&key);
     }
   else if (mac_islookup(search_type, lookup_querystyle))
     {