{"thread":{"id":"27537","subject":"[PATCH/RFC] http: pass http.cookiefile using CURLOPT_COOKIEFILE","startedAt":"2011-06-02T20:31:25Z","lastAt":"2011-06-03T02:43:11Z","messageCount":3,"participants":["Duncan Brown","Shawn Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"169226","messageId":"20110602203125.0E04C734F12@antares.phy.syr.edu","threadId":"27537","inReplyTo":null,"subject":"[PATCH/RFC] http: pass http.cookiefile using CURLOPT_COOKIEFILE","fromName":"Duncan Brown","fromEmail":"dabrown@physics.syr.edu","sentAt":"2011-06-02T20:31:25Z","receivedAt":"2011-06-02T20:31:25Z","isPatch":true,"sender":{"key":"dabrown@physics.syr.edu","avatar":null},"body":"If the config option http.cookiefile is set, pass this file to libCURL using\nthe CURLOPT_COOKIEFILE option. This is similar to calling curl with the -b\noption.  This allows git http authorization with authentication mechanisms\nthat use cookies, such as SAML Enhanced Client or Proxy (ECP) used by\nShibboleth.\n\nTo use SAML/ECP, the user needs to request a session cookie with their own ECP\ncode. See for example:\n\n<https://wiki.shibboleth.net/confluence/display/SHIB2/ECP>\n\nOnce the cookie file has been created, it can be passed to git with, e.g.\n\ngit config --global http.cookiefile \"/home/dbrown/.curlcookies\"\n\nlibCURL will then pass the appropriate session cookies to the git http server.\n\nSigned-off-by: Duncan Brown <duncan.brown@ligo.org>\n---\n Documentation/config.txt |    8 ++++++++\n http.c                   |    5 +++++\n 2 files changed, 13 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 6b93777..c631d1c 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1196,6 +1196,14 @@ http.proxy::\n \tenvironment variable (see linkgit:curl[1]).  This can be overridden\n \ton a per-remote basis; see remote.<name>.proxy\n \n+http.cookiefile::\n+\tFile containing previously stored cookie lines which should be used\n+\tin the git http session, if they match the server. The file format\n+\tof the file to read cookies from should be plain HTTP headers or\n+\tthe Netscape/Mozilla cookie file format (see linkgit:curl[1]).\n+\tNOTE that the file specified with http.cookiefile is only used as\n+\tinput. No cookies will be stored in the file.\n+\n http.sslVerify::\n \tWhether to verify the SSL certificate when fetching or pushing\n \tover HTTPS. Can be overridden by the 'GIT_SSL_NO_VERIFY' environment\ndiff --git a/http.c b/http.c\nindex b2ae8de..a1ea3db 100644\n--- a/http.c\n+++ b/http.c\n@@ -41,6 +41,7 @@ static long curl_low_speed_limit = -1;\n static long curl_low_speed_time = -1;\n static int curl_ftp_no_epsv;\n static const char *curl_http_proxy;\n+static const char *curl_cookie_file;\n static char *user_name, *user_pass;\n static const char *user_agent;\n \n@@ -191,6 +192,9 @@ static int http_options(const char *var, const char *value, void *cb)\n \tif (!strcmp(\"http.proxy\", var))\n \t\treturn git_config_string(&curl_http_proxy, var, value);\n \n+\tif (!strcmp(\"http.cookiefile\", var))\n+\t\treturn git_config_string(&curl_cookie_file, var, value);\n+\n \tif (!strcmp(\"http.postbuffer\", var)) {\n \t\thttp_post_buffer = git_config_int(var, value);\n \t\tif (http_post_buffer < LARGE_PACKET_MAX)\n@@ -531,6 +535,7 @@ struct active_request_slot *get_active_slot(void)\n \tslot->finished = NULL;\n \tslot->callback_data = NULL;\n \tslot->callback_func = NULL;\n+\tcurl_easy_setopt(slot->curl, CURLOPT_COOKIEFILE, curl_cookie_file);\n \tcurl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, pragma_header);\n \tcurl_easy_setopt(slot->curl, CURLOPT_ERRORBUFFER, curl_errorstr);\n \tcurl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, NULL);\n-- \n1.7.3.4\n"},{"id":"169234","messageId":"BANLkTi=3cQx9L4rrkniBhqFfL1TuNgu0doaSpdV8ajgsWJvw1Q@mail.gmail.com","threadId":"27537","inReplyTo":"20110602203125.0E04C734F12@antares.phy.syr.edu","subject":"Re: [PATCH/RFC] http: pass http.cookiefile using CURLOPT_COOKIEFILE","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2011-06-03T00:01:19Z","receivedAt":"2011-06-03T00:01:19Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"On Thu, Jun 2, 2011 at 13:31, Duncan Brown <dabrown@physics.syr.edu> wrote:\n> If the config option http.cookiefile is set, pass this file to libCURL using\n> the CURLOPT_COOKIEFILE option. This is similar to calling curl with the -b\n> option.  This allows git http authorization with authentication mechanisms\n> that use cookies, such as SAML Enhanced Client or Proxy (ECP) used by\n> Shibboleth.\n\nWow, the patch was this simple?\n\nThanks Duncan!\n\n> ---\n>  Documentation/config.txt |    8 ++++++++\n>  http.c                   |    5 +++++\n>  2 files changed, 13 insertions(+), 0 deletions(-)\n\nJunio, I didn't test this myself, but the code looks good to me. I\ndon't see any obvious issues with it.\n\n-- \nShawn.\n"},{"id":"169236","messageId":"BD4E94C2-E51C-44CA-8E6B-BE9371131DC5@physics.syr.edu","threadId":"27537","inReplyTo":"BANLkTi=3cQx9L4rrkniBhqFfL1TuNgu0doaSpdV8ajgsWJvw1Q@mail.gmail.com","subject":"Re: [PATCH/RFC] http: pass http.cookiefile using CURLOPT_COOKIEFILE","fromName":"Duncan Brown","fromEmail":"dabrown@physics.syr.edu","sentAt":"2011-06-03T02:43:11Z","receivedAt":"2011-06-03T02:43:11Z","isPatch":true,"sender":{"key":"dabrown@physics.syr.edu","avatar":null},"body":"Hi Shawn,\n\nOn Jun 2, 2011, at 8:01 PM, Shawn Pearce wrote:\n\n> On Thu, Jun 2, 2011 at 13:31, Duncan Brown <dabrown@physics.syr.edu> wrote:\n>> If the config option http.cookiefile is set, pass this file to libCURL using\n>> the CURLOPT_COOKIEFILE option. This is similar to calling curl with the -b\n>> option.  This allows git http authorization with authentication mechanisms\n>> that use cookies, such as SAML Enhanced Client or Proxy (ECP) used by\n>> Shibboleth.\n> \n> Wow, the patch was this simple?\n\nYep, it took longer to google for the libCURL docs than it did to write the code! With this patch, I can do the following:\n\n[dbrown@spice-dev2 test]$ ./ecp.sh SUGWG https://sugwg-git.phy.syr.edu/git/qm/info/refs?service=git-upload-pack dbrown\nEnter host password for user 'dbrown':\n\n001e# service=git-upload-pack\n0000009b0b31a9bef84542ff7dd5a10eb72ef2a67d176a35 HEADmulti_ack thin-pack side-band side-band-64k ofs-delta shallow no-progress include-tag multi_ack_detailed\n003f0b31a9bef84542ff7dd5a10eb72ef2a67d176a35 refs/heads/master\n00424b2259eb6bada1a160e8dcf394b93fa60a60c90d refs/tags/first_corr\n004266eea9443af5f0026a44d58990547f8ff60897c6 refs/tags/pre_double\n0043f8d991153a857af157e9dfaa9e8851ae2440cafd refs/tags/ptf_test_01\n0000\n\necp.sh is Scott Koranda's demonstration ECP client:\n\n<https://wiki.shibboleth.net/confluence/display/SHIB2/Contributions#Contributions-simplebash>\n\nIt gets a Shib session cookie and stores it in ~/.curlcookies with curl and xlstproc command line tools. Now that I have my session cookie, I can do\n\n[dbrown@spice-dev2 test]$ git config --global http.cookiefile \"/home/dbrown/.curlcookies\"\n[dbrown@spice-dev2 test]$ git clone https://sugwg-git.phy.syr.edu/git/qm\nCloning into qm...\nremote: Counting objects: 2071, done.\nremote: Compressing objects: 100% (833/833), done.\nremote: Total 2071 (delta 1352), reused 1851 (delta 1224)\nReceiving objects: 100% (2071/2071), 681.53 KiB, done.\nResolving deltas: 100% (1352/1352), done.\n\nWithout the session cookie:\n\n[dbrown@spice-dev2 test]$ rm ~/.curlcookies \n[dbrown@spice-dev2 test]$ git clone https://sugwg-git.phy.syr.edu/git/qm\nCloning into qm...\nwarning: remote HEAD refers to nonexistent ref, unable to checkout.\n\n> Thanks Duncan!\n\nNo problem.\n\nCheers,\nDuncan.\n\n> \n>> ---\n>>  Documentation/config.txt |    8 ++++++++\n>>  http.c                   |    5 +++++\n>>  2 files changed, 13 insertions(+), 0 deletions(-)\n> \n> Junio, I didn't test this myself, but the code looks good to me. I\n> don't see any obvious issues with it.\n> \n> -- \n> Shawn.\n> \n\n-- \n\nDuncan Brown                          Room 263-1, Department of Physics,\nAssociate Professor of Physics        Syracuse University, NY 13244, USA\nPhone: (315) 443 5993             http://www.gravity.phy.syr.edu/~duncan\n"}]}