http: create function to get curl allowed protocols
Move the creation of an allowed protocols whitelist to a helper function. This will be useful when we need to compute the set of allowed protocols differently for normal and redirect cases. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
f1762d772e
commit
aeae4db174
31
http.c
31
http.c
@ -489,10 +489,25 @@ static void set_curl_keepalive(CURL *c)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static long get_curl_allowed_protocols(void)
|
||||||
|
{
|
||||||
|
long allowed_protocols = 0;
|
||||||
|
|
||||||
|
if (is_transport_allowed("http"))
|
||||||
|
allowed_protocols |= CURLPROTO_HTTP;
|
||||||
|
if (is_transport_allowed("https"))
|
||||||
|
allowed_protocols |= CURLPROTO_HTTPS;
|
||||||
|
if (is_transport_allowed("ftp"))
|
||||||
|
allowed_protocols |= CURLPROTO_FTP;
|
||||||
|
if (is_transport_allowed("ftps"))
|
||||||
|
allowed_protocols |= CURLPROTO_FTPS;
|
||||||
|
|
||||||
|
return allowed_protocols;
|
||||||
|
}
|
||||||
|
|
||||||
static CURL *get_curl_handle(void)
|
static CURL *get_curl_handle(void)
|
||||||
{
|
{
|
||||||
CURL *result = curl_easy_init();
|
CURL *result = curl_easy_init();
|
||||||
long allowed_protocols = 0;
|
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
die("curl_easy_init failed");
|
die("curl_easy_init failed");
|
||||||
@ -572,16 +587,10 @@ static CURL *get_curl_handle(void)
|
|||||||
curl_easy_setopt(result, CURLOPT_POST301, 1);
|
curl_easy_setopt(result, CURLOPT_POST301, 1);
|
||||||
#endif
|
#endif
|
||||||
#if LIBCURL_VERSION_NUM >= 0x071304
|
#if LIBCURL_VERSION_NUM >= 0x071304
|
||||||
if (is_transport_allowed("http"))
|
curl_easy_setopt(result, CURLOPT_REDIR_PROTOCOLS,
|
||||||
allowed_protocols |= CURLPROTO_HTTP;
|
get_curl_allowed_protocols());
|
||||||
if (is_transport_allowed("https"))
|
curl_easy_setopt(result, CURLOPT_PROTOCOLS,
|
||||||
allowed_protocols |= CURLPROTO_HTTPS;
|
get_curl_allowed_protocols());
|
||||||
if (is_transport_allowed("ftp"))
|
|
||||||
allowed_protocols |= CURLPROTO_FTP;
|
|
||||||
if (is_transport_allowed("ftps"))
|
|
||||||
allowed_protocols |= CURLPROTO_FTPS;
|
|
||||||
curl_easy_setopt(result, CURLOPT_REDIR_PROTOCOLS, allowed_protocols);
|
|
||||||
curl_easy_setopt(result, CURLOPT_PROTOCOLS, allowed_protocols);
|
|
||||||
#else
|
#else
|
||||||
warning("protocol restrictions not applied to curl redirects because\n"
|
warning("protocol restrictions not applied to curl redirects because\n"
|
||||||
"your curl version is too old (>= 7.19.4)");
|
"your curl version is too old (>= 7.19.4)");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user