cryptnet: Lock cache file while accessing it.
[wine/multimedia.git] / dlls / ntdll / version.c
blob86637fc15fb470011eb9d1b294152548fd045af9
1 /*
2 * Windows and DOS version functions
4 * Copyright 1997 Marcus Meissner
5 * Copyright 1998 Patrik Stridvall
6 * Copyright 1998, 2003 Andreas Mohr
7 * Copyright 1997, 2003 Alexandre Julliard
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "config.h"
25 #include "wine/port.h"
27 #include <string.h>
28 #include <stdlib.h>
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include "ntstatus.h"
32 #define WIN32_NO_STATUS
33 #include "windef.h"
34 #include "wine/unicode.h"
35 #include "wine/debug.h"
36 #include "ntdll_misc.h"
37 #include "ddk/wdm.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(ver);
41 typedef enum
43 WIN20, /* Windows 2.0 */
44 WIN30, /* Windows 3.0 */
45 WIN31, /* Windows 3.1 */
46 WIN95, /* Windows 95 */
47 WIN98, /* Windows 98 */
48 WINME, /* Windows Me */
49 NT351, /* Windows NT 3.51 */
50 NT40, /* Windows NT 4.0 */
51 NT2K, /* Windows 2000 */
52 WINXP, /* Windows XP */
53 WIN2K3, /* Windows 2003 */
54 WINVISTA,/* Windows Vista */
55 WIN2K8, /* Windows 2008 */
56 WIN2K8R2,/* Windows 2008 R2 */
57 WIN7, /* Windows 7 */
58 WIN8, /* Windows 8 */
59 NB_WINDOWS_VERSIONS
60 } WINDOWS_VERSION;
62 /* FIXME: compare values below with original and fix.
63 * An *excellent* win9x version page (ALL versions !)
64 * can be found at www.mdgx.com/ver.htm */
65 static const RTL_OSVERSIONINFOEXW VersionData[NB_WINDOWS_VERSIONS] =
67 /* WIN20 FIXME: verify values */
69 sizeof(RTL_OSVERSIONINFOEXW), 2, 0, 0, VER_PLATFORM_WIN32s,
70 {'W','i','n','3','2','s',' ','1','.','3',0},
71 0, 0, 0, 0, 0
73 /* WIN30 FIXME: verify values */
75 sizeof(RTL_OSVERSIONINFOEXW), 3, 0, 0, VER_PLATFORM_WIN32s,
76 {'W','i','n','3','2','s',' ','1','.','3',0},
77 0, 0, 0, 0, 0
79 /* WIN31 */
81 sizeof(RTL_OSVERSIONINFOEXW), 3, 10, 0, VER_PLATFORM_WIN32s,
82 {'W','i','n','3','2','s',' ','1','.','3',0},
83 0, 0, 0, 0, 0
85 /* WIN95 */
87 /* Win95: 4, 0, 0x40003B6, ""
88 * Win95sp1: 4, 0, 0x40003B6, " A " (according to doc)
89 * Win95osr2: 4, 0, 0x4000457, " B " (according to doc)
90 * Win95osr2.1: 4, 3, 0x40304BC, " B " (according to doc)
91 * Win95osr2.5: 4, 3, 0x40304BE, " C " (according to doc)
92 * Win95a/b can be discerned via regkey SubVersionNumber
94 sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x40003B6, VER_PLATFORM_WIN32_WINDOWS,
95 {0},
96 0, 0, 0, 0, 0
98 /* WIN98 (second edition) */
100 /* Win98: 4, 10, 0x40A07CE, " " 4.10.1998
101 * Win98SE: 4, 10, 0x40A08AE, " A " 4.10.2222
103 sizeof(RTL_OSVERSIONINFOEXW), 4, 10, 0x40A08AE, VER_PLATFORM_WIN32_WINDOWS,
104 {' ','A',' ',0},
105 0, 0, 0, 0, 0
107 /* WINME */
109 sizeof(RTL_OSVERSIONINFOEXW), 4, 90, 0x45A0BB8, VER_PLATFORM_WIN32_WINDOWS,
110 {' ',0},
111 0, 0, 0, 0, 0
113 /* NT351 */
115 sizeof(RTL_OSVERSIONINFOEXW), 3, 51, 0x421, VER_PLATFORM_WIN32_NT,
116 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','5',0},
117 5, 0, 0, VER_NT_WORKSTATION, 0
119 /* NT40 */
121 sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x565, VER_PLATFORM_WIN32_NT,
122 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','6','a',0},
123 6, 0, 0, VER_NT_WORKSTATION, 0
125 /* NT2K */
127 sizeof(RTL_OSVERSIONINFOEXW), 5, 0, 0x893, VER_PLATFORM_WIN32_NT,
128 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','4',0},
129 4, 0, 0, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
131 /* WINXP */
133 sizeof(RTL_OSVERSIONINFOEXW), 5, 1, 0xA28, VER_PLATFORM_WIN32_NT,
134 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0},
135 3, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
137 /* WIN2K3 */
139 sizeof(RTL_OSVERSIONINFOEXW), 5, 2, 0xECE, VER_PLATFORM_WIN32_NT,
140 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
141 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
143 /* WINVISTA */
145 sizeof(RTL_OSVERSIONINFOEXW), 6, 0, 0x1772, VER_PLATFORM_WIN32_NT,
146 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
147 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
149 /* WIN2K8 */
151 sizeof(RTL_OSVERSIONINFOEXW), 6, 0, 0x1772, VER_PLATFORM_WIN32_NT,
152 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
153 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
155 /* WIN7 */
157 sizeof(RTL_OSVERSIONINFOEXW), 6, 1, 0x1DB1, VER_PLATFORM_WIN32_NT,
158 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','1',0},
159 1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
161 /* WIN2K8R2 */
163 sizeof(RTL_OSVERSIONINFOEXW), 6, 1, 0x1DB1, VER_PLATFORM_WIN32_NT,
164 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','1',0},
165 1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
167 /* WIN8 */
169 sizeof(RTL_OSVERSIONINFOEXW), 6, 2, 0x23F0, VER_PLATFORM_WIN32_NT,
170 {' ',0},
171 0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
176 static const char * const WinVersionNames[NB_WINDOWS_VERSIONS] =
177 { /* no spaces in here ! */
178 "win20", /* WIN20 */
179 "win30", /* WIN30 */
180 "win31", /* WIN31 */
181 "win95", /* WIN95 */
182 "win98", /* WIN98 */
183 "winme", /* WINME */
184 "nt351", /* NT351 */
185 "nt40", /* NT40 */
186 "win2000,win2k,nt2k,nt2000", /* NT2K */
187 "winxp", /* WINXP */
188 "win2003,win2k3", /* WIN2K3 */
189 "vista,winvista", /* WINVISTA*/
190 "win2008,win2k8", /* WIN2K8 */
191 "win2008r2,win2k8r2", /* WIN2K8R2 */
192 "win7", /* WIN7 */
193 "win8", /* WIN8 */
197 /* initialized to null so that we crash if we try to retrieve the version too early at startup */
198 static const RTL_OSVERSIONINFOEXW *current_version;
201 /**********************************************************************
202 * get_nt_registry_version
204 * Fetch the version information from the NT-style registry keys.
206 static BOOL get_nt_registry_version( RTL_OSVERSIONINFOEXW *version )
208 static const WCHAR version_keyW[] = {'M','a','c','h','i','n','e','\\',
209 'S','o','f','t','w','a','r','e','\\',
210 'M','i','c','r','o','s','o','f','t','\\',
211 'W','i','n','d','o','w','s',' ','N','T','\\',
212 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
213 static const WCHAR service_pack_keyW[] = {'M','a','c','h','i','n','e','\\',
214 'S','y','s','t','e','m','\\',
215 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
216 'C','o','n','t','r','o','l','\\',
217 'W','i','n','d','o','w','s',0};
218 static const WCHAR product_keyW[] = {'M','a','c','h','i','n','e','\\',
219 'S','y','s','t','e','m','\\',
220 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
221 'C','o','n','t','r','o','l','\\',
222 'P','r','o','d','u','c','t','O','p','t','i','o','n','s',0};
223 static const WCHAR CurrentBuildNumberW[] = {'C','u','r','r','e','n','t','B','u','i','l','d','N','u','m','b','e','r',0};
224 static const WCHAR CSDVersionW[] = {'C','S','D','V','e','r','s','i','o','n',0};
225 static const WCHAR CurrentVersionW[] = {'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
226 static const WCHAR ProductTypeW[] = {'P','r','o','d','u','c','t','T','y','p','e',0};
227 static const WCHAR WinNTW[] = {'W','i','n','N','T',0};
228 static const WCHAR ServerNTW[] = {'S','e','r','v','e','r','N','T',0};
229 static const WCHAR LanmanNTW[] = {'L','a','n','m','a','n','N','T',0};
231 OBJECT_ATTRIBUTES attr;
232 UNICODE_STRING nameW, valueW;
233 HANDLE hkey, hkey2;
234 char tmp[64];
235 DWORD count;
236 BOOL ret = FALSE;
237 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
239 attr.Length = sizeof(attr);
240 attr.RootDirectory = 0;
241 attr.ObjectName = &nameW;
242 attr.Attributes = 0;
243 attr.SecurityDescriptor = NULL;
244 attr.SecurityQualityOfService = NULL;
245 RtlInitUnicodeString( &nameW, version_keyW );
247 if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) return FALSE;
249 memset( version, 0, sizeof(*version) );
251 RtlInitUnicodeString( &valueW, CurrentVersionW );
252 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
254 WCHAR *p, *str = (WCHAR *)info->Data;
255 str[info->DataLength / sizeof(WCHAR)] = 0;
256 p = strchrW( str, '.' );
257 if (p)
259 *p++ = 0;
260 version->dwMinorVersion = atoiW( p );
262 version->dwMajorVersion = atoiW( str );
265 if (version->dwMajorVersion) /* we got the main version, now fetch the other fields */
267 ret = TRUE;
268 version->dwPlatformId = VER_PLATFORM_WIN32_NT;
270 /* get build number */
272 RtlInitUnicodeString( &valueW, CurrentBuildNumberW );
273 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
275 WCHAR *str = (WCHAR *)info->Data;
276 str[info->DataLength / sizeof(WCHAR)] = 0;
277 version->dwBuildNumber = atoiW( str );
280 /* get version description */
282 RtlInitUnicodeString( &valueW, CSDVersionW );
283 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
285 DWORD len = min( info->DataLength, sizeof(version->szCSDVersion) - sizeof(WCHAR) );
286 memcpy( version->szCSDVersion, info->Data, len );
287 version->szCSDVersion[len / sizeof(WCHAR)] = 0;
290 /* get service pack version */
292 RtlInitUnicodeString( &nameW, service_pack_keyW );
293 if (!NtOpenKey( &hkey2, KEY_ALL_ACCESS, &attr ))
295 RtlInitUnicodeString( &valueW, CSDVersionW );
296 if (!NtQueryValueKey( hkey2, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
298 if (info->DataLength >= sizeof(DWORD))
300 DWORD dw = *(DWORD *)info->Data;
301 version->wServicePackMajor = LOWORD(dw) >> 8;
302 version->wServicePackMinor = LOWORD(dw) & 0xff;
305 NtClose( hkey2 );
308 /* get product type */
310 RtlInitUnicodeString( &nameW, product_keyW );
311 if (!NtOpenKey( &hkey2, KEY_ALL_ACCESS, &attr ))
313 RtlInitUnicodeString( &valueW, ProductTypeW );
314 if (!NtQueryValueKey( hkey2, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
316 WCHAR *str = (WCHAR *)info->Data;
317 str[info->DataLength / sizeof(WCHAR)] = 0;
318 if (!strcmpiW( str, WinNTW )) version->wProductType = VER_NT_WORKSTATION;
319 else if (!strcmpiW( str, LanmanNTW )) version->wProductType = VER_NT_DOMAIN_CONTROLLER;
320 else if (!strcmpiW( str, ServerNTW )) version->wProductType = VER_NT_SERVER;
322 NtClose( hkey2 );
325 /* FIXME: get wSuiteMask */
328 NtClose( hkey );
329 return ret;
333 /**********************************************************************
334 * get_win9x_registry_version
336 * Fetch the version information from the Win9x-style registry keys.
338 static BOOL get_win9x_registry_version( RTL_OSVERSIONINFOEXW *version )
340 static const WCHAR version_keyW[] = {'M','a','c','h','i','n','e','\\',
341 'S','o','f','t','w','a','r','e','\\',
342 'M','i','c','r','o','s','o','f','t','\\',
343 'W','i','n','d','o','w','s','\\',
344 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
345 static const WCHAR VersionNumberW[] = {'V','e','r','s','i','o','n','N','u','m','b','e','r',0};
346 static const WCHAR SubVersionNumberW[] = {'S','u','b','V','e','r','s','i','o','n','N','u','m','b','e','r',0};
348 OBJECT_ATTRIBUTES attr;
349 UNICODE_STRING nameW, valueW;
350 HANDLE hkey;
351 char tmp[64];
352 DWORD count;
353 BOOL ret = FALSE;
354 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
356 attr.Length = sizeof(attr);
357 attr.RootDirectory = 0;
358 attr.ObjectName = &nameW;
359 attr.Attributes = 0;
360 attr.SecurityDescriptor = NULL;
361 attr.SecurityQualityOfService = NULL;
362 RtlInitUnicodeString( &nameW, version_keyW );
364 if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) return FALSE;
366 memset( version, 0, sizeof(*version) );
368 RtlInitUnicodeString( &valueW, VersionNumberW );
369 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
371 WCHAR *p, *str = (WCHAR *)info->Data;
372 str[info->DataLength / sizeof(WCHAR)] = 0;
373 p = strchrW( str, '.' );
374 if (p) *p++ = 0;
375 version->dwMajorVersion = atoiW( str );
376 if (p)
378 str = p;
379 p = strchrW( str, '.' );
380 if (p)
382 *p++ = 0;
383 version->dwBuildNumber = atoiW( p );
385 version->dwMinorVersion = atoiW( str );
387 /* build number contains version too on Win9x */
388 version->dwBuildNumber |= MAKEWORD( version->dwMinorVersion, version->dwMajorVersion ) << 16;
391 if (version->dwMajorVersion) /* we got the main version, now fetch the other fields */
393 ret = TRUE;
394 version->dwPlatformId = VER_PLATFORM_WIN32_WINDOWS;
396 RtlInitUnicodeString( &valueW, SubVersionNumberW );
397 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
399 DWORD len = min( info->DataLength, sizeof(version->szCSDVersion) - sizeof(WCHAR) );
400 memcpy( version->szCSDVersion, info->Data, len );
401 version->szCSDVersion[len / sizeof(WCHAR)] = 0;
405 NtClose( hkey );
406 return ret;
410 /**********************************************************************
411 * parse_win_version
413 * Parse the contents of the Version key.
415 static BOOL parse_win_version( HANDLE hkey )
417 static const WCHAR VersionW[] = {'V','e','r','s','i','o','n',0};
419 UNICODE_STRING valueW;
420 char tmp[64], buffer[50];
421 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
422 DWORD count, len;
423 int i;
425 RtlInitUnicodeString( &valueW, VersionW );
426 if (NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
427 return FALSE;
429 RtlUnicodeToMultiByteN( buffer, sizeof(buffer)-1, &len, (WCHAR *)info->Data, info->DataLength );
430 buffer[len] = 0;
432 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
434 const char *p, *pCurr = WinVersionNames[i];
435 /* iterate through all winver aliases separated by comma */
436 do {
437 p = strchr(pCurr, ',');
438 len = p ? p - pCurr : strlen(pCurr);
439 if ( (!strncmp( pCurr, buffer, len )) && (buffer[len] == 0) )
441 current_version = &VersionData[i];
442 TRACE( "got win version %s\n", WinVersionNames[i] );
443 return TRUE;
445 pCurr = p+1;
446 } while (p);
449 MESSAGE("Invalid Windows version value '%s' specified in config file.\n", buffer );
450 MESSAGE("Valid versions are:" );
451 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
453 /* only list the first, "official" alias in case of aliases */
454 const char *pCurr = WinVersionNames[i];
455 const char *p = strchr(pCurr, ',');
456 len = (p) ? p - pCurr : strlen(pCurr);
458 MESSAGE(" '%.*s'%c", (int)len, pCurr, (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
460 return FALSE;
464 /**********************************************************************
465 * version_init
467 void version_init( const WCHAR *appname )
469 static const WCHAR configW[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e',0};
470 static const WCHAR appdefaultsW[] = {'A','p','p','D','e','f','a','u','l','t','s','\\',0};
472 OBJECT_ATTRIBUTES attr;
473 UNICODE_STRING nameW;
474 HANDLE root, hkey, config_key;
475 BOOL got_win_ver = FALSE;
477 current_version = &VersionData[WINXP]; /* default if nothing else is specified */
479 RtlOpenCurrentUser( KEY_ALL_ACCESS, &root );
480 attr.Length = sizeof(attr);
481 attr.RootDirectory = root;
482 attr.ObjectName = &nameW;
483 attr.Attributes = 0;
484 attr.SecurityDescriptor = NULL;
485 attr.SecurityQualityOfService = NULL;
486 RtlInitUnicodeString( &nameW, configW );
488 /* @@ Wine registry key: HKCU\Software\Wine */
489 if (NtOpenKey( &config_key, KEY_ALL_ACCESS, &attr )) config_key = 0;
490 NtClose( root );
491 if (!config_key) goto done;
493 /* open AppDefaults\\appname key */
494 if (appname && *appname)
496 const WCHAR *p;
497 WCHAR appversion[MAX_PATH+20];
499 if ((p = strrchrW( appname, '/' ))) appname = p + 1;
500 if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
502 strcpyW( appversion, appdefaultsW );
503 strcatW( appversion, appname );
504 RtlInitUnicodeString( &nameW, appversion );
505 attr.RootDirectory = config_key;
507 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe */
508 if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
510 TRACE( "getting version from %s\n", debugstr_w(appversion) );
511 got_win_ver = parse_win_version( hkey );
512 NtClose( hkey );
516 if (!got_win_ver)
518 TRACE( "getting default version\n" );
519 got_win_ver = parse_win_version( config_key );
521 NtClose( config_key );
523 done:
524 if (!got_win_ver)
526 static RTL_OSVERSIONINFOEXW registry_version;
528 TRACE( "getting registry version\n" );
529 if (get_nt_registry_version( &registry_version ) ||
530 get_win9x_registry_version( &registry_version ))
531 current_version = &registry_version;
535 NtCurrentTeb()->Peb->OSMajorVersion = current_version->dwMajorVersion;
536 NtCurrentTeb()->Peb->OSMinorVersion = current_version->dwMinorVersion;
537 NtCurrentTeb()->Peb->OSBuildNumber = current_version->dwBuildNumber;
538 NtCurrentTeb()->Peb->OSPlatformId = current_version->dwPlatformId;
540 user_shared_data->NtProductType = current_version->wProductType;
541 user_shared_data->ProductTypeIsValid = TRUE;
542 user_shared_data->NtMajorVersion = current_version->dwMajorVersion;
543 user_shared_data->NtMinorVersion = current_version->dwMinorVersion;
544 user_shared_data->SuiteMask = current_version->wSuiteMask;
546 TRACE( "got %d.%d platform %d build %x name %s service pack %d.%d product %d\n",
547 current_version->dwMajorVersion, current_version->dwMinorVersion,
548 current_version->dwPlatformId, current_version->dwBuildNumber,
549 debugstr_w(current_version->szCSDVersion),
550 current_version->wServicePackMajor, current_version->wServicePackMinor,
551 current_version->wProductType );
554 /***********************************************************************
555 * RtlGetProductInfo (NTDLL.@)
557 * Gives info about the current Windows product type, in a format compatible
558 * with the given Windows version
560 * Returns TRUE if the input is valid, FALSE otherwise
562 BOOLEAN WINAPI RtlGetProductInfo(DWORD dwOSMajorVersion, DWORD dwOSMinorVersion, DWORD dwSpMajorVersion,
563 DWORD dwSpMinorVersion, PDWORD pdwReturnedProductType)
565 TRACE("(%d, %d, %d, %d, %p)\n", dwOSMajorVersion, dwOSMinorVersion,
566 dwSpMajorVersion, dwSpMinorVersion, pdwReturnedProductType);
568 if (!pdwReturnedProductType)
569 return FALSE;
571 if (dwOSMajorVersion < 6)
573 *pdwReturnedProductType = PRODUCT_UNDEFINED;
574 return FALSE;
577 if (current_version->wProductType == VER_NT_WORKSTATION)
578 *pdwReturnedProductType = PRODUCT_ULTIMATE_N;
579 else
580 *pdwReturnedProductType = PRODUCT_STANDARD_SERVER;
582 return TRUE;
585 /***********************************************************************
586 * RtlGetVersion (NTDLL.@)
588 NTSTATUS WINAPI RtlGetVersion( RTL_OSVERSIONINFOEXW *info )
590 info->dwMajorVersion = current_version->dwMajorVersion;
591 info->dwMinorVersion = current_version->dwMinorVersion;
592 info->dwBuildNumber = current_version->dwBuildNumber;
593 info->dwPlatformId = current_version->dwPlatformId;
594 strcpyW( info->szCSDVersion, current_version->szCSDVersion );
595 if(info->dwOSVersionInfoSize == sizeof(RTL_OSVERSIONINFOEXW))
597 info->wServicePackMajor = current_version->wServicePackMajor;
598 info->wServicePackMinor = current_version->wServicePackMinor;
599 info->wSuiteMask = current_version->wSuiteMask;
600 info->wProductType = current_version->wProductType;
602 return STATUS_SUCCESS;
606 /******************************************************************************
607 * RtlGetNtVersionNumbers (NTDLL.@)
609 * Get the version numbers of the run time library.
611 * PARAMS
612 * major [O] Destination for the Major version
613 * minor [O] Destination for the Minor version
614 * build [O] Destination for the Build version
616 * RETURNS
617 * Nothing.
619 * NOTES
620 * Introduced in Windows XP (NT5.1)
622 void WINAPI RtlGetNtVersionNumbers( LPDWORD major, LPDWORD minor, LPDWORD build )
624 if (major) *major = current_version->dwMajorVersion;
625 if (minor) *minor = current_version->dwMinorVersion;
626 /* FIXME: Does anybody know the real formula? */
627 if (build) *build = (0xF0000000 | current_version->dwBuildNumber);
631 /******************************************************************************
632 * RtlGetNtProductType (NTDLL.@)
634 BOOLEAN WINAPI RtlGetNtProductType( LPDWORD type )
636 if (type) *type = current_version->wProductType;
637 return TRUE;
641 static inline NTSTATUS version_compare_values(ULONG left, ULONG right, UCHAR condition)
643 switch (condition) {
644 case VER_EQUAL:
645 if (left != right) return STATUS_REVISION_MISMATCH;
646 break;
647 case VER_GREATER:
648 if (left <= right) return STATUS_REVISION_MISMATCH;
649 break;
650 case VER_GREATER_EQUAL:
651 if (left < right) return STATUS_REVISION_MISMATCH;
652 break;
653 case VER_LESS:
654 if (left >= right) return STATUS_REVISION_MISMATCH;
655 break;
656 case VER_LESS_EQUAL:
657 if (left > right) return STATUS_REVISION_MISMATCH;
658 break;
659 default:
660 return STATUS_REVISION_MISMATCH;
662 return STATUS_SUCCESS;
665 /******************************************************************************
666 * RtlVerifyVersionInfo (NTDLL.@)
668 NTSTATUS WINAPI RtlVerifyVersionInfo( const RTL_OSVERSIONINFOEXW *info,
669 DWORD dwTypeMask, DWORDLONG dwlConditionMask )
671 RTL_OSVERSIONINFOEXW ver;
672 NTSTATUS status;
674 TRACE("(%p,0x%x,0x%s)\n", info, dwTypeMask, wine_dbgstr_longlong(dwlConditionMask));
676 ver.dwOSVersionInfoSize = sizeof(ver);
677 if ((status = RtlGetVersion( &ver )) != STATUS_SUCCESS) return status;
679 if(!(dwTypeMask && dwlConditionMask)) return STATUS_INVALID_PARAMETER;
681 if(dwTypeMask & VER_PRODUCT_TYPE)
683 status = version_compare_values(ver.wProductType, info->wProductType, dwlConditionMask >> 7*3 & 0x07);
684 if (status != STATUS_SUCCESS)
685 return status;
687 if(dwTypeMask & VER_SUITENAME)
688 switch(dwlConditionMask >> 6*3 & 0x07)
690 case VER_AND:
691 if((info->wSuiteMask & ver.wSuiteMask) != info->wSuiteMask)
692 return STATUS_REVISION_MISMATCH;
693 break;
694 case VER_OR:
695 if(!(info->wSuiteMask & ver.wSuiteMask) && info->wSuiteMask)
696 return STATUS_REVISION_MISMATCH;
697 break;
698 default:
699 return STATUS_INVALID_PARAMETER;
701 if(dwTypeMask & VER_PLATFORMID)
703 status = version_compare_values(ver.dwPlatformId, info->dwPlatformId, dwlConditionMask >> 3*3 & 0x07);
704 if (status != STATUS_SUCCESS)
705 return status;
707 if(dwTypeMask & VER_BUILDNUMBER)
709 status = version_compare_values(ver.dwBuildNumber, info->dwBuildNumber, dwlConditionMask >> 2*3 & 0x07);
710 if (status != STATUS_SUCCESS)
711 return status;
714 if(dwTypeMask & (VER_MAJORVERSION|VER_MINORVERSION|VER_SERVICEPACKMAJOR|VER_SERVICEPACKMINOR))
716 unsigned char condition = 0;
717 BOOLEAN do_next_check = TRUE;
719 if(dwTypeMask & VER_MAJORVERSION)
720 condition = dwlConditionMask >> 1*3 & 0x07;
721 else if(dwTypeMask & VER_MINORVERSION)
722 condition = dwlConditionMask >> 0*3 & 0x07;
723 else if(dwTypeMask & VER_SERVICEPACKMAJOR)
724 condition = dwlConditionMask >> 5*3 & 0x07;
725 else if(dwTypeMask & VER_SERVICEPACKMINOR)
726 condition = dwlConditionMask >> 4*3 & 0x07;
728 if(dwTypeMask & VER_MAJORVERSION)
730 status = version_compare_values(ver.dwMajorVersion, info->dwMajorVersion, condition);
731 do_next_check = (ver.dwMajorVersion == info->dwMajorVersion) &&
732 ((condition != VER_EQUAL) || (status == STATUS_SUCCESS));
734 if((dwTypeMask & VER_MINORVERSION) && do_next_check)
736 status = version_compare_values(ver.dwMinorVersion, info->dwMinorVersion, condition);
737 do_next_check = (ver.dwMinorVersion == info->dwMinorVersion) &&
738 ((condition != VER_EQUAL) || (status == STATUS_SUCCESS));
740 if((dwTypeMask & VER_SERVICEPACKMAJOR) && do_next_check)
742 status = version_compare_values(ver.wServicePackMajor, info->wServicePackMajor, condition);
743 do_next_check = (ver.wServicePackMajor == info->wServicePackMajor) &&
744 ((condition != VER_EQUAL) || (status == STATUS_SUCCESS));
746 if((dwTypeMask & VER_SERVICEPACKMINOR) && do_next_check)
748 status = version_compare_values(ver.wServicePackMinor, info->wServicePackMinor, condition);
751 if (status != STATUS_SUCCESS)
752 return status;
755 return STATUS_SUCCESS;