X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/acd8a635510ea87b8940c13c5c664a0fc18ebae1..803f25412:/uip/post.c?ds=sidebyside diff --git a/uip/post.c b/uip/post.c index 9bbaa5f5..0beab55b 100644 --- a/uip/post.c +++ b/uip/post.c @@ -76,13 +76,13 @@ X("server host", 6, SERVSW) /* specify alternate SMTP server */ \ X("snoop", -5, SNOOPSW) /* snoop the SMTP transaction */ \ X("partno", -6, PARTSW) \ - X("queued", -6, QUEUESW) \ X("sasl", SASLminc(-4), SASLSW) \ X("nosasl", SASLminc(-6), NOSASLSW) \ X("saslmaxssf", SASLminc(-10), SASLMXSSFSW) \ X("saslmech", SASLminc(-5), SASLMECHSW) \ + X("oauth", -5, OAUTHSW) \ X("user", SASLminc(-4), USERSW) \ - X("port server port name/number", 4, PORTSW) \ + X("port server submission port name/number", 4, PORTSW) \ X("tls", TLSminc(-3), TLSSW) \ X("initialtls", TLSminc(-10), INITTLSSW) \ X("notls", TLSminc(-5), NTLSSW) \ @@ -201,8 +201,8 @@ static int sasl=0; /* Use SASL auth for SMTP */ static int saslssf=-1; /* Our maximum SSF for SASL */ static char *saslmech=NULL; /* Force use of particular SASL mech */ static char *user=NULL; /* Authenticate as this user */ -static char *port="smtp"; /* Name of server port for SMTP */ -static int tls=0; /* Use TLS for encryption */ +static char *port="submission"; /* Name of server port for SMTP submission */ +static int tls=-1; /* Use TLS for encryption */ static int fromcount=0; /* Count of addresses on From: header */ static int seensender=0; /* Have we seen a Sender: header? */ @@ -223,7 +223,6 @@ static char from[BUFSIZ]; /* my network address */ static char sender[BUFSIZ]; /* my Sender: header */ static char efrom[BUFSIZ]; /* my Envelope-From: header */ static char fullfrom[BUFSIZ]; /* full contents of From header */ -static char signature[BUFSIZ]; /* my signature */ static char *filter = NULL; /* the filter for BCC'ing */ static char *subject = NULL; /* the subject field for BCC'ing */ static char *fccfold[FCCS]; /* foldernames for FCC'ing */ @@ -239,12 +238,9 @@ static int snoop = 0; static char *clientsw = NULL; static char *serversw = NULL; -extern struct smtp sm_reply; - static char prefix[] = "----- =_aaaaaaaaaa"; static char *partno = NULL; -static int queued = 0; /* * static prototypes @@ -261,14 +257,14 @@ static void anno (void); static int annoaux (struct mailname *); static void insert_fcc (struct headers *, char *); static void make_bcc_file (int); -static void verify_all_addresses (int, char *); +static void verify_all_addresses (int, char *, const char *); static void chkadr (void); static void sigon (void); static void sigoff (void); static void p_refile (char *); static void fcc (char *, char *); static void die (char *, char *, ...); -static void post (char *, int, int, char *); +static void post (char *, int, int, char *, const char *); static void do_text (char *file, int fd); static void do_an_address (struct mailname *, int); static void do_addresses (int, int); @@ -283,15 +279,9 @@ main (int argc, char **argv) char buf[BUFSIZ], name[NAMESZ]; FILE *in, *out; m_getfld_state_t gstate = 0; + char *xoauth_client_res = NULL; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* foil search of user profile/context */ - if (context_foil (NULL) == -1) - done (1); + if (nmh_init(argv[0], 0 /* use context_foil() */)) { return 1; } mts_init (invo_name); arguments = getarguments (invo_name, argc, argv, 0); @@ -432,10 +422,6 @@ main (int argc, char **argv) adios (NULL, "missing argument to %s", argp[-2]); continue; - case QUEUESW: - queued++; - continue; - case SASLSW: sasl++; continue; @@ -454,7 +440,13 @@ main (int argc, char **argv) if (!(saslmech = *argp++) || *saslmech == '-') adios (NULL, "missing argument to %s", argp[-2]); continue; - + + case OAUTHSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + xoauth_client_res = cp; + continue; + case USERSW: if (!(user = *argp++) || *user == '-') adios (NULL, "missing argument to %s", argp[-2]); @@ -536,15 +528,12 @@ main (int argc, char **argv) if ((out = fopen ("/dev/null", "w")) == NULL) adios ("/dev/null", "unable to open"); } else { - char *cp = m_mktemp(m_maildir(invo_name), NULL, &out); - if (cp == NULL) { - cp = m_mktemp2(NULL, invo_name, NULL, &out); - if (cp == NULL) { - adios ("post", "unable to create temporary file"); - } - } + char *cp = m_mktemp2(NULL, invo_name, NULL, &out); + if (cp == NULL) { + adios(NULL, "unable to create temporary file in %s", + get_temp_dir()); + } strncpy(tmpfil, cp, sizeof(tmpfil)); - chmod (tmpfil, 0600); } } @@ -621,10 +610,25 @@ main (int argc, char **argv) envelope = from; } + if (tls == -1) { +#ifdef TLS_SUPPORT + /* + * The user didn't specify any of the tls switches. Try to + * help them by implying -initialtls if they're using port 465 + * (smtps, until IANA revoked that registration in 1998). + */ + tls = ! strcmp (port, "465") || ! strcasecmp (port, "smtps") + ? 2 + : 0; +#else /* ! TLS_SUPPORT */ + tls = 0; +#endif /* ! TLS_SUPPORT */ + } + /* If we are doing a "whom" check */ if (whomsw) { /* This won't work with MTS_SENDMAIL_PIPE. */ - verify_all_addresses (1, envelope); + verify_all_addresses (1, envelope, xoauth_client_res); done (0); } @@ -636,18 +640,18 @@ main (int argc, char **argv) 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); + verify_all_addresses (verbose, envelope, xoauth_client_res); } - post (tmpfil, 0, verbose, envelope); + post (tmpfil, 0, verbose, envelope, xoauth_client_res); } - post (bccfil, 1, verbose, envelope); - unlink (bccfil); + post (bccfil, 1, verbose, envelope, xoauth_client_res); + (void) m_unlink (bccfil); } else { - post (tmpfil, 0, isatty (1), envelope); + post (tmpfil, 0, isatty (1), envelope, xoauth_client_res); } p_refile (tmpfil); - unlink (tmpfil); + (void) m_unlink (tmpfil); if (verbose) { if (partno) @@ -670,7 +674,7 @@ putfmt (char *name, char *str, FILE *out) { int count, grp, i, keep; char *cp, *pp, *qp; - char namep[BUFSIZ]; + char namep[BUFSIZ], error[BUFSIZ]; struct mailname *mp = NULL, *np = NULL; struct headers *hdr; @@ -718,7 +722,7 @@ putfmt (char *name, char *str, FILE *out) if (hdr->flags & HFCC) { if ((cp = strrchr(str, '\n'))) *cp = 0; - for (cp = pp = str; (cp = strchr(pp, ',')); pp = cp) { + for (pp = str; (cp = strchr(pp, ',')); pp = cp) { *cp++ = 0; insert_fcc (hdr, pp); } @@ -733,18 +737,20 @@ putfmt (char *name, char *str, FILE *out) tmpaddrs.m_next = NULL; for (count = 0; (cp = getname (str)); count++) - if ((mp = getm (cp, NULL, 0, AD_HOST, NULL))) { + if ((mp = getm (cp, NULL, 0, error, sizeof(error)))) { if (tmpaddrs.m_next) np->m_next = mp; else tmpaddrs.m_next = mp; np = mp; } - else + else { + admonish(cp, "%s", error); if (hdr->flags & HTRY) badadr++; else badmsg++; + } if (count < 1) { if (hdr->flags & HNIL) @@ -785,7 +791,8 @@ putfmt (char *name, char *str, FILE *out) if (np->m_gname) putgrp (namep, np->m_gname, out, hdr->flags); while ((cp = getname (pp))) { - if (!(mp = getm (cp, NULL, 0, AD_HOST, NULL))) { + if (!(mp = getm (cp, NULL, 0, error, sizeof(error)))) { + admonish(cp, "%s", error); badadr++; continue; } @@ -934,9 +941,6 @@ putfmt (char *name, char *str, FILE *out) static void start_headers (void) { - char *cp, sigbuf[BUFSIZ]; - struct mailname *mp; - time (&tclock); /* @@ -947,21 +951,6 @@ start_headers (void) efrom[0] = '\0'; sender[0] = '\0'; fullfrom[0] = '\0'; - - if ((cp = getfullname ()) && *cp) { - strncpy (sigbuf, cp, sizeof(sigbuf)); - snprintf (signature, sizeof(signature), "%s <%s>", - sigbuf, getlocaladdr()); - if ((cp = getname (signature)) == NULL) - adios (NULL, "getname () failed -- you lose extraordinarily big"); - if ((mp = getm (cp, NULL, 0, AD_HOST, NULL)) == NULL) - adios (NULL, "bad signature '%s'", sigbuf); - mnfree (mp); - while (getname ("")) - continue; - } else { - strncpy (signature, getlocaladdr(), sizeof(signature)); - } } @@ -1298,8 +1287,9 @@ make_bcc_file (int dashstuff) FILE *out; char *tfile = NULL, *program; - tfile = m_mktemp2(NULL, "bccs", NULL, &out); - if (tfile == NULL) adios("bcc", "unable to create temporary file"); + if ((tfile = m_mktemp2(NULL, "bccs", NULL, &out)) == NULL) { + adios(NULL, "unable to create temporary file in %s", get_temp_dir()); + } strncpy (bccfil, tfile, sizeof(bccfil)); fprintf (out, "From: %s\n", fullfrom); @@ -1504,7 +1494,8 @@ do_addresses (int bccque, int talk) */ static void -post (char *file, int bccque, int talk, char *envelope) +post (char *file, int bccque, int talk, char *envelope, + const char *xoauth_client_res) { int fd; int retval, i; @@ -1553,9 +1544,9 @@ post (char *file, int bccque, int talk, char *envelope) } } 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))) + verbose, snoop, sasl, saslssf, + saslmech, user, xoauth_client_res, tls)) + || rp_isbad (retval = sm_winit (envelope))) die (NULL, "problem initializing server; %s", rp_string (retval)); do_addresses (bccque, talk && verbose); @@ -1584,7 +1575,7 @@ post (char *file, int bccque, int talk, char *envelope) /* Address Verification */ static void -verify_all_addresses (int talk, char *envelope) +verify_all_addresses (int talk, char *envelope, const char *xoauth_client_res) { int retval; struct mailname *lp; @@ -1593,8 +1584,8 @@ verify_all_addresses (int talk, char *envelope) if (!whomsw || checksw) if (rp_isbad (retval = sm_init (clientsw, serversw, port, watch, - verbose, snoop, queued, sasl, - saslssf, saslmech, user, tls)) + verbose, snoop, sasl, saslssf, + saslmech, user, xoauth_client_res, tls)) || rp_isbad (retval = sm_winit (envelope))) die (NULL, "problem initializing server; %s", rp_string (retval)); @@ -1730,9 +1721,9 @@ sigser (int i) { NMH_UNUSED (i); - unlink (tmpfil); + (void) m_unlink (tmpfil); if (msgflags & MINV) - unlink (bccfil); + (void) m_unlink (bccfil); if (!whomsw || checksw) sm_end (NOTOK); @@ -1854,9 +1845,9 @@ die (char *what, char *fmt, ...) { va_list ap; - unlink (tmpfil); + (void) m_unlink (tmpfil); if (msgflags & MINV) - unlink (bccfil); + (void) m_unlink (bccfil); if (!whomsw || checksw) sm_end (NOTOK);