Remove unneeded headers to reduce unneeded rebuilds.
[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         {0},
138         0, 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  */
372 static DWORD VERSION_GetLinkedDllVersion(void)
373 {
374     WINDOWS_VERSION WinVersion = NB_WINDOWS_VERSIONS;
375     PIMAGE_OPTIONAL_HEADER ophd;
376     IMAGE_NT_HEADERS *nt;
377     const WCHAR *name;
378     PLIST_ENTRY mark, entry;
379     PLDR_MODULE mod;
380     unsigned int i;
381
382     /* First check the native dlls provided. These have to be
383        from one windows version */
384
385     mark = &NtCurrentTeb()->Peb->LdrData->InLoadOrderModuleList;
386     for (entry = mark->Flink; entry != mark; entry = entry->Flink)
387     {
388         mod = CONTAINING_RECORD(entry, LDR_MODULE, InLoadOrderModuleList);
389         if (mod->Flags & LDR_WINE_INTERNAL) continue;
390         nt = RtlImageNtHeader(mod->BaseAddress);
391         ophd = &nt->OptionalHeader;
392         name = strrchrW( mod->FullDllName.Buffer, '\\' );
393         if (name) name++;
394         else name = mod->FullDllName.Buffer;
395
396         TRACE("%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
397               debugstr_w(name), ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
398               ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
399               ophd->MajorImageVersion, ophd->MinorImageVersion,
400               ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
401
402         for (i = 0; i < sizeof(special_dlls)/sizeof(special_dlls[0]); i++)
403         {
404             /* test if it is a special dll */
405             if (!strcmpiW(name, special_dlls[i]))
406             {
407                 DWORD DllVersion = VERSION_GetSystemDLLVersion(mod->BaseAddress);
408                 if (WinVersion == NB_WINDOWS_VERSIONS) WinVersion = DllVersion;
409                 else if (WinVersion != DllVersion)
410                 {
411                     ERR("You mixed system DLLs from different windows versions! Expect a crash! (%s: expected version %s, but is %s)\n",
412                         debugstr_w(name),
413                         debugstr_w(VersionData[WinVersion].szCSDVersion),
414                         debugstr_w(VersionData[DllVersion].szCSDVersion));
415                     return WIN20; /* this may let the exe exit */
416                 }
417                 break;
418             }
419         }
420     }
421
422     if(WinVersion != NB_WINDOWS_VERSIONS) return WinVersion;
423
424     /* we are using no external system dlls, look at the exe */
425     nt = RtlImageNtHeader(NtCurrentTeb()->Peb->ImageBaseAddress);
426     ophd = &nt->OptionalHeader;
427
428     TRACE("%02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
429           ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
430           ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
431           ophd->MajorImageVersion, ophd->MinorImageVersion,
432           ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
433
434     /* special nt 3.51 */
435     if (3 == ophd->MajorOperatingSystemVersion && 51 == ophd->MinorOperatingSystemVersion)
436     {
437         return NT351;
438     }
439
440     /* the MajorSubsystemVersion is the only usable sign */
441     if (ophd->MajorSubsystemVersion < 4)
442     {
443         if ( ophd->MajorOperatingSystemVersion == 1
444              && ophd->MinorOperatingSystemVersion == 0)
445         {
446             return WIN31; /* win32s */
447         }
448
449         if (ophd->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
450             return NT351; /* FIXME: NT 3.1, not tested */
451         else
452             return WIN98;
453     }
454
455     switch (ophd->MajorOperatingSystemVersion)
456     {
457     case 5:
458         switch (ophd->MinorOperatingSystemVersion)
459         {
460         case 0 : return NT2K;
461         case 1 : return WINXP;
462         case 2 : return WIN2K3;
463         }
464         break;
465     case 4:
466         switch(ophd->MinorOperatingSystemVersion)
467         {
468         case 90 : return WINME;
469         case 10 : return WIN98;
470         case 0  :
471             switch(ophd->MajorImageVersion)
472             {
473             case 4 : return NT40;
474             case 0 : return WIN95;
475             }
476             break;
477         }
478         break;
479     case 1:
480         if(ophd->MinorOperatingSystemVersion == 0)
481            return WIN95;
482         break;
483     }
484     FIXME("Unknown EXE OS version %d.%d, please report !!\n",
485           ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion );
486     return WIN98;
487 }
488
489 /**********************************************************************
490  *         VERSION_GetVersion
491  *
492  * WARNING !!!
493  * Don't call this function too early during the Wine init,
494  * as pdb->exe_modref (required by VERSION_GetImageVersion()) might still
495  * be NULL in such cases, which causes the winver to ALWAYS be detected
496  * as WIN31.
497  * And as we cache the winver once it has been determined, this is bad.
498  * This can happen much easier than you might think, as this function
499  * is called by EVERY GetVersion*() API !
500  *
501  */
502 static const RTL_OSVERSIONINFOEXW *VERSION_GetVersion(void)
503 {
504     static WORD winver = 0xffff;
505
506     if (versionForced)
507         return &VersionData[forcedWinVersion];  /* user has overridden any sensible checks */
508
509     if (winver == 0xffff) /* to be determined */
510     {
511         WINDOWS_VERSION retver = VERSION_GetLinkedDllVersion();
512
513         /* cache determined value, but do not store in case of WIN31 */
514         if (retver != WIN31) winver = retver;
515         return &VersionData[retver];
516     }
517     return &VersionData[winver];
518 }
519
520
521 /***********************************************************************
522  *         RtlGetVersion   (NTDLL.@)
523  */
524 NTSTATUS WINAPI RtlGetVersion( RTL_OSVERSIONINFOEXW *info )
525 {
526     const RTL_OSVERSIONINFOEXW * const current = VERSION_GetVersion();
527
528     info->dwMajorVersion = current->dwMajorVersion;
529     info->dwMinorVersion = current->dwMinorVersion;
530     info->dwBuildNumber  = current->dwBuildNumber;
531     info->dwPlatformId   = current->dwPlatformId;
532     strcpyW( info->szCSDVersion, current->szCSDVersion );
533     if(info->dwOSVersionInfoSize == sizeof(RTL_OSVERSIONINFOEXW))
534     {
535         info->wServicePackMajor = current->wServicePackMajor;
536         info->wServicePackMinor = current->wServicePackMinor;
537         info->wSuiteMask        = current->wSuiteMask;
538         info->wProductType      = current->wProductType;
539     }
540     TRACE("<-- %s (%s)\n", debug_names[current - VersionData], debugstr_w(current->szCSDVersion) );
541     return STATUS_SUCCESS;
542 }
543
544
545 /******************************************************************************
546  *  RtlGetNtVersionNumbers   (NTDLL.@)
547  *
548  * Get the version numbers of the run time library.
549  *
550  * PARAMS
551  *  major [O] Destination for the Major version
552  *  minor [O] Destination for the Minor version
553  *  build [O] Destination for the Build version
554  *
555  * RETURNS
556  *  Nothing.
557  *
558  * NOTES
559  * Introduced in Windows XP (NT5.1)
560  */
561 void WINAPI RtlGetNtVersionNumbers( LPDWORD major, LPDWORD minor, LPDWORD build )
562 {
563     const RTL_OSVERSIONINFOEXW * const current = VERSION_GetVersion();
564
565     if (major) *major = current->dwMajorVersion;
566     if (minor) *minor = current->dwMinorVersion;
567     /* FIXME: Does anybody know the real formula? */
568     if (build) *build = (0xF0000000 | current->dwBuildNumber);
569 }
570
571
572 /******************************************************************************
573  *        VerifyVersionInfoW   (KERNEL32.@)
574  */
575 NTSTATUS WINAPI RtlVerifyVersionInfo( const RTL_OSVERSIONINFOEXW *info,
576                                       DWORD dwTypeMask, DWORDLONG dwlConditionMask )
577 {
578     RTL_OSVERSIONINFOEXW ver;
579     NTSTATUS status;
580
581     FIXME("(%p,%lu,%llx): Not all cases correctly implemented yet\n",
582           info, dwTypeMask, dwlConditionMask);
583
584     /* FIXME:
585         - Check the following special case on Windows (various versions):
586           o lp->wSuiteMask == 0 and ver.wSuiteMask != 0 and VER_AND/VER_OR
587           o lp->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW)
588         - MSDN talks about some tests being impossible. Check what really happens.
589      */
590
591     ver.dwOSVersionInfoSize = sizeof(ver);
592     if ((status = RtlGetVersion( &ver )) != STATUS_SUCCESS) return status;
593
594     if(!(dwTypeMask && dwlConditionMask)) return STATUS_INVALID_PARAMETER;
595
596     if(dwTypeMask & VER_PRODUCT_TYPE)
597         switch(dwlConditionMask >> 7*3 & 0x07) {
598             case VER_EQUAL:
599                 if(ver.wProductType != info->wProductType) return STATUS_REVISION_MISMATCH;
600                 break;
601             case VER_GREATER:
602                 if(ver.wProductType <= info->wProductType) return STATUS_REVISION_MISMATCH;
603                 break;
604             case VER_GREATER_EQUAL:
605                 if(ver.wProductType < info->wProductType) return STATUS_REVISION_MISMATCH;
606                 break;
607             case VER_LESS:
608                 if(ver.wProductType >= info->wProductType) return STATUS_REVISION_MISMATCH;
609                 break;
610             case VER_LESS_EQUAL:
611                 if(ver.wProductType > info->wProductType) return STATUS_REVISION_MISMATCH;
612                 break;
613             default:
614                 return STATUS_INVALID_PARAMETER;
615         }
616     if(dwTypeMask & VER_SUITENAME)
617         switch(dwlConditionMask >> 6*3 & 0x07)
618         {
619             case VER_AND:
620                 if((info->wSuiteMask & ver.wSuiteMask) != info->wSuiteMask)
621                     return STATUS_REVISION_MISMATCH;
622                 break;
623             case VER_OR:
624                 if(!(info->wSuiteMask & ver.wSuiteMask) && info->wSuiteMask)
625                     return STATUS_REVISION_MISMATCH;
626                 break;
627             default:
628                 return STATUS_INVALID_PARAMETER;
629         }
630     if(dwTypeMask & VER_PLATFORMID)
631         switch(dwlConditionMask >> 3*3 & 0x07)
632         {
633             case VER_EQUAL:
634                 if(ver.dwPlatformId != info->dwPlatformId) return STATUS_REVISION_MISMATCH;
635                 break;
636             case VER_GREATER:
637                 if(ver.dwPlatformId <= info->dwPlatformId) return STATUS_REVISION_MISMATCH;
638                 break;
639             case VER_GREATER_EQUAL:
640                 if(ver.dwPlatformId < info->dwPlatformId) return STATUS_REVISION_MISMATCH;
641                 break;
642             case VER_LESS:
643                 if(ver.dwPlatformId >= info->dwPlatformId) return STATUS_REVISION_MISMATCH;
644                 break;
645             case VER_LESS_EQUAL:
646                 if(ver.dwPlatformId > info->dwPlatformId) return STATUS_REVISION_MISMATCH;
647                 break;
648             default:
649                 return STATUS_INVALID_PARAMETER;
650         }
651     if(dwTypeMask & VER_BUILDNUMBER)
652         switch(dwlConditionMask >> 2*3 & 0x07)
653         {
654             case VER_EQUAL:
655                 if(ver.dwBuildNumber != info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
656                 break;
657             case VER_GREATER:
658                 if(ver.dwBuildNumber <= info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
659                 break;
660             case VER_GREATER_EQUAL:
661                 if(ver.dwBuildNumber < info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
662                 break;
663             case VER_LESS:
664                 if(ver.dwBuildNumber >= info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
665                 break;
666             case VER_LESS_EQUAL:
667                 if(ver.dwBuildNumber > info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
668                 break;
669             default:
670                 return STATUS_INVALID_PARAMETER;
671         }
672     if(dwTypeMask & VER_MAJORVERSION)
673         switch(dwlConditionMask >> 1*3 & 0x07)
674         {
675             case VER_EQUAL:
676                 if(ver.dwMajorVersion != info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
677                 break;
678             case VER_GREATER:
679                 if(ver.dwMajorVersion <= info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
680                 break;
681             case VER_GREATER_EQUAL:
682                 if(ver.dwMajorVersion < info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
683                 break;
684             case VER_LESS:
685                 if(ver.dwMajorVersion >= info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
686                 break;
687             case VER_LESS_EQUAL:
688                 if(ver.dwMajorVersion > info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
689                 break;
690             default:
691                 return STATUS_INVALID_PARAMETER;
692         }
693     if(dwTypeMask & VER_MINORVERSION)
694         switch(dwlConditionMask >> 0*3 & 0x07)
695         {
696             case VER_EQUAL:
697                 if(ver.dwMinorVersion != info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
698                 break;
699             case VER_GREATER:
700                 if(ver.dwMinorVersion <= info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
701                 break;
702             case VER_GREATER_EQUAL:
703                 if(ver.dwMinorVersion < info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
704                 break;
705             case VER_LESS:
706                 if(ver.dwMinorVersion >= info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
707                 break;
708             case VER_LESS_EQUAL:
709                 if(ver.dwMinorVersion > info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
710                 break;
711             default:
712                 return STATUS_INVALID_PARAMETER;
713         }
714     if(dwTypeMask & VER_SERVICEPACKMAJOR)
715         switch(dwlConditionMask >> 5*3 & 0x07)
716         {
717             case VER_EQUAL:
718                 if(ver.wServicePackMajor != info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
719                 break;
720             case VER_GREATER:
721                 if(ver.wServicePackMajor <= info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
722                 break;
723             case VER_GREATER_EQUAL:
724                 if(ver.wServicePackMajor < info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
725                 break;
726             case VER_LESS:
727                 if(ver.wServicePackMajor >= info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
728                 break;
729             case VER_LESS_EQUAL:
730                 if(ver.wServicePackMajor > info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
731                 break;
732             default:
733                 return STATUS_INVALID_PARAMETER;
734         }
735     if(dwTypeMask & VER_SERVICEPACKMINOR)
736         switch(dwlConditionMask >> 4*3 & 0x07)
737         {
738             case VER_EQUAL:
739                 if(ver.wServicePackMinor != info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
740                 break;
741             case VER_GREATER:
742                 if(ver.wServicePackMinor <= info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
743                 break;
744             case VER_GREATER_EQUAL:
745                 if(ver.wServicePackMinor < info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
746                 break;
747             case VER_LESS:
748                 if(ver.wServicePackMinor >= info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
749                 break;
750             case VER_LESS_EQUAL:
751                 if(ver.wServicePackMinor > info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
752                 break;
753             default:
754                 return STATUS_INVALID_PARAMETER;
755         }
756
757     return STATUS_SUCCESS;
758 }