[PATCH v2 0/2] improve-wincred-compatibility
- From
Karsten Blees <karsten.blees@gmail.com>
- Date
- Jan 10, 2013, 12:10 UTC
- Message-ID
- <50EEAF9A.6020302@gmail.com>
- In-Reply-To
- <CABPQNSb7MjTKgmeB9TcUV0+-FfjPZ1sgKPsfVDg6+uaw2f_azQ@mail.gmail.com>
Changes since initial version (see attached diff for details): - split in two patches - removed unused variables - improved the dll error message - changed ?: to if else - added comments
Also available here: https://github.com/kblees/git/tree/kb/improve-wincred-compatibility-v2 git pull git://github.com/kblees/git.git kb/improve-wincred-compatibility-v2
Karsten Blees (2): wincred: accept CRLF on stdin to simplify console usage wincred: improve compatibility with windows versions
.../credential/wincred/git-credential-wincred.c | 206 ++++++++------------- 1 file changed, 75 insertions(+), 131 deletions(-)
> git diff kb/improve-wincred-compatibility..kb/improve-wincred-compatibility-v2
diff --git a/contrib/credential/wincred/git-credential-wincred.c b/contrib/credential/wincred/git-credential-wincred.c index 3464080..dac19ea 100644 --- a/contrib/credential/wincred/git-credential-wincred.c +++ b/contrib/credential/wincred/git-credential-wincred.c @@ -66,7 +66,7 @@ typedef BOOL (WINAPI *CredEnumerateWT)(LPCWSTR, DWORD, DWORD *, typedef VOID (WINAPI *CredFreeT)(PVOID); typedef BOOL (WINAPI *CredDeleteWT)(LPCWSTR, DWORD, DWORD); -static HMODULE advapi, credui; +static HMODULE advapi; static CredWriteWT CredWriteW; static CredEnumerateWT CredEnumerateW; static CredFreeT CredFree; @@ -77,7 +77,7 @@ static void load_cred_funcs(void) /* load DLLs */ advapi = LoadLibrary("advapi32.dll"); if (!advapi) - die("failed to load DLLs"); + die("failed to load advapi32.dll"); /* get function pointers */ CredWriteW = (CredWriteWT)GetProcAddress(advapi, "CredWriteW"); @@ -107,14 +107,34 @@ static void write_item(const char *what, LPCWSTR wbuf, int wlen) free(buf); } +/* + * Match an (optional) expected string and a delimiter in the target string, + * consuming the matched text by updating the target pointer. + */ static int match_part(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim) { - LPCWSTR start = *ptarget; - LPCWSTR end = *delim ? wcsstr(start, delim) : start + wcslen(start); - int len = end ? end - start : wcslen(start); + LPCWSTR delim_pos, start = *ptarget; + int len; + + /* find start of delimiter (or end-of-string if delim is empty) */ + if (*delim) + delim_pos = wcsstr(start, delim); + else + delim_pos = start + wcslen(start); + + /* + * match text up to delimiter, or end of string (e.g. the '/' after + * host is optional if not followed by a path) + */ + if (delim_pos) + len = delim_pos - start; + else + len = wcslen(start); + /* update ptarget if we either found a delimiter or need a match */ - if (end || want) - *ptarget = end ? end + wcslen(delim) : start + len; + if (delim_pos || want) + *ptarget = delim_pos ? delim_pos + wcslen(delim) : start + len; + return !want || (!wcsncmp(want, start, len) && !want[len]); } @@ -157,9 +177,6 @@ static void get_credential(void) static void store_credential(void) { CREDENTIALW cred; - BYTE *auth_buf; - DWORD auth_buf_size = 0; - CREDENTIAL_ATTRIBUTEW attrs[CRED_MAX_ATTRIBUTES]; if (!wusername || !password) return;
-- *** Please reply-to-all at all times *** *** (do not pretend to know who is subscribed and who is not) *** *** Please avoid top-posting. *** The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free. You received this message because you are subscribed to the Google Groups "msysGit" group. To post to this group, send email to msysgit@googlegroups.com To unsubscribe from this group, send email to msysgit+unsubscribe@googlegroups.com For more options, and view previous threads, visit this group at http://groups.google.com/group/msysgit?hl=en_US?hl=en