123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321 |
- #include "curl_setup.h"
- #if defined(_WIN32)
- #include <curl/curl.h>
- #include "version_win32.h"
- #include "warnless.h"
- #ifdef BUILDING_LIBCURL
- #include "curl_memory.h"
- #endif
- #include "memdebug.h"
- struct OUR_OSVERSIONINFOEXW {
- ULONG dwOSVersionInfoSize;
- ULONG dwMajorVersion;
- ULONG dwMinorVersion;
- ULONG dwBuildNumber;
- ULONG dwPlatformId;
- WCHAR szCSDVersion[128];
- USHORT wServicePackMajor;
- USHORT wServicePackMinor;
- USHORT wSuiteMask;
- UCHAR wProductType;
- UCHAR wReserved;
- };
- bool curlx_verify_windows_version(const unsigned int majorVersion,
- const unsigned int minorVersion,
- const unsigned int buildVersion,
- const PlatformIdentifier platform,
- const VersionCondition condition)
- {
- bool matched = FALSE;
- #if defined(CURL_WINDOWS_UWP)
-
- const WORD fullVersion = MAKEWORD(minorVersion, majorVersion);
- const WORD targetVersion = (WORD)_WIN32_WINNT;
- (void)buildVersion;
- switch(condition) {
- case VERSION_LESS_THAN:
- matched = targetVersion < fullVersion;
- break;
- case VERSION_LESS_THAN_EQUAL:
- matched = targetVersion <= fullVersion;
- break;
- case VERSION_EQUAL:
- matched = targetVersion == fullVersion;
- break;
- case VERSION_GREATER_THAN_EQUAL:
- matched = targetVersion >= fullVersion;
- break;
- case VERSION_GREATER_THAN:
- matched = targetVersion > fullVersion;
- break;
- }
- if(matched && (platform == PLATFORM_WINDOWS)) {
-
- matched = FALSE;
- }
- #elif !defined(_WIN32_WINNT) || !defined(_WIN32_WINNT_WIN2K) || \
- (_WIN32_WINNT < _WIN32_WINNT_WIN2K)
- OSVERSIONINFO osver;
- memset(&osver, 0, sizeof(osver));
- osver.dwOSVersionInfoSize = sizeof(osver);
-
- if(GetVersionEx(&osver)) {
-
- switch(condition) {
- case VERSION_LESS_THAN:
- if(osver.dwMajorVersion < majorVersion ||
- (osver.dwMajorVersion == majorVersion &&
- osver.dwMinorVersion < minorVersion) ||
- (buildVersion != 0 &&
- (osver.dwMajorVersion == majorVersion &&
- osver.dwMinorVersion == minorVersion &&
- osver.dwBuildNumber < buildVersion)))
- matched = TRUE;
- break;
- case VERSION_LESS_THAN_EQUAL:
- if(osver.dwMajorVersion < majorVersion ||
- (osver.dwMajorVersion == majorVersion &&
- osver.dwMinorVersion < minorVersion) ||
- (osver.dwMajorVersion == majorVersion &&
- osver.dwMinorVersion == minorVersion &&
- (buildVersion == 0 ||
- osver.dwBuildNumber <= buildVersion)))
- matched = TRUE;
- break;
- case VERSION_EQUAL:
- if(osver.dwMajorVersion == majorVersion &&
- osver.dwMinorVersion == minorVersion &&
- (buildVersion == 0 ||
- osver.dwBuildNumber == buildVersion))
- matched = TRUE;
- break;
- case VERSION_GREATER_THAN_EQUAL:
- if(osver.dwMajorVersion > majorVersion ||
- (osver.dwMajorVersion == majorVersion &&
- osver.dwMinorVersion > minorVersion) ||
- (osver.dwMajorVersion == majorVersion &&
- osver.dwMinorVersion == minorVersion &&
- (buildVersion == 0 ||
- osver.dwBuildNumber >= buildVersion)))
- matched = TRUE;
- break;
- case VERSION_GREATER_THAN:
- if(osver.dwMajorVersion > majorVersion ||
- (osver.dwMajorVersion == majorVersion &&
- osver.dwMinorVersion > minorVersion) ||
- (buildVersion != 0 &&
- (osver.dwMajorVersion == majorVersion &&
- osver.dwMinorVersion == minorVersion &&
- osver.dwBuildNumber > buildVersion)))
- matched = TRUE;
- break;
- }
-
- if(matched) {
- switch(platform) {
- case PLATFORM_WINDOWS:
- if(osver.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS)
- matched = FALSE;
- break;
- case PLATFORM_WINNT:
- if(osver.dwPlatformId != VER_PLATFORM_WIN32_NT)
- matched = FALSE;
- break;
- default:
- break;
- }
- }
- }
- #else
- ULONGLONG cm = 0;
- struct OUR_OSVERSIONINFOEXW osver;
- BYTE majorCondition;
- BYTE minorCondition;
- BYTE buildCondition;
- BYTE spMajorCondition;
- BYTE spMinorCondition;
- DWORD dwTypeMask = VER_MAJORVERSION | VER_MINORVERSION |
- VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR;
- typedef LONG (APIENTRY *RTLVERIFYVERSIONINFO_FN)
- (struct OUR_OSVERSIONINFOEXW *, ULONG, ULONGLONG);
- static RTLVERIFYVERSIONINFO_FN pRtlVerifyVersionInfo;
- static bool onetime = TRUE;
- if(onetime) {
- pRtlVerifyVersionInfo = CURLX_FUNCTION_CAST(RTLVERIFYVERSIONINFO_FN,
- (GetProcAddress(GetModuleHandleA("ntdll"), "RtlVerifyVersionInfo")));
- onetime = FALSE;
- }
- switch(condition) {
- case VERSION_LESS_THAN:
- majorCondition = VER_LESS;
- minorCondition = VER_LESS;
- buildCondition = VER_LESS;
- spMajorCondition = VER_LESS_EQUAL;
- spMinorCondition = VER_LESS_EQUAL;
- break;
- case VERSION_LESS_THAN_EQUAL:
- majorCondition = VER_LESS_EQUAL;
- minorCondition = VER_LESS_EQUAL;
- buildCondition = VER_LESS_EQUAL;
- spMajorCondition = VER_LESS_EQUAL;
- spMinorCondition = VER_LESS_EQUAL;
- break;
- case VERSION_EQUAL:
- majorCondition = VER_EQUAL;
- minorCondition = VER_EQUAL;
- buildCondition = VER_EQUAL;
- spMajorCondition = VER_GREATER_EQUAL;
- spMinorCondition = VER_GREATER_EQUAL;
- break;
- case VERSION_GREATER_THAN_EQUAL:
- majorCondition = VER_GREATER_EQUAL;
- minorCondition = VER_GREATER_EQUAL;
- buildCondition = VER_GREATER_EQUAL;
- spMajorCondition = VER_GREATER_EQUAL;
- spMinorCondition = VER_GREATER_EQUAL;
- break;
- case VERSION_GREATER_THAN:
- majorCondition = VER_GREATER;
- minorCondition = VER_GREATER;
- buildCondition = VER_GREATER;
- spMajorCondition = VER_GREATER_EQUAL;
- spMinorCondition = VER_GREATER_EQUAL;
- break;
- default:
- return FALSE;
- }
- memset(&osver, 0, sizeof(osver));
- osver.dwOSVersionInfoSize = sizeof(osver);
- osver.dwMajorVersion = majorVersion;
- osver.dwMinorVersion = minorVersion;
- osver.dwBuildNumber = buildVersion;
- if(platform == PLATFORM_WINDOWS)
- osver.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS;
- else if(platform == PLATFORM_WINNT)
- osver.dwPlatformId = VER_PLATFORM_WIN32_NT;
- cm = VerSetConditionMask(cm, VER_MAJORVERSION, majorCondition);
- cm = VerSetConditionMask(cm, VER_MINORVERSION, minorCondition);
- cm = VerSetConditionMask(cm, VER_SERVICEPACKMAJOR, spMajorCondition);
- cm = VerSetConditionMask(cm, VER_SERVICEPACKMINOR, spMinorCondition);
- if(platform != PLATFORM_DONT_CARE) {
- cm = VerSetConditionMask(cm, VER_PLATFORMID, VER_EQUAL);
- dwTypeMask |= VER_PLATFORMID;
- }
-
- if(pRtlVerifyVersionInfo)
- matched = !pRtlVerifyVersionInfo(&osver, dwTypeMask, cm);
- else
- matched = !!VerifyVersionInfoW((OSVERSIONINFOEXW *)&osver, dwTypeMask, cm);
-
- if(matched && buildVersion &&
- (condition == VERSION_EQUAL ||
- ((condition == VERSION_GREATER_THAN_EQUAL ||
- condition == VERSION_LESS_THAN_EQUAL) &&
- curlx_verify_windows_version(majorVersion, minorVersion, 0,
- platform, VERSION_EQUAL)))) {
- cm = VerSetConditionMask(0, VER_BUILDNUMBER, buildCondition);
- dwTypeMask = VER_BUILDNUMBER;
- if(pRtlVerifyVersionInfo)
- matched = !pRtlVerifyVersionInfo(&osver, dwTypeMask, cm);
- else
- matched = !!VerifyVersionInfoW((OSVERSIONINFOEXW *)&osver,
- dwTypeMask, cm);
- }
- #endif
- return matched;
- }
- #endif
|