http: pass http.cookiefile using CURLOPT_COOKIEFILE

If the config option http.cookiefile is set, pass this file to libCURL using the CURLOPT_COOKIEFILE option. This is similar to calling curl with the -b option. This allows git http authorization with authentication mechanisms that use cookies, such as SAML Enhanced Client or Proxy (ECP) used by Shibboleth. To use SAML/ECP, the user needs to request a session cookie with their own ECP code. See for example: <https://wiki.shibboleth.net/confluence/display/SHIB2/ECP> Once the cookie file has been created, it can be passed to git with, e.g. git config --global http.cookiefile "/home/dbrown/.curlcookies" libCURL will then pass the appropriate session cookies to the git http server. Signed-off-by: Duncan Brown <duncan.brown@ligo.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Duncan Brown committed Jun 2, 2011 at 16:31 UTC bcfb95dde46bd7cf2c6673ab8a3e6f0c0429906e
2 files changed +13
Documentation/config.txt
+8
@@ -1196,6 +1196,14 @@ http.proxy::
1196 environment variable (see linkgit:curl[1]). This can be overridden
1197 on a per-remote basis; see remote.<name>.proxy
1198
1199 +http.cookiefile::
1200 + File containing previously stored cookie lines which should be used
1201 + in the git http session, if they match the server. The file format
1202 + of the file to read cookies from should be plain HTTP headers or
1203 + the Netscape/Mozilla cookie file format (see linkgit:curl[1]).
1204 + NOTE that the file specified with http.cookiefile is only used as
1205 + input. No cookies will be stored in the file.
1206 +
1207 http.sslVerify::
1208 Whether to verify the SSL certificate when fetching or pushing
1209 over HTTPS. Can be overridden by the 'GIT_SSL_NO_VERIFY' environment
http.c
+5
@@ -41,6 +41,7 @@ static long curl_low_speed_limit = -1;
41 static long curl_low_speed_time = -1;
42 static int curl_ftp_no_epsv;
43 static const char *curl_http_proxy;
44 +static const char *curl_cookie_file;
45 static char *user_name, *user_pass;
46 static const char *user_agent;
47
@@ -191,6 +192,9 @@ static int http_options(const char *var, const char *value, void *cb)
192 if (!strcmp("http.proxy", var))
193 return git_config_string(&curl_http_proxy, var, value);
194
195 + if (!strcmp("http.cookiefile", var))
196 + return git_config_string(&curl_cookie_file, var, value);
197 +
198 if (!strcmp("http.postbuffer", var)) {
199 http_post_buffer = git_config_int(var, value);
200 if (http_post_buffer < LARGE_PACKET_MAX)
@@ -531,6 +535,7 @@ struct active_request_slot *get_active_slot(void)
535 slot->finished = NULL;
536 slot->callback_data = NULL;
537 slot->callback_func = NULL;
538 + curl_easy_setopt(slot->curl, CURLOPT_COOKIEFILE, curl_cookie_file);
539 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, pragma_header);
540 curl_easy_setopt(slot->curl, CURLOPT_ERRORBUFFER, curl_errorstr);
541 curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, NULL);