]> granicus.if.org Git - curl/commitdiff
win32: Fixed use of deprecated function 'GetVersionInfoEx' for VC12
authorSteve Holme <steve_holme@hotmail.com>
Wed, 15 Jan 2014 20:11:02 +0000 (20:11 +0000)
committerSteve Holme <steve_holme@hotmail.com>
Wed, 15 Jan 2014 20:21:01 +0000 (20:21 +0000)
Starting with Visual Studio 2013 (VC12) and Windows 8.1 the
GetVersionInfoEx() function has been marked as deprecated and it's
return value atered. Updated connect.c and curl_sspi.c to use
VerifyVersionInfo() where possible, which has been available since
Windows 2000.

lib/connect.c
lib/curl_sspi.c

index 0816af2d4b35319465d0841ca1f4c772ab7de3f3..16ad524dfd0019894bb3f3b78e284a427938029c 100644 (file)
@@ -916,19 +916,38 @@ void Curl_sndbufset(curl_socket_t sockfd)
   int val = CURL_MAX_WRITE_SIZE + 32;
   int curval = 0;
   int curlen = sizeof(curval);
+  DWORD majorVersion = 6;
 
-  OSVERSIONINFO osver;
   static int detectOsState = DETECT_OS_NONE;
 
   if(detectOsState == DETECT_OS_NONE) {
+#if !defined(VerifyVersionInfo)
+    OSVERSIONINFO osver;
+
     memset(&osver, 0, sizeof(osver));
     osver.dwOSVersionInfoSize = sizeof(osver);
+
     detectOsState = DETECT_OS_PREVISTA;
     if(GetVersionEx(&osver)) {
-      if(osver.dwMajorVersion >= 6)
+      if(osver.dwMajorVersion >= majorVersion)
         detectOsState = DETECT_OS_VISTA_OR_LATER;
     }
+#else
+    ULONGLONG majorVersionMask;
+    OSVERSIONINFOEX osver;
+
+    memset(&osver, 0, sizeof(osver));
+    osver.dwOSVersionInfoSize = sizeof(osver);
+    osver.dwMajorVersion = majorVersion;
+    majorVersionMask = VerSetConditionMask(0, VER_MAJORVERSION, VER_EQUAL);
+
+    if(VerifyVersionInfo(&osver, VER_MAJORVERSION, majorVersionMask))
+      detectOsState = DETECT_OS_VISTA_OR_LATER;
+    else
+      detectOsState = DETECT_OS_PREVISTA;
+#endif
   }
+
   if(detectOsState == DETECT_OS_VISTA_OR_LATER)
     return;
 
@@ -940,7 +959,6 @@ void Curl_sndbufset(curl_socket_t sockfd)
 }
 #endif
 
-
 /*
  * singleipconnect()
  *
index e747d86b1d2684053ec4b63365158ceff4f25992..5a48e4943aa8666e30d44d60dbb876b222ec47cd 100644 (file)
@@ -68,25 +68,51 @@ PSecurityFunctionTable s_pSecFn = NULL;
  */
 CURLcode Curl_sspi_global_init(void)
 {
-  OSVERSIONINFO osver;
+  bool securityDll = FALSE;
   INITSECURITYINTERFACE_FN pInitSecurityInterface;
 
   /* If security interface is not yet initialized try to do this */
   if(!s_hSecDll) {
+    /* Security Service Provider Interface (SSPI) functions are located in
+     * security.dll on WinNT 4.0 and in secur32.dll on Win9x. Win2K and XP
+     * have both these DLLs (security.dll forwards calls to secur32.dll) */
+    DWORD majorVersion = 4;
+    DWORD platformId = VER_PLATFORM_WIN32_NT;
+
+#if !defined(VerifyVersionInfo)
+    OSVERSIONINFO osver;
 
-    /* Find out Windows version */
     memset(&osver, 0, sizeof(osver));
     osver.dwOSVersionInfoSize = sizeof(osver);
+
+    /* Find out Windows version */
     if(!GetVersionEx(&osver))
       return CURLE_FAILED_INIT;
 
-    /* Security Service Provider Interface (SSPI) functions are located in
-     * security.dll on WinNT 4.0 and in secur32.dll on Win9x. Win2K and XP
-     * have both these DLLs (security.dll forwards calls to secur32.dll) */
+    /* Verify the major version number == 4 and platform id == WIN_NT */
+    if(osver.dwMajorVersion == majorVersion &&
+       osver.dwPlatformId == platformId)
+      securityDll = TRUE;
+#else
+    ULONGLONG majorVersionMask;
+    ULONGLONG platformIdMask;
+    OSVERSIONINFOEX osver;
+
+    memset(&osver, 0, sizeof(osver));
+    osver.dwOSVersionInfoSize = sizeof(osver);
+    osver.dwMajorVersion = majorVersion;
+    osver.dwPlatformId = platformId;
+    majorVersionMask = VerSetConditionMask(0, VER_MAJORVERSION, VER_EQUAL);
+    platformIdMask = VerSetConditionMask(0, VER_PLATFORMID, VER_EQUAL);
+
+    /* Verify the major version number == 4 and platform id == WIN_NT */
+    if(VerifyVersionInfo(&osver, VER_MAJORVERSION, majorVersionMask) &&
+       VerifyVersionInfo(&osver, VER_PLATFORMID, platformIdMask))
+      securityDll = TRUE;
+#endif
 
     /* Load SSPI dll into the address space of the calling process */
-    if(osver.dwPlatformId == VER_PLATFORM_WIN32_NT
-      && osver.dwMajorVersion == 4)
+    if(securityDll)
       s_hSecDll = LoadLibrary(TEXT("security.dll"));
     else
       s_hSecDll = LoadLibrary(TEXT("secur32.dll"));