Skip to content

Commit 2a1a882

Browse files
committed
Merge branch 'kn/osxkeychain-skip-idempotent-store'
The credential helper that talks with osx keychain learned to avoid storing back the authentication material it just got received from the keychain. * kn/osxkeychain-skip-idempotent-store: osxkeychain: state to skip unnecessary store operations osxkeychain: exclusive lock to serialize execution of operations
2 parents b32f298 + e1ab45b commit 2a1a882

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

contrib/credential/osxkeychain/git-credential-osxkeychain.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ static CFStringRef username;
1212
static CFDataRef password;
1313
static CFDataRef password_expiry_utc;
1414
static CFDataRef oauth_refresh_token;
15+
static int state_seen;
1516

1617
static void clear_credential(void)
1718
{
@@ -171,6 +172,9 @@ static OSStatus find_internet_password(void)
171172

172173
CFRelease(item);
173174

175+
write_item("capability[]", "state", strlen("state"));
176+
write_item("state[]", "osxkeychain:seen=1", strlen("osxkeychain:seen=1"));
177+
174178
out:
175179
CFRelease(attrs);
176180

@@ -284,6 +288,9 @@ static OSStatus add_internet_password(void)
284288
CFDictionaryRef attrs;
285289
OSStatus result;
286290

291+
if (state_seen)
292+
return errSecSuccess;
293+
287294
/* Only store complete credentials */
288295
if (!protocol || !host || !username || !password)
289296
return -1;
@@ -395,6 +402,10 @@ static void read_credential(void)
395402
oauth_refresh_token = CFDataCreate(kCFAllocatorDefault,
396403
(UInt8 *)v,
397404
strlen(v));
405+
else if (!strcmp(buf, "state[]")) {
406+
if (!strcmp(v, "osxkeychain:seen=1"))
407+
state_seen = 1;
408+
}
398409
/*
399410
* Ignore other lines; we don't know what they mean, but
400411
* this future-proofs us when later versions of git do
@@ -414,6 +425,9 @@ int main(int argc, const char **argv)
414425
if (!argv[1])
415426
die("%s", usage);
416427

428+
if (open(argv[0], O_RDONLY | O_EXLOCK) == -1)
429+
die("failed to lock %s", argv[0]);
430+
417431
read_credential();
418432

419433
if (!strcmp(argv[1], "get"))

0 commit comments

Comments
 (0)