aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/cron
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2019-04-15 18:53:28 +0000
committerKyle Evans <kevans@FreeBSD.org>2019-04-15 18:53:28 +0000
commit12455a9e3108df1bd7c0363773b939df7d43b332 (patch)
tree0fe0c57fbc160bc8e6ff909e4ecc90b663396b61 /usr.sbin/cron
parent1631235aa6084c51978c52785c6c0e9837c0a5ba (diff)
downloadsrc-12455a9e3108df1bd7c0363773b939df7d43b332.tar.gz
src-12455a9e3108df1bd7c0363773b939df7d43b332.zip
cron(8): Add MAILFROM ability for crontabs
This changes the sender mail address in a similar fashion to how MAILTO may change the recipient. The default from address remains unchanged. MFC after: 1 week
Notes
Notes: svn path=/head/; revision=346252
Diffstat (limited to 'usr.sbin/cron')
-rw-r--r--usr.sbin/cron/cron/cron.85
-rw-r--r--usr.sbin/cron/cron/do_command.c11
-rw-r--r--usr.sbin/cron/crontab/crontab.55
3 files changed, 16 insertions, 5 deletions
diff --git a/usr.sbin/cron/cron/cron.8 b/usr.sbin/cron/cron/cron.8
index 5dc9595e0061..c436cc2d3962 100644
--- a/usr.sbin/cron/cron/cron.8
+++ b/usr.sbin/cron/cron/cron.8
@@ -17,7 +17,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd July 19, 2017
+.Dd April 15, 2019
.Dt CRON 8
.Os
.Sh NAME
@@ -79,6 +79,9 @@ commands, any output is mailed to the owner of the crontab (or to the user
named in the
.Ev MAILTO
environment variable in the crontab, if such exists).
+The from address of this mail may be set with the
+.Ev MAILFROM
+environment variable.
.Pp
Additionally,
.Nm
diff --git a/usr.sbin/cron/cron/do_command.c b/usr.sbin/cron/cron/do_command.c
index f62303a5df29..13d14e442a27 100644
--- a/usr.sbin/cron/cron/do_command.c
+++ b/usr.sbin/cron/cron/do_command.c
@@ -93,7 +93,7 @@ child_process(e, u)
{
int stdin_pipe[2], stdout_pipe[2];
register char *input_data;
- char *usernm, *mailto;
+ char *usernm, *mailto, *mailfrom;
int children = 0;
# if defined(LOGIN_CAP)
struct passwd *pwd;
@@ -111,6 +111,7 @@ child_process(e, u)
*/
usernm = env_get("LOGNAME", e->envp);
mailto = env_get("MAILTO", e->envp);
+ mailfrom = env_get("MAILFROM", e->envp);
#ifdef PAM
/* use PAM to see if the user's account is available,
@@ -503,8 +504,12 @@ child_process(e, u)
warn("%s", MAILCMD);
(void) _exit(ERROR_EXIT);
}
- fprintf(mail, "From: Cron Daemon <%s@%s>\n",
- usernm, hostname);
+ if (mailfrom == NULL || *mailfrom == '\0')
+ fprintf(mail, "From: Cron Daemon <%s@%s>\n",
+ usernm, hostname);
+ else
+ fprintf(mail, "From: Cron Daemon <%s>\n",
+ mailfrom);
fprintf(mail, "To: %s\n", mailto);
fprintf(mail, "Subject: Cron <%s@%s> %s\n",
usernm, first_word(hostname, "."),
diff --git a/usr.sbin/cron/crontab/crontab.5 b/usr.sbin/cron/crontab/crontab.5
index 697242b4d0fc..fa2895a10195 100644
--- a/usr.sbin/cron/crontab/crontab.5
+++ b/usr.sbin/cron/crontab/crontab.5
@@ -17,7 +17,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd June 6, 2018
+.Dd April 15, 2019
.Dt CRONTAB 5
.Os
.Sh NAME
@@ -116,6 +116,9 @@ If
.Ev MAILTO
is defined (and non-empty), mail is
sent to the user so named.
+If
+.Ev MAILFROM
+is defined (and non-empty), its value will be used as the from address.
.Ev MAILTO
may also be used to direct mail to multiple recipients
by separating recipient users with a comma.