From 8fe04d4a8ddb81016b03e7c721a532e46de76794 Mon Sep 17 00:00:00 2001 From: Matthias Andree Date: Sat, 9 Oct 2010 13:16:44 +0200 Subject: [PATCH] NTLM: cancel properly in case of failure. --- ntlmsubr.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/ntlmsubr.c b/ntlmsubr.c index ab685ff0..3684bf9e 100644 --- a/ntlmsubr.c +++ b/ntlmsubr.c @@ -2,6 +2,7 @@ #ifdef NTLM_ENABLE #include "fetchmail.h" +#include "i18n.h" #include "ntlm.h" #include "socket.h" @@ -29,8 +30,12 @@ int ntlm_helper(int sock, struct query *ctl, const char *proto) if ((result = gen_recv(sock, msgbuf, sizeof msgbuf))) return result; - if (0 != strcmp(msgbuf, "+ ")) - return PS_AUTHFAIL; + if (msgbuf[0] != '+' && strspn(msgbuf+1, " \t") < strlen(msgbuf+1)) { + if (outlevel >= O_VERBOSE) { + report(stdout, GT_("Warning: received malformed challenge to \"AUTH(ENTICATE) NTLM\"!\n")); + } + goto cancelfail; + } buildSmbNtlmAuthRequest(&request,ctl->remotename,NULL); @@ -46,8 +51,8 @@ int ntlm_helper(int sock, struct query *ctl, const char *proto) strcat(msgbuf,"\r\n"); SockWrite (sock, msgbuf, strlen (msgbuf)); - if ((gen_recv(sock, msgbuf, sizeof msgbuf))) - return result; + if ((result = gen_recv(sock, msgbuf, sizeof msgbuf))) + goto cancelfail; (void)from64tobits (&challenge, msgbuf, sizeof(challenge)); @@ -69,6 +74,14 @@ int ntlm_helper(int sock, struct query *ctl, const char *proto) SockWrite (sock, msgbuf, strlen (msgbuf)); return PS_SUCCESS; + +cancelfail: /* cancel authentication and return failure */ + { + if (outlevel >= O_MONITOR) + report(stdout, "%s> *\n", proto); + SockWrite(sock, "*\r\n", 3); + return result; + } } #endif /* NTLM_ENABLE */ -- 2.43.2