summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/src/daemon.c56
-rw-r--r--src/src/exim.c2
-rw-r--r--src/src/globals.c2
-rw-r--r--src/src/globals.h1
-rw-r--r--src/src/host.c2
-rw-r--r--src/src/macros.h1
-rw-r--r--src/src/receive.c4
-rw-r--r--src/src/smtp_in.c26
8 files changed, 58 insertions, 36 deletions
diff --git a/src/src/daemon.c b/src/src/daemon.c
index f6867b882..028626c0e 100644
--- a/src/src/daemon.c
+++ b/src/src/daemon.c
@@ -181,7 +181,7 @@ Returns: nothing
*/
static void
-handle_smtp_call(struct pollfd *fd_polls, int listen_socket_count,
+handle_smtp_call(struct pollfd * fd_polls, int listen_socket_count,
int accept_socket, struct sockaddr *accepted)
{
pid_t pid;
@@ -360,31 +360,8 @@ if (max_for_this_host > 0 && smtp_accept_count >= max_for_this_host)
}
}
-/* OK, the connection count checks have been passed. Before we can fork the
-accepting process, we must first log the connection if requested. This logging
-used to happen in the subprocess, but doing that means that the value of
-smtp_accept_count can be out of step by the time it is logged. So we have to do
-the logging here and accept the performance cost. Note that smtp_accept_count
-hasn't yet been incremented to take account of this connection.
-
-In order to minimize the cost (because this is going to happen for every
-connection), do a preliminary selector test here. This saves ploughing through
-the generalized logging code each time when the selector is false. If the
-selector is set, check whether the host is on the list for logging. If not,
-arrange to unset the selector in the subprocess. */
-
-if (LOGGING(smtp_connection))
- {
- uschar *list = hosts_connection_nolog;
- memset(sender_host_cache, 0, sizeof(sender_host_cache));
- if (list && verify_check_host(&list) == OK)
- save_log_selector &= ~L_smtp_connection;
- else
- log_write(L_smtp_connection, LOG_MAIN, "SMTP connection from %Y "
- "(TCP/IP connection count = %d)", whofrom, smtp_accept_count + 1);
- }
-
-/* Now we can fork the accepting process; do a lookup tidy, just in case any
+/* OK, the connection count checks have been passed.
+Now we can fork the accepting process; do a lookup tidy, just in case any
expansion above did a lookup. */
search_tidyup();
@@ -404,6 +381,33 @@ if (pid == 0)
#endif
smtp_accept_count++; /* So that it includes this process */
+ connection_id = getpid();
+
+ /* Log the connection if requested.
+ In order to minimize the cost (because this is going to happen for every
+ connection), do a preliminary selector test here. This saves ploughing through
+ the generalized logging code each time when the selector is false. If the
+ selector is set, check whether the host is on the list for logging. If not,
+ arrange to unset the selector in the subprocess.
+
+ jgh 2023/08/08 :- moved this logging in from the parent process, just
+ pre-fork. There was a claim back from 2004 that smtp_accept_count could have
+ become out-of-date by the time the child could log it, and I can't see how
+ that could happen. */
+
+ if (LOGGING(smtp_connection))
+ {
+ uschar * list = hosts_connection_nolog;
+ memset(sender_host_cache, 0, sizeof(sender_host_cache));
+ if (list && verify_check_host(&list) == OK)
+ save_log_selector &= ~L_smtp_connection;
+ else if (LOGGING(connection_id))
+ log_write(L_smtp_connection, LOG_MAIN, "SMTP connection from %Y "
+ "Ci=%lu (TCP/IP connection count = %d)", whofrom, connection_id, smtp_accept_count);
+ else
+ log_write(L_smtp_connection, LOG_MAIN, "SMTP connection from %Y "
+ "(TCP/IP connection count = %d)", whofrom, smtp_accept_count);
+ }
/* If the listen backlog was over the monitoring level, log it. */
diff --git a/src/src/exim.c b/src/src/exim.c
index 94061f97d..c44c7cb1b 100644
--- a/src/src/exim.c
+++ b/src/src/exim.c
@@ -5418,6 +5418,7 @@ if (host_checking)
"**** This is not for real!\n\n",
sender_host_address);
+ connection_id = getpid();
memset(sender_host_cache, 0, sizeof(sender_host_cache));
if (verify_check_host(&hosts_connection_nolog) == OK)
{
@@ -5606,6 +5607,7 @@ because a log line has already been written for all its failure exists
(usually "connection refused: <reason>") and writing another one is
unnecessary clutter. */
+connection_id = getpid();
if (smtp_input)
{
smtp_in = stdin;
diff --git a/src/src/globals.c b/src/src/globals.c
index 9f4053937..56d192781 100644
--- a/src/src/globals.c
+++ b/src/src/globals.c
@@ -737,6 +737,7 @@ uid_t config_uid = CONFIGURE_OWNER;
uid_t config_uid = 0;
#endif
+ulong connection_id = 0L;
int connection_max_messages= -1;
uschar *continue_proxy_cipher = NULL;
BOOL continue_proxy_dane = FALSE;
@@ -1089,6 +1090,7 @@ bit_table log_options[] = { /* must be in alphabetical order,
BIT_TABLE(L, all),
BIT_TABLE(L, all_parents),
BIT_TABLE(L, arguments),
+ BIT_TABLE(L, connection_id),
BIT_TABLE(L, connection_reject),
BIT_TABLE(L, delay_delivery),
BIT_TABLE(L, deliver_time),
diff --git a/src/src/globals.h b/src/src/globals.h
index 3a5513382..2458066dd 100644
--- a/src/src/globals.h
+++ b/src/src/globals.h
@@ -432,6 +432,7 @@ extern gstring *client_cmd_log; /* debug log of client cmds & responses *
extern int clmacro_count; /* Number of command line macros */
extern uschar *clmacros[]; /* Copy of them, for re-exec */
extern BOOL commandline_checks_require_admin; /* belt and braces for insecure setups */
+extern ulong connection_id; /* per-daemon connection number */
extern int connection_max_messages;/* Max down one SMTP connection */
extern FILE *config_file; /* Configuration file */
extern const uschar *config_filename; /* Configuration file name */
diff --git a/src/src/host.c b/src/src/host.c
index e274673a0..3e5a88660 100644
--- a/src/src/host.c
+++ b/src/src/host.c
@@ -628,6 +628,8 @@ else
if (sender_ident)
g = string_fmt_append(g, " U=%s", sender_ident);
}
+if (LOGGING(connection_id))
+ g = string_fmt_append(g, " Ci=%lu", connection_id);
gstring_release_unused(g);
return string_from_gstring(g);
}
diff --git a/src/src/macros.h b/src/src/macros.h
index 941c4f00c..47d75044b 100644
--- a/src/src/macros.h
+++ b/src/src/macros.h
@@ -466,6 +466,7 @@ enum logbit {
Li_8bitmime = BITWORDSIZE,
Li_acl_warn_skipped,
Li_arguments,
+ Li_connection_id,
Li_deliver_time,
Li_delivery_size,
Li_dkim,
diff --git a/src/src/receive.c b/src/src/receive.c
index 4271561d7..14038f2ec 100644
--- a/src/src/receive.c
+++ b/src/src/receive.c
@@ -1156,7 +1156,7 @@ Returns: the SMTP response
*/
static uschar *
-handle_lost_connection(uschar *s)
+handle_lost_connection(uschar * s)
{
log_write(L_lost_incoming_connection | L_smtp_connection, LOG_MAIN,
"%s lost while reading message data%s", smtp_get_connection_info(), s);
@@ -1379,6 +1379,8 @@ if (f.tcp_in_fastopen && !f.tcp_in_fastopen_logged)
}
if (sender_ident)
g = string_append(g, 2, US" U=", sender_ident);
+if (LOGGING(connection_id))
+ g = string_fmt_append(g, " Ci=%lu", connection_id);
if (received_protocol)
g = string_append(g, 2, US" P=", received_protocol);
if (LOGGING(pipelining) && f.smtp_in_pipelining_advertised)
diff --git a/src/src/smtp_in.c b/src/src/smtp_in.c
index 765d33bf4..18cde79b1 100644
--- a/src/src/smtp_in.c
+++ b/src/src/smtp_in.c
@@ -1342,21 +1342,29 @@ smtp_get_connection_info(void)
{
const uschar * hostname = sender_fullhost
? sender_fullhost : sender_host_address;
+gstring * g = string_catn(NULL, US"SMTP connection", 15);
+
+if (LOGGING(connection_id))
+ g = string_fmt_append(g, " Ci=%lu", connection_id);
+g = string_catn(g, US" from ", 6);
if (host_checking)
- return string_sprintf("SMTP connection from %s", hostname);
+ g = string_cat(g, hostname);
+
+else if (f.sender_host_unknown || f.sender_host_notsocket)
+ g = string_cat(g, sender_ident);
-if (f.sender_host_unknown || f.sender_host_notsocket)
- return string_sprintf("SMTP connection from %s", sender_ident);
+else if (f.is_inetd)
+ g = string_append(g, 2, hostname, US" (via inetd)");
-if (f.is_inetd)
- return string_sprintf("SMTP connection from %s (via inetd)", hostname);
+else if (LOGGING(incoming_interface) && interface_address)
+ g = string_fmt_append(g, "%s I=[%s]:%d", hostname, interface_address, interface_port);
-if (LOGGING(incoming_interface) && interface_address)
- return string_sprintf("SMTP connection from %s I=[%s]:%d", hostname,
- interface_address, interface_port);
+else
+ g = string_cat(g, hostname);
-return string_sprintf("SMTP connection from %s", hostname);
+gstring_release_unused(g);
+return string_from_gstring(g);
}