Merge pull request #4743 from Agent00Log/dev/winbugfixes Windows: default credentials / fallback credential handling
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c
index 1a317f6..3df892d 100644
--- a/src/transports/winhttp.c
+++ b/src/transports/winhttp.c
@@ -184,10 +184,10 @@ static int apply_default_credentials(HINTERNET request, int mechanisms)
DWORD native_scheme = 0;
if ((mechanisms & GIT_WINHTTP_AUTH_NTLM) != 0)
- native_scheme |= WINHTTP_AUTH_SCHEME_NTLM;
+ native_scheme = WINHTTP_AUTH_SCHEME_NTLM;
if ((mechanisms & GIT_WINHTTP_AUTH_NEGOTIATE) != 0)
- native_scheme |= WINHTTP_AUTH_SCHEME_NEGOTIATE;
+ native_scheme = WINHTTP_AUTH_SCHEME_NEGOTIATE;
if (!native_scheme) {
giterr_set(GITERR_NET, "invalid authentication scheme");
@@ -219,6 +219,7 @@ static int fallback_cred_acquire_cb(
* as an authentication mechanism */
if (GIT_CREDTYPE_DEFAULT & allowed_types) {
wchar_t *wide_url;
+ HRESULT hCoInitResult;
/* Convert URL to wide characters */
if (git__utf8_to_16_alloc(&wide_url, url) < 0) {
@@ -226,7 +227,9 @@ static int fallback_cred_acquire_cb(
return -1;
}
- if (SUCCEEDED(CoInitializeEx(NULL, COINIT_MULTITHREADED))) {
+ hCoInitResult = CoInitializeEx(NULL, COINIT_MULTITHREADED);
+
+ if (SUCCEEDED(hCoInitResult) || hCoInitResult == RPC_E_CHANGED_MODE) {
IInternetSecurityManager* pISM;
/* And if the target URI is in the My Computer, Intranet, or Trusted zones */
@@ -250,7 +253,9 @@ static int fallback_cred_acquire_cb(
pISM->lpVtbl->Release(pISM);
}
- CoUninitialize();
+ if (SUCCEEDED(hCoInitResult))
+ /* Only unitialize if the call to CoInitializeEx was successful. */
+ CoUninitialize();
}
git__free(wide_url);