mirror of
https://github.com/moparisthebest/curl
synced 2025-02-28 09:21:50 -05:00
win32: Add Curl_verify_windows_version() to curlx
Closes https://github.com/curl/curl/pull/5754
This commit is contained in:
parent
5c2728eb42
commit
790137b0f7
@ -60,7 +60,8 @@ LIB_CFILES = altsvc.c amigaos.c asyn-ares.c asyn-thread.c base64.c \
|
|||||||
sendf.c setopt.c sha256.c share.c slist.c smb.c smtp.c socketpair.c socks.c \
|
sendf.c setopt.c sha256.c share.c slist.c smb.c smtp.c socketpair.c socks.c \
|
||||||
socks_gssapi.c socks_sspi.c speedcheck.c splay.c strcase.c strdup.c \
|
socks_gssapi.c socks_sspi.c speedcheck.c splay.c strcase.c strdup.c \
|
||||||
strerror.c strtok.c strtoofft.c system_win32.c telnet.c tftp.c timeval.c \
|
strerror.c strtok.c strtoofft.c system_win32.c telnet.c tftp.c timeval.c \
|
||||||
transfer.c urlapi.c version.c warnless.c wildcard.c x509asn1.c dynbuf.c
|
transfer.c urlapi.c version.c warnless.c wildcard.c x509asn1.c dynbuf.c \
|
||||||
|
version_win32.c
|
||||||
|
|
||||||
LIB_HFILES = altsvc.h amigaos.h arpa_telnet.h asyn.h conncache.h connect.h \
|
LIB_HFILES = altsvc.h amigaos.h arpa_telnet.h asyn.h conncache.h connect.h \
|
||||||
content_encoding.h cookie.h curl_addrinfo.h curl_base64.h curl_ctype.h \
|
content_encoding.h cookie.h curl_addrinfo.h curl_base64.h curl_ctype.h \
|
||||||
@ -79,7 +80,7 @@ LIB_HFILES = altsvc.h amigaos.h arpa_telnet.h asyn.h conncache.h connect.h \
|
|||||||
smb.h smtp.h sockaddr.h socketpair.h socks.h speedcheck.h splay.h strcase.h \
|
smb.h smtp.h sockaddr.h socketpair.h socks.h speedcheck.h splay.h strcase.h \
|
||||||
strdup.h strerror.h strtok.h strtoofft.h system_win32.h telnet.h tftp.h \
|
strdup.h strerror.h strtok.h strtoofft.h system_win32.h telnet.h tftp.h \
|
||||||
timeval.h transfer.h urlapi-int.h urldata.h warnless.h wildcard.h \
|
timeval.h transfer.h urlapi-int.h urldata.h warnless.h wildcard.h \
|
||||||
x509asn1.h dynbuf.h
|
x509asn1.h dynbuf.h version_win32.h
|
||||||
|
|
||||||
LIB_RCFILES = libcurl.rc
|
LIB_RCFILES = libcurl.rc
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@
|
|||||||
#include "warnless.h"
|
#include "warnless.h"
|
||||||
#include "conncache.h"
|
#include "conncache.h"
|
||||||
#include "multihandle.h"
|
#include "multihandle.h"
|
||||||
#include "system_win32.h"
|
#include "version_win32.h"
|
||||||
#include "quic.h"
|
#include "quic.h"
|
||||||
#include "socks.h"
|
#include "socks.h"
|
||||||
|
|
||||||
@ -1085,8 +1085,8 @@ void Curl_sndbufset(curl_socket_t sockfd)
|
|||||||
static int detectOsState = DETECT_OS_NONE;
|
static int detectOsState = DETECT_OS_NONE;
|
||||||
|
|
||||||
if(detectOsState == DETECT_OS_NONE) {
|
if(detectOsState == DETECT_OS_NONE) {
|
||||||
if(Curl_verify_windows_version(6, 0, PLATFORM_WINNT,
|
if(curlx_verify_windows_version(6, 0, PLATFORM_WINNT,
|
||||||
VERSION_GREATER_THAN_EQUAL))
|
VERSION_GREATER_THAN_EQUAL))
|
||||||
detectOsState = DETECT_OS_VISTA_OR_LATER;
|
detectOsState = DETECT_OS_VISTA_OR_LATER;
|
||||||
else
|
else
|
||||||
detectOsState = DETECT_OS_PREVISTA;
|
detectOsState = DETECT_OS_PREVISTA;
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "curl_sspi.h"
|
#include "curl_sspi.h"
|
||||||
#include "curl_multibyte.h"
|
#include "curl_multibyte.h"
|
||||||
#include "system_win32.h"
|
#include "system_win32.h"
|
||||||
|
#include "version_win32.h"
|
||||||
#include "warnless.h"
|
#include "warnless.h"
|
||||||
|
|
||||||
/* The last #include files should be: */
|
/* The last #include files should be: */
|
||||||
@ -82,7 +83,7 @@ CURLcode Curl_sspi_global_init(void)
|
|||||||
* have both these DLLs (security.dll forwards calls to secur32.dll) */
|
* have both these DLLs (security.dll forwards calls to secur32.dll) */
|
||||||
|
|
||||||
/* Load SSPI dll into the address space of the calling process */
|
/* Load SSPI dll into the address space of the calling process */
|
||||||
if(Curl_verify_windows_version(4, 0, PLATFORM_WINNT, VERSION_EQUAL))
|
if(curlx_verify_windows_version(4, 0, PLATFORM_WINNT, VERSION_EQUAL))
|
||||||
s_hSecDll = Curl_load_library(TEXT("security.dll"));
|
s_hSecDll = Curl_load_library(TEXT("security.dll"));
|
||||||
else
|
else
|
||||||
s_hSecDll = Curl_load_library(TEXT("secur32.dll"));
|
s_hSecDll = Curl_load_library(TEXT("secur32.dll"));
|
||||||
|
@ -63,6 +63,9 @@
|
|||||||
curlx_unicodefree()
|
curlx_unicodefree()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "version_win32.h"
|
||||||
|
/* "version_win32.h" provides curlx_verify_windows_version() */
|
||||||
|
|
||||||
/* Now setup curlx_ * names for the functions that are to become curlx_ and
|
/* Now setup curlx_ * names for the functions that are to become curlx_ and
|
||||||
be removed from a future libcurl official API:
|
be removed from a future libcurl official API:
|
||||||
curlx_getenv
|
curlx_getenv
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include "system_win32.h"
|
#include "system_win32.h"
|
||||||
|
#include "version_win32.h"
|
||||||
#include "curl_sspi.h"
|
#include "curl_sspi.h"
|
||||||
#include "warnless.h"
|
#include "warnless.h"
|
||||||
|
|
||||||
@ -106,8 +107,8 @@ CURLcode Curl_win32_init(long flags)
|
|||||||
Curl_if_nametoindex = pIfNameToIndex;
|
Curl_if_nametoindex = pIfNameToIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Curl_verify_windows_version(6, 0, PLATFORM_WINNT,
|
if(curlx_verify_windows_version(6, 0, PLATFORM_WINNT,
|
||||||
VERSION_GREATER_THAN_EQUAL)) {
|
VERSION_GREATER_THAN_EQUAL)) {
|
||||||
Curl_isVistaOrGreater = TRUE;
|
Curl_isVistaOrGreater = TRUE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -159,198 +160,6 @@ typedef HMODULE (APIENTRY *LOADLIBRARYEX_FN)(LPCTSTR, HANDLE, DWORD);
|
|||||||
# define LOADLIBARYEX "LoadLibraryExA"
|
# define LOADLIBARYEX "LoadLibraryExA"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
|
||||||
* Curl_verify_windows_version()
|
|
||||||
*
|
|
||||||
* This is used to verify if we are running on a specific windows version.
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
*
|
|
||||||
* majorVersion [in] - The major version number.
|
|
||||||
* minorVersion [in] - The minor version number.
|
|
||||||
* platform [in] - The optional platform identifier.
|
|
||||||
* condition [in] - The test condition used to specifier whether we are
|
|
||||||
* checking a version less then, equal to or greater than
|
|
||||||
* what is specified in the major and minor version
|
|
||||||
* numbers.
|
|
||||||
*
|
|
||||||
* Returns TRUE if matched; otherwise FALSE.
|
|
||||||
*/
|
|
||||||
bool Curl_verify_windows_version(const unsigned int majorVersion,
|
|
||||||
const unsigned int minorVersion,
|
|
||||||
const PlatformIdentifier platform,
|
|
||||||
const VersionCondition condition)
|
|
||||||
{
|
|
||||||
bool matched = FALSE;
|
|
||||||
|
|
||||||
#if defined(CURL_WINDOWS_APP)
|
|
||||||
/* We have no way to determine the Windows version from Windows apps,
|
|
||||||
so let's assume we're running on the target Windows version. */
|
|
||||||
const WORD fullVersion = MAKEWORD(minorVersion, majorVersion);
|
|
||||||
const WORD targetVersion = (WORD)_WIN32_WINNT;
|
|
||||||
|
|
||||||
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)) {
|
|
||||||
/* we're always running on PLATFORM_WINNT */
|
|
||||||
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);
|
|
||||||
|
|
||||||
/* Find out Windows version */
|
|
||||||
if(GetVersionEx(&osver)) {
|
|
||||||
/* Verify the Operating System version number */
|
|
||||||
switch(condition) {
|
|
||||||
case VERSION_LESS_THAN:
|
|
||||||
if(osver.dwMajorVersion < majorVersion ||
|
|
||||||
(osver.dwMajorVersion == majorVersion &&
|
|
||||||
osver.dwMinorVersion < minorVersion))
|
|
||||||
matched = TRUE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VERSION_LESS_THAN_EQUAL:
|
|
||||||
if(osver.dwMajorVersion < majorVersion ||
|
|
||||||
(osver.dwMajorVersion == majorVersion &&
|
|
||||||
osver.dwMinorVersion <= minorVersion))
|
|
||||||
matched = TRUE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VERSION_EQUAL:
|
|
||||||
if(osver.dwMajorVersion == majorVersion &&
|
|
||||||
osver.dwMinorVersion == minorVersion)
|
|
||||||
matched = TRUE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VERSION_GREATER_THAN_EQUAL:
|
|
||||||
if(osver.dwMajorVersion > majorVersion ||
|
|
||||||
(osver.dwMajorVersion == majorVersion &&
|
|
||||||
osver.dwMinorVersion >= minorVersion))
|
|
||||||
matched = TRUE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VERSION_GREATER_THAN:
|
|
||||||
if(osver.dwMajorVersion > majorVersion ||
|
|
||||||
(osver.dwMajorVersion == majorVersion &&
|
|
||||||
osver.dwMinorVersion > minorVersion))
|
|
||||||
matched = TRUE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Verify the platform identifier (if necessary) */
|
|
||||||
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;
|
|
||||||
|
|
||||||
default: /* like platform == PLATFORM_DONT_CARE */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
ULONGLONG cm = 0;
|
|
||||||
OSVERSIONINFOEX osver;
|
|
||||||
BYTE majorCondition;
|
|
||||||
BYTE minorCondition;
|
|
||||||
BYTE spMajorCondition;
|
|
||||||
BYTE spMinorCondition;
|
|
||||||
|
|
||||||
switch(condition) {
|
|
||||||
case VERSION_LESS_THAN:
|
|
||||||
majorCondition = VER_LESS;
|
|
||||||
minorCondition = VER_LESS;
|
|
||||||
spMajorCondition = VER_LESS_EQUAL;
|
|
||||||
spMinorCondition = VER_LESS_EQUAL;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VERSION_LESS_THAN_EQUAL:
|
|
||||||
majorCondition = VER_LESS_EQUAL;
|
|
||||||
minorCondition = VER_LESS_EQUAL;
|
|
||||||
spMajorCondition = VER_LESS_EQUAL;
|
|
||||||
spMinorCondition = VER_LESS_EQUAL;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VERSION_EQUAL:
|
|
||||||
majorCondition = VER_EQUAL;
|
|
||||||
minorCondition = VER_EQUAL;
|
|
||||||
spMajorCondition = VER_GREATER_EQUAL;
|
|
||||||
spMinorCondition = VER_GREATER_EQUAL;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VERSION_GREATER_THAN_EQUAL:
|
|
||||||
majorCondition = VER_GREATER_EQUAL;
|
|
||||||
minorCondition = VER_GREATER_EQUAL;
|
|
||||||
spMajorCondition = VER_GREATER_EQUAL;
|
|
||||||
spMinorCondition = VER_GREATER_EQUAL;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VERSION_GREATER_THAN:
|
|
||||||
majorCondition = VER_GREATER;
|
|
||||||
minorCondition = 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;
|
|
||||||
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);
|
|
||||||
|
|
||||||
if(VerifyVersionInfo(&osver, (VER_MAJORVERSION | VER_MINORVERSION |
|
|
||||||
VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR),
|
|
||||||
cm))
|
|
||||||
matched = TRUE;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return matched;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Curl_load_library()
|
* Curl_load_library()
|
||||||
*
|
*
|
||||||
|
@ -32,34 +32,12 @@ extern bool Curl_isVistaOrGreater;
|
|||||||
CURLcode Curl_win32_init(long flags);
|
CURLcode Curl_win32_init(long flags);
|
||||||
void Curl_win32_cleanup(long init_flags);
|
void Curl_win32_cleanup(long init_flags);
|
||||||
|
|
||||||
/* Version condition */
|
|
||||||
typedef enum {
|
|
||||||
VERSION_LESS_THAN,
|
|
||||||
VERSION_LESS_THAN_EQUAL,
|
|
||||||
VERSION_EQUAL,
|
|
||||||
VERSION_GREATER_THAN_EQUAL,
|
|
||||||
VERSION_GREATER_THAN
|
|
||||||
} VersionCondition;
|
|
||||||
|
|
||||||
/* Platform identifier */
|
|
||||||
typedef enum {
|
|
||||||
PLATFORM_DONT_CARE,
|
|
||||||
PLATFORM_WINDOWS,
|
|
||||||
PLATFORM_WINNT
|
|
||||||
} PlatformIdentifier;
|
|
||||||
|
|
||||||
/* We use our own typedef here since some headers might lack this */
|
/* We use our own typedef here since some headers might lack this */
|
||||||
typedef unsigned int(WINAPI *IF_NAMETOINDEX_FN)(const char *);
|
typedef unsigned int(WINAPI *IF_NAMETOINDEX_FN)(const char *);
|
||||||
|
|
||||||
/* This is used instead of if_nametoindex if available on Windows */
|
/* This is used instead of if_nametoindex if available on Windows */
|
||||||
extern IF_NAMETOINDEX_FN Curl_if_nametoindex;
|
extern IF_NAMETOINDEX_FN Curl_if_nametoindex;
|
||||||
|
|
||||||
/* This is used to verify if we are running on a specific windows version */
|
|
||||||
bool Curl_verify_windows_version(const unsigned int majorVersion,
|
|
||||||
const unsigned int minorVersion,
|
|
||||||
const PlatformIdentifier platform,
|
|
||||||
const VersionCondition condition);
|
|
||||||
|
|
||||||
/* This is used to dynamically load DLLs */
|
/* This is used to dynamically load DLLs */
|
||||||
HMODULE Curl_load_library(LPCTSTR filename);
|
HMODULE Curl_load_library(LPCTSTR filename);
|
||||||
|
|
||||||
|
226
lib/version_win32.c
Normal file
226
lib/version_win32.c
Normal file
@ -0,0 +1,226 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 2016 - 2020, Steve Holme, <steve_holme@hotmail.com>.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at https://curl.haxx.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include "curl_setup.h"
|
||||||
|
|
||||||
|
#if defined(WIN32)
|
||||||
|
|
||||||
|
#include <curl/curl.h>
|
||||||
|
#include "version_win32.h"
|
||||||
|
|
||||||
|
/* The last #include files should be: */
|
||||||
|
#include "curl_memory.h"
|
||||||
|
#include "memdebug.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* curlx_verify_windows_version()
|
||||||
|
*
|
||||||
|
* This is used to verify if we are running on a specific windows version.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
*
|
||||||
|
* majorVersion [in] - The major version number.
|
||||||
|
* minorVersion [in] - The minor version number.
|
||||||
|
* platform [in] - The optional platform identifier.
|
||||||
|
* condition [in] - The test condition used to specifier whether we are
|
||||||
|
* checking a version less then, equal to or greater than
|
||||||
|
* what is specified in the major and minor version
|
||||||
|
* numbers.
|
||||||
|
*
|
||||||
|
* Returns TRUE if matched; otherwise FALSE.
|
||||||
|
*/
|
||||||
|
bool curlx_verify_windows_version(const unsigned int majorVersion,
|
||||||
|
const unsigned int minorVersion,
|
||||||
|
const PlatformIdentifier platform,
|
||||||
|
const VersionCondition condition)
|
||||||
|
{
|
||||||
|
bool matched = FALSE;
|
||||||
|
|
||||||
|
#if defined(CURL_WINDOWS_APP)
|
||||||
|
/* We have no way to determine the Windows version from Windows apps,
|
||||||
|
so let's assume we're running on the target Windows version. */
|
||||||
|
const WORD fullVersion = MAKEWORD(minorVersion, majorVersion);
|
||||||
|
const WORD targetVersion = (WORD)_WIN32_WINNT;
|
||||||
|
|
||||||
|
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)) {
|
||||||
|
/* we're always running on PLATFORM_WINNT */
|
||||||
|
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);
|
||||||
|
|
||||||
|
/* Find out Windows version */
|
||||||
|
if(GetVersionEx(&osver)) {
|
||||||
|
/* Verify the Operating System version number */
|
||||||
|
switch(condition) {
|
||||||
|
case VERSION_LESS_THAN:
|
||||||
|
if(osver.dwMajorVersion < majorVersion ||
|
||||||
|
(osver.dwMajorVersion == majorVersion &&
|
||||||
|
osver.dwMinorVersion < minorVersion))
|
||||||
|
matched = TRUE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VERSION_LESS_THAN_EQUAL:
|
||||||
|
if(osver.dwMajorVersion < majorVersion ||
|
||||||
|
(osver.dwMajorVersion == majorVersion &&
|
||||||
|
osver.dwMinorVersion <= minorVersion))
|
||||||
|
matched = TRUE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VERSION_EQUAL:
|
||||||
|
if(osver.dwMajorVersion == majorVersion &&
|
||||||
|
osver.dwMinorVersion == minorVersion)
|
||||||
|
matched = TRUE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VERSION_GREATER_THAN_EQUAL:
|
||||||
|
if(osver.dwMajorVersion > majorVersion ||
|
||||||
|
(osver.dwMajorVersion == majorVersion &&
|
||||||
|
osver.dwMinorVersion >= minorVersion))
|
||||||
|
matched = TRUE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VERSION_GREATER_THAN:
|
||||||
|
if(osver.dwMajorVersion > majorVersion ||
|
||||||
|
(osver.dwMajorVersion == majorVersion &&
|
||||||
|
osver.dwMinorVersion > minorVersion))
|
||||||
|
matched = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Verify the platform identifier (if necessary) */
|
||||||
|
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;
|
||||||
|
|
||||||
|
default: /* like platform == PLATFORM_DONT_CARE */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
ULONGLONG cm = 0;
|
||||||
|
OSVERSIONINFOEX osver;
|
||||||
|
BYTE majorCondition;
|
||||||
|
BYTE minorCondition;
|
||||||
|
BYTE spMajorCondition;
|
||||||
|
BYTE spMinorCondition;
|
||||||
|
|
||||||
|
switch(condition) {
|
||||||
|
case VERSION_LESS_THAN:
|
||||||
|
majorCondition = VER_LESS;
|
||||||
|
minorCondition = VER_LESS;
|
||||||
|
spMajorCondition = VER_LESS_EQUAL;
|
||||||
|
spMinorCondition = VER_LESS_EQUAL;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VERSION_LESS_THAN_EQUAL:
|
||||||
|
majorCondition = VER_LESS_EQUAL;
|
||||||
|
minorCondition = VER_LESS_EQUAL;
|
||||||
|
spMajorCondition = VER_LESS_EQUAL;
|
||||||
|
spMinorCondition = VER_LESS_EQUAL;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VERSION_EQUAL:
|
||||||
|
majorCondition = VER_EQUAL;
|
||||||
|
minorCondition = VER_EQUAL;
|
||||||
|
spMajorCondition = VER_GREATER_EQUAL;
|
||||||
|
spMinorCondition = VER_GREATER_EQUAL;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VERSION_GREATER_THAN_EQUAL:
|
||||||
|
majorCondition = VER_GREATER_EQUAL;
|
||||||
|
minorCondition = VER_GREATER_EQUAL;
|
||||||
|
spMajorCondition = VER_GREATER_EQUAL;
|
||||||
|
spMinorCondition = VER_GREATER_EQUAL;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VERSION_GREATER_THAN:
|
||||||
|
majorCondition = VER_GREATER;
|
||||||
|
minorCondition = 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;
|
||||||
|
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);
|
||||||
|
|
||||||
|
if(VerifyVersionInfo(&osver, (VER_MAJORVERSION | VER_MINORVERSION |
|
||||||
|
VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR),
|
||||||
|
cm))
|
||||||
|
matched = TRUE;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return matched;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* WIN32 */
|
53
lib/version_win32.h
Normal file
53
lib/version_win32.h
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#ifndef HEADER_CURL_VERSION_WIN32_H
|
||||||
|
#define HEADER_CURL_VERSION_WIN32_H
|
||||||
|
/***************************************************************************
|
||||||
|
* _ _ ____ _
|
||||||
|
* Project ___| | | | _ \| |
|
||||||
|
* / __| | | | |_) | |
|
||||||
|
* | (__| |_| | _ <| |___
|
||||||
|
* \___|\___/|_| \_\_____|
|
||||||
|
*
|
||||||
|
* Copyright (C) 2016 - 2019, Steve Holme, <steve_holme@hotmail.com>.
|
||||||
|
*
|
||||||
|
* This software is licensed as described in the file COPYING, which
|
||||||
|
* you should have received as part of this distribution. The terms
|
||||||
|
* are also available at https://curl.haxx.se/docs/copyright.html.
|
||||||
|
*
|
||||||
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||||
|
* copies of the Software, and permit persons to whom the Software is
|
||||||
|
* furnished to do so, under the terms of the COPYING file.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include "curl_setup.h"
|
||||||
|
|
||||||
|
#if defined(WIN32)
|
||||||
|
|
||||||
|
/* Version condition */
|
||||||
|
typedef enum {
|
||||||
|
VERSION_LESS_THAN,
|
||||||
|
VERSION_LESS_THAN_EQUAL,
|
||||||
|
VERSION_EQUAL,
|
||||||
|
VERSION_GREATER_THAN_EQUAL,
|
||||||
|
VERSION_GREATER_THAN
|
||||||
|
} VersionCondition;
|
||||||
|
|
||||||
|
/* Platform identifier */
|
||||||
|
typedef enum {
|
||||||
|
PLATFORM_DONT_CARE,
|
||||||
|
PLATFORM_WINDOWS,
|
||||||
|
PLATFORM_WINNT
|
||||||
|
} PlatformIdentifier;
|
||||||
|
|
||||||
|
/* This is used to verify if we are running on a specific windows version */
|
||||||
|
bool curlx_verify_windows_version(const unsigned int majorVersion,
|
||||||
|
const unsigned int minorVersion,
|
||||||
|
const PlatformIdentifier platform,
|
||||||
|
const VersionCondition condition);
|
||||||
|
|
||||||
|
#endif /* WIN32 */
|
||||||
|
|
||||||
|
#endif /* HEADER_CURL_VERSION_WIN32_H */
|
@ -50,7 +50,7 @@
|
|||||||
#include "x509asn1.h"
|
#include "x509asn1.h"
|
||||||
#include "curl_printf.h"
|
#include "curl_printf.h"
|
||||||
#include "multiif.h"
|
#include "multiif.h"
|
||||||
#include "system_win32.h"
|
#include "version_win32.h"
|
||||||
|
|
||||||
/* The last #include file should be: */
|
/* The last #include file should be: */
|
||||||
#include "curl_memory.h"
|
#include "curl_memory.h"
|
||||||
@ -436,8 +436,8 @@ schannel_connect_step1(struct connectdata *conn, int sockindex)
|
|||||||
"schannel: SSL/TLS connection with %s port %hu (step 1/3)\n",
|
"schannel: SSL/TLS connection with %s port %hu (step 1/3)\n",
|
||||||
hostname, conn->remote_port));
|
hostname, conn->remote_port));
|
||||||
|
|
||||||
if(Curl_verify_windows_version(5, 1, PLATFORM_WINNT,
|
if(curlx_verify_windows_version(5, 1, PLATFORM_WINNT,
|
||||||
VERSION_LESS_THAN_EQUAL)) {
|
VERSION_LESS_THAN_EQUAL)) {
|
||||||
/* Schannel in Windows XP (OS version 5.1) uses legacy handshakes and
|
/* Schannel in Windows XP (OS version 5.1) uses legacy handshakes and
|
||||||
algorithms that may not be supported by all servers. */
|
algorithms that may not be supported by all servers. */
|
||||||
infof(data, "schannel: Windows version is old and may not be able to "
|
infof(data, "schannel: Windows version is old and may not be able to "
|
||||||
@ -450,8 +450,8 @@ schannel_connect_step1(struct connectdata *conn, int sockindex)
|
|||||||
BACKEND->use_alpn = conn->bits.tls_enable_alpn &&
|
BACKEND->use_alpn = conn->bits.tls_enable_alpn &&
|
||||||
!GetProcAddress(GetModuleHandle(TEXT("ntdll")),
|
!GetProcAddress(GetModuleHandle(TEXT("ntdll")),
|
||||||
"wine_get_version") &&
|
"wine_get_version") &&
|
||||||
Curl_verify_windows_version(6, 3, PLATFORM_WINNT,
|
curlx_verify_windows_version(6, 3, PLATFORM_WINNT,
|
||||||
VERSION_GREATER_THAN_EQUAL);
|
VERSION_GREATER_THAN_EQUAL);
|
||||||
#else
|
#else
|
||||||
BACKEND->use_alpn = false;
|
BACKEND->use_alpn = false;
|
||||||
#endif
|
#endif
|
||||||
@ -467,8 +467,8 @@ schannel_connect_step1(struct connectdata *conn, int sockindex)
|
|||||||
#else
|
#else
|
||||||
#ifdef HAS_MANUAL_VERIFY_API
|
#ifdef HAS_MANUAL_VERIFY_API
|
||||||
if(SSL_CONN_CONFIG(CAfile)) {
|
if(SSL_CONN_CONFIG(CAfile)) {
|
||||||
if(Curl_verify_windows_version(6, 1, PLATFORM_WINNT,
|
if(curlx_verify_windows_version(6, 1, PLATFORM_WINNT,
|
||||||
VERSION_GREATER_THAN_EQUAL)) {
|
VERSION_GREATER_THAN_EQUAL)) {
|
||||||
BACKEND->use_manual_cred_validation = true;
|
BACKEND->use_manual_cred_validation = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -2015,8 +2015,8 @@ schannel_recv(struct connectdata *conn, int sockindex,
|
|||||||
*/
|
*/
|
||||||
if(len && !BACKEND->decdata_offset && BACKEND->recv_connection_closed &&
|
if(len && !BACKEND->decdata_offset && BACKEND->recv_connection_closed &&
|
||||||
!BACKEND->recv_sspi_close_notify) {
|
!BACKEND->recv_sspi_close_notify) {
|
||||||
bool isWin2k = Curl_verify_windows_version(5, 0, PLATFORM_WINNT,
|
bool isWin2k = curlx_verify_windows_version(5, 0, PLATFORM_WINNT,
|
||||||
VERSION_EQUAL);
|
VERSION_EQUAL);
|
||||||
|
|
||||||
if(isWin2k && sspi_status == SEC_E_OK)
|
if(isWin2k && sspi_status == SEC_E_OK)
|
||||||
BACKEND->recv_sspi_close_notify = true;
|
BACKEND->recv_sspi_close_notify = true;
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
#include "curl_multibyte.h"
|
#include "curl_multibyte.h"
|
||||||
#include "curl_printf.h"
|
#include "curl_printf.h"
|
||||||
#include "hostcheck.h"
|
#include "hostcheck.h"
|
||||||
#include "system_win32.h"
|
#include "version_win32.h"
|
||||||
|
|
||||||
/* The last #include file should be: */
|
/* The last #include file should be: */
|
||||||
#include "curl_memory.h"
|
#include "curl_memory.h"
|
||||||
@ -317,8 +317,8 @@ static DWORD cert_get_name_string(struct Curl_easy *data,
|
|||||||
DWORD i;
|
DWORD i;
|
||||||
|
|
||||||
/* CERT_NAME_SEARCH_ALL_NAMES_FLAG is available from Windows 8 onwards. */
|
/* CERT_NAME_SEARCH_ALL_NAMES_FLAG is available from Windows 8 onwards. */
|
||||||
if(Curl_verify_windows_version(6, 2, PLATFORM_WINNT,
|
if(curlx_verify_windows_version(6, 2, PLATFORM_WINNT,
|
||||||
VERSION_GREATER_THAN_EQUAL)) {
|
VERSION_GREATER_THAN_EQUAL)) {
|
||||||
#ifdef CERT_NAME_SEARCH_ALL_NAMES_FLAG
|
#ifdef CERT_NAME_SEARCH_ALL_NAMES_FLAG
|
||||||
/* CertGetNameString will provide the 8-bit character string without
|
/* CertGetNameString will provide the 8-bit character string without
|
||||||
* any decoding */
|
* any decoding */
|
||||||
@ -564,7 +564,7 @@ CURLcode Curl_verify_certificate(struct connectdata *conn, int sockindex)
|
|||||||
* trusted certificates. This is only supported on Windows 7+.
|
* trusted certificates. This is only supported on Windows 7+.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if(Curl_verify_windows_version(6, 1, PLATFORM_WINNT, VERSION_LESS_THAN)) {
|
if(curlx_verify_windows_version(6, 1, PLATFORM_WINNT, VERSION_LESS_THAN)) {
|
||||||
failf(data, "schannel: this version of Windows is too old to support "
|
failf(data, "schannel: this version of Windows is too old to support "
|
||||||
"certificate verification via CA bundle file.");
|
"certificate verification via CA bundle file.");
|
||||||
result = CURLE_SSL_CACERT_BADFILE;
|
result = CURLE_SSL_CACERT_BADFILE;
|
||||||
|
@ -286,6 +286,7 @@ rem
|
|||||||
call :element %1 lib "warnless.c" %3
|
call :element %1 lib "warnless.c" %3
|
||||||
call :element %1 lib "curl_ctype.c" %3
|
call :element %1 lib "curl_ctype.c" %3
|
||||||
call :element %1 lib "curl_multibyte.c" %3
|
call :element %1 lib "curl_multibyte.c" %3
|
||||||
|
call :element %1 lib "version_win32.c" %3
|
||||||
) else if "!var!" == "CURL_SRC_X_H_FILES" (
|
) else if "!var!" == "CURL_SRC_X_H_FILES" (
|
||||||
call :element %1 lib "config-win32.h" %3
|
call :element %1 lib "config-win32.h" %3
|
||||||
call :element %1 lib "curl_setup.h" %3
|
call :element %1 lib "curl_setup.h" %3
|
||||||
@ -294,6 +295,7 @@ rem
|
|||||||
call :element %1 lib "warnless.h" %3
|
call :element %1 lib "warnless.h" %3
|
||||||
call :element %1 lib "curl_ctype.h" %3
|
call :element %1 lib "curl_ctype.h" %3
|
||||||
call :element %1 lib "curl_multibyte.h" %3
|
call :element %1 lib "curl_multibyte.h" %3
|
||||||
|
call :element %1 lib "version_win32.h" %3
|
||||||
) else if "!var!" == "CURL_LIB_C_FILES" (
|
) else if "!var!" == "CURL_LIB_C_FILES" (
|
||||||
for /f "delims=" %%c in ('dir /b ..\lib\*.c') do call :element %1 lib "%%c" %3
|
for /f "delims=" %%c in ('dir /b ..\lib\*.c') do call :element %1 lib "%%c" %3
|
||||||
) else if "!var!" == "CURL_LIB_H_FILES" (
|
) else if "!var!" == "CURL_LIB_H_FILES" (
|
||||||
|
@ -35,7 +35,8 @@ CURLX_CFILES = \
|
|||||||
../lib/nonblock.c \
|
../lib/nonblock.c \
|
||||||
../lib/warnless.c \
|
../lib/warnless.c \
|
||||||
../lib/curl_ctype.c \
|
../lib/curl_ctype.c \
|
||||||
../lib/curl_multibyte.c
|
../lib/curl_multibyte.c \
|
||||||
|
../lib/version_win32.c
|
||||||
|
|
||||||
CURLX_HFILES = \
|
CURLX_HFILES = \
|
||||||
../lib/curl_setup.h \
|
../lib/curl_setup.h \
|
||||||
@ -43,7 +44,8 @@ CURLX_HFILES = \
|
|||||||
../lib/nonblock.h \
|
../lib/nonblock.h \
|
||||||
../lib/warnless.h \
|
../lib/warnless.h \
|
||||||
../lib/curl_ctype.h \
|
../lib/curl_ctype.h \
|
||||||
../lib/curl_multibyte.h
|
../lib/curl_multibyte.h \
|
||||||
|
../lib/version_win32.h
|
||||||
|
|
||||||
CURL_CFILES = \
|
CURL_CFILES = \
|
||||||
slist_wc.c \
|
slist_wc.c \
|
||||||
|
@ -619,7 +619,8 @@ CURL_FROM_LIBCURL=$(CURL_DIROBJ)\tool_hugehelp.obj \
|
|||||||
$(CURL_DIROBJ)\strtoofft.obj \
|
$(CURL_DIROBJ)\strtoofft.obj \
|
||||||
$(CURL_DIROBJ)\warnless.obj \
|
$(CURL_DIROBJ)\warnless.obj \
|
||||||
$(CURL_DIROBJ)\curl_ctype.obj \
|
$(CURL_DIROBJ)\curl_ctype.obj \
|
||||||
$(CURL_DIROBJ)\curl_multibyte.obj
|
$(CURL_DIROBJ)\curl_multibyte.obj \
|
||||||
|
$(CURL_DIROBJ)\version_win32.obj
|
||||||
|
|
||||||
$(PROGRAM_NAME): $(CURL_DIROBJ) $(CURL_FROM_LIBCURL) $(EXE_OBJS)
|
$(PROGRAM_NAME): $(CURL_DIROBJ) $(CURL_FROM_LIBCURL) $(EXE_OBJS)
|
||||||
$(CURL_LINK) $(CURL_LFLAGS) $(CURL_LIBCURL_LIBNAME) $(WIN_LIBS) $(CURL_FROM_LIBCURL) $(EXE_OBJS)
|
$(CURL_LINK) $(CURL_LFLAGS) $(CURL_LIBCURL_LIBNAME) $(WIN_LIBS) $(CURL_FROM_LIBCURL) $(EXE_OBJS)
|
||||||
@ -640,6 +641,8 @@ $(CURL_DIROBJ)\curl_ctype.obj: ../lib/curl_ctype.c
|
|||||||
$(CURL_CC) $(CURL_CFLAGS) /Fo"$@" ../lib/curl_ctype.c
|
$(CURL_CC) $(CURL_CFLAGS) /Fo"$@" ../lib/curl_ctype.c
|
||||||
$(CURL_DIROBJ)\curl_multibyte.obj: ../lib/curl_multibyte.c
|
$(CURL_DIROBJ)\curl_multibyte.obj: ../lib/curl_multibyte.c
|
||||||
$(CURL_CC) $(CURL_CFLAGS) /Fo"$@" ../lib/curl_multibyte.c
|
$(CURL_CC) $(CURL_CFLAGS) /Fo"$@" ../lib/curl_multibyte.c
|
||||||
|
$(CURL_DIROBJ)\version_win32.obj: ../lib/version_win32.c
|
||||||
|
$(CURL_CC) $(CURL_CFLAGS) /Fo"$@" ../lib/version_win32.c
|
||||||
$(CURL_DIROBJ)\curl.res: $(CURL_SRC_DIR)\curl.rc
|
$(CURL_DIROBJ)\curl.res: $(CURL_SRC_DIR)\curl.rc
|
||||||
rc $(CURL_RC_FLAGS)
|
rc $(CURL_RC_FLAGS)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user