ntdll: Added NtGetTickCount implementation.
[wine] / dlls / ntdll / version.c
1 /*
2  * Windows and DOS version functions
3  *
4  * Copyright 1997 Marcus Meissner
5  * Copyright 1998 Patrik Stridvall
6  * Copyright 1998, 2003 Andreas Mohr
7  * Copyright 1997, 2003 Alexandre Julliard
8  *
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.
13  *
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.
18  *
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #include "config.h"
25 #include "wine/port.h"
26
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
38 WINE_DEFAULT_DEBUG_CHANNEL(ver);
39
40 typedef enum
41 {
42     WIN20,   /* Windows 2.0 */
43     WIN30,   /* Windows 3.0 */
44     WIN31,   /* Windows 3.1 */
45     WIN95,   /* Windows 95 */
46     WIN98,   /* Windows 98 */
47     WINME,   /* Windows Me */
48     NT351,   /* Windows NT 3.51 */
49     NT40,    /* Windows NT 4.0 */
50     NT2K,    /* Windows 2000 */
51     WINXP,   /* Windows XP */
52     WIN2K3,  /* Windows 2003 */
53     NB_WINDOWS_VERSIONS
54 } WINDOWS_VERSION;
55
56 /* FIXME: compare values below with original and fix.
57  * An *excellent* win9x version page (ALL versions !)
58  * can be found at www.mdgx.com/ver.htm */
59 static const RTL_OSVERSIONINFOEXW VersionData[NB_WINDOWS_VERSIONS] =
60 {
61     /* WIN20 FIXME: verify values */
62     {
63         sizeof(RTL_OSVERSIONINFOEXW), 2, 0, 0, VER_PLATFORM_WIN32s,
64         {'W','i','n','3','2','s',' ','1','.','3',0},
65         0, 0, 0, 0, 0
66     },
67     /* WIN30 FIXME: verify values */
68     {
69         sizeof(RTL_OSVERSIONINFOEXW), 3, 0, 0, VER_PLATFORM_WIN32s,
70         {'W','i','n','3','2','s',' ','1','.','3',0},
71         0, 0, 0, 0, 0
72     },
73     /* WIN31 */
74     {
75         sizeof(RTL_OSVERSIONINFOEXW), 3, 10, 0, VER_PLATFORM_WIN32s,
76         {'W','i','n','3','2','s',' ','1','.','3',0},
77         0, 0, 0, 0, 0
78     },
79     /* WIN95 */
80     {
81         /* Win95:       4, 0, 0x40003B6, ""
82          * Win95sp1:    4, 0, 0x40003B6, " A " (according to doc)
83          * Win95osr2:   4, 0, 0x4000457, " B " (according to doc)
84          * Win95osr2.1: 4, 3, 0x40304BC, " B " (according to doc)
85          * Win95osr2.5: 4, 3, 0x40304BE, " C " (according to doc)
86          * Win95a/b can be discerned via regkey SubVersionNumber
87          * See also:
88          * http://support.microsoft.com/support/kb/articles/q158/2/38.asp
89          */
90         sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x40003B6, VER_PLATFORM_WIN32_WINDOWS,
91         {0},
92         0, 0, 0, 0, 0
93     },
94     /* WIN98 (second edition) */
95     {
96         /* Win98:   4, 10, 0x40A07CE, " "   4.10.1998
97          * Win98SE: 4, 10, 0x40A08AE, " A " 4.10.2222
98          */
99         sizeof(RTL_OSVERSIONINFOEXW), 4, 10, 0x40A08AE, VER_PLATFORM_WIN32_WINDOWS,
100         {' ','A',' ',0},
101         0, 0, 0, 0, 0
102     },
103     /* WINME */
104     {
105         sizeof(RTL_OSVERSIONINFOEXW), 4, 90, 0x45A0BB8, VER_PLATFORM_WIN32_WINDOWS,
106         {' ',0},
107         0, 0, 0, 0, 0
108     },
109     /* NT351 */
110     {
111         sizeof(RTL_OSVERSIONINFOEXW), 3, 51, 0x421, VER_PLATFORM_WIN32_NT,
112         {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
113         0, 0, 0, 0, 0
114     },
115     /* NT40 */
116     {
117         sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x565, VER_PLATFORM_WIN32_NT,
118         {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','6','a',0},
119         6, 0, 0, VER_NT_WORKSTATION, 0
120     },
121     /* NT2K */
122     {
123         sizeof(RTL_OSVERSIONINFOEXW), 5, 0, 0x893, VER_PLATFORM_WIN32_NT,
124         {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','4',0},
125         4, 0, 0, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
126     },
127     /* WINXP */
128     {
129         sizeof(RTL_OSVERSIONINFOEXW), 5, 1, 0xA28, VER_PLATFORM_WIN32_NT,
130         {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
131         2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
132     },
133     /* WIN2K3 */
134     {
135         sizeof(RTL_OSVERSIONINFOEXW), 5, 2, 0xECE, VER_PLATFORM_WIN32_NT,
136         {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','1',0},
137         1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
138     }
139 };
140
141 static const char * const WinVersionNames[NB_WINDOWS_VERSIONS] =
142 { /* no spaces in here ! */
143     "win20",                      /* WIN20 */
144     "win30",                      /* WIN30 */
145     "win31",                      /* WIN31 */
146     "win95",                      /* WIN95 */
147     "win98",                      /* WIN98 */
148     "winme",                      /* WINME */
149     "nt351",                      /* NT351 */
150     "nt40",                       /* NT40 */
151     "win2000,win2k,nt2k,nt2000",  /* NT2K */
152     "winxp",                      /* WINXP */
153     "win2003,win2k3"              /* WIN2K3 */
154 };
155
156
157 /* initialized to null so that we crash if we try to retrieve the version too early at startup */
158 static const RTL_OSVERSIONINFOEXW *current_version;
159
160
161 /**********************************************************************
162  *         get_nt_registry_version
163  *
164  * Fetch the version information from the NT-style registry keys.
165  */
166 static BOOL get_nt_registry_version( RTL_OSVERSIONINFOEXW *version )
167 {
168     static const WCHAR version_keyW[] = {'M','a','c','h','i','n','e','\\',
169                                          'S','o','f','t','w','a','r','e','\\',
170                                          'M','i','c','r','o','s','o','f','t','\\',
171                                          'W','i','n','d','o','w','s',' ','N','T','\\',
172                                          'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
173     static const WCHAR service_pack_keyW[] = {'M','a','c','h','i','n','e','\\',
174                                               'S','y','s','t','e','m','\\',
175                                               'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
176                                               'C','o','n','t','r','o','l','\\',
177                                               'W','i','n','d','o','w','s',0};
178     static const WCHAR product_keyW[] = {'M','a','c','h','i','n','e','\\',
179                                          'S','y','s','t','e','m','\\',
180                                          'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
181                                          'C','o','n','t','r','o','l','\\',
182                                          'P','r','o','d','u','c','t','O','p','t','i','o','n','s',0};
183     static const WCHAR CurrentBuildNumberW[] = {'C','u','r','r','e','n','t','B','u','i','l','d','N','u','m','b','e','r',0};
184     static const WCHAR CSDVersionW[] = {'C','S','D','V','e','r','s','i','o','n',0};
185     static const WCHAR CurrentVersionW[] = {'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
186     static const WCHAR ProductTypeW[] = {'P','r','o','d','u','c','t','T','y','p','e',0};
187     static const WCHAR WinNTW[]    = {'W','i','n','N','T',0};
188     static const WCHAR ServerNTW[] = {'S','e','r','v','e','r','N','T',0};
189     static const WCHAR LanmanNTW[] = {'L','a','n','m','a','n','N','T',0};
190
191     OBJECT_ATTRIBUTES attr;
192     UNICODE_STRING nameW, valueW;
193     HANDLE hkey, hkey2;
194     char tmp[64];
195     DWORD count;
196     BOOL ret = FALSE;
197     KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
198
199     attr.Length = sizeof(attr);
200     attr.RootDirectory = 0;
201     attr.ObjectName = &nameW;
202     attr.Attributes = 0;
203     attr.SecurityDescriptor = NULL;
204     attr.SecurityQualityOfService = NULL;
205     RtlInitUnicodeString( &nameW, version_keyW );
206
207     if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) return FALSE;
208
209     memset( version, 0, sizeof(*version) );
210
211     RtlInitUnicodeString( &valueW, CurrentVersionW );
212     if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
213     {
214         WCHAR *p, *str = (WCHAR *)info->Data;
215         str[info->DataLength / sizeof(WCHAR)] = 0;
216         p = strchrW( str, '.' );
217         if (p)
218         {
219             *p++ = 0;
220             version->dwMinorVersion = atoiW( p );
221         }
222         version->dwMajorVersion = atoiW( str );
223     }
224
225     if (version->dwMajorVersion)   /* we got the main version, now fetch the other fields */
226     {
227         ret = TRUE;
228         version->dwPlatformId = VER_PLATFORM_WIN32_NT;
229
230         /* get build number */
231
232         RtlInitUnicodeString( &valueW, CurrentBuildNumberW );
233         if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
234         {
235             WCHAR *str = (WCHAR *)info->Data;
236             str[info->DataLength / sizeof(WCHAR)] = 0;
237             version->dwBuildNumber = atoiW( str );
238         }
239
240         /* get version description */
241
242         RtlInitUnicodeString( &valueW, CSDVersionW );
243         if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
244         {
245             DWORD len = min( info->DataLength, sizeof(version->szCSDVersion) - sizeof(WCHAR) );
246             memcpy( version->szCSDVersion, info->Data, len );
247             version->szCSDVersion[len / sizeof(WCHAR)] = 0;
248         }
249
250         /* get service pack version */
251
252         RtlInitUnicodeString( &nameW, service_pack_keyW );
253         if (!NtOpenKey( &hkey2, KEY_ALL_ACCESS, &attr ))
254         {
255             RtlInitUnicodeString( &valueW, CSDVersionW );
256             if (!NtQueryValueKey( hkey2, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
257             {
258                 if (info->DataLength >= sizeof(DWORD))
259                 {
260                     DWORD dw = *(DWORD *)info->Data;
261                     version->wServicePackMajor = LOWORD(dw) >> 8;
262                     version->wServicePackMinor = LOWORD(dw) & 0xff;
263                 }
264             }
265             NtClose( hkey2 );
266         }
267
268         /* get product type */
269
270         RtlInitUnicodeString( &nameW, product_keyW );
271         if (!NtOpenKey( &hkey2, KEY_ALL_ACCESS, &attr ))
272         {
273             RtlInitUnicodeString( &valueW, ProductTypeW );
274             if (!NtQueryValueKey( hkey2, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
275             {
276                 WCHAR *str = (WCHAR *)info->Data;
277                 str[info->DataLength / sizeof(WCHAR)] = 0;
278                 if (!strcmpiW( str, WinNTW )) version->wProductType = VER_NT_WORKSTATION;
279                 else if (!strcmpiW( str, LanmanNTW )) version->wProductType = VER_NT_DOMAIN_CONTROLLER;
280                 else if (!strcmpiW( str, ServerNTW )) version->wProductType = VER_NT_SERVER;
281             }
282             NtClose( hkey2 );
283         }
284
285         /* FIXME: get wSuiteMask */
286     }
287
288     NtClose( hkey );
289     return ret;
290 }
291
292
293 /**********************************************************************
294  *         get_win9x_registry_version
295  *
296  * Fetch the version information from the Win9x-style registry keys.
297  */
298 static BOOL get_win9x_registry_version( RTL_OSVERSIONINFOEXW *version )
299 {
300     static const WCHAR version_keyW[] = {'M','a','c','h','i','n','e','\\',
301                                          'S','o','f','t','w','a','r','e','\\',
302                                          'M','i','c','r','o','s','o','f','t','\\',
303                                          'W','i','n','d','o','w','s','\\',
304                                          'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
305     static const WCHAR VersionNumberW[] = {'V','e','r','s','i','o','n','N','u','m','b','e','r',0};
306     static const WCHAR SubVersionNumberW[] = {'S','u','b','V','e','r','s','i','o','n','N','u','m','b','e','r',0};
307
308     OBJECT_ATTRIBUTES attr;
309     UNICODE_STRING nameW, valueW;
310     HANDLE hkey;
311     char tmp[64];
312     DWORD count;
313     BOOL ret = FALSE;
314     KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
315
316     attr.Length = sizeof(attr);
317     attr.RootDirectory = 0;
318     attr.ObjectName = &nameW;
319     attr.Attributes = 0;
320     attr.SecurityDescriptor = NULL;
321     attr.SecurityQualityOfService = NULL;
322     RtlInitUnicodeString( &nameW, version_keyW );
323
324     if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) return FALSE;
325
326     memset( version, 0, sizeof(*version) );
327
328     RtlInitUnicodeString( &valueW, VersionNumberW );
329     if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
330     {
331         WCHAR *p, *str = (WCHAR *)info->Data;
332         str[info->DataLength / sizeof(WCHAR)] = 0;
333         p = strchrW( str, '.' );
334         if (p) *p++ = 0;
335         version->dwMajorVersion = atoiW( str );
336         if (p)
337         {
338             str = p;
339             p = strchrW( str, '.' );
340             if (p)
341             {
342                 *p++ = 0;
343                 version->dwBuildNumber = atoiW( p );
344             }
345             version->dwMinorVersion = atoiW( str );
346         }
347         /* build number contains version too on Win9x */
348         version->dwBuildNumber |= MAKEWORD( version->dwMinorVersion, version->dwMajorVersion ) << 16;
349     }
350
351     if (version->dwMajorVersion)   /* we got the main version, now fetch the other fields */
352     {
353         ret = TRUE;
354         version->dwPlatformId = VER_PLATFORM_WIN32_WINDOWS;
355
356         RtlInitUnicodeString( &valueW, SubVersionNumberW );
357         if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
358         {
359             DWORD len = min( info->DataLength, sizeof(version->szCSDVersion) - sizeof(WCHAR) );
360             memcpy( version->szCSDVersion, info->Data, len );
361             version->szCSDVersion[len / sizeof(WCHAR)] = 0;
362         }
363     }
364
365     NtClose( hkey );
366     return ret;
367 }
368
369
370 /**********************************************************************
371  *         parse_win_version
372  *
373  * Parse the contents of the Version key.
374  */
375 static BOOL parse_win_version( HANDLE hkey )
376 {
377     static const WCHAR VersionW[] = {'V','e','r','s','i','o','n',0};
378
379     UNICODE_STRING valueW;
380     char tmp[64], buffer[50];
381     KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
382     DWORD count, len;
383     int i;
384
385     RtlInitUnicodeString( &valueW, VersionW );
386     if (NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
387         return FALSE;
388
389     RtlUnicodeToMultiByteN( buffer, sizeof(buffer)-1, &len, (WCHAR *)info->Data, info->DataLength );
390     buffer[len] = 0;
391
392     for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
393     {
394         const char *p, *pCurr = WinVersionNames[i];
395         /* iterate through all winver aliases separated by comma */
396         do {
397             p = strchr(pCurr, ',');
398             len = p ? p - pCurr : strlen(pCurr);
399             if ( (!strncmp( pCurr, buffer, len )) && (buffer[len] == 0) )
400             {
401                 current_version = &VersionData[i];
402                 TRACE( "got win version %s\n", WinVersionNames[i] );
403                 return TRUE;
404             }
405             pCurr = p+1;
406         } while (p);
407     }
408
409     MESSAGE("Invalid Windows version value '%s' specified in config file.\n", buffer );
410     MESSAGE("Valid versions are:" );
411     for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
412     {
413         /* only list the first, "official" alias in case of aliases */
414         const char *pCurr = WinVersionNames[i];
415         const char *p = strchr(pCurr, ',');
416         len = (p) ? p - pCurr : strlen(pCurr);
417
418         MESSAGE(" '%.*s'%c", (int)len, pCurr, (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
419     }
420     return FALSE;
421 }
422
423
424 /**********************************************************************
425  *         version_init
426  */
427 void version_init( const WCHAR *appname )
428 {
429     static const WCHAR configW[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e',0};
430     static const WCHAR appdefaultsW[] = {'A','p','p','D','e','f','a','u','l','t','s','\\',0};
431
432     OBJECT_ATTRIBUTES attr;
433     UNICODE_STRING nameW;
434     HANDLE root, hkey, config_key;
435     BOOL got_win_ver = FALSE;
436
437     current_version = &VersionData[NT2K];  /* default if nothing else is specified */
438
439     RtlOpenCurrentUser( KEY_ALL_ACCESS, &root );
440     attr.Length = sizeof(attr);
441     attr.RootDirectory = root;
442     attr.ObjectName = &nameW;
443     attr.Attributes = 0;
444     attr.SecurityDescriptor = NULL;
445     attr.SecurityQualityOfService = NULL;
446     RtlInitUnicodeString( &nameW, configW );
447
448     /* @@ Wine registry key: HKCU\Software\Wine */
449     if (NtOpenKey( &config_key, KEY_ALL_ACCESS, &attr )) config_key = 0;
450     NtClose( root );
451     if (!config_key) goto done;
452
453     /* open AppDefaults\\appname key */
454     if (appname && *appname)
455     {
456         const WCHAR *p;
457         WCHAR appversion[MAX_PATH+20];
458
459         if ((p = strrchrW( appname, '/' ))) appname = p + 1;
460         if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
461
462         strcpyW( appversion, appdefaultsW );
463         strcatW( appversion, appname );
464         RtlInitUnicodeString( &nameW, appversion );
465         attr.RootDirectory = config_key;
466
467         /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe */
468         if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
469         {
470             TRACE( "getting version from %s\n", debugstr_w(appversion) );
471             got_win_ver = parse_win_version( hkey );
472             NtClose( hkey );
473         }
474     }
475
476     if (!got_win_ver)
477     {
478         TRACE( "getting default version\n" );
479         got_win_ver = parse_win_version( config_key );
480     }
481     NtClose( config_key );
482
483 done:
484     if (!got_win_ver)
485     {
486         static RTL_OSVERSIONINFOEXW registry_version;
487
488         TRACE( "getting registry version\n" );
489         if (get_nt_registry_version( &registry_version ) ||
490             get_win9x_registry_version( &registry_version ))
491             current_version = &registry_version;
492     }
493
494
495     NtCurrentTeb()->Peb->OSMajorVersion = current_version->dwMajorVersion;
496     NtCurrentTeb()->Peb->OSMinorVersion = current_version->dwMinorVersion;
497     NtCurrentTeb()->Peb->OSBuildNumber  = current_version->dwBuildNumber;
498     NtCurrentTeb()->Peb->OSPlatformId   = current_version->dwPlatformId;
499
500     TRACE( "got %ld.%ld plaform %ld build %lx name %s service pack %d.%d product %d\n",
501            current_version->dwMajorVersion, current_version->dwMinorVersion,
502            current_version->dwPlatformId, current_version->dwBuildNumber,
503            debugstr_w(current_version->szCSDVersion),
504            current_version->wServicePackMajor, current_version->wServicePackMinor,
505            current_version->wProductType );
506 }
507
508
509 /***********************************************************************
510  *         RtlGetVersion   (NTDLL.@)
511  */
512 NTSTATUS WINAPI RtlGetVersion( RTL_OSVERSIONINFOEXW *info )
513 {
514     info->dwMajorVersion = current_version->dwMajorVersion;
515     info->dwMinorVersion = current_version->dwMinorVersion;
516     info->dwBuildNumber  = current_version->dwBuildNumber;
517     info->dwPlatformId   = current_version->dwPlatformId;
518     strcpyW( info->szCSDVersion, current_version->szCSDVersion );
519     if(info->dwOSVersionInfoSize == sizeof(RTL_OSVERSIONINFOEXW))
520     {
521         info->wServicePackMajor = current_version->wServicePackMajor;
522         info->wServicePackMinor = current_version->wServicePackMinor;
523         info->wSuiteMask        = current_version->wSuiteMask;
524         info->wProductType      = current_version->wProductType;
525     }
526     return STATUS_SUCCESS;
527 }
528
529
530 /******************************************************************************
531  *  RtlGetNtVersionNumbers   (NTDLL.@)
532  *
533  * Get the version numbers of the run time library.
534  *
535  * PARAMS
536  *  major [O] Destination for the Major version
537  *  minor [O] Destination for the Minor version
538  *  build [O] Destination for the Build version
539  *
540  * RETURNS
541  *  Nothing.
542  *
543  * NOTES
544  * Introduced in Windows XP (NT5.1)
545  */
546 void WINAPI RtlGetNtVersionNumbers( LPDWORD major, LPDWORD minor, LPDWORD build )
547 {
548     if (major) *major = current_version->dwMajorVersion;
549     if (minor) *minor = current_version->dwMinorVersion;
550     /* FIXME: Does anybody know the real formula? */
551     if (build) *build = (0xF0000000 | current_version->dwBuildNumber);
552 }
553
554
555 /******************************************************************************
556  *  RtlGetNtProductType   (NTDLL.@)
557  */
558 BOOLEAN WINAPI RtlGetNtProductType( LPDWORD type )
559 {
560     if (type) *type = current_version->wProductType;
561     return TRUE;
562 }
563
564
565 /******************************************************************************
566  *        RtlVerifyVersionInfo   (NTDLL.@)
567  */
568 NTSTATUS WINAPI RtlVerifyVersionInfo( const RTL_OSVERSIONINFOEXW *info,
569                                       DWORD dwTypeMask, DWORDLONG dwlConditionMask )
570 {
571     RTL_OSVERSIONINFOEXW ver;
572     NTSTATUS status;
573
574     FIXME("(%p,%lu,%llx): Not all cases correctly implemented yet\n",
575           info, dwTypeMask, dwlConditionMask);
576
577     /* FIXME:
578         - Check the following special case on Windows (various versions):
579           o lp->wSuiteMask == 0 and ver.wSuiteMask != 0 and VER_AND/VER_OR
580           o lp->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW)
581         - MSDN talks about some tests being impossible. Check what really happens.
582      */
583
584     ver.dwOSVersionInfoSize = sizeof(ver);
585     if ((status = RtlGetVersion( &ver )) != STATUS_SUCCESS) return status;
586
587     if(!(dwTypeMask && dwlConditionMask)) return STATUS_INVALID_PARAMETER;
588
589     if(dwTypeMask & VER_PRODUCT_TYPE)
590         switch(dwlConditionMask >> 7*3 & 0x07) {
591             case VER_EQUAL:
592                 if(ver.wProductType != info->wProductType) return STATUS_REVISION_MISMATCH;
593                 break;
594             case VER_GREATER:
595                 if(ver.wProductType <= info->wProductType) return STATUS_REVISION_MISMATCH;
596                 break;
597             case VER_GREATER_EQUAL:
598                 if(ver.wProductType < info->wProductType) return STATUS_REVISION_MISMATCH;
599                 break;
600             case VER_LESS:
601                 if(ver.wProductType >= info->wProductType) return STATUS_REVISION_MISMATCH;
602                 break;
603             case VER_LESS_EQUAL:
604                 if(ver.wProductType > info->wProductType) return STATUS_REVISION_MISMATCH;
605                 break;
606             default:
607                 return STATUS_INVALID_PARAMETER;
608         }
609     if(dwTypeMask & VER_SUITENAME)
610         switch(dwlConditionMask >> 6*3 & 0x07)
611         {
612             case VER_AND:
613                 if((info->wSuiteMask & ver.wSuiteMask) != info->wSuiteMask)
614                     return STATUS_REVISION_MISMATCH;
615                 break;
616             case VER_OR:
617                 if(!(info->wSuiteMask & ver.wSuiteMask) && info->wSuiteMask)
618                     return STATUS_REVISION_MISMATCH;
619                 break;
620             default:
621                 return STATUS_INVALID_PARAMETER;
622         }
623     if(dwTypeMask & VER_PLATFORMID)
624         switch(dwlConditionMask >> 3*3 & 0x07)
625         {
626             case VER_EQUAL:
627                 if(ver.dwPlatformId != info->dwPlatformId) return STATUS_REVISION_MISMATCH;
628                 break;
629             case VER_GREATER:
630                 if(ver.dwPlatformId <= info->dwPlatformId) return STATUS_REVISION_MISMATCH;
631                 break;
632             case VER_GREATER_EQUAL:
633                 if(ver.dwPlatformId < info->dwPlatformId) return STATUS_REVISION_MISMATCH;
634                 break;
635             case VER_LESS:
636                 if(ver.dwPlatformId >= info->dwPlatformId) return STATUS_REVISION_MISMATCH;
637                 break;
638             case VER_LESS_EQUAL:
639                 if(ver.dwPlatformId > info->dwPlatformId) return STATUS_REVISION_MISMATCH;
640                 break;
641             default:
642                 return STATUS_INVALID_PARAMETER;
643         }
644     if(dwTypeMask & VER_BUILDNUMBER)
645         switch(dwlConditionMask >> 2*3 & 0x07)
646         {
647             case VER_EQUAL:
648                 if(ver.dwBuildNumber != info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
649                 break;
650             case VER_GREATER:
651                 if(ver.dwBuildNumber <= info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
652                 break;
653             case VER_GREATER_EQUAL:
654                 if(ver.dwBuildNumber < info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
655                 break;
656             case VER_LESS:
657                 if(ver.dwBuildNumber >= info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
658                 break;
659             case VER_LESS_EQUAL:
660                 if(ver.dwBuildNumber > info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
661                 break;
662             default:
663                 return STATUS_INVALID_PARAMETER;
664         }
665     if(dwTypeMask & VER_MAJORVERSION)
666         switch(dwlConditionMask >> 1*3 & 0x07)
667         {
668             case VER_EQUAL:
669                 if(ver.dwMajorVersion != info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
670                 break;
671             case VER_GREATER:
672                 if(ver.dwMajorVersion <= info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
673                 break;
674             case VER_GREATER_EQUAL:
675                 if(ver.dwMajorVersion < info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
676                 break;
677             case VER_LESS:
678                 if(ver.dwMajorVersion >= info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
679                 break;
680             case VER_LESS_EQUAL:
681                 if(ver.dwMajorVersion > info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
682                 break;
683             default:
684                 return STATUS_INVALID_PARAMETER;
685         }
686     if(dwTypeMask & VER_MINORVERSION)
687         switch(dwlConditionMask >> 0*3 & 0x07)
688         {
689             case VER_EQUAL:
690                 if(ver.dwMinorVersion != info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
691                 break;
692             case VER_GREATER:
693                 if(ver.dwMinorVersion <= info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
694                 break;
695             case VER_GREATER_EQUAL:
696                 if(ver.dwMinorVersion < info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
697                 break;
698             case VER_LESS:
699                 if(ver.dwMinorVersion >= info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
700                 break;
701             case VER_LESS_EQUAL:
702                 if(ver.dwMinorVersion > info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
703                 break;
704             default:
705                 return STATUS_INVALID_PARAMETER;
706         }
707     if(dwTypeMask & VER_SERVICEPACKMAJOR)
708         switch(dwlConditionMask >> 5*3 & 0x07)
709         {
710             case VER_EQUAL:
711                 if(ver.wServicePackMajor != info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
712                 break;
713             case VER_GREATER:
714                 if(ver.wServicePackMajor <= info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
715                 break;
716             case VER_GREATER_EQUAL:
717                 if(ver.wServicePackMajor < info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
718                 break;
719             case VER_LESS:
720                 if(ver.wServicePackMajor >= info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
721                 break;
722             case VER_LESS_EQUAL:
723                 if(ver.wServicePackMajor > info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
724                 break;
725             default:
726                 return STATUS_INVALID_PARAMETER;
727         }
728     if(dwTypeMask & VER_SERVICEPACKMINOR)
729         switch(dwlConditionMask >> 4*3 & 0x07)
730         {
731             case VER_EQUAL:
732                 if(ver.wServicePackMinor != info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
733                 break;
734             case VER_GREATER:
735                 if(ver.wServicePackMinor <= info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
736                 break;
737             case VER_GREATER_EQUAL:
738                 if(ver.wServicePackMinor < info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
739                 break;
740             case VER_LESS:
741                 if(ver.wServicePackMinor >= info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
742                 break;
743             case VER_LESS_EQUAL:
744                 if(ver.wServicePackMinor > info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
745                 break;
746             default:
747                 return STATUS_INVALID_PARAMETER;
748         }
749
750     return STATUS_SUCCESS;
751 }