inetcomm: Add an implementation of IPOP3Transport::CommandRETR.
[wine/wine64.git] / dlls / ntdll / version.c
blob09b338f2fe268443cf06cac05bfc61f67ca632ab
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 NB_WINDOWS_VERSIONS
57 } WINDOWS_VERSION;
59 /* FIXME: compare values below with original and fix.
60 * An *excellent* win9x version page (ALL versions !)
61 * can be found at www.mdgx.com/ver.htm */
62 static const RTL_OSVERSIONINFOEXW VersionData[NB_WINDOWS_VERSIONS] =
64 /* WIN20 FIXME: verify values */
66 sizeof(RTL_OSVERSIONINFOEXW), 2, 0, 0, VER_PLATFORM_WIN32s,
67 {'W','i','n','3','2','s',' ','1','.','3',0},
68 0, 0, 0, 0, 0
70 /* WIN30 FIXME: verify values */
72 sizeof(RTL_OSVERSIONINFOEXW), 3, 0, 0, VER_PLATFORM_WIN32s,
73 {'W','i','n','3','2','s',' ','1','.','3',0},
74 0, 0, 0, 0, 0
76 /* WIN31 */
78 sizeof(RTL_OSVERSIONINFOEXW), 3, 10, 0, VER_PLATFORM_WIN32s,
79 {'W','i','n','3','2','s',' ','1','.','3',0},
80 0, 0, 0, 0, 0
82 /* WIN95 */
84 /* Win95: 4, 0, 0x40003B6, ""
85 * Win95sp1: 4, 0, 0x40003B6, " A " (according to doc)
86 * Win95osr2: 4, 0, 0x4000457, " B " (according to doc)
87 * Win95osr2.1: 4, 3, 0x40304BC, " B " (according to doc)
88 * Win95osr2.5: 4, 3, 0x40304BE, " C " (according to doc)
89 * Win95a/b can be discerned via regkey SubVersionNumber
91 sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x40003B6, VER_PLATFORM_WIN32_WINDOWS,
92 {0},
93 0, 0, 0, 0, 0
95 /* WIN98 (second edition) */
97 /* Win98: 4, 10, 0x40A07CE, " " 4.10.1998
98 * Win98SE: 4, 10, 0x40A08AE, " A " 4.10.2222
100 sizeof(RTL_OSVERSIONINFOEXW), 4, 10, 0x40A08AE, VER_PLATFORM_WIN32_WINDOWS,
101 {' ','A',' ',0},
102 0, 0, 0, 0, 0
104 /* WINME */
106 sizeof(RTL_OSVERSIONINFOEXW), 4, 90, 0x45A0BB8, VER_PLATFORM_WIN32_WINDOWS,
107 {' ',0},
108 0, 0, 0, 0, 0
110 /* NT351 */
112 sizeof(RTL_OSVERSIONINFOEXW), 3, 51, 0x421, VER_PLATFORM_WIN32_NT,
113 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
114 0, 0, 0, 0, 0
116 /* NT40 */
118 sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x565, VER_PLATFORM_WIN32_NT,
119 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','6','a',0},
120 6, 0, 0, VER_NT_WORKSTATION, 0
122 /* NT2K */
124 sizeof(RTL_OSVERSIONINFOEXW), 5, 0, 0x893, VER_PLATFORM_WIN32_NT,
125 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','4',0},
126 4, 0, 0, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
128 /* WINXP */
130 sizeof(RTL_OSVERSIONINFOEXW), 5, 1, 0xA28, VER_PLATFORM_WIN32_NT,
131 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
132 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
134 /* WIN2K3 */
136 sizeof(RTL_OSVERSIONINFOEXW), 5, 2, 0xECE, VER_PLATFORM_WIN32_NT,
137 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','1',0},
138 1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
140 /* WINVISTA */
142 sizeof(RTL_OSVERSIONINFOEXW), 6, 0, 0x1770, VER_PLATFORM_WIN32_NT,
143 {' ',0},
144 0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
146 /* WIN2K8 */
148 sizeof(RTL_OSVERSIONINFOEXW), 6, 0, 0x1771, VER_PLATFORM_WIN32_NT,
149 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','1',0},
150 0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
154 static const char * const WinVersionNames[NB_WINDOWS_VERSIONS] =
155 { /* no spaces in here ! */
156 "win20", /* WIN20 */
157 "win30", /* WIN30 */
158 "win31", /* WIN31 */
159 "win95", /* WIN95 */
160 "win98", /* WIN98 */
161 "winme", /* WINME */
162 "nt351", /* NT351 */
163 "nt40", /* NT40 */
164 "win2000,win2k,nt2k,nt2000", /* NT2K */
165 "winxp", /* WINXP */
166 "win2003,win2k3", /* WIN2K3 */
167 "vista,winvista", /* WINVISTA*/
168 "win2008,win2k8", /* WIN2K8 */
172 /* initialized to null so that we crash if we try to retrieve the version too early at startup */
173 static const RTL_OSVERSIONINFOEXW *current_version;
176 /**********************************************************************
177 * get_nt_registry_version
179 * Fetch the version information from the NT-style registry keys.
181 static BOOL get_nt_registry_version( RTL_OSVERSIONINFOEXW *version )
183 static const WCHAR version_keyW[] = {'M','a','c','h','i','n','e','\\',
184 'S','o','f','t','w','a','r','e','\\',
185 'M','i','c','r','o','s','o','f','t','\\',
186 'W','i','n','d','o','w','s',' ','N','T','\\',
187 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
188 static const WCHAR service_pack_keyW[] = {'M','a','c','h','i','n','e','\\',
189 'S','y','s','t','e','m','\\',
190 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
191 'C','o','n','t','r','o','l','\\',
192 'W','i','n','d','o','w','s',0};
193 static const WCHAR product_keyW[] = {'M','a','c','h','i','n','e','\\',
194 'S','y','s','t','e','m','\\',
195 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
196 'C','o','n','t','r','o','l','\\',
197 'P','r','o','d','u','c','t','O','p','t','i','o','n','s',0};
198 static const WCHAR CurrentBuildNumberW[] = {'C','u','r','r','e','n','t','B','u','i','l','d','N','u','m','b','e','r',0};
199 static const WCHAR CSDVersionW[] = {'C','S','D','V','e','r','s','i','o','n',0};
200 static const WCHAR CurrentVersionW[] = {'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
201 static const WCHAR ProductTypeW[] = {'P','r','o','d','u','c','t','T','y','p','e',0};
202 static const WCHAR WinNTW[] = {'W','i','n','N','T',0};
203 static const WCHAR ServerNTW[] = {'S','e','r','v','e','r','N','T',0};
204 static const WCHAR LanmanNTW[] = {'L','a','n','m','a','n','N','T',0};
206 OBJECT_ATTRIBUTES attr;
207 UNICODE_STRING nameW, valueW;
208 HANDLE hkey, hkey2;
209 char tmp[64];
210 DWORD count;
211 BOOL ret = FALSE;
212 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
214 attr.Length = sizeof(attr);
215 attr.RootDirectory = 0;
216 attr.ObjectName = &nameW;
217 attr.Attributes = 0;
218 attr.SecurityDescriptor = NULL;
219 attr.SecurityQualityOfService = NULL;
220 RtlInitUnicodeString( &nameW, version_keyW );
222 if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) return FALSE;
224 memset( version, 0, sizeof(*version) );
226 RtlInitUnicodeString( &valueW, CurrentVersionW );
227 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
229 WCHAR *p, *str = (WCHAR *)info->Data;
230 str[info->DataLength / sizeof(WCHAR)] = 0;
231 p = strchrW( str, '.' );
232 if (p)
234 *p++ = 0;
235 version->dwMinorVersion = atoiW( p );
237 version->dwMajorVersion = atoiW( str );
240 if (version->dwMajorVersion) /* we got the main version, now fetch the other fields */
242 ret = TRUE;
243 version->dwPlatformId = VER_PLATFORM_WIN32_NT;
245 /* get build number */
247 RtlInitUnicodeString( &valueW, CurrentBuildNumberW );
248 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
250 WCHAR *str = (WCHAR *)info->Data;
251 str[info->DataLength / sizeof(WCHAR)] = 0;
252 version->dwBuildNumber = atoiW( str );
255 /* get version description */
257 RtlInitUnicodeString( &valueW, CSDVersionW );
258 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
260 DWORD len = min( info->DataLength, sizeof(version->szCSDVersion) - sizeof(WCHAR) );
261 memcpy( version->szCSDVersion, info->Data, len );
262 version->szCSDVersion[len / sizeof(WCHAR)] = 0;
265 /* get service pack version */
267 RtlInitUnicodeString( &nameW, service_pack_keyW );
268 if (!NtOpenKey( &hkey2, KEY_ALL_ACCESS, &attr ))
270 RtlInitUnicodeString( &valueW, CSDVersionW );
271 if (!NtQueryValueKey( hkey2, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
273 if (info->DataLength >= sizeof(DWORD))
275 DWORD dw = *(DWORD *)info->Data;
276 version->wServicePackMajor = LOWORD(dw) >> 8;
277 version->wServicePackMinor = LOWORD(dw) & 0xff;
280 NtClose( hkey2 );
283 /* get product type */
285 RtlInitUnicodeString( &nameW, product_keyW );
286 if (!NtOpenKey( &hkey2, KEY_ALL_ACCESS, &attr ))
288 RtlInitUnicodeString( &valueW, ProductTypeW );
289 if (!NtQueryValueKey( hkey2, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
291 WCHAR *str = (WCHAR *)info->Data;
292 str[info->DataLength / sizeof(WCHAR)] = 0;
293 if (!strcmpiW( str, WinNTW )) version->wProductType = VER_NT_WORKSTATION;
294 else if (!strcmpiW( str, LanmanNTW )) version->wProductType = VER_NT_DOMAIN_CONTROLLER;
295 else if (!strcmpiW( str, ServerNTW )) version->wProductType = VER_NT_SERVER;
297 NtClose( hkey2 );
300 /* FIXME: get wSuiteMask */
303 NtClose( hkey );
304 return ret;
308 /**********************************************************************
309 * get_win9x_registry_version
311 * Fetch the version information from the Win9x-style registry keys.
313 static BOOL get_win9x_registry_version( RTL_OSVERSIONINFOEXW *version )
315 static const WCHAR version_keyW[] = {'M','a','c','h','i','n','e','\\',
316 'S','o','f','t','w','a','r','e','\\',
317 'M','i','c','r','o','s','o','f','t','\\',
318 'W','i','n','d','o','w','s','\\',
319 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
320 static const WCHAR VersionNumberW[] = {'V','e','r','s','i','o','n','N','u','m','b','e','r',0};
321 static const WCHAR SubVersionNumberW[] = {'S','u','b','V','e','r','s','i','o','n','N','u','m','b','e','r',0};
323 OBJECT_ATTRIBUTES attr;
324 UNICODE_STRING nameW, valueW;
325 HANDLE hkey;
326 char tmp[64];
327 DWORD count;
328 BOOL ret = FALSE;
329 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
331 attr.Length = sizeof(attr);
332 attr.RootDirectory = 0;
333 attr.ObjectName = &nameW;
334 attr.Attributes = 0;
335 attr.SecurityDescriptor = NULL;
336 attr.SecurityQualityOfService = NULL;
337 RtlInitUnicodeString( &nameW, version_keyW );
339 if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) return FALSE;
341 memset( version, 0, sizeof(*version) );
343 RtlInitUnicodeString( &valueW, VersionNumberW );
344 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
346 WCHAR *p, *str = (WCHAR *)info->Data;
347 str[info->DataLength / sizeof(WCHAR)] = 0;
348 p = strchrW( str, '.' );
349 if (p) *p++ = 0;
350 version->dwMajorVersion = atoiW( str );
351 if (p)
353 str = p;
354 p = strchrW( str, '.' );
355 if (p)
357 *p++ = 0;
358 version->dwBuildNumber = atoiW( p );
360 version->dwMinorVersion = atoiW( str );
362 /* build number contains version too on Win9x */
363 version->dwBuildNumber |= MAKEWORD( version->dwMinorVersion, version->dwMajorVersion ) << 16;
366 if (version->dwMajorVersion) /* we got the main version, now fetch the other fields */
368 ret = TRUE;
369 version->dwPlatformId = VER_PLATFORM_WIN32_WINDOWS;
371 RtlInitUnicodeString( &valueW, SubVersionNumberW );
372 if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
374 DWORD len = min( info->DataLength, sizeof(version->szCSDVersion) - sizeof(WCHAR) );
375 memcpy( version->szCSDVersion, info->Data, len );
376 version->szCSDVersion[len / sizeof(WCHAR)] = 0;
380 NtClose( hkey );
381 return ret;
385 /**********************************************************************
386 * parse_win_version
388 * Parse the contents of the Version key.
390 static BOOL parse_win_version( HANDLE hkey )
392 static const WCHAR VersionW[] = {'V','e','r','s','i','o','n',0};
394 UNICODE_STRING valueW;
395 char tmp[64], buffer[50];
396 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
397 DWORD count, len;
398 int i;
400 RtlInitUnicodeString( &valueW, VersionW );
401 if (NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
402 return FALSE;
404 RtlUnicodeToMultiByteN( buffer, sizeof(buffer)-1, &len, (WCHAR *)info->Data, info->DataLength );
405 buffer[len] = 0;
407 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
409 const char *p, *pCurr = WinVersionNames[i];
410 /* iterate through all winver aliases separated by comma */
411 do {
412 p = strchr(pCurr, ',');
413 len = p ? p - pCurr : strlen(pCurr);
414 if ( (!strncmp( pCurr, buffer, len )) && (buffer[len] == 0) )
416 current_version = &VersionData[i];
417 TRACE( "got win version %s\n", WinVersionNames[i] );
418 return TRUE;
420 pCurr = p+1;
421 } while (p);
424 MESSAGE("Invalid Windows version value '%s' specified in config file.\n", buffer );
425 MESSAGE("Valid versions are:" );
426 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
428 /* only list the first, "official" alias in case of aliases */
429 const char *pCurr = WinVersionNames[i];
430 const char *p = strchr(pCurr, ',');
431 len = (p) ? p - pCurr : strlen(pCurr);
433 MESSAGE(" '%.*s'%c", (int)len, pCurr, (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
435 return FALSE;
439 /**********************************************************************
440 * version_init
442 void version_init( const WCHAR *appname )
444 static const WCHAR configW[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e',0};
445 static const WCHAR appdefaultsW[] = {'A','p','p','D','e','f','a','u','l','t','s','\\',0};
447 OBJECT_ATTRIBUTES attr;
448 UNICODE_STRING nameW;
449 HANDLE root, hkey, config_key;
450 BOOL got_win_ver = FALSE;
452 current_version = &VersionData[NT2K]; /* default if nothing else is specified */
454 RtlOpenCurrentUser( KEY_ALL_ACCESS, &root );
455 attr.Length = sizeof(attr);
456 attr.RootDirectory = root;
457 attr.ObjectName = &nameW;
458 attr.Attributes = 0;
459 attr.SecurityDescriptor = NULL;
460 attr.SecurityQualityOfService = NULL;
461 RtlInitUnicodeString( &nameW, configW );
463 /* @@ Wine registry key: HKCU\Software\Wine */
464 if (NtOpenKey( &config_key, KEY_ALL_ACCESS, &attr )) config_key = 0;
465 NtClose( root );
466 if (!config_key) goto done;
468 /* open AppDefaults\\appname key */
469 if (appname && *appname)
471 const WCHAR *p;
472 WCHAR appversion[MAX_PATH+20];
474 if ((p = strrchrW( appname, '/' ))) appname = p + 1;
475 if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
477 strcpyW( appversion, appdefaultsW );
478 strcatW( appversion, appname );
479 RtlInitUnicodeString( &nameW, appversion );
480 attr.RootDirectory = config_key;
482 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe */
483 if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
485 TRACE( "getting version from %s\n", debugstr_w(appversion) );
486 got_win_ver = parse_win_version( hkey );
487 NtClose( hkey );
491 if (!got_win_ver)
493 TRACE( "getting default version\n" );
494 got_win_ver = parse_win_version( config_key );
496 NtClose( config_key );
498 done:
499 if (!got_win_ver)
501 static RTL_OSVERSIONINFOEXW registry_version;
503 TRACE( "getting registry version\n" );
504 if (get_nt_registry_version( &registry_version ) ||
505 get_win9x_registry_version( &registry_version ))
506 current_version = &registry_version;
510 NtCurrentTeb()->Peb->OSMajorVersion = current_version->dwMajorVersion;
511 NtCurrentTeb()->Peb->OSMinorVersion = current_version->dwMinorVersion;
512 NtCurrentTeb()->Peb->OSBuildNumber = current_version->dwBuildNumber;
513 NtCurrentTeb()->Peb->OSPlatformId = current_version->dwPlatformId;
515 user_shared_data->NtProductType = current_version->wProductType;
516 user_shared_data->ProductTypeIsValid = TRUE;
517 user_shared_data->MajorNtVersion = current_version->dwMajorVersion;
518 user_shared_data->MinorNtVersion = current_version->dwMinorVersion;
519 user_shared_data->MinorNtVersion = current_version->dwMinorVersion;
520 user_shared_data->SuiteMask = current_version->wSuiteMask;
522 TRACE( "got %d.%d plaform %d build %x name %s service pack %d.%d product %d\n",
523 current_version->dwMajorVersion, current_version->dwMinorVersion,
524 current_version->dwPlatformId, current_version->dwBuildNumber,
525 debugstr_w(current_version->szCSDVersion),
526 current_version->wServicePackMajor, current_version->wServicePackMinor,
527 current_version->wProductType );
531 /***********************************************************************
532 * RtlGetVersion (NTDLL.@)
534 NTSTATUS WINAPI RtlGetVersion( RTL_OSVERSIONINFOEXW *info )
536 info->dwMajorVersion = current_version->dwMajorVersion;
537 info->dwMinorVersion = current_version->dwMinorVersion;
538 info->dwBuildNumber = current_version->dwBuildNumber;
539 info->dwPlatformId = current_version->dwPlatformId;
540 strcpyW( info->szCSDVersion, current_version->szCSDVersion );
541 if(info->dwOSVersionInfoSize == sizeof(RTL_OSVERSIONINFOEXW))
543 info->wServicePackMajor = current_version->wServicePackMajor;
544 info->wServicePackMinor = current_version->wServicePackMinor;
545 info->wSuiteMask = current_version->wSuiteMask;
546 info->wProductType = current_version->wProductType;
548 return STATUS_SUCCESS;
552 /******************************************************************************
553 * RtlGetNtVersionNumbers (NTDLL.@)
555 * Get the version numbers of the run time library.
557 * PARAMS
558 * major [O] Destination for the Major version
559 * minor [O] Destination for the Minor version
560 * build [O] Destination for the Build version
562 * RETURNS
563 * Nothing.
565 * NOTES
566 * Introduced in Windows XP (NT5.1)
568 void WINAPI RtlGetNtVersionNumbers( LPDWORD major, LPDWORD minor, LPDWORD build )
570 if (major) *major = current_version->dwMajorVersion;
571 if (minor) *minor = current_version->dwMinorVersion;
572 /* FIXME: Does anybody know the real formula? */
573 if (build) *build = (0xF0000000 | current_version->dwBuildNumber);
577 /******************************************************************************
578 * RtlGetNtProductType (NTDLL.@)
580 BOOLEAN WINAPI RtlGetNtProductType( LPDWORD type )
582 if (type) *type = current_version->wProductType;
583 return TRUE;
587 static inline NTSTATUS version_compare_values(ULONG left, ULONG right, UCHAR condition)
589 switch (condition) {
590 case VER_EQUAL:
591 if (left != right) return STATUS_REVISION_MISMATCH;
592 break;
593 case VER_GREATER:
594 if (left <= right) return STATUS_REVISION_MISMATCH;
595 break;
596 case VER_GREATER_EQUAL:
597 if (left < right) return STATUS_REVISION_MISMATCH;
598 break;
599 case VER_LESS:
600 if (left >= right) return STATUS_REVISION_MISMATCH;
601 break;
602 case VER_LESS_EQUAL:
603 if (left > right) return STATUS_REVISION_MISMATCH;
604 break;
605 default:
606 return STATUS_REVISION_MISMATCH;
608 return STATUS_SUCCESS;
611 /******************************************************************************
612 * RtlVerifyVersionInfo (NTDLL.@)
614 NTSTATUS WINAPI RtlVerifyVersionInfo( const RTL_OSVERSIONINFOEXW *info,
615 DWORD dwTypeMask, DWORDLONG dwlConditionMask )
617 RTL_OSVERSIONINFOEXW ver;
618 NTSTATUS status;
620 TRACE("(%p,0x%x,0x%s)\n", info, dwTypeMask, wine_dbgstr_longlong(dwlConditionMask));
622 ver.dwOSVersionInfoSize = sizeof(ver);
623 if ((status = RtlGetVersion( &ver )) != STATUS_SUCCESS) return status;
625 if(!(dwTypeMask && dwlConditionMask)) return STATUS_INVALID_PARAMETER;
627 if(dwTypeMask & VER_PRODUCT_TYPE)
629 status = version_compare_values(ver.wProductType, info->wProductType, dwlConditionMask >> 7*3 & 0x07);
630 if (status != STATUS_SUCCESS)
631 return status;
633 if(dwTypeMask & VER_SUITENAME)
634 switch(dwlConditionMask >> 6*3 & 0x07)
636 case VER_AND:
637 if((info->wSuiteMask & ver.wSuiteMask) != info->wSuiteMask)
638 return STATUS_REVISION_MISMATCH;
639 break;
640 case VER_OR:
641 if(!(info->wSuiteMask & ver.wSuiteMask) && info->wSuiteMask)
642 return STATUS_REVISION_MISMATCH;
643 break;
644 default:
645 return STATUS_INVALID_PARAMETER;
647 if(dwTypeMask & VER_PLATFORMID)
649 status = version_compare_values(ver.dwPlatformId, info->dwPlatformId, dwlConditionMask >> 3*3 & 0x07);
650 if (status != STATUS_SUCCESS)
651 return status;
653 if(dwTypeMask & VER_BUILDNUMBER)
655 status = version_compare_values(ver.dwBuildNumber, info->dwBuildNumber, dwlConditionMask >> 2*3 & 0x07);
656 if (status != STATUS_SUCCESS)
657 return status;
660 if(dwTypeMask & (VER_MAJORVERSION|VER_MINORVERSION|VER_SERVICEPACKMAJOR|VER_SERVICEPACKMINOR))
662 unsigned char condition = 0;
663 BOOLEAN do_next_check = TRUE;
665 if(dwTypeMask & VER_MAJORVERSION)
666 condition = dwlConditionMask >> 1*3 & 0x07;
667 else if(dwTypeMask & VER_MINORVERSION)
668 condition = dwlConditionMask >> 0*3 & 0x07;
669 else if(dwTypeMask & VER_SERVICEPACKMAJOR)
670 condition = dwlConditionMask >> 5*3 & 0x07;
671 else if(dwTypeMask & VER_SERVICEPACKMINOR)
672 condition = dwlConditionMask >> 4*3 & 0x07;
674 if(dwTypeMask & VER_MAJORVERSION)
676 status = version_compare_values(ver.dwMajorVersion, info->dwMajorVersion, condition);
677 do_next_check = (ver.dwMajorVersion == info->dwMajorVersion) &&
678 ((condition != VER_EQUAL) || (status == STATUS_SUCCESS));
680 if((dwTypeMask & VER_MINORVERSION) && do_next_check)
682 status = version_compare_values(ver.dwMinorVersion, info->dwMinorVersion, condition);
683 do_next_check = (ver.dwMinorVersion == info->dwMinorVersion) &&
684 ((condition != VER_EQUAL) || (status == STATUS_SUCCESS));
686 if((dwTypeMask & VER_SERVICEPACKMAJOR) && do_next_check)
688 status = version_compare_values(ver.wServicePackMajor, info->wServicePackMajor, condition);
689 do_next_check = (ver.wServicePackMajor == info->wServicePackMajor) &&
690 ((condition != VER_EQUAL) || (status == STATUS_SUCCESS));
692 if((dwTypeMask & VER_SERVICEPACKMINOR) && do_next_check)
694 status = version_compare_values(ver.wServicePackMinor, info->wServicePackMinor, condition);
697 if (status != STATUS_SUCCESS)
698 return status;
701 return STATUS_SUCCESS;