Skip to content

Commit 5bc069e

Browse files
committed
Merge branch 'mh/credential-password-expiry-wincred'
Teach the recently invented "password expiry time" trait to the wincred credential helper. * mh/credential-password-expiry-wincred: credential/wincred: store password_expiry_utc
2 parents cb29fb8 + 488d9d5 commit 5bc069e

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

contrib/credential/wincred/git-credential-wincred.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ static void *xmalloc(size_t size)
3434
return ret;
3535
}
3636

37-
static WCHAR *wusername, *password, *protocol, *host, *path, target[1024];
37+
static WCHAR *wusername, *password, *protocol, *host, *path, target[1024],
38+
*password_expiry_utc;
3839

3940
static void write_item(const char *what, LPCWSTR wbuf, int wlen)
4041
{
@@ -126,6 +127,7 @@ static void get_credential(void)
126127
CREDENTIALW **creds;
127128
DWORD num_creds;
128129
int i;
130+
CREDENTIAL_ATTRIBUTEW *attr;
129131

130132
if (!CredEnumerateW(L"git:*", 0, &num_creds, &creds))
131133
return;
@@ -138,6 +140,14 @@ static void get_credential(void)
138140
write_item("password",
139141
(LPCWSTR)creds[i]->CredentialBlob,
140142
creds[i]->CredentialBlobSize / sizeof(WCHAR));
143+
for (int j = 0; j < creds[i]->AttributeCount; j++) {
144+
attr = creds[i]->Attributes + j;
145+
if (!wcscmp(attr->Keyword, L"git_password_expiry_utc")) {
146+
write_item("password_expiry_utc", (LPCWSTR)attr->Value,
147+
attr->ValueSize / sizeof(WCHAR));
148+
break;
149+
}
150+
}
141151
break;
142152
}
143153

@@ -147,6 +157,7 @@ static void get_credential(void)
147157
static void store_credential(void)
148158
{
149159
CREDENTIALW cred;
160+
CREDENTIAL_ATTRIBUTEW expiry_attr;
150161

151162
if (!wusername || !password)
152163
return;
@@ -160,6 +171,14 @@ static void store_credential(void)
160171
cred.Persist = CRED_PERSIST_LOCAL_MACHINE;
161172
cred.AttributeCount = 0;
162173
cred.Attributes = NULL;
174+
if (password_expiry_utc != NULL) {
175+
expiry_attr.Keyword = L"git_password_expiry_utc";
176+
expiry_attr.Value = (LPVOID)password_expiry_utc;
177+
expiry_attr.ValueSize = (wcslen(password_expiry_utc)) * sizeof(WCHAR);
178+
expiry_attr.Flags = 0;
179+
cred.Attributes = &expiry_attr;
180+
cred.AttributeCount = 1;
181+
}
163182
cred.TargetAlias = NULL;
164183
cred.UserName = wusername;
165184

@@ -232,6 +251,8 @@ static void read_credential(void)
232251
wusername = utf8_to_utf16_dup(v);
233252
} else if (!strcmp(buf, "password"))
234253
password = utf8_to_utf16_dup(v);
254+
else if (!strcmp(buf, "password_expiry_utc"))
255+
password_expiry_utc = utf8_to_utf16_dup(v);
235256
/*
236257
* Ignore other lines; we don't know what they mean, but
237258
* this future-proofs us when later versions of git do
@@ -248,7 +269,7 @@ int main(int argc, char *argv[])
248269
"usage: git credential-wincred <get|store|erase>\n";
249270

250271
if (!argv[1])
251-
die(usage);
272+
die("%s", usage);
252273

253274
/* git use binary pipes to avoid CRLF-issues */
254275
_setmode(_fileno(stdin), _O_BINARY);

0 commit comments

Comments
 (0)