Lines 26-31
Link Here
|
26 |
#if defined(sequent) |
26 |
#if defined(sequent) |
27 |
# include <sys/universe.h> |
27 |
# include <sys/universe.h> |
28 |
#endif |
28 |
#endif |
|
|
29 |
#ifndef NO_OPENSSL |
30 |
# include <openssl/bio.h> |
31 |
# include <openssl/evp.h> |
32 |
#endif |
29 |
#if defined(SYSLOG) |
33 |
#if defined(SYSLOG) |
30 |
# include <syslog.h> |
34 |
# include <syslog.h> |
31 |
#endif |
35 |
#endif |
Lines 36-45
Link Here
|
36 |
# include <security/pam_appl.h> |
40 |
# include <security/pam_appl.h> |
37 |
# include <security/openpam.h> |
41 |
# include <security/openpam.h> |
38 |
#endif |
42 |
#endif |
|
|
43 |
#include <magic.h> |
44 |
#include <inttypes.h> |
39 |
|
45 |
|
|
|
46 |
magic_t Magic = NULL; /* Try to set Content-Type in generated e-mail? */ |
40 |
|
47 |
|
41 |
static void child_process(entry *, user *), |
48 |
static void child_process(const entry *, const user *); |
42 |
do_univ(user *); |
49 |
#if defined(sequent) |
|
|
50 |
static void do_univ(const user *); |
51 |
#endif |
43 |
|
52 |
|
44 |
|
53 |
|
45 |
void |
54 |
void |
Lines 85-100
Link Here
|
85 |
Debug(DPROC, ("[%d] main process returning to work\n", getpid())) |
94 |
Debug(DPROC, ("[%d] main process returning to work\n", getpid())) |
86 |
} |
95 |
} |
87 |
|
96 |
|
|
|
97 |
#ifndef NO_OPENSSL |
98 |
static size_t |
99 |
mimefwrite(const void * restrict ptr, size_t size, size_t nmemb, |
100 |
FILE * restrict stream) |
101 |
{ |
102 |
static BIO *base64; |
103 |
int bytes; |
88 |
|
104 |
|
|
|
105 |
Debug(DPROC, ("[%d] PROCESSING binary output %p, %zd, %zd, %p\n", |
106 |
getpid(), ptr, size, nmemb, stream)); |
107 |
|
108 |
if (ptr == NULL) { |
109 |
if (base64 == NULL) |
110 |
return 0; |
111 |
|
112 |
Debug(DPROC, ("[%d] CLOSING base64 output %p\n", |
113 |
getpid(), stream)); |
114 |
|
115 |
BIO_set_close(base64, BIO_NOCLOSE); |
116 |
BIO_free_all(base64); |
117 |
base64 = NULL; |
118 |
return 0; |
119 |
} |
120 |
|
121 |
if (base64 == NULL) { |
122 |
BIO *b64 = BIO_new(BIO_f_base64()); |
123 |
|
124 |
base64 = BIO_new_fp(stream, BIO_NOCLOSE); |
125 |
base64 = BIO_push(b64, base64); |
126 |
} |
127 |
|
128 |
bytes = BIO_write(base64, ptr, size * nmemb); |
129 |
|
130 |
return bytes / size; |
131 |
} |
132 |
#endif |
133 |
|
89 |
static void |
134 |
static void |
90 |
child_process(e, u) |
135 |
child_process(e, u) |
91 |
entry *e; |
136 |
const entry *e; |
92 |
user *u; |
137 |
const user *u; |
93 |
{ |
138 |
{ |
94 |
int stdin_pipe[2], stdout_pipe[2]; |
139 |
int stdin_pipe[2], stdout_pipe[2]; |
95 |
register char *input_data; |
140 |
register char *input_data; |
96 |
char *usernm, *mailto, *mailfrom; |
141 |
char *usernm, *mailto, *mailfrom; |
97 |
int children = 0; |
142 |
int children = 0; |
|
|
143 |
size_t (*writer)(const void * restrict, size_t, size_t, |
144 |
FILE * restrict) = fwrite; |
98 |
# if defined(LOGIN_CAP) |
145 |
# if defined(LOGIN_CAP) |
99 |
struct passwd *pwd; |
146 |
struct passwd *pwd; |
100 |
login_cap_t *lc; |
147 |
login_cap_t *lc; |
Lines 275-285
Link Here
|
275 |
close(stdin_pipe[READ_PIPE]); |
322 |
close(stdin_pipe[READ_PIPE]); |
276 |
close(stdout_pipe[WRITE_PIPE]); |
323 |
close(stdout_pipe[WRITE_PIPE]); |
277 |
|
324 |
|
|
|
325 |
#if defined(sequent) |
278 |
/* set our login universe. Do this in the grandchild |
326 |
/* set our login universe. Do this in the grandchild |
279 |
* so that the child can invoke /usr/lib/sendmail |
327 |
* so that the child can invoke /usr/lib/sendmail |
280 |
* without surprises. |
328 |
* without surprises. |
281 |
*/ |
329 |
*/ |
282 |
do_univ(u); |
330 |
do_univ(u); |
|
|
331 |
#endif |
283 |
|
332 |
|
284 |
# if defined(LOGIN_CAP) |
333 |
# if defined(LOGIN_CAP) |
285 |
/* Set user's entire context, but skip the environment |
334 |
/* Set user's entire context, but skip the environment |
Lines 453-459
Link Here
|
453 |
|
502 |
|
454 |
/*local*/{ |
503 |
/*local*/{ |
455 |
register FILE *in = fdopen(stdout_pipe[READ_PIPE], "r"); |
504 |
register FILE *in = fdopen(stdout_pipe[READ_PIPE], "r"); |
456 |
register int ch; |
505 |
char buf[BUFSIZ]; |
|
|
506 |
size_t bufsize; |
457 |
|
507 |
|
458 |
if (in == NULL) { |
508 |
if (in == NULL) { |
459 |
warn("fdopen failed in child"); |
509 |
warn("fdopen failed in child"); |
Lines 460-474
Link Here
|
460 |
_exit(ERROR_EXIT); |
510 |
_exit(ERROR_EXIT); |
461 |
} |
511 |
} |
462 |
|
512 |
|
463 |
ch = getc(in); |
513 |
/* |
464 |
if (ch != EOF) { |
514 |
* Read a little bit of the job's output -- enough to |
|
|
515 |
* determine the * Content-Type of it... |
516 |
*/ |
517 |
bufsize = fread(buf, sizeof(char), |
518 |
sizeof(buf)/sizeof(char), in); |
519 |
|
520 |
if (bufsize > 0) { |
465 |
register FILE *mail; |
521 |
register FILE *mail; |
466 |
register int bytes = 1; |
522 |
off_t bytes = 0; |
467 |
int status = 0; |
523 |
int status = 0; |
468 |
|
524 |
|
469 |
Debug(DPROC|DEXT, |
525 |
Debug(DPROC|DEXT, |
470 |
("[%d] got data (%x:%c) from grandchild\n", |
526 |
("[%d] got data (%x:%c) from grandchild, " |
471 |
getpid(), ch, ch)) |
527 |
"%zd chars\n", |
|
|
528 |
getpid(), buf[0], buf[0], bufsize)) |
472 |
|
529 |
|
473 |
/* get name of recipient. this is MAILTO if set to a |
530 |
/* get name of recipient. this is MAILTO if set to a |
474 |
* valid local username; USER otherwise. |
531 |
* valid local username; USER otherwise. |
Lines 494-499
Link Here
|
494 |
register char **env; |
551 |
register char **env; |
495 |
auto char mailcmd[MAX_COMMAND]; |
552 |
auto char mailcmd[MAX_COMMAND]; |
496 |
auto char hostname[MAXHOSTNAMELEN]; |
553 |
auto char hostname[MAXHOSTNAMELEN]; |
|
|
554 |
const char *mimetype; |
497 |
|
555 |
|
498 |
if (gethostname(hostname, MAXHOSTNAMELEN) == -1) |
556 |
if (gethostname(hostname, MAXHOSTNAMELEN) == -1) |
499 |
hostname[0] = '\0'; |
557 |
hostname[0] = '\0'; |
Lines 511-516
Link Here
|
511 |
fprintf(mail, "From: Cron Daemon <%s>\n", |
569 |
fprintf(mail, "From: Cron Daemon <%s>\n", |
512 |
mailfrom); |
570 |
mailfrom); |
513 |
fprintf(mail, "To: %s\n", mailto); |
571 |
fprintf(mail, "To: %s\n", mailto); |
|
|
572 |
|
573 |
if (Magic) { |
574 |
mimetype = magic_buffer(Magic, |
575 |
buf, bufsize*sizeof(char)); |
576 |
if (mimetype == NULL) { |
577 |
fprintf(mail, |
578 |
"X-Cron-MagicError: %s\n", |
579 |
magic_error(Magic)); |
580 |
} else { |
581 |
const char *encoding = "8bit"; |
582 |
#ifndef NO_OPENSSL |
583 |
/* |
584 |
* If available, use OpenSSL's |
585 |
* base64 functinality to |
586 |
* convert binary body: |
587 |
*/ |
588 |
if (strstr(mimetype, |
589 |
"charset=binary")) { |
590 |
encoding = "base64"; |
591 |
writer = mimefwrite; |
592 |
} |
593 |
#endif |
594 |
|
595 |
fprintf(mail, |
596 |
"Mime-Version: 1.0\n" |
597 |
"Content-Type: %s\n" |
598 |
"Content-Transfer-" |
599 |
"Encoding: %s\n", |
600 |
mimetype, encoding); |
601 |
} |
602 |
} |
603 |
|
514 |
fprintf(mail, "Subject: Cron <%s@%s> %s\n", |
604 |
fprintf(mail, "Subject: Cron <%s@%s> %s\n", |
515 |
usernm, first_word(hostname, "."), |
605 |
usernm, first_word(hostname, "."), |
516 |
e->cmd); |
606 |
e->cmd); |
Lines 522-531
Link Here
|
522 |
fprintf(mail, "X-Cron-Env: <%s>\n", |
612 |
fprintf(mail, "X-Cron-Env: <%s>\n", |
523 |
*env); |
613 |
*env); |
524 |
fprintf(mail, "\n"); |
614 |
fprintf(mail, "\n"); |
525 |
|
|
|
526 |
/* this was the first char from the pipe |
527 |
*/ |
528 |
putc(ch, mail); |
529 |
} |
615 |
} |
530 |
|
616 |
|
531 |
/* we have to read the input pipe no matter whether |
617 |
/* we have to read the input pipe no matter whether |
Lines 533-544
Link Here
|
533 |
* mail pipe if we ARE mailing. |
619 |
* mail pipe if we ARE mailing. |
534 |
*/ |
620 |
*/ |
535 |
|
621 |
|
536 |
while (EOF != (ch = getc(in))) { |
622 |
do { |
537 |
bytes++; |
623 |
if (mailto) { |
538 |
if (mailto) |
624 |
bytes += sizeof(char) * |
539 |
putc(ch, mail); |
625 |
writer(buf, sizeof(char), |
540 |
} |
626 |
bufsize, mail); |
|
|
627 |
} |
541 |
|
628 |
|
|
|
629 |
bufsize = fread(buf, sizeof(char), |
630 |
sizeof(buf)/sizeof(char), in); |
631 |
} while (bufsize != 0); |
632 |
|
542 |
/* only close pipe if we opened it -- i.e., we're |
633 |
/* only close pipe if we opened it -- i.e., we're |
543 |
* mailing... |
634 |
* mailing... |
544 |
*/ |
635 |
*/ |
Lines 546-551
Link Here
|
546 |
if (mailto) { |
637 |
if (mailto) { |
547 |
Debug(DPROC, ("[%d] closing pipe to mail\n", |
638 |
Debug(DPROC, ("[%d] closing pipe to mail\n", |
548 |
getpid())) |
639 |
getpid())) |
|
|
640 |
#ifndef NO_OPENSSL |
641 |
/* |
642 |
* If we were using mimefwrite, give it a |
643 |
* chance to properly close things down: |
644 |
*/ |
645 |
if (writer == mimefwrite) |
646 |
mimefwrite(NULL, 0, 0, mail); |
647 |
#endif |
549 |
/* Note: the pclose will probably see |
648 |
/* Note: the pclose will probably see |
550 |
* the termination of the grandchild |
649 |
* the termination of the grandchild |
551 |
* in addition to the mail process, since |
650 |
* in addition to the mail process, since |
Lines 560-570
Link Here
|
560 |
* what's going on. |
659 |
* what's going on. |
561 |
*/ |
660 |
*/ |
562 |
if (mailto && status) { |
661 |
if (mailto && status) { |
563 |
char buf[MAX_TEMPSTR]; |
|
|
564 |
|
565 |
snprintf(buf, sizeof(buf), |
662 |
snprintf(buf, sizeof(buf), |
566 |
"mailed %d byte%s of output but got status 0x%04x\n", |
663 |
"mailed %jd byte%s of output but got status 0x%04x\n", |
567 |
bytes, (bytes==1)?"":"s", |
664 |
(intmax_t)bytes, (bytes==1)?"":"s", |
568 |
status); |
665 |
status); |
569 |
log_it(usernm, getpid(), "MAIL", buf); |
666 |
log_it(usernm, getpid(), "MAIL", buf); |
570 |
} |
667 |
} |
Lines 600-610
Link Here
|
600 |
} |
697 |
} |
601 |
|
698 |
|
602 |
|
699 |
|
|
|
700 |
#if defined(sequent) |
603 |
static void |
701 |
static void |
604 |
do_univ(u) |
702 |
do_univ(u) |
605 |
user *u; |
703 |
const user *u; |
606 |
{ |
704 |
{ |
607 |
#if defined(sequent) |
|
|
608 |
/* Dynix (Sequent) hack to put the user associated with |
705 |
/* Dynix (Sequent) hack to put the user associated with |
609 |
* the passed user structure into the ATT universe if |
706 |
* the passed user structure into the ATT universe if |
610 |
* necessary. We have to dig the gecos info out of |
707 |
* necessary. We have to dig the gecos info out of |
Lines 634-638
Link Here
|
634 |
return; |
731 |
return; |
635 |
|
732 |
|
636 |
(void) universe(U_ATT); |
733 |
(void) universe(U_ATT); |
|
|
734 |
} |
637 |
#endif |
735 |
#endif |
638 |
} |
|
|