AC_DEFINE(MAILARG,"/usr/sbin/sendmail",[There will be path to sendmail.])
-AC_DEFINE(MAILFMT,"%s -FCronDaemon -i -odi -oem -oi -t",
+AC_DEFINE(MAILFMT,"%s -FCronDaemon -i -odi -oem -oi -t -f %s",
[-i = don't terminate on "." by itself
-Fx = Set full-name of sender
-odi = Option Deliverymode Interactive
-oem = Option Errors Mailedtosender
-oi = Ignore "." alone on a line
-t = Get recipient from headers
+-f %s = Envelope sender address
-d = undocumented but common flag.])
AC_DEFINE(SYSLOG,1,[Using syslog for log messages.])
mail will be sent. Otherwise mail is sent to the owner of the crontab. This
option is useful if you decide on /bin/mail instead of /usr/lib/sendmail as
your mailer when you install cron -- /bin/mail doesn\'t do aliasing, and UUCP
-usually doesn\'t read its mail.
+usually doesn\'t read its mail. If MAILFROM is defined (and non-empty), it
+will be used as the envelope sender address, otherwise, ``root'' will be used.
.PP
By default, cron will send mail using the mail 'Content-Type:' header of 'text/plain'
with the 'charset=' parameter set to the charmap / codeset of the locale in which
static void
child_process(entry *e, user *u) {
int stdin_pipe[2], stdout_pipe[2];
- char *input_data, *usernm, *mailto;
+ char *input_data, *usernm, *mailto, *mailfrom;
int children = 0;
char **jobenv=0L;
pid_t pid = getpid();
*/
usernm = e->pwd->pw_name;
mailto = env_get("MAILTO", jobenv);
+ mailfrom = env_get("MAILFROM", e->envp);
/* our parent is watching for our death by catching SIGCHLD. we
* do not care to watch for our children's deaths this way -- we
*/
mailto = usernm;
}
-
+
+ /* get sender address. this is MAILFROM if set (and safe),
+ * root otherwise.
+ */
+ if (!mailfrom || !*mailfrom || !safe_p(usernm, mailfrom)) {
+ mailfrom = calloc(5, sizeof(char));
+ strcpy(mailfrom, "root");
+ }
+
/* if we are supposed to be mailing, MAILTO will
* be non-NULL. only in this case should we set
* up the mail command and subjects and stuff...
if ( MailCmd[0] == '\0' )
{
- if (strlens(MAILFMT, MAILARG, NULL) + 1
+ if (strlens(MAILFMT, MAILARG, mailfrom, NULL) + 1
>= sizeof mailcmd) {
fprintf(stderr, "mailcmd too long\n");
(void) _exit(ERROR_EXIT);
}
- (void)sprintf(mailcmd, MAILFMT, MAILARG);
+ (void)sprintf(mailcmd, MAILFMT, MAILARG, mailfrom);
}else
{
strncpy( mailcmd, MailCmd, MAX_COMMAND );
(void) _exit(ERROR_EXIT);
}
- fprintf(mail, "From: root (Cron Daemon)\n");
+ fprintf(mail, "From: %s (Cron Daemon)\n", mailfrom);
fprintf(mail, "To: %s\n", mailto);
fprintf(mail, "Subject: Cron <%s@%s> %s\n",
usernm, first_word(hostname, "."),