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.
This commit is contained in:
Miroslav Lichvar 2018-06-20 13:02:55 +02:00
parent 49cdd6bf09
commit 9a6369d8f1

View file

@ -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);