Release 1.3.7.
[wine/gsoc-2012-control.git] / dlls / ntdll / version.c
blobe10990573d0c368e4f5ea29d3cb0e7d723ad075f
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 WIN7, /* Windows 7 */
57 NB_WINDOWS_VERSIONS
58 } WINDOWS_VERSION;
60 /* FIXME: compare values below with original and fix.
61 * An *excellent* win9x version page (ALL versions !)
62 * can be found at www.mdgx.com/ver.htm */
63 static const RTL_OSVERSIONINFOEXW VersionData[NB_WINDOWS_VERSIONS] =
65 /* WIN20 FIXME: verify values */
67 sizeof(RTL_OSVERSIONINFOEXW), 2, 0, 0, VER_PLATFORM_WIN32s,
68 {'W','i','n','3','2','s',' ','1','.','3',0},
69 0, 0, 0, 0, 0
71 /* WIN30 FIXME: verify values */
73 sizeof(RTL_OSVERSIONINFOEXW), 3, 0, 0, VER_PLATFORM_WIN32s,
74 {'W','i','n','3','2','s',' ','1','.','3',0},
75 0, 0, 0, 0, 0
77 /* WIN31 */
79 sizeof(RTL_OSVERSIONINFOEXW), 3, 10, 0, VER_PLATFORM_WIN32s,
80 {'W','i','n','3','2','s',' ','1','.','3',0},
81 0, 0, 0, 0, 0
83 /* WIN95 */
85 /* Win95: 4, 0, 0x40003B6, ""
86 * Win95sp1: 4, 0, 0x40003B6, " A " (according to doc)
87 * Win95osr2: 4, 0, 0x4000457, " B " (according to doc)
88 * Win95osr2.1: 4, 3, 0x40304BC, " B " (according to doc)
89 * Win95osr2.5: 4, 3, 0x40304BE, " C " (according to doc)
90 * Win95a/b can be discerned via regkey SubVersionNumber
92 sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x40003B6, VER_PLATFORM_WIN32_WINDOWS,
93 {0},
94 0, 0, 0, 0, 0
96 /* WIN98 (second edition) */
98 /* Win98: 4, 10, 0x40A07CE, " " 4.10.1998
99 * Win98SE: 4, 10, 0x40A08AE, " A " 4.10.2222
101 sizeof(RTL_OSVERSIONINFOEXW), 4, 10, 0x40A08AE, VER_PLATFORM_WIN32_WINDOWS,
102 {' ','A',' ',0},
103 0, 0, 0, 0, 0
105 /* WINME */
107 sizeof(RTL_OSVERSIONINFOEXW), 4, 90, 0x45A0BB8, VER_PLATFORM_WIN32_WINDOWS,
108 {' ',0},
109 0, 0, 0, 0, 0
111 /* NT351 */
113 sizeof(RTL_OSVERSIONINFOEXW), 3, 51, 0x421, VER_PLATFORM_WIN32_NT,
114 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
115 0, 0, 0, 0, 0
117 /* NT40 */
119 sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x565, VER_PLATFORM_WIN32_NT,
120 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','6','a',0},
121 6, 0, 0, VER_NT_WORKSTATION, 0
123 /* NT2K */
125 sizeof(RTL_OSVERSIONINFOEXW), 5, 0, 0x893, VER_PLATFORM_WIN32_NT,
126 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','4',0},
127 4, 0, 0, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
129 /* WINXP */
131 sizeof(RTL_OSVERSIONINFOEXW), 5, 1, 0xA28, VER_PLATFORM_WIN32_NT,
132 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0},
133 3, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
135 /* WIN2K3 */
137 sizeof(RTL_OSVERSIONINFOEXW), 5, 2, 0xECE, VER_PLATFORM_WIN32_NT,
138 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','1',0},
139 1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
141 /* WINVISTA */
143 sizeof(RTL_OSVERSIONINFOEXW), 6, 0, 0x1772, VER_PLATFORM_WIN32_NT,
144 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
145 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
147 /* WIN2K8 */
149 sizeof(RTL_OSVERSIONINFOEXW), 6, 0, 0x1771, VER_PLATFORM_WIN32_NT,
150 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','1',0},
151 0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
153 /* WIN7 */
155 sizeof(RTL_OSVERSIONINFOEXW), 6, 1, 0x1DB1, VER_PLATFORM_WIN32_NT,
156 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','1',0},
157 1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
161 static const char * const WinVersionNames[NB_WINDOWS_VERSIONS] =
162 { /* no spaces in here ! */
163 "win20", /* WIN20 */
164 "win30", /* WIN30 */
165 "win31", /* WIN31 */
166 "win95", /* WIN95 */
167 "win98", /* WIN98 */
168 "winme", /* WINME */
169 "nt351", /* NT351 */
170 "nt40", /* NT40 */
171 "win2000,win2k,nt2k,nt2000", /* NT2K */
172 "winxp", /* WINXP */
173 "win2003,win2k3", /* WIN2K3 */
174 "vista,winvista", /* WINVISTA*/
175 "win2008,win2k8", /* WIN2K8 */
176 "win7", /* WIN7 */
180 /* initialized to null so that we crash if we try to retrieve the version too early at startup */
181 static const RTL_OSVERSIONINFOEXW *current_version;
184 /**********************************************************************
185 * get_nt_registry_version
187 * Fetch the version information from the NT-style registry keys.
189 static BOOL get_nt_registry_version( RTL_OSVERSIONINFOEXW *version )
191 static const WCHAR version_keyW[] = {'M','a','c','h','i','n','e','\\',
192 'S','o','f','t','w','a','r','e','\\',
193 'M','i','c','r','o','s','o','f','t','\\',
194 'W','i','n','d','o','w','s',' ','N','T','\\',
195 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
196 static const WCHAR service_pack_keyW[] = {'M','a','c','h','i','n','e','\\',
197 'S','y','s','t','e','m','\\',
198 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
199 'C','o','n','t','r','o','l','\\',
200 'W','i','n','d','o','w','s',0};
201 static const WCHAR product_keyW[] = {'M','a','c','h','i','n','e','\\',
202 'S','y','s','t','e','m','\\',
203 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
204 'C','o','n','t','r','o','l','\\',
205 'P','r','o','d','u','c','t','O','p','t','i','o','n','s',0};
206 static const WCHAR CurrentBuildNumberW[] = {'C','u','r','r','e','n','t','B','u','i','l','d','N','u','m','b','e','r',0};
207 static const WCHAR CSDVersionW[] = {'C','S','D','V','e','r','s','i','o','n',0};
208 static const WCHAR CurrentVersionW[] = {'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
209 static const WCHAR ProductTypeW[] = {'P','r','o','d','u','c','t','T','y','p','e',0};
210 static const WCHAR WinNTW[] = {'W','i','n','N','T',0};
211 static const WCHAR ServerNTW[] = {'S','e','r','v','e','r','N','T',0};
212 static const WCHAR LanmanNTW[] = {'L','a','n','m','a','n','N','T',0};
214 OBJECT_ATTRIBUTES attr;
215 UNICODE_STRING nameW, valueW;
216 HANDLE hkey, hkey2;
217 char tmp[64];
218 DWORD count;
219 BOOL ret = FALSE;
220 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
222 attr.Length = sizeof(attr);
223 attr.RootDirectory = 0;
224 attr.ObjectName = &nameW;
225 attr.Attributes = 0;
226 attr.SecurityDescriptor = NULL;
227 attr.SecurityQualityOfService = NULL;
228 RtlInitUnicodeString( &nameW, version_keyW );
230 if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) return FALSE;
232 memset( version, 0, sizeof(*version) );
234 RtlInitUnicodeString( &valueW, CurrentVersionW );
235 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
237 WCHAR *p, *str = (WCHAR *)info->Data;
238 str[info->DataLength / sizeof(WCHAR)] = 0;
239 p = strchrW( str, '.' );
240 if (p)
242 *p++ = 0;
243 version->dwMinorVersion = atoiW( p );
245 version->dwMajorVersion = atoiW( str );
248 if (version->dwMajorVersion) /* we got the main version, now fetch the other fields */
250 ret = TRUE;
251 version->dwPlatformId = VER_PLATFORM_WIN32_NT;
253 /* get build number */
255 RtlInitUnicodeString( &valueW, CurrentBuildNumberW );
256 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
258 WCHAR *str = (WCHAR *)info->Data;
259 str[info->DataLength / sizeof(WCHAR)] = 0;
260 version->dwBuildNumber = atoiW( str );
263 /* get version description */
265 RtlInitUnicodeString( &valueW, CSDVersionW );
266 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
268 DWORD len = min( info->DataLength, sizeof(version->szCSDVersion) - sizeof(WCHAR) );
269 memcpy( version->szCSDVersion, info->Data, len );
270 version->szCSDVersion[len / sizeof(WCHAR)] = 0;
273 /* get service pack version */
275 RtlInitUnicodeString( &nameW, service_pack_keyW );
276 if (!NtOpenKey( &hkey2, KEY_ALL_ACCESS, &attr ))
278 RtlInitUnicodeString( &valueW, CSDVersionW );
279 if (!NtQueryValueKey( hkey2, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
281 if (info->DataLength >= sizeof(DWORD))
283 DWORD dw = *(DWORD *)info->Data;
284 version->wServicePackMajor = LOWORD(dw) >> 8;
285 version->wServicePackMinor = LOWORD(dw) & 0xff;
288 NtClose( hkey2 );
291 /* get product type */
293 RtlInitUnicodeString( &nameW, product_keyW );
294 if (!NtOpenKey( &hkey2, KEY_ALL_ACCESS, &attr ))
296 RtlInitUnicodeString( &valueW, ProductTypeW );
297 if (!NtQueryValueKey( hkey2, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
299 WCHAR *str = (WCHAR *)info->Data;
300 str[info->DataLength / sizeof(WCHAR)] = 0;
301 if (!strcmpiW( str, WinNTW )) version->wProductType = VER_NT_WORKSTATION;
302 else if (!strcmpiW( str, LanmanNTW )) version->wProductType = VER_NT_DOMAIN_CONTROLLER;
303 else if (!strcmpiW( str, ServerNTW )) version->wProductType = VER_NT_SERVER;
305 NtClose( hkey2 );
308 /* FIXME: get wSuiteMask */
311 NtClose( hkey );
312 return ret;
316 /**********************************************************************
317 * get_win9x_registry_version
319 * Fetch the version information from the Win9x-style registry keys.
321 static BOOL get_win9x_registry_version( RTL_OSVERSIONINFOEXW *version )
323 static const WCHAR version_keyW[] = {'M','a','c','h','i','n','e','\\',
324 'S','o','f','t','w','a','r','e','\\',
325 'M','i','c','r','o','s','o','f','t','\\',
326 'W','i','n','d','o','w','s','\\',
327 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
328 static const WCHAR VersionNumberW[] = {'V','e','r','s','i','o','n','N','u','m','b','e','r',0};
329 static const WCHAR SubVersionNumberW[] = {'S','u','b','V','e','r','s','i','o','n','N','u','m','b','e','r',0};
331 OBJECT_ATTRIBUTES attr;
332 UNICODE_STRING nameW, valueW;
333 HANDLE hkey;
334 char tmp[64];
335 DWORD count;
336 BOOL ret = FALSE;
337 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
339 attr.Length = sizeof(attr);
340 attr.RootDirectory = 0;
341 attr.ObjectName = &nameW;
342 attr.Attributes = 0;
343 attr.SecurityDescriptor = NULL;
344 attr.SecurityQualityOfService = NULL;
345 RtlInitUnicodeString( &nameW, version_keyW );
347 if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) return FALSE;
349 memset( version, 0, sizeof(*version) );
351 RtlInitUnicodeString( &valueW, VersionNumberW );
352 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
354 WCHAR *p, *str = (WCHAR *)info->Data;
355 str[info->DataLength / sizeof(WCHAR)] = 0;
356 p = strchrW( str, '.' );
357 if (p) *p++ = 0;
358 version->dwMajorVersion = atoiW( str );
359 if (p)
361 str = p;
362 p = strchrW( str, '.' );
363 if (p)
365 *p++ = 0;
366 version->dwBuildNumber = atoiW( p );
368 version->dwMinorVersion = atoiW( str );
370 /* build number contains version too on Win9x */
371 version->dwBuildNumber |= MAKEWORD( version->dwMinorVersion, version->dwMajorVersion ) << 16;
374 if (version->dwMajorVersion) /* we got the main version, now fetch the other fields */
376 ret = TRUE;
377 version->dwPlatformId = VER_PLATFORM_WIN32_WINDOWS;
379 RtlInitUnicodeString( &valueW, SubVersionNumberW );
380 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
382 DWORD len = min( info->DataLength, sizeof(version->szCSDVersion) - sizeof(WCHAR) );
383 memcpy( version->szCSDVersion, info->Data, len );
384 version->szCSDVersion[len / sizeof(WCHAR)] = 0;
388 NtClose( hkey );
389 return ret;
393 /**********************************************************************
394 * parse_win_version
396 * Parse the contents of the Version key.
398 static BOOL parse_win_version( HANDLE hkey )
400 static const WCHAR VersionW[] = {'V','e','r','s','i','o','n',0};
402 UNICODE_STRING valueW;
403 char tmp[64], buffer[50];
404 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
405 DWORD count, len;
406 int i;
408 RtlInitUnicodeString( &valueW, VersionW );
409 if (NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
410 return FALSE;
412 RtlUnicodeToMultiByteN( buffer, sizeof(buffer)-1, &len, (WCHAR *)info->Data, info->DataLength );
413 buffer[len] = 0;
415 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
417 const char *p, *pCurr = WinVersionNames[i];
418 /* iterate through all winver aliases separated by comma */
419 do {
420 p = strchr(pCurr, ',');
421 len = p ? p - pCurr : strlen(pCurr);
422 if ( (!strncmp( pCurr, buffer, len )) && (buffer[len] == 0) )
424 current_version = &VersionData[i];
425 TRACE( "got win version %s\n", WinVersionNames[i] );
426 return TRUE;
428 pCurr = p+1;
429 } while (p);
432 MESSAGE("Invalid Windows version value '%s' specified in config file.\n", buffer );
433 MESSAGE("Valid versions are:" );
434 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
436 /* only list the first, "official" alias in case of aliases */
437 const char *pCurr = WinVersionNames[i];
438 const char *p = strchr(pCurr, ',');
439 len = (p) ? p - pCurr : strlen(pCurr);
441 MESSAGE(" '%.*s'%c", (int)len, pCurr, (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
443 return FALSE;
447 /**********************************************************************
448 * version_init
450 void version_init( const WCHAR *appname )
452 static const WCHAR configW[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e',0};
453 static const WCHAR appdefaultsW[] = {'A','p','p','D','e','f','a','u','l','t','s','\\',0};
455 OBJECT_ATTRIBUTES attr;
456 UNICODE_STRING nameW;
457 HANDLE root, hkey, config_key;
458 BOOL got_win_ver = FALSE;
460 current_version = &VersionData[WINXP]; /* default if nothing else is specified */
462 RtlOpenCurrentUser( KEY_ALL_ACCESS, &root );
463 attr.Length = sizeof(attr);
464 attr.RootDirectory = root;
465 attr.ObjectName = &nameW;
466 attr.Attributes = 0;
467 attr.SecurityDescriptor = NULL;
468 attr.SecurityQualityOfService = NULL;
469 RtlInitUnicodeString( &nameW, configW );
471 /* @@ Wine registry key: HKCU\Software\Wine */
472 if (NtOpenKey( &config_key, KEY_ALL_ACCESS, &attr )) config_key = 0;
473 NtClose( root );
474 if (!config_key) goto done;
476 /* open AppDefaults\\appname key */
477 if (appname && *appname)
479 const WCHAR *p;
480 WCHAR appversion[MAX_PATH+20];
482 if ((p = strrchrW( appname, '/' ))) appname = p + 1;
483 if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
485 strcpyW( appversion, appdefaultsW );
486 strcatW( appversion, appname );
487 RtlInitUnicodeString( &nameW, appversion );
488 attr.RootDirectory = config_key;
490 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe */
491 if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
493 TRACE( "getting version from %s\n", debugstr_w(appversion) );
494 got_win_ver = parse_win_version( hkey );
495 NtClose( hkey );
499 if (!got_win_ver)
501 TRACE( "getting default version\n" );
502 got_win_ver = parse_win_version( config_key );
504 NtClose( config_key );
506 done:
507 if (!got_win_ver)
509 static RTL_OSVERSIONINFOEXW registry_version;
511 TRACE( "getting registry version\n" );
512 if (get_nt_registry_version( &registry_version ) ||
513 get_win9x_registry_version( &registry_version ))
514 current_version = &registry_version;
518 NtCurrentTeb()->Peb->OSMajorVersion = current_version->dwMajorVersion;
519 NtCurrentTeb()->Peb->OSMinorVersion = current_version->dwMinorVersion;
520 NtCurrentTeb()->Peb->OSBuildNumber = current_version->dwBuildNumber;
521 NtCurrentTeb()->Peb->OSPlatformId = current_version->dwPlatformId;
523 user_shared_data->NtProductType = current_version->wProductType;
524 user_shared_data->ProductTypeIsValid = TRUE;
525 user_shared_data->MajorNtVersion = current_version->dwMajorVersion;
526 user_shared_data->MinorNtVersion = current_version->dwMinorVersion;
527 user_shared_data->MinorNtVersion = current_version->dwMinorVersion;
528 user_shared_data->SuiteMask = current_version->wSuiteMask;
530 TRACE( "got %d.%d platform %d build %x name %s service pack %d.%d product %d\n",
531 current_version->dwMajorVersion, current_version->dwMinorVersion,
532 current_version->dwPlatformId, current_version->dwBuildNumber,
533 debugstr_w(current_version->szCSDVersion),
534 current_version->wServicePackMajor, current_version->wServicePackMinor,
535 current_version->wProductType );
538 /***********************************************************************
539 * GetProductInfo (NTDLL.@)
541 * Gives info about the current Windows product type, in a format compatible
542 * with the given Windows version
544 * Returns TRUE if the input is valid, FALSE otherwise
546 BOOLEAN WINAPI RtlGetProductInfo(DWORD dwOSMajorVersion, DWORD dwOSMinorVersion, DWORD dwSpMajorVersion,
547 DWORD dwSpMinorVersion, PDWORD pdwReturnedProductType)
549 FIXME("(%d,%d,%d,%d,%p): stub\n", dwOSMajorVersion, dwOSMinorVersion,
550 dwSpMajorVersion, dwSpMinorVersion, pdwReturnedProductType);
552 *pdwReturnedProductType = PRODUCT_ULTIMATE_N;
554 return TRUE;
557 /***********************************************************************
558 * RtlGetVersion (NTDLL.@)
560 NTSTATUS WINAPI RtlGetVersion( RTL_OSVERSIONINFOEXW *info )
562 info->dwMajorVersion = current_version->dwMajorVersion;
563 info->dwMinorVersion = current_version->dwMinorVersion;
564 info->dwBuildNumber = current_version->dwBuildNumber;
565 info->dwPlatformId = current_version->dwPlatformId;
566 strcpyW( info->szCSDVersion, current_version->szCSDVersion );
567 if(info->dwOSVersionInfoSize == sizeof(RTL_OSVERSIONINFOEXW))
569 info->wServicePackMajor = current_version->wServicePackMajor;
570 info->wServicePackMinor = current_version->wServicePackMinor;
571 info->wSuiteMask = current_version->wSuiteMask;
572 info->wProductType = current_version->wProductType;
574 return STATUS_SUCCESS;
578 /******************************************************************************
579 * RtlGetNtVersionNumbers (NTDLL.@)
581 * Get the version numbers of the run time library.
583 * PARAMS
584 * major [O] Destination for the Major version
585 * minor [O] Destination for the Minor version
586 * build [O] Destination for the Build version
588 * RETURNS
589 * Nothing.
591 * NOTES
592 * Introduced in Windows XP (NT5.1)
594 void WINAPI RtlGetNtVersionNumbers( LPDWORD major, LPDWORD minor, LPDWORD build )
596 if (major) *major = current_version->dwMajorVersion;
597 if (minor) *minor = current_version->dwMinorVersion;
598 /* FIXME: Does anybody know the real formula? */
599 if (build) *build = (0xF0000000 | current_version->dwBuildNumber);
603 /******************************************************************************
604 * RtlGetNtProductType (NTDLL.@)
606 BOOLEAN WINAPI RtlGetNtProductType( LPDWORD type )
608 if (type) *type = current_version->wProductType;
609 return TRUE;
613 static inline NTSTATUS version_compare_values(ULONG left, ULONG right, UCHAR condition)
615 switch (condition) {
616 case VER_EQUAL:
617 if (left != right) return STATUS_REVISION_MISMATCH;
618 break;
619 case VER_GREATER:
620 if (left <= right) return STATUS_REVISION_MISMATCH;
621 break;
622 case VER_GREATER_EQUAL:
623 if (left < right) return STATUS_REVISION_MISMATCH;
624 break;
625 case VER_LESS:
626 if (left >= right) return STATUS_REVISION_MISMATCH;
627 break;
628 case VER_LESS_EQUAL:
629 if (left > right) return STATUS_REVISION_MISMATCH;
630 break;
631 default:
632 return STATUS_REVISION_MISMATCH;
634 return STATUS_SUCCESS;
637 /******************************************************************************
638 * RtlVerifyVersionInfo (NTDLL.@)
640 NTSTATUS WINAPI RtlVerifyVersionInfo( const RTL_OSVERSIONINFOEXW *info,
641 DWORD dwTypeMask, DWORDLONG dwlConditionMask )
643 RTL_OSVERSIONINFOEXW ver;
644 NTSTATUS status;
646 TRACE("(%p,0x%x,0x%s)\n", info, dwTypeMask, wine_dbgstr_longlong(dwlConditionMask));
648 ver.dwOSVersionInfoSize = sizeof(ver);
649 if ((status = RtlGetVersion( &ver )) != STATUS_SUCCESS) return status;
651 if(!(dwTypeMask && dwlConditionMask)) return STATUS_INVALID_PARAMETER;
653 if(dwTypeMask & VER_PRODUCT_TYPE)
655 status = version_compare_values(ver.wProductType, info->wProductType, dwlConditionMask >> 7*3 & 0x07);
656 if (status != STATUS_SUCCESS)
657 return status;
659 if(dwTypeMask & VER_SUITENAME)
660 switch(dwlConditionMask >> 6*3 & 0x07)
662 case VER_AND:
663 if((info->wSuiteMask & ver.wSuiteMask) != info->wSuiteMask)
664 return STATUS_REVISION_MISMATCH;
665 break;
666 case VER_OR:
667 if(!(info->wSuiteMask & ver.wSuiteMask) && info->wSuiteMask)
668 return STATUS_REVISION_MISMATCH;
669 break;
670 default:
671 return STATUS_INVALID_PARAMETER;
673 if(dwTypeMask & VER_PLATFORMID)
675 status = version_compare_values(ver.dwPlatformId, info->dwPlatformId, dwlConditionMask >> 3*3 & 0x07);
676 if (status != STATUS_SUCCESS)
677 return status;
679 if(dwTypeMask & VER_BUILDNUMBER)
681 status = version_compare_values(ver.dwBuildNumber, info->dwBuildNumber, dwlConditionMask >> 2*3 & 0x07);
682 if (status != STATUS_SUCCESS)
683 return status;
686 if(dwTypeMask & (VER_MAJORVERSION|VER_MINORVERSION|VER_SERVICEPACKMAJOR|VER_SERVICEPACKMINOR))
688 unsigned char condition = 0;
689 BOOLEAN do_next_check = TRUE;
691 if(dwTypeMask & VER_MAJORVERSION)
692 condition = dwlConditionMask >> 1*3 & 0x07;
693 else if(dwTypeMask & VER_MINORVERSION)
694 condition = dwlConditionMask >> 0*3 & 0x07;
695 else if(dwTypeMask & VER_SERVICEPACKMAJOR)
696 condition = dwlConditionMask >> 5*3 & 0x07;
697 else if(dwTypeMask & VER_SERVICEPACKMINOR)
698 condition = dwlConditionMask >> 4*3 & 0x07;
700 if(dwTypeMask & VER_MAJORVERSION)
702 status = version_compare_values(ver.dwMajorVersion, info->dwMajorVersion, condition);
703 do_next_check = (ver.dwMajorVersion == info->dwMajorVersion) &&
704 ((condition != VER_EQUAL) || (status == STATUS_SUCCESS));
706 if((dwTypeMask & VER_MINORVERSION) && do_next_check)
708 status = version_compare_values(ver.dwMinorVersion, info->dwMinorVersion, condition);
709 do_next_check = (ver.dwMinorVersion == info->dwMinorVersion) &&
710 ((condition != VER_EQUAL) || (status == STATUS_SUCCESS));
712 if((dwTypeMask & VER_SERVICEPACKMAJOR) && do_next_check)
714 status = version_compare_values(ver.wServicePackMajor, info->wServicePackMajor, condition);
715 do_next_check = (ver.wServicePackMajor == info->wServicePackMajor) &&
716 ((condition != VER_EQUAL) || (status == STATUS_SUCCESS));
718 if((dwTypeMask & VER_SERVICEPACKMINOR) && do_next_check)
720 status = version_compare_values(ver.wServicePackMinor, info->wServicePackMinor, condition);
723 if (status != STATUS_SUCCESS)
724 return status;
727 return STATUS_SUCCESS;