9d7d3f
From 2ac0f436a3ed216d3fc634592d302c6b8efe25d0 Mon Sep 17 00:00:00 2001
9d7d3f
From: Frank Meier <frank.meier@ergon.ch>
9d7d3f
Date: Fri, 22 Aug 2014 14:54:41 +0200
9d7d3f
Subject: [PATCH] NTLM: ignore CURLOPT_FORBID_REUSE during NTLM HTTP auth
9d7d3f
9d7d3f
Problem: if CURLOPT_FORBID_REUSE is set, requests using NTLM failed
9d7d3f
since NTLM requires multiple requests that re-use the same connection
9d7d3f
for the authentication to work
9d7d3f
9d7d3f
Solution: Ignore the forbid reuse flag in case the NTLM authentication
9d7d3f
handshake is in progress, according to the NTLM state flag.
9d7d3f
9d7d3f
Fixed known bug #77.
9d7d3f
9d7d3f
Upstream-commit: 63a0bd4270decef04e64fbe497b42f2c9e26c62b
9d7d3f
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
9d7d3f
---
9d7d3f
 docs/KNOWN_BUGS | 4 ----
9d7d3f
 lib/url.c       | 7 +++++--
9d7d3f
 2 files changed, 5 insertions(+), 6 deletions(-)
9d7d3f
9d7d3f
diff --git a/docs/KNOWN_BUGS b/docs/KNOWN_BUGS
9d7d3f
index d363827..170987e 100644
9d7d3f
--- a/docs/KNOWN_BUGS
9d7d3f
+++ b/docs/KNOWN_BUGS
9d7d3f
@@ -18,10 +18,6 @@ may have been fixed since this was written!
9d7d3f
   any file at all. Like when using FTP.
9d7d3f
   http://curl.haxx.se/bug/view.cgi?id=3438362
9d7d3f
 
9d7d3f
-77. CURLOPT_FORBID_REUSE on a handle prevents NTLM from working since it
9d7d3f
-  "abuses" the underlying connection re-use system and if connections are
9d7d3f
-  forced to close they break the NTLM support.
9d7d3f
-
9d7d3f
 76. The SOCKET type in Win64 is 64 bits large (and thus so is curl_socket_t on
9d7d3f
   that platform), and long is only 32 bits. It makes it impossible for
9d7d3f
   curl_easy_getinfo() to return a socket properly with the CURLINFO_LASTSOCKET
9d7d3f
diff --git a/lib/url.c b/lib/url.c
9d7d3f
index de8e153..5fcef89 100644
9d7d3f
--- a/lib/url.c
9d7d3f
+++ b/lib/url.c
9d7d3f
@@ -5252,7 +5252,8 @@ CURLcode Curl_done(struct connectdata **connp,
9d7d3f
   }
9d7d3f
 
9d7d3f
   /* if data->set.reuse_forbid is TRUE, it means the libcurl client has
9d7d3f
-     forced us to close this no matter what we think.
9d7d3f
+     forced us to close this connection. This is ignored for requests taking
9d7d3f
+     place in a NTLM authentication handshake
9d7d3f
 
9d7d3f
      if conn->bits.close is TRUE, it means that the connection should be
9d7d3f
      closed in spite of all our efforts to be nice, due to protocol
9d7d3f
@@ -5267,7 +5268,9 @@ CURLcode Curl_done(struct connectdata **connp,
9d7d3f
      connection_id == -1 here means that the connection has not been added
9d7d3f
      to the connection cache (OOM) and thus we must disconnect it here.
9d7d3f
   */
9d7d3f
-  if(data->set.reuse_forbid || conn->bits.close || premature ||
9d7d3f
+  if((data->set.reuse_forbid && !(conn->ntlm.state == NTLMSTATE_TYPE2 ||
9d7d3f
+                                  conn->proxyntlm.state == NTLMSTATE_TYPE2))
9d7d3f
+     || conn->bits.close || premature ||
9d7d3f
      (-1 == conn->connection_id)) {
9d7d3f
     CURLcode res2 = Curl_disconnect(conn, premature); /* close connection */
9d7d3f
 
9d7d3f
-- 
9d7d3f
2.1.0
9d7d3f