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