msisys.ocx: Fix the signature of DllGetClassObject to match that declared in the...
[wine/gsoc_dplay.git] / dlls / ntdll / version.c
blob0f188330b31f21ab33ad97a6098a60862371f3b7
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 NB_WINDOWS_VERSIONS
56 } WINDOWS_VERSION;
58 /* FIXME: compare values below with original and fix.
59 * An *excellent* win9x version page (ALL versions !)
60 * can be found at www.mdgx.com/ver.htm */
61 static const RTL_OSVERSIONINFOEXW VersionData[NB_WINDOWS_VERSIONS] =
63 /* WIN20 FIXME: verify values */
65 sizeof(RTL_OSVERSIONINFOEXW), 2, 0, 0, VER_PLATFORM_WIN32s,
66 {'W','i','n','3','2','s',' ','1','.','3',0},
67 0, 0, 0, 0, 0
69 /* WIN30 FIXME: verify values */
71 sizeof(RTL_OSVERSIONINFOEXW), 3, 0, 0, VER_PLATFORM_WIN32s,
72 {'W','i','n','3','2','s',' ','1','.','3',0},
73 0, 0, 0, 0, 0
75 /* WIN31 */
77 sizeof(RTL_OSVERSIONINFOEXW), 3, 10, 0, VER_PLATFORM_WIN32s,
78 {'W','i','n','3','2','s',' ','1','.','3',0},
79 0, 0, 0, 0, 0
81 /* WIN95 */
83 /* Win95: 4, 0, 0x40003B6, ""
84 * Win95sp1: 4, 0, 0x40003B6, " A " (according to doc)
85 * Win95osr2: 4, 0, 0x4000457, " B " (according to doc)
86 * Win95osr2.1: 4, 3, 0x40304BC, " B " (according to doc)
87 * Win95osr2.5: 4, 3, 0x40304BE, " C " (according to doc)
88 * Win95a/b can be discerned via regkey SubVersionNumber
89 * See also:
90 * http://support.microsoft.com/support/kb/articles/q158/2/38.asp
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',' ','2',0},
133 2, 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, 0x1770, VER_PLATFORM_WIN32_NT,
144 {' ',0},
145 0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
149 static const char * const WinVersionNames[NB_WINDOWS_VERSIONS] =
150 { /* no spaces in here ! */
151 "win20", /* WIN20 */
152 "win30", /* WIN30 */
153 "win31", /* WIN31 */
154 "win95", /* WIN95 */
155 "win98", /* WIN98 */
156 "winme", /* WINME */
157 "nt351", /* NT351 */
158 "nt40", /* NT40 */
159 "win2000,win2k,nt2k,nt2000", /* NT2K */
160 "winxp", /* WINXP */
161 "win2003,win2k3", /* WIN2K3 */
162 "vista,winvista" /* WINVISTA*/
166 /* initialized to null so that we crash if we try to retrieve the version too early at startup */
167 static const RTL_OSVERSIONINFOEXW *current_version;
170 /**********************************************************************
171 * get_nt_registry_version
173 * Fetch the version information from the NT-style registry keys.
175 static BOOL get_nt_registry_version( RTL_OSVERSIONINFOEXW *version )
177 static const WCHAR version_keyW[] = {'M','a','c','h','i','n','e','\\',
178 'S','o','f','t','w','a','r','e','\\',
179 'M','i','c','r','o','s','o','f','t','\\',
180 'W','i','n','d','o','w','s',' ','N','T','\\',
181 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
182 static const WCHAR service_pack_keyW[] = {'M','a','c','h','i','n','e','\\',
183 'S','y','s','t','e','m','\\',
184 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
185 'C','o','n','t','r','o','l','\\',
186 'W','i','n','d','o','w','s',0};
187 static const WCHAR product_keyW[] = {'M','a','c','h','i','n','e','\\',
188 'S','y','s','t','e','m','\\',
189 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
190 'C','o','n','t','r','o','l','\\',
191 'P','r','o','d','u','c','t','O','p','t','i','o','n','s',0};
192 static const WCHAR CurrentBuildNumberW[] = {'C','u','r','r','e','n','t','B','u','i','l','d','N','u','m','b','e','r',0};
193 static const WCHAR CSDVersionW[] = {'C','S','D','V','e','r','s','i','o','n',0};
194 static const WCHAR CurrentVersionW[] = {'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
195 static const WCHAR ProductTypeW[] = {'P','r','o','d','u','c','t','T','y','p','e',0};
196 static const WCHAR WinNTW[] = {'W','i','n','N','T',0};
197 static const WCHAR ServerNTW[] = {'S','e','r','v','e','r','N','T',0};
198 static const WCHAR LanmanNTW[] = {'L','a','n','m','a','n','N','T',0};
200 OBJECT_ATTRIBUTES attr;
201 UNICODE_STRING nameW, valueW;
202 HANDLE hkey, hkey2;
203 char tmp[64];
204 DWORD count;
205 BOOL ret = FALSE;
206 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
208 attr.Length = sizeof(attr);
209 attr.RootDirectory = 0;
210 attr.ObjectName = &nameW;
211 attr.Attributes = 0;
212 attr.SecurityDescriptor = NULL;
213 attr.SecurityQualityOfService = NULL;
214 RtlInitUnicodeString( &nameW, version_keyW );
216 if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) return FALSE;
218 memset( version, 0, sizeof(*version) );
220 RtlInitUnicodeString( &valueW, CurrentVersionW );
221 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
223 WCHAR *p, *str = (WCHAR *)info->Data;
224 str[info->DataLength / sizeof(WCHAR)] = 0;
225 p = strchrW( str, '.' );
226 if (p)
228 *p++ = 0;
229 version->dwMinorVersion = atoiW( p );
231 version->dwMajorVersion = atoiW( str );
234 if (version->dwMajorVersion) /* we got the main version, now fetch the other fields */
236 ret = TRUE;
237 version->dwPlatformId = VER_PLATFORM_WIN32_NT;
239 /* get build number */
241 RtlInitUnicodeString( &valueW, CurrentBuildNumberW );
242 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
244 WCHAR *str = (WCHAR *)info->Data;
245 str[info->DataLength / sizeof(WCHAR)] = 0;
246 version->dwBuildNumber = atoiW( str );
249 /* get version description */
251 RtlInitUnicodeString( &valueW, CSDVersionW );
252 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
254 DWORD len = min( info->DataLength, sizeof(version->szCSDVersion) - sizeof(WCHAR) );
255 memcpy( version->szCSDVersion, info->Data, len );
256 version->szCSDVersion[len / sizeof(WCHAR)] = 0;
259 /* get service pack version */
261 RtlInitUnicodeString( &nameW, service_pack_keyW );
262 if (!NtOpenKey( &hkey2, KEY_ALL_ACCESS, &attr ))
264 RtlInitUnicodeString( &valueW, CSDVersionW );
265 if (!NtQueryValueKey( hkey2, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
267 if (info->DataLength >= sizeof(DWORD))
269 DWORD dw = *(DWORD *)info->Data;
270 version->wServicePackMajor = LOWORD(dw) >> 8;
271 version->wServicePackMinor = LOWORD(dw) & 0xff;
274 NtClose( hkey2 );
277 /* get product type */
279 RtlInitUnicodeString( &nameW, product_keyW );
280 if (!NtOpenKey( &hkey2, KEY_ALL_ACCESS, &attr ))
282 RtlInitUnicodeString( &valueW, ProductTypeW );
283 if (!NtQueryValueKey( hkey2, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
285 WCHAR *str = (WCHAR *)info->Data;
286 str[info->DataLength / sizeof(WCHAR)] = 0;
287 if (!strcmpiW( str, WinNTW )) version->wProductType = VER_NT_WORKSTATION;
288 else if (!strcmpiW( str, LanmanNTW )) version->wProductType = VER_NT_DOMAIN_CONTROLLER;
289 else if (!strcmpiW( str, ServerNTW )) version->wProductType = VER_NT_SERVER;
291 NtClose( hkey2 );
294 /* FIXME: get wSuiteMask */
297 NtClose( hkey );
298 return ret;
302 /**********************************************************************
303 * get_win9x_registry_version
305 * Fetch the version information from the Win9x-style registry keys.
307 static BOOL get_win9x_registry_version( RTL_OSVERSIONINFOEXW *version )
309 static const WCHAR version_keyW[] = {'M','a','c','h','i','n','e','\\',
310 'S','o','f','t','w','a','r','e','\\',
311 'M','i','c','r','o','s','o','f','t','\\',
312 'W','i','n','d','o','w','s','\\',
313 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
314 static const WCHAR VersionNumberW[] = {'V','e','r','s','i','o','n','N','u','m','b','e','r',0};
315 static const WCHAR SubVersionNumberW[] = {'S','u','b','V','e','r','s','i','o','n','N','u','m','b','e','r',0};
317 OBJECT_ATTRIBUTES attr;
318 UNICODE_STRING nameW, valueW;
319 HANDLE hkey;
320 char tmp[64];
321 DWORD count;
322 BOOL ret = FALSE;
323 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
325 attr.Length = sizeof(attr);
326 attr.RootDirectory = 0;
327 attr.ObjectName = &nameW;
328 attr.Attributes = 0;
329 attr.SecurityDescriptor = NULL;
330 attr.SecurityQualityOfService = NULL;
331 RtlInitUnicodeString( &nameW, version_keyW );
333 if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) return FALSE;
335 memset( version, 0, sizeof(*version) );
337 RtlInitUnicodeString( &valueW, VersionNumberW );
338 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
340 WCHAR *p, *str = (WCHAR *)info->Data;
341 str[info->DataLength / sizeof(WCHAR)] = 0;
342 p = strchrW( str, '.' );
343 if (p) *p++ = 0;
344 version->dwMajorVersion = atoiW( str );
345 if (p)
347 str = p;
348 p = strchrW( str, '.' );
349 if (p)
351 *p++ = 0;
352 version->dwBuildNumber = atoiW( p );
354 version->dwMinorVersion = atoiW( str );
356 /* build number contains version too on Win9x */
357 version->dwBuildNumber |= MAKEWORD( version->dwMinorVersion, version->dwMajorVersion ) << 16;
360 if (version->dwMajorVersion) /* we got the main version, now fetch the other fields */
362 ret = TRUE;
363 version->dwPlatformId = VER_PLATFORM_WIN32_WINDOWS;
365 RtlInitUnicodeString( &valueW, SubVersionNumberW );
366 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
368 DWORD len = min( info->DataLength, sizeof(version->szCSDVersion) - sizeof(WCHAR) );
369 memcpy( version->szCSDVersion, info->Data, len );
370 version->szCSDVersion[len / sizeof(WCHAR)] = 0;
374 NtClose( hkey );
375 return ret;
379 /**********************************************************************
380 * parse_win_version
382 * Parse the contents of the Version key.
384 static BOOL parse_win_version( HANDLE hkey )
386 static const WCHAR VersionW[] = {'V','e','r','s','i','o','n',0};
388 UNICODE_STRING valueW;
389 char tmp[64], buffer[50];
390 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
391 DWORD count, len;
392 int i;
394 RtlInitUnicodeString( &valueW, VersionW );
395 if (NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
396 return FALSE;
398 RtlUnicodeToMultiByteN( buffer, sizeof(buffer)-1, &len, (WCHAR *)info->Data, info->DataLength );
399 buffer[len] = 0;
401 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
403 const char *p, *pCurr = WinVersionNames[i];
404 /* iterate through all winver aliases separated by comma */
405 do {
406 p = strchr(pCurr, ',');
407 len = p ? p - pCurr : strlen(pCurr);
408 if ( (!strncmp( pCurr, buffer, len )) && (buffer[len] == 0) )
410 current_version = &VersionData[i];
411 TRACE( "got win version %s\n", WinVersionNames[i] );
412 return TRUE;
414 pCurr = p+1;
415 } while (p);
418 MESSAGE("Invalid Windows version value '%s' specified in config file.\n", buffer );
419 MESSAGE("Valid versions are:" );
420 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
422 /* only list the first, "official" alias in case of aliases */
423 const char *pCurr = WinVersionNames[i];
424 const char *p = strchr(pCurr, ',');
425 len = (p) ? p - pCurr : strlen(pCurr);
427 MESSAGE(" '%.*s'%c", (int)len, pCurr, (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
429 return FALSE;
433 /**********************************************************************
434 * version_init
436 void version_init( const WCHAR *appname )
438 static const WCHAR configW[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e',0};
439 static const WCHAR appdefaultsW[] = {'A','p','p','D','e','f','a','u','l','t','s','\\',0};
441 OBJECT_ATTRIBUTES attr;
442 UNICODE_STRING nameW;
443 HANDLE root, hkey, config_key;
444 BOOL got_win_ver = FALSE;
446 current_version = &VersionData[NT2K]; /* default if nothing else is specified */
448 RtlOpenCurrentUser( KEY_ALL_ACCESS, &root );
449 attr.Length = sizeof(attr);
450 attr.RootDirectory = root;
451 attr.ObjectName = &nameW;
452 attr.Attributes = 0;
453 attr.SecurityDescriptor = NULL;
454 attr.SecurityQualityOfService = NULL;
455 RtlInitUnicodeString( &nameW, configW );
457 /* @@ Wine registry key: HKCU\Software\Wine */
458 if (NtOpenKey( &config_key, KEY_ALL_ACCESS, &attr )) config_key = 0;
459 NtClose( root );
460 if (!config_key) goto done;
462 /* open AppDefaults\\appname key */
463 if (appname && *appname)
465 const WCHAR *p;
466 WCHAR appversion[MAX_PATH+20];
468 if ((p = strrchrW( appname, '/' ))) appname = p + 1;
469 if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
471 strcpyW( appversion, appdefaultsW );
472 strcatW( appversion, appname );
473 RtlInitUnicodeString( &nameW, appversion );
474 attr.RootDirectory = config_key;
476 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe */
477 if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
479 TRACE( "getting version from %s\n", debugstr_w(appversion) );
480 got_win_ver = parse_win_version( hkey );
481 NtClose( hkey );
485 if (!got_win_ver)
487 TRACE( "getting default version\n" );
488 got_win_ver = parse_win_version( config_key );
490 NtClose( config_key );
492 done:
493 if (!got_win_ver)
495 static RTL_OSVERSIONINFOEXW registry_version;
497 TRACE( "getting registry version\n" );
498 if (get_nt_registry_version( &registry_version ) ||
499 get_win9x_registry_version( &registry_version ))
500 current_version = &registry_version;
504 NtCurrentTeb()->Peb->OSMajorVersion = current_version->dwMajorVersion;
505 NtCurrentTeb()->Peb->OSMinorVersion = current_version->dwMinorVersion;
506 NtCurrentTeb()->Peb->OSBuildNumber = current_version->dwBuildNumber;
507 NtCurrentTeb()->Peb->OSPlatformId = current_version->dwPlatformId;
509 user_shared_data->NtProductType = current_version->wProductType;
510 user_shared_data->ProductTypeIsValid = TRUE;
511 user_shared_data->MajorNtVersion = current_version->dwMajorVersion;
512 user_shared_data->MinorNtVersion = current_version->dwMinorVersion;
513 user_shared_data->MinorNtVersion = current_version->dwMinorVersion;
514 user_shared_data->SuiteMask = current_version->wSuiteMask;
516 TRACE( "got %d.%d plaform %d build %x name %s service pack %d.%d product %d\n",
517 current_version->dwMajorVersion, current_version->dwMinorVersion,
518 current_version->dwPlatformId, current_version->dwBuildNumber,
519 debugstr_w(current_version->szCSDVersion),
520 current_version->wServicePackMajor, current_version->wServicePackMinor,
521 current_version->wProductType );
525 /***********************************************************************
526 * RtlGetVersion (NTDLL.@)
528 NTSTATUS WINAPI RtlGetVersion( RTL_OSVERSIONINFOEXW *info )
530 info->dwMajorVersion = current_version->dwMajorVersion;
531 info->dwMinorVersion = current_version->dwMinorVersion;
532 info->dwBuildNumber = current_version->dwBuildNumber;
533 info->dwPlatformId = current_version->dwPlatformId;
534 strcpyW( info->szCSDVersion, current_version->szCSDVersion );
535 if(info->dwOSVersionInfoSize == sizeof(RTL_OSVERSIONINFOEXW))
537 info->wServicePackMajor = current_version->wServicePackMajor;
538 info->wServicePackMinor = current_version->wServicePackMinor;
539 info->wSuiteMask = current_version->wSuiteMask;
540 info->wProductType = current_version->wProductType;
542 return STATUS_SUCCESS;
546 /******************************************************************************
547 * RtlGetNtVersionNumbers (NTDLL.@)
549 * Get the version numbers of the run time library.
551 * PARAMS
552 * major [O] Destination for the Major version
553 * minor [O] Destination for the Minor version
554 * build [O] Destination for the Build version
556 * RETURNS
557 * Nothing.
559 * NOTES
560 * Introduced in Windows XP (NT5.1)
562 void WINAPI RtlGetNtVersionNumbers( LPDWORD major, LPDWORD minor, LPDWORD build )
564 if (major) *major = current_version->dwMajorVersion;
565 if (minor) *minor = current_version->dwMinorVersion;
566 /* FIXME: Does anybody know the real formula? */
567 if (build) *build = (0xF0000000 | current_version->dwBuildNumber);
571 /******************************************************************************
572 * RtlGetNtProductType (NTDLL.@)
574 BOOLEAN WINAPI RtlGetNtProductType( LPDWORD type )
576 if (type) *type = current_version->wProductType;
577 return TRUE;
581 static inline NTSTATUS version_compare_values(ULONG left, ULONG right, UCHAR condition)
583 switch (condition) {
584 case VER_EQUAL:
585 if (left != right) return STATUS_REVISION_MISMATCH;
586 break;
587 case VER_GREATER:
588 if (left <= right) return STATUS_REVISION_MISMATCH;
589 break;
590 case VER_GREATER_EQUAL:
591 if (left < right) return STATUS_REVISION_MISMATCH;
592 break;
593 case VER_LESS:
594 if (left >= right) return STATUS_REVISION_MISMATCH;
595 break;
596 case VER_LESS_EQUAL:
597 if (left > right) return STATUS_REVISION_MISMATCH;
598 break;
599 default:
600 return STATUS_REVISION_MISMATCH;
602 return STATUS_SUCCESS;
605 /******************************************************************************
606 * RtlVerifyVersionInfo (NTDLL.@)
608 NTSTATUS WINAPI RtlVerifyVersionInfo( const RTL_OSVERSIONINFOEXW *info,
609 DWORD dwTypeMask, DWORDLONG dwlConditionMask )
611 RTL_OSVERSIONINFOEXW ver;
612 NTSTATUS status;
614 TRACE("(%p,0x%x,0x%s)\n", info, dwTypeMask, wine_dbgstr_longlong(dwlConditionMask));
616 ver.dwOSVersionInfoSize = sizeof(ver);
617 if ((status = RtlGetVersion( &ver )) != STATUS_SUCCESS) return status;
619 if(!(dwTypeMask && dwlConditionMask)) return STATUS_INVALID_PARAMETER;
621 if(dwTypeMask & VER_PRODUCT_TYPE)
623 status = version_compare_values(ver.wProductType, info->wProductType, dwlConditionMask >> 7*3 & 0x07);
624 if (status != STATUS_SUCCESS)
625 return status;
627 if(dwTypeMask & VER_SUITENAME)
628 switch(dwlConditionMask >> 6*3 & 0x07)
630 case VER_AND:
631 if((info->wSuiteMask & ver.wSuiteMask) != info->wSuiteMask)
632 return STATUS_REVISION_MISMATCH;
633 break;
634 case VER_OR:
635 if(!(info->wSuiteMask & ver.wSuiteMask) && info->wSuiteMask)
636 return STATUS_REVISION_MISMATCH;
637 break;
638 default:
639 return STATUS_INVALID_PARAMETER;
641 if(dwTypeMask & VER_PLATFORMID)
643 status = version_compare_values(ver.dwPlatformId, info->dwPlatformId, dwlConditionMask >> 3*3 & 0x07);
644 if (status != STATUS_SUCCESS)
645 return status;
647 if(dwTypeMask & VER_BUILDNUMBER)
649 status = version_compare_values(ver.dwBuildNumber, info->dwBuildNumber, dwlConditionMask >> 2*3 & 0x07);
650 if (status != STATUS_SUCCESS)
651 return status;
654 if(dwTypeMask & (VER_MAJORVERSION|VER_MINORVERSION|VER_SERVICEPACKMAJOR|VER_SERVICEPACKMINOR))
656 unsigned char condition = 0;
657 BOOLEAN do_next_check = TRUE;
659 if(dwTypeMask & VER_MAJORVERSION)
660 condition = dwlConditionMask >> 1*3 & 0x07;
661 else if(dwTypeMask & VER_MINORVERSION)
662 condition = dwlConditionMask >> 0*3 & 0x07;
663 else if(dwTypeMask & VER_SERVICEPACKMAJOR)
664 condition = dwlConditionMask >> 5*3 & 0x07;
665 else if(dwTypeMask & VER_SERVICEPACKMINOR)
666 condition = dwlConditionMask >> 4*3 & 0x07;
668 if(dwTypeMask & VER_MAJORVERSION)
670 status = version_compare_values(ver.dwMajorVersion, info->dwMajorVersion, condition);
671 do_next_check = (ver.dwMajorVersion == info->dwMajorVersion) &&
672 ((condition != VER_EQUAL) || (status == STATUS_SUCCESS));
674 if((dwTypeMask & VER_MINORVERSION) && do_next_check)
676 status = version_compare_values(ver.dwMinorVersion, info->dwMinorVersion, condition);
677 do_next_check = (ver.dwMinorVersion == info->dwMinorVersion) &&
678 ((condition != VER_EQUAL) || (status == STATUS_SUCCESS));
680 if((dwTypeMask & VER_SERVICEPACKMAJOR) && do_next_check)
682 status = version_compare_values(ver.wServicePackMajor, info->wServicePackMajor, condition);
683 do_next_check = (ver.wServicePackMajor == info->wServicePackMajor) &&
684 ((condition != VER_EQUAL) || (status == STATUS_SUCCESS));
686 if((dwTypeMask & VER_SERVICEPACKMINOR) && do_next_check)
688 status = version_compare_values(ver.wServicePackMinor, info->wServicePackMinor, condition);
691 if (status != STATUS_SUCCESS)
692 return status;
695 return STATUS_SUCCESS;