Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 03 Sep 2019 14:07:28 -0000
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r346514 - in stable: 11/usr.sbin/cron/cron 11/usr.sbin/cron/crontab 12/usr.sbin/cron/cron 12/usr.sbin/cron/crontab
Message-ID:  <201904220306.x3M36Do1073208@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Mon Apr 22 03:06:12 2019
New Revision: 346514
URL: https://svnweb.freebsd.org/changeset/base/346514

Log:
  MFC r346252: 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.
  
  PR:		140304

Modified:
  stable/12/usr.sbin/cron/cron/cron.8
  stable/12/usr.sbin/cron/cron/do_command.c
  stable/12/usr.sbin/cron/crontab/crontab.5
Directory Properties:
  stable/12/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/11/usr.sbin/cron/cron/cron.8
  stable/11/usr.sbin/cron/cron/do_command.c
  stable/11/usr.sbin/cron/crontab/crontab.5
Directory Properties:
  stable/11/   (props changed)

Modified: stable/12/usr.sbin/cron/cron/cron.8
==============================================================================
--- stable/12/usr.sbin/cron/cron/cron.8	Mon Apr 22 03:04:39 2019	(r346513)
+++ stable/12/usr.sbin/cron/cron/cron.8	Mon Apr 22 03:06:12 2019	(r346514)
@@ -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 cro
 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

Modified: stable/12/usr.sbin/cron/cron/do_command.c
==============================================================================
--- stable/12/usr.sbin/cron/cron/do_command.c	Mon Apr 22 03:04:39 2019	(r346513)
+++ stable/12/usr.sbin/cron/cron/do_command.c	Mon Apr 22 03:06:12 2019	(r346514)
@@ -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, "."),

Modified: stable/12/usr.sbin/cron/crontab/crontab.5
==============================================================================
--- stable/12/usr.sbin/cron/crontab/crontab.5	Mon Apr 22 03:04:39 2019	(r346513)
+++ stable/12/usr.sbin/cron/crontab/crontab.5	Mon Apr 22 03:06:12 2019	(r346514)
@@ -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.





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201904220306.x3M36Do1073208>