From 9a6369d8f1a402331ada1e6fda43153ecb5e421f Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Wed, 20 Jun 2018 13:02:55 +0200 Subject: [PATCH] reference: specify recipient in message when sending email Instead of adding the recipient to the sendmail command line (which is interpretted by the shell) add a "To" line to the message and run sendmail with the -t option to read the recipient from the message. --- reference.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/reference.c b/reference.c index 0ae7ab2..9c1d70f 100644 --- a/reference.c +++ b/reference.c @@ -539,7 +539,7 @@ maybe_log_offset(double offset, time_t now) if (do_mail_change && (abs_offset > mail_change_threshold)) { - snprintf(buffer, sizeof(buffer), "%s %." S_MAX_USER_LEN "s", MAIL_PROGRAM, mail_change_user); + snprintf(buffer, sizeof (buffer), "%s -t", MAIL_PROGRAM); p = popen(buffer, "w"); if (p) { if (gethostname(host, sizeof(host)) < 0) { @@ -547,6 +547,7 @@ maybe_log_offset(double offset, time_t now) } host[sizeof (host) - 1] = '\0'; + fprintf(p, "To: %s\n", mail_change_user); fprintf(p, "Subject: chronyd reports change to system clock on node [%s]\n", host); fputs("\n", p);