diff options
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | fetchmail.h | 5 | ||||
-rw-r--r-- | imap.c | 50 | ||||
-rw-r--r-- | ntlmsubr.c | 74 | ||||
-rw-r--r-- | pop3.c | 53 |
5 files changed, 88 insertions, 96 deletions
diff --git a/Makefile.am b/Makefile.am index c1318b0a..973bf400 100644 --- a/Makefile.am +++ b/Makefile.am @@ -39,7 +39,7 @@ libfm_a_SOURCES= xmalloc.c base64.c rfc822.c report.c rfc2047e.c \ libesmtp/gethostbyname.h libesmtp/gethostbyname.c \ smbtypes.h fm_getaddrinfo.c tls.c rfc822valid.c \ xmalloc.h sdump.h sdump.c x509_name_match.c \ - fm_strl.h + fm_strl.h ntlmsubr.c libfm_a_LIBADD= $(EXTRAOBJ) libfm_a_DEPENDENCIES= $(EXTRAOBJ) LDADD = libfm.a @LIBINTL@ $(LIBOBJS) diff --git a/fetchmail.h b/fetchmail.h index 50165c12..f6c6a4ec 100644 --- a/fetchmail.h +++ b/fetchmail.h @@ -767,6 +767,11 @@ int rfc822_valid_msgid(const unsigned char *); /* prototype from x509_name_match.c */ int name_match(const char *p1, const char *p2); +/* prototype from ntlmsubr.c */ +#ifdef NTLM_ENABLE +int ntlm_helper(int sock, struct query *ctl, const char *protocol); +#endif + /* macro to determine if we want to spam progress to stdout */ #define want_progress() \ ((outlevel >= O_VERBOSE || (outlevel > O_SILENT && run.showdots)) \ @@ -290,57 +290,13 @@ static int imap_ok(int sock, char *argbuf) static int do_imap_ntlm(int sock, struct query *ctl) { - tSmbNtlmAuthRequest request; - tSmbNtlmAuthChallenge challenge; - tSmbNtlmAuthResponse response; - - char msgbuf[2048]; - int result,len; + int result; gen_send(sock, "AUTHENTICATE NTLM"); - if ((result = gen_recv(sock, msgbuf, sizeof msgbuf))) - 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, "IMAP> %s\n", msgbuf); - - strcat(msgbuf,"\r\n"); - SockWrite (sock, msgbuf, strlen (msgbuf)); - - if ((gen_recv(sock, msgbuf, sizeof msgbuf))) + if ((result = ntlm_helper(sock, ctl, "IMAP"))) return result; - - (void)from64tobits (&challenge, msgbuf, sizeof(challenge)); - - 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, "IMAP> %s\n", msgbuf); - - strcat(msgbuf,"\r\n"); - SockWrite (sock, msgbuf, strlen (msgbuf)); - + result = imap_ok (sock, NULL); if (result == PS_SUCCESS) return PS_SUCCESS; diff --git a/ntlmsubr.c b/ntlmsubr.c new file mode 100644 index 00000000..ab685ff0 --- /dev/null +++ b/ntlmsubr.c @@ -0,0 +1,74 @@ +#include "config.h" + +#ifdef NTLM_ENABLE +#include "fetchmail.h" +#include "ntlm.h" +#include "socket.h" + +#include <string.h> + +int ntlm_helper(int sock, struct query *ctl, const char *proto) +{ +/* + * NTLM support by Grant Edwards. + * + * Handle MS-Exchange NTLM authentication method. This is the same + * as the NTLM auth used by Samba for SMB related services. We just + * encode the packets in base64 instead of sending them out via a + * network interface. + * + * Much source (ntlm.h, smb*.c smb*.h) was borrowed from Samba. + */ + tSmbNtlmAuthRequest request; + tSmbNtlmAuthChallenge challenge; + tSmbNtlmAuthResponse response; + + char msgbuf[2048]; + int result; + + if ((result = gen_recv(sock, msgbuf, sizeof msgbuf))) + return result; + + if (0 != strcmp(msgbuf, "+ ")) + 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, "%s> %s\n", proto, msgbuf); + + strcat(msgbuf,"\r\n"); + SockWrite (sock, msgbuf, strlen (msgbuf)); + + if ((gen_recv(sock, msgbuf, sizeof msgbuf))) + return result; + + (void)from64tobits (&challenge, msgbuf, sizeof(challenge)); + + 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, "%s> %s\n", proto, msgbuf); + + strcat(msgbuf,"\r\n"); + SockWrite (sock, msgbuf, strlen (msgbuf)); + + return PS_SUCCESS; +} + +#endif /* NTLM_ENABLE */ @@ -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; - - (void)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 |