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
This commit is contained in:
@ -34,7 +34,8 @@ static void *xmalloc(size_t size)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static WCHAR *wusername, *password, *protocol, *host, *path, target[1024];
|
static WCHAR *wusername, *password, *protocol, *host, *path, target[1024],
|
||||||
|
*password_expiry_utc;
|
||||||
|
|
||||||
static void write_item(const char *what, LPCWSTR wbuf, int wlen)
|
static void write_item(const char *what, LPCWSTR wbuf, int wlen)
|
||||||
{
|
{
|
||||||
@ -126,6 +127,7 @@ static void get_credential(void)
|
|||||||
CREDENTIALW **creds;
|
CREDENTIALW **creds;
|
||||||
DWORD num_creds;
|
DWORD num_creds;
|
||||||
int i;
|
int i;
|
||||||
|
CREDENTIAL_ATTRIBUTEW *attr;
|
||||||
|
|
||||||
if (!CredEnumerateW(L"git:*", 0, &num_creds, &creds))
|
if (!CredEnumerateW(L"git:*", 0, &num_creds, &creds))
|
||||||
return;
|
return;
|
||||||
@ -138,6 +140,14 @@ static void get_credential(void)
|
|||||||
write_item("password",
|
write_item("password",
|
||||||
(LPCWSTR)creds[i]->CredentialBlob,
|
(LPCWSTR)creds[i]->CredentialBlob,
|
||||||
creds[i]->CredentialBlobSize / sizeof(WCHAR));
|
creds[i]->CredentialBlobSize / sizeof(WCHAR));
|
||||||
|
for (int j = 0; j < creds[i]->AttributeCount; j++) {
|
||||||
|
attr = creds[i]->Attributes + j;
|
||||||
|
if (!wcscmp(attr->Keyword, L"git_password_expiry_utc")) {
|
||||||
|
write_item("password_expiry_utc", (LPCWSTR)attr->Value,
|
||||||
|
attr->ValueSize / sizeof(WCHAR));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,6 +157,7 @@ static void get_credential(void)
|
|||||||
static void store_credential(void)
|
static void store_credential(void)
|
||||||
{
|
{
|
||||||
CREDENTIALW cred;
|
CREDENTIALW cred;
|
||||||
|
CREDENTIAL_ATTRIBUTEW expiry_attr;
|
||||||
|
|
||||||
if (!wusername || !password)
|
if (!wusername || !password)
|
||||||
return;
|
return;
|
||||||
@ -160,6 +171,14 @@ static void store_credential(void)
|
|||||||
cred.Persist = CRED_PERSIST_LOCAL_MACHINE;
|
cred.Persist = CRED_PERSIST_LOCAL_MACHINE;
|
||||||
cred.AttributeCount = 0;
|
cred.AttributeCount = 0;
|
||||||
cred.Attributes = NULL;
|
cred.Attributes = NULL;
|
||||||
|
if (password_expiry_utc != NULL) {
|
||||||
|
expiry_attr.Keyword = L"git_password_expiry_utc";
|
||||||
|
expiry_attr.Value = (LPVOID)password_expiry_utc;
|
||||||
|
expiry_attr.ValueSize = (wcslen(password_expiry_utc)) * sizeof(WCHAR);
|
||||||
|
expiry_attr.Flags = 0;
|
||||||
|
cred.Attributes = &expiry_attr;
|
||||||
|
cred.AttributeCount = 1;
|
||||||
|
}
|
||||||
cred.TargetAlias = NULL;
|
cred.TargetAlias = NULL;
|
||||||
cred.UserName = wusername;
|
cred.UserName = wusername;
|
||||||
|
|
||||||
@ -232,6 +251,8 @@ static void read_credential(void)
|
|||||||
wusername = utf8_to_utf16_dup(v);
|
wusername = utf8_to_utf16_dup(v);
|
||||||
} else if (!strcmp(buf, "password"))
|
} else if (!strcmp(buf, "password"))
|
||||||
password = utf8_to_utf16_dup(v);
|
password = utf8_to_utf16_dup(v);
|
||||||
|
else if (!strcmp(buf, "password_expiry_utc"))
|
||||||
|
password_expiry_utc = utf8_to_utf16_dup(v);
|
||||||
/*
|
/*
|
||||||
* Ignore other lines; we don't know what they mean, but
|
* Ignore other lines; we don't know what they mean, but
|
||||||
* this future-proofs us when later versions of git do
|
* this future-proofs us when later versions of git do
|
||||||
@ -248,7 +269,7 @@ int main(int argc, char *argv[])
|
|||||||
"usage: git credential-wincred <get|store|erase>\n";
|
"usage: git credential-wincred <get|store|erase>\n";
|
||||||
|
|
||||||
if (!argv[1])
|
if (!argv[1])
|
||||||
die(usage);
|
die("%s", usage);
|
||||||
|
|
||||||
/* git use binary pipes to avoid CRLF-issues */
|
/* git use binary pipes to avoid CRLF-issues */
|
||||||
_setmode(_fileno(stdin), _O_BINARY);
|
_setmode(_fileno(stdin), _O_BINARY);
|
||||||
|
Reference in New Issue
Block a user