]> Pileus Git - ~andy/fetchmail/blobdiff - pop3.c
Merge branch 'master' of gitorious.org:fetchmail/fetchmail
[~andy/fetchmail] / pop3.c
diff --git a/pop3.c b/pop3.c
index abd690e8096c7e1968bd8b7fc490aaf588825ea5..5148c25d50b8fd9625f738a1d4e12ae91d2a8945 100644 (file)
--- a/pop3.c
+++ b/pop3.c
@@ -82,60 +82,17 @@ char *sdps_envto;
 static int do_pop3_ntlm(int sock, struct query *ctl,
        int msn_instead /** if true, send AUTH MSN, else send AUTH NTLM */)
 {
-    tSmbNtlmAuthRequest request;
-    tSmbNtlmAuthChallenge challenge;
-    tSmbNtlmAuthResponse response;
+    char msgbuf[POPBUFSIZE+1];
+    int result;
 
-    char msgbuf[2048];
-    int result,len;
-  
     gen_send(sock, msn_instead ? "AUTH MSN" : "AUTH NTLM");
 
-    if ((result = gen_recv(sock, msgbuf, sizeof msgbuf)))
+    if ((result = ntlm_helper(sock, ctl, "POP3")))
        return result;
-  
-    if (msgbuf[0] != '+')
-       return PS_AUTHFAIL;
-  
-    buildSmbNtlmAuthRequest(&request,ctl->remotename,NULL);
-
-    if (outlevel >= O_DEBUG)
-       dumpSmbNtlmAuthRequest(stdout, &request);
-
-    memset(msgbuf,0,sizeof msgbuf);
-    to64frombits (msgbuf, &request, SmbLength(&request));
-  
-    if (outlevel >= O_MONITOR)
-       report(stdout, "POP3> %s\n", msgbuf);
-  
-    strcat(msgbuf,"\r\n");
-    SockWrite (sock, msgbuf, strlen (msgbuf));
-
-    if ((gen_recv(sock, msgbuf, sizeof msgbuf)))
-       return result;
-  
-    len = from64tobits (&challenge, msgbuf, sizeof(msgbuf));
-    
-    if (outlevel >= O_DEBUG)
-       dumpSmbNtlmAuthChallenge(stdout, &challenge);
-    
-    buildSmbNtlmAuthResponse(&challenge, &response,ctl->remotename,ctl->password);
-  
-    if (outlevel >= O_DEBUG)
-       dumpSmbNtlmAuthResponse(stdout, &response);
-  
-    memset(msgbuf,0,sizeof msgbuf);
-    to64frombits (msgbuf, &response, SmbLength(&response));
-
-    if (outlevel >= O_MONITOR)
-       report(stdout, "POP3> %s\n", msgbuf);
-      
-    strcat(msgbuf,"\r\n");
-    SockWrite (sock, msgbuf, strlen (msgbuf));
-  
+
     if ((result = gen_recv (sock, msgbuf, sizeof msgbuf)))
        return result;
-  
+
     if (strstr (msgbuf, "OK"))
        return PS_SUCCESS;
     else
@@ -491,7 +448,7 @@ static int pop3_getauth(int sock, struct query *ctl, char *greeting)
                * (see below). */
               if (gen_transact(sock, "STLS") == PS_SUCCESS
                       && SSLOpen(sock, ctl->sslcert, ctl->sslkey, "tls1", ctl->sslcertck,
-                          ctl->sslcertpath, ctl->sslfingerprint, commonname,
+                          ctl->sslcertfile, ctl->sslcertpath, ctl->sslfingerprint, commonname,
                           ctl->server.pollname, &ctl->remotename) != -1)
               {
                   /*
@@ -565,7 +522,8 @@ static int pop3_getauth(int sock, struct query *ctl, char *greeting)
 #if defined(GSSAPI)
        if (has_gssapi &&
            (ctl->server.authenticate == A_GSSAPI ||
-            ctl->server.authenticate == A_ANY))
+           (ctl->server.authenticate == A_ANY
+            && check_gss_creds("pop", ctl->server.truename) == PS_SUCCESS)))
        {
            ok = do_gssauth(sock,"AUTH","pop",ctl->server.truename,ctl->remotename);
            if (ok == PS_SUCCESS || ctl->server.authenticate != A_ANY)
@@ -693,7 +651,7 @@ static int pop3_getauth(int sock, struct query *ctl, char *greeting)
        strcpy((char *)ctl->digest, MD5Digest((unsigned char *)msg));
        free(msg);
 
-       ok = gen_transact(sock, "APOP %s %s", ctl->remotename, ctl->digest);
+       ok = gen_transact(sock, "APOP %s %s", ctl->remotename, (char *)ctl->digest);
        break;
 
     case P_RPOP:
@@ -856,7 +814,7 @@ static int pop3_fastuidl( int sock,  struct query *ctl, unsigned int count, int
            if (mark == UID_DELETED || mark == UID_EXPUNGED)
            {
                if (outlevel >= O_VERBOSE)
-                   report(stderr, GT_("id=%s (num=%d) was deleted, but is still present!\n"), id, try_nr);
+                   report(stderr, GT_("id=%s (num=%u) was deleted, but is still present!\n"), id, try_nr);
                /* just mark it as seen now! */
                newl->val.status.mark = mark = UID_SEEN;
            }
@@ -1009,9 +967,13 @@ static int pop3_getrange(int sock,
     /* get the total message count */
     gen_send(sock, "STAT");
     ok = pop3_ok(sock, buf);
-    if (ok == 0)
-       sscanf(buf,"%d %d", countp, bytes);
-    else
+    if (ok == 0) {
+       int asgn;
+
+       asgn = sscanf(buf,"%d %d", countp, bytes);
+       if (asgn != 2)
+               return PS_PROTOCOL;
+    } else
        return(ok);
 
     /*