X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=uip%2Fpost.c;h=6f04593d9854cf84cb3637ba66d1ec0d1f5153f4;hb=79e665fc9bdaa67a9cd2dfd02bd4494bbec7cc2d;hp=79a53aad20b5f1d6edf699d830b667d1c5b28dab;hpb=15e3d453f414fc1b815ec4895960cad312e78ef9;p=mmh diff --git a/uip/post.c b/uip/post.c index 79a53aa..6f04593 100644 --- a/uip/post.c +++ b/uip/post.c @@ -43,8 +43,6 @@ #define FCCS 10 /* max number of fccs allowed */ -#define uptolow(c) ((isalpha(c) && isupper (c)) ? tolower (c) : c) - /* In the following array of structures, the numeric second field of the structures (minchars) is apparently used like this: @@ -146,32 +144,32 @@ struct headers { /* * flags for headers->flags */ -#define HNOP 0x0000 /* just used to keep .set around */ -#define HBAD 0x0001 /* bad header - don't let it through */ -#define HADR 0x0002 /* header has an address field */ -#define HSUB 0x0004 /* Subject: header */ -#define HTRY 0x0008 /* try to send to addrs on header */ -#define HBCC 0x0010 /* don't output this header */ -#define HMNG 0x0020 /* munge this header */ -#define HNGR 0x0040 /* no groups allowed in this header */ -#define HFCC 0x0080 /* FCC: type header */ -#define HNIL 0x0100 /* okay for this header not to have addrs */ -#define HIGN 0x0200 /* ignore this header */ -#define HDCC 0x0400 /* another undocumented feature */ -#define HONE 0x0800 /* Only one address allowed */ -#define HEFM 0x1000 /* Envelope-From: header */ +#define HNOP 0x0000 /* just used to keep .set around */ +#define HBAD 0x0001 /* bad header - don't let it through */ +#define HADR 0x0002 /* header has an address field */ +#define HSUB 0x0004 /* Subject: header */ +#define HTRY 0x0008 /* try to send to addrs on header */ +#define HBCC 0x0010 /* don't output this header, unless MTS_SENDMAIL_PIPE */ +#define HMNG 0x0020 /* munge this header */ +#define HNGR 0x0040 /* no groups allowed in this header */ +#define HFCC 0x0080 /* FCC: type header */ +#define HNIL 0x0100 /* okay for this header not to have addrs */ +#define HIGN 0x0200 /* ignore this header */ +#define HDCC 0x0400 /* another undocumented feature */ +#define HONE 0x0800 /* Only (zero or) one address allowed */ +#define HEFM 0x1000 /* Envelope-From: header */ /* * flags for headers->set */ -#define MFRM 0x0001 /* we've seen a From: */ -#define MDAT 0x0002 /* we've seen a Date: */ -#define MRFM 0x0004 /* we've seen a Resent-From: */ -#define MVIS 0x0008 /* we've seen sighted addrs */ -#define MINV 0x0010 /* we've seen blind addrs */ -#define MSND 0x0020 /* we've seen a Sender: */ -#define MRSN 0x0040 /* We've seen a Resent-Sendr:*/ -#define MEFM 0x0080 /* We've seen Envelope-From: */ +#define MFRM 0x0001 /* we've seen a From: */ +#define MDAT 0x0002 /* we've seen a Date: */ +#define MRFM 0x0004 /* we've seen a Resent-From: */ +#define MVIS 0x0008 /* we've seen sighted addrs */ +#define MINV 0x0010 /* we've seen blind addrs */ +#define MSND 0x0020 /* we've seen a Sender: */ +#define MRSN 0x0040 /* We've seen a Resent-Sendr:*/ +#define MEFM 0x0080 /* We've seen Envelope-From: */ static struct headers NHeaders[] = { @@ -345,10 +343,10 @@ main (int argc, char **argv) case HELPSW: snprintf (buf, sizeof(buf), "%s [switches] file", invo_name); print_help (buf, switches, 0); - done (1); + done (0); case VERSIONSW: print_version(invo_name); - done (1); + done (0); case LIBSW: if (!(cp = *argp++) || *cp == '-') @@ -622,14 +620,13 @@ main (int argc, char **argv) * address for SMTP. * * - If we were given an Envelope-From header, use that. - * - If we were given multiple addresses in the From: header, use - * the Sender: address + * - If we were given a Sender: address, use that. * - Otherwise, use the address on the From: line */ if (msgflags & MEFM) { envelope = efrom; - } else if (fromcount > 1) { + } else if (seensender) { envelope = sender; } else { envelope = from; @@ -637,6 +634,7 @@ main (int argc, char **argv) /* If we are doing a "whom" check */ if (whomsw) { + /* This won't work with MTS_SENDMAIL_PIPE. */ verify_all_addresses (1, envelope); done (0); } @@ -644,7 +642,13 @@ main (int argc, char **argv) if (msgflags & MINV) { make_bcc_file (dashstuff); if (msgflags & MVIS) { - verify_all_addresses (verbose, envelope); + if (sm_mts != MTS_SENDMAIL_PIPE) { + /* It would be nice to have support to call + verify_all_addresses with MTS_SENDMAIL_PIPE, but + that might require running sendmail as root. Note + that spost didn't verify addresses. */ + verify_all_addresses (verbose, envelope); + } post (tmpfil, 0, verbose, envelope); } post (bccfil, 1, verbose, envelope); @@ -739,6 +743,14 @@ putfmt (char *name, char *str, FILE *out) if (hdr->flags & HNIL) fprintf (out, "%s: %s", name, str); else { + /* + * Sender (or Resent-Sender) can have only one address + */ + if ((msgstate == RESENT) ? (hdr->set & MRSN) + : (hdr->set & MSND)) { + advise (NULL, "%s: field requires one address", name); + badmsg++; + } #ifdef notdef advise (NULL, "%s: field requires at least one address", name); badmsg++; @@ -885,18 +897,20 @@ static void start_headers (void) { unsigned char *cp; - char myhost[BUFSIZ], sigbuf[BUFSIZ]; + char sigbuf[BUFSIZ]; struct mailname *mp; myuid = getuid (); mygid = getgid (); time (&tclock); - strncpy (from, getlocaladdr(), sizeof(from)); - strncpy (myhost, LocalName (0), sizeof(myhost)); + /* + * Probably not necessary, but just in case ... + */ - for (cp = myhost; *cp; cp++) - *cp = uptolow (*cp); + from[0] = '\0'; + efrom[0] = '\0'; + sender[0] = '\0'; if ((cp = getfullname ()) && *cp) { strncpy (sigbuf, cp, sizeof(sigbuf)); @@ -933,12 +947,14 @@ finish_headers (FILE *out) advise (NULL, "message has no From: header"); advise (NULL, "See default components files for examples"); badmsg++; + break; } - if (fromcount > 1 && seensender == 0) { - advise (NULL, "A Sender: header is required with multiple " - "From: addresses"); + if (fromcount > 1 && (seensender == 0 && !(msgflags & MEFM))) { + advise (NULL, "A Sender: or Envelope-From: header is required " + "with multiple\nFrom: addresses"); badmsg++; + break; } if (whomsw) @@ -948,6 +964,23 @@ finish_headers (FILE *out) if (msgid) fprintf (out, "Message-ID: <%d.%ld@%s>\n", (int) getpid (), (long) tclock, LocalName (1)); + /* + * If we have multiple From: addresses, make sure we have an + * Sender: header. If we don't have one, then generate one + * from Envelope-From: (which in this case, cannot be blank) + */ + + if (fromcount > 1 && seensender == 0) { + if (efrom[0] == '\0') { + advise (NULL, "Envelope-From cannot be blank when there " + "is multiple From: addresses\nand no Sender: " + "header"); + badmsg++; + } else { + fprintf (out, "Sender: %s\n", efrom); + } + } + if (!(msgflags & MVIS)) fprintf (out, "Bcc: Blind Distribution List: ;\n"); break; @@ -965,11 +998,13 @@ finish_headers (FILE *out) advise (NULL, "message has no Resent-From: header"); advise (NULL, "See default components files for examples"); badmsg++; + break; } - if (fromcount > 1 && seensender == 0) { - advise (NULL, "A Resent-Sender: header is required with " - "multiple Resent-From: addresses"); + if (fromcount > 1 && (seensender == 0 && !(msgflags & MEFM))) { + advise (NULL, "A Resent-Sender: or Envelope-From: header is " + "required with multiple\nResent-From: addresses"); badmsg++; + break; } if (whomsw) @@ -979,6 +1014,23 @@ finish_headers (FILE *out) if (msgid) fprintf (out, "Resent-Message-ID: <%d.%ld@%s>\n", (int) getpid (), (long) tclock, LocalName (1)); + /* + * If we have multiple Resent-From: addresses, make sure we have an + * Resent-Sender: header. If we don't have one, then generate one + * from Envelope-From (which in this case, cannot be blank) + */ + + if (fromcount > 1 && seensender == 0) { + if (efrom[0] == '\0') { + advise (NULL, "Envelope-From cannot be blank when there " + "is multiple Resent-From: addresses and no " + "Resent-Sender: header"); + badmsg++; + } else { + fprintf (out, "Resent-Sender: %s\n", efrom); + } + } + if (!(msgflags & MVIS)) fprintf (out, "Resent-Bcc: Blind Re-Distribution List: ;\n"); break; @@ -1013,7 +1065,8 @@ putadr (char *name, char *aka, struct mailname *mp, FILE *out, unsigned int flag if (mp->m_mbox == NULL || ((flags & HTRY) && !insert (mp))) return 0; - if ((flags & (HBCC | HDCC | HEFM)) || mp->m_ingrp) + if (sm_mts != MTS_SENDMAIL_PIPE && + ((flags & (HBCC | HDCC | HEFM)) || mp->m_ingrp)) return 1; if (!nameoutput) { @@ -1057,7 +1110,7 @@ putgrp (char *name, char *group, FILE *out, unsigned int flags) int len; char *cp; - if (flags & HBCC) + if (sm_mts != MTS_SENDMAIL_PIPE && (flags & HBCC)) return; if (!nameoutput) { @@ -1419,10 +1472,10 @@ do_addresses (int bccque, int talk) static void post (char *file, int bccque, int talk, char *envelope) { - int fd, onex; - int retval; + int fd; + int retval, i; + pid_t child_id; - onex = !(msgflags & MINV) || bccque; if (verbose) { if (msgflags & MINV) printf (" -- Posting for %s Recipients --\n", @@ -1433,31 +1486,64 @@ post (char *file, int bccque, int talk, char *envelope) sigon (); - if (rp_isbad (retval = sm_init (clientsw, serversw, port, watch, verbose, - snoop, onex, queued, sasl, saslssf, - saslmech, user, tls)) - || rp_isbad (retval = sm_winit (envelope))) - die (NULL, "problem initializing server; %s", rp_string (retval)); - - do_addresses (bccque, talk && verbose); - if ((fd = open (file, O_RDONLY)) == NOTOK) - die (file, "unable to re-open"); - do_text (file, fd); - close (fd); - fflush (stdout); + if (sm_mts == MTS_SENDMAIL_PIPE) { + char *sargv[16], **argp; - sm_end (onex ? OK : DONE); - sigoff (); + for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) + sleep (5); + switch (child_id) { + case NOTOK: + adios ("fork", "unable to"); - if (verbose) { - if (msgflags & MINV) - printf (" -- %s Recipient Copies Posted --\n", - bccque ? "Blind" : "Sighted"); - else - printf (" -- Recipient Copies Posted --\n"); - } + case OK: + if (freopen( file, "r", stdin) == NULL) { + adios (file, "can't reopen for sendmail"); + } - fflush (stdout); + argp = sargv; + *argp++ = "sendmail"; + *argp++ = "-t"; /* read msg for recipients */ + *argp++ = "-i"; /* don't stop on "." */ + if (whomsw) + *argp++ = "-bv"; + if (snoop) + *argp++ = "-v"; + *argp = NULL; + + execv (sendmail, sargv); + adios (sendmail, "can't exec"); + + default: + pidXwait (child_id, NULL); + break; + } + } else { + if (rp_isbad (retval = sm_init (clientsw, serversw, port, watch, + verbose, snoop, queued, sasl, + saslssf, saslmech, user, tls)) || + rp_isbad (retval = sm_winit (envelope))) + die (NULL, "problem initializing server; %s", rp_string (retval)); + + do_addresses (bccque, talk && verbose); + if ((fd = open (file, O_RDONLY)) == NOTOK) + die (file, "unable to re-open"); + do_text (file, fd); + close (fd); + fflush (stdout); + + sm_end (!(msgflags & MINV) || bccque ? OK : DONE); + sigoff (); + + if (verbose) { + if (msgflags & MINV) + printf (" -- %s Recipient Copies Posted --\n", + bccque ? "Blind" : "Sighted"); + else + printf (" -- Recipient Copies Posted --\n"); + } + + fflush (stdout); + } } @@ -1473,7 +1559,7 @@ verify_all_addresses (int talk, char *envelope) if (!whomsw || checksw) if (rp_isbad (retval = sm_init (clientsw, serversw, port, watch, - verbose, snoop, 0, queued, sasl, + verbose, snoop, queued, sasl, saslssf, saslmech, user, tls)) || rp_isbad (retval = sm_winit (envelope))) die (NULL, "problem initializing server; %s", rp_string (retval));