Lines 33-37
Link Here
|
33 |
# include <login_cap.h> |
33 |
# include <login_cap.h> |
34 |
#endif |
34 |
#endif |
|
|
35 |
#include <magic.h> |
36 |
#include <inttypes.h> |
35 |
|
37 |
|
|
|
38 |
magic_t Magic = NULL; /* Try to set Content-Type in generated e-mail? */ |
36 |
|
39 |
|
37 |
static void child_process __P((entry *, user *)), |
40 |
static void child_process __P((entry *, user *)), |
Lines 394-398
Link Here
|
394 |
/*local*/{ |
397 |
/*local*/{ |
395 |
register FILE *in = fdopen(stdout_pipe[READ_PIPE], "r"); |
398 |
register FILE *in = fdopen(stdout_pipe[READ_PIPE], "r"); |
396 |
register int ch; |
399 |
char buf[BUFSIZ]; |
|
|
400 |
size_t bufsize; |
397 |
|
401 |
|
398 |
if (in == NULL) { |
402 |
if (in == NULL) { |
Lines 401-413
Link Here
|
401 |
} |
405 |
} |
402 |
|
406 |
|
403 |
ch = getc(in); |
407 |
/* |
404 |
if (ch != EOF) { |
408 |
* Read a little bit of the job's output -- enough to |
|
|
409 |
* determine the * Content-Type of it... |
410 |
*/ |
411 |
bufsize = fread(buf, sizeof(char), |
412 |
sizeof(buf)/sizeof(char), in); |
413 |
|
414 |
if (bufsize > 0) { |
405 |
register FILE *mail; |
415 |
register FILE *mail; |
406 |
register int bytes = 1; |
416 |
off_t bytes = 0; |
407 |
int status = 0; |
417 |
int status = 0; |
408 |
|
418 |
|
409 |
Debug(DPROC|DEXT, |
419 |
Debug(DPROC|DEXT, |
410 |
("[%d] got data (%x:%c) from grandchild\n", |
420 |
("[%d] got data (%x:%c) from grandchild, %d chars\n", |
411 |
getpid(), ch, ch)) |
421 |
getpid(), buf[0], buf[0], (int)bufsize)) |
412 |
|
422 |
|
413 |
/* get name of recipient. this is MAILTO if set to a |
423 |
/* get name of recipient. this is MAILTO if set to a |
Lines 437-440
Link Here
|
437 |
auto char mailcmd[MAX_COMMAND]; |
447 |
auto char mailcmd[MAX_COMMAND]; |
438 |
auto char hostname[MAXHOSTNAMELEN]; |
448 |
auto char hostname[MAXHOSTNAMELEN]; |
|
|
449 |
const char *mimetype; |
439 |
|
450 |
|
440 |
(void) gethostname(hostname, MAXHOSTNAMELEN); |
451 |
(void) gethostname(hostname, MAXHOSTNAMELEN); |
Lines 445-450
Link Here
|
445 |
(void) _exit(ERROR_EXIT); |
456 |
(void) _exit(ERROR_EXIT); |
446 |
} |
457 |
} |
|
|
458 |
|
447 |
fprintf(mail, "From: %s (Cron Daemon)\n", usernm); |
459 |
fprintf(mail, "From: %s (Cron Daemon)\n", usernm); |
448 |
fprintf(mail, "To: %s\n", mailto); |
460 |
fprintf(mail, "To: %s\n", mailto); |
|
|
461 |
|
462 |
if (Magic) { |
463 |
mimetype = magic_buffer(Magic, |
464 |
buf, bufsize*sizeof(char)); |
465 |
if (mimetype == NULL) { |
466 |
fprintf(mail, |
467 |
"X-Cron-MagicError: %s\n", |
468 |
magic_error(Magic)); |
469 |
} else { |
470 |
fprintf(mail, |
471 |
"Mime-Version: 1.0\n" |
472 |
"Content-Type: %s\n" |
473 |
"Content-Transfer-" |
474 |
"Encoding: 8bit\n", |
475 |
mimetype); |
476 |
} |
477 |
} |
478 |
|
449 |
fprintf(mail, "Subject: Cron <%s@%s> %s\n", |
479 |
fprintf(mail, "Subject: Cron <%s@%s> %s\n", |
450 |
usernm, first_word(hostname, "."), |
480 |
usernm, first_word(hostname, "."), |
Lines 458-465
Link Here
|
458 |
*env); |
488 |
*env); |
459 |
fprintf(mail, "\n"); |
489 |
fprintf(mail, "\n"); |
460 |
|
|
|
461 |
/* this was the first char from the pipe |
462 |
*/ |
463 |
putc(ch, mail); |
464 |
} |
490 |
} |
465 |
|
491 |
|
Lines 468-477
Link Here
|
468 |
* mail pipe if we ARE mailing. |
494 |
* mail pipe if we ARE mailing. |
469 |
*/ |
495 |
*/ |
470 |
|
496 |
do { |
471 |
while (EOF != (ch = getc(in))) { |
497 |
if (mailto) { |
472 |
bytes++; |
498 |
bytes += sizeof(char) * |
473 |
if (mailto) |
499 |
fwrite(buf, sizeof(char), |
474 |
putc(ch, mail); |
500 |
bufsize, mail); |
475 |
} |
501 |
} |
|
|
502 |
bufsize = fread(buf, sizeof(char), |
503 |
sizeof(buf)/sizeof(char), in); |
504 |
} while (bufsize != 0); |
476 |
|
505 |
|
477 |
/* only close pipe if we opened it -- i.e., we're |
506 |
/* only close pipe if we opened it -- i.e., we're |
Lines 496-504
Link Here
|
496 |
*/ |
525 |
*/ |
497 |
if (mailto && status) { |
526 |
if (mailto && status) { |
498 |
char buf[MAX_TEMPSTR]; |
|
|
499 |
|
500 |
snprintf(buf, sizeof(buf), |
527 |
snprintf(buf, sizeof(buf), |
501 |
"mailed %d byte%s of output but got status 0x%04x\n", |
528 |
"mailed %jd byte%s of output but got status 0x%04x\n", |
502 |
bytes, (bytes==1)?"":"s", |
529 |
(intmax_t)bytes, (bytes==1)?"":"s", |
503 |
status); |
530 |
status); |
504 |
log_it(usernm, getpid(), "MAIL", buf); |
531 |
log_it(usernm, getpid(), "MAIL", buf); |