ntdll: Fix NtAccessCheck for NULL, but present SACLs and DACLs.
[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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 #include "ddk/wdm.h"
38
39 WINE_DEFAULT_DEBUG_CHANNEL(ver);
40
41 typedef enum
42 {
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;
57
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] =
62 {
63     /* WIN20 FIXME: verify values */
64     {
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
68     },
69     /* WIN30 FIXME: verify values */
70     {
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
74     },
75     /* WIN31 */
76     {
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
80     },
81     /* WIN95 */
82     {
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
91          */
92         sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x40003B6, VER_PLATFORM_WIN32_WINDOWS,
93         {0},
94         0, 0, 0, 0, 0
95     },
96     /* WIN98 (second edition) */
97     {
98         /* Win98:   4, 10, 0x40A07CE, " "   4.10.1998
99          * Win98SE: 4, 10, 0x40A08AE, " A " 4.10.2222
100          */
101         sizeof(RTL_OSVERSIONINFOEXW), 4, 10, 0x40A08AE, VER_PLATFORM_WIN32_WINDOWS,
102         {' ','A',' ',0},
103         0, 0, 0, 0, 0
104     },
105     /* WINME */
106     {
107         sizeof(RTL_OSVERSIONINFOEXW), 4, 90, 0x45A0BB8, VER_PLATFORM_WIN32_WINDOWS,
108         {' ',0},
109         0, 0, 0, 0, 0
110     },
111     /* NT351 */
112     {
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
116     },
117     /* NT40 */
118     {
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
122     },
123     /* NT2K */
124     {
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! */
128     },
129     /* WINXP */
130     {
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! */
134     },
135     /* WIN2K3 */
136     {
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
140     },
141     /* WINVISTA */
142     {
143         sizeof(RTL_OSVERSIONINFOEXW), 6, 0, 0x1770, VER_PLATFORM_WIN32_NT,
144         {' ',0},
145         0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
146     }
147 };
148
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*/
163 };
164
165
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;
168
169
170 /**********************************************************************
171  *         get_nt_registry_version
172  *
173  * Fetch the version information from the NT-style registry keys.
174  */
175 static BOOL get_nt_registry_version( RTL_OSVERSIONINFOEXW *version )
176 {
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};
199
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;
207
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 );
215
216     if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) return FALSE;
217
218     memset( version, 0, sizeof(*version) );
219
220     RtlInitUnicodeString( &valueW, CurrentVersionW );
221     if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
222     {
223         WCHAR *p, *str = (WCHAR *)info->Data;
224         str[info->DataLength / sizeof(WCHAR)] = 0;
225         p = strchrW( str, '.' );
226         if (p)
227         {
228             *p++ = 0;
229             version->dwMinorVersion = atoiW( p );
230         }
231         version->dwMajorVersion = atoiW( str );
232     }
233
234     if (version->dwMajorVersion)   /* we got the main version, now fetch the other fields */
235     {
236         ret = TRUE;
237         version->dwPlatformId = VER_PLATFORM_WIN32_NT;
238
239         /* get build number */
240
241         RtlInitUnicodeString( &valueW, CurrentBuildNumberW );
242         if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
243         {
244             WCHAR *str = (WCHAR *)info->Data;
245             str[info->DataLength / sizeof(WCHAR)] = 0;
246             version->dwBuildNumber = atoiW( str );
247         }
248
249         /* get version description */
250
251         RtlInitUnicodeString( &valueW, CSDVersionW );
252         if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
253         {
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;
257         }
258
259         /* get service pack version */
260
261         RtlInitUnicodeString( &nameW, service_pack_keyW );
262         if (!NtOpenKey( &hkey2, KEY_ALL_ACCESS, &attr ))
263         {
264             RtlInitUnicodeString( &valueW, CSDVersionW );
265             if (!NtQueryValueKey( hkey2, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
266             {
267                 if (info->DataLength >= sizeof(DWORD))
268                 {
269                     DWORD dw = *(DWORD *)info->Data;
270                     version->wServicePackMajor = LOWORD(dw) >> 8;
271                     version->wServicePackMinor = LOWORD(dw) & 0xff;
272                 }
273             }
274             NtClose( hkey2 );
275         }
276
277         /* get product type */
278
279         RtlInitUnicodeString( &nameW, product_keyW );
280         if (!NtOpenKey( &hkey2, KEY_ALL_ACCESS, &attr ))
281         {
282             RtlInitUnicodeString( &valueW, ProductTypeW );
283             if (!NtQueryValueKey( hkey2, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
284             {
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;
290             }
291             NtClose( hkey2 );
292         }
293
294         /* FIXME: get wSuiteMask */
295     }
296
297     NtClose( hkey );
298     return ret;
299 }
300
301
302 /**********************************************************************
303  *         get_win9x_registry_version
304  *
305  * Fetch the version information from the Win9x-style registry keys.
306  */
307 static BOOL get_win9x_registry_version( RTL_OSVERSIONINFOEXW *version )
308 {
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};
316
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;
324
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 );
332
333     if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) return FALSE;
334
335     memset( version, 0, sizeof(*version) );
336
337     RtlInitUnicodeString( &valueW, VersionNumberW );
338     if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
339     {
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)
346         {
347             str = p;
348             p = strchrW( str, '.' );
349             if (p)
350             {
351                 *p++ = 0;
352                 version->dwBuildNumber = atoiW( p );
353             }
354             version->dwMinorVersion = atoiW( str );
355         }
356         /* build number contains version too on Win9x */
357         version->dwBuildNumber |= MAKEWORD( version->dwMinorVersion, version->dwMajorVersion ) << 16;
358     }
359
360     if (version->dwMajorVersion)   /* we got the main version, now fetch the other fields */
361     {
362         ret = TRUE;
363         version->dwPlatformId = VER_PLATFORM_WIN32_WINDOWS;
364
365         RtlInitUnicodeString( &valueW, SubVersionNumberW );
366         if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
367         {
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;
371         }
372     }
373
374     NtClose( hkey );
375     return ret;
376 }
377
378
379 /**********************************************************************
380  *         parse_win_version
381  *
382  * Parse the contents of the Version key.
383  */
384 static BOOL parse_win_version( HANDLE hkey )
385 {
386     static const WCHAR VersionW[] = {'V','e','r','s','i','o','n',0};
387
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;
393
394     RtlInitUnicodeString( &valueW, VersionW );
395     if (NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
396         return FALSE;
397
398     RtlUnicodeToMultiByteN( buffer, sizeof(buffer)-1, &len, (WCHAR *)info->Data, info->DataLength );
399     buffer[len] = 0;
400
401     for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
402     {
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) )
409             {
410                 current_version = &VersionData[i];
411                 TRACE( "got win version %s\n", WinVersionNames[i] );
412                 return TRUE;
413             }
414             pCurr = p+1;
415         } while (p);
416     }
417
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++)
421     {
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);
426
427         MESSAGE(" '%.*s'%c", (int)len, pCurr, (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
428     }
429     return FALSE;
430 }
431
432
433 /**********************************************************************
434  *         version_init
435  */
436 void version_init( const WCHAR *appname )
437 {
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};
440
441     OBJECT_ATTRIBUTES attr;
442     UNICODE_STRING nameW;
443     HANDLE root, hkey, config_key;
444     BOOL got_win_ver = FALSE;
445
446     current_version = &VersionData[NT2K];  /* default if nothing else is specified */
447
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 );
456
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;
461
462     /* open AppDefaults\\appname key */
463     if (appname && *appname)
464     {
465         const WCHAR *p;
466         WCHAR appversion[MAX_PATH+20];
467
468         if ((p = strrchrW( appname, '/' ))) appname = p + 1;
469         if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
470
471         strcpyW( appversion, appdefaultsW );
472         strcatW( appversion, appname );
473         RtlInitUnicodeString( &nameW, appversion );
474         attr.RootDirectory = config_key;
475
476         /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe */
477         if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
478         {
479             TRACE( "getting version from %s\n", debugstr_w(appversion) );
480             got_win_ver = parse_win_version( hkey );
481             NtClose( hkey );
482         }
483     }
484
485     if (!got_win_ver)
486     {
487         TRACE( "getting default version\n" );
488         got_win_ver = parse_win_version( config_key );
489     }
490     NtClose( config_key );
491
492 done:
493     if (!got_win_ver)
494     {
495         static RTL_OSVERSIONINFOEXW registry_version;
496
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;
501     }
502
503
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;
508
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;
515
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 );
522 }
523
524
525 /***********************************************************************
526  *         RtlGetVersion   (NTDLL.@)
527  */
528 NTSTATUS WINAPI RtlGetVersion( RTL_OSVERSIONINFOEXW *info )
529 {
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))
536     {
537         info->wServicePackMajor = current_version->wServicePackMajor;
538         info->wServicePackMinor = current_version->wServicePackMinor;
539         info->wSuiteMask        = current_version->wSuiteMask;
540         info->wProductType      = current_version->wProductType;
541     }
542     return STATUS_SUCCESS;
543 }
544
545
546 /******************************************************************************
547  *  RtlGetNtVersionNumbers   (NTDLL.@)
548  *
549  * Get the version numbers of the run time library.
550  *
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
555  *
556  * RETURNS
557  *  Nothing.
558  *
559  * NOTES
560  * Introduced in Windows XP (NT5.1)
561  */
562 void WINAPI RtlGetNtVersionNumbers( LPDWORD major, LPDWORD minor, LPDWORD build )
563 {
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);
568 }
569
570
571 /******************************************************************************
572  *  RtlGetNtProductType   (NTDLL.@)
573  */
574 BOOLEAN WINAPI RtlGetNtProductType( LPDWORD type )
575 {
576     if (type) *type = current_version->wProductType;
577     return TRUE;
578 }
579
580
581 static inline NTSTATUS version_compare_values(ULONG left, ULONG right, UCHAR condition)
582 {
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;
601     }
602     return STATUS_SUCCESS;
603 }
604
605 /******************************************************************************
606  *        RtlVerifyVersionInfo   (NTDLL.@)
607  */
608 NTSTATUS WINAPI RtlVerifyVersionInfo( const RTL_OSVERSIONINFOEXW *info,
609                                       DWORD dwTypeMask, DWORDLONG dwlConditionMask )
610 {
611     RTL_OSVERSIONINFOEXW ver;
612     NTSTATUS status;
613
614     TRACE("(%p,0x%x,0x%s)\n", info, dwTypeMask, wine_dbgstr_longlong(dwlConditionMask));
615
616     ver.dwOSVersionInfoSize = sizeof(ver);
617     if ((status = RtlGetVersion( &ver )) != STATUS_SUCCESS) return status;
618
619     if(!(dwTypeMask && dwlConditionMask)) return STATUS_INVALID_PARAMETER;
620
621     if(dwTypeMask & VER_PRODUCT_TYPE)
622     {
623         status = version_compare_values(ver.wProductType, info->wProductType, dwlConditionMask >> 7*3 & 0x07);
624         if (status != STATUS_SUCCESS)
625             return status;
626     }
627     if(dwTypeMask & VER_SUITENAME)
628         switch(dwlConditionMask >> 6*3 & 0x07)
629         {
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;
640         }
641     if(dwTypeMask & VER_PLATFORMID)
642     {
643         status = version_compare_values(ver.dwPlatformId, info->dwPlatformId, dwlConditionMask >> 3*3 & 0x07);
644         if (status != STATUS_SUCCESS)
645             return status;
646     }
647     if(dwTypeMask & VER_BUILDNUMBER)
648     {
649         status = version_compare_values(ver.dwBuildNumber, info->dwBuildNumber, dwlConditionMask >> 2*3 & 0x07);
650         if (status != STATUS_SUCCESS)
651             return status;
652     }
653
654     if(dwTypeMask & (VER_MAJORVERSION|VER_MINORVERSION|VER_SERVICEPACKMAJOR|VER_SERVICEPACKMINOR))
655     {
656         unsigned char condition = 0;
657         BOOLEAN do_next_check = TRUE;
658
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;
667
668         if(dwTypeMask & VER_MAJORVERSION)
669         {
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));
673         }
674         if((dwTypeMask & VER_MINORVERSION) && do_next_check)
675         {
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));
679         }
680         if((dwTypeMask & VER_SERVICEPACKMAJOR) && do_next_check)
681         {
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));
685         }
686         if((dwTypeMask & VER_SERVICEPACKMINOR) && do_next_check)
687         {
688             status = version_compare_values(ver.wServicePackMinor, info->wServicePackMinor, condition);
689         }
690
691         if (status != STATUS_SUCCESS)
692             return status;
693     }
694
695     return STATUS_SUCCESS;
696 }