From: Jeff King <peff@peff.net>
To: Nelson Benitez Leon <nelsonjesus.benitez@seap.minhap.es>
Cc: git@vger.kernel.org, sam@vilain.net
Subject: Re: [PATCH 3/3] http: when proxy url has username but no password, ask for password
Date: Tue, 28 Feb 2012 14:31:25 -0500 [thread overview]
Message-ID: <20120228193125.GA11725@sigill.intra.peff.net> (raw)
In-Reply-To: <4F4CCEFD.90402@seap.minhap.es>
On Tue, Feb 28, 2012 at 01:56:29PM +0100, Nelson Benitez Leon wrote:
> 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
next prev parent reply other threads:[~2012-02-28 19:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-28 12:56 [PATCH 3/3] http: when proxy url has username but no password, ask for password Nelson Benitez Leon
2012-02-28 19:31 ` Jeff King [this message]
2012-02-29 10:46 ` Nelson Benitez Leon
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=20120228193125.GA11725@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=nelsonjesus.benitez@seap.minhap.es \
--cc=sam@vilain.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).