All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Improve http proxy support
@ 2012-02-22 14:04 Nelson Benítez León
  2012-02-22 14:13 ` Matthieu Moy
  0 siblings, 1 reply; 5+ messages in thread
From: Nelson Benítez León @ 2012-02-22 14:04 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 884 bytes --]

Hi, my initial motivation for this patch was to add NTLM proxy
authentication so I could 'git clone' from inside my employers
network, but apart from doing that, I also added two more features,
so, this patch adds the following improvements to the http proxy
support:

- Support NTLM proxy authentication (as well as other authentication
methods) by setting CURLOPT_PROXYAUTH[1] to CURLAUTH_ANY.

- Look up environment vars http_proxy and HTTP_PROXY in case git
http.proxy config option is not set. This supports system wide proxy
support in terminals.

- Support proxy urls with username but without a password, in which
case we interactively ask for the password (as it's already done in
http auth code). This makes possible to not have the password written
down in git config files or in env vars.

Thanks!

[1] http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTPROXYAUTH

[-- Attachment #2: gitproxyauthv2.patch --]
[-- Type: application/octet-stream, Size: 1701 bytes --]

--- http.c	2012-01-19 01:19:22.000000000 +0100
+++ http.mod2.c	2012-02-22 14:44:11.727773038 +0100
@@ -299,8 +299,54 @@
 	if (curl_ftp_no_epsv)
 		curl_easy_setopt(result, CURLOPT_FTP_USE_EPSV, 0);
 
-	if (curl_http_proxy)
-		curl_easy_setopt(result, CURLOPT_PROXY, curl_http_proxy);
+	if (!curl_http_proxy) {
+		const char *env_proxy;
+		env_proxy = getenv("HTTP_PROXY");
+		if (!env_proxy) {
+			env_proxy = getenv("http_proxy");
+		}
+		if (env_proxy) {
+			curl_http_proxy = xstrdup(env_proxy);
+		}
+	}
+	if (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 */
+			char *ask_str, *proxyuser, *proxypass;
+			int len;
+			struct strbuf pbuf = STRBUF_INIT;
+			len = at - cp;
+			proxyuser = xmalloc(len + 1);
+			memcpy(proxyuser, cp, len);
+			proxyuser[len] = '\0';
+			
+			strbuf_addf(&pbuf, "Enter password for proxy %s...", at+1);
+			ask_str = strbuf_detach(&pbuf, NULL);
+			proxypass = xstrdup(git_getpass(ask_str));
+			
+			strbuf_insert(&pbuf, 0, curl_http_proxy, cp - curl_http_proxy);
+			strbuf_addf(&pbuf, "%s:%s", proxyuser, proxypass);
+			strbuf_add(&pbuf, at, strlen(at));
+			curl_easy_setopt(result, CURLOPT_PROXY, strbuf_detach(&pbuf, NULL));
+			
+			free(ask_str);
+			free(proxyuser);
+			free(proxypass);
+		} else {
+			curl_easy_setopt(result, CURLOPT_PROXY, curl_http_proxy);
+		}
+		curl_easy_setopt(result, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
+	}
 
 	return result;
 }

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Improve http proxy support
  2012-02-22 14:04 [PATCH] Improve http proxy support Nelson Benítez León
@ 2012-02-22 14:13 ` Matthieu Moy
  2012-02-22 16:43   ` Thomas Rast
  2012-02-23 12:20   ` Nelson Benítez León
  0 siblings, 2 replies; 5+ messages in thread
From: Matthieu Moy @ 2012-02-22 14:13 UTC (permalink / raw)
  To: Nelson Benítez León; +Cc: git

Nelson Benítez León <nbenitezl@gmail.com> writes:

> Hi, my initial motivation for this patch was to add NTLM proxy
> authentication [...]

That sounds interesting, but please read Documentation/SubmittingPatches
in Git's tree. The formatting of your email is wrong (giving more work
for your maintainer) and you need to sign-off your patch to allow your
code to be legally included.

Thanks,

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Improve http proxy support
  2012-02-22 14:13 ` Matthieu Moy
@ 2012-02-22 16:43   ` Thomas Rast
  2012-02-23 12:20   ` Nelson Benítez León
  1 sibling, 0 replies; 5+ messages in thread
From: Thomas Rast @ 2012-02-22 16:43 UTC (permalink / raw)
  To: Nelson Benítez León; +Cc: Matthieu Moy, git

Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:

> Nelson Benítez León <nbenitezl@gmail.com> writes:
>
>> Hi, my initial motivation for this patch was to add NTLM proxy
>> authentication [...]
>
> That sounds interesting, but please read Documentation/SubmittingPatches
> in Git's tree. The formatting of your email is wrong (giving more work
> for your maintainer) and you need to sign-off your patch to allow your
> code to be legally included.

Judging from the message, it also conflates three changes into one
patch.  Don't do that.

-- 
Thomas Rast
trast@{inf,student}.ethz.ch

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Improve http proxy support
  2012-02-22 14:13 ` Matthieu Moy
  2012-02-22 16:43   ` Thomas Rast
@ 2012-02-23 12:20   ` Nelson Benítez León
  2012-02-23 12:52     ` [PATCH] README: point to Documentation/SubmittingPatches Matthieu Moy
  1 sibling, 1 reply; 5+ messages in thread
From: Nelson Benítez León @ 2012-02-23 12:20 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: git

El día 22 de febrero de 2012 15:13, Matthieu Moy
<Matthieu.Moy@grenoble-inp.fr> escribió:
> Nelson Benítez León <nbenitezl@gmail.com> writes:
>
>> Hi, my initial motivation for this patch was to add NTLM proxy
>> authentication [...]
>
> That sounds interesting, but please read Documentation/SubmittingPatches
> in Git's tree. The formatting of your email is wrong (giving more work
> for your maintainer) and you need to sign-off your patch to allow your
> code to be legally included.

Thank you for the advice, I read README file (couldn't find a HACKING
one) and the git website, and neither of those had a reference to
SubmittingPatches..

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] README: point to Documentation/SubmittingPatches
  2012-02-23 12:20   ` Nelson Benítez León
@ 2012-02-23 12:52     ` Matthieu Moy
  0 siblings, 0 replies; 5+ messages in thread
From: Matthieu Moy @ 2012-02-23 12:52 UTC (permalink / raw)
  To: git, gitster; +Cc: Matthieu Moy

It was indeed not obvious for new contributors to find this document in
the source tree, since there were no reference to it outside the
Documentation/ directory.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
> Thank you for the advice, I read README file (couldn't find a HACKING
> one) and the git website, and neither of those had a reference to
> SubmittingPatches..

Indeed. As a bonnus, here's a submission that should match the
guidelines (above --- is the commit message, and here is the place for
free comments).

 README |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/README b/README
index 67cfeb2..d2690ec 100644
--- a/README
+++ b/README
@@ -42,10 +42,12 @@ including full documentation and Git related tools.
 
 The user discussion and development of Git take place on the Git
 mailing list -- everyone is welcome to post bug reports, feature
-requests, comments and patches to git@vger.kernel.org. To subscribe
-to the list, send an email with just "subscribe git" in the body to
-majordomo@vger.kernel.org. The mailing list archives are available at
-http://marc.theaimsgroup.com/?l=git and other archival sites.
+requests, comments and patches to git@vger.kernel.org (read
+Documentation/SubmittingPatches for instructions on patch submission).
+To subscribe to the list, send an email with just "subscribe git" in
+the body to majordomo@vger.kernel.org. The mailing list archives are
+available at http://marc.theaimsgroup.com/?l=git and other archival
+sites.
 
 The messages titled "A note from the maintainer", "What's in
 git.git (stable)" and "What's cooking in git.git (topics)" and
-- 
1.7.9.111.gf3fb0.dirty

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-02-23 12:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-22 14:04 [PATCH] Improve http proxy support Nelson Benítez León
2012-02-22 14:13 ` Matthieu Moy
2012-02-22 16:43   ` Thomas Rast
2012-02-23 12:20   ` Nelson Benítez León
2012-02-23 12:52     ` [PATCH] README: point to Documentation/SubmittingPatches Matthieu Moy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.