X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/9a6d835cfe7761f6a85f84233d9d93722efe6ecc..f98955f258440b73a698f6cb83f2623ff4da2ff1:/uip/popsbr.c diff --git a/uip/popsbr.c b/uip/popsbr.c index 71011667..cf6b8042 100644 --- a/uip/popsbr.c +++ b/uip/popsbr.c @@ -146,14 +146,6 @@ pop_init (char *host, char *port, char *user, char *pass, char *proxy, if (user) netsec_set_userid(nsc, user); - if (tls) { - if (netsec_set_tls(nsc, 1, &errstr) != OK) { - snprintf(response, sizeof(response), "%s", errstr); - free(errstr); - return NOTOK; - } - } - if (oauth_svc != NULL) { if (netsec_set_oauth_service(nsc, oauth_svc) != OK) { snprintf(response, sizeof(response), "OAuth2 not supported"); @@ -213,14 +205,21 @@ pop_init (char *host, char *port, char *user, char *pass, char *proxy, sizeof(response), snoop)) == NOTOK) { return NOTOK; } + fd2 = fd1; } SIGNAL (SIGPIPE, SIG_IGN); - netsec_set_fd(nsc, fd1); + netsec_set_fd(nsc, fd1, fd2); netsec_set_snoop(nsc, snoop); if (tls) { + if (netsec_set_tls(nsc, 1, &errstr) != OK) { + snprintf(response, sizeof(response), "%s", errstr); + free(errstr); + return NOTOK; + } + if (netsec_negotiate_tls(nsc, &errstr) != OK) { snprintf(response, sizeof(response), "%s", errstr); free(errstr); @@ -289,7 +288,7 @@ pop_sasl_callback(enum sasl_message_type mtype, unsigned const char *indata, unsigned int indatalen, unsigned char **outdata, unsigned int *outdatalen, char **errstr) { - int rc; + int rc, snoopoffset; char *mech, *line; size_t len, b64len; @@ -333,16 +332,22 @@ pop_sasl_callback(enum sasl_message_type mtype, unsigned const char *indata, "for initial challenge response"); return NOTOK; } + netsec_set_snoop_callback(nsc, netsec_b64_snoop_decoder, NULL); rc = netsec_printf(nsc, errstr, "%s\r\n", b64data); + netsec_set_snoop_callback(nsc, NULL, NULL); free(b64data); if (rc != OK) return NOTOK; if (netsec_flush(nsc, errstr) != OK) return NOTOK; } else { + netsec_set_snoop_callback(nsc, netsec_b64_snoop_decoder, + &snoopoffset); + snoopoffset = 6 + strlen(mech); rc = netsec_printf(nsc, errstr, "AUTH %s %s\r\n", mech, b64data); free(b64data); + netsec_set_snoop_callback(nsc, NULL, NULL); if (rc != OK) return NOTOK; if (netsec_flush(nsc, errstr) != OK) @@ -362,7 +367,10 @@ pop_sasl_callback(enum sasl_message_type mtype, unsigned const char *indata, * and feed it back into the SASL library. */ case NETSEC_SASL_READ: + netsec_set_snoop_callback(nsc, netsec_b64_snoop_decoder, &snoopoffset); + snoopoffset = 2; line = netsec_readline(nsc, &len, errstr); + netsec_set_snoop_callback(nsc, NULL, NULL); if (line == NULL) return NOTOK; @@ -375,10 +383,12 @@ pop_sasl_callback(enum sasl_message_type mtype, unsigned const char *indata, *outdata = NULL; *outdatalen = 0; } else { - rc = decodeBase64(line + 2, (const char **) outdata, &len, 0, NULL); + rc = decodeBase64(line + 2, outdata, &len, 0, NULL); *outdatalen = len; - if (rc != OK) + if (rc != OK) { + netsec_err(errstr, "Unable to decode base64 response"); return NOTOK; + } } break; @@ -393,7 +403,9 @@ pop_sasl_callback(enum sasl_message_type mtype, unsigned const char *indata, unsigned char *b64data; b64data = mh_xmalloc(BASE64SIZE(indatalen)); writeBase64raw(indata, indatalen, b64data); + netsec_set_snoop_callback(nsc, netsec_b64_snoop_decoder, NULL); rc = netsec_printf(nsc, errstr, "%s\r\n", b64data); + netsec_set_snoop_callback(nsc, NULL, NULL); free(b64data); } @@ -402,8 +414,6 @@ pop_sasl_callback(enum sasl_message_type mtype, unsigned const char *indata, if (netsec_flush(nsc, errstr) != OK) return NOTOK; - - return OK; break; /* @@ -523,7 +533,7 @@ pop_retr (int msgno, int (*action)(char *)) static int traverse (int (*action)(char *), const char *fmt, ...) { - int result; + int result, snoopstate; va_list ap; char buffer[sizeof(response)]; @@ -535,13 +545,18 @@ traverse (int (*action)(char *), const char *fmt, ...) return NOTOK; strncpy (buffer, response, sizeof(buffer)); + if ((snoopstate = netsec_get_snoop(nsc))) + netsec_set_snoop(nsc, 0); + for (;;) switch (multiline ()) { case NOTOK: + netsec_set_snoop(nsc, snoopstate); return NOTOK; case DONE: strncpy (response, buffer, sizeof(response)); + netsec_set_snoop(nsc, snoopstate); return OK; case OK: @@ -711,7 +726,7 @@ pop_getline (char *s, int n, netsec_context *ns) * someday. */ - destlen = len < ((size_t) (n - 1)) ? len : n - 1; + destlen = len < ((size_t) (n - 1)) ? len : (size_t) (n - 1); memcpy(s, p, destlen); s[destlen] = '\0';