]> diplodocus.org Git - nmh/blobdiff - uip/popsbr.c
Add EndsWithC(char *s, int c) and call it in some initial places.
[nmh] / uip / popsbr.c
index 710116679dc30c0618338307370a8a65716508f2..cf6b804223e5b77cbc998d7aac8a27aefa930b8f 100644 (file)
@@ -146,14 +146,6 @@ pop_init (char *host, char *port, char *user, char *pass, char *proxy,
     if (user)
        netsec_set_userid(nsc, user);
 
     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");
     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;
        }
                           sizeof(response), snoop)) == NOTOK) {
            return NOTOK;
        }
+       fd2 = fd1;
     }
 
     SIGNAL (SIGPIPE, SIG_IGN);
 
     }
 
     SIGNAL (SIGPIPE, SIG_IGN);
 
-    netsec_set_fd(nsc, fd1);
+    netsec_set_fd(nsc, fd1, fd2);
     netsec_set_snoop(nsc, snoop);
 
     if (tls) {
     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);
        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)
 {
                  unsigned int indatalen, unsigned char **outdata,
                  unsigned int *outdatalen, char **errstr)
 {
-    int rc;
+    int rc, snoopoffset;
     char *mech, *line;
     size_t len, b64len;
 
     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;
                }
                               "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);
                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 {
                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);
                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)
                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:
         * 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);
        line = netsec_readline(nsc, &len, errstr);
+       netsec_set_snoop_callback(nsc, NULL, NULL);
 
        if (line == NULL)
            return NOTOK;
 
        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 {
            *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;
            *outdatalen = len;
-           if (rc != OK)
+           if (rc != OK) {
+               netsec_err(errstr, "Unable to decode base64 response");
                return NOTOK;
                return NOTOK;
+           }
        }
        break;
 
        }
        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);
            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);
            rc = netsec_printf(nsc, errstr, "%s\r\n", b64data);
+           netsec_set_snoop_callback(nsc, NULL, NULL);
            free(b64data);
        }
 
            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;
 
        if (netsec_flush(nsc, errstr) != OK)
            return NOTOK;
-
-       return OK;
        break;
 
     /*
        break;
 
     /*
@@ -523,7 +533,7 @@ pop_retr (int msgno, int (*action)(char *))
 static int
 traverse (int (*action)(char *), const char *fmt, ...)
 {
 static int
 traverse (int (*action)(char *), const char *fmt, ...)
 {
-    int result;
+    int result, snoopstate;
     va_list ap;
     char buffer[sizeof(response)];
 
     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));
 
        return NOTOK;
     strncpy (buffer, response, sizeof(buffer));
 
+    if ((snoopstate = netsec_get_snoop(nsc)))
+       netsec_set_snoop(nsc, 0);
+
     for (;;)
        switch (multiline ()) {
            case NOTOK: 
     for (;;)
        switch (multiline ()) {
            case NOTOK: 
+               netsec_set_snoop(nsc, snoopstate);
                return NOTOK;
 
            case DONE: 
                strncpy (response, buffer, sizeof(response));
                return NOTOK;
 
            case DONE: 
                strncpy (response, buffer, sizeof(response));
+               netsec_set_snoop(nsc, snoopstate);
                return OK;
 
            case OK: 
                return OK;
 
            case OK: 
@@ -711,7 +726,7 @@ pop_getline (char *s, int n, netsec_context *ns)
      * someday.
      */
 
      * 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';
 
     memcpy(s, p, destlen);
     s[destlen] = '\0';