git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: git@vger.kernel.org
Cc: "Dan Langille (dalangil)" <dalangil@cisco.com>,
	Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>
Subject: [PATCH v3] remote-curl: fall back to Basic auth if Negotiate fails
Date: Thu,  8 Jan 2015 00:29:20 +0000	[thread overview]
Message-ID: <1420676960-492860-1-git-send-email-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <1420142187-1025433-1-git-send-email-sandals@crustytoothpaste.net>

Apache servers using mod_auth_kerb can be configured to allow the user
to authenticate either using Negotiate (using the Kerberos ticket) or
Basic authentication (using the Kerberos password).  Often, one will
want to use Negotiate authentication if it is available, but fall back
to Basic authentication if the ticket is missing or expired.

However, libcurl will try very hard to use something other than Basic
auth, even over HTTPS.  If Basic and something else are offered, libcurl
will never attempt to use Basic, even if the other option fails.
Teach the HTTP client code to stop trying authentication mechanisms that
don't use a password (currently Negotiate) after the first failure,
since if they failed the first time, they will never succeed.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Jeff King <peff@peff.net>
---
Peff's original change was to get_curl_handle; however, we retry the
second time with the same slot and we may not call get_curl_handle
again, so I had to move that change to get_active_slot.  This has been
tested pushing with both Negotiate and Basic against an HTTPS server
both when info/refs was protected and when it was not.

 http.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/http.c b/http.c
index 040f362..44b130c 100644
--- a/http.c
+++ b/http.c
@@ -62,6 +62,9 @@ static const char *user_agent;
 
 static struct credential cert_auth = CREDENTIAL_INIT;
 static int ssl_cert_password_required;
+#ifdef LIBCURL_CAN_HANDLE_AUTH_ANY
+static unsigned long http_auth_methods = CURLAUTH_ANY;
+#endif
 
 static struct curl_slist *pragma_header;
 static struct curl_slist *no_pragma_header;
@@ -580,6 +583,9 @@ struct active_request_slot *get_active_slot(void)
 	curl_easy_setopt(slot->curl, CURLOPT_UPLOAD, 0);
 	curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);
 	curl_easy_setopt(slot->curl, CURLOPT_FAILONERROR, 1);
+#ifdef LIBCURL_CAN_HANDLE_AUTH_ANY
+	curl_easy_setopt(slot->curl, CURLOPT_HTTPAUTH, http_auth_methods);
+#endif
 	if (http_auth.password)
 		init_curl_http_auth(slot->curl);
 
@@ -870,6 +876,9 @@ int handle_curl_result(struct slot_results *results)
 			credential_reject(&http_auth);
 			return HTTP_NOAUTH;
 		} else {
+#ifdef LIBCURL_CAN_HANDLE_AUTH_ANY
+			http_auth_methods &= ~CURLAUTH_GSSNEGOTIATE;
+#endif
 			return HTTP_REAUTH;
 		}
 	} else {
@@ -986,6 +995,7 @@ static void extract_content_type(struct strbuf *raw, struct strbuf *type,
 		strbuf_addstr(charset, "ISO-8859-1");
 }
 
+
 /* http_request() targets */
 #define HTTP_REQUEST_STRBUF	0
 #define HTTP_REQUEST_FILE	1
-- 
2.2.1.209.g41e5f3a

  parent reply	other threads:[~2015-01-08  0:29 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-18 22:19 git-http-backend auth via Kerberos Dan Langille (dalangil)
2014-12-18 22:54 ` brian m. carlson
2014-12-19 15:07   ` Dan Langille (dalangil)
2014-12-19 15:50     ` Dan Langille (dalangil)
2014-12-19 16:07     ` Dan Langille (dalangil)
2014-12-19 20:16     ` brian m. carlson
2014-12-19 20:57       ` Dan Langille (dalangil)
2014-12-27  4:01         ` [PATCH] remote-curl: fall back to Basic auth if Negotiate fails brian m. carlson
2014-12-27 17:56           ` Jeff King
2014-12-27 21:09             ` brian m. carlson
2014-12-27 21:29               ` Jeff King
2014-12-28  0:05                 ` brian m. carlson
2015-01-01 19:56           ` [PATCH v2] " brian m. carlson
2015-01-03 11:19             ` Jeff King
2015-01-03 17:45               ` brian m. carlson
2015-01-03 20:14                 ` Jeff King
2015-01-05 16:02             ` Dan Langille (dalangil)
2015-01-05 21:23             ` Dan Langille (dalangil)
2015-01-05 23:53               ` brian m. carlson
2015-01-06 15:31                 ` Dan Langille (dalangil)
2015-01-06 15:41                   ` Dan Langille (dalangil)
2015-01-06 16:07                   ` Dan Langille (dalangil)
2015-01-08  0:02                     ` brian m. carlson
2015-01-08  0:29             ` brian m. carlson [this message]
2015-01-20 16:40               ` [PATCH v3] " Dan Langille (dalangil)
2015-01-21  0:22                 ` Junio C Hamano
2015-01-22 14:47                   ` Dan Langille (dalangil)
2015-02-17 23:05                   ` Dan Langille (dalangil)
2015-02-17 23:36                     ` Junio C Hamano
2015-02-18 16:17                       ` Dan Langille (dalangil)
2015-02-19 20:35                         ` brian m. carlson
2015-02-24 21:03                           ` Dan Langille (dalangil)
2015-02-25 20:59                             ` Dan Langille (dalangil)
2015-03-10 18:05                               ` Dan Langille (dalangil)
2015-03-10 22:29                                 ` brian m. carlson
2015-03-11 19:33                                   ` Dan Langille (dalangil)
2015-03-11 21:59                                     ` brian m. carlson
2015-03-12 13:09                                       ` Dan Langille (dalangil)
2015-01-05 13:12           ` [PATCH] " Dan Langille (dalangil)
2021-02-16 16:57 [PATCH v2] remote-curl: fall back to basic " Christopher via GitGitGadget
2021-03-22 11:51 ` [PATCH v3] " Christopher via GitGitGadget

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1420676960-492860-1-git-send-email-sandals@crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=dalangil@cisco.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).