You are not logged in.

#1 2010-01-22 19:50:33

erick.red
Member
From: Miami, FL, USA
Registered: 2007-06-16
Posts: 41
Website

git authentication against proxies

Hello there:

Maybe this is not the right place to post this, but, maybe here more interested people will hear of it.

My situation is this, i found myself behind a proxy trying to make git clone over http protocol, and i wasn't able to do it. My proxy use digest authentiction, and git software doesn't manage http proxy with auth, so i downloaded the code of git (course after i got tired of searching google) and start reading to patch it.

After a few looks and some advice from my fellow developers i managed to do so, then i made a patch and i thougt about make a PKGBUILD and submit a package to aur, then after reading all the guidelines (aur guildelines, bug report guidelines) i decide the right thing to do was not to upload a package to aur.
So i submitted the patch to the git's maintainers and now i'll posted here fpor someone else looking for it.

--- git-1.6.6/http.c    2009-12-23 19:00:22.000000000 -0500
+++ git-1.6.6/http.c    2010-01-19 11:59:17.000000000 -0500
@@ -33,6 +33,10 @@
 static long curl_low_speed_time = -1;
 static int curl_ftp_no_epsv;
 static const char *curl_http_proxy;
+static const char *curl_http_proxy_auth;
+static const char *curl_http_proxy_user;
+static const char *curl_http_proxy_pass;
+
 static char *user_name, *user_pass;
 
 #if LIBCURL_VERSION_NUM >= 0x071700
@@ -174,6 +178,15 @@
     if (!strcmp("http.proxy", var))
         return git_config_string(&curl_http_proxy, var, value);
 
+    if (!strcmp("http.proxy-auth", var))
+        return git_config_string(&curl_http_proxy_auth, var, value);
+
+    if (!strcmp("http.proxy-user", var))
+        return git_config_string(&curl_http_proxy_user, var, value);
+
+    if (!strcmp("http.proxy-pass", var))
+        return git_config_string(&curl_http_proxy_pass, var, value);
+
     if (!strcmp("http.postbuffer", var)) {
         http_post_buffer = git_config_int(var, value);
         if (http_post_buffer < LARGE_PACKET_MAX)
@@ -267,8 +280,32 @@
         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_user && curl_http_proxy_pass)
+        {
+            char* c;
+            c = xstrdup(curl_http_proxy_user);
+            strcpy(c, curl_http_proxy_user);
+            strcat(c, ":");
+            strcat(c, curl_http_proxy_pass);
+            c[strlen(curl_http_proxy_user) + strlen(curl_http_proxy_pass) + 1] = 0;
+            curl_easy_setopt(result, CURLOPT_PROXYUSERPWD, c);
+            free(c);
+        }
+        if(curl_http_proxy_auth)
+        {
+            if(!strcmp(curl_http_proxy_auth, "digest"))
+                curl_easy_setopt(result, CURLOPT_PROXYAUTH, CURLAUTH_DIGEST);
+            else if(!strcmp(curl_http_proxy_auth, "basic"))
+                curl_easy_setopt(result, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
+            else if(!strcmp(curl_http_proxy_auth, "ntlm"))
+                curl_easy_setopt(result, CURLOPT_PROXYAUTH, CURLAUTH_NTLM);
+        }
+
+    }
+
     return result;
 }
 
@@ -430,6 +467,21 @@
         curl_http_proxy = NULL;
     }
 
+    if (curl_http_proxy_auth) {
+        free((void *)curl_http_proxy_auth);
+        curl_http_proxy_auth = NULL;
+    }
+
+    if (curl_http_proxy_user) {
+        free((void *)curl_http_proxy_user);
+        curl_http_proxy_user = NULL;
+    }
+
+    if (curl_http_proxy_pass) {
+        free((void *)curl_http_proxy_pass);
+        curl_http_proxy_pass = NULL;
+    }
+
     if (ssl_cert_password != NULL) {
         memset(ssl_cert_password, 0, strlen(ssl_cert_password));
         free(ssl_cert_password);

Any suggestion, would be appreciated.


Carpe diem, quam minimum credula postero

Offline

Board footer

Powered by FluxBB