
Over HTTP, NTLM and Kerberos require two rounds of authentication on the client side. It's possible that there are custom authentication schemes that also implement this same approach. Since these are tricky schemes to implement and the HTTP library in use may not always handle them gracefully on all systems, it would be helpful to allow the credential helper to implement them instead for increased portability and robustness. To allow this to happen, add a boolean flag, continue, that indicates that instead of failing when we get a 401, we should retry another round of authentication. However, this necessitates some changes in our current credential code so that we can make this work. Keep the state[] headers between iterations, but only use them to send to the helper and only consider the new ones we read from the credential helper to be valid on subsequent iterations. That avoids us passing stale data when we finally approve or reject the credential. Similarly, clear the multistage and wwwauth[] values appropriately so that we don't pass stale data or think we're trying a multiround response when we're not. Remove the credential values so that we can actually fill a second time with new responses. Limit the number of iterations of reauthentication we do to 3. This means that if there's a problem, we'll terminate with an error message instead of retrying indefinitely and not informing the user (and possibly conducting a DoS on the server). In our tests, handle creating multiple response output files from our helper so we can verify that each of the messages sent is correct. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
38 lines
963 B
C
38 lines
963 B
C
#include "git-compat-util.h"
|
|
#include "credential.h"
|
|
#include "builtin.h"
|
|
#include "config.h"
|
|
|
|
static const char usage_msg[] =
|
|
"git credential (fill|approve|reject)";
|
|
|
|
int cmd_credential(int argc, const char **argv, const char *prefix UNUSED)
|
|
{
|
|
const char *op;
|
|
struct credential c = CREDENTIAL_INIT;
|
|
|
|
git_config(git_default_config, NULL);
|
|
|
|
if (argc != 2 || !strcmp(argv[1], "-h"))
|
|
usage(usage_msg);
|
|
op = argv[1];
|
|
|
|
if (credential_read(&c, stdin, CREDENTIAL_OP_INITIAL) < 0)
|
|
die("unable to read credential from stdin");
|
|
|
|
if (!strcmp(op, "fill")) {
|
|
credential_fill(&c, 0);
|
|
credential_next_state(&c);
|
|
credential_write(&c, stdout, CREDENTIAL_OP_RESPONSE);
|
|
} else if (!strcmp(op, "approve")) {
|
|
credential_set_all_capabilities(&c, CREDENTIAL_OP_HELPER);
|
|
credential_approve(&c);
|
|
} else if (!strcmp(op, "reject")) {
|
|
credential_set_all_capabilities(&c, CREDENTIAL_OP_HELPER);
|
|
credential_reject(&c);
|
|
} else {
|
|
usage(usage_msg);
|
|
}
|
|
return 0;
|
|
}
|