Added (stubbed) SystemDriverInformation and
[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 "winbase.h"
34 #include "winreg.h"
35 #include "wine/unicode.h"
36 #include "wine/debug.h"
37 #include "ntdll_misc.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     NB_WINDOWS_VERSIONS
55 } WINDOWS_VERSION;
56
57 /* FIXME: compare values below with original and fix.
58  * An *excellent* win9x version page (ALL versions !)
59  * can be found at members.aol.com/axcel216/ver.htm */
60 static const RTL_OSVERSIONINFOEXW VersionData[NB_WINDOWS_VERSIONS] =
61 {
62     /* WIN20 FIXME: verify values */
63     {
64         sizeof(RTL_OSVERSIONINFOEXW), 2, 0, 0, VER_PLATFORM_WIN32s,
65         {'W','i','n','3','2','s',' ','1','.','3',0},
66         0, 0, 0, 0, 0
67     },
68     /* WIN30 FIXME: verify values */
69     {
70         sizeof(RTL_OSVERSIONINFOEXW), 3, 0, 0, VER_PLATFORM_WIN32s,
71         {'W','i','n','3','2','s',' ','1','.','3',0},
72         0, 0, 0, 0, 0
73     },
74     /* WIN31 */
75     {
76         sizeof(RTL_OSVERSIONINFOEXW), 3, 10, 0, VER_PLATFORM_WIN32s,
77         {'W','i','n','3','2','s',' ','1','.','3',0},
78         0, 0, 0, 0, 0
79     },
80     /* WIN95 */
81     {
82         /* Win95:       4, 0, 0x40003B6, ""
83          * Win95sp1:    4, 0, 0x40003B6, " A " (according to doc)
84          * Win95osr2:   4, 0, 0x4000457, " B " (according to doc)
85          * Win95osr2.1: 4, 3, 0x40304BC, " B " (according to doc)
86          * Win95osr2.5: 4, 3, 0x40304BE, " C " (according to doc)
87          * Win95a/b can be discerned via regkey SubVersionNumber
88          * See also:
89          * http://support.microsoft.com/support/kb/articles/q158/2/38.asp
90          */
91         sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x40003B6, VER_PLATFORM_WIN32_WINDOWS,
92         {0},
93         0, 0, 0, 0, 0
94     },
95     /* WIN98 (second edition) */
96     {
97         /* Win98:   4, 10, 0x40A07CE, " "   4.10.1998
98          * Win98SE: 4, 10, 0x40A08AE, " A " 4.10.2222
99          */
100         sizeof(RTL_OSVERSIONINFOEXW), 4, 10, 0x40A08AE, VER_PLATFORM_WIN32_WINDOWS,
101         {' ','A',' ',0},
102         0, 0, 0, 0, 0
103     },
104     /* WINME */
105     {
106         sizeof(RTL_OSVERSIONINFOEXW), 4, 90, 0x45A0BB8, VER_PLATFORM_WIN32_WINDOWS,
107         {' ',0},
108         0, 0, 0, 0, 0
109     },
110     /* NT351 */
111     {
112         sizeof(RTL_OSVERSIONINFOEXW), 3, 51, 0x421, VER_PLATFORM_WIN32_NT,
113         {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
114         0, 0, 0, 0, 0
115     },
116     /* NT40 */
117     {
118         sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x565, VER_PLATFORM_WIN32_NT,
119         {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','6','a',0},
120         6, 0, 0, VER_NT_WORKSTATION, 0
121     },
122     /* NT2K */
123     {
124         sizeof(RTL_OSVERSIONINFOEXW), 5, 0, 0x893, VER_PLATFORM_WIN32_NT,
125         {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','4',0},
126         4, 0, 0, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
127     },
128     /* WINXP */
129     {
130         sizeof(RTL_OSVERSIONINFOEXW), 5, 1, 0xA28, VER_PLATFORM_WIN32_NT,
131         {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
132         2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
133     },
134     /* WIN2K3 */
135     {
136         sizeof(RTL_OSVERSIONINFOEXW), 5, 2, 0xECE, VER_PLATFORM_WIN32_NT,
137         {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','1',0},
138         1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
139     }
140 };
141
142 static const char * const WinVersionNames[NB_WINDOWS_VERSIONS] =
143 { /* no spaces in here ! */
144     "win20",                      /* WIN20 */
145     "win30",                      /* WIN30 */
146     "win31",                      /* WIN31 */
147     "win95",                      /* WIN95 */
148     "win98",                      /* WIN98 */
149     "winme",                      /* WINME */
150     "nt351",                      /* NT351 */
151     "nt40",                       /* NT40 */
152     "win2000,win2k,nt2k,nt2000",  /* NT2K */
153     "winxp",                      /* WINXP */
154     "win2003,win2k3"              /* WIN2K3 */
155 };
156
157 /* names to print out in debug traces */
158 static const char * const debug_names[NB_WINDOWS_VERSIONS] =
159 {
160     "Windows 2.0",       /* WIN20 */
161     "Windows 3.0",       /* WIN30 */
162     "Windows 3.1",       /* WIN31 */
163     "Windows 95",        /* WIN95 */
164     "Windows 98",        /* WIN98 */
165     "Windows Me",        /* WINME */
166     "Windows NT 3.51",   /* NT351 */
167     "Windows NT 4.0",    /* NT40 */
168     "Windows 2000",      /* NT2K */
169     "Windows XP",        /* WINXP */
170     "Windows Server 2003"/* WIN2K3 */
171 };
172
173 /* if one of the following dlls is importing ntdll the windows
174 version autodetection switches wine to unicode (nt 3.51 or 4.0) */
175 static const WCHAR special_dlls[][16] =
176 {
177     {'c','o','m','d','l','g','3','2','.','d','l','l',0},
178     {'c','o','m','c','t','l','3','2','.','d','l','l',0},
179     {'s','h','e','l','l','3','2','.','d','l','l',0},
180     {'o','l','e','3','2','.','d','l','l',0},
181     {'r','p','c','r','t','4','.','d','l','l',0}
182 };
183
184 /* the current version has not been autodetected but forced via cmdline */
185 static BOOL versionForced = FALSE;
186 static WINDOWS_VERSION forcedWinVersion; /* init value irrelevant */
187
188 /**********************************************************************
189  *         parse_win_version
190  *
191  * Parse the contents of the Version key.
192  */
193 static BOOL parse_win_version( HKEY hkey )
194 {
195     static const WCHAR WindowsW[] = {'W','i','n','d','o','w','s',0};
196
197     UNICODE_STRING valueW;
198     char tmp[64], buffer[50];
199     KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
200     DWORD count, len;
201     int i;
202
203     RtlInitUnicodeString( &valueW, WindowsW );
204     if (NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
205         return FALSE;
206
207     RtlUnicodeToMultiByteN( buffer, sizeof(buffer)-1, &len, (WCHAR *)info->Data, info->DataLength );
208     buffer[len] = 0;
209
210     for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
211     {
212         const char *p, *pCurr = WinVersionNames[i];
213         /* iterate through all winver aliases separated by comma */
214         do {
215             p = strchr(pCurr, ',');
216             len = p ? p - pCurr : strlen(pCurr);
217             if ( (!strncmp( pCurr, buffer, len )) && (buffer[len] == 0) )
218             {
219                 forcedWinVersion = i;
220                 versionForced = TRUE;
221                 TRACE( "got win version %s\n", WinVersionNames[forcedWinVersion] );
222                 return TRUE;
223             }
224             pCurr = p+1;
225         } while (p);
226     }
227
228     MESSAGE("Invalid Windows version value '%s' specified in config file.\n", buffer );
229     MESSAGE("Valid versions are:" );
230     for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
231     {
232         /* only list the first, "official" alias in case of aliases */
233         const char *pCurr = WinVersionNames[i];
234         const char *p = strchr(pCurr, ',');
235         len = (p) ? p - pCurr : strlen(pCurr);
236
237         MESSAGE(" '%.*s'%c", (int)len, pCurr, (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
238     }
239     return FALSE;
240 }
241
242
243 /**********************************************************************
244  *         VERSION_Init
245  */
246 void VERSION_Init( const WCHAR *appname )
247 {
248     OBJECT_ATTRIBUTES attr;
249     UNICODE_STRING nameW;
250     HKEY hkey, config_key;
251     static const WCHAR configW[] = {'M','a','c','h','i','n','e','\\',
252                                     'S','o','f','t','w','a','r','e','\\',
253                                     'W','i','n','e','\\',
254                                     'W','i','n','e','\\',
255                                     'C','o','n','f','i','g',0};
256     static const WCHAR appdefaultsW[] = {'A','p','p','D','e','f','a','u','l','t','s','\\',0};
257     static const WCHAR versionW[] = {'\\','V','e','r','s','i','o','n',0};
258
259     attr.Length = sizeof(attr);
260     attr.RootDirectory = 0;
261     attr.ObjectName = &nameW;
262     attr.Attributes = 0;
263     attr.SecurityDescriptor = NULL;
264     attr.SecurityQualityOfService = NULL;
265     RtlInitUnicodeString( &nameW, configW );
266
267     if (NtOpenKey( &config_key, KEY_ALL_ACCESS, &attr )) return;
268     attr.RootDirectory = config_key;
269
270     /* open AppDefaults\\appname\\Version key */
271     if (appname && *appname)
272     {
273         const WCHAR *p;
274         WCHAR appversion[MAX_PATH+20];
275         BOOL got_win_ver = FALSE;
276
277         if ((p = strrchrW( appname, '/' ))) appname = p + 1;
278         if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
279
280         strcpyW( appversion, appdefaultsW );
281         strcatW( appversion, appname );
282         strcatW( appversion, versionW );
283         TRACE( "getting version from %s\n", debugstr_w(appversion) );
284         RtlInitUnicodeString( &nameW, appversion );
285
286         if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
287         {
288             got_win_ver = parse_win_version( hkey );
289             NtClose( hkey );
290         }
291         if (got_win_ver) goto done;
292     }
293
294     TRACE( "getting default version\n" );
295     RtlInitUnicodeString( &nameW, versionW + 1 );
296     if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
297     {
298         parse_win_version( hkey );
299         NtClose( hkey );
300     }
301
302  done:
303     NtClose( config_key );
304 }
305
306
307 /**********************************************************************
308  *      VERSION_GetSystemDLLVersion
309  *
310  * This function tries to figure out if a given (native) dll comes from
311  * win95/98 or winnt. Since all values in the OptionalHeader are not a
312  * usable hint, we test if a dll imports the ntdll.
313  * This is at least working for all system dlls like comctl32, comdlg32 and
314  * shell32.
315  * If you have a better idea to figure this out...
316  */
317 static DWORD VERSION_GetSystemDLLVersion( HMODULE hmod )
318 {
319     DWORD size;
320     IMAGE_IMPORT_DESCRIPTOR *pe_imp;
321
322     if ((pe_imp = RtlImageDirectoryEntryToData( hmod, TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &size )))
323     {
324         for ( ; pe_imp->Name; pe_imp++)
325         {
326             char * name = (char *)hmod + (unsigned int)pe_imp->Name;
327             TRACE("%s\n", name);
328
329             if (!strncasecmp(name, "ntdll", 5))
330             {
331               switch(RtlImageNtHeader(hmod)->OptionalHeader.MajorOperatingSystemVersion) {
332                   case 3:
333                           MESSAGE("WARNING: very old native DLL (NT 3.x) used, might cause instability.\n");
334                           return NT351;
335                   case 4: return NT40;
336                   case 5: switch (RtlImageNtHeader(hmod)->OptionalHeader.MinorOperatingSystemVersion){
337                           case 0: return NT2K;
338                           case 1: return WINXP;
339                           case 2: return WIN2K3;
340                           }
341                   default:
342                           FIXME("Unknown DLL OS version, please report !!\n");
343                           return WIN2K3;
344               }
345             }
346         }
347     }
348     return WIN95;
349 }
350
351
352 /**********************************************************************
353  *      VERSION_GetLinkedDllVersion
354  *
355  * Some version data (not reliable!):
356  * linker/OS/image/subsys
357  *
358  * x.xx/1.00/0.00/3.10  Win32s          (any version ?)
359  * 2.39/1.00/0.00/3.10  Win32s          freecell.exe (any version)
360  * 2.50/1.00/4.00/4.00  Win32s 1.30     winhlp32.exe
361  * 2.60/3.51/3.51/3.51  NT351SP5        system dlls
362  * 2.60/3.51/3.51/4.00  NT351SP5        comctl32 dll
363  * 2.xx/1.00/0.00/4.00  Win95           system files
364  * x.xx/4.00/0.00/4.00  Win95           most applications
365  * 3.10/4.00/0.00/4.00  Win98           notepad
366  * x.xx/5.00/5.00/4.00  Win98           system dlls (e.g. comctl32.dll)
367  * x.xx/4.00/4.00/4.00  NT 4            most apps
368  * 5.12/5.00/5.00/4.00  NT4+IE5         comctl32.dll
369  * 5.12/5.00/5.00/4.00  Win98           calc
370  * x.xx/5.00/5.00/4.00  win95/win98/NT4 IE5 files
371  * 2.38/4.00/1.00/4.00  Mingw32         applications compiled with mingw32
372  */
373 static DWORD VERSION_GetLinkedDllVersion(void)
374 {
375     WINDOWS_VERSION WinVersion = NB_WINDOWS_VERSIONS;
376     PIMAGE_OPTIONAL_HEADER ophd;
377     IMAGE_NT_HEADERS *nt;
378     const WCHAR *name;
379     PLIST_ENTRY mark, entry;
380     PLDR_MODULE mod;
381     unsigned int i;
382
383     /* First check the native dlls provided. These have to be
384        from one windows version */
385
386     mark = &NtCurrentTeb()->Peb->LdrData->InLoadOrderModuleList;
387     for (entry = mark->Flink; entry != mark; entry = entry->Flink)
388     {
389         mod = CONTAINING_RECORD(entry, LDR_MODULE, InLoadOrderModuleList);
390         if (mod->Flags & LDR_WINE_INTERNAL) continue;
391         nt = RtlImageNtHeader(mod->BaseAddress);
392         ophd = &nt->OptionalHeader;
393         name = strrchrW( mod->FullDllName.Buffer, '\\' );
394         if (name) name++;
395         else name = mod->FullDllName.Buffer;
396
397         TRACE("%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
398               debugstr_w(name), ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
399               ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
400               ophd->MajorImageVersion, ophd->MinorImageVersion,
401               ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
402
403         for (i = 0; i < sizeof(special_dlls)/sizeof(special_dlls[0]); i++)
404         {
405             /* test if it is a special dll */
406             if (!strcmpiW(name, special_dlls[i]))
407             {
408                 DWORD DllVersion = VERSION_GetSystemDLLVersion(mod->BaseAddress);
409                 if (WinVersion == NB_WINDOWS_VERSIONS) WinVersion = DllVersion;
410                 else if (WinVersion != DllVersion)
411                 {
412                     ERR("You mixed system DLLs from different windows versions! Expect a crash! (%s: expected version %s, but is %s)\n",
413                         debugstr_w(name),
414                         debugstr_w(VersionData[WinVersion].szCSDVersion),
415                         debugstr_w(VersionData[DllVersion].szCSDVersion));
416                     return WIN20; /* this may let the exe exit */
417                 }
418                 break;
419             }
420         }
421     }
422
423     if(WinVersion != NB_WINDOWS_VERSIONS) return WinVersion;
424
425     /* we are using no external system dlls, look at the exe */
426     nt = RtlImageNtHeader(NtCurrentTeb()->Peb->ImageBaseAddress);
427     ophd = &nt->OptionalHeader;
428
429     TRACE("%02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
430           ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
431           ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
432           ophd->MajorImageVersion, ophd->MinorImageVersion,
433           ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
434
435     /* special nt 3.51 */
436     if (3 == ophd->MajorOperatingSystemVersion && 51 == ophd->MinorOperatingSystemVersion)
437     {
438         return NT351;
439     }
440
441     /* the MajorSubsystemVersion is the only usable sign */
442     if (ophd->MajorSubsystemVersion < 4)
443     {
444         if ( ophd->MajorOperatingSystemVersion == 1
445              && ophd->MinorOperatingSystemVersion == 0)
446         {
447             return WIN31; /* win32s */
448         }
449
450         if (ophd->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
451             return NT351; /* FIXME: NT 3.1, not tested */
452         else
453             return WIN98;
454     }
455
456     switch (ophd->MajorOperatingSystemVersion)
457     {
458     case 5:
459         switch (ophd->MinorOperatingSystemVersion)
460         {
461         case 0 : return NT2K;
462         case 1 : return WINXP;
463         case 2 : return WIN2K3;
464         }
465         break;
466     case 4:
467         switch(ophd->MinorOperatingSystemVersion)
468         {
469         case 90 : return WINME;
470         case 10 : return WIN98;
471         case 0  :
472             switch(ophd->MajorImageVersion)
473             {
474             case 4 : return WIN98;  /* most apps will use this */
475             case 1 : return WIN98; /* this seems to be generated by Mingw32 */
476             case 0 : return WIN95;
477             }
478             break;
479         }
480         break;
481     case 1:
482         if(ophd->MinorOperatingSystemVersion == 0)
483            return WIN95;
484         break;
485     }
486     FIXME("Unknown EXE OS version %d.%d, please report !!\n",
487           ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion );
488     return WIN98;
489 }
490
491 /**********************************************************************
492  *         VERSION_GetVersion
493  *
494  * WARNING !!!
495  * Don't call this function too early during the Wine init,
496  * as pdb->exe_modref (required by VERSION_GetImageVersion()) might still
497  * be NULL in such cases, which causes the winver to ALWAYS be detected
498  * as WIN31.
499  * And as we cache the winver once it has been determined, this is bad.
500  * This can happen much easier than you might think, as this function
501  * is called by EVERY GetVersion*() API !
502  *
503  */
504 static const RTL_OSVERSIONINFOEXW *VERSION_GetVersion(void)
505 {
506     static WORD winver = 0xffff;
507
508     if (versionForced)
509         return &VersionData[forcedWinVersion];  /* user has overridden any sensible checks */
510
511     if (winver == 0xffff) /* to be determined */
512     {
513         WINDOWS_VERSION retver = VERSION_GetLinkedDllVersion();
514
515         /* cache determined value, but do not store in case of WIN31 */
516         if (retver != WIN31) winver = retver;
517         return &VersionData[retver];
518     }
519     return &VersionData[winver];
520 }
521
522
523 /***********************************************************************
524  *         RtlGetVersion   (NTDLL.@)
525  */
526 NTSTATUS WINAPI RtlGetVersion( RTL_OSVERSIONINFOEXW *info )
527 {
528     const RTL_OSVERSIONINFOEXW * const current = VERSION_GetVersion();
529
530     info->dwMajorVersion = current->dwMajorVersion;
531     info->dwMinorVersion = current->dwMinorVersion;
532     info->dwBuildNumber  = current->dwBuildNumber;
533     info->dwPlatformId   = current->dwPlatformId;
534     strcpyW( info->szCSDVersion, current->szCSDVersion );
535     if(info->dwOSVersionInfoSize == sizeof(RTL_OSVERSIONINFOEXW))
536     {
537         info->wServicePackMajor = current->wServicePackMajor;
538         info->wServicePackMinor = current->wServicePackMinor;
539         info->wSuiteMask        = current->wSuiteMask;
540         info->wProductType      = current->wProductType;
541     }
542     TRACE("<-- %s (%s)\n", debug_names[current - VersionData], debugstr_w(current->szCSDVersion) );
543     return STATUS_SUCCESS;
544 }
545
546
547 /******************************************************************************
548  *  RtlGetNtVersionNumbers   (NTDLL.@)
549  *
550  * Get the version numbers of the run time library.
551  *
552  * PARAMS
553  *  major [O] Destination for the Major version
554  *  minor [O] Destination for the Minor version
555  *  build [O] Destination for the Build version
556  *
557  * RETURNS
558  *  Nothing.
559  *
560  * NOTES
561  * Introduced in Windows XP (NT5.1)
562  */
563 void WINAPI RtlGetNtVersionNumbers( LPDWORD major, LPDWORD minor, LPDWORD build )
564 {
565     const RTL_OSVERSIONINFOEXW * const current = VERSION_GetVersion();
566
567     if (major) *major = current->dwMajorVersion;
568     if (minor) *minor = current->dwMinorVersion;
569     /* FIXME: Does anybody know the real formula? */
570     if (build) *build = (0xF0000000 | current->dwBuildNumber);
571 }
572
573
574 /******************************************************************************
575  *        VerifyVersionInfoW   (KERNEL32.@)
576  */
577 NTSTATUS WINAPI RtlVerifyVersionInfo( const RTL_OSVERSIONINFOEXW *info,
578                                       DWORD dwTypeMask, DWORDLONG dwlConditionMask )
579 {
580     RTL_OSVERSIONINFOEXW ver;
581     NTSTATUS status;
582
583     FIXME("(%p,%lu,%llx): Not all cases correctly implemented yet\n",
584           info, dwTypeMask, dwlConditionMask);
585
586     /* FIXME:
587         - Check the following special case on Windows (various versions):
588           o lp->wSuiteMask == 0 and ver.wSuiteMask != 0 and VER_AND/VER_OR
589           o lp->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW)
590         - MSDN talks about some tests being impossible. Check what really happens.
591      */
592
593     ver.dwOSVersionInfoSize = sizeof(ver);
594     if ((status = RtlGetVersion( &ver )) != STATUS_SUCCESS) return status;
595
596     if(!(dwTypeMask && dwlConditionMask)) return STATUS_INVALID_PARAMETER;
597
598     if(dwTypeMask & VER_PRODUCT_TYPE)
599         switch(dwlConditionMask >> 7*3 & 0x07) {
600             case VER_EQUAL:
601                 if(ver.wProductType != info->wProductType) return STATUS_REVISION_MISMATCH;
602                 break;
603             case VER_GREATER:
604                 if(ver.wProductType <= info->wProductType) return STATUS_REVISION_MISMATCH;
605                 break;
606             case VER_GREATER_EQUAL:
607                 if(ver.wProductType < info->wProductType) return STATUS_REVISION_MISMATCH;
608                 break;
609             case VER_LESS:
610                 if(ver.wProductType >= info->wProductType) return STATUS_REVISION_MISMATCH;
611                 break;
612             case VER_LESS_EQUAL:
613                 if(ver.wProductType > info->wProductType) return STATUS_REVISION_MISMATCH;
614                 break;
615             default:
616                 return STATUS_INVALID_PARAMETER;
617         }
618     if(dwTypeMask & VER_SUITENAME)
619         switch(dwlConditionMask >> 6*3 & 0x07)
620         {
621             case VER_AND:
622                 if((info->wSuiteMask & ver.wSuiteMask) != info->wSuiteMask)
623                     return STATUS_REVISION_MISMATCH;
624                 break;
625             case VER_OR:
626                 if(!(info->wSuiteMask & ver.wSuiteMask) && info->wSuiteMask)
627                     return STATUS_REVISION_MISMATCH;
628                 break;
629             default:
630                 return STATUS_INVALID_PARAMETER;
631         }
632     if(dwTypeMask & VER_PLATFORMID)
633         switch(dwlConditionMask >> 3*3 & 0x07)
634         {
635             case VER_EQUAL:
636                 if(ver.dwPlatformId != info->dwPlatformId) return STATUS_REVISION_MISMATCH;
637                 break;
638             case VER_GREATER:
639                 if(ver.dwPlatformId <= info->dwPlatformId) return STATUS_REVISION_MISMATCH;
640                 break;
641             case VER_GREATER_EQUAL:
642                 if(ver.dwPlatformId < info->dwPlatformId) return STATUS_REVISION_MISMATCH;
643                 break;
644             case VER_LESS:
645                 if(ver.dwPlatformId >= info->dwPlatformId) return STATUS_REVISION_MISMATCH;
646                 break;
647             case VER_LESS_EQUAL:
648                 if(ver.dwPlatformId > info->dwPlatformId) return STATUS_REVISION_MISMATCH;
649                 break;
650             default:
651                 return STATUS_INVALID_PARAMETER;
652         }
653     if(dwTypeMask & VER_BUILDNUMBER)
654         switch(dwlConditionMask >> 2*3 & 0x07)
655         {
656             case VER_EQUAL:
657                 if(ver.dwBuildNumber != info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
658                 break;
659             case VER_GREATER:
660                 if(ver.dwBuildNumber <= info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
661                 break;
662             case VER_GREATER_EQUAL:
663                 if(ver.dwBuildNumber < info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
664                 break;
665             case VER_LESS:
666                 if(ver.dwBuildNumber >= info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
667                 break;
668             case VER_LESS_EQUAL:
669                 if(ver.dwBuildNumber > info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
670                 break;
671             default:
672                 return STATUS_INVALID_PARAMETER;
673         }
674     if(dwTypeMask & VER_MAJORVERSION)
675         switch(dwlConditionMask >> 1*3 & 0x07)
676         {
677             case VER_EQUAL:
678                 if(ver.dwMajorVersion != info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
679                 break;
680             case VER_GREATER:
681                 if(ver.dwMajorVersion <= info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
682                 break;
683             case VER_GREATER_EQUAL:
684                 if(ver.dwMajorVersion < info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
685                 break;
686             case VER_LESS:
687                 if(ver.dwMajorVersion >= info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
688                 break;
689             case VER_LESS_EQUAL:
690                 if(ver.dwMajorVersion > info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
691                 break;
692             default:
693                 return STATUS_INVALID_PARAMETER;
694         }
695     if(dwTypeMask & VER_MINORVERSION)
696         switch(dwlConditionMask >> 0*3 & 0x07)
697         {
698             case VER_EQUAL:
699                 if(ver.dwMinorVersion != info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
700                 break;
701             case VER_GREATER:
702                 if(ver.dwMinorVersion <= info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
703                 break;
704             case VER_GREATER_EQUAL:
705                 if(ver.dwMinorVersion < info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
706                 break;
707             case VER_LESS:
708                 if(ver.dwMinorVersion >= info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
709                 break;
710             case VER_LESS_EQUAL:
711                 if(ver.dwMinorVersion > info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
712                 break;
713             default:
714                 return STATUS_INVALID_PARAMETER;
715         }
716     if(dwTypeMask & VER_SERVICEPACKMAJOR)
717         switch(dwlConditionMask >> 5*3 & 0x07)
718         {
719             case VER_EQUAL:
720                 if(ver.wServicePackMajor != info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
721                 break;
722             case VER_GREATER:
723                 if(ver.wServicePackMajor <= info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
724                 break;
725             case VER_GREATER_EQUAL:
726                 if(ver.wServicePackMajor < info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
727                 break;
728             case VER_LESS:
729                 if(ver.wServicePackMajor >= info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
730                 break;
731             case VER_LESS_EQUAL:
732                 if(ver.wServicePackMajor > info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
733                 break;
734             default:
735                 return STATUS_INVALID_PARAMETER;
736         }
737     if(dwTypeMask & VER_SERVICEPACKMINOR)
738         switch(dwlConditionMask >> 4*3 & 0x07)
739         {
740             case VER_EQUAL:
741                 if(ver.wServicePackMinor != info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
742                 break;
743             case VER_GREATER:
744                 if(ver.wServicePackMinor <= info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
745                 break;
746             case VER_GREATER_EQUAL:
747                 if(ver.wServicePackMinor < info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
748                 break;
749             case VER_LESS:
750                 if(ver.wServicePackMinor >= info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
751                 break;
752             case VER_LESS_EQUAL:
753                 if(ver.wServicePackMinor > info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
754                 break;
755             default:
756                 return STATUS_INVALID_PARAMETER;
757         }
758
759     return STATUS_SUCCESS;
760 }