asyn-thread: avoid using GetAddrInfoExW with impersonation

Multiple reports suggest that GetAddrInfoExW fails when impersonation is
used. This PR checks if thread is impersonating and avoids using
GetAddrInfoExW api.

Reported-by: Keerthi Timmaraju
Assisted-by: edmcln on github
Fixes #13612
Closes #13738
This commit is contained in:
Pavel P 2024-05-22 01:23:34 +02:00 committed by Daniel Stenberg
parent 30de937bda
commit 0caadc1f24
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
3 changed files with 14 additions and 1 deletions

View File

@ -638,7 +638,8 @@ static bool init_resolve_thread(struct Curl_easy *data,
#ifdef _WIN32
if(Curl_isWindows8OrGreater && Curl_FreeAddrInfoExW &&
Curl_GetAddrInfoExCancel && Curl_GetAddrInfoExW) {
Curl_GetAddrInfoExCancel && Curl_GetAddrInfoExW &&
!Curl_win32_impersonating()) {
#define MAX_NAME_LEN 256 /* max domain name is 253 chars */
#define MAX_PORT_LEN 8
WCHAR namebuf[MAX_NAME_LEN];

View File

@ -267,4 +267,14 @@ HMODULE Curl_load_library(LPCTSTR filename)
#endif
}
bool Curl_win32_impersonating(void)
{
HANDLE token = NULL;
if(OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, TRUE, &token)) {
CloseHandle(token);
return TRUE;
}
return FALSE;
}
#endif /* _WIN32 */

View File

@ -68,6 +68,8 @@ extern FREEADDRINFOEXW_FN Curl_FreeAddrInfoExW;
extern GETADDRINFOEXCANCEL_FN Curl_GetAddrInfoExCancel;
extern GETADDRINFOEXW_FN Curl_GetAddrInfoExW;
bool Curl_win32_impersonating(void);
/* This is used to dynamically load DLLs */
HMODULE Curl_load_library(LPCTSTR filename);
#else /* _WIN32 */