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

Re: [PATCH 3/3] http: when proxy url has username but no password, ask for password

From
Jeff King <peff@peff.net>
Date
Feb 28, 2012, 19:31 UTC
Message-ID
<20120228193125.GA11725@sigill.intra.peff.net>
In-Reply-To
<4F4CCEFD.90402@seap.minhap.es>
On Tue, Feb 28, 2012 at 01:56:29PM +0100, Nelson Benitez Leon wrote:
Show 21 quoted lines
> diff --git a/http.c b/http.c
> index 79cbe50..68e3f7d 100644
> --- a/http.c
> +++ b/http.c
> @@ -306,7 +306,41 @@ static CURL *get_curl_handle(void)
>  		}
>  	}
>  	if (curl_http_proxy) {
> -		curl_easy_setopt(result, CURLOPT_PROXY, curl_http_proxy);
> +		char *at, *colon, *proxyuser;
> +		const char *cp;
> +		cp = strstr(curl_http_proxy, "://");
> +		if (cp == NULL) {
> +			cp = curl_http_proxy;
> +		} else {
> +			cp += 3;
> +		}
> +		at = strchr(cp, '@');
> +		colon = strchr(cp, ':');
> +		if (at && (!colon || at < colon)) {
> +			/* proxy string has username but no password, ask for password */

Don't parse the URL by hand. Use credential_from_url, which will do it for you (and will properly handle things like unquoting the various components).

> +			char *ask_str, *proxyuser, *proxypass;

Shouldn't these be static globals? If we have multiple curl handles, you would want them to share the authentication information we collect here, and not have to ask the user again, no?

> +			strbuf_addf(&pbuf, "Enter password for proxy %s...", at+1);
> +			ask_str = strbuf_detach(&pbuf, NULL);
> +			proxypass = xstrdup(git_getpass(ask_str));

And this should be using credential_fill(), which will let it use credential helpers to save passwords, give it the same type of prompt as elsewhere, etc.

See Documentation/technical/api-credential.txt, and see how regular http auth is handled for an example.

-Peff
Previous: Nelson Benitez LeonNext: Nelson Benitez Leon
Message 2 of 3 in “http: when proxy url has username but no password, ask for password”
  1. 3/3 http: when proxy url has username but no password, ask for passwordNelson Benitez Leon, Feb 28, 2012
  2. Jeff KingFeb 28, 2012
  3. Nelson Benitez LeonFeb 29, 2012

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.