ntdll: Define a couple more information classes.
[wine.git] / dlls / ntdll / version.c
bloba6340ebf4c2a0bc9fafc92c9a32f23a01ba4f9e7
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 WINXP64, /* Windows XP 64-bit */
54 WIN2K3, /* Windows 2003 */
55 WINVISTA,/* Windows Vista */
56 WIN2K8, /* Windows 2008 */
57 WIN2K8R2,/* Windows 2008 R2 */
58 WIN7, /* Windows 7 */
59 WIN8, /* Windows 8 */
60 WIN81, /* Windows 8.1 */
61 NB_WINDOWS_VERSIONS
62 } WINDOWS_VERSION;
64 /* FIXME: compare values below with original and fix.
65 * An *excellent* win9x version page (ALL versions !)
66 * can be found at www.mdgx.com/ver.htm */
67 static const RTL_OSVERSIONINFOEXW VersionData[NB_WINDOWS_VERSIONS] =
69 /* WIN20 FIXME: verify values */
71 sizeof(RTL_OSVERSIONINFOEXW), 2, 0, 0, VER_PLATFORM_WIN32s,
72 {'W','i','n','3','2','s',' ','1','.','3',0},
73 0, 0, 0, 0, 0
75 /* WIN30 FIXME: verify values */
77 sizeof(RTL_OSVERSIONINFOEXW), 3, 0, 0, VER_PLATFORM_WIN32s,
78 {'W','i','n','3','2','s',' ','1','.','3',0},
79 0, 0, 0, 0, 0
81 /* WIN31 */
83 sizeof(RTL_OSVERSIONINFOEXW), 3, 10, 0, VER_PLATFORM_WIN32s,
84 {'W','i','n','3','2','s',' ','1','.','3',0},
85 0, 0, 0, 0, 0
87 /* WIN95 */
89 /* Win95: 4, 0, 0x40003B6, ""
90 * Win95sp1: 4, 0, 0x40003B6, " A " (according to doc)
91 * Win95osr2: 4, 0, 0x4000457, " B " (according to doc)
92 * Win95osr2.1: 4, 3, 0x40304BC, " B " (according to doc)
93 * Win95osr2.5: 4, 3, 0x40304BE, " C " (according to doc)
94 * Win95a/b can be discerned via regkey SubVersionNumber
96 sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x40003B6, VER_PLATFORM_WIN32_WINDOWS,
97 {0},
98 0, 0, 0, 0, 0
100 /* WIN98 (second edition) */
102 /* Win98: 4, 10, 0x40A07CE, " " 4.10.1998
103 * Win98SE: 4, 10, 0x40A08AE, " A " 4.10.2222
105 sizeof(RTL_OSVERSIONINFOEXW), 4, 10, 0x40A08AE, VER_PLATFORM_WIN32_WINDOWS,
106 {' ','A',' ',0},
107 0, 0, 0, 0, 0
109 /* WINME */
111 sizeof(RTL_OSVERSIONINFOEXW), 4, 90, 0x45A0BB8, VER_PLATFORM_WIN32_WINDOWS,
112 {' ',0},
113 0, 0, 0, 0, 0
115 /* NT351 */
117 sizeof(RTL_OSVERSIONINFOEXW), 3, 51, 0x421, VER_PLATFORM_WIN32_NT,
118 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','5',0},
119 5, 0, 0, VER_NT_WORKSTATION, 0
121 /* NT40 */
123 sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x565, VER_PLATFORM_WIN32_NT,
124 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','6','a',0},
125 6, 0, 0, VER_NT_WORKSTATION, 0
127 /* NT2K */
129 sizeof(RTL_OSVERSIONINFOEXW), 5, 0, 0x893, VER_PLATFORM_WIN32_NT,
130 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','4',0},
131 4, 0, 0, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
133 /* WINXP */
135 sizeof(RTL_OSVERSIONINFOEXW), 5, 1, 0xA28, VER_PLATFORM_WIN32_NT,
136 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0},
137 3, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
139 /* WINXP64 */
141 sizeof(RTL_OSVERSIONINFOEXW), 5, 2, 0xECE, VER_PLATFORM_WIN32_NT,
142 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
143 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
145 /* WIN2K3 */
147 sizeof(RTL_OSVERSIONINFOEXW), 5, 2, 0xECE, VER_PLATFORM_WIN32_NT,
148 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
149 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
151 /* WINVISTA */
153 sizeof(RTL_OSVERSIONINFOEXW), 6, 0, 0x1772, VER_PLATFORM_WIN32_NT,
154 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
155 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
157 /* WIN2K8 */
159 sizeof(RTL_OSVERSIONINFOEXW), 6, 0, 0x1772, VER_PLATFORM_WIN32_NT,
160 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
161 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
163 /* WIN7 */
165 sizeof(RTL_OSVERSIONINFOEXW), 6, 1, 0x1DB1, VER_PLATFORM_WIN32_NT,
166 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','1',0},
167 1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
169 /* WIN2K8R2 */
171 sizeof(RTL_OSVERSIONINFOEXW), 6, 1, 0x1DB1, VER_PLATFORM_WIN32_NT,
172 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','1',0},
173 1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
175 /* WIN8 */
177 sizeof(RTL_OSVERSIONINFOEXW), 6, 2, 0x23F0, VER_PLATFORM_WIN32_NT,
178 {' ',0},
179 0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
181 /* WIN81 */
183 sizeof(RTL_OSVERSIONINFOEXW), 6, 3, 0x2580, VER_PLATFORM_WIN32_NT,
184 {' ',0},
185 0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
190 static const char * const WinVersionNames[NB_WINDOWS_VERSIONS] =
191 { /* no spaces in here ! */
192 "win20", /* WIN20 */
193 "win30", /* WIN30 */
194 "win31", /* WIN31 */
195 "win95", /* WIN95 */
196 "win98", /* WIN98 */
197 "winme", /* WINME */
198 "nt351", /* NT351 */
199 "nt40", /* NT40 */
200 "win2000,win2k,nt2k,nt2000", /* NT2K */
201 "winxp", /* WINXP */
202 "winxp64", /* WINXP64 */
203 "win2003,win2k3", /* WIN2K3 */
204 "vista,winvista", /* WINVISTA*/
205 "win2008,win2k8", /* WIN2K8 */
206 "win2008r2,win2k8r2", /* WIN2K8R2 */
207 "win7", /* WIN7 */
208 "win8", /* WIN8 */
209 "win81", /* WIN81 */
213 /* initialized to null so that we crash if we try to retrieve the version too early at startup */
214 static const RTL_OSVERSIONINFOEXW *current_version;
217 /**********************************************************************
218 * get_nt_registry_version
220 * Fetch the version information from the NT-style registry keys.
222 static BOOL get_nt_registry_version( RTL_OSVERSIONINFOEXW *version )
224 static const WCHAR version_keyW[] = {'M','a','c','h','i','n','e','\\',
225 'S','o','f','t','w','a','r','e','\\',
226 'M','i','c','r','o','s','o','f','t','\\',
227 'W','i','n','d','o','w','s',' ','N','T','\\',
228 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
229 static const WCHAR service_pack_keyW[] = {'M','a','c','h','i','n','e','\\',
230 'S','y','s','t','e','m','\\',
231 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
232 'C','o','n','t','r','o','l','\\',
233 'W','i','n','d','o','w','s',0};
234 static const WCHAR product_keyW[] = {'M','a','c','h','i','n','e','\\',
235 'S','y','s','t','e','m','\\',
236 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
237 'C','o','n','t','r','o','l','\\',
238 'P','r','o','d','u','c','t','O','p','t','i','o','n','s',0};
239 static const WCHAR CurrentBuildNumberW[] = {'C','u','r','r','e','n','t','B','u','i','l','d','N','u','m','b','e','r',0};
240 static const WCHAR CSDVersionW[] = {'C','S','D','V','e','r','s','i','o','n',0};
241 static const WCHAR CurrentVersionW[] = {'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
242 static const WCHAR ProductTypeW[] = {'P','r','o','d','u','c','t','T','y','p','e',0};
243 static const WCHAR WinNTW[] = {'W','i','n','N','T',0};
244 static const WCHAR ServerNTW[] = {'S','e','r','v','e','r','N','T',0};
245 static const WCHAR LanmanNTW[] = {'L','a','n','m','a','n','N','T',0};
247 OBJECT_ATTRIBUTES attr;
248 UNICODE_STRING nameW, valueW;
249 HANDLE hkey, hkey2;
250 char tmp[64];
251 DWORD count;
252 BOOL ret = FALSE;
253 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
255 attr.Length = sizeof(attr);
256 attr.RootDirectory = 0;
257 attr.ObjectName = &nameW;
258 attr.Attributes = 0;
259 attr.SecurityDescriptor = NULL;
260 attr.SecurityQualityOfService = NULL;
261 RtlInitUnicodeString( &nameW, version_keyW );
263 if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) return FALSE;
265 memset( version, 0, sizeof(*version) );
267 RtlInitUnicodeString( &valueW, CurrentVersionW );
268 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
270 WCHAR *p, *str = (WCHAR *)info->Data;
271 str[info->DataLength / sizeof(WCHAR)] = 0;
272 p = strchrW( str, '.' );
273 if (p)
275 *p++ = 0;
276 version->dwMinorVersion = atoiW( p );
278 version->dwMajorVersion = atoiW( str );
281 if (version->dwMajorVersion) /* we got the main version, now fetch the other fields */
283 ret = TRUE;
284 version->dwPlatformId = VER_PLATFORM_WIN32_NT;
286 /* get build number */
288 RtlInitUnicodeString( &valueW, CurrentBuildNumberW );
289 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
291 WCHAR *str = (WCHAR *)info->Data;
292 str[info->DataLength / sizeof(WCHAR)] = 0;
293 version->dwBuildNumber = atoiW( str );
296 /* get version description */
298 RtlInitUnicodeString( &valueW, CSDVersionW );
299 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
301 DWORD len = min( info->DataLength, sizeof(version->szCSDVersion) - sizeof(WCHAR) );
302 memcpy( version->szCSDVersion, info->Data, len );
303 version->szCSDVersion[len / sizeof(WCHAR)] = 0;
306 /* get service pack version */
308 RtlInitUnicodeString( &nameW, service_pack_keyW );
309 if (!NtOpenKey( &hkey2, KEY_ALL_ACCESS, &attr ))
311 RtlInitUnicodeString( &valueW, CSDVersionW );
312 if (!NtQueryValueKey( hkey2, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
314 if (info->DataLength >= sizeof(DWORD))
316 DWORD dw = *(DWORD *)info->Data;
317 version->wServicePackMajor = LOWORD(dw) >> 8;
318 version->wServicePackMinor = LOWORD(dw) & 0xff;
321 NtClose( hkey2 );
324 /* get product type */
326 RtlInitUnicodeString( &nameW, product_keyW );
327 if (!NtOpenKey( &hkey2, KEY_ALL_ACCESS, &attr ))
329 RtlInitUnicodeString( &valueW, ProductTypeW );
330 if (!NtQueryValueKey( hkey2, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
332 WCHAR *str = (WCHAR *)info->Data;
333 str[info->DataLength / sizeof(WCHAR)] = 0;
334 if (!strcmpiW( str, WinNTW )) version->wProductType = VER_NT_WORKSTATION;
335 else if (!strcmpiW( str, LanmanNTW )) version->wProductType = VER_NT_DOMAIN_CONTROLLER;
336 else if (!strcmpiW( str, ServerNTW )) version->wProductType = VER_NT_SERVER;
338 NtClose( hkey2 );
341 /* FIXME: get wSuiteMask */
344 NtClose( hkey );
345 return ret;
349 /**********************************************************************
350 * get_win9x_registry_version
352 * Fetch the version information from the Win9x-style registry keys.
354 static BOOL get_win9x_registry_version( RTL_OSVERSIONINFOEXW *version )
356 static const WCHAR version_keyW[] = {'M','a','c','h','i','n','e','\\',
357 'S','o','f','t','w','a','r','e','\\',
358 'M','i','c','r','o','s','o','f','t','\\',
359 'W','i','n','d','o','w','s','\\',
360 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
361 static const WCHAR VersionNumberW[] = {'V','e','r','s','i','o','n','N','u','m','b','e','r',0};
362 static const WCHAR SubVersionNumberW[] = {'S','u','b','V','e','r','s','i','o','n','N','u','m','b','e','r',0};
364 OBJECT_ATTRIBUTES attr;
365 UNICODE_STRING nameW, valueW;
366 HANDLE hkey;
367 char tmp[64];
368 DWORD count;
369 BOOL ret = FALSE;
370 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
372 attr.Length = sizeof(attr);
373 attr.RootDirectory = 0;
374 attr.ObjectName = &nameW;
375 attr.Attributes = 0;
376 attr.SecurityDescriptor = NULL;
377 attr.SecurityQualityOfService = NULL;
378 RtlInitUnicodeString( &nameW, version_keyW );
380 if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) return FALSE;
382 memset( version, 0, sizeof(*version) );
384 RtlInitUnicodeString( &valueW, VersionNumberW );
385 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
387 WCHAR *p, *str = (WCHAR *)info->Data;
388 str[info->DataLength / sizeof(WCHAR)] = 0;
389 p = strchrW( str, '.' );
390 if (p) *p++ = 0;
391 version->dwMajorVersion = atoiW( str );
392 if (p)
394 str = p;
395 p = strchrW( str, '.' );
396 if (p)
398 *p++ = 0;
399 version->dwBuildNumber = atoiW( p );
401 version->dwMinorVersion = atoiW( str );
403 /* build number contains version too on Win9x */
404 version->dwBuildNumber |= MAKEWORD( version->dwMinorVersion, version->dwMajorVersion ) << 16;
407 if (version->dwMajorVersion) /* we got the main version, now fetch the other fields */
409 ret = TRUE;
410 version->dwPlatformId = VER_PLATFORM_WIN32_WINDOWS;
412 RtlInitUnicodeString( &valueW, SubVersionNumberW );
413 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
415 DWORD len = min( info->DataLength, sizeof(version->szCSDVersion) - sizeof(WCHAR) );
416 memcpy( version->szCSDVersion, info->Data, len );
417 version->szCSDVersion[len / sizeof(WCHAR)] = 0;
421 NtClose( hkey );
422 return ret;
426 /**********************************************************************
427 * parse_win_version
429 * Parse the contents of the Version key.
431 static BOOL parse_win_version( HANDLE hkey )
433 static const WCHAR VersionW[] = {'V','e','r','s','i','o','n',0};
435 UNICODE_STRING valueW;
436 char tmp[64], buffer[50];
437 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
438 DWORD count, len;
439 int i;
441 RtlInitUnicodeString( &valueW, VersionW );
442 if (NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
443 return FALSE;
445 RtlUnicodeToMultiByteN( buffer, sizeof(buffer)-1, &len, (WCHAR *)info->Data, info->DataLength );
446 buffer[len] = 0;
448 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
450 const char *p, *pCurr = WinVersionNames[i];
451 /* iterate through all winver aliases separated by comma */
452 do {
453 p = strchr(pCurr, ',');
454 len = p ? p - pCurr : strlen(pCurr);
455 if ( (!strncmp( pCurr, buffer, len )) && (buffer[len] == 0) )
457 current_version = &VersionData[i];
458 TRACE( "got win version %s\n", WinVersionNames[i] );
459 return TRUE;
461 pCurr = p+1;
462 } while (p);
465 MESSAGE("Invalid Windows version value '%s' specified in config file.\n", buffer );
466 MESSAGE("Valid versions are:" );
467 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
469 /* only list the first, "official" alias in case of aliases */
470 const char *pCurr = WinVersionNames[i];
471 const char *p = strchr(pCurr, ',');
472 len = (p) ? p - pCurr : strlen(pCurr);
474 MESSAGE(" '%.*s'%c", (int)len, pCurr, (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
476 return FALSE;
480 /**********************************************************************
481 * version_init
483 void version_init( const WCHAR *appname )
485 static const WCHAR configW[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e',0};
486 static const WCHAR appdefaultsW[] = {'A','p','p','D','e','f','a','u','l','t','s','\\',0};
487 static const BOOL is_win64 = (sizeof(void *) > sizeof(int));
488 OBJECT_ATTRIBUTES attr;
489 UNICODE_STRING nameW;
490 HANDLE root, hkey, config_key;
491 BOOL got_win_ver = FALSE;
493 if (is_win64 || is_wow64)
494 current_version = &VersionData[WINXP64]; /* default if nothing else is specified */
495 else
496 current_version = &VersionData[WINXP];
498 RtlOpenCurrentUser( KEY_ALL_ACCESS, &root );
499 attr.Length = sizeof(attr);
500 attr.RootDirectory = root;
501 attr.ObjectName = &nameW;
502 attr.Attributes = 0;
503 attr.SecurityDescriptor = NULL;
504 attr.SecurityQualityOfService = NULL;
505 RtlInitUnicodeString( &nameW, configW );
507 /* @@ Wine registry key: HKCU\Software\Wine */
508 if (NtOpenKey( &config_key, KEY_ALL_ACCESS, &attr )) config_key = 0;
509 NtClose( root );
510 if (!config_key) goto done;
512 /* open AppDefaults\\appname key */
513 if (appname && *appname)
515 const WCHAR *p;
516 WCHAR appversion[MAX_PATH+20];
518 if ((p = strrchrW( appname, '/' ))) appname = p + 1;
519 if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
521 strcpyW( appversion, appdefaultsW );
522 strcatW( appversion, appname );
523 RtlInitUnicodeString( &nameW, appversion );
524 attr.RootDirectory = config_key;
526 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe */
527 if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
529 TRACE( "getting version from %s\n", debugstr_w(appversion) );
530 got_win_ver = parse_win_version( hkey );
531 NtClose( hkey );
535 if (!got_win_ver)
537 TRACE( "getting default version\n" );
538 got_win_ver = parse_win_version( config_key );
540 NtClose( config_key );
542 done:
543 if (!got_win_ver)
545 static RTL_OSVERSIONINFOEXW registry_version;
547 TRACE( "getting registry version\n" );
548 if (get_nt_registry_version( &registry_version ) ||
549 get_win9x_registry_version( &registry_version ))
550 current_version = &registry_version;
554 NtCurrentTeb()->Peb->OSMajorVersion = current_version->dwMajorVersion;
555 NtCurrentTeb()->Peb->OSMinorVersion = current_version->dwMinorVersion;
556 NtCurrentTeb()->Peb->OSBuildNumber = current_version->dwBuildNumber;
557 NtCurrentTeb()->Peb->OSPlatformId = current_version->dwPlatformId;
559 user_shared_data->NtProductType = current_version->wProductType;
560 user_shared_data->ProductTypeIsValid = TRUE;
561 user_shared_data->NtMajorVersion = current_version->dwMajorVersion;
562 user_shared_data->NtMinorVersion = current_version->dwMinorVersion;
563 user_shared_data->SuiteMask = current_version->wSuiteMask;
565 TRACE( "got %d.%d platform %d build %x name %s service pack %d.%d product %d\n",
566 current_version->dwMajorVersion, current_version->dwMinorVersion,
567 current_version->dwPlatformId, current_version->dwBuildNumber,
568 debugstr_w(current_version->szCSDVersion),
569 current_version->wServicePackMajor, current_version->wServicePackMinor,
570 current_version->wProductType );
573 /***********************************************************************
574 * RtlGetProductInfo (NTDLL.@)
576 * Gives info about the current Windows product type, in a format compatible
577 * with the given Windows version
579 * Returns TRUE if the input is valid, FALSE otherwise
581 BOOLEAN WINAPI RtlGetProductInfo(DWORD dwOSMajorVersion, DWORD dwOSMinorVersion, DWORD dwSpMajorVersion,
582 DWORD dwSpMinorVersion, PDWORD pdwReturnedProductType)
584 TRACE("(%d, %d, %d, %d, %p)\n", dwOSMajorVersion, dwOSMinorVersion,
585 dwSpMajorVersion, dwSpMinorVersion, pdwReturnedProductType);
587 if (!pdwReturnedProductType)
588 return FALSE;
590 if (dwOSMajorVersion < 6)
592 *pdwReturnedProductType = PRODUCT_UNDEFINED;
593 return FALSE;
596 if (current_version->wProductType == VER_NT_WORKSTATION)
597 *pdwReturnedProductType = PRODUCT_ULTIMATE_N;
598 else
599 *pdwReturnedProductType = PRODUCT_STANDARD_SERVER;
601 return TRUE;
604 /***********************************************************************
605 * RtlGetVersion (NTDLL.@)
607 NTSTATUS WINAPI RtlGetVersion( RTL_OSVERSIONINFOEXW *info )
609 info->dwMajorVersion = current_version->dwMajorVersion;
610 info->dwMinorVersion = current_version->dwMinorVersion;
611 info->dwBuildNumber = current_version->dwBuildNumber;
612 info->dwPlatformId = current_version->dwPlatformId;
613 strcpyW( info->szCSDVersion, current_version->szCSDVersion );
614 if(info->dwOSVersionInfoSize == sizeof(RTL_OSVERSIONINFOEXW))
616 info->wServicePackMajor = current_version->wServicePackMajor;
617 info->wServicePackMinor = current_version->wServicePackMinor;
618 info->wSuiteMask = current_version->wSuiteMask;
619 info->wProductType = current_version->wProductType;
621 return STATUS_SUCCESS;
625 /******************************************************************************
626 * RtlGetNtVersionNumbers (NTDLL.@)
628 * Get the version numbers of the run time library.
630 * PARAMS
631 * major [O] Destination for the Major version
632 * minor [O] Destination for the Minor version
633 * build [O] Destination for the Build version
635 * RETURNS
636 * Nothing.
638 * NOTES
639 * Introduced in Windows XP (NT5.1)
641 void WINAPI RtlGetNtVersionNumbers( LPDWORD major, LPDWORD minor, LPDWORD build )
643 if (major) *major = current_version->dwMajorVersion;
644 if (minor) *minor = current_version->dwMinorVersion;
645 /* FIXME: Does anybody know the real formula? */
646 if (build) *build = (0xF0000000 | current_version->dwBuildNumber);
650 /******************************************************************************
651 * RtlGetNtProductType (NTDLL.@)
653 BOOLEAN WINAPI RtlGetNtProductType( LPDWORD type )
655 if (type) *type = current_version->wProductType;
656 return TRUE;
660 static inline NTSTATUS version_compare_values(ULONG left, ULONG right, UCHAR condition)
662 switch (condition) {
663 case VER_EQUAL:
664 if (left != right) return STATUS_REVISION_MISMATCH;
665 break;
666 case VER_GREATER:
667 if (left <= right) return STATUS_REVISION_MISMATCH;
668 break;
669 case VER_GREATER_EQUAL:
670 if (left < right) return STATUS_REVISION_MISMATCH;
671 break;
672 case VER_LESS:
673 if (left >= right) return STATUS_REVISION_MISMATCH;
674 break;
675 case VER_LESS_EQUAL:
676 if (left > right) return STATUS_REVISION_MISMATCH;
677 break;
678 default:
679 return STATUS_REVISION_MISMATCH;
681 return STATUS_SUCCESS;
684 /******************************************************************************
685 * RtlVerifyVersionInfo (NTDLL.@)
687 NTSTATUS WINAPI RtlVerifyVersionInfo( const RTL_OSVERSIONINFOEXW *info,
688 DWORD dwTypeMask, DWORDLONG dwlConditionMask )
690 RTL_OSVERSIONINFOEXW ver;
691 NTSTATUS status;
693 TRACE("(%p,0x%x,0x%s)\n", info, dwTypeMask, wine_dbgstr_longlong(dwlConditionMask));
695 ver.dwOSVersionInfoSize = sizeof(ver);
696 if ((status = RtlGetVersion( &ver )) != STATUS_SUCCESS) return status;
698 if(!(dwTypeMask && dwlConditionMask)) return STATUS_INVALID_PARAMETER;
700 if(dwTypeMask & VER_PRODUCT_TYPE)
702 status = version_compare_values(ver.wProductType, info->wProductType, dwlConditionMask >> 7*3 & 0x07);
703 if (status != STATUS_SUCCESS)
704 return status;
706 if(dwTypeMask & VER_SUITENAME)
707 switch(dwlConditionMask >> 6*3 & 0x07)
709 case VER_AND:
710 if((info->wSuiteMask & ver.wSuiteMask) != info->wSuiteMask)
711 return STATUS_REVISION_MISMATCH;
712 break;
713 case VER_OR:
714 if(!(info->wSuiteMask & ver.wSuiteMask) && info->wSuiteMask)
715 return STATUS_REVISION_MISMATCH;
716 break;
717 default:
718 return STATUS_INVALID_PARAMETER;
720 if(dwTypeMask & VER_PLATFORMID)
722 status = version_compare_values(ver.dwPlatformId, info->dwPlatformId, dwlConditionMask >> 3*3 & 0x07);
723 if (status != STATUS_SUCCESS)
724 return status;
726 if(dwTypeMask & VER_BUILDNUMBER)
728 status = version_compare_values(ver.dwBuildNumber, info->dwBuildNumber, dwlConditionMask >> 2*3 & 0x07);
729 if (status != STATUS_SUCCESS)
730 return status;
733 if(dwTypeMask & (VER_MAJORVERSION|VER_MINORVERSION|VER_SERVICEPACKMAJOR|VER_SERVICEPACKMINOR))
735 unsigned char condition = 0;
736 BOOLEAN do_next_check = TRUE;
738 if(dwTypeMask & VER_MAJORVERSION)
739 condition = dwlConditionMask >> 1*3 & 0x07;
740 else if(dwTypeMask & VER_MINORVERSION)
741 condition = dwlConditionMask >> 0*3 & 0x07;
742 else if(dwTypeMask & VER_SERVICEPACKMAJOR)
743 condition = dwlConditionMask >> 5*3 & 0x07;
744 else if(dwTypeMask & VER_SERVICEPACKMINOR)
745 condition = dwlConditionMask >> 4*3 & 0x07;
747 if(dwTypeMask & VER_MAJORVERSION)
749 status = version_compare_values(ver.dwMajorVersion, info->dwMajorVersion, condition);
750 do_next_check = (ver.dwMajorVersion == info->dwMajorVersion) &&
751 ((condition != VER_EQUAL) || (status == STATUS_SUCCESS));
753 if((dwTypeMask & VER_MINORVERSION) && do_next_check)
755 status = version_compare_values(ver.dwMinorVersion, info->dwMinorVersion, condition);
756 do_next_check = (ver.dwMinorVersion == info->dwMinorVersion) &&
757 ((condition != VER_EQUAL) || (status == STATUS_SUCCESS));
759 if((dwTypeMask & VER_SERVICEPACKMAJOR) && do_next_check)
761 status = version_compare_values(ver.wServicePackMajor, info->wServicePackMajor, condition);
762 do_next_check = (ver.wServicePackMajor == info->wServicePackMajor) &&
763 ((condition != VER_EQUAL) || (status == STATUS_SUCCESS));
765 if((dwTypeMask & VER_SERVICEPACKMINOR) && do_next_check)
767 status = version_compare_values(ver.wServicePackMinor, info->wServicePackMinor, condition);
770 if (status != STATUS_SUCCESS)
771 return status;
774 return STATUS_SUCCESS;