diff --git a/usr.sbin/cron/cron/cron.c b/usr.sbin/cron/cron/cron.c --- a/usr.sbin/cron/cron/cron.c +++ b/usr.sbin/cron/cron/cron.c @@ -56,7 +56,7 @@ #endif fprintf(stderr, "usage: cron [-j jitter] [-J rootjitter] " - "[-m mailto] [-n] [-s] [-o] [-x debugflag[,...]]\n"); + "[-m mailto] [-n] [-s] [-o] [-H] [-x debugflag[,...]]\n"); #if DEBUGGING fprintf(stderr, "\ndebugflags: "); @@ -499,7 +499,7 @@ int argch; char *endp; - while ((argch = getopt(argc, argv, "j:J:m:nosx:")) != -1) { + while ((argch = getopt(argc, argv, "j:J:m:nosHx:")) != -1) { switch (argch) { case 'j': Jitter = strtoul(optarg, &endp, 10); @@ -525,6 +525,9 @@ case 's': dst_enabled = 1; break; + case 'H': + HtmlPreformat = 1; + break; case 'x': if (!set_debug_flags(optarg)) usage(); diff --git a/usr.sbin/cron/cron/do_command.c b/usr.sbin/cron/cron/do_command.c --- a/usr.sbin/cron/cron/do_command.c +++ b/usr.sbin/cron/cron/do_command.c @@ -77,6 +77,23 @@ } +static char* +escape_html(int ch, char *tempbuf) +{ + switch (ch) { + case '<': + return "<"; + case '>': + return ">"; + case '&': + return "&"; + default: + tempbuf[0] = ch; + return tempbuf; + } +} + + static void child_process(entry *e, user *u) { @@ -557,8 +574,11 @@ for (env = e->envp; *env; env++) fprintf(mail, "X-Cron-Env: <%s>\n", *env); + if (HtmlPreformat) + fprintf(mail, "Content-Type: text/html\n"); fprintf(mail, "\n"); - + if (HtmlPreformat) + fprintf(mail, "
\n"); /* this was the first char from the pipe */ putc(ch, mail); @@ -571,9 +591,18 @@ while (EOF != (ch = getc(in))) { bytes++; - if (mail) - putc(ch, mail); + if (mail) { + if (HtmlPreformat) { + char tempbuf[2] = {0, 0}; + char *escapedstring = escape_html(ch, &tempbuf[0]); + fputs(escapedstring, mail); + } else { + putc(ch, mail); + } + } } + if (mailto && HtmlPreformat) + fprintf(mail, "\n"); } /*if data from grandchild*/ diff --git a/usr.sbin/cron/cron/globals.h b/usr.sbin/cron/cron/globals.h --- a/usr.sbin/cron/cron/globals.h +++ b/usr.sbin/cron/cron/globals.h @@ -63,6 +63,7 @@ XTRN unsigned Jitter; XTRN unsigned RootJitter; XTRN time_t TargetTime INIT(0); +XTRN int HtmlPreformat INIT(0); XTRN struct pidfh *pfh; #if DEBUGGING