ntdll: Use wcsicmp() instead of strcmpiW() where possible.
[wine.git] / dlls / ntdll / version.c
blob4994dbbb5e5ed9321c9e9f06bdc2090d833ad791
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 WIN10, /* Windows 10 */
62 NB_WINDOWS_VERSIONS
63 } WINDOWS_VERSION;
65 /* FIXME: compare values below with original and fix.
66 * An *excellent* win9x version page (ALL versions !)
67 * can be found at www.mdgx.com/ver.htm */
68 static const RTL_OSVERSIONINFOEXW VersionData[NB_WINDOWS_VERSIONS] =
70 /* WIN20 FIXME: verify values */
72 sizeof(RTL_OSVERSIONINFOEXW), 2, 0, 0, VER_PLATFORM_WIN32s,
73 {'W','i','n','3','2','s',' ','1','.','3',0},
74 0, 0, 0, 0, 0
76 /* WIN30 FIXME: verify values */
78 sizeof(RTL_OSVERSIONINFOEXW), 3, 0, 0, VER_PLATFORM_WIN32s,
79 {'W','i','n','3','2','s',' ','1','.','3',0},
80 0, 0, 0, 0, 0
82 /* WIN31 */
84 sizeof(RTL_OSVERSIONINFOEXW), 3, 10, 0, VER_PLATFORM_WIN32s,
85 {'W','i','n','3','2','s',' ','1','.','3',0},
86 0, 0, 0, 0, 0
88 /* WIN95 */
90 /* Win95: 4, 0, 0x40003B6, ""
91 * Win95sp1: 4, 0, 0x40003B6, " A " (according to doc)
92 * Win95osr2: 4, 0, 0x4000457, " B " (according to doc)
93 * Win95osr2.1: 4, 3, 0x40304BC, " B " (according to doc)
94 * Win95osr2.5: 4, 3, 0x40304BE, " C " (according to doc)
95 * Win95a/b can be discerned via regkey SubVersionNumber
97 sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x40003B6, VER_PLATFORM_WIN32_WINDOWS,
98 {0},
99 0, 0, 0, 0, 0
101 /* WIN98 (second edition) */
103 /* Win98: 4, 10, 0x40A07CE, " " 4.10.1998
104 * Win98SE: 4, 10, 0x40A08AE, " A " 4.10.2222
106 sizeof(RTL_OSVERSIONINFOEXW), 4, 10, 0x40A08AE, VER_PLATFORM_WIN32_WINDOWS,
107 {' ','A',' ',0},
108 0, 0, 0, 0, 0
110 /* WINME */
112 sizeof(RTL_OSVERSIONINFOEXW), 4, 90, 0x45A0BB8, VER_PLATFORM_WIN32_WINDOWS,
113 {' ',0},
114 0, 0, 0, 0, 0
116 /* NT351 */
118 sizeof(RTL_OSVERSIONINFOEXW), 3, 51, 0x421, VER_PLATFORM_WIN32_NT,
119 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','5',0},
120 5, 0, 0, VER_NT_WORKSTATION, 0
122 /* NT40 */
124 sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x565, VER_PLATFORM_WIN32_NT,
125 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','6','a',0},
126 6, 0, 0, VER_NT_WORKSTATION, 0
128 /* NT2K */
130 sizeof(RTL_OSVERSIONINFOEXW), 5, 0, 0x893, VER_PLATFORM_WIN32_NT,
131 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','4',0},
132 4, 0, 0, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
134 /* WINXP */
136 sizeof(RTL_OSVERSIONINFOEXW), 5, 1, 0xA28, VER_PLATFORM_WIN32_NT,
137 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0},
138 3, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
140 /* WINXP64 */
142 sizeof(RTL_OSVERSIONINFOEXW), 5, 2, 0xECE, VER_PLATFORM_WIN32_NT,
143 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
144 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
146 /* WIN2K3 */
148 sizeof(RTL_OSVERSIONINFOEXW), 5, 2, 0xECE, VER_PLATFORM_WIN32_NT,
149 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
150 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
152 /* WINVISTA */
154 sizeof(RTL_OSVERSIONINFOEXW), 6, 0, 0x1772, VER_PLATFORM_WIN32_NT,
155 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
156 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
158 /* WIN2K8 */
160 sizeof(RTL_OSVERSIONINFOEXW), 6, 0, 0x1772, VER_PLATFORM_WIN32_NT,
161 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
162 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
164 /* WIN7 */
166 sizeof(RTL_OSVERSIONINFOEXW), 6, 1, 0x1DB1, VER_PLATFORM_WIN32_NT,
167 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','1',0},
168 1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
170 /* WIN2K8R2 */
172 sizeof(RTL_OSVERSIONINFOEXW), 6, 1, 0x1DB1, VER_PLATFORM_WIN32_NT,
173 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','1',0},
174 1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
176 /* WIN8 */
178 sizeof(RTL_OSVERSIONINFOEXW), 6, 2, 0x23F0, VER_PLATFORM_WIN32_NT,
179 {0}, 0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
181 /* WIN81 */
183 sizeof(RTL_OSVERSIONINFOEXW), 6, 3, 0x2580, VER_PLATFORM_WIN32_NT,
184 {0}, 0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
186 /* WIN10 */
188 sizeof(RTL_OSVERSIONINFOEXW), 10, 0, 0x42EE, VER_PLATFORM_WIN32_NT,
189 {0}, 0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
194 static const struct { WCHAR name[12]; WINDOWS_VERSION ver; } version_names[] =
196 { {'w','i','n','2','0',0}, WIN20 },
197 { {'w','i','n','3','0',0}, WIN30 },
198 { {'w','i','n','3','1',0}, WIN31 },
199 { {'w','i','n','9','5',0}, WIN95 },
200 { {'w','i','n','9','8',0}, WIN98 },
201 { {'w','i','n','m','e',0}, WINME },
202 { {'n','t','3','5','1',0}, NT351 },
203 { {'n','t','4','0',0}, NT40 },
204 { {'w','i','n','2','0','0','0',0}, NT2K },
205 { {'w','i','n','2','k',0}, NT2K },
206 { {'n','t','2','k',0}, NT2K },
207 { {'n','t','2','0','0','0',0}, NT2K },
208 { {'w','i','n','x','p',0}, WINXP },
209 { {'w','i','n','x','p','6','4',0}, WINXP64 },
210 { {'w','i','n','2','0','0','3',0}, WIN2K3 },
211 { {'w','i','n','2','k','3',0}, WIN2K3 },
212 { {'v','i','s','t','a',0}, WINVISTA },
213 { {'w','i','n','v','i','s','t','a',0}, WINVISTA },
214 { {'w','i','n','2','0','0','8',0}, WIN2K8 },
215 { {'w','i','n','2','k','8',0}, WIN2K8 },
216 { {'w','i','n','2','0','0','8','r','2',0}, WIN2K8R2 },
217 { {'w','i','n','2','k','8','r','2',0}, WIN2K8R2 },
218 { {'w','i','n','7',0}, WIN7 },
219 { {'w','i','n','8',0}, WIN8 },
220 { {'w','i','n','8','1',0}, WIN81 },
221 { {'w','i','n','1','0',0}, WIN10 },
225 /* initialized to null so that we crash if we try to retrieve the version too early at startup */
226 static const RTL_OSVERSIONINFOEXW *current_version;
229 /**********************************************************************
230 * get_nt_registry_version
232 * Fetch the version information from the NT-style registry keys.
234 static BOOL get_nt_registry_version( RTL_OSVERSIONINFOEXW *version )
236 static const WCHAR version_keyW[] = {'M','a','c','h','i','n','e','\\',
237 'S','o','f','t','w','a','r','e','\\',
238 'M','i','c','r','o','s','o','f','t','\\',
239 'W','i','n','d','o','w','s',' ','N','T','\\',
240 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
241 static const WCHAR service_pack_keyW[] = {'M','a','c','h','i','n','e','\\',
242 'S','y','s','t','e','m','\\',
243 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
244 'C','o','n','t','r','o','l','\\',
245 'W','i','n','d','o','w','s',0};
246 static const WCHAR product_keyW[] = {'M','a','c','h','i','n','e','\\',
247 'S','y','s','t','e','m','\\',
248 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
249 'C','o','n','t','r','o','l','\\',
250 'P','r','o','d','u','c','t','O','p','t','i','o','n','s',0};
251 static const WCHAR CurrentBuildNumberW[] = {'C','u','r','r','e','n','t','B','u','i','l','d','N','u','m','b','e','r',0};
252 static const WCHAR CSDVersionW[] = {'C','S','D','V','e','r','s','i','o','n',0};
253 static const WCHAR CurrentVersionW[] = {'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
254 static const WCHAR ProductTypeW[] = {'P','r','o','d','u','c','t','T','y','p','e',0};
255 static const WCHAR WinNTW[] = {'W','i','n','N','T',0};
256 static const WCHAR ServerNTW[] = {'S','e','r','v','e','r','N','T',0};
257 static const WCHAR LanmanNTW[] = {'L','a','n','m','a','n','N','T',0};
259 OBJECT_ATTRIBUTES attr;
260 UNICODE_STRING nameW, valueW;
261 HANDLE hkey, hkey2;
262 char tmp[64];
263 DWORD count;
264 BOOL ret = FALSE;
265 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
267 attr.Length = sizeof(attr);
268 attr.RootDirectory = 0;
269 attr.ObjectName = &nameW;
270 attr.Attributes = 0;
271 attr.SecurityDescriptor = NULL;
272 attr.SecurityQualityOfService = NULL;
273 RtlInitUnicodeString( &nameW, version_keyW );
275 if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) return FALSE;
277 memset( version, 0, sizeof(*version) );
279 RtlInitUnicodeString( &valueW, CurrentVersionW );
280 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
282 WCHAR *p, *str = (WCHAR *)info->Data;
283 str[info->DataLength / sizeof(WCHAR)] = 0;
284 p = strchrW( str, '.' );
285 if (p)
287 *p++ = 0;
288 version->dwMinorVersion = atoiW( p );
290 version->dwMajorVersion = atoiW( str );
293 if (version->dwMajorVersion) /* we got the main version, now fetch the other fields */
295 ret = TRUE;
296 version->dwPlatformId = VER_PLATFORM_WIN32_NT;
298 /* get build number */
300 RtlInitUnicodeString( &valueW, CurrentBuildNumberW );
301 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
303 WCHAR *str = (WCHAR *)info->Data;
304 str[info->DataLength / sizeof(WCHAR)] = 0;
305 version->dwBuildNumber = atoiW( str );
308 /* get version description */
310 RtlInitUnicodeString( &valueW, CSDVersionW );
311 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
313 DWORD len = min( info->DataLength, sizeof(version->szCSDVersion) - sizeof(WCHAR) );
314 memcpy( version->szCSDVersion, info->Data, len );
315 version->szCSDVersion[len / sizeof(WCHAR)] = 0;
318 /* get service pack version */
320 RtlInitUnicodeString( &nameW, service_pack_keyW );
321 if (!NtOpenKey( &hkey2, KEY_ALL_ACCESS, &attr ))
323 RtlInitUnicodeString( &valueW, CSDVersionW );
324 if (!NtQueryValueKey( hkey2, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
326 if (info->DataLength >= sizeof(DWORD))
328 DWORD dw = *(DWORD *)info->Data;
329 version->wServicePackMajor = LOWORD(dw) >> 8;
330 version->wServicePackMinor = LOWORD(dw) & 0xff;
333 NtClose( hkey2 );
336 /* get product type */
338 RtlInitUnicodeString( &nameW, product_keyW );
339 if (!NtOpenKey( &hkey2, KEY_ALL_ACCESS, &attr ))
341 RtlInitUnicodeString( &valueW, ProductTypeW );
342 if (!NtQueryValueKey( hkey2, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
344 WCHAR *str = (WCHAR *)info->Data;
345 str[info->DataLength / sizeof(WCHAR)] = 0;
346 if (!wcsicmp( str, WinNTW )) version->wProductType = VER_NT_WORKSTATION;
347 else if (!wcsicmp( str, LanmanNTW )) version->wProductType = VER_NT_DOMAIN_CONTROLLER;
348 else if (!wcsicmp( str, ServerNTW )) version->wProductType = VER_NT_SERVER;
350 NtClose( hkey2 );
353 /* FIXME: get wSuiteMask */
356 NtClose( hkey );
357 return ret;
361 /**********************************************************************
362 * get_win9x_registry_version
364 * Fetch the version information from the Win9x-style registry keys.
366 static BOOL get_win9x_registry_version( RTL_OSVERSIONINFOEXW *version )
368 static const WCHAR version_keyW[] = {'M','a','c','h','i','n','e','\\',
369 'S','o','f','t','w','a','r','e','\\',
370 'M','i','c','r','o','s','o','f','t','\\',
371 'W','i','n','d','o','w','s','\\',
372 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
373 static const WCHAR VersionNumberW[] = {'V','e','r','s','i','o','n','N','u','m','b','e','r',0};
374 static const WCHAR SubVersionNumberW[] = {'S','u','b','V','e','r','s','i','o','n','N','u','m','b','e','r',0};
376 OBJECT_ATTRIBUTES attr;
377 UNICODE_STRING nameW, valueW;
378 HANDLE hkey;
379 char tmp[64];
380 DWORD count;
381 BOOL ret = FALSE;
382 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
384 attr.Length = sizeof(attr);
385 attr.RootDirectory = 0;
386 attr.ObjectName = &nameW;
387 attr.Attributes = 0;
388 attr.SecurityDescriptor = NULL;
389 attr.SecurityQualityOfService = NULL;
390 RtlInitUnicodeString( &nameW, version_keyW );
392 if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) return FALSE;
394 memset( version, 0, sizeof(*version) );
396 RtlInitUnicodeString( &valueW, VersionNumberW );
397 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
399 WCHAR *p, *str = (WCHAR *)info->Data;
400 str[info->DataLength / sizeof(WCHAR)] = 0;
401 p = strchrW( str, '.' );
402 if (p) *p++ = 0;
403 version->dwMajorVersion = atoiW( str );
404 if (p)
406 str = p;
407 p = strchrW( str, '.' );
408 if (p)
410 *p++ = 0;
411 version->dwBuildNumber = atoiW( p );
413 version->dwMinorVersion = atoiW( str );
415 /* build number contains version too on Win9x */
416 version->dwBuildNumber |= MAKEWORD( version->dwMinorVersion, version->dwMajorVersion ) << 16;
419 if (version->dwMajorVersion) /* we got the main version, now fetch the other fields */
421 ret = TRUE;
422 version->dwPlatformId = VER_PLATFORM_WIN32_WINDOWS;
424 RtlInitUnicodeString( &valueW, SubVersionNumberW );
425 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
427 DWORD len = min( info->DataLength, sizeof(version->szCSDVersion) - sizeof(WCHAR) );
428 memcpy( version->szCSDVersion, info->Data, len );
429 version->szCSDVersion[len / sizeof(WCHAR)] = 0;
433 NtClose( hkey );
434 return ret;
438 /**********************************************************************
439 * parse_win_version
441 * Parse the contents of the Version key.
443 static BOOL parse_win_version( HANDLE hkey )
445 static const WCHAR VersionW[] = {'V','e','r','s','i','o','n',0};
447 UNICODE_STRING valueW;
448 WCHAR *name, tmp[64];
449 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
450 DWORD i, count;
452 RtlInitUnicodeString( &valueW, VersionW );
453 if (NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp) - sizeof(WCHAR), &count ))
454 return FALSE;
456 name = (WCHAR *)info->Data;
457 name[info->DataLength / sizeof(WCHAR)] = 0;
459 for (i = 0; i < ARRAY_SIZE(version_names); i++)
461 if (strcmpW( version_names[i].name, name )) continue;
462 current_version = &VersionData[version_names[i].ver];
463 TRACE( "got win version %s\n", debugstr_w(version_names[i].name) );
464 return TRUE;
467 ERR( "Invalid Windows version value %s specified in config file.\n", debugstr_w(name) );
468 return FALSE;
472 /**********************************************************************
473 * version_init
475 void version_init(void)
477 static const WCHAR configW[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e',0};
478 static const WCHAR appdefaultsW[] = {'A','p','p','D','e','f','a','u','l','t','s','\\',0};
479 OBJECT_ATTRIBUTES attr;
480 UNICODE_STRING nameW;
481 HANDLE root, hkey, config_key;
482 BOOL got_win_ver = FALSE;
483 const WCHAR *p, *appname = NtCurrentTeb()->Peb->ProcessParameters->ImagePathName.Buffer;
484 WCHAR appversion[MAX_PATH+20];
486 current_version = &VersionData[WIN7];
488 RtlOpenCurrentUser( KEY_ALL_ACCESS, &root );
489 attr.Length = sizeof(attr);
490 attr.RootDirectory = root;
491 attr.ObjectName = &nameW;
492 attr.Attributes = 0;
493 attr.SecurityDescriptor = NULL;
494 attr.SecurityQualityOfService = NULL;
495 RtlInitUnicodeString( &nameW, configW );
497 /* @@ Wine registry key: HKCU\Software\Wine */
498 if (NtOpenKey( &config_key, KEY_ALL_ACCESS, &attr )) config_key = 0;
499 NtClose( root );
500 if (!config_key) goto done;
502 /* open AppDefaults\\appname key */
504 if ((p = strrchrW( appname, '/' ))) appname = p + 1;
505 if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
507 strcpyW( appversion, appdefaultsW );
508 strcatW( appversion, appname );
509 RtlInitUnicodeString( &nameW, appversion );
510 attr.RootDirectory = config_key;
512 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe */
513 if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
515 TRACE( "getting version from %s\n", debugstr_w(appversion) );
516 got_win_ver = parse_win_version( hkey );
517 NtClose( hkey );
520 if (!got_win_ver)
522 TRACE( "getting default version\n" );
523 got_win_ver = parse_win_version( config_key );
525 NtClose( config_key );
527 done:
528 if (!got_win_ver)
530 static RTL_OSVERSIONINFOEXW registry_version;
532 TRACE( "getting registry version\n" );
533 if (get_nt_registry_version( &registry_version ) ||
534 get_win9x_registry_version( &registry_version ))
535 current_version = &registry_version;
539 NtCurrentTeb()->Peb->OSMajorVersion = current_version->dwMajorVersion;
540 NtCurrentTeb()->Peb->OSMinorVersion = current_version->dwMinorVersion;
541 NtCurrentTeb()->Peb->OSBuildNumber = current_version->dwBuildNumber;
542 NtCurrentTeb()->Peb->OSPlatformId = current_version->dwPlatformId;
544 user_shared_data->NtProductType = current_version->wProductType;
545 user_shared_data->ProductTypeIsValid = TRUE;
546 user_shared_data->NtMajorVersion = current_version->dwMajorVersion;
547 user_shared_data->NtMinorVersion = current_version->dwMinorVersion;
548 user_shared_data->SuiteMask = current_version->wSuiteMask;
550 TRACE( "got %d.%d platform %d build %x name %s service pack %d.%d product %d\n",
551 current_version->dwMajorVersion, current_version->dwMinorVersion,
552 current_version->dwPlatformId, current_version->dwBuildNumber,
553 debugstr_w(current_version->szCSDVersion),
554 current_version->wServicePackMajor, current_version->wServicePackMinor,
555 current_version->wProductType );
558 /***********************************************************************
559 * RtlGetProductInfo (NTDLL.@)
561 * Gives info about the current Windows product type, in a format compatible
562 * with the given Windows version
564 * Returns TRUE if the input is valid, FALSE otherwise
566 BOOLEAN WINAPI RtlGetProductInfo(DWORD dwOSMajorVersion, DWORD dwOSMinorVersion, DWORD dwSpMajorVersion,
567 DWORD dwSpMinorVersion, PDWORD pdwReturnedProductType)
569 TRACE("(%d, %d, %d, %d, %p)\n", dwOSMajorVersion, dwOSMinorVersion,
570 dwSpMajorVersion, dwSpMinorVersion, pdwReturnedProductType);
572 if (!pdwReturnedProductType)
573 return FALSE;
575 if (dwOSMajorVersion < 6)
577 *pdwReturnedProductType = PRODUCT_UNDEFINED;
578 return FALSE;
581 if (current_version->wProductType == VER_NT_WORKSTATION)
582 *pdwReturnedProductType = PRODUCT_ULTIMATE_N;
583 else
584 *pdwReturnedProductType = PRODUCT_STANDARD_SERVER;
586 return TRUE;
589 /***********************************************************************
590 * RtlGetVersion (NTDLL.@)
592 NTSTATUS WINAPI RtlGetVersion( RTL_OSVERSIONINFOEXW *info )
594 info->dwMajorVersion = current_version->dwMajorVersion;
595 info->dwMinorVersion = current_version->dwMinorVersion;
596 info->dwBuildNumber = current_version->dwBuildNumber;
597 info->dwPlatformId = current_version->dwPlatformId;
598 strcpyW( info->szCSDVersion, current_version->szCSDVersion );
599 if(info->dwOSVersionInfoSize == sizeof(RTL_OSVERSIONINFOEXW))
601 info->wServicePackMajor = current_version->wServicePackMajor;
602 info->wServicePackMinor = current_version->wServicePackMinor;
603 info->wSuiteMask = current_version->wSuiteMask;
604 info->wProductType = current_version->wProductType;
606 return STATUS_SUCCESS;
610 /******************************************************************************
611 * RtlGetNtVersionNumbers (NTDLL.@)
613 * Get the version numbers of the run time library.
615 * PARAMS
616 * major [O] Destination for the Major version
617 * minor [O] Destination for the Minor version
618 * build [O] Destination for the Build version
620 * RETURNS
621 * Nothing.
623 * NOTES
624 * Introduced in Windows XP (NT5.1)
626 void WINAPI RtlGetNtVersionNumbers( LPDWORD major, LPDWORD minor, LPDWORD build )
628 if (major) *major = current_version->dwMajorVersion;
629 if (minor) *minor = current_version->dwMinorVersion;
630 /* FIXME: Does anybody know the real formula? */
631 if (build) *build = (0xF0000000 | current_version->dwBuildNumber);
635 /******************************************************************************
636 * RtlGetNtProductType (NTDLL.@)
638 BOOLEAN WINAPI RtlGetNtProductType( LPDWORD type )
640 if (type) *type = current_version->wProductType;
641 return TRUE;
644 static inline UCHAR version_update_condition(UCHAR *last_condition, UCHAR condition)
646 switch (*last_condition)
648 case 0:
649 *last_condition = condition;
650 break;
651 case VER_EQUAL:
652 if (condition >= VER_EQUAL && condition <= VER_LESS_EQUAL)
654 *last_condition = condition;
655 return condition;
657 break;
658 case VER_GREATER:
659 case VER_GREATER_EQUAL:
660 if (condition >= VER_EQUAL && condition <= VER_GREATER_EQUAL)
661 return condition;
662 break;
663 case VER_LESS:
664 case VER_LESS_EQUAL:
665 if (condition == VER_EQUAL || (condition >= VER_LESS && condition <= VER_LESS_EQUAL))
666 return condition;
667 break;
669 if (!condition) *last_condition |= 0x10;
670 return *last_condition & 0xf;
673 static inline NTSTATUS version_compare_values(ULONG left, ULONG right, UCHAR condition)
675 switch (condition) {
676 case VER_EQUAL:
677 if (left != right) return STATUS_REVISION_MISMATCH;
678 break;
679 case VER_GREATER:
680 if (left <= right) return STATUS_REVISION_MISMATCH;
681 break;
682 case VER_GREATER_EQUAL:
683 if (left < right) return STATUS_REVISION_MISMATCH;
684 break;
685 case VER_LESS:
686 if (left >= right) return STATUS_REVISION_MISMATCH;
687 break;
688 case VER_LESS_EQUAL:
689 if (left > right) return STATUS_REVISION_MISMATCH;
690 break;
691 default:
692 return STATUS_REVISION_MISMATCH;
694 return STATUS_SUCCESS;
697 /******************************************************************************
698 * RtlVerifyVersionInfo (NTDLL.@)
700 NTSTATUS WINAPI RtlVerifyVersionInfo( const RTL_OSVERSIONINFOEXW *info,
701 DWORD dwTypeMask, DWORDLONG dwlConditionMask )
703 RTL_OSVERSIONINFOEXW ver;
704 NTSTATUS status;
706 TRACE("(%p,0x%x,0x%s)\n", info, dwTypeMask, wine_dbgstr_longlong(dwlConditionMask));
708 ver.dwOSVersionInfoSize = sizeof(ver);
709 if ((status = RtlGetVersion( &ver )) != STATUS_SUCCESS) return status;
711 if(!(dwTypeMask && dwlConditionMask)) return STATUS_INVALID_PARAMETER;
713 if(dwTypeMask & VER_PRODUCT_TYPE)
715 status = version_compare_values(ver.wProductType, info->wProductType, dwlConditionMask >> 7*3 & 0x07);
716 if (status != STATUS_SUCCESS)
717 return status;
719 if(dwTypeMask & VER_SUITENAME)
720 switch(dwlConditionMask >> 6*3 & 0x07)
722 case VER_AND:
723 if((info->wSuiteMask & ver.wSuiteMask) != info->wSuiteMask)
724 return STATUS_REVISION_MISMATCH;
725 break;
726 case VER_OR:
727 if(!(info->wSuiteMask & ver.wSuiteMask) && info->wSuiteMask)
728 return STATUS_REVISION_MISMATCH;
729 break;
730 default:
731 return STATUS_INVALID_PARAMETER;
733 if(dwTypeMask & VER_PLATFORMID)
735 status = version_compare_values(ver.dwPlatformId, info->dwPlatformId, dwlConditionMask >> 3*3 & 0x07);
736 if (status != STATUS_SUCCESS)
737 return status;
739 if(dwTypeMask & VER_BUILDNUMBER)
741 status = version_compare_values(ver.dwBuildNumber, info->dwBuildNumber, dwlConditionMask >> 2*3 & 0x07);
742 if (status != STATUS_SUCCESS)
743 return status;
746 if(dwTypeMask & (VER_MAJORVERSION|VER_MINORVERSION|VER_SERVICEPACKMAJOR|VER_SERVICEPACKMINOR))
748 unsigned char condition, last_condition = 0;
749 BOOLEAN do_next_check = TRUE;
751 if(dwTypeMask & VER_MAJORVERSION)
753 condition = version_update_condition(&last_condition, dwlConditionMask >> 1*3 & 0x07);
754 status = version_compare_values(ver.dwMajorVersion, info->dwMajorVersion, condition);
755 do_next_check = (ver.dwMajorVersion == info->dwMajorVersion) &&
756 ((condition >= VER_EQUAL) && (condition <= VER_LESS_EQUAL));
758 if((dwTypeMask & VER_MINORVERSION) && do_next_check)
760 condition = version_update_condition(&last_condition, dwlConditionMask >> 0*3 & 0x07);
761 status = version_compare_values(ver.dwMinorVersion, info->dwMinorVersion, condition);
762 do_next_check = (ver.dwMinorVersion == info->dwMinorVersion) &&
763 ((condition >= VER_EQUAL) && (condition <= VER_LESS_EQUAL));
765 if((dwTypeMask & VER_SERVICEPACKMAJOR) && do_next_check)
767 condition = version_update_condition(&last_condition, dwlConditionMask >> 5*3 & 0x07);
768 status = version_compare_values(ver.wServicePackMajor, info->wServicePackMajor, condition);
769 do_next_check = (ver.wServicePackMajor == info->wServicePackMajor) &&
770 ((condition >= VER_EQUAL) && (condition <= VER_LESS_EQUAL));
772 if((dwTypeMask & VER_SERVICEPACKMINOR) && do_next_check)
774 condition = version_update_condition(&last_condition, dwlConditionMask >> 4*3 & 0x07);
775 status = version_compare_values(ver.wServicePackMinor, info->wServicePackMinor, condition);
778 if (status != STATUS_SUCCESS)
779 return status;
782 return STATUS_SUCCESS;