From: mmaslano Date: Fri, 17 Aug 2007 13:13:20 +0000 (+0200) Subject: Option -m was added: it's possible to use something else then sendmail. X-Git-Tag: v4.2~47 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=99267df3ed42d1c246e4a89ece66c16d6cb53003;p=cronie Option -m was added: it's possible to use something else then sendmail. --- diff --git a/cron.8 b/cron.8 index ab47564..7bc5a22 100644 --- a/cron.8 +++ b/cron.8 @@ -29,6 +29,7 @@ cron \- daemon to execute scheduled commands (ISC Cron V4.1) .IR load_avg ] .RB [ \-n ] .RB [ \-p ] +.RB [ \-m ] .SH DESCRIPTION .I Cron should be started from /etc/rc or /etc/rc.local. It will return immediately, @@ -63,6 +64,16 @@ need not be restarted whenever a crontab file is modified. Note that the .IR Crontab (1) command updates the modtime of the spool directory whenever it changes a crontab. +.PP +The +.B -m +option allows you to specify a shell command string to use for sending +cron mail output instead of +.IR sendmail (8). +This command must accept a fully +formatted mail message (with headers) on stdin and send it as a mail +message to the recipients specified in the mail headers. +.PP .SS Daylight Saving Time and other time changes Local time changes of less than three hours, such as those caused by the start or end of Daylight Saving Time, are handled specially. diff --git a/cron.c b/cron.c index 0fc1d38..4491297 100644 --- a/cron.c +++ b/cron.c @@ -48,7 +48,7 @@ static void usage(void) { const char **dflags; - fprintf(stderr, "usage: %s [-n] [-p] [-x [", ProgramName); + fprintf(stderr, "usage: %s [-n] [-p] [-m ] [-x [", ProgramName); for (dflags = DebugFlagNames; *dflags; dflags++) fprintf(stderr, "%s%s", *dflags, dflags[1] ? "," : "]"); fprintf(stderr, "]\n"); @@ -437,7 +437,7 @@ static void parse_args(int argc, char *argv[]) { int argch; - while (-1 != (argch = getopt(argc, argv, "npx:"))) { + while (-1 != (argch = getopt(argc, argv, "npx:m:"))) { switch (argch) { default: usage(); @@ -451,6 +451,9 @@ parse_args(int argc, char *argv[]) { case 'p': PermitAnyCrontab=1; break; + case 'm': + strncpy(MailCmd, optarg, MAX_COMMAND); + break; } } } diff --git a/do_command.c b/do_command.c index ee17b44..9574df4 100644 --- a/do_command.c +++ b/do_command.c @@ -508,16 +508,24 @@ child_process(entry *e, user *u) { char hostname[MAXHOSTNAMELEN]; gethostname(hostname, MAXHOSTNAMELEN); - if (strlens(MAILFMT, MAILARG, NULL) + 1 - >= sizeof mailcmd) { - fprintf(stderr, "mailcmd too long\n"); - (void) _exit(ERROR_EXIT); + + if ( MailCmd[0] == '\0' ) + { + if (strlens(MAILFMT, MAILARG, NULL) + 1 + >= sizeof mailcmd) { + fprintf(stderr, "mailcmd too long\n"); + (void) _exit(ERROR_EXIT); + } + (void)sprintf(mailcmd, MAILFMT, MAILARG); + }else + { + strncpy( mailcmd, MailCmd, MAX_COMMAND ); } - (void)sprintf(mailcmd, MAILFMT, MAILARG); if (!(mail = cron_popen(mailcmd, "w", e->pwd))) { perror(mailcmd); (void) _exit(ERROR_EXIT); } + fprintf(mail, "From: root (Cron Daemon)\n"); fprintf(mail, "To: %s\n", mailto); fprintf(mail, "Subject: Cron <%s@%s> %s\n", diff --git a/globals.h b/globals.h index 22bfae0..a31bec5 100644 --- a/globals.h +++ b/globals.h @@ -65,6 +65,7 @@ XTRN time_t StartTime INIT(0); XTRN int NoFork INIT(0); XTRN int PermitAnyCrontab INIT(0); XTRN int ValidateMailRcpts INIT(0); +XTRN char MailCmd[MAX_COMMAND] INIT(""); #if DEBUGGING XTRN int DebugFlags INIT(0);