X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=uip%2Fpost.c;h=6ce328075ab7e44a5b89f62620d1d704e7c47d9f;hb=703b7d98727c1f7e1e76434a04a3125d76d7d168;hp=d99da1fd627ec86ee9380d7594212699a77e3452;hpb=76b51b746c95647aceff29ab178eff496843f528;p=mmh diff --git a/uip/post.c b/uip/post.c index d99da1f..6ce3280 100644 --- a/uip/post.c +++ b/uip/post.c @@ -2,8 +2,6 @@ /* * post.c -- enter messages into the mail transport system * - * $Id$ - * * This code is Copyright (c) 2002, by the authors of nmh. See the * COPYRIGHT file in the root directory of the nmh distribution for * complete copyright information. @@ -22,19 +20,12 @@ #include #include -#include #include -#ifdef TIME_WITH_SYS_TIME +#ifdef HAVE_SYS_TIME_H # include -# include -#else -# ifdef TM_IN_SYS_TIME -# include -# else -# include -# endif #endif +#include #ifdef SMTPMTS # include @@ -46,6 +37,12 @@ # define SASLminc(a) 0 #endif /* CYRUS_SASL */ +#ifndef TLS_SUPPORT +# define TLSminc(a) (a) +#else /* TLS_SUPPORT */ +# define TLSminc(a) 0 +#endif /* TLS_SUPPORT */ + #define FCCS 10 /* max number of fccs allowed */ #define uptolow(c) ((isalpha(c) && isupper (c)) ? tolower (c) : c) @@ -134,10 +131,22 @@ static struct swit switches[] = { { "queued", -6 }, #define SASLSW 37 { "sasl", SASLminc(-4) }, -#define SASLMECHSW 38 +#define NOSASLSW 38 + { "nosasl", SASLminc(-6) }, +#define SASLMXSSFSW 39 + { "saslmaxssf", SASLminc(-10) }, +#define SASLMECHSW 40 { "saslmech", SASLminc(-5) }, -#define USERSW 39 +#define USERSW 41 { "user", SASLminc(-4) }, +#define PORTSW 42 + { "port server port name/number", 4 }, +#define TLSSW 43 + { "tls", TLSminc(-3) }, +#define FILEPROCSW 44 + { "fileproc", -4 }, +#define MHLPROCSW 45 + { "mhlproc", -3 }, { NULL, 0 } }; @@ -234,8 +243,11 @@ static int checksw = 0; /* whom -check */ static int linepos=0; /* putadr()'s position on the line */ static int nameoutput=0; /* putadr() has output header name */ 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 unsigned msgflags = 0; /* what we've seen */ @@ -258,10 +270,10 @@ static char *fccfold[FCCS]; /* foldernames for FCC'ing */ static struct headers *hdrtab; /* table for the message we're doing */ -static struct mailname localaddrs={NULL}; /* local addrs */ -static struct mailname netaddrs={NULL}; /* network addrs */ -static struct mailname uuaddrs={NULL}; /* uucp addrs */ -static struct mailname tmpaddrs={NULL}; /* temporary queue */ +static struct mailname localaddrs; /* local addrs */ +static struct mailname netaddrs; /* network addrs */ +static struct mailname uuaddrs; /* uucp addrs */ +static struct mailname tmpaddrs; /* temporary queue */ #ifdef SMTPMTS static int snoop = 0; @@ -508,6 +520,16 @@ main (int argc, char **argv) case SASLSW: sasl++; continue; + + case NOSASLSW: + sasl = 0; + continue; + + case SASLMXSSFSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + saslssf = atoi(cp); + continue; case SASLMECHSW: if (!(saslmech = *argp++) || *saslmech == '-') @@ -518,6 +540,27 @@ main (int argc, char **argv) if (!(user = *argp++) || *user == '-') adios (NULL, "missing argument to %s", argp[-2]); continue; + + case PORTSW: + if (!(port = *argp++) || *port == '-') + adios (NULL, "missing argument to %s", argp[-2]); + continue; + + case TLSSW: + tls++; + continue; + + case FILEPROCSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + fileproc = cp; + continue; + + case MHLPROCSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + mhlproc = cp; + continue; } } if (msg) @@ -546,13 +589,14 @@ main (int argc, char **argv) if ((out = fopen (fill_in ? fill_in : "/dev/null", "w")) == NULL) adios ("/dev/null", "unable to open"); } else { - strncpy (tmpfil, m_scratch ("", m_maildir (invo_name)), - sizeof(tmpfil)); - if ((out = fopen (tmpfil, "w")) == NULL) { - strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil)); - if ((out = fopen (tmpfil, "w")) == NULL) - adios (tmpfil, "unable to create"); - } + 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"); + } + } + strncpy(tmpfil, cp, sizeof(tmpfil)); chmod (tmpfil, 0600); } } @@ -639,7 +683,8 @@ main (int argc, char **argv) if (verbose) printf (partno ? "Partial Message #%s Processed\n" : "Message Processed\n", partno); - return done (0); + done (0); + return 1; } @@ -653,7 +698,7 @@ putfmt (char *name, char *str, FILE *out) int count, grp, i, keep; char *cp, *pp, *qp; char namep[BUFSIZ]; - struct mailname *mp, *np; + struct mailname *mp = NULL, *np = NULL; struct headers *hdr; while (*str == ' ' || *str == '\t') @@ -838,8 +883,8 @@ start_headers (void) mygid = getgid (); time (&tclock); - strncpy (from, adrsprintf (NULL, NULL), sizeof(from)); - strncpy (myhost, LocalName (), sizeof(myhost)); + strncpy (from, getlocaladdr(), sizeof(from)); + strncpy (myhost, LocalName (0), sizeof(myhost)); for (cp = myhost; *cp; cp++) *cp = uptolow (*cp); @@ -847,7 +892,7 @@ start_headers (void) if ((cp = getfullname ()) && *cp) { strncpy (sigbuf, cp, sizeof(sigbuf)); snprintf (signature, sizeof(signature), "%s <%s>", - sigbuf, adrsprintf (NULL, NULL)); + 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) @@ -856,7 +901,7 @@ start_headers (void) while (getname ("")) continue; } else { - strncpy (signature, adrsprintf (NULL, NULL), sizeof(signature)); + strncpy (signature, getlocaladdr(), sizeof(signature)); } } @@ -878,7 +923,7 @@ finish_headers (FILE *out) fprintf (out, "Date: %s\n", dtime (&tclock, 0)); if (msgid) fprintf (out, "Message-ID: <%d.%ld@%s>\n", - (int) getpid (), (long) tclock, LocalName ()); + (int) getpid (), (long) tclock, LocalName (1)); if (msgflags & MFRM) { /* There was already a From: in the draft. Don't add one. */ if (!draft_from_masquerading) @@ -913,7 +958,7 @@ finish_headers (FILE *out) fprintf (out, "Resent-Date: %s\n", dtime (&tclock, 0)); if (msgid) fprintf (out, "Resent-Message-ID: <%d.%ld@%s>\n", - (int) getpid (), (long) tclock, LocalName ()); + (int) getpid (), (long) tclock, LocalName (1)); if (msgflags & MRFM) { /* There was already a Resent-From: in draft. Don't add one. */ if (!draft_from_masquerading) @@ -1157,16 +1202,17 @@ make_bcc_file (int dashstuff) pid_t child_id; char *vec[6]; FILE *out; + char *tfile = NULL; - strncpy (bccfil, m_tmpfil ("bccs"), sizeof(bccfil)); - if ((out = fopen (bccfil, "w")) == NULL) - adios (bccfil, "unable to create"); + tfile = m_mktemp2(NULL, "bccs", NULL, &out); + if (tfile == NULL) adios("bcc", "unable to create temporary file"); chmod (bccfil, 0600); + strncpy (bccfil, tfile, sizeof(bccfil)); fprintf (out, "Date: %s\n", dtime (&tclock, 0)); if (msgid) fprintf (out, "Message-ID: <%d.%ld@%s>\n", - (int) getpid (), (long) tclock, LocalName ()); + (int) getpid (), (long) tclock, LocalName (1)); if (msgflags & MFRM) { /* There was already a From: in the draft. Don't add one. */ if (!draft_from_masquerading) @@ -1287,16 +1333,13 @@ make_bcc_file (int dashstuff) static int find_prefix (void) { - int len, result; + int result = OK; unsigned char buffer[BUFSIZ]; FILE *in; if ((in = fopen (tmpfil, "r")) == NULL) adios (tmpfil, "unable to re-open"); - len = strlen (prefix); - - result = OK; while (fgets (buffer, sizeof(buffer) - 1, in)) if (buffer[0] == '-' && buffer[1] == '-') { unsigned char *cp; @@ -1402,9 +1445,9 @@ post (char *file, int bccque, int talk) sigon (); - if (rp_isbad (retval = sm_init (clientsw, serversw, watch, verbose, - snoop, onex, queued, sasl, saslmech, - user)) + if (rp_isbad (retval = sm_init (clientsw, serversw, port, watch, verbose, + snoop, onex, queued, sasl, saslssf, + saslmech, user, tls)) || rp_isbad (retval = sm_winit (smtpmode, from))) die (NULL, "problem initializing server; %s", rp_string (retval)); @@ -1441,8 +1484,9 @@ verify_all_addresses (int talk) sigon (); if (!whomsw || checksw) - if (rp_isbad (retval = sm_init (clientsw, serversw, watch, verbose, snoop, 0, - queued, sasl, saslmech, user)) + if (rp_isbad (retval = sm_init (clientsw, serversw, port, watch, + verbose, snoop, 0, queued, sasl, + saslssf, saslmech, user, tls)) || rp_isbad (retval = sm_winit (smtpmode, from))) die (NULL, "problem initializing server; %s", rp_string (retval)); @@ -1575,12 +1619,10 @@ do_text (char *file, int fd) * SIGNAL HANDLING */ -static RETSIGTYPE +static void sigser (int i) { -#ifndef RELIABLE_SIGNALS - SIGNAL (i, SIG_IGN); -#endif + NMH_UNUSED (i); unlink (tmpfil); if (msgflags & MINV)