git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3] remote-curl: fall back to Basic auth if Negotiate fails

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Jan 8, 2015, 00:29 UTC
Message-ID
<1420676960-492860-1-git-send-email-sandals@crustytoothpaste.net>
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
Previous: brian m. carlsonNext: Dan Langille (dalangil)
Message 24 of 39 in “git-http-backend auth via Kerberos”
  1. Dan Langille (dalangil)Dec 18, 2014
  2. brian m. carlsonDec 18, 2014
  3. Dan Langille (dalangil)Dec 19, 2014
  4. Dan Langille (dalangil)Dec 19, 2014
  5. Dan Langille (dalangil)Dec 19, 2014
  6. brian m. carlsonDec 19, 2014
  7. Dan Langille (dalangil)Dec 19, 2014
  8. remote-curl: fall back to Basic auth if Negotiate fails.brian m. carlson, Dec 27, 2014
  9. Jeff KingDec 27, 2014
  10. brian m. carlsonDec 27, 2014
  11. Jeff KingDec 27, 2014
  12. brian m. carlsonDec 28, 2014
  13. remote-curl: fall back to Basic auth if Negotiate failsbrian m. carlson, Jan 1, 2015
  14. Jeff KingJan 3, 2015
  15. brian m. carlsonJan 3, 2015
  16. Jeff KingJan 3, 2015
  17. Dan Langille (dalangil)Jan 5, 2015
  18. Dan Langille (dalangil)Jan 5, 2015
  19. brian m. carlsonJan 5, 2015
  20. Dan Langille (dalangil)Jan 6, 2015
  21. Dan Langille (dalangil)Jan 6, 2015
  22. Dan Langille (dalangil)Jan 6, 2015
  23. brian m. carlsonJan 8, 2015
  24. remote-curl: fall back to Basic auth if Negotiate failsbrian m. carlson, Jan 8, 2015
  25. Dan Langille (dalangil)Jan 20, 2015
  26. Junio C HamanoJan 21, 2015
  27. Dan Langille (dalangil)Jan 22, 2015
  28. Dan Langille (dalangil)Feb 17, 2015
  29. Junio C HamanoFeb 17, 2015
  30. Dan Langille (dalangil)Feb 18, 2015
  31. brian m. carlsonFeb 19, 2015
  32. Dan Langille (dalangil)Feb 24, 2015
  33. Dan Langille (dalangil)Feb 25, 2015
  34. Dan Langille (dalangil)Mar 10, 2015
  35. brian m. carlsonMar 10, 2015
  36. Dan Langille (dalangil)Mar 11, 2015
  37. brian m. carlsonMar 11, 2015
  38. Dan Langille (dalangil)Mar 12, 2015
  39. Dan Langille (dalangil)Jan 5, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.