* Exim - an Internet mail transport agent *
*************************************************/
-/* Copyright (c) The Exim Maintainers 2020 - 2022 */
-/* Copyright (c) University of Cambridge 1995 - 2018 */
+/* Copyright (c) The Exim Maintainers 2020 - 2023 */
+/* Copyright (c) University of Cambridge 1995 - 2023 */
/* See the file NOTICE for conditions of use and distribution. */
+/* SPDX-License-Identifier: GPL-2.0-or-later */
/* Functions concerned with verifying things. The original code for callout
caching was contributed by Kevin Fleming (but I hacked it around a bit). */
*/
static BOOL
-cached_callout_lookup(address_item * addr, uschar * address_key,
- uschar * from_address, int * opt_ptr, uschar ** pm_ptr,
+cached_callout_lookup(address_item * addr, const uschar * address_key,
+ const uschar * from_address, int * opt_ptr, uschar ** pm_ptr,
int * yield, uschar ** failure_ptr,
dbdata_callout_cache * new_domain_record, int * old_domain_res)
{
*/
static void
cache_callout_write(dbdata_callout_cache * dom_rec, const uschar * domain,
- int done, dbdata_callout_cache_address * addr_rec, uschar * address_key)
+ int done, dbdata_callout_cache_address * addr_rec, const uschar * address_key)
{
open_db dbblock;
-open_db *dbm_file = NULL;
+open_db * dbm_file = NULL;
/* If we get here with done == TRUE, a successful callout happened, and yield
will be set OK or FAIL according to the response to the RCPT command.
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")
int yield = OK;
int old_domain_cache_result = ccache_accept;
BOOL done = FALSE;
-uschar *address_key;
-uschar *from_address;
-uschar *random_local_part = NULL;
-const uschar *save_deliver_domain = deliver_domain;
-uschar **failure_ptr = options & vopt_is_recipient
+const uschar * address_key;
+const uschar * from_address;
+uschar * random_local_part = NULL;
+const uschar * save_deliver_domain = deliver_domain;
+uschar ** failure_ptr = options & vopt_is_recipient
? &recipient_verify_failure : &sender_verify_failure;
dbdata_callout_cache new_domain_record;
dbdata_callout_cache_address new_address_record;
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 */
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")
sx->conn_args.interface = interface;
sx->helo_data = tf->helo_data;
sx->conn_args.tblock = addr->transport;
- sx->conn_args.sock = -1;
+ sx->cctx.sock = sx->conn_args.sock = -1;
sx->verify = TRUE;
tls_retry_connection:
if (yield != OK)
{
errno = addr->basic_errno;
+
+ /* For certain errors we want specifically to log the transport name,
+ for ease of fixing config errors. Slightly ugly doing it here, but we want
+ to not leak that also in the SMTP response. */
+ switch (errno)
+ {
+ case EPROTOTYPE:
+ case ENOPROTOOPT:
+ case EPROTONOSUPPORT:
+ case ESOCKTNOSUPPORT:
+ case EOPNOTSUPP:
+ case EPFNOSUPPORT:
+ case EAFNOSUPPORT:
+ case EADDRINUSE:
+ case EADDRNOTAVAIL:
+ case ENETDOWN:
+ case ENETUNREACH:
+ log_write(0, LOG_MAIN|LOG_PANIC,
+ "%s verify %s (making calloout connection): T=%s %s",
+ options & vopt_is_recipient ? "sender" : "recipient",
+ yield == FAIL ? "fail" : "defer",
+ transport_name, strerror(errno));
+ }
+
transport_name = NULL;
deliver_host = deliver_host_address = NULL;
deliver_domain = save_deliver_domain;
if (random_local_part)
{
- uschar * main_address = addr->address;
+ const uschar * main_address = addr->address;
const uschar * rcpt_domain = addr->domain;
#ifdef SUPPORT_I18N
/* 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 */
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 */
}
}
if (done)
{
- uschar * main_address = addr->address;
+ const uschar * main_address = addr->address;
/*XXX oops, affixes */
addr->address = string_sprintf("postmaster@%.1000s", addr->domain);
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;
HDEBUG(D_acl|D_v) debug_printf("Cutthrough cancelled by presence of transport filter\n");
}
#ifndef DISABLE_DKIM
+ /* DKIM signing needs to add a header after seeing the whole body, so we cannot just copy
+ body bytes to the outbound as they are received, which is the intent of cutthrough. */
if (ob->dkim.dkim_domain)
{
cutthrough.delivery= FALSE;
/* Ensure no cutthrough on multiple verifies that were incompatible */
if (options & vopt_callout_recipsender)
cancel_cutthrough_connection(TRUE, US"not usable for cutthrough");
- if (sx->send_quit)
+ if (sx->send_quit && sx->cctx.sock >= 0)
if (smtp_write_command(sx, SCMD_FLUSH, "QUIT\r\n") != -1)
/* Wait a short time for response, and discard it */
smtp_read_response(sx, sx->buffer, sizeof(sx->buffer), '2', 1);
static BOOL
-_cutthrough_puts(uschar * cp, int n)
+_cutthrough_puts(const uschar * cp, int n)
{
while(n--)
{
/* Buffered output of counted data block. Return boolean success */
static BOOL
-cutthrough_puts(uschar * cp, int n)
+cutthrough_puts(const uschar * cp, int n)
{
if (cutthrough.cctx.sock < 0) return TRUE;
if (_cutthrough_puts(cp, n)) return TRUE;
}
-/* Get and check response from cutthrough target */
+/* Get and check response from cutthrough target.
+Used for
+- nonfirst RCPT
+- predata
+- data finaldot
+- cutthrough conn close
+*/
static uschar
cutthrough_response(client_conn_ctx * cctx, char expect, uschar ** copy, int timeout)
{
sx.inblock.ptrend = inbuffer;
sx.inblock.cctx = cctx;
if(!smtp_read_response(&sx, responsebuffer, sizeof(responsebuffer), expect, timeout))
- cancel_cutthrough_connection(TRUE, US"target timeout on read");
+ cancel_cutthrough_connection(TRUE, US"unexpected response to smtp command");
if(copy)
{
/* tctx arg only to match write_chunk() */
static BOOL
-cutthrough_write_chunk(transport_ctx * tctx, uschar * s, int len)
+cutthrough_write_chunk(transport_ctx * tctx, const uschar * s, int len)
{
-uschar * s2;
+const uschar * s2;
while(s && (s2 = Ustrchr(s, '\n')))
{
if(!cutthrough_puts(s, s2-s) || !cutthrough_put_nl())
int verify_type = expn ? v_expn :
f.address_test_mode ? v_none :
options & vopt_is_recipient ? v_recipient : v_sender;
-address_item *addr_list;
-address_item *addr_new = NULL;
-address_item *addr_remote = NULL;
-address_item *addr_local = NULL;
-address_item *addr_succeed = NULL;
-uschar **failure_ptr = options & vopt_is_recipient
+address_item * addr_list;
+address_item * addr_new = NULL;
+address_item * addr_remote = NULL;
+address_item * addr_local = NULL;
+address_item * addr_succeed = NULL;
+uschar ** failure_ptr = options & vopt_is_recipient
? &recipient_verify_failure : &sender_verify_failure;
-uschar *ko_prefix, *cr;
-uschar *address = vaddr->address;
-uschar *save_sender;
+uschar * ko_prefix, * cr;
+const uschar * address = vaddr->address;
+const uschar * save_sender;
uschar null_sender[] = { 0 }; /* Ensure writeable memory */
/* Clear, just in case */
if (global_rewrite_rules)
{
- uschar *old = address;
- /* deconst ok as address was not const */
- address = US rewrite_address(address, options & vopt_is_recipient, FALSE,
+ const uschar * old = address;
+ address = rewrite_address(address, options & vopt_is_recipient, FALSE,
global_rewrite_rules, rewrite_existflags);
if (address != old)
{
if (tf.hosts && (!host_list || tf.hosts_override))
{
uschar *s;
- const uschar *save_deliver_domain = deliver_domain;
- uschar *save_deliver_localpart = deliver_localpart;
+ const uschar * save_deliver_domain = deliver_domain;
+ const uschar * save_deliver_localpart = deliver_localpart;
host_list = NULL; /* Ignore the router's hosts */
for (int i = 0; i < recipients_count; i++)
{
BOOL found = FALSE;
- uschar *address = recipients_list[i].address;
+ const uschar * address = recipients_list[i].address;
for (header_line * h = header_list; !found && h; h = h->next)
{
- uschar *colon, *s;
+ uschar * colon, * s;
if (h->type != htype_to && h->type != htype_cc) continue;
*/
address_item *
-verify_checked_sender(uschar *sender)
+verify_checked_sender(const uschar * sender)
{
for (address_item * addr = sender_verified_list; addr; addr = addr->next)
if (Ustrcmp(sender, addr->address) == 0) return addr;
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);
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);
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
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
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 = US"malformed IPv4 address or address mask";
- 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
endname = semicolon;
opts = NULL;
}
+else
+ opts = NULL;
/* If we are doing an IP address only match, then all lookups must be IP
address lookups, even if there is no "net-". */
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))
{