git/test-credential.c
Jeff King abca927dbe introduce credentials API
There are a few places in git that need to get a username
and password credential from the user; the most notable one
is HTTP authentication for smart-http pushing.

Right now the only choices for providing credentials are to
put them plaintext into your ~/.netrc, or to have git prompt
you (either on the terminal or via an askpass program). The
former is not very secure, and the latter is not very
convenient.

Unfortunately, there is no "always best" solution for
password management. The details will depend on the tradeoff
you want between security and convenience, as well as how
git can integrate with other security systems (e.g., many
operating systems provide a keychain or password wallet for
single sign-on).

This patch provides an abstract notion of credentials as a
data item, and provides three basic operations:

  - fill (i.e., acquire from external storage or from the
    user)

  - approve (mark a credential as "working" for further
    storage)

  - reject (mark a credential as "not working", so it can
    be removed from storage)

These operations can be backed by external helper processes
that interact with system- or user-specific secure storage.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-12-11 23:16:24 -08:00

39 lines
791 B
C

#include "cache.h"
#include "credential.h"
#include "string-list.h"
static const char usage_msg[] =
"test-credential <fill|approve|reject> [helper...]";
int main(int argc, const char **argv)
{
const char *op;
struct credential c = CREDENTIAL_INIT;
int i;
op = argv[1];
if (!op)
usage(usage_msg);
for (i = 2; i < argc; i++)
string_list_append(&c.helpers, argv[i]);
if (credential_read(&c, stdin) < 0)
die("unable to read credential from stdin");
if (!strcmp(op, "fill")) {
credential_fill(&c);
if (c.username)
printf("username=%s\n", c.username);
if (c.password)
printf("password=%s\n", c.password);
}
else if (!strcmp(op, "approve"))
credential_approve(&c);
else if (!strcmp(op, "reject"))
credential_reject(&c);
else
usage(usage_msg);
return 0;
}