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