]> granicus.if.org Git - cronie/commitdiff
MAILFROM, if set, will be used as the envelope sender address when cron
authorMarcela Mašláňová <mmaslano@redhat.com>
Wed, 13 May 2009 14:39:36 +0000 (16:39 +0200)
committerMarcela Mašláňová <mmaslano@redhat.com>
Wed, 13 May 2009 14:39:36 +0000 (16:39 +0200)
mails the output of commands in that crontab.
The initial patch was written by: Heath Caldwell

configure.ac
man/crontab.5
src/do_command.c

index 5ba63f9fce0ec8f5d56fe398025eb143ee9c7109..b11a91f854884ec1bf5ee2704141aaa1f94c6741 100644 (file)
@@ -206,13 +206,14 @@ AC_DEFINE(DEBUGGING,1,[Code will be built with debug info.])
 
 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.])
index 604ad73fbb4f0c41ec9dd2b826d7fa3aebcdfe0c..ca59df7ccbde3d6ce41e578be3f28f5fe7595b0a 100644 (file)
@@ -75,7 +75,8 @@ sent to the user so named.  If MAILTO is defined but empty (MAILTO=""), no
 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 
index c95f9c0b98906d3bad36f001db8f331f20460b0f..cac5bb445ca2414dc1d0af35bdb24e5a52c46199 100644 (file)
@@ -61,7 +61,7 @@ do_command(entry *e, user *u) {
 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();
@@ -92,6 +92,7 @@ child_process(entry *e, user *u) {
         */
        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
@@ -361,7 +362,15 @@ child_process(entry *e, user *u) {
                                 */
                                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...
@@ -382,12 +391,12 @@ child_process(entry *e, user *u) {
                                
                                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 );
@@ -397,7 +406,7 @@ child_process(entry *e, user *u) {
                                        (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, "."),