From: Ken Hornstein Date: Fri, 23 Sep 2016 18:14:26 +0000 (-0400) Subject: Merge branch 'pop-tls' X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/1d08c1e0c0de0d321883ece1c36bce851fe893c7?hp=-c Merge branch 'pop-tls' --- 1d08c1e0c0de0d321883ece1c36bce851fe893c7 diff --combined Makefile.am index 0db9cfb5,d8a57eaa..515f4811 --- a/Makefile.am +++ b/Makefile.am @@@ -78,7 -78,7 +78,7 @@@ TESTS = test/ali/test-ali test/anno/tes test/mhbuild/test-forw test/mhbuild/test-header-encode \ test/mhbuild/test-utf8-body \ test/mhfixmsg/test-mhfixmsg test/mhical/test-mhical \ - test/mhl/test-mhl-flags \ + test/mhl/test-mhl-flags test/mhl/test-rfc6532 \ test/mhlist/test-mhlist test/mhlist/test-ext-params \ test/mhmail/test-mhmail \ test/mhparam/test-mhparam test/mhpath/test-mhpath \ @@@ -197,9 -197,9 +197,9 @@@ noinst_LIBRARIES = sbr/libmh.a mts/libm noinst_HEADERS = h/addrsbr.h h/aliasbr.h h/crawl_folders.h h/dropsbr.h \ h/fmt_compile.h h/fmt_scan.h h/icalendar.h h/md5.h h/mf.h \ h/mh.h h/mhcachesbr.h h/mhparse.h h/mime.h \ - h/mts.h h/nmh.h h/picksbr.h h/popsbr.h h/prototypes.h \ - h/rcvmail.h h/scansbr.h h/signals.h h/tws.h h/utils.h \ - mts/smtp/smtp.h sbr/ctype-checked.h h/oauth.h \ + h/mts.h h/nmh.h h/netsec.h h/picksbr.h h/popsbr.h + h/prototypes.h h/rcvmail.h h/scansbr.h h/signals.h h/tws.h + h/utils.h mts/smtp/smtp.h sbr/ctype-checked.h h/oauth.h \ thirdparty/jsmn/jsmn.h ## @@@ -303,7 -303,7 +303,7 @@@ EXTRA_DIST = autogen.sh config/version. test/post/test-post-common.sh test/send/README \ test/oauth/common.sh \ test/valgrind.supp uip/mhmail \ - SPECS/nmh.spec SPECS/build-nmh-cygwin $(man_SRCS) + SPECS/nmh.spec SPECS/nmh.cygport $(man_SRCS) ## ## These are all of the definitions for each of the programs listed above. @@@ -342,7 -342,8 +342,8 @@@ uip_forw_SOURCES = uip/forw.c uip/whatn uip_forw_LDADD = $(LDADD) $(READLINELIB) $(TERMLIB) $(ICONVLIB) $(POSTLINK) uip_inc_SOURCES = uip/inc.c uip/scansbr.c uip/dropsbr.c uip/popsbr.c - uip_inc_LDADD = $(LDADD) $(TERMLIB) $(ICONVLIB) $(SASLLIB) $(CURLLIB) $(POSTLINK) + uip_inc_LDADD = $(LDADD) $(TERMLIB) $(ICONVLIB) $(SASLLIB) $(CURLLIB) \ + $(TLSLIB) $(POSTLINK) uip_install_mh_SOURCES = uip/install-mh.c uip_install_mh_LDADD = $(LDADD) $(POSTLINK) @@@ -389,7 -390,7 +390,7 @@@ uip_mhstore_SOURCES = uip/mhstore.c uip uip_mhstore_LDADD = $(LDADD) $(TERMLIB) $(ICONVLIB) $(POSTLINK) uip_msgchk_SOURCES = uip/msgchk.c uip/popsbr.c - uip_msgchk_LDADD = $(LDADD) $(SASLLIB) $(CURLLIB) $(POSTLINK) + uip_msgchk_LDADD = $(LDADD) $(SASLLIB) $(CURLLIB) $(TLSLIB) $(POSTLINK) uip_new_SOURCES = uip/new.c uip_new_LDADD = $(LDADD) $(POSTLINK) @@@ -609,7 -610,8 +610,8 @@@ sbr_libmh_a_SOURCES = sbr/addrsbr.c sbr sbr/m_draft.c sbr/m_getfld.c sbr/m_gmprot.c \ sbr/m_maildir.c sbr/m_name.c sbr/m_popen.c sbr/m_rand.c \ sbr/makedir.c sbr/md5.c sbr/message_id.c \ - sbr/mime_type.c sbr/mts.c sbr/norm_charmap.c sbr/path.c \ + sbr/mime_type.c sbr/mts.c sbr/netsec.c \ + sbr/norm_charmap.c sbr/path.c \ sbr/peekc.c sbr/pidwait.c sbr/pidstatus.c \ sbr/print_help.c sbr/print_sw.c sbr/print_version.c \ sbr/push.c sbr/putenv.c sbr/refile.c sbr/remdir.c \ @@@ -635,7 -637,7 +637,7 @@@ config/sbr_libmh_a-config.$(OBJEXT) sbr/sbr_libmh_a-mts.$(OBJEXT): Makefile -sbr_libmh_a_CPPFLAGS = -I./sbr \ +sbr_libmh_a_CPPFLAGS = ${AM_CPPFLAGS} -I./sbr \ -DNMHBINDIR='"$(bindir)"' \ -DNMHLIBEXECDIR='"$(nmhlibexecdir)"' \ -DNMHETCDIR='"@nmhetcdirinst@$(nmhetcdir)"' \ diff --combined sbr/oauth.c index 3433fba0,85fe7146..f4564d0f mode 100755,100644..100755 --- a/sbr/oauth.c +++ b/sbr/oauth.c @@@ -127,17 -127,16 +127,16 @@@ static boolean get_json_strings(const c static boolean make_query_url(char *, size_t, CURL *, const char *, ...); static boolean post(struct curl_ctx *, const char *, const char *); - char * - mh_oauth_do_xoauth(const char *user, const char *svc, FILE *log) + int + mh_oauth_do_xoauth(const char *user, const char *svc, unsigned char **oauth_res, + size_t *oauth_res_len, FILE *log) { mh_oauth_ctx *ctx; mh_oauth_cred *cred; char *fn; int failed_to_lock = 0; FILE *fp; - size_t client_res_len; char *client_res; - char *client_res_b64; if (!mh_oauth_new (&ctx, svc)) adios(NULL, mh_oauth_get_err_string(ctx)); @@@ -183,18 -182,14 +182,14 @@@ free(fn); /* XXX writeBase64raw modifies the source buffer! make a copy */ - client_res = getcpy(mh_oauth_sasl_client_response(&client_res_len, user, + client_res = getcpy(mh_oauth_sasl_client_response(oauth_res_len, user, cred)); mh_oauth_cred_free(cred); mh_oauth_free(ctx); - client_res_b64 = mh_xmalloc(((((client_res_len) + 2) / 3 ) * 4) + 1); - if (writeBase64raw((unsigned char *)client_res, client_res_len, - (unsigned char *)client_res_b64) != OK) { - adios(NULL, "base64 encoding of XOAUTH2 client response failed"); - } - free(client_res); - return client_res_b64; + *oauth_res = (unsigned char *) client_res; + + return OK; } static boolean @@@ -961,14 -956,6 +956,14 @@@ post(struct curl_ctx *ctx, const char * curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, ctx); + if (strncmp(url, "http://127.0.0.1:", 17) == 0) { + /* Hack: on Cygwin, curl doesn't fail to connect with ECONNREFUSED. + Instead, it waits to timeout. So set a really short timeout, but + just on localhost (for convenience of the user, and the test + suite). */ + curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 2L); + } + status = curl_easy_perform(curl); /* first check for error from callback */ if (ctx->too_big) { diff --combined uip/inc.c index bf382544,43ae88d4..015fbab5 --- a/uip/inc.c +++ b/uip/inc.c @@@ -49,6 -49,12 +49,12 @@@ # define SASLminc(a) 0 #endif + #ifndef TLS_SUPPORT + # define TLSminc(a) (a) + #else + # define TLSminc(a) 0 + #endif + #define INC_SWITCHES \ X("audit audit-file", 0, AUDSW) \ X("noaudit", 0, NAUDSW) \ @@@ -69,10 -75,12 +75,12 @@@ X("width columns", 0, WIDTHSW) \ X("version", 0, VERSIONSW) \ X("help", 0, HELPSW) \ - X("snoop", -5, SNOOPSW) \ + X("snoop", 0, SNOOPSW) \ X("sasl", SASLminc(5), SASLSW) \ X("nosasl", SASLminc(3), NOSASLSW) \ X("saslmech", SASLminc(5), SASLMECHSW) \ + X("initialtls", TLSminc(-10), INITTLSSW) \ + X("notls", TLSminc(-12), NOTLSSW) \ X("authservice", SASLminc(0), AUTHSERVICESW) \ X("proxy command", 0, PROXYSW) \ @@@ -186,7 -194,7 +194,7 @@@ main (int argc, char **argv int chgflag = 1, trnflag = 1; int noisy = 1, width = -1; int hghnum = 0, msgnum = 0; - int sasl = 0; + int sasl = 0, tls = 0; int incerr = 0; /* <0 if inc hits an error which means it should not truncate mailspool */ char *cp, *maildir = NULL, *folder = NULL; char *format = NULL, *form = NULL; @@@ -211,7 -219,7 +219,7 @@@ if (nmh_init(argv[0], 1)) { return 1; } - mts_init (invo_name); + mts_init (); arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; @@@ -234,13 -242,13 +242,13 @@@ while ((cp = *argp++)) { if (*cp == '-') { switch (smatch (++cp, switches)) { - case AMBIGSW: + case AMBIGSW: ambigsw (cp, switches); done (1); - case UNKWNSW: + case UNKWNSW: adios (NULL, "-%s unknown", cp); - case HELPSW: + case HELPSW: snprintf (buf, sizeof(buf), "%s [+folder] [switches]", invo_name); print_help (buf, switches, 1); done (0); @@@ -248,19 -256,19 +256,19 @@@ print_version(invo_name); done (0); - case AUDSW: + case AUDSW: if (!(cp = *argp++) || *cp == '-') adios (NULL, "missing argument to %s", argp[-2]); audfile = getcpy (m_maildir (cp)); continue; - case NAUDSW: + case NAUDSW: audfile = NULL; continue; - case CHGSW: + case CHGSW: chgflag++; continue; - case NCHGSW: + case NCHGSW: chgflag = 0; continue; @@@ -271,14 -279,14 +279,14 @@@ * 1 by default (truncating is default) * 0 if -notruncate is given */ - case TRNCSW: + case TRNCSW: trnflag = 2; continue; - case NTRNCSW: + case NTRNCSW: trnflag = 0; continue; - case FILESW: + case FILESW: if (!(cp = *argp++) || *cp == '-') adios (NULL, "missing argument to %s", argp[-2]); from = path (cp, TFILE); @@@ -291,25 -299,25 +299,25 @@@ trnflag = 0; continue; - case SILSW: + case SILSW: noisy = 0; continue; - case NSILSW: + case NSILSW: noisy++; continue; - case FORMSW: + case FORMSW: if (!(form = *argp++) || *form == '-') adios (NULL, "missing argument to %s", argp[-2]); format = NULL; continue; - case FMTSW: + case FMTSW: if (!(format = *argp++) || *format == '-') adios (NULL, "missing argument to %s", argp[-2]); form = NULL; continue; - case WIDTHSW: + case WIDTHSW: if (!(cp = *argp++) || *cp == '-') adios (NULL, "missing argument to %s", argp[-2]); width = atoi (cp); @@@ -354,6 -362,14 +362,14 @@@ adios (NULL, "missing argument to %s", argp[-2]); continue; + case INITTLSSW: + tls++; + continue; + + case NOTLSSW: + tls = 0; + continue; + case AUTHSERVICESW: #ifdef OAUTH_SUPPORT if (!(auth_svc = *argp++) || *auth_svc == '-') @@@ -421,7 -437,7 +437,7 @@@ * initialize POP connection */ if (pop_init (host, port, creds.user, creds.password, proxy, snoop, - sasl, saslmech, auth_svc) == NOTOK) + sasl, saslmech, tls, auth_svc) == NOTOK) adios (NULL, "%s", response); /* Check if there are any messages */ @@@ -657,7 -673,7 +673,7 @@@ go_to_it switch (incerr = scan (pf, msgnum, 0, nfs, width, packfile ? 0 : msgnum == mp->hghmsg + 1 && chgflag, 1, NULL, stop - start, noisy, &scanl)) { - case SCNEOF: + case SCNEOF: printf ("%*d empty\n", DMAXFOLDER, msgnum); break; @@@ -668,12 -684,12 +684,12 @@@ /* fall thru */ case SCNERR: - case SCNNUM: + case SCNNUM: break; - case SCNMSG: + case SCNMSG: case SCNENC: - default: + default: if (aud) fputs (charstring_buffer (scanl), aud); if (noisy) @@@ -733,7 -749,7 +749,7 @@@ msgnum == hghnum && chgflag, 1, NULL, 0L, noisy, &scanl)) { case SCNFAT: - case SCNEOF: + case SCNEOF: break; case SCNERR: @@@ -742,11 -758,11 +758,11 @@@ advise (NULL, "aborted!"); /* doesn't clean up locks! */ break; - case SCNNUM: + case SCNNUM: advise (NULL, "BUG in %s, number out of range", invo_name); break; - default: + default: advise (NULL, "BUG in %s, scan() botch (%d)", invo_name, incerr); break; @@@ -807,7 -823,7 +823,7 @@@ } fclose (sf); sf = NULL; - } + } if (pf == NULL && (pf = fopen (cp, "r")) == NULL) adios (cp, "not available"); chmod (cp, m_gmprot ()); @@@ -816,7 -832,7 +832,7 @@@ switch (incerr = scan (pf, msgnum, 0, nfs, width, msgnum == mp->hghmsg + 1 && chgflag, 1, NULL, stop - start, noisy, &scanl)) { - case SCNEOF: + case SCNEOF: printf ("%*d empty\n", DMAXFOLDER, msgnum); break; @@@ -827,12 -843,12 +843,12 @@@ /* fall thru */ case SCNERR: - case SCNNUM: + case SCNNUM: break; - case SCNMSG: + case SCNMSG: case SCNENC: - default: + default: /* * Run the external program hook on the message. */ diff --combined uip/mhparse.c index d78ca7e5,8ebe1894..7ec030ba --- a/uip/mhparse.c +++ b/uip/mhparse.c @@@ -1751,7 -1751,7 +1751,7 @@@ openBase64 (CT ct, char **file /* sbeck -- handle suffixes */ CI ci; CE ce = &ct->c_cefile; - const char *decoded; + unsigned char *decoded; size_t decoded_len; unsigned char digest[16]; @@@ -1840,11 -1840,10 +1840,11 @@@ if (decodeBase64 (buffer, &decoded, &decoded_len, ct->c_type == CT_TEXT, ct->c_digested ? digest : NULL) == OK) { size_t i; - const char *decoded_p = decoded; + unsigned char *decoded_p = decoded; for (i = 0; i < decoded_len; ++i) { putc (*decoded_p++, ce->ce_fp); } + free ((char *) decoded); if (ferror (ce->ce_fp)) { content_error (ce->ce_file, ct, "error writing to"); goto clean_up; @@@ -2907,13 -2906,13 +2907,13 @@@ openURL (CT ct, char **file static int readDigest (CT ct, char *cp) { - const char *digest; + unsigned char *digest; size_t len; if (decodeBase64 (cp, &digest, &len, 0, NULL) == OK) { const size_t maxlen = sizeof ct->c_digest / sizeof ct->c_digest[0]; - if (strlen (digest) <= maxlen) { + if (strlen ((char *) digest) <= maxlen) { memcpy (ct->c_digest, digest, maxlen); if (debugsw) { @@@ -2930,7 -2929,7 +2930,7 @@@ } else { if (debugsw) { fprintf (stderr, "invalid MD5 digest (got %d octets)\n", - (int) strlen (digest)); + (int) strlen ((char *) digest)); } return NOTOK; diff --combined uip/msgchk.c index b6a5d809,3a650bc6..5861dae9 --- a/uip/msgchk.c +++ b/uip/msgchk.c @@@ -30,7 -30,7 +30,7 @@@ X("port name/number", 0, PORTSW) \ X("version", 0, VERSIONSW) \ X("help", 0, HELPSW) \ - X("snoop", -5, SNOOPSW) \ + X("snoop", 0, SNOOPSW) \ X("sasl", SASLminc(4), SASLSW) \ X("saslmech", SASLminc(5), SASLMECHSW) \ X("authservice", SASLminc(0), AUTHSERVICESW) \ @@@ -88,7 -88,7 +88,7 @@@ main (int argc, char **argv if (nmh_init(argv[0], 1)) { return 1; } - mts_init (invo_name); + mts_init (); arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; @@@ -350,7 -350,7 +350,7 @@@ remotemail (char *host, char *port, cha /* open the POP connection */ if (pop_init (host, port, creds.user, creds.password, proxy, snoop, sasl, - saslmech, auth_svc) == NOTOK + saslmech, 0, auth_svc) == NOTOK || pop_stat (&nmsgs, &nbytes) == NOTOK /* check for messages */ || pop_quit () == NOTOK) { /* quit POP connection */ advise (NULL, "%s", response); diff --combined uip/post.c index 0fee356b,6482d1d0..0a42ad2f --- a/uip/post.c +++ b/uip/post.c @@@ -83,7 -83,6 +83,6 @@@ X("partno", -6, PARTSW) \ X("sasl", SASLminc(4), SASLSW) \ X("nosasl", SASLminc(6), NOSASLSW) \ - X("saslmaxssf", SASLminc(10), SASLMXSSFSW) \ X("saslmech", SASLminc(5), SASLMECHSW) \ X("user", SASLminc(-4), USERSW) \ X("port server submission port name/number", 4, PORTSW) \ @@@ -231,7 -230,6 +230,6 @@@ static int checksw = 0; /* whom -chec 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="submission"; /* Name of server port for SMTP submission */ @@@ -315,7 -313,7 +313,7 @@@ main (int argc, char **argv if (nmh_init(argv[0], 0 /* use context_foil() */)) { return 1; } - mts_init (invo_name); + mts_init (); arguments = getarguments (invo_name, argc, argv, 0); argp = arguments; @@@ -462,12 -460,6 +460,6 @@@ 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 == '-') adios (NULL, "missing argument to %s", argp[-2]); @@@ -1635,8 -1627,7 +1627,7 @@@ post (char *file, int bccque, int talk } } else { if (rp_isbad (retval = sm_init (clientsw, serversw, port, watch, - verbose, snoop, sasl, saslssf, - saslmech, user, + verbose, snoop, sasl, saslmech, user, oauth_flag ? auth_svc : NULL, tls)) || rp_isbad (retval = sm_winit (envelope))) die (NULL, "problem initializing server; %s", rp_string (retval)); @@@ -1676,8 -1667,7 +1667,7 @@@ verify_all_addresses (int talk, char *e if (!whomsw || checksw) if (rp_isbad (retval = sm_init (clientsw, serversw, port, watch, - verbose, snoop, sasl, saslssf, - saslmech, user, + verbose, snoop, sasl, saslmech, user, oauth_flag ? auth_svc : NULL, tls)) || rp_isbad (retval = sm_winit (envelope))) die (NULL, "problem initializing server; %s", rp_string (retval)); diff --combined uip/whatnowsbr.c index 80386e95,8498f92c..d6c336f6 --- a/uip/whatnowsbr.c +++ b/uip/whatnowsbr.c @@@ -942,12 -942,11 +942,11 @@@ buildfile (char **argp, char *file X("client host", -6, CLIESW) \ X("server host", 6, SERVSW) \ X("snoop", -5, SNOOPSW) \ - X("draftfolder +folder", -6, SDRFSW) \ - X("draftmessage msg", -6, SDRMSW) \ - X("nodraftfolder", -3, SNDRFSW) \ + X("draftfolder +folder", 0, SDRFSW) \ + X("draftmessage msg", 0, SDRMSW) \ + X("nodraftfolder", 0, SNDRFSW) \ X("sasl", SASLminc(4), SASLSW) \ X("nosasl", SASLminc(6), NOSASLSW) \ - X("saslmaxssf", SASLminc(10), SASLMXSSFSW) \ X("saslmech", SASLminc(5), SASLMECHSW) \ X("authservice", SASLminc(0), AUTHSERVICESW) \ X("user username", SASLminc(4), USERSW) \ @@@ -1165,7 -1164,6 +1164,6 @@@ sendit (char *sp, char **arg, char *fil case WIDTHSW: case CLIESW: case SERVSW: - case SASLMXSSFSW: case USERSW: case PORTSW: case MTSSM: