From 5dceb6626b476173b5ef0b7372e3f4616a70365f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Wolski?= <andre@dena-design.de>
Date: Tue, 16 Aug 2016 14:44:34 +0200
Subject: [PATCH] NTLM restart authentication (trivial change)

* src/http-ntlm.c (ntlm_input): Continue on NTLMSTATE_LAST,
  error on NTLMSTATE_TYPE3

The code comes from the cURL project. Thanks to Daniel Stenberg
for donating the code.

https://lists.gnu.org/archive/html/bug-wget/2018-12/msg00030.html
---
 src/http-ntlm.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/http-ntlm.c b/src/http-ntlm.c
index a614fba3..1e0087a0 100644
--- a/src/http-ntlm.c
+++ b/src/http-ntlm.c
@@ -135,13 +135,24 @@ ntlm_input (struct ntlmdata *ntlm, const char *header)
     }
   else
     {
-      if (ntlm->state >= NTLMSTATE_TYPE1)
+      if (ntlm->state == NTLMSTATE_LAST)
+        {
+          DEBUGP (("NTLM auth restarted.\n"));
+          /* no return, continue */
+        }
+      else if (ntlm->state == NTLMSTATE_TYPE3)
+        {
+          DEBUGP (("NTLM handshake rejected.\n"));
+          ntlm->state = NTLMSTATE_NONE;
+          return false;
+        }
+      else if (ntlm->state >= NTLMSTATE_TYPE1)
         {
           DEBUGP (("Unexpected empty NTLM message.\n"));
           return false; /* this is an error */
         }
 
-      DEBUGP (("Empty NTLM message, starting transaction.\n"));
+      DEBUGP (("Empty NTLM message, (re)starting transaction.\n"));
       ntlm->state = NTLMSTATE_TYPE1; /* we should sent away a type-1 */
     }