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

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

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Jan 3, 2015, 17:45 UTC
Message-ID
<20150103174509.GA1025060@vauxhall.crustytoothpaste.net>
In-Reply-To
<20150103111922.GB27793@peff.net>
On Sat, Jan 03, 2015 at 06:19:23AM -0500, Jeff King wrote:
>This pattern gets repeated in several places. Now that
>http_passwordless_auth is a global, can we handle it automatically for
>the callers, as below (which, aside from compiling, is completely
>untested by me)?
This looks good (although I haven't tested it).
Show 7 quoted lines
>Note that this is in a slightly different boat than credential_fill.
>Ideally we would also handle picking up credentials on behalf of the
>callers of get_curl_handle/handle_curl_result. But that may involve
>significant work and/or prompting the user, which we _must_ avoid if we
>do not know if we are going to retry the request (and only the caller
>knows that for sure). However, in the case of http_passwordless_auth, we
>are just setting a flag, so it's OK to do it preemptively.

Right. We already prompt the user for a username and password in that case, so we already have the credentials that we need.

Show 20 quoted lines
>diff --git a/http.c b/http.c
>index 040f362..2bbcdf1 100644
>--- a/http.c
>+++ b/http.c
>@@ -62,6 +62,8 @@ static const char *user_agent;
>
> static struct credential cert_auth = CREDENTIAL_INIT;
> static int ssl_cert_password_required;
>+/* Should we allow non-password-based authentication (e.g. GSSAPI)? */
>+static int http_passwordless_auth = 1;
>
> static struct curl_slist *pragma_header;
> static struct curl_slist *no_pragma_header;
>@@ -318,7 +320,12 @@ static CURL *get_curl_handle(void)
> 	curl_easy_setopt(result, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
> #endif
> #ifdef LIBCURL_CAN_HANDLE_AUTH_ANY
>-	curl_easy_setopt(result, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
>+	{
>+		int flags = CURLAUTH_ANY;

I think this needs to be unsigned long or it can cause undefined behavior, since libcurl uses unsigned long in the flags. I'll fix that up when I reroll. I'll need your sign-off since it will essentially be your work.

Show 25 quoted lines
>+		if (!http_passwordless_auth)
>+			flags &= ~CURLAUTH_GSSNEGOTIATE;
>+		curl_easy_setopt(result, CURLOPT_HTTPAUTH, flags);
>+	}
> #endif
>
> 	if (http_proactive_auth)
>@@ -870,6 +877,7 @@ int handle_curl_result(struct slot_results *results)
> 			credential_reject(&http_auth);
> 			return HTTP_NOAUTH;
> 		} else {
>+			http_passwordless_auth = 0;
> 			return HTTP_REAUTH;
> 		}
> 	} else {
>
>
>Note that you could probably drop http_passwordless_auth completely, and
>just keep a:
>
>  static int http_auth_methods = CURLAUTH_ANY;
>
>and then drop CURLAUTH_GSSNEGOTIATE from it instead of setting the
>passwordless_auth flag to 0 (again, it happens in one place, so I don't
>know that it needs an extra layer of abstraction).

This does seem to handle both cases well. It also has the pleasant side effect of being static.

-- 
brian m. carlson / brian with sandals: Houston, Texas, US
+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187
Previous: Jeff KingNext: Jeff King
Message 15 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.