credential-cache: implement authtype capability

Now that we have full support in Git for the authtype capability, let's
add support to the cache credential helper.

When parsing data, we always set the initial capabilities because we're
the helper, and we need both the initial and helper capabilities to be
set in order to have the helper capabilities take effect.

When emitting data, always emit the supported capability and make sure
we emit items only if we have them and they're supported by the caller.
Since we may no longer have a username or password, be sure to emit
those conditionally as well so we don't segfault on a NULL pointer.
Similarly, when comparing credentials, consider both the password and
credential fields when we're matching passwords.

Adjust the partial credential detection code so that we can store
credentials missing a username or password as long as they have an
authtype and credential.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
brian m. carlson
2024-04-17 00:02:39 +00:00
committed by Junio C Hamano
parent 30c0a3036f
commit 40220f48b1
4 changed files with 28 additions and 6 deletions

View File

@ -80,7 +80,8 @@ int credential_match(const struct credential *want,
CHECK(host) &&
CHECK(path) &&
CHECK(username) &&
(!match_password || CHECK(password));
(!match_password || CHECK(password)) &&
(!match_password || CHECK(credential));
#undef CHECK
}
@ -248,8 +249,8 @@ static void credential_getpass(struct credential *c)
PROMPT_ASKPASS);
}
static int credential_has_capability(const struct credential_capability *capa,
enum credential_op_type op_type)
int credential_has_capability(const struct credential_capability *capa,
enum credential_op_type op_type)
{
/*
* We're checking here if each previous step indicated that we had the