Lines 36-42
Link Here
|
36 |
# include <security/pam_appl.h> |
36 |
# include <security/pam_appl.h> |
37 |
# include <security/openpam.h> |
37 |
# include <security/openpam.h> |
38 |
#endif |
38 |
#endif |
|
|
39 |
#include <magic.h> |
40 |
#include <inttypes.h> |
39 |
|
41 |
|
|
|
42 |
magic_t Magic = NULL; /* Try to set Content-Type in generated e-mail? */ |
40 |
|
43 |
|
41 |
static void child_process(entry *, user *), |
44 |
static void child_process(entry *, user *), |
42 |
do_univ(user *); |
45 |
do_univ(user *); |
Lines 442-448
Link Here
|
442 |
|
445 |
|
443 |
/*local*/{ |
446 |
/*local*/{ |
444 |
register FILE *in = fdopen(stdout_pipe[READ_PIPE], "r"); |
447 |
register FILE *in = fdopen(stdout_pipe[READ_PIPE], "r"); |
445 |
register int ch; |
448 |
char buf[BUFSIZ]; |
|
|
449 |
size_t bufsize; |
446 |
|
450 |
|
447 |
if (in == NULL) { |
451 |
if (in == NULL) { |
448 |
warn("fdopen failed in child"); |
452 |
warn("fdopen failed in child"); |
Lines 449-463
Link Here
|
449 |
_exit(ERROR_EXIT); |
453 |
_exit(ERROR_EXIT); |
450 |
} |
454 |
} |
451 |
|
455 |
|
452 |
ch = getc(in); |
456 |
/* |
453 |
if (ch != EOF) { |
457 |
* Read a little bit of the job's output -- enough to |
|
|
458 |
* determine the * Content-Type of it... |
459 |
*/ |
460 |
bufsize = fread(buf, sizeof(char), |
461 |
sizeof(buf)/sizeof(char), in); |
462 |
|
463 |
if (bufsize > 0) { |
454 |
register FILE *mail; |
464 |
register FILE *mail; |
455 |
register int bytes = 1; |
465 |
off_t bytes = 0; |
456 |
int status = 0; |
466 |
int status = 0; |
457 |
|
467 |
|
458 |
Debug(DPROC|DEXT, |
468 |
Debug(DPROC|DEXT, |
459 |
("[%d] got data (%x:%c) from grandchild\n", |
469 |
("[%d] got data (%x:%c) from grandchild, %d chars\n", |
460 |
getpid(), ch, ch)) |
470 |
getpid(), buf[0], buf[0], (int)bufsize)) |
461 |
|
471 |
|
462 |
/* get name of recipient. this is MAILTO if set to a |
472 |
/* get name of recipient. this is MAILTO if set to a |
463 |
* valid local username; USER otherwise. |
473 |
* valid local username; USER otherwise. |
Lines 483-488
Link Here
|
483 |
register char **env; |
493 |
register char **env; |
484 |
auto char mailcmd[MAX_COMMAND]; |
494 |
auto char mailcmd[MAX_COMMAND]; |
485 |
auto char hostname[MAXHOSTNAMELEN]; |
495 |
auto char hostname[MAXHOSTNAMELEN]; |
|
|
496 |
const char *mimetype; |
486 |
|
497 |
|
487 |
if (gethostname(hostname, MAXHOSTNAMELEN) == -1) |
498 |
if (gethostname(hostname, MAXHOSTNAMELEN) == -1) |
488 |
hostname[0] = '\0'; |
499 |
hostname[0] = '\0'; |
Lines 496-501
Link Here
|
496 |
fprintf(mail, "From: Cron Daemon <%s@%s>\n", |
507 |
fprintf(mail, "From: Cron Daemon <%s@%s>\n", |
497 |
usernm, hostname); |
508 |
usernm, hostname); |
498 |
fprintf(mail, "To: %s\n", mailto); |
509 |
fprintf(mail, "To: %s\n", mailto); |
|
|
510 |
|
511 |
if (Magic) { |
512 |
mimetype = magic_buffer(Magic, |
513 |
buf, bufsize*sizeof(char)); |
514 |
if (mimetype == NULL) { |
515 |
fprintf(mail, |
516 |
"X-Cron-MagicError: %s\n", |
517 |
magic_error(Magic)); |
518 |
} else { |
519 |
fprintf(mail, |
520 |
"Mime-Version: 1.0\n" |
521 |
"Content-Type: %s\n" |
522 |
"Content-Transfer-" |
523 |
"Encoding: 8bit\n", |
524 |
mimetype); |
525 |
} |
526 |
} |
527 |
|
499 |
fprintf(mail, "Subject: Cron <%s@%s> %s\n", |
528 |
fprintf(mail, "Subject: Cron <%s@%s> %s\n", |
500 |
usernm, first_word(hostname, "."), |
529 |
usernm, first_word(hostname, "."), |
501 |
e->cmd); |
530 |
e->cmd); |
Lines 507-516
Link Here
|
507 |
fprintf(mail, "X-Cron-Env: <%s>\n", |
536 |
fprintf(mail, "X-Cron-Env: <%s>\n", |
508 |
*env); |
537 |
*env); |
509 |
fprintf(mail, "\n"); |
538 |
fprintf(mail, "\n"); |
510 |
|
|
|
511 |
/* this was the first char from the pipe |
512 |
*/ |
513 |
putc(ch, mail); |
514 |
} |
539 |
} |
515 |
|
540 |
|
516 |
/* we have to read the input pipe no matter whether |
541 |
/* we have to read the input pipe no matter whether |
Lines 517-529
Link Here
|
517 |
* we mail or not, but obviously we only write to |
542 |
* we mail or not, but obviously we only write to |
518 |
* mail pipe if we ARE mailing. |
543 |
* mail pipe if we ARE mailing. |
519 |
*/ |
544 |
*/ |
|
|
545 |
do { |
546 |
if (mailto) { |
547 |
bytes += sizeof(char) * |
548 |
fwrite(buf, sizeof(char), |
549 |
bufsize, mail); |
550 |
} |
551 |
bufsize = fread(buf, sizeof(char), |
552 |
sizeof(buf)/sizeof(char), in); |
553 |
} while (bufsize != 0); |
520 |
|
554 |
|
521 |
while (EOF != (ch = getc(in))) { |
|
|
522 |
bytes++; |
523 |
if (mailto) |
524 |
putc(ch, mail); |
525 |
} |
526 |
|
527 |
/* only close pipe if we opened it -- i.e., we're |
555 |
/* only close pipe if we opened it -- i.e., we're |
528 |
* mailing... |
556 |
* mailing... |
529 |
*/ |
557 |
*/ |
Lines 545-555
Link Here
|
545 |
* what's going on. |
573 |
* what's going on. |
546 |
*/ |
574 |
*/ |
547 |
if (mailto && status) { |
575 |
if (mailto && status) { |
548 |
char buf[MAX_TEMPSTR]; |
|
|
549 |
|
550 |
snprintf(buf, sizeof(buf), |
576 |
snprintf(buf, sizeof(buf), |
551 |
"mailed %d byte%s of output but got status 0x%04x\n", |
577 |
"mailed %jd byte%s of output but got status 0x%04x\n", |
552 |
bytes, (bytes==1)?"":"s", |
578 |
(intmax_t)bytes, (bytes==1)?"":"s", |
553 |
status); |
579 |
status); |
554 |
log_it(usernm, getpid(), "MAIL", buf); |
580 |
log_it(usernm, getpid(), "MAIL", buf); |
555 |
} |
581 |
} |