{"thread":{"id":"29093","subject":"[PATCHv2 0/13] credential helpers","startedAt":"2011-12-06T06:21:28Z","lastAt":"2011-12-09T23:56:44Z","messageCount":30,"participants":["Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"180344","messageId":"20111206062127.GA29046@sigill.intra.peff.net","threadId":"29093","inReplyTo":null,"subject":"[PATCHv2 0/13] credential helpers","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-12-06T06:21:28Z","receivedAt":"2011-12-06T06:21:28Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"This is a re-roll of the credential helper series. Changes are noted\nbelow.\n\n  [01/13]: test-lib: add test_config_global variant\n  [02/13]: t5550: fix typo\n  [03/13]: introduce credentials API\n\n    - simplified \"first word is alnum\" rules. You can now use \"!f() {\"\n      to get a shell snippet helper.\n    - documentation clarifications based on discussion with Junio\n    - fix missing EOF in test script (same as the fixup in pu)\n    - minor code style fixups\n\n  [04/13]: credential: add function for parsing url components\n  [05/13]: http: use credential API to get passwords\n  [06/13]: credential: apply helper config\n  [07/13]: credential: add credential.*.username\n  [08/13]: credential: make relevance of http path configurable\n  [09/13]: docs: end-user documentation for the credential subsystem\n  [10/13]: credentials: add \"cache\" helper\n\n    - don't die on unknown action, as suggested by credential helper\n      docs. This is to leave room for new actions later.\n\n  [11/13]: strbuf: add strbuf_add*_urlencode\n  [12/13]: credentials: add \"store\" helper\n\n    - don't die on unknown action, as above\n    - \"store --store=foo\" is now spelled \"store --file=foo\"\n    - passwords are now stored in most-recently-added order\n    - drop remove/lookup restrictions, per discussion with Junio\n\n    This last one has an interesting side effect. You can now\n    do: \"git credential-store erase </dev/null\" to erase everything\n    (since you have provided no restrictions, it matches everything).\n    It's not something git would send intentionally, but it seems\n    accidentally destructive (e.g., for some reason the main git process\n    dies and closes the pipe). Perhaps a \"credential on the wire\" should\n    be re-defined as a set of key/value lines followed by a blank line\n    to signal \"end\"?\n\n  [13/13]: t: add test harness for external credential helpers\n\n    - actually invoke cleanup functions. The lib-credential script\n      provides a best-effort cleanup function, since external helpers\n      may be writing to system storage outsid of the trash directory.\n      But in v1 we didn't actually call it.\n\n-Peff\n"},{"id":"180346","messageId":"20111206062228.GA29233@sigill.intra.peff.net","threadId":"29093","inReplyTo":"20111206062127.GA29046@sigill.intra.peff.net","subject":"[PATCHv2 01/13] test-lib: add test_config_global variant","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-12-06T06:22:28Z","receivedAt":"2011-12-06T06:22:28Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"The point of test_config is to simultaneously set a config\nvariable and register its cleanup handler, like:\n\n  test_config core.foo bar\n\nHowever, it stupidly assumes that $1 contained the name of\nthe variable, which means it won't work for:\n\n  test_config --global core.foo bar\n\nWe could try to parse the command-line ourselves and figure\nout which parts need to be fed to test_unconfig. But since\nthis is likely the most common variant, it's much simpler\nand less error-prone to simply add a new function.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n t/test-lib.sh |    5 +++++\n 1 files changed, 5 insertions(+), 0 deletions(-)\n\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex bdd9513..160479b 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -379,6 +379,11 @@ test_config () {\n \tgit config \"$@\"\n }\n \n+test_config_global () {\n+\ttest_when_finished \"test_unconfig --global '$1'\" &&\n+\tgit config --global \"$@\"\n+}\n+\n # Use test_set_prereq to tell that a particular prerequisite is available.\n # The prerequisite can later be checked for in two ways:\n #\n-- \n1.7.8.rc4.4.g884ec\n"},{"id":"180345","messageId":"20111206062232.GB29233@sigill.intra.peff.net","threadId":"29093","inReplyTo":"20111206062127.GA29046@sigill.intra.peff.net","subject":"[PATCHv2 02/13] t5550: fix typo","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-12-06T06:22:32Z","receivedAt":"2011-12-06T06:22:32Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"This didn't have an impact, because it was just setting up\nan \"expect\" file that happened to be identical to the one in\nthe test before it.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n t/t5550-http-fetch.sh |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/t/t5550-http-fetch.sh b/t/t5550-http-fetch.sh\nindex 311a33c..3d6e871 100755\n--- a/t/t5550-http-fetch.sh\n+++ b/t/t5550-http-fetch.sh\n@@ -66,7 +66,7 @@ test_expect_success 'cloning password-protected repository can fail' '\n \n test_expect_success 'http auth can use user/pass in URL' '\n \t>askpass-query &&\n-\techo wrong >askpass-reponse &&\n+\techo wrong >askpass-response &&\n \tgit clone \"$HTTPD_URL_USER_PASS/auth/repo.git\" clone-auth-none &&\n \ttest_cmp askpass-expect-none askpass-query\n '\n-- \n1.7.8.rc4.4.g884ec\n"},{"id":"180347","messageId":"20111206062237.GC29233@sigill.intra.peff.net","threadId":"29093","inReplyTo":"20111206062127.GA29046@sigill.intra.peff.net","subject":"[PATCHv2 03/13] introduce credentials API","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-12-06T06:22:37Z","receivedAt":"2011-12-06T06:22:37Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"There are a few places in git that need to get a username\nand password credential from the user; the most notable one\nis HTTP authentication for smart-http pushing.\n\nRight now the only choices for providing credentials are to\nput them plaintext into your ~/.netrc, or to have git prompt\nyou (either on the terminal or via an askpass program). The\nformer is not very secure, and the latter is not very\nconvenient.\n\nUnfortunately, there is no \"always best\" solution for\npassword management. The details will depend on the tradeoff\nyou want between security and convenience, as well as how\ngit can integrate with other security systems (e.g., many\noperating systems provide a keychain or password wallet for\nsingle sign-on).\n\nThis patch provides an abstract notion of credentials as a\ndata item, and provides three basic operations:\n\n  - fill (i.e., acquire from external storage or from the\n    user)\n\n  - approve (mark a credential as \"working\" for further\n    storage)\n\n  - reject (mark a credential as \"not working\", so it can\n    be removed from storage)\n\nThese operations can be backed by external helper processes\nthat interact with system- or user-specific secure storage.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n .gitignore                                  |    1 +\n Documentation/technical/api-credentials.txt |  241 +++++++++++++++++++++++++++\n Makefile                                    |    3 +\n credential.c                                |  234 ++++++++++++++++++++++++++\n credential.h                                |   28 +++\n t/lib-credential.sh                         |   33 ++++\n t/t0300-credentials.sh                      |  195 ++++++++++++++++++++++\n test-credential.c                           |   38 +++++\n 8 files changed, 773 insertions(+), 0 deletions(-)\n create mode 100644 Documentation/technical/api-credentials.txt\n create mode 100644 credential.c\n create mode 100644 credential.h\n create mode 100755 t/lib-credential.sh\n create mode 100755 t/t0300-credentials.sh\n create mode 100644 test-credential.c\n\ndiff --git a/.gitignore b/.gitignore\nindex 8572c8c..7d2fefc 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -167,6 +167,7 @@\n /gitweb/static/gitweb.js\n /gitweb/static/gitweb.min.*\n /test-chmtime\n+/test-credential\n /test-ctype\n /test-date\n /test-delta\ndiff --git a/Documentation/technical/api-credentials.txt b/Documentation/technical/api-credentials.txt\nnew file mode 100644\nindex 0000000..f624aef\n--- /dev/null\n+++ b/Documentation/technical/api-credentials.txt\n@@ -0,0 +1,241 @@\n+credentials API\n+===============\n+\n+The credentials API provides an abstracted way of gathering username and\n+password credentials from the user (even though credentials in the wider\n+world can take many forms, in this document the word \"credential\" always\n+refers to a username and password pair).\n+\n+Data Structures\n+---------------\n+\n+`struct credential`::\n+\n+\tThis struct represents a single username/password combination\n+\talong with any associated context. All string fields should be\n+\theap-allocated (or NULL if they are not known or not applicable).\n+\tThe meaning of the individual context fields is the same as\n+\ttheir counterparts in the helper protocol; see the section below\n+\tfor a description of each field.\n++\n+The `helpers` member of the struct is a `string_list` of helpers.  Each\n+string specifies an external helper which will be run, in order, to\n+either acquire or store credentials. See the section on credential\n+helpers below.\n++\n+This struct should always be initialized with `CREDENTIAL_INIT` or\n+`credential_init`.\n+\n+\n+Functions\n+---------\n+\n+`credential_init`::\n+\n+\tInitialize a credential structure, setting all fields to empty.\n+\n+`credential_clear`::\n+\n+\tFree any resources associated with the credential structure,\n+\treturning it to a pristine initialized state.\n+\n+`credential_fill`::\n+\n+\tInstruct the credential subsystem to fill the username and\n+\tpassword fields of the passed credential struct by first\n+\tconsulting helpers, then asking the user. After this function\n+\treturns, the username and password fields of the credential are\n+\tguaranteed to be non-NULL. If an error occurs, the function will\n+\tdie().\n+\n+`credential_reject`::\n+\n+\tInform the credential subsystem that the provided credentials\n+\thave been rejected. This will cause the credential subsystem to\n+\tnotify any helpers of the rejection (which allows them, for\n+\texample, to purge the invalid credentials from storage).  It\n+\twill also free() the username and password fields of the\n+\tcredential and set them to NULL (readying the credential for\n+\tanother call to `credential_fill`). Any errors from helpers are\n+\tignored.\n+\n+`credential_approve`::\n+\n+\tInform the credential subsystem that the provided credentials\n+\twere successfully used for authentication.  This will cause the\n+\tcredential subsystem to notify any helpers of the approval, so\n+\tthat they may store the result to be used again.  Any errors\n+\tfrom helpers are ignored.\n+\n+Example\n+-------\n+\n+The example below shows how the functions of the credential API could be\n+used to login to a fictitious \"foo\" service on a remote host:\n+\n+-----------------------------------------------------------------------\n+int foo_login(struct foo_connection *f)\n+{\n+\tint status;\n+\t/*\n+\t * Create a credential with some context; we don't yet know the\n+\t * username or password.\n+\t */\n+\n+\tstruct credential c = CREDENTIAL_INIT;\n+\tc.protocol = xstrdup(\"foo\");\n+\tc.host = xstrdup(f->hostname);\n+\n+\t/*\n+\t * Fill in the username and password fields by contacting\n+\t * helpers and/or asking the user. The function will die if it\n+\t * fails.\n+\t */\n+\tcredential_fill(&c);\n+\n+\t/*\n+\t * Otherwise, we have a username and password. Try to use it.\n+\t */\n+\tstatus = send_foo_login(f, c.username, c.password);\n+\tswitch (status) {\n+\tcase FOO_OK:\n+\t\t/* It worked. Store the credential for later use. */\n+\t\tcredential_accept(&c);\n+\t\tbreak;\n+\tcase FOO_BAD_LOGIN:\n+\t\t/* Erase the credential from storage so we don't try it\n+\t\t * again. */\n+\t\tcredential_reject(&c);\n+\t\tbreak;\n+\tdefault:\n+\t\t/*\n+\t\t * Some other error occured. We don't know if the\n+\t\t * credential is good or bad, so report nothing to the\n+\t\t * credential subsystem.\n+\t\t */\n+\t}\n+\n+\t/* Free any associated resources. */\n+\tcredential_clear(&c);\n+\n+\treturn status;\n+}\n+-----------------------------------------------------------------------\n+\n+\n+Credential Helpers\n+------------------\n+\n+Credential helpers are programs executed by git to fetch or save\n+credentials from and to long-term storage (where \"long-term\" is simply\n+longer than a single git process; e.g., credentials may be stored\n+in-memory for a few minutes, or indefinitely on disk).\n+\n+Each helper is specified by a single string. The string is transformed\n+by git into a command to be executed using these rules:\n+\n+  1. If the helper string begins with \"!\", it is considered a shell\n+     snippet, and everything after the \"!\" becomes the command.\n+\n+  2. Otherwise, if the helper string begins with an absolute path, the\n+     verbatim helper string becomes the command.\n+\n+  3. Otherwise, the string \"git credential-\" is prepended to the helper\n+     string, and the result becomes the command.\n+\n+The resulting command then has an \"operation\" argument appended to it\n+(see below for details), and the result is executed by the shell.\n+\n+Here are some example specifications:\n+\n+----------------------------------------------------\n+# run \"git credential-foo\"\n+foo\n+\n+# same as above, but pass an argument to the helper\n+foo --bar=baz\n+\n+# the arguments are parsed by the shell, so use shell\n+# quoting if necessary\n+foo --bar=\"whitespace arg\"\n+\n+# you can also use an absolute path, which will not use the git wrapper\n+/path/to/my/helper --with-arguments\n+\n+# or you can specify your own shell snippet\n+!f() { echo \"password=`cat $HOME/.secret`\"; }; f\n+----------------------------------------------------\n+\n+Generally speaking, rule (3) above is the simplest for users to specify.\n+Authors of credential helpers should make an effort to assist their\n+users by naming their program \"git-credential-$NAME\", and putting it in\n+the $PATH or $GIT_EXEC_PATH during installation, which will allow a user\n+to enable it with `git config credential.helper $NAME`.\n+\n+When a helper is executed, it will have one \"operation\" argument\n+appended to its command line, which is one of:\n+\n+`get`::\n+\n+\tReturn a matching credential, if any exists.\n+\n+`store`::\n+\n+\tStore the credential, if applicable to the helper.\n+\n+`erase`::\n+\n+\tRemove a matching credential, if any, from the helper's storage.\n+\n+The details of the credential will be provided on the helper's stdin\n+stream. The credential is split into a set of named attributes.\n+Attributes are provided to the helper, one per line. Each attribute is\n+specified by a key-value pair, separated by an `=` (equals) sign,\n+followed by a newline. The key may contain any bytes except `=`,\n+newline, or NUL. The value may contain any bytes except newline or NUL.\n+In both cases, all bytes are treated as-is (i.e., there is no quoting,\n+and one cannot transmit a value with newline or NUL in it). The list of\n+attributes is terminated by a blank line or end-of-file.\n+\n+Git will send the following attributes (but may not send all of\n+them for a given credential; for example, a `host` attribute makes no\n+sense when dealing with a non-network protocol):\n+\n+`protocol`::\n+\n+\tThe protocol over which the credential will be used (e.g.,\n+\t`https`).\n+\n+`host`::\n+\n+\tThe remote hostname for a network credential.\n+\n+`path`::\n+\n+\tThe path with which the credential will be used. E.g., for\n+\taccessing a remote https repository, this will be the\n+\trepository's path on the server.\n+\n+`username`::\n+\n+\tThe credential's username, if we already have one (e.g., from a\n+\tURL, from the user, or from a previously run helper).\n+\n+`password`::\n+\n+\tThe credential's password, if we are asking it to be stored.\n+\n+For a `get` operation, the helper should produce a list of attributes\n+on stdout in the same format. A helper is free to produce a subset, or\n+even no values at all if it has nothing useful to provide. Any provided\n+attributes will overwrite those already known about by git.\n+\n+For a `store` or `erase` operation, the helper's output is ignored.\n+If it fails to perform the requested operation, it may complain to\n+stderr to inform the user. If it does not support the requested\n+operation (e.g., a read-only store), it should silently ignore the\n+request.\n+\n+If a helper receives any other operation, it should silently ignore the\n+request. This leaves room for future operations to be added (older\n+helpers will just ignore the new requests).\ndiff --git a/Makefile b/Makefile\nindex b1c80a6..5ca363b 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -431,6 +431,7 @@ PROGRAM_OBJS += sh-i18n--envsubst.o\n PROGRAMS += $(patsubst %.o,git-%$X,$(PROGRAM_OBJS))\n \n TEST_PROGRAMS_NEED_X += test-chmtime\n+TEST_PROGRAMS_NEED_X += test-credential\n TEST_PROGRAMS_NEED_X += test-ctype\n TEST_PROGRAMS_NEED_X += test-date\n TEST_PROGRAMS_NEED_X += test-delta\n@@ -525,6 +526,7 @@ LIB_H += compat/win32/poll.h\n LIB_H += compat/win32/dirent.h\n LIB_H += connected.h\n LIB_H += convert.h\n+LIB_H += credential.h\n LIB_H += csum-file.h\n LIB_H += decorate.h\n LIB_H += delta.h\n@@ -609,6 +611,7 @@ LIB_OBJS += connect.o\n LIB_OBJS += connected.o\n LIB_OBJS += convert.o\n LIB_OBJS += copy.o\n+LIB_OBJS += credential.o\n LIB_OBJS += csum-file.o\n LIB_OBJS += ctype.o\n LIB_OBJS += date.o\ndiff --git a/credential.c b/credential.c\nnew file mode 100644\nindex 0000000..86397f3\n--- /dev/null\n+++ b/credential.c\n@@ -0,0 +1,234 @@\n+#include \"cache.h\"\n+#include \"credential.h\"\n+#include \"string-list.h\"\n+#include \"run-command.h\"\n+\n+void credential_init(struct credential *c)\n+{\n+\tmemset(c, 0, sizeof(*c));\n+\tc->helpers.strdup_strings = 1;\n+}\n+\n+void credential_clear(struct credential *c)\n+{\n+\tfree(c->protocol);\n+\tfree(c->host);\n+\tfree(c->path);\n+\tfree(c->username);\n+\tfree(c->password);\n+\tstring_list_clear(&c->helpers, 0);\n+\n+\tcredential_init(c);\n+}\n+\n+static void credential_describe(struct credential *c, struct strbuf *out)\n+{\n+\tif (!c->protocol)\n+\t\treturn;\n+\tstrbuf_addf(out, \"%s://\", c->protocol);\n+\tif (c->username && *c->username)\n+\t\tstrbuf_addf(out, \"%s@\", c->username);\n+\tif (c->host)\n+\t\tstrbuf_addstr(out, c->host);\n+\tif (c->path)\n+\t\tstrbuf_addf(out, \"/%s\", c->path);\n+}\n+\n+static char *credential_ask_one(const char *what, struct credential *c)\n+{\n+\tstruct strbuf desc = STRBUF_INIT;\n+\tstruct strbuf prompt = STRBUF_INIT;\n+\tchar *r;\n+\n+\tcredential_describe(c, &desc);\n+\tif (desc.len)\n+\t\tstrbuf_addf(&prompt, \"%s for '%s': \", what, desc.buf);\n+\telse\n+\t\tstrbuf_addf(&prompt, \"%s: \", what);\n+\n+\t/* FIXME: for usernames, we should do something less magical that\n+\t * actually echoes the characters. However, we need to read from\n+\t * /dev/tty and not stdio, which is not portable (but getpass will do\n+\t * it for us). http.c uses the same workaround. */\n+\tr = git_getpass(prompt.buf);\n+\n+\tstrbuf_release(&desc);\n+\tstrbuf_release(&prompt);\n+\treturn xstrdup(r);\n+}\n+\n+static void credential_getpass(struct credential *c)\n+{\n+\tif (!c->username)\n+\t\tc->username = credential_ask_one(\"Username\", c);\n+\tif (!c->password)\n+\t\tc->password = credential_ask_one(\"Password\", c);\n+}\n+\n+int credential_read(struct credential *c, FILE *fp)\n+{\n+\tstruct strbuf line = STRBUF_INIT;\n+\n+\twhile (strbuf_getline(&line, fp, '\\n') != EOF) {\n+\t\tchar *key = line.buf;\n+\t\tchar *value = strchr(key, '=');\n+\n+\t\tif (!line.len)\n+\t\t\tbreak;\n+\n+\t\tif (!value) {\n+\t\t\twarning(\"invalid credential line: %s\", key);\n+\t\t\tstrbuf_release(&line);\n+\t\t\treturn -1;\n+\t\t}\n+\t\t*value++ = '\\0';\n+\n+\t\tif (!strcmp(key, \"username\")) {\n+\t\t\tfree(c->username);\n+\t\t\tc->username = xstrdup(value);\n+\t\t} else if (!strcmp(key, \"password\")) {\n+\t\t\tfree(c->password);\n+\t\t\tc->password = xstrdup(value);\n+\t\t} else if (!strcmp(key, \"protocol\")) {\n+\t\t\tfree(c->protocol);\n+\t\t\tc->protocol = xstrdup(value);\n+\t\t} else if (!strcmp(key, \"host\")) {\n+\t\t\tfree(c->host);\n+\t\t\tc->host = xstrdup(value);\n+\t\t} else if (!strcmp(key, \"path\")) {\n+\t\t\tfree(c->path);\n+\t\t\tc->path = xstrdup(value);\n+\t\t}\n+\t\t/*\n+\t\t * Ignore other lines; we don't know what they mean, but\n+\t\t * this future-proofs us when later versions of git do\n+\t\t * learn new lines, and the helpers are updated to match.\n+\t\t */\n+\t}\n+\n+\tstrbuf_release(&line);\n+\treturn 0;\n+}\n+\n+static void credential_write_item(FILE *fp, const char *key, const char *value)\n+{\n+\tif (!value)\n+\t\treturn;\n+\tfprintf(fp, \"%s=%s\\n\", key, value);\n+}\n+\n+static void credential_write(const struct credential *c, FILE *fp)\n+{\n+\tcredential_write_item(fp, \"protocol\", c->protocol);\n+\tcredential_write_item(fp, \"host\", c->host);\n+\tcredential_write_item(fp, \"path\", c->path);\n+\tcredential_write_item(fp, \"username\", c->username);\n+\tcredential_write_item(fp, \"password\", c->password);\n+}\n+\n+static int run_credential_helper(struct credential *c,\n+\t\t\t\t const char *cmd,\n+\t\t\t\t int want_output)\n+{\n+\tstruct child_process helper;\n+\tconst char *argv[] = { NULL, NULL };\n+\tFILE *fp;\n+\n+\tmemset(&helper, 0, sizeof(helper));\n+\targv[0] = cmd;\n+\thelper.argv = argv;\n+\thelper.use_shell = 1;\n+\thelper.in = -1;\n+\tif (want_output)\n+\t\thelper.out = -1;\n+\telse\n+\t\thelper.no_stdout = 1;\n+\n+\tif (start_command(&helper) < 0)\n+\t\treturn -1;\n+\n+\tfp = xfdopen(helper.in, \"w\");\n+\tcredential_write(c, fp);\n+\tfclose(fp);\n+\n+\tif (want_output) {\n+\t\tint r;\n+\t\tfp = xfdopen(helper.out, \"r\");\n+\t\tr = credential_read(c, fp);\n+\t\tfclose(fp);\n+\t\tif (r < 0) {\n+\t\t\tfinish_command(&helper);\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+\n+\tif (finish_command(&helper))\n+\t\treturn -1;\n+\treturn 0;\n+}\n+\n+static int credential_do(struct credential *c, const char *helper,\n+\t\t\t const char *operation)\n+{\n+\tstruct strbuf cmd = STRBUF_INIT;\n+\tint r;\n+\n+\tif (helper[0] == '!')\n+\t\tstrbuf_addstr(&cmd, helper + 1);\n+\telse if (is_absolute_path(helper))\n+\t\tstrbuf_addstr(&cmd, helper);\n+\telse\n+\t\tstrbuf_addf(&cmd, \"git credential-%s\", helper);\n+\n+\tstrbuf_addf(&cmd, \" %s\", operation);\n+\tr = run_credential_helper(c, cmd.buf, !strcmp(operation, \"get\"));\n+\n+\tstrbuf_release(&cmd);\n+\treturn r;\n+}\n+\n+void credential_fill(struct credential *c)\n+{\n+\tint i;\n+\n+\tif (c->username && c->password)\n+\t\treturn;\n+\n+\tfor (i = 0; i < c->helpers.nr; i++) {\n+\t\tcredential_do(c, c->helpers.items[i].string, \"get\");\n+\t\tif (c->username && c->password)\n+\t\t\treturn;\n+\t}\n+\n+\tcredential_getpass(c);\n+\tif (!c->username && !c->password)\n+\t\tdie(\"unable to get password from user\");\n+}\n+\n+void credential_approve(struct credential *c)\n+{\n+\tint i;\n+\n+\tif (c->approved)\n+\t\treturn;\n+\tif (!c->username || !c->password)\n+\t\treturn;\n+\n+\tfor (i = 0; i < c->helpers.nr; i++)\n+\t\tcredential_do(c, c->helpers.items[i].string, \"store\");\n+\tc->approved = 1;\n+}\n+\n+void credential_reject(struct credential *c)\n+{\n+\tint i;\n+\n+\tfor (i = 0; i < c->helpers.nr; i++)\n+\t\tcredential_do(c, c->helpers.items[i].string, \"erase\");\n+\n+\tfree(c->username);\n+\tc->username = NULL;\n+\tfree(c->password);\n+\tc->password = NULL;\n+\tc->approved = 0;\n+}\ndiff --git a/credential.h b/credential.h\nnew file mode 100644\nindex 0000000..2ea7d49\n--- /dev/null\n+++ b/credential.h\n@@ -0,0 +1,28 @@\n+#ifndef CREDENTIAL_H\n+#define CREDENTIAL_H\n+\n+#include \"string-list.h\"\n+\n+struct credential {\n+\tstruct string_list helpers;\n+\tunsigned approved:1;\n+\n+\tchar *username;\n+\tchar *password;\n+\tchar *protocol;\n+\tchar *host;\n+\tchar *path;\n+};\n+\n+#define CREDENTIAL_INIT { STRING_LIST_INIT_DUP }\n+\n+void credential_init(struct credential *);\n+void credential_clear(struct credential *);\n+\n+void credential_fill(struct credential *);\n+void credential_approve(struct credential *);\n+void credential_reject(struct credential *);\n+\n+int credential_read(struct credential *, FILE *);\n+\n+#endif /* CREDENTIAL_H */\ndiff --git a/t/lib-credential.sh b/t/lib-credential.sh\nnew file mode 100755\nindex 0000000..54ae1f4\n--- /dev/null\n+++ b/t/lib-credential.sh\n@@ -0,0 +1,33 @@\n+#!/bin/sh\n+\n+# Try a set of credential helpers; the expected stdin,\n+# stdout and stderr should be provided on stdin,\n+# separated by \"--\".\n+check() {\n+\tread_chunk >stdin &&\n+\tread_chunk >expect-stdout &&\n+\tread_chunk >expect-stderr &&\n+\ttest-credential \"$@\" <stdin >stdout 2>stderr &&\n+\ttest_cmp expect-stdout stdout &&\n+\ttest_cmp expect-stderr stderr\n+}\n+\n+read_chunk() {\n+\twhile read line; do\n+\t\tcase \"$line\" in\n+\t\t--) break ;;\n+\t\t*) echo \"$line\" ;;\n+\t\tesac\n+\tdone\n+}\n+\n+\n+cat >askpass <<\\EOF\n+#!/bin/sh\n+echo >&2 askpass: $*\n+what=`echo $1 | cut -d\" \" -f1 | tr A-Z a-z | tr -cd a-z`\n+echo \"askpass-$what\"\n+EOF\n+chmod +x askpass\n+GIT_ASKPASS=\"$PWD/askpass\"\n+export GIT_ASKPASS\ndiff --git a/t/t0300-credentials.sh b/t/t0300-credentials.sh\nnew file mode 100755\nindex 0000000..81a455f\n--- /dev/null\n+++ b/t/t0300-credentials.sh\n@@ -0,0 +1,195 @@\n+#!/bin/sh\n+\n+test_description='basic credential helper tests'\n+. ./test-lib.sh\n+. \"$TEST_DIRECTORY\"/lib-credential.sh\n+\n+test_expect_success 'setup helper scripts' '\n+\tcat >dump <<-\\EOF &&\n+\twhoami=`echo $0 | sed s/.*git-credential-//`\n+\techo >&2 \"$whoami: $*\"\n+\twhile IFS== read key value; do\n+\t\techo >&2 \"$whoami: $key=$value\"\n+\t\teval \"$key=$value\"\n+\tdone\n+\tEOF\n+\n+\tcat >git-credential-useless <<-\\EOF &&\n+\t#!/bin/sh\n+\t. ./dump\n+\texit 0\n+\tEOF\n+\tchmod +x git-credential-useless &&\n+\n+\tcat >git-credential-verbatim <<-\\EOF &&\n+\t#!/bin/sh\n+\tuser=$1; shift\n+\tpass=$1; shift\n+\t. ./dump\n+\ttest -z \"$user\" || echo username=$user\n+\ttest -z \"$pass\" || echo password=$pass\n+\tEOF\n+\tchmod +x git-credential-verbatim &&\n+\n+\tPATH=\"$PWD:$PATH\"\n+'\n+\n+test_expect_success 'credential_fill invokes helper' '\n+\tcheck fill \"verbatim foo bar\" <<-\\EOF\n+\t--\n+\tusername=foo\n+\tpassword=bar\n+\t--\n+\tverbatim: get\n+\tEOF\n+'\n+\n+test_expect_success 'credential_fill invokes multiple helpers' '\n+\tcheck fill useless \"verbatim foo bar\" <<-\\EOF\n+\t--\n+\tusername=foo\n+\tpassword=bar\n+\t--\n+\tuseless: get\n+\tverbatim: get\n+\tEOF\n+'\n+\n+test_expect_success 'credential_fill stops when we get a full response' '\n+\tcheck fill \"verbatim one two\" \"verbatim three four\" <<-\\EOF\n+\t--\n+\tusername=one\n+\tpassword=two\n+\t--\n+\tverbatim: get\n+\tEOF\n+'\n+\n+test_expect_success 'credential_fill continues through partial response' '\n+\tcheck fill \"verbatim one \\\"\\\"\" \"verbatim two three\" <<-\\EOF\n+\t--\n+\tusername=two\n+\tpassword=three\n+\t--\n+\tverbatim: get\n+\tverbatim: get\n+\tverbatim: username=one\n+\tEOF\n+'\n+\n+test_expect_success 'credential_fill passes along metadata' '\n+\tcheck fill \"verbatim one two\" <<-\\EOF\n+\tprotocol=ftp\n+\thost=example.com\n+\tpath=foo.git\n+\t--\n+\tusername=one\n+\tpassword=two\n+\t--\n+\tverbatim: get\n+\tverbatim: protocol=ftp\n+\tverbatim: host=example.com\n+\tverbatim: path=foo.git\n+\tEOF\n+'\n+\n+test_expect_success 'credential_approve calls all helpers' '\n+\tcheck approve useless \"verbatim one two\" <<-\\EOF\n+\tusername=foo\n+\tpassword=bar\n+\t--\n+\t--\n+\tuseless: store\n+\tuseless: username=foo\n+\tuseless: password=bar\n+\tverbatim: store\n+\tverbatim: username=foo\n+\tverbatim: password=bar\n+\tEOF\n+'\n+\n+test_expect_success 'do not bother storing password-less credential' '\n+\tcheck approve useless <<-\\EOF\n+\tusername=foo\n+\t--\n+\t--\n+\tEOF\n+'\n+\n+\n+test_expect_success 'credential_reject calls all helpers' '\n+\tcheck reject useless \"verbatim one two\" <<-\\EOF\n+\tusername=foo\n+\tpassword=bar\n+\t--\n+\t--\n+\tuseless: erase\n+\tuseless: username=foo\n+\tuseless: password=bar\n+\tverbatim: erase\n+\tverbatim: username=foo\n+\tverbatim: password=bar\n+\tEOF\n+'\n+\n+test_expect_success 'usernames can be preserved' '\n+\tcheck fill \"verbatim \\\"\\\" three\" <<-\\EOF\n+\tusername=one\n+\t--\n+\tusername=one\n+\tpassword=three\n+\t--\n+\tverbatim: get\n+\tverbatim: username=one\n+\tEOF\n+'\n+\n+test_expect_success 'usernames can be overridden' '\n+\tcheck fill \"verbatim two three\" <<-\\EOF\n+\tusername=one\n+\t--\n+\tusername=two\n+\tpassword=three\n+\t--\n+\tverbatim: get\n+\tverbatim: username=one\n+\tEOF\n+'\n+\n+test_expect_success 'do not bother completing already-full credential' '\n+\tcheck fill \"verbatim three four\" <<-\\EOF\n+\tusername=one\n+\tpassword=two\n+\t--\n+\tusername=one\n+\tpassword=two\n+\t--\n+\tEOF\n+'\n+\n+# We can't test the basic terminal password prompt here because\n+# getpass() tries too hard to find the real terminal. But if our\n+# askpass helper is run, we know the internal getpass is working.\n+test_expect_success 'empty helper list falls back to internal getpass' '\n+\tcheck fill <<-\\EOF\n+\t--\n+\tusername=askpass-username\n+\tpassword=askpass-password\n+\t--\n+\taskpass: Username:\n+\taskpass: Password:\n+\tEOF\n+'\n+\n+test_expect_success 'internal getpass does not ask for known username' '\n+\tcheck fill <<-\\EOF\n+\tusername=foo\n+\t--\n+\tusername=foo\n+\tpassword=askpass-password\n+\t--\n+\taskpass: Password:\n+\tEOF\n+'\n+\n+test_done\ndiff --git a/test-credential.c b/test-credential.c\nnew file mode 100644\nindex 0000000..dee200e\n--- /dev/null\n+++ b/test-credential.c\n@@ -0,0 +1,38 @@\n+#include \"cache.h\"\n+#include \"credential.h\"\n+#include \"string-list.h\"\n+\n+static const char usage_msg[] =\n+\"test-credential <fill|approve|reject> [helper...]\";\n+\n+int main(int argc, const char **argv)\n+{\n+\tconst char *op;\n+\tstruct credential c = CREDENTIAL_INIT;\n+\tint i;\n+\n+\top = argv[1];\n+\tif (!op)\n+\t\tusage(usage_msg);\n+\tfor (i = 2; i < argc; i++)\n+\t\tstring_list_append(&c.helpers, argv[i]);\n+\n+\tif (credential_read(&c, stdin) < 0)\n+\t\tdie(\"unable to read credential from stdin\");\n+\n+\tif (!strcmp(op, \"fill\")) {\n+\t\tcredential_fill(&c);\n+\t\tif (c.username)\n+\t\t\tprintf(\"username=%s\\n\", c.username);\n+\t\tif (c.password)\n+\t\t\tprintf(\"password=%s\\n\", c.password);\n+\t}\n+\telse if (!strcmp(op, \"approve\"))\n+\t\tcredential_approve(&c);\n+\telse if (!strcmp(op, \"reject\"))\n+\t\tcredential_reject(&c);\n+\telse\n+\t\tusage(usage_msg);\n+\n+\treturn 0;\n+}\n-- \n1.7.8.rc4.4.g884ec\n"},{"id":"180349","messageId":"20111206062241.GD29233@sigill.intra.peff.net","threadId":"29093","inReplyTo":"20111206062127.GA29046@sigill.intra.peff.net","subject":"[PATCHv2 04/13] credential: add function for parsing url components","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-12-06T06:22:41Z","receivedAt":"2011-12-06T06:22:41Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"All of the components of a credential struct can be found in\na URL.  For example, the URL:\n\n  http://foo:bar@example.com/repo.git\n\ncontains:\n\n  protocol=http\n  host=example.com\n  path=repo.git\n  username=foo\n  password=bar\n\nWe want to be able to turn URLs into broken-down credential\nstructs so that we know two things:\n\n  1. Which parts of the username/password we still need\n\n  2. What the context of the request is (for prompting or\n     as a key for storing credentials).\n\nThis code is based on http_auth_init in http.c, but needed a\nfew modifications in order to get all of the components that\nthe credential object is interested in.\n\nOnce the http code is switched over to the credential API,\nthen http_auth_init can just go away.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n Documentation/technical/api-credentials.txt |    4 ++\n credential.c                                |   52 +++++++++++++++++++++++++++\n credential.h                                |    1 +\n 3 files changed, 57 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/technical/api-credentials.txt b/Documentation/technical/api-credentials.txt\nindex f624aef..21ca6a2 100644\n--- a/Documentation/technical/api-credentials.txt\n+++ b/Documentation/technical/api-credentials.txt\n@@ -67,6 +67,10 @@ Functions\n \tthat they may store the result to be used again.  Any errors\n \tfrom helpers are ignored.\n \n+`credential_from_url`::\n+\n+\tParse a URL into broken-down credential fields.\n+\n Example\n -------\n \ndiff --git a/credential.c b/credential.c\nindex 86397f3..c349b9a 100644\n--- a/credential.c\n+++ b/credential.c\n@@ -2,6 +2,7 @@\n #include \"credential.h\"\n #include \"string-list.h\"\n #include \"run-command.h\"\n+#include \"url.h\"\n \n void credential_init(struct credential *c)\n {\n@@ -232,3 +233,54 @@ void credential_reject(struct credential *c)\n \tc->password = NULL;\n \tc->approved = 0;\n }\n+\n+void credential_from_url(struct credential *c, const char *url)\n+{\n+\tconst char *at, *colon, *cp, *slash, *host, *proto_end;\n+\n+\tcredential_clear(c);\n+\n+\t/*\n+\t * Match one of:\n+\t *   (1) proto://<host>/...\n+\t *   (2) proto://<user>@<host>/...\n+\t *   (3) proto://<user>:<pass>@<host>/...\n+\t */\n+\tproto_end = strstr(url, \"://\");\n+\tif (!proto_end)\n+\t\treturn;\n+\tcp = proto_end + 3;\n+\tat = strchr(cp, '@');\n+\tcolon = strchr(cp, ':');\n+\tslash = strchrnul(cp, '/');\n+\n+\tif (!at || slash <= at) {\n+\t\t/* Case (1) */\n+\t\thost = cp;\n+\t}\n+\telse if (!colon || at <= colon) {\n+\t\t/* Case (2) */\n+\t\tc->username = url_decode_mem(cp, at - cp);\n+\t\thost = at + 1;\n+\t} else {\n+\t\t/* Case (3) */\n+\t\tc->username = url_decode_mem(cp, colon - cp);\n+\t\tc->password = url_decode_mem(colon + 1, at - (colon + 1));\n+\t\thost = at + 1;\n+\t}\n+\n+\tif (proto_end - url > 0)\n+\t\tc->protocol = xmemdupz(url, proto_end - url);\n+\tif (slash - host > 0)\n+\t\tc->host = url_decode_mem(host, slash - host);\n+\t/* Trim leading and trailing slashes from path */\n+\twhile (*slash == '/')\n+\t\tslash++;\n+\tif (*slash) {\n+\t\tchar *p;\n+\t\tc->path = url_decode(slash);\n+\t\tp = c->path + strlen(c->path) - 1;\n+\t\twhile (p > c->path && *p == '/')\n+\t\t\t*p-- = '\\0';\n+\t}\n+}\ndiff --git a/credential.h b/credential.h\nindex 2ea7d49..8a6d162 100644\n--- a/credential.h\n+++ b/credential.h\n@@ -24,5 +24,6 @@ struct credential {\n void credential_reject(struct credential *);\n \n int credential_read(struct credential *, FILE *);\n+void credential_from_url(struct credential *, const char *url);\n \n #endif /* CREDENTIAL_H */\n-- \n1.7.8.rc4.4.g884ec\n"},{"id":"180348","messageId":"20111206062244.GE29233@sigill.intra.peff.net","threadId":"29093","inReplyTo":"20111206062127.GA29046@sigill.intra.peff.net","subject":"[PATCHv2 05/13] http: use credential API to get passwords","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-12-06T06:22:44Z","receivedAt":"2011-12-06T06:22:44Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"This patch converts the http code to use the new credential\nAPI, both for http authentication as well as for getting\ncertificate passwords.\n\nMost of the code change is simply variable naming (the\npasswords are now contained inside the credential struct)\nor deletion of obsolete code (the credential code handles\nURL parsing and prompting for us).\n\nThe behavior should be the same, with one exception: the\ncredential code will prompt with a description based on the\ncredential components. Therefore, the old prompt of:\n\n  Username for 'example.com':\n  Password for 'example.com':\n\nnow looks like:\n\n  Username for 'https://example.com/repo.git':\n  Password for 'https://user@example.com/repo.git':\n\nNote that we include more information in each line,\nspecifically:\n\n  1. We now include the protocol. While more noisy, this is\n     an important part of knowing what you are accessing\n     (especially if you care about http vs https).\n\n  2. We include the username in the password prompt. This is\n     not a big deal when you have just been prompted for it,\n     but the username may also come from the remote's URL\n     (and after future patches, from configuration or\n     credential helpers).  In that case, it's a nice\n     reminder of the user for which you're giving the\n     password.\n\n  3. We include the path component of the URL. In many\n     cases, the user won't care about this and it's simply\n     noise (i.e., they'll use the same credential for a\n     whole site). However, that is part of a larger\n     question, which is whether path components should be\n     part of credential context, both for prompting and for\n     lookup by storage helpers. That issue will be addressed\n     as a whole in a future patch.\n\nSimilarly, for unlocking certificates, we used to say:\n\n  Certificate Password for 'example.com':\n\nand we now say:\n\n  Password for 'cert:///path/to/certificate':\n\nShowing the path to the client certificate makes more sense,\nas that is what you are unlocking, not \"example.com\".\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n http.c                |  113 +++++++++++--------------------------------------\n t/t5550-http-fetch.sh |   38 ++++++++++++-----\n 2 files changed, 52 insertions(+), 99 deletions(-)\n\ndiff --git a/http.c b/http.c\nindex e6c7597..917a1ae 100644\n--- a/http.c\n+++ b/http.c\n@@ -3,6 +3,7 @@\n #include \"sideband.h\"\n #include \"run-command.h\"\n #include \"url.h\"\n+#include \"credential.h\"\n \n int data_received;\n int active_requests;\n@@ -42,7 +43,7 @@\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, *description;\n+static struct credential http_auth = CREDENTIAL_INIT;\n static const char *user_agent;\n \n #if LIBCURL_VERSION_NUM >= 0x071700\n@@ -53,7 +54,7 @@\n #define CURLOPT_KEYPASSWD CURLOPT_SSLCERTPASSWD\n #endif\n \n-static char *ssl_cert_password;\n+static struct credential cert_auth = CREDENTIAL_INIT;\n static int ssl_cert_password_required;\n \n static struct curl_slist *pragma_header;\n@@ -139,27 +140,6 @@ static void process_curl_messages(void)\n }\n #endif\n \n-static char *git_getpass_with_description(const char *what, const char *desc)\n-{\n-\tstruct strbuf prompt = STRBUF_INIT;\n-\tchar *r;\n-\n-\tif (desc)\n-\t\tstrbuf_addf(&prompt, \"%s for '%s': \", what, desc);\n-\telse\n-\t\tstrbuf_addf(&prompt, \"%s: \", what);\n-\t/*\n-\t * NEEDSWORK: for usernames, we should do something less magical that\n-\t * actually echoes the characters. However, we need to read from\n-\t * /dev/tty and not stdio, which is not portable (but getpass will do\n-\t * it for us). http.c uses the same workaround.\n-\t */\n-\tr = git_getpass(prompt.buf);\n-\n-\tstrbuf_release(&prompt);\n-\treturn xstrdup(r);\n-}\n-\n static int http_options(const char *var, const char *value, void *cb)\n {\n \tif (!strcmp(\"http.sslverify\", var)) {\n@@ -232,11 +212,11 @@ static int http_options(const char *var, const char *value, void *cb)\n \n static void init_curl_http_auth(CURL *result)\n {\n-\tif (user_name) {\n+\tif (http_auth.username) {\n \t\tstruct strbuf up = STRBUF_INIT;\n-\t\tif (!user_pass)\n-\t\t\tuser_pass = xstrdup(git_getpass_with_description(\"Password\", description));\n-\t\tstrbuf_addf(&up, \"%s:%s\", user_name, user_pass);\n+\t\tcredential_fill(&http_auth);\n+\t\tstrbuf_addf(&up, \"%s:%s\",\n+\t\t\t    http_auth.username, http_auth.password);\n \t\tcurl_easy_setopt(result, CURLOPT_USERPWD,\n \t\t\t\t strbuf_detach(&up, NULL));\n \t}\n@@ -244,18 +224,14 @@ static void init_curl_http_auth(CURL *result)\n \n static int has_cert_password(void)\n {\n-\tif (ssl_cert_password != NULL)\n-\t\treturn 1;\n \tif (ssl_cert == NULL || ssl_cert_password_required != 1)\n \t\treturn 0;\n-\t/* Only prompt the user once. */\n-\tssl_cert_password_required = -1;\n-\tssl_cert_password = git_getpass_with_description(\"Certificate Password\", description);\n-\tif (ssl_cert_password != NULL) {\n-\t\tssl_cert_password = xstrdup(ssl_cert_password);\n-\t\treturn 1;\n-\t} else\n-\t\treturn 0;\n+\tif (!cert_auth.password) {\n+\t\tcert_auth.protocol = xstrdup(\"cert\");\n+\t\tcert_auth.path = xstrdup(ssl_cert);\n+\t\tcredential_fill(&cert_auth);\n+\t}\n+\treturn 1;\n }\n \n static CURL *get_curl_handle(void)\n@@ -282,7 +258,7 @@ static int has_cert_password(void)\n \tif (ssl_cert != NULL)\n \t\tcurl_easy_setopt(result, CURLOPT_SSLCERT, ssl_cert);\n \tif (has_cert_password())\n-\t\tcurl_easy_setopt(result, CURLOPT_KEYPASSWD, ssl_cert_password);\n+\t\tcurl_easy_setopt(result, CURLOPT_KEYPASSWD, cert_auth.password);\n #if LIBCURL_VERSION_NUM >= 0x070903\n \tif (ssl_key != NULL)\n \t\tcurl_easy_setopt(result, CURLOPT_SSLKEY, ssl_key);\n@@ -324,42 +300,6 @@ static int has_cert_password(void)\n \treturn result;\n }\n \n-static void http_auth_init(const char *url)\n-{\n-\tconst char *at, *colon, *cp, *slash, *host;\n-\n-\tcp = strstr(url, \"://\");\n-\tif (!cp)\n-\t\treturn;\n-\n-\t/*\n-\t * Ok, the URL looks like \"proto://something\".  Which one?\n-\t * \"proto://<user>:<pass>@<host>/...\",\n-\t * \"proto://<user>@<host>/...\", or just\n-\t * \"proto://<host>/...\"?\n-\t */\n-\tcp += 3;\n-\tat = strchr(cp, '@');\n-\tcolon = strchr(cp, ':');\n-\tslash = strchrnul(cp, '/');\n-\tif (!at || slash <= at) {\n-\t\t/* No credentials, but we may have to ask for some later */\n-\t\thost = cp;\n-\t}\n-\telse if (!colon || at <= colon) {\n-\t\t/* Only username */\n-\t\tuser_name = url_decode_mem(cp, at - cp);\n-\t\tuser_pass = NULL;\n-\t\thost = at + 1;\n-\t} else {\n-\t\tuser_name = url_decode_mem(cp, colon - cp);\n-\t\tuser_pass = url_decode_mem(colon + 1, at - (colon + 1));\n-\t\thost = at + 1;\n-\t}\n-\n-\tdescription = url_decode_mem(host, slash - host);\n-}\n-\n static void set_from_env(const char **var, const char *envname)\n {\n \tconst char *val = getenv(envname);\n@@ -432,7 +372,7 @@ void http_init(struct remote *remote, const char *url)\n \t\tcurl_ftp_no_epsv = 1;\n \n \tif (url) {\n-\t\thttp_auth_init(url);\n+\t\tcredential_from_url(&http_auth, url);\n \t\tif (!ssl_cert_password_required &&\n \t\t    getenv(\"GIT_SSL_CERT_PASSWORD_PROTECTED\") &&\n \t\t    !prefixcmp(url, \"https://\"))\n@@ -481,10 +421,10 @@ void http_cleanup(void)\n \t\tcurl_http_proxy = NULL;\n \t}\n \n-\tif (ssl_cert_password != NULL) {\n-\t\tmemset(ssl_cert_password, 0, strlen(ssl_cert_password));\n-\t\tfree(ssl_cert_password);\n-\t\tssl_cert_password = NULL;\n+\tif (cert_auth.password != NULL) {\n+\t\tmemset(cert_auth.password, 0, strlen(cert_auth.password));\n+\t\tfree(cert_auth.password);\n+\t\tcert_auth.password = NULL;\n \t}\n \tssl_cert_password_required = 0;\n }\n@@ -836,17 +776,11 @@ static int http_request(const char *url, void *result, int target, int options)\n \t\telse if (missing_target(&results))\n \t\t\tret = HTTP_MISSING_TARGET;\n \t\telse if (results.http_code == 401) {\n-\t\t\tif (user_name && user_pass) {\n+\t\t\tif (http_auth.username && http_auth.password) {\n+\t\t\t\tcredential_reject(&http_auth);\n \t\t\t\tret = HTTP_NOAUTH;\n \t\t\t} else {\n-\t\t\t\t/*\n-\t\t\t\t * git_getpass is needed here because its very likely stdin/stdout are\n-\t\t\t\t * pipes to our parent process.  So we instead need to use /dev/tty,\n-\t\t\t\t * but that is non-portable.  Using git_getpass() can at least be stubbed\n-\t\t\t\t * on other platforms with a different implementation if/when necessary.\n-\t\t\t\t */\n-\t\t\t\tif (!user_name)\n-\t\t\t\t\tuser_name = xstrdup(git_getpass_with_description(\"Username\", description));\n+\t\t\t\tcredential_fill(&http_auth);\n \t\t\t\tinit_curl_http_auth(slot->curl);\n \t\t\t\tret = HTTP_REAUTH;\n \t\t\t}\n@@ -866,6 +800,9 @@ static int http_request(const char *url, void *result, int target, int options)\n \tcurl_slist_free_all(headers);\n \tstrbuf_release(&buf);\n \n+\tif (ret == HTTP_OK)\n+\t\tcredential_approve(&http_auth);\n+\n \treturn ret;\n }\n \ndiff --git a/t/t5550-http-fetch.sh b/t/t5550-http-fetch.sh\nindex 3d6e871..398a2d2 100755\n--- a/t/t5550-http-fetch.sh\n+++ b/t/t5550-http-fetch.sh\n@@ -49,40 +49,56 @@ test_expect_success 'setup askpass helpers' '\n \tEOF\n \tchmod +x askpass &&\n \tGIT_ASKPASS=\"$PWD/askpass\" &&\n-\texport GIT_ASKPASS &&\n-\t>askpass-expect-none &&\n-\techo \"askpass: Password for '\\''$HTTPD_DEST'\\'': \" >askpass-expect-pass &&\n-\t{ echo \"askpass: Username for '\\''$HTTPD_DEST'\\'': \" &&\n-\t  cat askpass-expect-pass\n-\t} >askpass-expect-both\n-'\n+\texport GIT_ASKPASS\n+'\n+\n+expect_askpass() {\n+\tdest=$HTTPD_DEST/auth/repo.git\n+\t{\n+\t\tcase \"$1\" in\n+\t\tnone)\n+\t\t\t;;\n+\t\tpass)\n+\t\t\techo \"askpass: Password for 'http://$2@$dest': \"\n+\t\t\t;;\n+\t\tboth)\n+\t\t\techo \"askpass: Username for 'http://$dest': \"\n+\t\t\techo \"askpass: Password for 'http://$2@$dest': \"\n+\t\t\t;;\n+\t\t*)\n+\t\t\tfalse\n+\t\t\t;;\n+\t\tesac\n+\t} >askpass-expect &&\n+\ttest_cmp askpass-expect askpass-query\n+}\n \n test_expect_success 'cloning password-protected repository can fail' '\n \t>askpass-query &&\n \techo wrong >askpass-response &&\n \ttest_must_fail git clone \"$HTTPD_URL/auth/repo.git\" clone-auth-fail &&\n-\ttest_cmp askpass-expect-both askpass-query\n+\texpect_askpass both wrong\n '\n \n test_expect_success 'http auth can use user/pass in URL' '\n \t>askpass-query &&\n \techo wrong >askpass-response &&\n \tgit clone \"$HTTPD_URL_USER_PASS/auth/repo.git\" clone-auth-none &&\n-\ttest_cmp askpass-expect-none askpass-query\n+\texpect_askpass none\n '\n \n test_expect_success 'http auth can use just user in URL' '\n \t>askpass-query &&\n \techo user@host >askpass-response &&\n \tgit clone \"$HTTPD_URL_USER/auth/repo.git\" clone-auth-pass &&\n-\ttest_cmp askpass-expect-pass askpass-query\n+\texpect_askpass pass user@host\n '\n \n test_expect_success 'http auth can request both user and pass' '\n \t>askpass-query &&\n \techo user@host >askpass-response &&\n \tgit clone \"$HTTPD_URL/auth/repo.git\" clone-auth-both &&\n-\ttest_cmp askpass-expect-both askpass-query\n+\texpect_askpass both user@host\n '\n \n test_expect_success 'fetch changes via http' '\n-- \n1.7.8.rc4.4.g884ec\n"},{"id":"180350","messageId":"20111206062247.GF29233@sigill.intra.peff.net","threadId":"29093","inReplyTo":"20111206062127.GA29046@sigill.intra.peff.net","subject":"[PATCHv2 06/13] credential: apply helper config","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-12-06T06:22:47Z","receivedAt":"2011-12-06T06:22:47Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"The functionality for credential storage helpers is already\nthere; we just need to give the users a way to turn it on.\nThis patch provides a \"credential.helper\" configuration\nvariable which allows the user to provide one or more helper\nstrings.\n\nRather than simply matching credential.helper, we will also\ncompare URLs in subsection headings to the current context.\nThis means you can apply configuration to a subset of\ncredentials. For example:\n\n  [credential \"https://example.com\"]\n\thelper = foo\n\nwould match a request for \"https://example.com/foo.git\", but\nnot one for \"https://kernel.org/foo.git\".\n\nThis is overkill for the \"helper\" variable, since users are\nunlikely to want different helpers for different sites (and\nsince helpers run arbitrary code, they could do the matching\nthemselves anyway).\n\nHowever, future patches will add new config variables where\nthis extra feature will be more useful.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n credential.c           |   61 ++++++++++++++++++++++++++++++++++++++++++++++++\n credential.h           |    5 +++-\n t/t0300-credentials.sh |   42 +++++++++++++++++++++++++++++++++\n t/t5550-http-fetch.sh  |   12 +++++++++\n 4 files changed, 119 insertions(+), 1 deletions(-)\n\ndiff --git a/credential.c b/credential.c\nindex c349b9a..96be1c2 100644\n--- a/credential.c\n+++ b/credential.c\n@@ -22,6 +22,61 @@ void credential_clear(struct credential *c)\n \tcredential_init(c);\n }\n \n+int credential_match(const struct credential *want,\n+\t\t     const struct credential *have)\n+{\n+#define CHECK(x) (!want->x || (have->x && !strcmp(want->x, have->x)))\n+\treturn CHECK(protocol) &&\n+\t       CHECK(host) &&\n+\t       CHECK(path) &&\n+\t       CHECK(username);\n+#undef CHECK\n+}\n+\n+static int credential_config_callback(const char *var, const char *value,\n+\t\t\t\t      void *data)\n+{\n+\tstruct credential *c = data;\n+\tconst char *key, *dot;\n+\n+\tkey = skip_prefix(var, \"credential.\");\n+\tif (!key)\n+\t\treturn 0;\n+\n+\tif (!value)\n+\t\treturn config_error_nonbool(var);\n+\n+\tdot = strrchr(key, '.');\n+\tif (dot) {\n+\t\tstruct credential want = CREDENTIAL_INIT;\n+\t\tchar *url = xmemdupz(key, dot - key);\n+\t\tint matched;\n+\n+\t\tcredential_from_url(&want, url);\n+\t\tmatched = credential_match(&want, c);\n+\n+\t\tcredential_clear(&want);\n+\t\tfree(url);\n+\n+\t\tif (!matched)\n+\t\t\treturn 0;\n+\t\tkey = dot + 1;\n+\t}\n+\n+\tif (!strcmp(key, \"helper\"))\n+\t\tstring_list_append(&c->helpers, value);\n+\n+\treturn 0;\n+}\n+\n+static void credential_apply_config(struct credential *c)\n+{\n+\tif (c->configured)\n+\t\treturn;\n+\tgit_config(credential_config_callback, c);\n+\tc->configured = 1;\n+}\n+\n static void credential_describe(struct credential *c, struct strbuf *out)\n {\n \tif (!c->protocol)\n@@ -195,6 +250,8 @@ void credential_fill(struct credential *c)\n \tif (c->username && c->password)\n \t\treturn;\n \n+\tcredential_apply_config(c);\n+\n \tfor (i = 0; i < c->helpers.nr; i++) {\n \t\tcredential_do(c, c->helpers.items[i].string, \"get\");\n \t\tif (c->username && c->password)\n@@ -215,6 +272,8 @@ void credential_approve(struct credential *c)\n \tif (!c->username || !c->password)\n \t\treturn;\n \n+\tcredential_apply_config(c);\n+\n \tfor (i = 0; i < c->helpers.nr; i++)\n \t\tcredential_do(c, c->helpers.items[i].string, \"store\");\n \tc->approved = 1;\n@@ -224,6 +283,8 @@ void credential_reject(struct credential *c)\n {\n \tint i;\n \n+\tcredential_apply_config(c);\n+\n \tfor (i = 0; i < c->helpers.nr; i++)\n \t\tcredential_do(c, c->helpers.items[i].string, \"erase\");\n \ndiff --git a/credential.h b/credential.h\nindex 8a6d162..e504272 100644\n--- a/credential.h\n+++ b/credential.h\n@@ -5,7 +5,8 @@\n \n struct credential {\n \tstruct string_list helpers;\n-\tunsigned approved:1;\n+\tunsigned approved:1,\n+\t\t configured:1;\n \n \tchar *username;\n \tchar *password;\n@@ -25,5 +26,7 @@ struct credential {\n \n int credential_read(struct credential *, FILE *);\n void credential_from_url(struct credential *, const char *url);\n+int credential_match(const struct credential *have,\n+\t\t     const struct credential *want);\n \n #endif /* CREDENTIAL_H */\ndiff --git a/t/t0300-credentials.sh b/t/t0300-credentials.sh\nindex 81a455f..e3f61f4 100755\n--- a/t/t0300-credentials.sh\n+++ b/t/t0300-credentials.sh\n@@ -192,4 +192,46 @@ test_expect_success 'internal getpass does not ask for known username' '\n \tEOF\n '\n \n+HELPER=\"f() {\n+\t\tcat >/dev/null\n+\t\techo username=foo\n+\t\techo password=bar\n+\t}; f\"\n+test_expect_success 'respect configured credentials' '\n+\ttest_config credential.helper \"$HELPER\" &&\n+\tcheck fill <<-\\EOF\n+\t--\n+\tusername=foo\n+\tpassword=bar\n+\t--\n+\tEOF\n+'\n+\n+test_expect_success 'match configured credential' '\n+\ttest_config credential.https://example.com.helper \"$HELPER\" &&\n+\tcheck fill <<-\\EOF\n+\tprotocol=https\n+\thost=example.com\n+\tpath=repo.git\n+\t--\n+\tusername=foo\n+\tpassword=bar\n+\t--\n+\tEOF\n+'\n+\n+test_expect_success 'do not match configured credential' '\n+\ttest_config credential.https://foo.helper \"$HELPER\" &&\n+\tcheck fill <<-\\EOF\n+\tprotocol=https\n+\thost=bar\n+\t--\n+\tusername=askpass-username\n+\tpassword=askpass-password\n+\t--\n+\taskpass: Username for '\\''https://bar'\\'':\n+\taskpass: Password for '\\''https://askpass-username@bar'\\'':\n+\tEOF\n+'\n+\n test_done\ndiff --git a/t/t5550-http-fetch.sh b/t/t5550-http-fetch.sh\nindex 398a2d2..21e2f5d 100755\n--- a/t/t5550-http-fetch.sh\n+++ b/t/t5550-http-fetch.sh\n@@ -101,6 +101,18 @@ test_expect_success 'http auth can request both user and pass' '\n \texpect_askpass both user@host\n '\n \n+test_expect_success 'http auth respects credential helper config' '\n+\ttest_config_global credential.helper \"f() {\n+\t\tcat >/dev/null\n+\t\techo username=user@host\n+\t\techo password=user@host\n+\t}; f\" &&\n+\t>askpass-query &&\n+\techo wrong >askpass-response &&\n+\tgit clone \"$HTTPD_URL/auth/repo.git\" clone-auth-helper &&\n+\texpect_askpass none\n+'\n+\n test_expect_success 'fetch changes via http' '\n \techo content >>file &&\n \tgit commit -a -m two &&\n-- \n1.7.8.rc4.4.g884ec\n"},{"id":"180351","messageId":"20111206062250.GG29233@sigill.intra.peff.net","threadId":"29093","inReplyTo":"20111206062127.GA29046@sigill.intra.peff.net","subject":"[PATCHv2 07/13] credential: add credential.*.username","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-12-06T06:22:50Z","receivedAt":"2011-12-06T06:22:50Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"Credential helpers can help users avoid having to type their\nusername and password over and over. However, some users may\nnot want a helper for their password, or they may be running\na helper which caches for a short time. In this case, it is\nconvenient to provide the non-secret username portion of\ntheir credential via config.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n credential.c           |    4 ++++\n t/t0300-credentials.sh |   13 +++++++++++++\n t/t5550-http-fetch.sh  |   16 ++++++++++++++++\n 3 files changed, 33 insertions(+), 0 deletions(-)\n\ndiff --git a/credential.c b/credential.c\nindex 96be1c2..3c17ea1 100644\n--- a/credential.c\n+++ b/credential.c\n@@ -65,6 +65,10 @@ static int credential_config_callback(const char *var, const char *value,\n \n \tif (!strcmp(key, \"helper\"))\n \t\tstring_list_append(&c->helpers, value);\n+\telse if (!strcmp(key, \"username\")) {\n+\t\tif (!c->username)\n+\t\t\tc->username = xstrdup(value);\n+\t}\n \n \treturn 0;\n }\ndiff --git a/t/t0300-credentials.sh b/t/t0300-credentials.sh\nindex e3f61f4..57751a1 100755\n--- a/t/t0300-credentials.sh\n+++ b/t/t0300-credentials.sh\n@@ -234,4 +234,17 @@ test_expect_success 'do not match configured credential' '\n \tEOF\n '\n \n+test_expect_success 'pull username from config' '\n+\ttest_config credential.https://example.com.username foo &&\n+\tcheck fill <<-\\EOF\n+\tprotocol=https\n+\thost=example.com\n+\t--\n+\tusername=foo\n+\tpassword=askpass-password\n+\t--\n+\taskpass: Password for '\\''https://foo@example.com'\\'':\n+\tEOF\n+'\n+\n test_done\ndiff --git a/t/t5550-http-fetch.sh b/t/t5550-http-fetch.sh\nindex 21e2f5d..18f4d59 100755\n--- a/t/t5550-http-fetch.sh\n+++ b/t/t5550-http-fetch.sh\n@@ -113,6 +113,22 @@ test_expect_success 'http auth respects credential helper config' '\n \texpect_askpass none\n '\n \n+test_expect_success 'http auth can get username from config' '\n+\ttest_config_global \"credential.$HTTPD_URL.username\" user@host &&\n+\t>askpass-query &&\n+\techo user@host >askpass-response &&\n+\tgit clone \"$HTTPD_URL/auth/repo.git\" clone-auth-user &&\n+\texpect_askpass pass user@host\n+'\n+\n+test_expect_success 'configured username does not override URL' '\n+\ttest_config_global \"credential.$HTTPD_URL.username\" wrong &&\n+\t>askpass-query &&\n+\techo user@host >askpass-response &&\n+\tgit clone \"$HTTPD_URL_USER/auth/repo.git\" clone-auth-user2 &&\n+\texpect_askpass pass user@host\n+'\n+\n test_expect_success 'fetch changes via http' '\n \techo content >>file &&\n \tgit commit -a -m two &&\n-- \n1.7.8.rc4.4.g884ec\n"},{"id":"180352","messageId":"20111206062252.GH29233@sigill.intra.peff.net","threadId":"29093","inReplyTo":"20111206062127.GA29046@sigill.intra.peff.net","subject":"[PATCHv2 08/13] credential: make relevance of http path configurable","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-12-06T06:22:52Z","receivedAt":"2011-12-06T06:22:52Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"When parsing a URL into a credential struct, we carefully\nrecord each part of the URL, including the path on the\nremote host, and use the result as part of the credential\ncontext.\n\nThis had two practical implications:\n\n  1. Credential helpers which store a credential for later\n     access are likely to use the \"path\" portion as part of\n     the storage key. That means that a request to\n\n       https://example.com/foo.git\n\n     would not use the same credential that was stored in an\n     earlier request for:\n\n       https://example.com/bar.git\n\n  2. The prompt shown to the user includes all relevant\n     context, including the path.\n\nIn most cases, however, users will have a single password\nper host. The behavior in (1) will be inconvenient, and the\nprompt in (2) will be overly long.\n\nThis patch introduces a config option to toggle the\nrelevance of http paths. When turned on, we use the path as\nbefore. When turned off, we drop the path component from the\ncontext: helpers don't see it, and it does not appear in the\nprompt.\n\nThis is nothing you couldn't do with a clever credential\nhelper at the start of your stack, like:\n\n  [credential \"http://\"]\n\thelper = \"f() { grep -v ^path= ; }; f\"\n\thelper = your_real_helper\n\nBut doing this:\n\n  [credential]\n\tuseHttpPath = false\n\nis way easier and more readable. Furthermore, since most\nusers will want the \"off\" behavior, that is the new default.\nUsers who want it \"on\" can set the variable (either for all\ncredentials, or just for a subset using\ncredential.*.useHttpPath).\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n credential.c           |   14 ++++++++++++++\n credential.h           |    3 ++-\n t/t0300-credentials.sh |   29 +++++++++++++++++++++++++++++\n t/t5550-http-fetch.sh  |    2 +-\n 4 files changed, 46 insertions(+), 2 deletions(-)\n\ndiff --git a/credential.c b/credential.c\nindex 3c17ea1..a17eafe 100644\n--- a/credential.c\n+++ b/credential.c\n@@ -69,16 +69,30 @@ static int credential_config_callback(const char *var, const char *value,\n \t\tif (!c->username)\n \t\t\tc->username = xstrdup(value);\n \t}\n+\telse if (!strcmp(key, \"usehttppath\"))\n+\t\tc->use_http_path = git_config_bool(var, value);\n \n \treturn 0;\n }\n \n+static int proto_is_http(const char *s)\n+{\n+\tif (!s)\n+\t\treturn 0;\n+\treturn !strcmp(s, \"https\") || !strcmp(s, \"http\");\n+}\n+\n static void credential_apply_config(struct credential *c)\n {\n \tif (c->configured)\n \t\treturn;\n \tgit_config(credential_config_callback, c);\n \tc->configured = 1;\n+\n+\tif (!c->use_http_path && proto_is_http(c->protocol)) {\n+\t\tfree(c->path);\n+\t\tc->path = NULL;\n+\t}\n }\n \n static void credential_describe(struct credential *c, struct strbuf *out)\ndiff --git a/credential.h b/credential.h\nindex e504272..96ea41b 100644\n--- a/credential.h\n+++ b/credential.h\n@@ -6,7 +6,8 @@\n struct credential {\n \tstruct string_list helpers;\n \tunsigned approved:1,\n-\t\t configured:1;\n+\t\t configured:1,\n+\t\t use_http_path:1;\n \n \tchar *username;\n \tchar *password;\ndiff --git a/t/t0300-credentials.sh b/t/t0300-credentials.sh\nindex 57751a1..89a8531 100755\n--- a/t/t0300-credentials.sh\n+++ b/t/t0300-credentials.sh\n@@ -247,4 +247,33 @@ test_expect_success 'pull username from config' '\n \tEOF\n '\n \n+test_expect_success 'http paths can be part of context' '\n+\tcheck fill \"verbatim foo bar\" <<-\\EOF &&\n+\tprotocol=https\n+\thost=example.com\n+\tpath=foo.git\n+\t--\n+\tusername=foo\n+\tpassword=bar\n+\t--\n+\tverbatim: get\n+\tverbatim: protocol=https\n+\tverbatim: host=example.com\n+\tEOF\n+\ttest_config credential.https://example.com.useHttpPath true &&\n+\tcheck fill \"verbatim foo bar\" <<-\\EOF\n+\tprotocol=https\n+\thost=example.com\n+\tpath=foo.git\n+\t--\n+\tusername=foo\n+\tpassword=bar\n+\t--\n+\tverbatim: get\n+\tverbatim: protocol=https\n+\tverbatim: host=example.com\n+\tverbatim: path=foo.git\n+\tEOF\n+'\n+\n test_done\ndiff --git a/t/t5550-http-fetch.sh b/t/t5550-http-fetch.sh\nindex 18f4d59..dd073d1 100755\n--- a/t/t5550-http-fetch.sh\n+++ b/t/t5550-http-fetch.sh\n@@ -53,7 +53,7 @@ test_expect_success 'setup askpass helpers' '\n '\n \n expect_askpass() {\n-\tdest=$HTTPD_DEST/auth/repo.git\n+\tdest=$HTTPD_DEST\n \t{\n \t\tcase \"$1\" in\n \t\tnone)\n-- \n1.7.8.rc4.4.g884ec\n"},{"id":"180355","messageId":"20111206062255.GI29233@sigill.intra.peff.net","threadId":"29093","inReplyTo":"20111206062127.GA29046@sigill.intra.peff.net","subject":"[PATCHv2 09/13] docs: end-user documentation for the credential subsystem","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-12-06T06:22:55Z","receivedAt":"2011-12-06T06:22:55Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"The credential API and helper format is already defined in\ntechnical/api-credentials.txt.  This presents the end-user\nview.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n Documentation/Makefile           |    1 +\n Documentation/config.txt         |   23 +++++\n Documentation/gitcredentials.txt |  171 ++++++++++++++++++++++++++++++++++++++\n 3 files changed, 195 insertions(+), 0 deletions(-)\n create mode 100644 Documentation/gitcredentials.txt\n\ndiff --git a/Documentation/Makefile b/Documentation/Makefile\nindex 304b31e..116f175 100644\n--- a/Documentation/Makefile\n+++ b/Documentation/Makefile\n@@ -7,6 +7,7 @@ MAN5_TXT=gitattributes.txt gitignore.txt gitmodules.txt githooks.txt \\\n MAN7_TXT=gitcli.txt gittutorial.txt gittutorial-2.txt \\\n \tgitcvs-migration.txt gitcore-tutorial.txt gitglossary.txt \\\n \tgitdiffcore.txt gitnamespaces.txt gitrevisions.txt gitworkflows.txt\n+MAN7_TXT += gitcredentials.txt\n \n MAN_TXT = $(MAN1_TXT) $(MAN5_TXT) $(MAN7_TXT)\n MAN_XML=$(patsubst %.txt,%.xml,$(MAN_TXT))\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 5a841da..36bcdf2 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -832,6 +832,29 @@ commit.template::\n \t\"{tilde}/\" is expanded to the value of `$HOME` and \"{tilde}user/\" to the\n \tspecified user's home directory.\n \n+credential.helper::\n+\tSpecify an external helper to be called when a username or\n+\tpassword credential is needed; the helper may consult external\n+\tstorage to avoid prompting the user for the credentials. See\n+\tlinkgit:gitcredentials[7] for details.\n+\n+credential.useHttpPath::\n+\tWhen acquiring credentials, consider the \"path\" component of an http\n+\tor https URL to be important. Defaults to false. See\n+\tlinkgit:gitcredentials[7] for more information.\n+\n+credential.username::\n+\tIf no username is set for a network authentication, use this username\n+\tby default. See credential.<context>.* below, and\n+\tlinkgit:gitcredentials[7].\n+\n+credential.<url>.*::\n+\tAny of the credential.* options above can be applied selectively to\n+\tsome credentials. For example \"credential.https://example.com.username\"\n+\twould set the default username only for https connections to\n+\texample.com. See linkgit:gitcredentials[7] for details on how URLs are\n+\tmatched.\n+\n include::diff-config.txt[]\n \n difftool.<tool>.path::\ndiff --git a/Documentation/gitcredentials.txt b/Documentation/gitcredentials.txt\nnew file mode 100644\nindex 0000000..07f6596\n--- /dev/null\n+++ b/Documentation/gitcredentials.txt\n@@ -0,0 +1,171 @@\n+gitcredentials(7)\n+=================\n+\n+NAME\n+----\n+gitcredentials - providing usernames and passwords to git\n+\n+SYNOPSIS\n+--------\n+------------------\n+git config credential.https://example.com.username myusername\n+git config credential.helper \"$helper $options\"\n+------------------\n+\n+DESCRIPTION\n+-----------\n+\n+Git will sometimes need credentials from the user in order to perform\n+operations; for example, it may need to ask for a username and password\n+in order to access a remote repository over HTTP. This manual describes\n+the mechanisms git uses to request these credentials, as well as some\n+features to avoid inputting these credentials repeatedly.\n+\n+REQUESTING CREDENTIALS\n+----------------------\n+\n+Without any credential helpers defined, git will try the following\n+strategies to ask the user for usernames and passwords:\n+\n+1. If the `GIT_ASKPASS` environment variable is set, the program\n+   specified by the variable is invoked. A suitable prompt is provided\n+   to the program on the command line, and the user's input is read\n+   from its standard output.\n+\n+2. Otherwise, if the `core.askpass` configuration variable is set, its\n+   value is used as above.\n+\n+3. Otherwise, if the `SSH_ASKPASS` environment variable is set, its\n+   value is used as above.\n+\n+4. Otherwise, the user is prompted on the terminal.\n+\n+AVOIDING REPETITION\n+-------------------\n+\n+It can be cumbersome to input the same credentials over and over.  Git\n+provides two methods to reduce this annoyance:\n+\n+1. Static configuration of usernames for a given authentication context.\n+\n+2. Credential helpers to cache or store passwords, or to interact with\n+   a system password wallet or keychain.\n+\n+The first is simple and appropriate if you do not have secure storage available\n+for a password. It is generally configured by adding this to your config:\n+\n+---------------------------------------\n+[credential \"https://example.com\"]\n+\tusername = me\n+---------------------------------------\n+\n+Credential helpers, on the other hand, are external programs from which git can\n+request both usernames and passwords; they typically interface with secure\n+storage provided by the OS or other programs.\n+\n+To use a helper, you must first select one to use.  Git does not yet\n+include any credential helpers, but you may have third-party helpers\n+installed; search for `credential-*` in the output of `git help -a`, and\n+consult the documentation of individual helpers.  Once you have selected\n+a helper, you can tell git to use it by putting its name into the\n+credential.helper variable.\n+\n+1. Find a helper.\n++\n+-------------------------------------------\n+$ git help -a | grep credential-\n+credential-foo\n+-------------------------------------------\n+\n+2. Read its description.\n++\n+-------------------------------------------\n+$ git help credential-foo\n+-------------------------------------------\n+\n+3. Tell git to use it.\n++\n+-------------------------------------------\n+$ git config --global credential.helper foo\n+-------------------------------------------\n+\n+If there are multiple instances of the `credential.helper` configuration\n+variable, each helper will be tried in turn, and may provide a username,\n+password, or nothing. Once git has acquired both a username and a\n+password, no more helpers will be tried.\n+\n+\n+CREDENTIAL CONTEXTS\n+-------------------\n+\n+Git considers each credential to have a context defined by a URL. This context\n+is used to look up context-specific configuration, and is passed to any\n+helpers, which may use it as an index into secure storage.\n+\n+For instance, imagine we are accessing `https://example.com/foo.git`. When git\n+looks into a config file to see if a section matches this context, it will\n+consider the two a match if the context is a more-specific subset of the\n+pattern in the config file. For example, if you have this in your config file:\n+\n+--------------------------------------\n+[credential \"https://example.com\"]\n+\tusername = foo\n+--------------------------------------\n+\n+then we will match: both protocols are the same, both hosts are the same, and\n+the \"pattern\" URL does not care about the path component at all. However, this\n+context would not match:\n+\n+--------------------------------------\n+[credential \"https://kernel.org\"]\n+\tusername = foo\n+--------------------------------------\n+\n+because the hostnames differ. Nor would it match `foo.example.com`; git\n+compares hostnames exactly, without considering whether two hosts are part of\n+the same domain. Likewise, a config entry for `http://example.com` would not\n+match: git compares the protocols exactly.\n+\n+\n+CONFIGURATION OPTIONS\n+---------------------\n+\n+Options for a credential context can be configured either in\n+`credential.\\*` (which applies to all credentials), or\n+`credential.<url>.\\*`, where <url> matches the context as described\n+above.\n+\n+The following options are available in either location:\n+\n+helper::\n+\n+\tThe name of an external credential helper, and any associated options.\n+\tIf the helper name is not an absolute path, then the string `git\n+\tcredential-` is prepended. The resulting string is executed by the\n+\tshell (so, for example, setting this to `foo --option=bar` will execute\n+\t`git credential-foo --option=bar` via the shell. See the manual of\n+\tspecific helpers for examples of their use.\n+\n+username::\n+\n+\tA default username, if one is not provided in the URL.\n+\n+useHttpPath::\n+\n+\tBy default, git does not consider the \"path\" component of an http URL\n+\tto be worth matching via external helpers. This means that a credential\n+\tstored for `https://example.com/foo.git` will also be used for\n+\t`https://example.com/bar.git`. If you do want to distinguish these\n+\tcases, set this option to `true`.\n+\n+\n+CUSTOM HELPERS\n+--------------\n+\n+You can write your own custom helpers to interface with any system in\n+which you keep credentials. See the documentation for git's\n+link:technical/api-credentials.html[credentials API] for details.\n+\n+GIT\n+---\n+Part of the linkgit:git[1] suite\n-- \n1.7.8.rc4.4.g884ec\n"},{"id":"180353","messageId":"20111206062258.GJ29233@sigill.intra.peff.net","threadId":"29093","inReplyTo":"20111206062127.GA29046@sigill.intra.peff.net","subject":"[PATCHv2 10/13] credentials: add \"cache\" helper","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-12-06T06:22:58Z","receivedAt":"2011-12-06T06:22:58Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"If you access repositories over smart-http using http\nauthentication, then it can be annoying to have git ask you\nfor your password repeatedly. We cache credentials in\nmemory, of course, but git is composed of many small\nprograms. Having to input your password for each one can be\nfrustrating.\n\nThis patch introduces a credential helper that will cache\npasswords in memory for a short period of time.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n .gitignore                                     |    2 +\n Documentation/git-credential-cache--daemon.txt |   26 +++\n Documentation/git-credential-cache.txt         |   77 +++++++\n Documentation/gitcredentials.txt               |   17 +-\n Makefile                                       |    3 +\n credential-cache--daemon.c                     |  269 ++++++++++++++++++++++++\n credential-cache.c                             |  120 +++++++++++\n git-compat-util.h                              |    1 +\n t/lib-credential.sh                            |  220 +++++++++++++++++++\n t/t0301-credential-cache.sh                    |   18 ++\n unix-socket.c                                  |   56 +++++\n unix-socket.h                                  |    7 +\n 12 files changed, 811 insertions(+), 5 deletions(-)\n create mode 100644 Documentation/git-credential-cache--daemon.txt\n create mode 100644 Documentation/git-credential-cache.txt\n create mode 100644 credential-cache--daemon.c\n create mode 100644 credential-cache.c\n create mode 100755 t/t0301-credential-cache.sh\n create mode 100644 unix-socket.c\n create mode 100644 unix-socket.h\n\ndiff --git a/.gitignore b/.gitignore\nindex 7d2fefc..a6b0bd4 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -30,6 +30,8 @@\n /git-commit-tree\n /git-config\n /git-count-objects\n+/git-credential-cache\n+/git-credential-cache--daemon\n /git-cvsexportcommit\n /git-cvsimport\n /git-cvsserver\ndiff --git a/Documentation/git-credential-cache--daemon.txt b/Documentation/git-credential-cache--daemon.txt\nnew file mode 100644\nindex 0000000..11edc5a\n--- /dev/null\n+++ b/Documentation/git-credential-cache--daemon.txt\n@@ -0,0 +1,26 @@\n+git-credential-cache--daemon(1)\n+===============================\n+\n+NAME\n+----\n+git-credential-cache--daemon - temporarily store user credentials in memory\n+\n+SYNOPSIS\n+--------\n+[verse]\n+git credential-cache--daemon <socket>\n+\n+DESCRIPTION\n+-----------\n+\n+NOTE: You probably don't want to invoke this command yourself; it is\n+started automatically when you use linkgit:git-credential-cache[1].\n+\n+This command listens on the Unix domain socket specified by `<socket>`\n+for `git-credential-cache` clients. Clients may store and retrieve\n+credentials. Each credential is held for a timeout specified by the\n+client; once no credentials are held, the daemon exits.\n+\n+GIT\n+---\n+Part of the linkgit:git[1] suite\ndiff --git a/Documentation/git-credential-cache.txt b/Documentation/git-credential-cache.txt\nnew file mode 100644\nindex 0000000..f3d09c5\n--- /dev/null\n+++ b/Documentation/git-credential-cache.txt\n@@ -0,0 +1,77 @@\n+git-credential-cache(1)\n+=======================\n+\n+NAME\n+----\n+git-credential-cache - helper to temporarily store passwords in memory\n+\n+SYNOPSIS\n+--------\n+-----------------------------\n+git config credential.helper 'cache [options]'\n+-----------------------------\n+\n+DESCRIPTION\n+-----------\n+\n+This command caches credentials in memory for use by future git\n+programs. The stored credentials never touch the disk, and are forgotten\n+after a configurable timeout.  The cache is accessible over a Unix\n+domain socket, restricted to the current user by filesystem permissions.\n+\n+You probably don't want to invoke this command directly; it is meant to\n+be used as a credential helper by other parts of git. See\n+linkgit:gitcredentials[7] or `EXAMPLES` below.\n+\n+OPTIONS\n+-------\n+\n+--timeout <seconds>::\n+\n+\tNumber of seconds to cache credentials (default: 900).\n+\n+--socket <path>::\n+\n+\tUse `<path>` to contact a running cache daemon (or start a new\n+\tcache daemon if one is not started). Defaults to\n+\t`~/.git-credential-cache/socket`. If your home directory is on a\n+\tnetwork-mounted filesystem, you may need to change this to a\n+\tlocal filesystem.\n+\n+CONTROLLING THE DAEMON\n+----------------------\n+\n+If you would like the daemon to exit early, forgetting all cached\n+credentials before their timeout, you can issue an `exit` action:\n+\n+--------------------------------------\n+git credential-cache exit\n+--------------------------------------\n+\n+EXAMPLES\n+--------\n+\n+The point of this helper is to reduce the number of times you must type\n+your username or password. For example:\n+\n+------------------------------------\n+$ git config credential.helper cache\n+$ git push http://example.com/repo.git\n+Username: <type your username>\n+Password: <type your password>\n+\n+[work for 5 more minutes]\n+$ git push http://example.com/repo.git\n+[your credentials are used automatically]\n+------------------------------------\n+\n+You can provide options via the credential.helper configuration\n+variable (this example drops the cache time to 5 minutes):\n+\n+-------------------------------------------------------\n+$ git config credential.helper 'cache --timeout=300'\n+-------------------------------------------------------\n+\n+GIT\n+---\n+Part of the linkgit:git[1] suite\ndiff --git a/Documentation/gitcredentials.txt b/Documentation/gitcredentials.txt\nindex 07f6596..4e3f860 100644\n--- a/Documentation/gitcredentials.txt\n+++ b/Documentation/gitcredentials.txt\n@@ -63,11 +63,18 @@ Credential helpers, on the other hand, are external programs from which git can\n request both usernames and passwords; they typically interface with secure\n storage provided by the OS or other programs.\n \n-To use a helper, you must first select one to use.  Git does not yet\n-include any credential helpers, but you may have third-party helpers\n-installed; search for `credential-*` in the output of `git help -a`, and\n-consult the documentation of individual helpers.  Once you have selected\n-a helper, you can tell git to use it by putting its name into the\n+To use a helper, you must first select one to use. Git currently\n+includes the following helpers:\n+\n+cache::\n+\n+\tCache credentials in memory for a short period of time. See\n+\tlinkgit:git-credential-cache[1] for details.\n+\n+You may also have third-party helpers installed; search for\n+`credential-*` in the output of `git help -a`, and consult the\n+documentation of individual helpers.  Once you have selected a helper,\n+you can tell git to use it by putting its name into the\n credential.helper variable.\n \n 1. Find a helper.\ndiff --git a/Makefile b/Makefile\nindex 5ca363b..5d41c29 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -427,6 +427,8 @@ PROGRAM_OBJS += show-index.o\n PROGRAM_OBJS += upload-pack.o\n PROGRAM_OBJS += http-backend.o\n PROGRAM_OBJS += sh-i18n--envsubst.o\n+PROGRAM_OBJS += credential-cache.o\n+PROGRAM_OBJS += credential-cache--daemon.o\n \n PROGRAMS += $(patsubst %.o,git-%$X,$(PROGRAM_OBJS))\n \n@@ -699,6 +701,7 @@ LIB_OBJS += transport-helper.o\n LIB_OBJS += tree-diff.o\n LIB_OBJS += tree.o\n LIB_OBJS += tree-walk.o\n+LIB_OBJS += unix-socket.o\n LIB_OBJS += unpack-trees.o\n LIB_OBJS += url.o\n LIB_OBJS += usage.o\ndiff --git a/credential-cache--daemon.c b/credential-cache--daemon.c\nnew file mode 100644\nindex 0000000..390f194\n--- /dev/null\n+++ b/credential-cache--daemon.c\n@@ -0,0 +1,269 @@\n+#include \"cache.h\"\n+#include \"credential.h\"\n+#include \"unix-socket.h\"\n+#include \"sigchain.h\"\n+\n+static const char *socket_path;\n+\n+static void cleanup_socket(void)\n+{\n+\tif (socket_path)\n+\t\tunlink(socket_path);\n+}\n+\n+static void cleanup_socket_on_signal(int sig)\n+{\n+\tcleanup_socket();\n+\tsigchain_pop(sig);\n+\traise(sig);\n+}\n+\n+struct credential_cache_entry {\n+\tstruct credential item;\n+\tunsigned long expiration;\n+};\n+static struct credential_cache_entry *entries;\n+static int entries_nr;\n+static int entries_alloc;\n+\n+static void cache_credential(struct credential *c, int timeout)\n+{\n+\tstruct credential_cache_entry *e;\n+\n+\tALLOC_GROW(entries, entries_nr + 1, entries_alloc);\n+\te = &entries[entries_nr++];\n+\n+\t/* take ownership of pointers */\n+\tmemcpy(&e->item, c, sizeof(*c));\n+\tmemset(c, 0, sizeof(*c));\n+\te->expiration = time(NULL) + timeout;\n+}\n+\n+static struct credential_cache_entry *lookup_credential(const struct credential *c)\n+{\n+\tint i;\n+\tfor (i = 0; i < entries_nr; i++) {\n+\t\tstruct credential *e = &entries[i].item;\n+\t\tif (credential_match(c, e))\n+\t\t\treturn &entries[i];\n+\t}\n+\treturn NULL;\n+}\n+\n+static void remove_credential(const struct credential *c)\n+{\n+\tstruct credential_cache_entry *e;\n+\n+\te = lookup_credential(c);\n+\tif (e)\n+\t\te->expiration = 0;\n+}\n+\n+static int check_expirations(void)\n+{\n+\tstatic unsigned long wait_for_entry_until;\n+\tint i = 0;\n+\tunsigned long now = time(NULL);\n+\tunsigned long next = (unsigned long)-1;\n+\n+\t/*\n+\t * Initially give the client 30 seconds to actually contact us\n+\t * and store a credential before we decide there's no point in\n+\t * keeping the daemon around.\n+\t */\n+\tif (!wait_for_entry_until)\n+\t\twait_for_entry_until = now + 30;\n+\n+\twhile (i < entries_nr) {\n+\t\tif (entries[i].expiration <= now) {\n+\t\t\tentries_nr--;\n+\t\t\tcredential_clear(&entries[i].item);\n+\t\t\tif (i != entries_nr)\n+\t\t\t\tmemcpy(&entries[i], &entries[entries_nr], sizeof(*entries));\n+\t\t\t/*\n+\t\t\t * Stick around 30 seconds in case a new credential\n+\t\t\t * shows up (e.g., because we just removed a failed\n+\t\t\t * one, and we will soon get the correct one).\n+\t\t\t */\n+\t\t\twait_for_entry_until = now + 30;\n+\t\t}\n+\t\telse {\n+\t\t\tif (entries[i].expiration < next)\n+\t\t\t\tnext = entries[i].expiration;\n+\t\t\ti++;\n+\t\t}\n+\t}\n+\n+\tif (!entries_nr) {\n+\t\tif (wait_for_entry_until <= now)\n+\t\t\treturn 0;\n+\t\tnext = wait_for_entry_until;\n+\t}\n+\n+\treturn next - now;\n+}\n+\n+static int read_request(FILE *fh, struct credential *c,\n+\t\t\tstruct strbuf *action, int *timeout) {\n+\tstatic struct strbuf item = STRBUF_INIT;\n+\tconst char *p;\n+\n+\tstrbuf_getline(&item, fh, '\\n');\n+\tp = skip_prefix(item.buf, \"action=\");\n+\tif (!p)\n+\t\treturn error(\"client sent bogus action line: %s\", item.buf);\n+\tstrbuf_addstr(action, p);\n+\n+\tstrbuf_getline(&item, fh, '\\n');\n+\tp = skip_prefix(item.buf, \"timeout=\");\n+\tif (!p)\n+\t\treturn error(\"client sent bogus timeout line: %s\", item.buf);\n+\t*timeout = atoi(p);\n+\n+\tif (credential_read(c, fh) < 0)\n+\t\treturn -1;\n+\treturn 0;\n+}\n+\n+static void serve_one_client(FILE *in, FILE *out)\n+{\n+\tstruct credential c = CREDENTIAL_INIT;\n+\tstruct strbuf action = STRBUF_INIT;\n+\tint timeout = -1;\n+\n+\tif (read_request(in, &c, &action, &timeout) < 0)\n+\t\t/* ignore error */ ;\n+\telse if (!strcmp(action.buf, \"get\")) {\n+\t\tstruct credential_cache_entry *e = lookup_credential(&c);\n+\t\tif (e) {\n+\t\t\tfprintf(out, \"username=%s\\n\", e->item.username);\n+\t\t\tfprintf(out, \"password=%s\\n\", e->item.password);\n+\t\t}\n+\t}\n+\telse if (!strcmp(action.buf, \"exit\"))\n+\t\texit(0);\n+\telse if (!strcmp(action.buf, \"erase\"))\n+\t\tremove_credential(&c);\n+\telse if (!strcmp(action.buf, \"store\")) {\n+\t\tif (timeout < 0)\n+\t\t\twarning(\"cache client didn't specify a timeout\");\n+\t\telse if (!c.username || !c.password)\n+\t\t\twarning(\"cache client gave us a partial credential\");\n+\t\telse {\n+\t\t\tremove_credential(&c);\n+\t\t\tcache_credential(&c, timeout);\n+\t\t}\n+\t}\n+\telse\n+\t\twarning(\"cache client sent unknown action: %s\", action.buf);\n+\n+\tcredential_clear(&c);\n+\tstrbuf_release(&action);\n+}\n+\n+static int serve_cache_loop(int fd)\n+{\n+\tstruct pollfd pfd;\n+\tunsigned long wakeup;\n+\n+\twakeup = check_expirations();\n+\tif (!wakeup)\n+\t\treturn 0;\n+\n+\tpfd.fd = fd;\n+\tpfd.events = POLLIN;\n+\tif (poll(&pfd, 1, 1000 * wakeup) < 0) {\n+\t\tif (errno != EINTR)\n+\t\t\tdie_errno(\"poll failed\");\n+\t\treturn 1;\n+\t}\n+\n+\tif (pfd.revents & POLLIN) {\n+\t\tint client, client2;\n+\t\tFILE *in, *out;\n+\n+\t\tclient = accept(fd, NULL, NULL);\n+\t\tif (client < 0) {\n+\t\t\twarning(\"accept failed: %s\", strerror(errno));\n+\t\t\treturn 1;\n+\t\t}\n+\t\tclient2 = dup(client);\n+\t\tif (client2 < 0) {\n+\t\t\twarning(\"dup failed: %s\", strerror(errno));\n+\t\t\tclose(client);\n+\t\t\treturn 1;\n+\t\t}\n+\n+\t\tin = xfdopen(client, \"r\");\n+\t\tout = xfdopen(client2, \"w\");\n+\t\tserve_one_client(in, out);\n+\t\tfclose(in);\n+\t\tfclose(out);\n+\t}\n+\treturn 1;\n+}\n+\n+static void serve_cache(const char *socket_path)\n+{\n+\tint fd;\n+\n+\tfd = unix_stream_listen(socket_path);\n+\tif (fd < 0)\n+\t\tdie_errno(\"unable to bind to '%s'\", socket_path);\n+\n+\tprintf(\"ok\\n\");\n+\tfclose(stdout);\n+\n+\twhile (serve_cache_loop(fd))\n+\t\t; /* nothing */\n+\n+\tclose(fd);\n+\tunlink(socket_path);\n+}\n+\n+static const char permissions_advice[] =\n+\"The permissions on your socket directory are too loose; other\\n\"\n+\"users may be able to read your cached credentials. Consider running:\\n\"\n+\"\\n\"\n+\"\tchmod 0700 %s\";\n+static void check_socket_directory(const char *path)\n+{\n+\tstruct stat st;\n+\tchar *path_copy = xstrdup(path);\n+\tchar *dir = dirname(path_copy);\n+\n+\tif (!stat(dir, &st)) {\n+\t\tif (st.st_mode & 077)\n+\t\t\tdie(permissions_advice, dir);\n+\t\tfree(path_copy);\n+\t\treturn;\n+\t}\n+\n+\t/*\n+\t * We must be sure to create the directory with the correct mode,\n+\t * not just chmod it after the fact; otherwise, there is a race\n+\t * condition in which somebody can chdir to it, sleep, then try to open\n+\t * our protected socket.\n+\t */\n+\tif (safe_create_leading_directories_const(dir) < 0)\n+\t\tdie_errno(\"unable to create directories for '%s'\", dir);\n+\tif (mkdir(dir, 0700) < 0)\n+\t\tdie_errno(\"unable to mkdir '%s'\", dir);\n+\tfree(path_copy);\n+}\n+\n+int main(int argc, const char **argv)\n+{\n+\tsocket_path = argv[1];\n+\n+\tif (!socket_path)\n+\t\tdie(\"usage: git-credential-cache--daemon <socket_path>\");\n+\tcheck_socket_directory(socket_path);\n+\n+\tatexit(cleanup_socket);\n+\tsigchain_push_common(cleanup_socket_on_signal);\n+\n+\tserve_cache(socket_path);\n+\n+\treturn 0;\n+}\ndiff --git a/credential-cache.c b/credential-cache.c\nnew file mode 100644\nindex 0000000..dc98372\n--- /dev/null\n+++ b/credential-cache.c\n@@ -0,0 +1,120 @@\n+#include \"cache.h\"\n+#include \"credential.h\"\n+#include \"string-list.h\"\n+#include \"parse-options.h\"\n+#include \"unix-socket.h\"\n+#include \"run-command.h\"\n+\n+#define FLAG_SPAWN 0x1\n+#define FLAG_RELAY 0x2\n+\n+static int send_request(const char *socket, const struct strbuf *out)\n+{\n+\tint got_data = 0;\n+\tint fd = unix_stream_connect(socket);\n+\n+\tif (fd < 0)\n+\t\treturn -1;\n+\n+\tif (write_in_full(fd, out->buf, out->len) < 0)\n+\t\tdie_errno(\"unable to write to cache daemon\");\n+\tshutdown(fd, SHUT_WR);\n+\n+\twhile (1) {\n+\t\tchar in[1024];\n+\t\tint r;\n+\n+\t\tr = read_in_full(fd, in, sizeof(in));\n+\t\tif (r == 0)\n+\t\t\tbreak;\n+\t\tif (r < 0)\n+\t\t\tdie_errno(\"read error from cache daemon\");\n+\t\twrite_or_die(1, in, r);\n+\t\tgot_data = 1;\n+\t}\n+\treturn got_data;\n+}\n+\n+static void spawn_daemon(const char *socket)\n+{\n+\tstruct child_process daemon;\n+\tconst char *argv[] = { NULL, NULL, NULL };\n+\tchar buf[128];\n+\tint r;\n+\n+\tmemset(&daemon, 0, sizeof(daemon));\n+\targv[0] = \"git-credential-cache--daemon\";\n+\targv[1] = socket;\n+\tdaemon.argv = argv;\n+\tdaemon.no_stdin = 1;\n+\tdaemon.out = -1;\n+\n+\tif (start_command(&daemon))\n+\t\tdie_errno(\"unable to start cache daemon\");\n+\tr = read_in_full(daemon.out, buf, sizeof(buf));\n+\tif (r < 0)\n+\t\tdie_errno(\"unable to read result code from cache daemon\");\n+\tif (r != 3 || memcmp(buf, \"ok\\n\", 3))\n+\t\tdie(\"cache daemon did not start: %.*s\", r, buf);\n+\tclose(daemon.out);\n+}\n+\n+static void do_cache(const char *socket, const char *action, int timeout,\n+\t\t     int flags)\n+{\n+\tstruct strbuf buf = STRBUF_INIT;\n+\n+\tstrbuf_addf(&buf, \"action=%s\\n\", action);\n+\tstrbuf_addf(&buf, \"timeout=%d\\n\", timeout);\n+\tif (flags & FLAG_RELAY) {\n+\t\tif (strbuf_read(&buf, 0, 0) < 0)\n+\t\t\tdie_errno(\"unable to relay credential\");\n+\t}\n+\n+\tif (!send_request(socket, &buf))\n+\t\treturn;\n+\tif (flags & FLAG_SPAWN) {\n+\t\tspawn_daemon(socket);\n+\t\tsend_request(socket, &buf);\n+\t}\n+\tstrbuf_release(&buf);\n+}\n+\n+int main(int argc, const char **argv)\n+{\n+\tchar *socket_path = NULL;\n+\tint timeout = 900;\n+\tconst char *op;\n+\tconst char * const usage[] = {\n+\t\t\"git credential-cache [options] <action>\",\n+\t\tNULL\n+\t};\n+\tstruct option options[] = {\n+\t\tOPT_INTEGER(0, \"timeout\", &timeout,\n+\t\t\t    \"number of seconds to cache credentials\"),\n+\t\tOPT_STRING(0, \"socket\", &socket_path, \"path\",\n+\t\t\t   \"path of cache-daemon socket\"),\n+\t\tOPT_END()\n+\t};\n+\n+\targc = parse_options(argc, argv, NULL, options, usage, 0);\n+\tif (!argc)\n+\t\tusage_with_options(usage, options);\n+\top = argv[0];\n+\n+\tif (!socket_path)\n+\t\tsocket_path = expand_user_path(\"~/.git-credential-cache/socket\");\n+\tif (!socket_path)\n+\t\tdie(\"unable to find a suitable socket path; use --socket\");\n+\n+\tif (!strcmp(op, \"exit\"))\n+\t\tdo_cache(socket_path, op, timeout, 0);\n+\telse if (!strcmp(op, \"get\") || !strcmp(op, \"erase\"))\n+\t\tdo_cache(socket_path, op, timeout, FLAG_RELAY);\n+\telse if (!strcmp(op, \"store\"))\n+\t\tdo_cache(socket_path, op, timeout, FLAG_RELAY|FLAG_SPAWN);\n+\telse\n+\t\t; /* ignore unknown operation */\n+\n+\treturn 0;\n+}\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 8b4dd5c..5c238bd 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -130,6 +130,7 @@\n #include <arpa/inet.h>\n #include <netdb.h>\n #include <pwd.h>\n+#include <sys/un.h>\n #ifndef NO_INTTYPES_H\n #include <inttypes.h>\n #else\ndiff --git a/t/lib-credential.sh b/t/lib-credential.sh\nindex 54ae1f4..fc34447 100755\n--- a/t/lib-credential.sh\n+++ b/t/lib-credential.sh\n@@ -21,6 +21,226 @@ read_chunk() {\n \tdone\n }\n \n+# Clear any residual data from previous tests. We only\n+# need this when testing third-party helpers which read and\n+# write outside of our trash-directory sandbox.\n+#\n+# Don't bother checking for success here, as it is\n+# outside the scope of tests and represents a best effort to\n+# clean up after ourselves.\n+helper_test_clean() {\n+\treject $1 https example.com store-user\n+\treject $1 https example.com user1\n+\treject $1 https example.com user2\n+\treject $1 ftp other.tld user\n+\treject $1 https timeout.tld user\n+}\n+\n+reject() {\n+\t(\n+\t\techo protocol=$2\n+\t\techo host=$3\n+\t\techo username=$4\n+\t) | test-credential reject $1\n+}\n+\n+helper_test() {\n+\tHELPER=$1\n+\n+\ttest_expect_success \"helper ($HELPER) has no existing data\" '\n+\t\tcheck fill $HELPER <<-\\EOF\n+\t\tprotocol=https\n+\t\thost=example.com\n+\t\t--\n+\t\tusername=askpass-username\n+\t\tpassword=askpass-password\n+\t\t--\n+\t\taskpass: Username for '\\''https://example.com'\\'':\n+\t\taskpass: Password for '\\''https://askpass-username@example.com'\\'':\n+\t\tEOF\n+\t'\n+\n+\ttest_expect_success \"helper ($HELPER) stores password\" '\n+\t\tcheck approve $HELPER <<-\\EOF\n+\t\tprotocol=https\n+\t\thost=example.com\n+\t\tusername=store-user\n+\t\tpassword=store-pass\n+\t\tEOF\n+\t'\n+\n+\ttest_expect_success \"helper ($HELPER) can retrieve password\" '\n+\t\tcheck fill $HELPER <<-\\EOF\n+\t\tprotocol=https\n+\t\thost=example.com\n+\t\t--\n+\t\tusername=store-user\n+\t\tpassword=store-pass\n+\t\t--\n+\t\tEOF\n+\t'\n+\n+\ttest_expect_success \"helper ($HELPER) requires matching protocol\" '\n+\t\tcheck fill $HELPER <<-\\EOF\n+\t\tprotocol=http\n+\t\thost=example.com\n+\t\t--\n+\t\tusername=askpass-username\n+\t\tpassword=askpass-password\n+\t\t--\n+\t\taskpass: Username for '\\''http://example.com'\\'':\n+\t\taskpass: Password for '\\''http://askpass-username@example.com'\\'':\n+\t\tEOF\n+\t'\n+\n+\ttest_expect_success \"helper ($HELPER) requires matching host\" '\n+\t\tcheck fill $HELPER <<-\\EOF\n+\t\tprotocol=https\n+\t\thost=other.tld\n+\t\t--\n+\t\tusername=askpass-username\n+\t\tpassword=askpass-password\n+\t\t--\n+\t\taskpass: Username for '\\''https://other.tld'\\'':\n+\t\taskpass: Password for '\\''https://askpass-username@other.tld'\\'':\n+\t\tEOF\n+\t'\n+\n+\ttest_expect_success \"helper ($HELPER) requires matching username\" '\n+\t\tcheck fill $HELPER <<-\\EOF\n+\t\tprotocol=https\n+\t\thost=example.com\n+\t\tusername=other\n+\t\t--\n+\t\tusername=other\n+\t\tpassword=askpass-password\n+\t\t--\n+\t\taskpass: Password for '\\''https://other@example.com'\\'':\n+\t\tEOF\n+\t'\n+\n+\ttest_expect_success \"helper ($HELPER) requires matching path\" '\n+\t\tcheck approve $HELPER <<-\\EOF &&\n+\t\tprotocol=ftp\n+\t\thost=other.tld\n+\t\tpath=foo.git\n+\t\tusername=user\n+\t\tpassword=pass\n+\t\tEOF\n+\t\tcheck fill $HELPER <<-\\EOF\n+\t\tprotocol=ftp\n+\t\thost=other.tld\n+\t\tpath=bar.git\n+\t\t--\n+\t\tusername=askpass-username\n+\t\tpassword=askpass-password\n+\t\t--\n+\t\taskpass: Username for '\\''ftp://other.tld/bar.git'\\'':\n+\t\taskpass: Password for '\\''ftp://askpass-username@other.tld/bar.git'\\'':\n+\t\tEOF\n+\t'\n+\n+\ttest_expect_success \"helper ($HELPER) can forget host\" '\n+\t\tcheck reject $HELPER <<-\\EOF &&\n+\t\tprotocol=https\n+\t\thost=example.com\n+\t\tEOF\n+\t\tcheck fill $HELPER <<-\\EOF\n+\t\tprotocol=https\n+\t\thost=example.com\n+\t\t--\n+\t\tusername=askpass-username\n+\t\tpassword=askpass-password\n+\t\t--\n+\t\taskpass: Username for '\\''https://example.com'\\'':\n+\t\taskpass: Password for '\\''https://askpass-username@example.com'\\'':\n+\t\tEOF\n+\t'\n+\n+\ttest_expect_success \"helper ($HELPER) can store multiple users\" '\n+\t\tcheck approve $HELPER <<-\\EOF &&\n+\t\tprotocol=https\n+\t\thost=example.com\n+\t\tusername=user1\n+\t\tpassword=pass1\n+\t\tEOF\n+\t\tcheck approve $HELPER <<-\\EOF &&\n+\t\tprotocol=https\n+\t\thost=example.com\n+\t\tusername=user2\n+\t\tpassword=pass2\n+\t\tEOF\n+\t\tcheck fill $HELPER <<-\\EOF &&\n+\t\tprotocol=https\n+\t\thost=example.com\n+\t\tusername=user1\n+\t\t--\n+\t\tusername=user1\n+\t\tpassword=pass1\n+\t\tEOF\n+\t\tcheck fill $HELPER <<-\\EOF\n+\t\tprotocol=https\n+\t\thost=example.com\n+\t\tusername=user2\n+\t\t--\n+\t\tusername=user2\n+\t\tpassword=pass2\n+\t\tEOF\n+\t'\n+\n+\ttest_expect_success \"helper ($HELPER) can forget user\" '\n+\t\tcheck reject $HELPER <<-\\EOF &&\n+\t\tprotocol=https\n+\t\thost=example.com\n+\t\tusername=user1\n+\t\tEOF\n+\t\tcheck fill $HELPER <<-\\EOF\n+\t\tprotocol=https\n+\t\thost=example.com\n+\t\tusername=user1\n+\t\t--\n+\t\tusername=user1\n+\t\tpassword=askpass-password\n+\t\t--\n+\t\taskpass: Password for '\\''https://user1@example.com'\\'':\n+\t\tEOF\n+\t'\n+\n+\ttest_expect_success \"helper ($HELPER) remembers other user\" '\n+\t\tcheck fill $HELPER <<-\\EOF\n+\t\tprotocol=https\n+\t\thost=example.com\n+\t\tusername=user2\n+\t\t--\n+\t\tusername=user2\n+\t\tpassword=pass2\n+\t\tEOF\n+\t'\n+}\n+\n+helper_test_timeout() {\n+\tHELPER=\"$*\"\n+\n+\ttest_expect_success \"helper ($HELPER) times out\" '\n+\t\tcheck approve \"$HELPER\" <<-\\EOF &&\n+\t\tprotocol=https\n+\t\thost=timeout.tld\n+\t\tusername=user\n+\t\tpassword=pass\n+\t\tEOF\n+\t\tsleep 2 &&\n+\t\tcheck fill \"$HELPER\" <<-\\EOF\n+\t\tprotocol=https\n+\t\thost=timeout.tld\n+\t\t--\n+\t\tusername=askpass-username\n+\t\tpassword=askpass-password\n+\t\t--\n+\t\taskpass: Username for '\\''https://timeout.tld'\\'':\n+\t\taskpass: Password for '\\''https://askpass-username@timeout.tld'\\'':\n+\t\tEOF\n+\t'\n+}\n \n cat >askpass <<\\EOF\n #!/bin/sh\ndiff --git a/t/t0301-credential-cache.sh b/t/t0301-credential-cache.sh\nnew file mode 100755\nindex 0000000..3a65f99\n--- /dev/null\n+++ b/t/t0301-credential-cache.sh\n@@ -0,0 +1,18 @@\n+#!/bin/sh\n+\n+test_description='credential-cache tests'\n+. ./test-lib.sh\n+. \"$TEST_DIRECTORY\"/lib-credential.sh\n+\n+# don't leave a stale daemon running\n+trap 'code=$?; git credential-cache exit; (exit $code); die' EXIT\n+\n+helper_test cache\n+helper_test_timeout cache --timeout=1\n+\n+# we can't rely on our \"trap\" above working after test_done,\n+# as test_done will delete the trash directory containing\n+# our socket, leaving us with no way to access the daemon.\n+git credential-cache exit\n+\n+test_done\ndiff --git a/unix-socket.c b/unix-socket.c\nnew file mode 100644\nindex 0000000..84b1509\n--- /dev/null\n+++ b/unix-socket.c\n@@ -0,0 +1,56 @@\n+#include \"cache.h\"\n+#include \"unix-socket.h\"\n+\n+static int unix_stream_socket(void)\n+{\n+\tint fd = socket(AF_UNIX, SOCK_STREAM, 0);\n+\tif (fd < 0)\n+\t\tdie_errno(\"unable to create socket\");\n+\treturn fd;\n+}\n+\n+static void unix_sockaddr_init(struct sockaddr_un *sa, const char *path)\n+{\n+\tint size = strlen(path) + 1;\n+\tif (size > sizeof(sa->sun_path))\n+\t\tdie(\"socket path is too long to fit in sockaddr\");\n+\tmemset(sa, 0, sizeof(*sa));\n+\tsa->sun_family = AF_UNIX;\n+\tmemcpy(sa->sun_path, path, size);\n+}\n+\n+int unix_stream_connect(const char *path)\n+{\n+\tint fd;\n+\tstruct sockaddr_un sa;\n+\n+\tunix_sockaddr_init(&sa, path);\n+\tfd = unix_stream_socket();\n+\tif (connect(fd, (struct sockaddr *)&sa, sizeof(sa)) < 0) {\n+\t\tclose(fd);\n+\t\treturn -1;\n+\t}\n+\treturn fd;\n+}\n+\n+int unix_stream_listen(const char *path)\n+{\n+\tint fd;\n+\tstruct sockaddr_un sa;\n+\n+\tunix_sockaddr_init(&sa, path);\n+\tfd = unix_stream_socket();\n+\n+\tunlink(path);\n+\tif (bind(fd, (struct sockaddr *)&sa, sizeof(sa)) < 0) {\n+\t\tclose(fd);\n+\t\treturn -1;\n+\t}\n+\n+\tif (listen(fd, 5) < 0) {\n+\t\tclose(fd);\n+\t\treturn -1;\n+\t}\n+\n+\treturn fd;\n+}\ndiff --git a/unix-socket.h b/unix-socket.h\nnew file mode 100644\nindex 0000000..e271aee\n--- /dev/null\n+++ b/unix-socket.h\n@@ -0,0 +1,7 @@\n+#ifndef UNIX_SOCKET_H\n+#define UNIX_SOCKET_H\n+\n+int unix_stream_connect(const char *path);\n+int unix_stream_listen(const char *path);\n+\n+#endif /* UNIX_SOCKET_H */\n-- \n1.7.8.rc4.4.g884ec\n"},{"id":"180354","messageId":"20111206062301.GK29233@sigill.intra.peff.net","threadId":"29093","inReplyTo":"20111206062127.GA29046@sigill.intra.peff.net","subject":"[PATCHv2 11/13] strbuf: add strbuf_add*_urlencode","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-12-06T06:23:01Z","receivedAt":"2011-12-06T06:23:01Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"This just follows the rfc3986 rules for percent-encoding\nurl data into a strbuf.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n strbuf.c |   37 +++++++++++++++++++++++++++++++++++++\n strbuf.h |    5 +++++\n 2 files changed, 42 insertions(+), 0 deletions(-)\n\ndiff --git a/strbuf.c b/strbuf.c\nindex 3ad2cc0..60e5e59 100644\n--- a/strbuf.c\n+++ b/strbuf.c\n@@ -397,3 +397,40 @@ int strbuf_read_file(struct strbuf *sb, const char *path, size_t hint)\n \n \treturn len;\n }\n+\n+static int is_rfc3986_reserved(char ch)\n+{\n+\tswitch (ch) {\n+\t\tcase '!': case '*': case '\\'': case '(': case ')': case ';':\n+\t\tcase ':': case '@': case '&': case '=': case '+': case '$':\n+\t\tcase ',': case '/': case '?': case '#': case '[': case ']':\n+\t\t\treturn 1;\n+\t}\n+\treturn 0;\n+}\n+\n+static int is_rfc3986_unreserved(char ch)\n+{\n+\treturn isalnum(ch) ||\n+\t\tch == '-' || ch == '_' || ch == '.' || ch == '~';\n+}\n+\n+void strbuf_add_urlencode(struct strbuf *sb, const char *s, size_t len,\n+\t\t\t  int reserved)\n+{\n+\tstrbuf_grow(sb, len);\n+\twhile (len--) {\n+\t\tchar ch = *s++;\n+\t\tif (is_rfc3986_unreserved(ch) ||\n+\t\t    (!reserved && is_rfc3986_reserved(ch)))\n+\t\t\tstrbuf_addch(sb, ch);\n+\t\telse\n+\t\t\tstrbuf_addf(sb, \"%%%02x\", ch);\n+\t}\n+}\n+\n+void strbuf_addstr_urlencode(struct strbuf *sb, const char *s,\n+\t\t\t     int reserved)\n+{\n+\tstrbuf_add_urlencode(sb, s, strlen(s), reserved);\n+}\ndiff --git a/strbuf.h b/strbuf.h\nindex 46a33f8..cecd48c 100644\n--- a/strbuf.h\n+++ b/strbuf.h\n@@ -115,4 +115,9 @@ struct strbuf_expand_dict_entry {\n extern int strbuf_branchname(struct strbuf *sb, const char *name);\n extern int strbuf_check_branch_ref(struct strbuf *sb, const char *name);\n \n+extern void strbuf_add_urlencode(struct strbuf *, const char *, size_t,\n+\t\t\t\t int reserved);\n+extern void strbuf_addstr_urlencode(struct strbuf *, const char *,\n+\t\t\t\t    int reserved);\n+\n #endif /* STRBUF_H */\n-- \n1.7.8.rc4.4.g884ec\n"},{"id":"180356","messageId":"20111206062305.GL29233@sigill.intra.peff.net","threadId":"29093","inReplyTo":"20111206062127.GA29046@sigill.intra.peff.net","subject":"[PATCHv2 12/13] credentials: add \"store\" helper","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-12-06T06:23:05Z","receivedAt":"2011-12-06T06:23:05Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"This is like \"cache\", except that we actually put the\ncredentials on disk. This can be terribly insecure, of\ncourse, but we do what we can to protect them by filesystem\npermissions, and we warn the user in the documentation.\n\nThis is not unlike using .netrc to store entries, but it's a\nlittle more user-friendly. Instead of putting credentials in\nplace ahead of time, we transparently store them after\nprompting the user for them once.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n .gitignore                             |    1 +\n Documentation/git-credential-store.txt |   75 ++++++++++++++++\n Documentation/gitcredentials.txt       |    5 +\n Makefile                               |    1 +\n credential-store.c                     |  148 ++++++++++++++++++++++++++++++++\n t/t0302-credential-store.sh            |    9 ++\n 6 files changed, 239 insertions(+), 0 deletions(-)\n create mode 100644 Documentation/git-credential-store.txt\n create mode 100644 credential-store.c\n create mode 100755 t/t0302-credential-store.sh\n\ndiff --git a/.gitignore b/.gitignore\nindex a6b0bd4..2b7a3f9 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -32,6 +32,7 @@\n /git-count-objects\n /git-credential-cache\n /git-credential-cache--daemon\n+/git-credential-store\n /git-cvsexportcommit\n /git-cvsimport\n /git-cvsserver\ndiff --git a/Documentation/git-credential-store.txt b/Documentation/git-credential-store.txt\nnew file mode 100644\nindex 0000000..3109346\n--- /dev/null\n+++ b/Documentation/git-credential-store.txt\n@@ -0,0 +1,75 @@\n+git-credential-store(1)\n+=======================\n+\n+NAME\n+----\n+git-credential-store - helper to store credentials on disk\n+\n+SYNOPSIS\n+--------\n+-------------------\n+git config credential.helper 'store [options]'\n+-------------------\n+\n+DESCRIPTION\n+-----------\n+\n+NOTE: Using this helper will store your passwords unencrypted on disk,\n+protected only by filesystem permissions. If this is not an acceptable\n+security tradeoff, try linkgit:git-credential-cache[1], or find a helper\n+that integrates with secure storage provided by your operating system.\n+\n+This command stores credentials indefinitely on disk for use by future\n+git programs.\n+\n+You probably don't want to invoke this command directly; it is meant to\n+be used as a credential helper by other parts of git. See\n+linkgit:gitcredentials[7] or `EXAMPLES` below.\n+\n+OPTIONS\n+-------\n+\n+--store=<path>::\n+\n+\tUse `<path>` to store credentials. The file will have its\n+\tfilesystem permissions set to prevent other users on the system\n+\tfrom reading it, but will not be encrypted or otherwise\n+\tprotected. Defaults to `~/.git-credentials`.\n+\n+EXAMPLES\n+--------\n+\n+The point of this helper is to reduce the number of times you must type\n+your username or password. For example:\n+\n+------------------------------------------\n+$ git config credential.helper store\n+$ git push http://example.com/repo.git\n+Username: <type your username>\n+Password: <type your password>\n+\n+[several days later]\n+$ git push http://example.com/repo.git\n+[your credentials are used automatically]\n+------------------------------------------\n+\n+STORAGE FORMAT\n+--------------\n+\n+The `.git-credentials` file is stored in plaintext. Each credential is\n+stored on its own line as a URL like:\n+\n+------------------------------\n+https://user:pass@example.com\n+------------------------------\n+\n+When git needs authentication for a particular URL context,\n+credential-store will consider that context a pattern to match against\n+each entry in the credentials file.  If the protocol, hostname, and\n+username (if we already have one) match, then the password is returned\n+to git. See the discussion of configuration in linkgit:gitcredentials[7]\n+for more information.\n+\n+GIT\n+---\n+Part of the linkgit:git[1] suite\ndiff --git a/Documentation/gitcredentials.txt b/Documentation/gitcredentials.txt\nindex 4e3f860..066f825 100644\n--- a/Documentation/gitcredentials.txt\n+++ b/Documentation/gitcredentials.txt\n@@ -71,6 +71,11 @@ cache::\n \tCache credentials in memory for a short period of time. See\n \tlinkgit:git-credential-cache[1] for details.\n \n+store::\n+\n+\tStore credentials indefinitely on disk. See\n+\tlinkgit:git-credential-store[1] for details.\n+\n You may also have third-party helpers installed; search for\n `credential-*` in the output of `git help -a`, and consult the\n documentation of individual helpers.  Once you have selected a helper,\ndiff --git a/Makefile b/Makefile\nindex 5d41c29..2537128 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -429,6 +429,7 @@ PROGRAM_OBJS += http-backend.o\n PROGRAM_OBJS += sh-i18n--envsubst.o\n PROGRAM_OBJS += credential-cache.o\n PROGRAM_OBJS += credential-cache--daemon.o\n+PROGRAM_OBJS += credential-store.o\n \n PROGRAMS += $(patsubst %.o,git-%$X,$(PROGRAM_OBJS))\n \ndiff --git a/credential-store.c b/credential-store.c\nnew file mode 100644\nindex 0000000..ed58768\n--- /dev/null\n+++ b/credential-store.c\n@@ -0,0 +1,148 @@\n+#include \"cache.h\"\n+#include \"credential.h\"\n+#include \"string-list.h\"\n+#include \"parse-options.h\"\n+\n+static struct lock_file credential_lock;\n+\n+static void parse_credential_file(const char *fn,\n+\t\t\t\t  struct credential *c,\n+\t\t\t\t  void (*match_cb)(struct credential *),\n+\t\t\t\t  void (*other_cb)(struct strbuf *))\n+{\n+\tFILE *fh;\n+\tstruct strbuf line = STRBUF_INIT;\n+\tstruct credential entry = CREDENTIAL_INIT;\n+\n+\tfh = fopen(fn, \"r\");\n+\tif (!fh) {\n+\t\tif (errno != ENOENT)\n+\t\t\tdie_errno(\"unable to open %s\", fn);\n+\t\treturn;\n+\t}\n+\n+\twhile (strbuf_getline(&line, fh, '\\n') != EOF) {\n+\t\tcredential_from_url(&entry, line.buf);\n+\t\tif (entry.username && entry.password &&\n+\t\t    credential_match(c, &entry)) {\n+\t\t\tif (match_cb) {\n+\t\t\t\tmatch_cb(&entry);\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\t\telse if (other_cb)\n+\t\t\tother_cb(&line);\n+\t}\n+\n+\tcredential_clear(&entry);\n+\tstrbuf_release(&line);\n+\tfclose(fh);\n+}\n+\n+static void print_entry(struct credential *c)\n+{\n+\tprintf(\"username=%s\\n\", c->username);\n+\tprintf(\"password=%s\\n\", c->password);\n+}\n+\n+static void print_line(struct strbuf *buf)\n+{\n+\tstrbuf_addch(buf, '\\n');\n+\twrite_or_die(credential_lock.fd, buf->buf, buf->len);\n+}\n+\n+static void rewrite_credential_file(const char *fn, struct credential *c,\n+\t\t\t\t    struct strbuf *extra)\n+{\n+\tif (hold_lock_file_for_update(&credential_lock, fn, 0) < 0)\n+\t\tdie_errno(\"unable to get credential storage lock\");\n+\tif (extra)\n+\t\tprint_line(extra);\n+\tparse_credential_file(fn, c, NULL, print_line);\n+\tif (commit_lock_file(&credential_lock) < 0)\n+\t\tdie_errno(\"unable to commit credential store\");\n+}\n+\n+static void store_credential(const char *fn, struct credential *c)\n+{\n+\tstruct strbuf buf = STRBUF_INIT;\n+\n+\t/*\n+\t * Sanity check that what we are storing is actually sensible.\n+\t * In particular, we can't make a URL without a protocol field.\n+\t * Without either a host or pathname (depending on the scheme),\n+\t * we have no primary key. And without a username and password,\n+\t * we are not actually storing a credential.\n+\t */\n+\tif (!c->protocol || !(c->host || c->path) ||\n+\t    !c->username || !c->password)\n+\t\treturn;\n+\n+\tstrbuf_addf(&buf, \"%s://\", c->protocol);\n+\tstrbuf_addstr_urlencode(&buf, c->username, 1);\n+\tstrbuf_addch(&buf, ':');\n+\tstrbuf_addstr_urlencode(&buf, c->password, 1);\n+\tstrbuf_addch(&buf, '@');\n+\tif (c->host)\n+\t\tstrbuf_addstr_urlencode(&buf, c->host, 1);\n+\tif (c->path) {\n+\t\tstrbuf_addch(&buf, '/');\n+\t\tstrbuf_addstr_urlencode(&buf, c->path, 0);\n+\t}\n+\n+\trewrite_credential_file(fn, c, &buf);\n+\tstrbuf_release(&buf);\n+}\n+\n+static void remove_credential(const char *fn, struct credential *c)\n+{\n+\trewrite_credential_file(fn, c, NULL);\n+}\n+\n+static int lookup_credential(const char *fn, struct credential *c)\n+{\n+\tparse_credential_file(fn, c, print_entry, NULL);\n+\treturn c->username && c->password;\n+}\n+\n+int main(int argc, const char **argv)\n+{\n+\tconst char * const usage[] = {\n+\t\t\"git credential-store [options] <action>\",\n+\t\tNULL\n+\t};\n+\tconst char *op;\n+\tstruct credential c = CREDENTIAL_INIT;\n+\tchar *file = NULL;\n+\tstruct option options[] = {\n+\t\tOPT_STRING_LIST(0, \"file\", &file, \"path\",\n+\t\t\t\t\"fetch and store credentials in <path>\"),\n+\t\tOPT_END()\n+\t};\n+\n+\tumask(077);\n+\n+\targc = parse_options(argc, argv, NULL, options, usage, 0);\n+\tif (argc != 1)\n+\t\tusage_with_options(usage, options);\n+\top = argv[0];\n+\n+\tif (!file)\n+\t\tfile = expand_user_path(\"~/.git-credentials\");\n+\tif (!file)\n+\t\tdie(\"unable to set up default path; use --file\");\n+\n+\tif (credential_read(&c, stdin) < 0)\n+\t\tdie(\"unable to read credential\");\n+\n+\tif (!strcmp(op, \"get\"))\n+\t\tlookup_credential(file, &c);\n+\telse if (!strcmp(op, \"erase\"))\n+\t\tremove_credential(file, &c);\n+\telse if (!strcmp(op, \"store\"))\n+\t\tstore_credential(file, &c);\n+\telse\n+\t\t; /* Ignore unknown operation. */\n+\n+\treturn 0;\n+}\ndiff --git a/t/t0302-credential-store.sh b/t/t0302-credential-store.sh\nnew file mode 100755\nindex 0000000..f61b40c\n--- /dev/null\n+++ b/t/t0302-credential-store.sh\n@@ -0,0 +1,9 @@\n+#!/bin/sh\n+\n+test_description='credential-store tests'\n+. ./test-lib.sh\n+. \"$TEST_DIRECTORY\"/lib-credential.sh\n+\n+helper_test store\n+\n+test_done\n-- \n1.7.8.rc4.4.g884ec\n"},{"id":"180357","messageId":"20111206062313.GM29233@sigill.intra.peff.net","threadId":"29093","inReplyTo":"20111206062127.GA29046@sigill.intra.peff.net","subject":"[PATCHv2 13/13] t: add test harness for external credential helpers","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-12-06T06:23:13Z","receivedAt":"2011-12-06T06:23:13Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"We already have tests for the internal helpers, but it's\nnice to give authors of external tools an easy way to\nsanity-check their helpers.\n\nIf you have written the \"git-credential-foo\" helper, you can\ndo so with:\n\n  GIT_TEST_CREDENTIAL_HELPER=foo \\\n  make t0303-credential-external.sh\n\nThis assumes that your helper is capable of both storing and\nretrieving credentials (some helpers may be read-only, and\nthey will fail these tests).\n\nIf your helper supports time-based expiration with a\nconfigurable timeout, you can test that feature like this:\n\n  GIT_TEST_CREDENTIAL_HELPER_TIMEOUT=\"foo --timeout=1\" \\\n  make t0303-credential-external.sh\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n t/t0303-credential-external.sh |   23 +++++++++++++++++++++++\n 1 files changed, 23 insertions(+), 0 deletions(-)\n create mode 100755 t/t0303-credential-external.sh\n\ndiff --git a/t/t0303-credential-external.sh b/t/t0303-credential-external.sh\nnew file mode 100755\nindex 0000000..79b046f\n--- /dev/null\n+++ b/t/t0303-credential-external.sh\n@@ -0,0 +1,23 @@\n+#!/bin/sh\n+\n+test_description='external credential helper tests'\n+. ./test-lib.sh\n+. \"$TEST_DIRECTORY\"/lib-credential.sh\n+\n+if test -z \"$GIT_TEST_CREDENTIAL_HELPER\"; then\n+\tsay \"# skipping external helper tests (set GIT_TEST_CREDENTIAL_HELPER)\"\n+else\n+\thelper_test_clean \"$GIT_TEST_CREDENTIAL_HELPER\"\n+\thelper_test \"$GIT_TEST_CREDENTIAL_HELPER\"\n+#\thelper_test_clean \"$GIT_TEST_CREDENTIAL_HELPER\"\n+fi\n+\n+if test -z \"$GIT_TEST_CREDENTIAL_HELPER_TIMEOUT\"; then\n+\tsay \"# skipping external helper timeout tests\"\n+else\n+\thelper_test_clean \"$GIT_TEST_CREDENTIAL_HELPER_TIMEOUT\"\n+\thelper_test_timeout \"$GIT_TEST_CREDENTIAL_HELPER_TIMEOUT\"\n+\thelper_test_clean \"$GIT_TEST_CREDENTIAL_HELPER_TIMEOUT\"\n+fi\n+\n+test_done\n-- \n1.7.8.rc4.4.g884ec\n"},{"id":"180416","messageId":"7v7h29fkfy.fsf@alter.siamese.dyndns.org","threadId":"29093","inReplyTo":"20111206062127.GA29046@sigill.intra.peff.net","subject":"Re: [PATCHv2 0/13] credential helpers","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-12-06T21:40:17Z","receivedAt":"2011-12-06T21:40:17Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n>     ... You can now\n>     do: \"git credential-store erase </dev/null\" to erase everything\n>     (since you have provided no restrictions, it matches everything).\n\nThat \"justification\" does not sound so true to me but perhaps that is\nbecause it is unclear what \"erase\" means and what it means to give the\noperation parameters.\n\nWhen I see \"erase $foo\", I would find it natural if $foo meant \"if there\nis something that matches $foo, then please remove it, but keep everything\nelse intact\", and not the other way around \"Match the existing entries\nagainst a pattern (or a set of matching patterns) I am giving you, and\ndrop all the rest\". So if I happen to give you an empty set, I would\nexpect nothing is removed.\n\nPerhaps the root cause of the issue is that you are treating the input as\n\"restriction\" instead of something that produces \"positive matches\"?\n\nConfused.\n"},{"id":"180420","messageId":"7vzkf5e5dp.fsf@alter.siamese.dyndns.org","threadId":"29093","inReplyTo":"20111206062305.GL29233@sigill.intra.peff.net","subject":"Re: [PATCHv2 12/13] credentials: add \"store\" helper","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-12-06T21:50:58Z","receivedAt":"2011-12-06T21:50:58Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> +static void store_credential(const char *fn, struct credential *c)\n> +{\n> +\tstruct strbuf buf = STRBUF_INIT;\n> +\n> +\t/*\n> +\t * Sanity check that what we are storing is actually sensible.\n> +\t * In particular, we can't make a URL without a protocol field.\n> +\t * Without either a host or pathname (depending on the scheme),\n> +\t * we have no primary key. And without a username and password,\n> +\t * we are not actually storing a credential.\n> +\t */\n> +\tif (!c->protocol || !(c->host || c->path) ||\n> +\t    !c->username || !c->password)\n> +\t\treturn;\n\nVery nicely explained. I wish all our patches had comments like this to\nexplain tricky bit that looks as if the choice was arbitrarily made but\nin fact the logic was carefully constructed.\n\nThanks.\n"},{"id":"180421","messageId":"7vvcpte5cg.fsf@alter.siamese.dyndns.org","threadId":"29093","inReplyTo":"20111206062313.GM29233@sigill.intra.peff.net","subject":"Re: [PATCHv2 13/13] t: add test harness for external credential helpers","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-12-06T21:51:43Z","receivedAt":"2011-12-06T21:51:43Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> diff --git a/t/t0303-credential-external.sh b/t/t0303-credential-external.sh\n> new file mode 100755\n> index 0000000..79b046f\n> --- /dev/null\n> +++ b/t/t0303-credential-external.sh\n> @@ -0,0 +1,23 @@\n> ...\n> +else\n> +\thelper_test_clean \"$GIT_TEST_CREDENTIAL_HELPER\"\n> +\thelper_test \"$GIT_TEST_CREDENTIAL_HELPER\"\n> +#\thelper_test_clean \"$GIT_TEST_CREDENTIAL_HELPER\"\n> +fi\n\nHuh? Leftover debugging cruft?\n"},{"id":"180422","messageId":"20111206220826.GC28493@sigill.intra.peff.net","threadId":"29093","inReplyTo":"7vvcpte5cg.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCHv2 13/13] t: add test harness for external credential helpers","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-12-06T22:08:26Z","receivedAt":"2011-12-06T22:08:26Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Dec 06, 2011 at 01:51:43PM -0800, Junio C Hamano wrote:\n\n> Jeff King <peff@peff.net> writes:\n> \n> > diff --git a/t/t0303-credential-external.sh b/t/t0303-credential-external.sh\n> > new file mode 100755\n> > index 0000000..79b046f\n> > --- /dev/null\n> > +++ b/t/t0303-credential-external.sh\n> > @@ -0,0 +1,23 @@\n> > ...\n> > +else\n> > +\thelper_test_clean \"$GIT_TEST_CREDENTIAL_HELPER\"\n> > +\thelper_test \"$GIT_TEST_CREDENTIAL_HELPER\"\n> > +#\thelper_test_clean \"$GIT_TEST_CREDENTIAL_HELPER\"\n> > +fi\n> \n> Huh? Leftover debugging cruft?\n\nOops, yes. It should be:\n\n  clean\n  do_the_test\n  clean\n\nThe first clean is \"remove any cruft accidentally leftover from a\nprevious run, so we can do our test\". The second clean is \"be a good\ncitizen and get rid of cruft we just accumulated\".\n\nAs part of my testing, I commented out the second clean momentarily so\nthat I could verify that the cruft was left without the clean, but gone\nwith the clean. And then I accidentally committed with the \"#\" left in.\n\nHere's the correct version, with some extra comments about the\nclean-test-clean cycle:\n\n-- >8 --\nSubject: [PATCHv2 13/13] t: add test harness for external credential helpers\n\nWe already have tests for the internal helpers, but it's\nnice to give authors of external tools an easy way to\nsanity-check their helpers.\n\nIf you have written the \"git-credential-foo\" helper, you can\ndo so with:\n\n  GIT_TEST_CREDENTIAL_HELPER=foo \\\n  make t0303-credential-external.sh\n\nThis assumes that your helper is capable of both storing and\nretrieving credentials (some helpers may be read-only, and\nthey will fail these tests).\n\nIf your helper supports time-based expiration with a\nconfigurable timeout, you can test that feature like this:\n\n  GIT_TEST_CREDENTIAL_HELPER_TIMEOUT=\"foo --timeout=1\" \\\n  make t0303-credential-external.sh\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n t/t0303-credential-external.sh |   30 ++++++++++++++++++++++++++++++\n 1 files changed, 30 insertions(+), 0 deletions(-)\n create mode 100755 t/t0303-credential-external.sh\n\ndiff --git a/t/t0303-credential-external.sh b/t/t0303-credential-external.sh\nnew file mode 100755\nindex 0000000..092dd3c\n--- /dev/null\n+++ b/t/t0303-credential-external.sh\n@@ -0,0 +1,30 @@\n+#!/bin/sh\n+\n+test_description='external credential helper tests'\n+. ./test-lib.sh\n+. \"$TEST_DIRECTORY\"/lib-credential.sh\n+\n+if test -z \"$GIT_TEST_CREDENTIAL_HELPER\"; then\n+\tsay \"# skipping external helper tests (set GIT_TEST_CREDENTIAL_HELPER)\"\n+else\n+\t# clean before the test in case there is cruft left\n+\t# over from a previous run that would impact results\n+\thelper_test_clean \"$GIT_TEST_CREDENTIAL_HELPER\"\n+\n+\thelper_test \"$GIT_TEST_CREDENTIAL_HELPER\"\n+\n+\t# then clean afterwards so that we are good citizens\n+\t# and don't leave cruft in the helper's storage, which\n+\t# might be long-term system storage\n+\thelper_test_clean \"$GIT_TEST_CREDENTIAL_HELPER\"\n+fi\n+\n+if test -z \"$GIT_TEST_CREDENTIAL_HELPER_TIMEOUT\"; then\n+\tsay \"# skipping external helper timeout tests\"\n+else\n+\thelper_test_clean \"$GIT_TEST_CREDENTIAL_HELPER_TIMEOUT\"\n+\thelper_test_timeout \"$GIT_TEST_CREDENTIAL_HELPER_TIMEOUT\"\n+\thelper_test_clean \"$GIT_TEST_CREDENTIAL_HELPER_TIMEOUT\"\n+fi\n+\n+test_done\n-- \n1.7.8.rc2.8.gf076c\n"},{"id":"180431","messageId":"7vsjkxckwk.fsf@alter.siamese.dyndns.org","threadId":"29093","inReplyTo":"20111206062247.GF29233@sigill.intra.peff.net","subject":"Re: [PATCHv2 06/13] credential: apply helper config","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-12-06T23:58:35Z","receivedAt":"2011-12-06T23:58:35Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> diff --git a/t/t0300-credentials.sh b/t/t0300-credentials.sh\n> index 81a455f..e3f61f4 100755\n> --- a/t/t0300-credentials.sh\n> +++ b/t/t0300-credentials.sh\n> @@ -192,4 +192,46 @@ test_expect_success 'internal getpass does not ask for known username' '\n>  \tEOF\n>  '\n>  \n> +HELPER=\"f() {\n> +\t\tcat >/dev/null\n> +\t\techo username=foo\n> +\t\techo password=bar\n> +\t}; f\"\n> +test_expect_success 'respect configured credentials' '\n> +\ttest_config credential.helper \"$HELPER\" &&\n> +\tcheck fill <<-\\EOF\n> +\t--\n> +\tusername=foo\n> +\tpassword=bar\n> +\t--\n> +\tEOF\n> +'\n\nHmm, why do I get ask-ass-{username,password} from this one?\n\n> +test_expect_success 'match configured credential' '\n> +\ttest_config credential.https://example.com.helper \"$HELPER\" &&\n> +\tcheck fill <<-\\EOF\n> +\tprotocol=https\n> +\thost=example.com\n> +\tpath=repo.git\n> +\t--\n> +\tusername=foo\n> +\tpassword=bar\n> +\t--\n> +\tEOF\n> +'\n\nAnd this one, too...\n"},{"id":"180434","messageId":"20111207004511.GA28370@sigill.intra.peff.net","threadId":"29093","inReplyTo":"7vsjkxckwk.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCHv2 06/13] credential: apply helper config","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-12-07T00:45:11Z","receivedAt":"2011-12-07T00:45:11Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Dec 06, 2011 at 03:58:35PM -0800, Junio C Hamano wrote:\n\n> > +test_expect_success 'respect configured credentials' '\n> > +\ttest_config credential.helper \"$HELPER\" &&\n> > +\tcheck fill <<-\\EOF\n> > +\t--\n> > +\tusername=foo\n> > +\tpassword=bar\n> > +\t--\n> > +\tEOF\n> > +'\n> \n> Hmm, why do I get ask-ass-{username,password} from this one?\n\nUgh. Because apparently one of my re-roll tweaks from patch 03 regressed\nthis. Sorry, I should have been more careful about running the full\nsuite, not just the tests in the commits I tweaked.\n\nLet me investigate and get back to you.\n\n-Peff\n"},{"id":"180435","messageId":"20111207004955.GA30288@sigill.intra.peff.net","threadId":"29093","inReplyTo":"20111207004511.GA28370@sigill.intra.peff.net","subject":"Re: [PATCHv2 06/13] credential: apply helper config","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-12-07T00:49:55Z","receivedAt":"2011-12-07T00:49:55Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Dec 06, 2011 at 07:45:11PM -0500, Jeff King wrote:\n\n> On Tue, Dec 06, 2011 at 03:58:35PM -0800, Junio C Hamano wrote:\n> \n> > > +test_expect_success 'respect configured credentials' '\n> > > +\ttest_config credential.helper \"$HELPER\" &&\n> > > +\tcheck fill <<-\\EOF\n> > > +\t--\n> > > +\tusername=foo\n> > > +\tpassword=bar\n> > > +\t--\n> > > +\tEOF\n> > > +'\n> > \n> > Hmm, why do I get ask-ass-{username,password} from this one?\n> \n> Ugh. Because apparently one of my re-roll tweaks from patch 03 regressed\n> this. Sorry, I should have been more careful about running the full\n> suite, not just the tests in the commits I tweaked.\n> \n> Let me investigate and get back to you.\n\nBrown paper bag time.\n\nThis needs squashed in, due to the changes in patch 03/13:\n\n---\ndiff --git a/t/t0300-credentials.sh b/t/t0300-credentials.sh\nindex e3f61f4..42d0f5b 100755\n--- a/t/t0300-credentials.sh\n+++ b/t/t0300-credentials.sh\n@@ -192,7 +192,7 @@ test_expect_success 'internal getpass does not ask for known username' '\n \tEOF\n '\n \n-HELPER=\"f() {\n+HELPER=\"!f() {\n \t\tcat >/dev/null\n \t\techo username=foo\n \t\techo password=bar\ndiff --git a/t/t5550-http-fetch.sh b/t/t5550-http-fetch.sh\nindex 21e2f5d..c59908f 100755\n--- a/t/t5550-http-fetch.sh\n+++ b/t/t5550-http-fetch.sh\n@@ -102,7 +102,7 @@ test_expect_success 'http auth can request both user and pass' '\n '\n \n test_expect_success 'http auth respects credential helper config' '\n-\ttest_config_global credential.helper \"f() {\n+\ttest_config_global credential.helper \"!f() {\n \t\tcat >/dev/null\n \t\techo username=user@host\n \t\techo password=user@host\n"},{"id":"180455","messageId":"20111207064231.GA499@sigill.intra.peff.net","threadId":"29093","inReplyTo":"7v7h29fkfy.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCHv2 0/13] credential helpers","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-12-07T06:42:31Z","receivedAt":"2011-12-07T06:42:31Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Dec 06, 2011 at 01:40:17PM -0800, Junio C Hamano wrote:\n\n> Jeff King <peff@peff.net> writes:\n> \n> >     ... You can now\n> >     do: \"git credential-store erase </dev/null\" to erase everything\n> >     (since you have provided no restrictions, it matches everything).\n> \n> That \"justification\" does not sound so true to me but perhaps that is\n> because it is unclear what \"erase\" means and what it means to give the\n> operation parameters.\n\nIt's not meant to be a justification, but rather an explanation. I think\nthe behavior is probably too dangerous to leave.\n\n> When I see \"erase $foo\", I would find it natural if $foo meant \"if there\n> is something that matches $foo, then please remove it, but keep everything\n> else intact\", and not the other way around \"Match the existing entries\n> against a pattern (or a set of matching patterns) I am giving you, and\n> drop all the rest\". So if I happen to give you an empty set, I would\n> expect nothing is removed.\n\nIt does do the first thing you mentioned (you provide one pattern $foo,\nand we match the pattern you have given). It's just that the pattern you\nhave specified is \"everything\". The problem is not in the matching, but\nin the pattern specification language.\n\nThis pattern:\n\n  protocol=https\n  host=github.com\n\nmeans \"match everything that uses https _and_ has a host of github.com\".\nThe username and path fields are not present, which implicitly means\n\"don't care about them\".\n\nSimilarly, this pattern:\n\n  protocol=https\n\nmeans \"match everything that uses https\". Everything else is not\nspecified, and therefore we allow anything.\n\nThen what does the empty pattern do? It cares about nothing, and\ntherefore matches everything.\n\nBy itself, I don't think that is a problem. It's something you might\nwant to specify, and it's logically consistent with the way the patterns\nare matched.  What is dangerous, though, is that failing to provide\ninput is byte-wise identical to the empty pattern. And that's why I say\nit's a pattern specification problem.\n\nA rough BNF for the pattern format is something like:\n\n  pattern = *line\n  line = key \"=\" value\n  key = *<any byte except NUL, \"=\", or \"\\n\">\n  value = *<any byte except NUL or \"\\n\">\n\nBecause the pattern takes 0 or more lines and no terminator, we can't\ndistinguish between empty or truncated input and the empty pattern. So\none solution would be:\n\n  pattern = *line \"\\n\"\n\ni.e., require a blank line terminator.\n\nDoes that explain the issue better?\n\n-Peff\n"},{"id":"180618","messageId":"7vmxb2hhne.fsf@alter.siamese.dyndns.org","threadId":"29093","inReplyTo":"20111207064231.GA499@sigill.intra.peff.net","subject":"Re: [PATCHv2 0/13] credential helpers","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-12-08T21:34:29Z","receivedAt":"2011-12-08T21:34:29Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> Because the pattern takes 0 or more lines and no terminator, we can't\n> distinguish between empty or truncated input and the empty pattern.\n\nI agree that such a positive \"Ok here is the end of specification\" marker\nis a good idea, even if we do not worry about \"an empty set\".\n\nWhen the requestor wants to specify the credentials with host and user,\nbut the wire is cut after host is communicated but before user is, we do\nwant to notice the communication error, instead of silently erasing all\nthe credentials on the host regardless of the user.\n\nThanks.\n"},{"id":"180627","messageId":"20111209022913.GA2600@sigill.intra.peff.net","threadId":"29093","inReplyTo":"7vmxb2hhne.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCHv2 0/13] credential helpers","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-12-09T02:29:13Z","receivedAt":"2011-12-09T02:29:13Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Dec 08, 2011 at 01:34:29PM -0800, Junio C Hamano wrote:\n\n> Jeff King <peff@peff.net> writes:\n> \n> > Because the pattern takes 0 or more lines and no terminator, we can't\n> > distinguish between empty or truncated input and the empty pattern.\n> \n> I agree that such a positive \"Ok here is the end of specification\" marker\n> is a good idea, even if we do not worry about \"an empty set\".\n> \n> When the requestor wants to specify the credentials with host and user,\n> but the wire is cut after host is communicated but before user is, we do\n> want to notice the communication error, instead of silently erasing all\n> the credentials on the host regardless of the user.\n\nOK, I've tweaked the series to require an end-of-credential marker (a\nblank line) both in input and output.\n\nIn addition, I've changed the code that runs helpers to make reading\nfrom the helpers an all-or-nothing thing (instead of incrementally\novewriting our credential as we read from it). Before, if a helper\nexited with error, we would happily use its partial result. Instead, we\nnow read its response into a holding area, and only copy it into our\ncredential when we get a successful exit code. This lets us detect\ntruncation when reading from the helper, too.\n\nIt works, and it detects truncated output both ways properly (I know\nbecause I had to update every test, since the old output was missing the\nend-of-credential marker).\n\nIt makes me a little sad, because the original format (relying on EOF)\nwas so Unix-y. You could make a helper like this:\n\n  echo password=`gpg -qd ~/.secret.gpg`\n\nand now you must remember to tack an extra \"echo\" at the end. Not a big\ndeal, but it somehow just feels less elegant to my gut.  OTOH, classic\nUnix constructs have always been a nightmare for robustness and error\nchecking[1], so this is certainly nothing new.\n\nThe diff from this tip to the old tip is below to give you a sense of\nthe magnitude of the change (the individual changes are squashed into\ntheir respective patches for the next re-roll, of course). I'll hold off\non posting the whole series to see if we get any more comments.\n\n-Peff\n\n[1] I mean things like:\n\n      grep foo bar | sed 's/some/transformation/'\n\n    where we totally ignore errors from grep, and where a truncated\n    output on the pipe would just subtly generate wrong answers.\n---\n\n Documentation/technical/api-credentials.txt |    2 +-\n credential-cache--daemon.c                  |    1 +\n credential-cache.c                          |    2 +\n credential-store.c                          |    1 +\n credential.c                                |   39 +++++++++++++++++++++++---\n t/lib-credential.sh                         |    1 +\n t/t0300-credentials.sh                      |    3 ++\n t/t5550-http-fetch.sh                       |    1 +\n 8 files changed, 44 insertions(+), 6 deletions(-)\n\ndiff --git a/Documentation/technical/api-credentials.txt b/Documentation/technical/api-credentials.txt\nindex 21ca6a2..0aac899 100644\n--- a/Documentation/technical/api-credentials.txt\n+++ b/Documentation/technical/api-credentials.txt\n@@ -199,7 +199,7 @@ followed by a newline. The key may contain any bytes except `=`,\n newline, or NUL. The value may contain any bytes except newline or NUL.\n In both cases, all bytes are treated as-is (i.e., there is no quoting,\n and one cannot transmit a value with newline or NUL in it). The list of\n-attributes is terminated by a blank line or end-of-file.\n+attributes is terminated by a blank line.\n \n Git will send the following attributes (but may not send all of\n them for a given credential; for example, a `host` attribute makes no\ndiff --git a/credential-cache--daemon.c b/credential-cache--daemon.c\nindex 390f194..38403645 100644\n--- a/credential-cache--daemon.c\n+++ b/credential-cache--daemon.c\n@@ -138,6 +138,7 @@ static void serve_one_client(FILE *in, FILE *out)\n \t\tif (e) {\n \t\t\tfprintf(out, \"username=%s\\n\", e->item.username);\n \t\t\tfprintf(out, \"password=%s\\n\", e->item.password);\n+\t\t\tfprintf(out, \"\\n\");\n \t\t}\n \t}\n \telse if (!strcmp(action.buf, \"exit\"))\ndiff --git a/credential-cache.c b/credential-cache.c\nindex dc98372..5b8d8c9 100644\n--- a/credential-cache.c\n+++ b/credential-cache.c\n@@ -70,6 +70,8 @@ static void do_cache(const char *socket, const char *action, int timeout,\n \t\tif (strbuf_read(&buf, 0, 0) < 0)\n \t\t\tdie_errno(\"unable to relay credential\");\n \t}\n+\telse\n+\t\tstrbuf_addch(&buf, '\\n');\n \n \tif (!send_request(socket, &buf))\n \t\treturn;\ndiff --git a/credential-store.c b/credential-store.c\nindex ed58768..00e38f0 100644\n--- a/credential-store.c\n+++ b/credential-store.c\n@@ -43,6 +43,7 @@ static void print_entry(struct credential *c)\n {\n \tprintf(\"username=%s\\n\", c->username);\n \tprintf(\"password=%s\\n\", c->password);\n+\tprintf(\"\\n\");\n }\n \n static void print_line(struct strbuf *buf)\ndiff --git a/credential.c b/credential.c\nindex a17eafe..6d2a37d 100644\n--- a/credential.c\n+++ b/credential.c\n@@ -147,8 +147,10 @@ int credential_read(struct credential *c, FILE *fp)\n \t\tchar *key = line.buf;\n \t\tchar *value = strchr(key, '=');\n \n-\t\tif (!line.len)\n-\t\t\tbreak;\n+\t\tif (!line.len) {\n+\t\t\tstrbuf_release(&line);\n+\t\t\treturn 0;\n+\t\t}\n \n \t\tif (!value) {\n \t\t\twarning(\"invalid credential line: %s\", key);\n@@ -181,7 +183,7 @@ int credential_read(struct credential *c, FILE *fp)\n \t}\n \n \tstrbuf_release(&line);\n-\treturn 0;\n+\treturn -1;\n }\n \n static void credential_write_item(FILE *fp, const char *key, const char *value)\n@@ -198,6 +200,26 @@ static void credential_write(const struct credential *c, FILE *fp)\n \tcredential_write_item(fp, \"path\", c->path);\n \tcredential_write_item(fp, \"username\", c->username);\n \tcredential_write_item(fp, \"password\", c->password);\n+\tputc('\\n', fp);\n+}\n+\n+static void credential_merge_one(char **dst, char **src)\n+{\n+\tif (!*src)\n+\t\treturn;\n+\tfree(*dst);\n+\t*dst = *src;\n+\t*src = NULL;\n+}\n+\n+static void credential_merge(struct credential *dst,\n+\t\t\t     struct credential *src)\n+{\n+\tcredential_merge_one(&dst->protocol, &src->protocol);\n+\tcredential_merge_one(&dst->host, &src->host);\n+\tcredential_merge_one(&dst->path, &src->path);\n+\tcredential_merge_one(&dst->username, &src->username);\n+\tcredential_merge_one(&dst->password, &src->password);\n }\n \n static int run_credential_helper(struct credential *c,\n@@ -206,6 +228,7 @@ static int run_credential_helper(struct credential *c,\n {\n \tstruct child_process helper;\n \tconst char *argv[] = { NULL, NULL };\n+\tstruct credential response = CREDENTIAL_INIT;\n \tFILE *fp;\n \n \tmemset(&helper, 0, sizeof(helper));\n@@ -227,17 +250,23 @@ static int run_credential_helper(struct credential *c,\n \n \tif (want_output) {\n \t\tint r;\n+\n \t\tfp = xfdopen(helper.out, \"r\");\n-\t\tr = credential_read(c, fp);\n+\t\tr = credential_read(&response, fp);\n \t\tfclose(fp);\n \t\tif (r < 0) {\n+\t\t\tcredential_clear(&response);\n \t\t\tfinish_command(&helper);\n \t\t\treturn -1;\n \t\t}\n \t}\n \n-\tif (finish_command(&helper))\n+\tif (finish_command(&helper)) {\n+\t\tcredential_clear(&response);\n \t\treturn -1;\n+\t}\n+\n+\tcredential_merge(c, &response);\n \treturn 0;\n }\n \ndiff --git a/t/lib-credential.sh b/t/lib-credential.sh\nindex fc34447..c0de4e9 100755\n--- a/t/lib-credential.sh\n+++ b/t/lib-credential.sh\n@@ -5,6 +5,7 @@\n # separated by \"--\".\n check() {\n \tread_chunk >stdin &&\n+\techo >>stdin &&\n \tread_chunk >expect-stdout &&\n \tread_chunk >expect-stderr &&\n \ttest-credential \"$@\" <stdin >stdout 2>stderr &&\ndiff --git a/t/t0300-credentials.sh b/t/t0300-credentials.sh\nindex 885af8f..f0e77dc 100755\n--- a/t/t0300-credentials.sh\n+++ b/t/t0300-credentials.sh\n@@ -9,6 +9,7 @@ test_expect_success 'setup helper scripts' '\n \twhoami=`echo $0 | sed s/.*git-credential-//`\n \techo >&2 \"$whoami: $*\"\n \twhile IFS== read key value; do\n+\t\ttest -z \"$key\" && break\n \t\techo >&2 \"$whoami: $key=$value\"\n \t\teval \"$key=$value\"\n \tdone\n@@ -28,6 +29,7 @@ test_expect_success 'setup helper scripts' '\n \t. ./dump\n \ttest -z \"$user\" || echo username=$user\n \ttest -z \"$pass\" || echo password=$pass\n+\techo\n \tEOF\n \tchmod +x git-credential-verbatim &&\n \n@@ -196,6 +198,7 @@ HELPER=\"!f() {\n \t\tcat >/dev/null\n \t\techo username=foo\n \t\techo password=bar\n+\t\techo\n \t}; f\"\n test_expect_success 'respect configured credentials' '\n \ttest_config credential.helper \"$HELPER\" &&\ndiff --git a/t/t5550-http-fetch.sh b/t/t5550-http-fetch.sh\nindex 95a133d..b817c69 100755\n--- a/t/t5550-http-fetch.sh\n+++ b/t/t5550-http-fetch.sh\n@@ -106,6 +106,7 @@ test_expect_success 'http auth respects credential helper config' '\n \t\tcat >/dev/null\n \t\techo username=user@host\n \t\techo password=user@host\n+\t\techo\n \t}; f\" &&\n \t>askpass-query &&\n \techo wrong >askpass-response &&\n"},{"id":"180678","messageId":"7vzkf1fwvn.fsf@alter.siamese.dyndns.org","threadId":"29093","inReplyTo":"20111209022913.GA2600@sigill.intra.peff.net","subject":"Re: [PATCHv2 0/13] credential helpers","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-12-09T18:00:44Z","receivedAt":"2011-12-09T18:00:44Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> It works, and it detects truncated output both ways properly (I know\n> because I had to update every test, since the old output was missing the\n> end-of-credential marker).\n>\n> It makes me a little sad, because the original format (relying on EOF)\n> was so Unix-y.\n\nIt saddens me, too.  A reasonable middle ground would be to stop treating\nan empty input as \"no restriction\" but \"never matches\".\n\nI suspect that it is far more likely for a helper to fail (due to\nconfiguration errors, for example) before it produces any output than\nafter it gives some but not all output lines.\n"},{"id":"180722","messageId":"20111209231800.GA14376@sigill.intra.peff.net","threadId":"29093","inReplyTo":"7vzkf1fwvn.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCHv2 0/13] credential helpers","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-12-09T23:18:00Z","receivedAt":"2011-12-09T23:18:00Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Dec 09, 2011 at 10:00:44AM -0800, Junio C Hamano wrote:\n\n> Jeff King <peff@peff.net> writes:\n> \n> > It works, and it detects truncated output both ways properly (I know\n> > because I had to update every test, since the old output was missing the\n> > end-of-credential marker).\n> >\n> > It makes me a little sad, because the original format (relying on EOF)\n> > was so Unix-y.\n> \n> It saddens me, too.  A reasonable middle ground would be to stop treating\n> an empty input as \"no restriction\" but \"never matches\".\n> \n> I suspect that it is far more likely for a helper to fail (due to\n> configuration errors, for example) before it produces any output than\n> after it gives some but not all output lines.\n\nYeah, I think that's a reasonable compromise. Instead of the patch I\nposted earlier, how about this:\n\ndiff --git a/credential-store.c b/credential-store.c\nindex a2c2cd0..26f7589 100644\n--- a/credential-store.c\n+++ b/credential-store.c\n@@ -96,7 +96,16 @@ static void store_credential(const char *fn, struct credential *c)\n \n static void remove_credential(const char *fn, struct credential *c)\n {\n-\trewrite_credential_file(fn, c, NULL);\n+\t/*\n+\t * Sanity check that we actually have something to match\n+\t * against. The input we get is a restrictive pattern,\n+\t * so technically a blank credential means \"erase everything\".\n+\t * But it is too easy to accidentally send this, since it is equivalent\n+\t * to empty input. So explicitly disallow it, and require that the\n+\t * pattern have some actual content to match.\n+\t */\n+\tif (c->protocol || c->host || c->path || c->username)\n+\t\trewrite_credential_file(fn, c, NULL);\n }\n \n static int lookup_credential(const char *fn, struct credential *c)\n\n\nWe _could_ modify credential_match() to automatically reject such a\npattern at that level, but it does actually have a use on the lookup\nside. In config, a context like \"https://example.com/foo.git\" would\nmatch each of:\n\n  [credential \"https://example.com/foo.git\"]\n          helper = ...\n  [credential \"https://example.com\"]\n          helper = ...\n  [credential \"https://\"]\n          helper = ...\n  [credential]\n          helper = ...\n\nThe final one is an just an extension of the others to the empty pattern\n(you could also spell it [credential \"\"], and it would have the same\neffect).\n\nSo the \"empty pattern\" does actually have a use, from the end-users's\npoint of view. It's just that with removal, it's a little more dangerous\nand a little less likely to be useful (as compared to lookup).\n\n-Peff\n"},{"id":"180723","messageId":"20111209231909.GA14526@sigill.intra.peff.net","threadId":"29093","inReplyTo":"20111206062305.GL29233@sigill.intra.peff.net","subject":"Re: [PATCHv2 12/13] credentials: add \"store\" helper","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-12-09T23:19:09Z","receivedAt":"2011-12-09T23:19:09Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Dec 06, 2011 at 01:23:05AM -0500, Jeff King wrote:\n\n> +int main(int argc, const char **argv)\n> +{\n> +\tconst char * const usage[] = {\n> +\t\t\"git credential-store [options] <action>\",\n> +\t\tNULL\n> +\t};\n> +\tconst char *op;\n> +\tstruct credential c = CREDENTIAL_INIT;\n> +\tchar *file = NULL;\n> +\tstruct option options[] = {\n> +\t\tOPT_STRING_LIST(0, \"file\", &file, \"path\",\n> +\t\t\t\t\"fetch and store credentials in <path>\"),\n> +\t\tOPT_END()\n> +\t};\n\nEek, this should be OPT_STRING, of course. I'll fix it in my next\nre-roll, but I wanted to mention it in case anybody is reviewing v2.\n\n-Peff\n"},{"id":"180724","messageId":"7vehwdcob3.fsf@alter.siamese.dyndns.org","threadId":"29093","inReplyTo":"20111209231800.GA14376@sigill.intra.peff.net","subject":"Re: [PATCHv2 0/13] credential helpers","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-12-09T23:34:08Z","receivedAt":"2011-12-09T23:34:08Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> Yeah, I think that's a reasonable compromise. Instead of the patch I\n> posted earlier, how about this:\n>\n> diff --git a/credential-store.c b/credential-store.c\n> index a2c2cd0..26f7589 100644\n> --- a/credential-store.c\n> +++ b/credential-store.c\n> @@ -96,7 +96,16 @@ static void store_credential(const char *fn, struct credential *c)\n>  \n>  static void remove_credential(const char *fn, struct credential *c)\n>  {\n> -\trewrite_credential_file(fn, c, NULL);\n> +\t/*\n> +\t * Sanity check that we actually have something to match\n> +\t * against. The input we get is a restrictive pattern,\n> +\t * so technically a blank credential means \"erase everything\".\n> +\t * But it is too easy to accidentally send this, since it is equivalent\n> +\t * to empty input. So explicitly disallow it, and require that the\n> +\t * pattern have some actual content to match.\n> +\t */\n> +\tif (c->protocol || c->host || c->path || c->username)\n> +\t\trewrite_credential_file(fn, c, NULL);\n>  }\n\nLooks very sane.\n\n> We _could_ modify credential_match() to automatically reject such a\n> pattern at that level,...\n\nI do not think that is such a good idea to modify \"match()\" function\neither, as I agree match with empty has its uses, but that does not stop\n\"rewrite_credential_file()\" from being safe by default, no? After all, the\none that makes the decision to drop things that match the pattern is that\nfunction (it chooses to give NULL to match_cb).\n\n> So the \"empty pattern\" does actually have a use, from the end-users's\n> point of view. It's just that with removal, it's a little more dangerous\n> and a little less likely to be useful (as compared to lookup).\n>\n> -Peff\n"},{"id":"180725","messageId":"20111209233957.GC10560@sigill.intra.peff.net","threadId":"29093","inReplyTo":"7vehwdcob3.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCHv2 0/13] credential helpers","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-12-09T23:39:58Z","receivedAt":"2011-12-09T23:39:58Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Dec 09, 2011 at 03:34:08PM -0800, Junio C Hamano wrote:\n\n> > We _could_ modify credential_match() to automatically reject such a\n> > pattern at that level,...\n> \n> I do not think that is such a good idea to modify \"match()\" function\n> either, as I agree match with empty has its uses, but that does not stop\n> \"rewrite_credential_file()\" from being safe by default, no? After all, the\n> one that makes the decision to drop things that match the pattern is that\n> function (it chooses to give NULL to match_cb).\n\nYeah, you could move it down to that level, but there isn't much point.\nrewrite_credential_file is unique to credential-store, and the only two\ncallers are store_credential (which has its own, stricter rules already)\nand remove_credential, which we are modifying here.\n\nNote that I didn't bother with the same safety valve for\ncredential-cache. It is, after all, a cache that will go away eventually\nanyway, so safety is less interesting.\n\nThird-party helpers will have to do their own checks anyway, as in\ngeneral I don't plan on them linking directly against git code.\n\nSpeaking of which, I hackishly ported Jay's osxkeychain helper to the\nnew format last night. I'll try to clean that up and post it tonight.\n\n-Peff\n"},{"id":"180731","messageId":"7vaa71cn9f.fsf@alter.siamese.dyndns.org","threadId":"29093","inReplyTo":"20111209233957.GC10560@sigill.intra.peff.net","subject":"Re: [PATCHv2 0/13] credential helpers","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-12-09T23:56:44Z","receivedAt":"2011-12-09T23:56:44Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> Speaking of which, I hackishly ported Jay's osxkeychain helper to the\n> new format last night. I'll try to clean that up and post it tonight.\n\n;-).\n"}]}