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