diff options
author | Yuhang Zhao <2546789017@qq.com> | 2021-10-24 13:13:12 +0800 |
---|---|---|
committer | Yuhang Zhao <2546789017@qq.com> | 2021-11-02 13:55:15 +0800 |
commit | 2526df506bda99f9497e83a4e6820557a722660e (patch) | |
tree | 48b45a8a8a5cf879b062354a92e02c9303d017f1 /src/network/kernel | |
parent | 35ddf3498859dc184456346f2b070fe94dabaf26 (diff) |
Remove pre-Win10 code paths in QtBase
Mostly a removal of dynamically loaded API.
They should all exist on Windows 10 1809
(Qt6's minimum supported version).
accessibility parts left untouched to make
sure MinGW still compiles.
Task-number: QTBUG-84432
Pick-to: 6.2
Change-Id: I7a091fc967bd6b9d18ac2de39db16e3b4b9a76ea
Reviewed-by: André de la Rocha <andre.rocha@qt.io>
Diffstat (limited to 'src/network/kernel')
-rw-r--r-- | src/network/kernel/qauthenticator.cpp | 17 | ||||
-rw-r--r-- | src/network/kernel/qnetworkproxy_win.cpp | 142 |
2 files changed, 31 insertions, 128 deletions
diff --git a/src/network/kernel/qauthenticator.cpp b/src/network/kernel/qauthenticator.cpp index 6424120d4d..f7e8a205a1 100644 --- a/src/network/kernel/qauthenticator.cpp +++ b/src/network/kernel/qauthenticator.cpp @@ -1548,27 +1548,16 @@ static QByteArray qNtlmPhase3(QAuthenticatorPrivate *ctx, const QByteArray& phas // See http://davenport.sourceforge.net/ntlm.html // and libcurl http_ntlm.c -// Handle of secur32.dll -static HMODULE securityDLLHandle = nullptr; // Pointer to SSPI dispatch table -static PSecurityFunctionTable pSecurityFunctionTable = nullptr; +static PSecurityFunctionTableW pSecurityFunctionTable = nullptr; static bool q_SSPI_library_load() { static QBasicMutex mutex; QMutexLocker l(&mutex); - // Initialize security interface - if (pSecurityFunctionTable == nullptr) { - securityDLLHandle = LoadLibrary(L"secur32.dll"); - if (securityDLLHandle != nullptr) { - INIT_SECURITY_INTERFACE pInitSecurityInterface = - reinterpret_cast<INIT_SECURITY_INTERFACE>( - reinterpret_cast<QFunctionPointer>(GetProcAddress(securityDLLHandle, "InitSecurityInterfaceW"))); - if (pInitSecurityInterface != nullptr) - pSecurityFunctionTable = pInitSecurityInterface(); - } - } + if (pSecurityFunctionTable == nullptr) + pSecurityFunctionTable = InitSecurityInterfaceW(); if (pSecurityFunctionTable == nullptr) return false; diff --git a/src/network/kernel/qnetworkproxy_win.cpp b/src/network/kernel/qnetworkproxy_win.cpp index 30663917ce..b633cd9bbd 100644 --- a/src/network/kernel/qnetworkproxy_win.cpp +++ b/src/network/kernel/qnetworkproxy_win.cpp @@ -45,109 +45,34 @@ #include <qstringlist.h> #include <qregularexpression.h> #include <qurl.h> -#include <private/qsystemlibrary_p.h> #include <qnetworkinterface.h> #include <qdebug.h> #include <string.h> #include <qt_windows.h> -#include <wininet.h> #include <lmcons.h> - -/* - * Information on the WinHTTP DLL: - * http://msdn.microsoft.com/en-us/library/aa384122(VS.85).aspx example for WPAD - * - * http://msdn.microsoft.com/en-us/library/aa384097(VS.85).aspx WinHttpGetProxyForUrl - * http://msdn.microsoft.com/en-us/library/aa384096(VS.85).aspx WinHttpGetIEProxyConfigForCurrentUs - * http://msdn.microsoft.com/en-us/library/aa384095(VS.85).aspx WinHttpGetDefaultProxyConfiguration - */ - -// We don't want to include winhttp.h because that's not -// present in some Windows SDKs (I don't know why) -// So, instead, copy the definitions here - -typedef struct { - DWORD dwFlags; - DWORD dwAutoDetectFlags; - LPCWSTR lpszAutoConfigUrl; - LPVOID lpvReserved; - DWORD dwReserved; - BOOL fAutoLogonIfChallenged; -} WINHTTP_AUTOPROXY_OPTIONS; - -typedef struct { - DWORD dwAccessType; - LPWSTR lpszProxy; - LPWSTR lpszProxyBypass; -} WINHTTP_PROXY_INFO; - -typedef struct { - BOOL fAutoDetect; - LPWSTR lpszAutoConfigUrl; - LPWSTR lpszProxy; - LPWSTR lpszProxyBypass; -} WINHTTP_CURRENT_USER_IE_PROXY_CONFIG; - -#define WINHTTP_AUTOPROXY_AUTO_DETECT 0x00000001 -#define WINHTTP_AUTOPROXY_CONFIG_URL 0x00000002 - -#define WINHTTP_AUTO_DETECT_TYPE_DHCP 0x00000001 -#define WINHTTP_AUTO_DETECT_TYPE_DNS_A 0x00000002 - -#define WINHTTP_ACCESS_TYPE_DEFAULT_PROXY 0 -#define WINHTTP_ACCESS_TYPE_NO_PROXY 1 -#define WINHTTP_ACCESS_TYPE_NAMED_PROXY 3 - -#define WINHTTP_NO_PROXY_NAME NULL -#define WINHTTP_NO_PROXY_BYPASS NULL - -#define WINHTTP_ERROR_BASE 12000 -#define ERROR_WINHTTP_LOGIN_FAILURE (WINHTTP_ERROR_BASE + 15) -#define ERROR_WINHTTP_UNABLE_TO_DOWNLOAD_SCRIPT (WINHTTP_ERROR_BASE + 167) -#define ERROR_WINHTTP_AUTODETECTION_FAILED (WINHTTP_ERROR_BASE + 180) +#include <winhttp.h> QT_BEGIN_NAMESPACE -typedef BOOL (WINAPI * PtrWinHttpGetProxyForUrl)(HINTERNET, LPCWSTR, WINHTTP_AUTOPROXY_OPTIONS*, WINHTTP_PROXY_INFO*); -typedef HINTERNET (WINAPI * PtrWinHttpOpen)(LPCWSTR, DWORD, LPCWSTR, LPCWSTR,DWORD); -typedef BOOL (WINAPI * PtrWinHttpGetDefaultProxyConfiguration)(WINHTTP_PROXY_INFO*); -typedef BOOL (WINAPI * PtrWinHttpGetIEProxyConfigForCurrentUser)(WINHTTP_CURRENT_USER_IE_PROXY_CONFIG*); -typedef BOOL (WINAPI * PtrWinHttpCloseHandle)(HINTERNET); -typedef BOOL (WINAPI * PtrCloseServiceHandle)(SC_HANDLE hSCObject); -static PtrWinHttpGetProxyForUrl ptrWinHttpGetProxyForUrl = 0; -static PtrWinHttpOpen ptrWinHttpOpen = 0; -static PtrWinHttpGetDefaultProxyConfiguration ptrWinHttpGetDefaultProxyConfiguration = 0; -static PtrWinHttpGetIEProxyConfigForCurrentUser ptrWinHttpGetIEProxyConfigForCurrentUser = 0; -static PtrWinHttpCloseHandle ptrWinHttpCloseHandle = 0; - - static bool currentProcessIsService() { - typedef BOOL (WINAPI *PtrGetUserName)(LPTSTR lpBuffer, LPDWORD lpnSize); - typedef BOOL (WINAPI *PtrLookupAccountName)(LPCTSTR lpSystemName, LPCTSTR lpAccountName, PSID Sid, - LPDWORD cbSid, LPTSTR ReferencedDomainName, LPDWORD cchReferencedDomainName, PSID_NAME_USE peUse); - static PtrGetUserName ptrGetUserName = (PtrGetUserName)QSystemLibrary::resolve(QLatin1String("Advapi32"), "GetUserNameW"); - static PtrLookupAccountName ptrLookupAccountName = (PtrLookupAccountName)QSystemLibrary::resolve(QLatin1String("Advapi32"), "LookupAccountNameW"); - - if (ptrGetUserName && ptrLookupAccountName) { - wchar_t userName[UNLEN + 1] = L""; - DWORD size = UNLEN; - if (ptrGetUserName(userName, &size)) { - SID_NAME_USE type = SidTypeUser; - DWORD sidSize = 0; - DWORD domainSize = 0; - // first call is to get the correct size - bool bRet = ptrLookupAccountName(NULL, userName, NULL, &sidSize, NULL, &domainSize, &type); - if (bRet == FALSE && ERROR_INSUFFICIENT_BUFFER != GetLastError()) - return false; - QVarLengthArray<BYTE, 68> buff(sidSize); - QVarLengthArray<wchar_t, MAX_PATH> domainName(domainSize); - // second call to LookupAccountNameW actually gets the SID - // both the pointer to the buffer and the pointer to the domain name should not be NULL - if (ptrLookupAccountName(NULL, userName, buff.data(), &sidSize, domainName.data(), &domainSize, &type)) - return type != SidTypeUser; //returns true if the current user is not a user - } + wchar_t userName[UNLEN + 1] = L""; + DWORD size = UNLEN; + if (GetUserNameW(userName, &size)) { + SID_NAME_USE type = SidTypeUser; + DWORD sidSize = 0; + DWORD domainSize = 0; + // first call is to get the correct size + bool bRet = LookupAccountNameW(NULL, userName, NULL, &sidSize, NULL, &domainSize, &type); + if (bRet == FALSE && ERROR_INSUFFICIENT_BUFFER != GetLastError()) + return false; + QVarLengthArray<BYTE, 68> buff(sidSize); + QVarLengthArray<wchar_t, MAX_PATH> domainName(domainSize); + // second call to LookupAccountNameW actually gets the SID + // both the pointer to the buffer and the pointer to the domain name should not be NULL + if (LookupAccountNameW(NULL, userName, buff.data(), &sidSize, domainName.data(), &domainSize, &type)) + return type != SidTypeUser; //returns true if the current user is not a user } return false; } @@ -456,7 +381,7 @@ QWindowsSystemProxy::QWindowsSystemProxy() QWindowsSystemProxy::~QWindowsSystemProxy() { if (hHttpSession) - ptrWinHttpCloseHandle(hHttpSession); + WinHttpCloseHandle(hHttpSession); } void QWindowsSystemProxy::reset() @@ -486,20 +411,9 @@ void QWindowsSystemProxy::init() proxySettingsWatcher.addLocation(HKEY_LOCAL_MACHINE, QStringLiteral("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings")); proxySettingsWatcher.addLocation(HKEY_LOCAL_MACHINE, QStringLiteral("Software\\Policies\\Microsoft\\Windows\\CurrentVersion\\Internet Settings")); - // load the winhttp.dll library - QSystemLibrary lib(L"winhttp"); - if (!lib.load()) - return; // failed to load - - ptrWinHttpOpen = (PtrWinHttpOpen)lib.resolve("WinHttpOpen"); - ptrWinHttpCloseHandle = (PtrWinHttpCloseHandle)lib.resolve("WinHttpCloseHandle"); - ptrWinHttpGetProxyForUrl = (PtrWinHttpGetProxyForUrl)lib.resolve("WinHttpGetProxyForUrl"); - ptrWinHttpGetDefaultProxyConfiguration = (PtrWinHttpGetDefaultProxyConfiguration)lib.resolve("WinHttpGetDefaultProxyConfiguration"); - ptrWinHttpGetIEProxyConfigForCurrentUser = (PtrWinHttpGetIEProxyConfigForCurrentUser)lib.resolve("WinHttpGetIEProxyConfigForCurrentUser"); - // Try to obtain the Internet Explorer configuration. WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ieProxyConfig; - const bool hasIEConfig = ptrWinHttpGetIEProxyConfigForCurrentUser(&ieProxyConfig); + const bool hasIEConfig = WinHttpGetIEProxyConfigForCurrentUser(&ieProxyConfig); if (hasIEConfig) { if (ieProxyConfig.lpszAutoConfigUrl) { autoConfigUrl = QString::fromWCharArray(ieProxyConfig.lpszAutoConfigUrl); @@ -524,7 +438,7 @@ void QWindowsSystemProxy::init() // attempt to get the default configuration instead // that config will serve as default if WPAD fails WINHTTP_PROXY_INFO proxyInfo; - if (ptrWinHttpGetDefaultProxyConfiguration(&proxyInfo) && + if (WinHttpGetDefaultProxyConfiguration(&proxyInfo) && proxyInfo.dwAccessType == WINHTTP_ACCESS_TYPE_NAMED_PROXY) { // we got information from the registry // overwrite the IE configuration, if any @@ -542,11 +456,11 @@ void QWindowsSystemProxy::init() hHttpSession = NULL; if (ieProxyConfig.fAutoDetect || !autoConfigUrl.isEmpty()) { // open the handle and obtain the options - hHttpSession = ptrWinHttpOpen(L"Qt System Proxy access/1.0", - WINHTTP_ACCESS_TYPE_NO_PROXY, - WINHTTP_NO_PROXY_NAME, - WINHTTP_NO_PROXY_BYPASS, - 0); + hHttpSession = WinHttpOpen(L"Qt System Proxy access/1.0", + WINHTTP_ACCESS_TYPE_NO_PROXY, + WINHTTP_NO_PROXY_NAME, + WINHTTP_NO_PROXY_BYPASS, + 0); if (!hHttpSession) return; @@ -603,7 +517,7 @@ QList<QNetworkProxy> QNetworkProxyFactory::systemProxyForQuery(const QNetworkPro urlQueryString = url.toString().left(2083); } - bool getProxySucceeded = ptrWinHttpGetProxyForUrl(sp->hHttpSession, + bool getProxySucceeded = WinHttpGetProxyForUrl(sp->hHttpSession, reinterpret_cast<LPCWSTR>(urlQueryString.utf16()), &sp->autoProxyOptions, &proxyInfo); @@ -621,7 +535,7 @@ QList<QNetworkProxy> QNetworkProxyFactory::systemProxyForQuery(const QNetworkPro sp->autoProxyOptions.dwFlags = WINHTTP_AUTOPROXY_CONFIG_URL; sp->autoProxyOptions.lpszAutoConfigUrl = reinterpret_cast<LPCWSTR>(sp->autoConfigUrl.utf16()); - getProxySucceeded = ptrWinHttpGetProxyForUrl(sp->hHttpSession, + getProxySucceeded = WinHttpGetProxyForUrl(sp->hHttpSession, reinterpret_cast<LPCWSTR>(urlQueryString.utf16()), &sp->autoProxyOptions, &proxyInfo); @@ -634,7 +548,7 @@ QList<QNetworkProxy> QNetworkProxyFactory::systemProxyForQuery(const QNetworkPro // We first tried without AutoLogon, because this might prevent caching the result. // But now we've to enable it (http://msdn.microsoft.com/en-us/library/aa383153%28v=VS.85%29.aspx) sp->autoProxyOptions.fAutoLogonIfChallenged = TRUE; - getProxySucceeded = ptrWinHttpGetProxyForUrl(sp->hHttpSession, + getProxySucceeded = WinHttpGetProxyForUrl(sp->hHttpSession, reinterpret_cast<LPCWSTR>(urlQueryString.utf16()), &sp->autoProxyOptions, &proxyInfo); |