80
* here, too
81
*/
82
};
83
+static struct credential proxy_auth = CREDENTIAL_INIT;
84
+static const char *curl_proxyuserpwd;
85
static const char *curl_cookie_file;
86
static int curl_save_cookies;
87
struct credential http_auth = CREDENTIAL_INIT;
179
#else
180
slot->results->auth_avail = 0;
181
#endif
182
+
183
+ curl_easy_getinfo(slot->curl, CURLINFO_HTTP_CONNECTCODE,
184
+ &slot->results->http_connectcode);
185
}
186
187
/* Run callback if appropriate */
339
}
340
}
341
342
+static void set_proxyauth_name_password(CURL *result)
343
+{
344
+#if LIBCURL_VERSION_NUM >= 0x071301
345
+ curl_easy_setopt(result, CURLOPT_PROXYUSERNAME,
346
+ proxy_auth.username);
347
+ curl_easy_setopt(result, CURLOPT_PROXYPASSWORD,
348
+ proxy_auth.password);
349
+#else
350
+ struct strbuf s = STRBUF_INIT;
351
+
352
+ strbuf_addstr_urlencode(&s, proxy_auth.username, 1);
353
+ strbuf_addch(&s, ':');
354
+ strbuf_addstr_urlencode(&s, proxy_auth.password, 1);
355
+ curl_proxyuserpwd = strbuf_detach(&s, NULL);
356
+ curl_easy_setopt(result, CURLOPT_PROXYUSERPWD, curl_proxyuserpwd);
357
+#endif
358
+}
359
+
360
static void init_curl_proxy_auth(CURL *result)
361
{
362
+ if (proxy_auth.username) {
363
+ if (!proxy_auth.password)
364
+ credential_fill(&proxy_auth);
365
+ set_proxyauth_name_password(result);
366
+ }
367
+
368
var_override(&http_proxy_authmethod, getenv("GIT_HTTP_PROXY_AUTHMETHOD"));
369
370
#if LIBCURL_VERSION_NUM >= 0x070a07 /* CURLOPT_PROXYAUTH and CURLAUTH_ANY */
546
curl_easy_setopt(result, CURLOPT_USE_SSL, CURLUSESSL_TRY);
547
#endif
548
549
+ /*
550
+ * CURL also examines these variables as a fallback; but we need to query
551
+ * them here in order to decide whether to prompt for missing password (cf.
552
+ * init_curl_proxy_auth()).
553
+ *
554
+ * Unlike many other common environment variables, these are historically
555
+ * lowercase only. It appears that CURL did not know this and implemented
556
+ * only uppercase variants, which was later corrected to take both - with
557
+ * the exception of http_proxy, which is lowercase only also in CURL. As
558
+ * the lowercase versions are the historical quasi-standard, they take
559
+ * precedence here, as in CURL.
560
+ */
561
+ if (!curl_http_proxy) {
562
+ if (!strcmp(http_auth.protocol, "https")) {
563
+ var_override(&curl_http_proxy, getenv("HTTPS_PROXY"));
564
+ var_override(&curl_http_proxy, getenv("https_proxy"));
565
+ } else {
566
+ var_override(&curl_http_proxy, getenv("http_proxy"));
567
+ }
568
+ if (!curl_http_proxy) {
569
+ var_override(&curl_http_proxy, getenv("ALL_PROXY"));
570
+ var_override(&curl_http_proxy, getenv("all_proxy"));
571
+ }
572
+ }
573
+
574
if (curl_http_proxy) {
575
curl_easy_setopt(result, CURLOPT_PROXY, curl_http_proxy);
576
#if LIBCURL_VERSION_NUM >= 0x071800
584
curl_easy_setopt(result,
585
CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
586
#endif
587
+ if (strstr(curl_http_proxy, "://"))
588
+ credential_from_url(&proxy_auth, curl_http_proxy);
589
+ else {
590
+ struct strbuf url = STRBUF_INIT;
591
+ strbuf_addf(&url, "http://%s", curl_http_proxy);
592
+ credential_from_url(&proxy_auth, url.buf);
593
+ strbuf_release(&url);
594
+ }
595
+
596
+ curl_easy_setopt(result, CURLOPT_PROXY, proxy_auth.host);
597
}
598
init_curl_proxy_auth(result);
599
737
curl_http_proxy = NULL;
738
}
739
740
+ if (proxy_auth.password) {
741
+ memset(proxy_auth.password, 0, strlen(proxy_auth.password));
742
+ free(proxy_auth.password);
743
+ proxy_auth.password = NULL;
744
+ }
745
+
746
+ free((void *)curl_proxyuserpwd);
747
+ curl_proxyuserpwd = NULL;
748
+
749
free((void *)http_proxy_authmethod);
750
http_proxy_authmethod = NULL;
751
1078
1079
if (results->curl_result == CURLE_OK) {
1080
credential_approve(&http_auth);
1081
+ if (proxy_auth.password)
1082
+ credential_approve(&proxy_auth);
1083
return HTTP_OK;
1084
} else if (missing_target(results))
1085
return HTTP_MISSING_TARGET;
1094
return HTTP_REAUTH;
1095
}
1096
} else {
1097
+ if (results->http_connectcode == 407)
1098
+ credential_reject(&proxy_auth);
1099
#if LIBCURL_VERSION_NUM >= 0x070c00
1100
if (!curl_errorstr[0])
1101
strlcpy(curl_errorstr,