From 691ca88ca06899e02e77cb28fbf075de450607bc Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Sun, 8 Mar 2020 22:24:37 +0000 Subject: [PATCH] Default notifier socket name to spooldir-dependent path even for abstract names --- doc/doc-docbook/spec.xfpt | 19 +++++++++++++++++++ doc/doc-txt/OptionLists.txt | 2 ++ src/src/daemon.c | 22 +++++++++++++++------- src/src/expand.c | 7 ++++--- src/src/globals.c | 1 + src/src/globals.h | 3 +-- src/src/queue.c | 6 +++--- src/src/readconf.c | 1 + test/confs/0621 | 1 + test/runtest | 5 +++-- test/stderr/0433 | 6 ++++++ test/stderr/0438 | 3 +++ test/stderr/0609 | 1 + test/stderr/1007 | 8 ++++++++ test/stderr/2201 | 1 + 15 files changed, 69 insertions(+), 17 deletions(-) diff --git a/doc/doc-docbook/spec.xfpt b/doc/doc-docbook/spec.xfpt index 25abda9e5..f91d51792 100644 --- a/doc/doc-docbook/spec.xfpt +++ b/doc/doc-docbook/spec.xfpt @@ -14309,6 +14309,7 @@ listed in more than one group. .row &%daemon_startup_sleep%& "time to sleep between tries" .row &%extra_local_interfaces%& "not necessarily listened on" .row &%local_interfaces%& "on which to listen, with optional ports" +.row &%notifier_socket%& "override compiled-in value" .row &%pid_file_path%& "override compiled-in value" .row &%queue_run_max%& "maximum simultaneous queue runners" .endtable @@ -16382,6 +16383,24 @@ harm. This option overrides the &%pipe_as_creator%& option of the &(pipe)& transport driver. +.new +.option notifier_socket main string "$spool_directory/exim_daemon_notify" +This option gives the name for a unix-domain socket on which the daemon +listens for work and information-requests. +Only installations running multiple daemons sharing a spool directory +should need to modify the default. + +The option is expanded before use. +If the platform supports Linux-style abstract socket names, the result +is used with a nul byte prefixed. +Otherwise, it should be a full path name and use a directory accessible +to Exim. + +If the Exim command line uses a &%-oX%& option and does not use &%-oP%& +then a notifier socket is not created. +.wen + + .option openssl_options main "string list" "+no_sslv2 +no_sslv3 +single_dh_use +no_ticket +no_renegotiation" .cindex "OpenSSL "compatibility options" This option allows an administrator to adjust the SSL options applied diff --git a/doc/doc-txt/OptionLists.txt b/doc/doc-txt/OptionLists.txt index 2978aed35..717f87e57 100644 --- a/doc/doc-txt/OptionLists.txt +++ b/doc/doc-txt/OptionLists.txt @@ -399,6 +399,8 @@ mx_domains domain list unset dnslookup mx_fail_domains domain list unset dnslookup 4.43 mysql_servers string list unset main 3.03 never_users string list unset main +notifier_socket string "$spool_directory/exim_daemon_notify" + main 4.94 notify_comsat boolean false appendfile once string* unset autoreply once_file_size integer 0 autoreply 3.20 diff --git a/src/src/daemon.c b/src/src/daemon.c index ac507b023..2813a50d1 100644 --- a/src/src/daemon.c +++ b/src/src/daemon.c @@ -972,7 +972,7 @@ if (daemon_notifier_fd >= 0) daemon_notifier_fd = -1; #ifndef EXIM_HAVE_ABSTRACT_UNIX_SOCKETS { - uschar * s = string_sprintf("%s/%s", spool_directory, NOTIFIER_SOCKET_NAME); + uschar * s = expand_string(notifier_socket); DEBUG(D_any) debug_printf("unlinking notifier socket %s\n", s); Uunlink(s); } @@ -1010,7 +1010,14 @@ const uschar * where; struct sockaddr_un sa_un = {.sun_family = AF_UNIX}; int len; -DEBUG(D_any) debug_printf("creating notifier socket "); +if (override_local_interfaces && !override_pid_file_path) + { + DEBUG(D_any) + debug_printf("-oX used without -oP so not creating notifier socket\n"); + return; + } + +DEBUG(D_any) debug_printf("creating notifier socket\n"); #ifdef SOCK_CLOEXEC if ((fd = socket(PF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) @@ -1024,13 +1031,14 @@ if ((fd = socket(PF_UNIX, SOCK_DGRAM, 0)) < 0) #ifdef EXIM_HAVE_ABSTRACT_UNIX_SOCKETS sa_un.sun_path[0] = 0; /* Abstract local socket addr - Linux-specific? */ len = offsetof(struct sockaddr_un, sun_path) + 1 - + snprintf(sa_un.sun_path+1, sizeof(sa_un.sun_path)-1, "%s", NOTIFIER_SOCKET_NAME); -DEBUG(D_any) debug_printf("@%s\n", sa_un.sun_path+1); + + snprintf(sa_un.sun_path+1, sizeof(sa_un.sun_path)-1, "%s", + expand_string(notifier_socket)); +DEBUG(D_any) debug_printf(" @%s\n", sa_un.sun_path+1); #else /* filesystem-visible and persistent; will neeed removal */ len = offsetof(struct sockaddr_un, sun_path) - + snprintf(sa_un.sun_path, sizeof(sa_un.sun_path), "%s/%s", - spool_directory, NOTIFIER_SOCKET_NAME); -DEBUG(D_any) debug_printf("%s\n", sa_un.sun_path); + + snprintf(sa_un.sun_path, sizeof(sa_un.sun_path), "%s", + expand_string(notifier_socket)); +DEBUG(D_any) debug_printf(" %s\n", sa_un.sun_path); #endif if (bind(fd, (const struct sockaddr *)&sa_un, len) < 0) diff --git a/src/src/expand.c b/src/src/expand.c index 3c3184347..4377ea1aa 100644 --- a/src/src/expand.c +++ b/src/src/expand.c @@ -1791,11 +1791,12 @@ debug_printf("local addr '%s%s'\n", #ifdef EXIM_HAVE_ABSTRACT_UNIX_SOCKETS sa_un.sun_path[0] = 0; /* Abstract local socket addr - Linux-specific? */ len = offsetof(struct sockaddr_un, sun_path) + 1 - + snprintf(sa_un.sun_path+1, sizeof(sa_un.sun_path)-1, "%s", NOTIFIER_SOCKET_NAME); + + snprintf(sa_un.sun_path+1, sizeof(sa_un.sun_path)-1, "%s", + expand_string(notifier_socket)); #else len = offsetof(struct sockaddr_un, sun_path) - + snprintf(sa_un.sun_path, sizeof(sa_un.sun_path), "%s/%s", - spool_directory, NOTIFIER_SOCKET_NAME); + + snprintf(sa_un.sun_path, sizeof(sa_un.sun_path), "%s", + expand_string(notifier_socket)); #endif if (connect(fd, (const struct sockaddr *)&sa_un, len) < 0) diff --git a/src/src/globals.c b/src/src/globals.c index 4ce15acaa..a771f1193 100644 --- a/src/src/globals.c +++ b/src/src/globals.c @@ -1164,6 +1164,7 @@ int mime_part_count = -1; #endif uid_t *never_users = NULL; +uschar *notifier_socket = US"$spool_directory/" NOTIFIER_SOCKET_NAME ; const int on = 1; /* for setsockopt */ const int off = 0; diff --git a/src/src/globals.h b/src/src/globals.h index 1fea9c9b0..28d170cdc 100644 --- a/src/src/globals.h +++ b/src/src/globals.h @@ -735,8 +735,7 @@ extern int mime_part_count; extern BOOL mua_wrapper; /* TRUE when Exim is wrapping an MUA */ extern uid_t *never_users; /* List of uids never to be used */ -#ifdef WITH_CONTENT_SCAN -#endif +extern uschar *notifier_socket; /* Name for daemon notifier unix-socket */ extern const int on; /* For setsockopt */ extern const int off; diff --git a/src/src/queue.c b/src/src/queue.c index 53dc6e026..1b70c02b6 100644 --- a/src/src/queue.c +++ b/src/src/queue.c @@ -1536,12 +1536,12 @@ if ((fd = socket(AF_UNIX, SOCK_DGRAM, 0)) >= 0) #ifdef EXIM_HAVE_ABSTRACT_UNIX_SOCKETS int len = offsetof(struct sockaddr_un, sun_path) + 1 + snprintf(sa_un.sun_path+1, sizeof(sa_un.sun_path)-1, "%s", - NOTIFIER_SOCKET_NAME); + expand_string(notifier_socket)); sa_un.sun_path[0] = 0; #else int len = offsetof(struct sockaddr_un, sun_path) - + snprintf(sa_un.sun_path, sizeof(sa_un.sun_path), "%s/%s", - spool_directory, NOTIFIER_SOCKET_NAME); + + snprintf(sa_un.sun_path, sizeof(sa_un.sun_path), "%s", + expand_string(notifier_socket)); #endif if (sendto(fd, buf, sizeof(buf), 0, (struct sockaddr *)&sa_un, len) < 0) diff --git a/src/src/readconf.c b/src/src/readconf.c index c8a3dffba..a506d9f1d 100644 --- a/src/src/readconf.c +++ b/src/src/readconf.c @@ -227,6 +227,7 @@ static optionlist optionlist_config[] = { { "mysql_servers", opt_stringptr, {&mysql_servers} }, #endif { "never_users", opt_uidlist, {&never_users} }, + { "notifier_socket", opt_stringptr, {¬ifier_socket} }, #ifndef DISABLE_TLS { "openssl_options", opt_stringptr, {&openssl_options} }, #endif diff --git a/test/confs/0621 b/test/confs/0621 index 32d906203..ef3427df9 100644 --- a/test/confs/0621 +++ b/test/confs/0621 @@ -8,6 +8,7 @@ domainlist local_domains = test.ex qualify_domain = test.ex queue_only +notifier_socket = DIR/spool/this_my_notify_socket log_selector = +millisec diff --git a/test/runtest b/test/runtest index 994ff9ff8..aeb0d8f53 100755 --- a/test/runtest +++ b/test/runtest @@ -1218,8 +1218,9 @@ RESET_AFTER_EXTRA_LINE_READ: next if /in\shosts_require_dane\?\sno\s\(option\sunset\)/x; # daemon notifier socket - s/^(creating notifier socket) .*$/$1/; - s/^(\s*\d+|ppppp) (creating notifier socket) .+$/ppppp $2/; + s/^(\s*\d+|ppppp) (creating notifier socket)$/ppppp $2/; + s/^ \@(.*exim_daemon_notify)$/ $1/; + s/^(\s*\d+|ppppp) \@(.*exim_daemon_notify)$/ppppp $2/; next if /unlinking notifier socket/; # DISABLE_OCSP diff --git a/test/stderr/0433 b/test/stderr/0433 index f9ac402e1..9972ae7d1 100644 --- a/test/stderr/0433 +++ b/test/stderr/0433 @@ -8,6 +8,7 @@ admin user dropping to exim gid; retaining priv uid originator: uid=CALLER_UID gid=CALLER_GID login=CALLER name=CALLER_NAME ppppp creating notifier socket +ppppp TESTSUITE/spool/exim_daemon_notify listening on all interfaces (IPv4) port 1225 pid written to TESTSUITE/spool/exim-daemon.pid changed uid/gid: running as a daemon @@ -28,6 +29,7 @@ admin user dropping to exim gid; retaining priv uid originator: uid=CALLER_UID gid=CALLER_GID login=CALLER name=CALLER_NAME ppppp creating notifier socket +ppppp TESTSUITE/spool/exim_daemon_notify listening on all interfaces (IPv4) port 1225 listening on all interfaces (IPv4) port 1226 pid written to TESTSUITE/spool/exim-daemon.pid @@ -49,6 +51,7 @@ admin user dropping to exim gid; retaining priv uid originator: uid=CALLER_UID gid=CALLER_GID login=CALLER name=CALLER_NAME ppppp creating notifier socket +ppppp TESTSUITE/spool/exim_daemon_notify listening on 127.0.0.1 port 1228 listening on all interfaces (IPv4) port 1225 listening on all interfaces (IPv4) port 1226 @@ -71,6 +74,7 @@ admin user dropping to exim gid; retaining priv uid originator: uid=CALLER_UID gid=CALLER_GID login=CALLER name=CALLER_NAME ppppp creating notifier socket +ppppp TESTSUITE/spool/exim_daemon_notify listening on all interfaces (IPv4) port 1225 listening on all interfaces (IPv4) port 1226 listening on 127.0.0.1 port 1228 @@ -95,6 +99,7 @@ originator: uid=CALLER_UID gid=CALLER_GID login=CALLER name=CALLER_NAME daemon_smtp_port overridden by -oX: <: 1227 creating notifier socket + TESTSUITE/spool/exim_daemon_notify listening on 127.0.0.1 port 1228 listening on all interfaces (IPv4) port 1227 pid written to TESTSUITE/spool/exim-daemon.pid @@ -118,6 +123,7 @@ originator: uid=CALLER_UID gid=CALLER_GID login=CALLER name=CALLER_NAME local_interfaces overridden by -oX: <; 0.0.0.0.1225; 0.0.0.0.1226 creating notifier socket + TESTSUITE/spool/exim_daemon_notify listening on all interfaces (IPv4) port 1225 listening on all interfaces (IPv4) port 1226 pid written to TESTSUITE/spool/exim-daemon.pid diff --git a/test/stderr/0438 b/test/stderr/0438 index 4fbd57705..1b39cfddc 100644 --- a/test/stderr/0438 +++ b/test/stderr/0438 @@ -10,6 +10,7 @@ originator: uid=CALLER_UID gid=CALLER_GID login=CALLER name=CALLER_NAME daemon_smtp_port overridden by -oX: <: 1225 creating notifier socket + TESTSUITE/spool/exim_daemon_notify listening on all interfaces (IPv4) port 1225 pid written to TESTSUITE/spool/exim-daemon.pid changed uid/gid: running as a daemon @@ -32,6 +33,7 @@ originator: uid=CALLER_UID gid=CALLER_GID login=CALLER name=CALLER_NAME daemon_smtp_port overridden by -oX: <: 1225 creating notifier socket + TESTSUITE/spool/exim_daemon_notify listening on all interfaces (IPv4) port 1225 pid written to TESTSUITE/spool/exim-daemon.anotherpid changed uid/gid: running as a daemon @@ -54,6 +56,7 @@ originator: uid=CALLER_UID gid=CALLER_GID login=CALLER name=CALLER_NAME daemon_smtp_port overridden by -oX: <: 1225 creating notifier socket + TESTSUITE/spool/exim_daemon_notify listening on all interfaces (IPv4) port 1225 pid written to TESTSUITE/spool/mypidfile changed uid/gid: running as a daemon diff --git a/test/stderr/0609 b/test/stderr/0609 index b8df9c301..fcae2635e 100644 --- a/test/stderr/0609 +++ b/test/stderr/0609 @@ -7,6 +7,7 @@ dropping to exim gid; retaining priv uid ppppp daemon_smtp_port overridden by -oX: ppppp <: 1225 ppppp creating notifier socket +ppppp TESTSUITE/spool/exim_daemon_notify ppppp listening on all interfaces (IPv4) port 1225 ppppp pid written to TESTSUITE/spool/exim-daemon.pid ppppp LOG: MAIN diff --git a/test/stderr/1007 b/test/stderr/1007 index 8eefcb56c..ebfae6aa1 100644 --- a/test/stderr/1007 +++ b/test/stderr/1007 @@ -8,6 +8,7 @@ admin user dropping to exim gid; retaining priv uid originator: uid=CALLER_UID gid=CALLER_GID login=CALLER name=CALLER_NAME ppppp creating notifier socket +ppppp TESTSUITE/spool/exim_daemon_notify listening on all interfaces (IPv6) port 1225 listening on all interfaces (IPv4) port 1225 pid written to TESTSUITE/spool/exim-daemon.pid @@ -29,6 +30,7 @@ admin user dropping to exim gid; retaining priv uid originator: uid=CALLER_UID gid=CALLER_GID login=CALLER name=CALLER_NAME ppppp creating notifier socket +ppppp TESTSUITE/spool/exim_daemon_notify listening on all interfaces (IPv6) port 1225 listening on all interfaces (IPv4) port 1225 listening on all interfaces (IPv6) port 1226 @@ -52,6 +54,7 @@ admin user dropping to exim gid; retaining priv uid originator: uid=CALLER_UID gid=CALLER_GID login=CALLER name=CALLER_NAME ppppp creating notifier socket +ppppp TESTSUITE/spool/exim_daemon_notify listening on all interfaces (IPv6) port 1225 listening on all interfaces (IPv4) port 1225 listening on all interfaces (IPv6) port 1226 @@ -76,6 +79,7 @@ admin user dropping to exim gid; retaining priv uid originator: uid=CALLER_UID gid=CALLER_GID login=CALLER name=CALLER_NAME ppppp creating notifier socket +ppppp TESTSUITE/spool/exim_daemon_notify listening on all interfaces (IPv6) port 1225 listening on all interfaces (IPv4) port 1225 listening on all interfaces (IPv6) port 1226 @@ -100,6 +104,7 @@ admin user dropping to exim gid; retaining priv uid originator: uid=CALLER_UID gid=CALLER_GID login=CALLER name=CALLER_NAME ppppp creating notifier socket +ppppp TESTSUITE/spool/exim_daemon_notify listening on ip6:ip6:ip6:ip6:ip6:ip6:ip6:ip6 port 1225 listening on ip6:ip6:ip6:ip6:ip6:ip6:ip6:ip6 port 1226 pid written to TESTSUITE/spool/exim-daemon.pid @@ -123,6 +128,7 @@ originator: uid=CALLER_UID gid=CALLER_GID login=CALLER name=CALLER_NAME daemon_smtp_port overridden by -oX: <: 1227 creating notifier socket + TESTSUITE/spool/exim_daemon_notify listening on all interfaces (IPv6) port 1227 listening on all interfaces (IPv4) port 1227 listening on 127.0.0.1 port 1228 @@ -149,6 +155,7 @@ daemon_smtp_port overridden by -oX: local_interfaces overridden by -oX: <; 127.0.0.1 creating notifier socket + TESTSUITE/spool/exim_daemon_notify listening on 127.0.0.1 port 1227 listening on 127.0.0.1 port 1225 pid written to TESTSUITE/spool/exim-daemon.pid @@ -172,6 +179,7 @@ originator: uid=CALLER_UID gid=CALLER_GID login=CALLER name=CALLER_NAME local_interfaces overridden by -oX: <; ::0.1225; 0.0.0.0.1225; 0.0.0.0.1226 creating notifier socket + TESTSUITE/spool/exim_daemon_notify listening on all interfaces (IPv6) port 1225 listening on all interfaces (IPv4) port 1225 listening on all interfaces (IPv4) port 1226 diff --git a/test/stderr/2201 b/test/stderr/2201 index 181a27f77..34426ed13 100644 --- a/test/stderr/2201 +++ b/test/stderr/2201 @@ -194,6 +194,7 @@ dropping to exim gid; retaining priv uid ppppp daemon_smtp_port overridden by -oX: ppppp <: 1225 ppppp creating notifier socket +ppppp TESTSUITE/spool/exim_daemon_notify ppppp listening on all interfaces (IPv4) port 1225 ppppp pid written to TESTSUITE/spool/exim-daemon.pid ppppp LOG: MAIN -- 2.30.2