2012-09-20 19:53:14 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
2005-09-08 00:09:32 +00:00
|
|
|
* PROJECT: ReactOS system libraries
|
|
|
|
* PURPOSE: Runtime code
|
|
|
|
* FILE: lib/rtl/version.c
|
2012-09-20 20:46:08 +00:00
|
|
|
* PROGRAMERS: Filip Navara
|
2012-11-01 12:52:34 +00:00
|
|
|
* Hermes Belusca-Maito (hermes.belusca@sfr.fr)
|
2004-05-31 19:33:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
2005-06-17 07:57:37 +00:00
|
|
|
|
2005-07-26 08:39:07 +00:00
|
|
|
#include <rtl.h>
|
2004-05-31 19:33:59 +00:00
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2004-08-05 18:17:37 +00:00
|
|
|
/* GLOBALS ******************************************************************/
|
|
|
|
|
2005-03-29 15:22:44 +00:00
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2012-11-01 12:52:34 +00:00
|
|
|
RtlGetVersion(OUT PRTL_OSVERSIONINFOW lpVersionInformation);
|
2004-05-31 19:33:59 +00:00
|
|
|
|
|
|
|
/* FUNCTIONS ****************************************************************/
|
|
|
|
|
2015-03-16 03:14:16 +00:00
|
|
|
static UCHAR
|
|
|
|
RtlpVerGetCondition(IN ULONGLONG ConditionMask,
|
|
|
|
IN ULONG TypeMask);
|
2012-09-20 20:46:08 +00:00
|
|
|
|
2012-09-20 19:53:14 +00:00
|
|
|
static BOOLEAN
|
2015-03-16 03:14:16 +00:00
|
|
|
RtlpVerCompare(ULONG left, ULONG right, UCHAR Condition)
|
2008-07-23 11:19:01 +00:00
|
|
|
{
|
2015-03-16 03:14:16 +00:00
|
|
|
switch (Condition)
|
2012-09-20 19:53:14 +00:00
|
|
|
{
|
2008-07-23 11:19:01 +00:00
|
|
|
case VER_EQUAL:
|
2012-09-20 19:53:14 +00:00
|
|
|
return (left == right);
|
2008-07-23 11:19:01 +00:00
|
|
|
case VER_GREATER:
|
2012-09-20 19:53:14 +00:00
|
|
|
return (left > right);
|
2008-07-23 11:19:01 +00:00
|
|
|
case VER_GREATER_EQUAL:
|
2012-09-20 19:53:14 +00:00
|
|
|
return (left >= right);
|
2008-07-23 11:19:01 +00:00
|
|
|
case VER_LESS:
|
2012-09-20 19:53:14 +00:00
|
|
|
return (left < right);
|
2008-07-23 11:19:01 +00:00
|
|
|
case VER_LESS_EQUAL:
|
2012-09-20 19:53:14 +00:00
|
|
|
return (left <= right);
|
2008-07-23 11:19:01 +00:00
|
|
|
default:
|
2012-09-20 19:53:14 +00:00
|
|
|
break;
|
2008-07-23 11:19:01 +00:00
|
|
|
}
|
2012-09-20 19:53:14 +00:00
|
|
|
return FALSE;
|
2008-07-23 11:19:01 +00:00
|
|
|
}
|
|
|
|
|
2004-08-05 18:17:37 +00:00
|
|
|
/*
|
2005-03-29 15:22:44 +00:00
|
|
|
* @implemented
|
2004-08-05 18:17:37 +00:00
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2012-11-01 12:52:34 +00:00
|
|
|
RtlVerifyVersionInfo(IN PRTL_OSVERSIONINFOEXW VersionInfo,
|
|
|
|
IN ULONG TypeMask,
|
|
|
|
IN ULONGLONG ConditionMask)
|
2004-08-05 18:17:37 +00:00
|
|
|
{
|
2016-08-30 15:10:07 +00:00
|
|
|
RTL_OSVERSIONINFOEXW Version;
|
2015-03-16 03:14:16 +00:00
|
|
|
BOOLEAN Comparison;
|
2016-08-30 15:10:07 +00:00
|
|
|
BOOLEAN DoNextCheck;
|
|
|
|
NTSTATUS Status;
|
|
|
|
UCHAR Condition;
|
2005-03-29 15:22:44 +00:00
|
|
|
|
|
|
|
/* FIXME:
|
|
|
|
- Check the following special case on Windows (various versions):
|
|
|
|
o lp->wSuiteMask == 0 and ver.wSuiteMask != 0 and VER_AND/VER_OR
|
|
|
|
o lp->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW)
|
|
|
|
- MSDN talks about some tests being impossible. Check what really happens.
|
|
|
|
*/
|
|
|
|
|
2016-08-30 15:10:07 +00:00
|
|
|
Version.dwOSVersionInfoSize = sizeof(Version);
|
2005-03-29 15:22:44 +00:00
|
|
|
|
2016-08-30 15:10:07 +00:00
|
|
|
Status = RtlGetVersion((PRTL_OSVERSIONINFOW)&Version);
|
|
|
|
if (Status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!TypeMask || !ConditionMask)
|
|
|
|
{
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
2005-03-29 15:22:44 +00:00
|
|
|
|
2012-09-20 19:53:14 +00:00
|
|
|
if (TypeMask & VER_PRODUCT_TYPE)
|
2008-07-23 11:19:01 +00:00
|
|
|
{
|
2016-08-30 15:10:07 +00:00
|
|
|
Comparison = RtlpVerCompare(Version.wProductType,
|
2012-09-20 19:53:14 +00:00
|
|
|
VersionInfo->wProductType,
|
2012-09-20 20:46:08 +00:00
|
|
|
RtlpVerGetCondition(ConditionMask, VER_PRODUCT_TYPE));
|
2015-03-16 03:14:16 +00:00
|
|
|
if (!Comparison)
|
2016-08-30 15:10:07 +00:00
|
|
|
{
|
2012-09-20 19:53:14 +00:00
|
|
|
return STATUS_REVISION_MISMATCH;
|
2016-08-30 15:10:07 +00:00
|
|
|
}
|
2008-07-23 11:19:01 +00:00
|
|
|
}
|
2012-09-20 19:53:14 +00:00
|
|
|
|
|
|
|
if (TypeMask & VER_SUITENAME)
|
2008-07-23 11:19:01 +00:00
|
|
|
{
|
2012-09-20 20:46:08 +00:00
|
|
|
switch (RtlpVerGetCondition(ConditionMask, VER_SUITENAME))
|
2005-03-29 15:22:44 +00:00
|
|
|
{
|
|
|
|
case VER_AND:
|
2016-08-30 15:10:07 +00:00
|
|
|
{
|
|
|
|
if ((VersionInfo->wSuiteMask & Version.wSuiteMask) != VersionInfo->wSuiteMask)
|
2012-09-20 19:53:14 +00:00
|
|
|
{
|
2005-03-29 15:22:44 +00:00
|
|
|
return STATUS_REVISION_MISMATCH;
|
2012-09-20 19:53:14 +00:00
|
|
|
}
|
2016-08-30 15:10:07 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-03-29 15:22:44 +00:00
|
|
|
case VER_OR:
|
2016-08-30 15:10:07 +00:00
|
|
|
{
|
|
|
|
if (!(VersionInfo->wSuiteMask & Version.wSuiteMask) && VersionInfo->wSuiteMask)
|
2012-09-20 19:53:14 +00:00
|
|
|
{
|
2005-03-29 15:22:44 +00:00
|
|
|
return STATUS_REVISION_MISMATCH;
|
2012-09-20 19:53:14 +00:00
|
|
|
}
|
2005-03-29 15:22:44 +00:00
|
|
|
break;
|
2016-08-30 15:10:07 +00:00
|
|
|
}
|
|
|
|
|
2005-03-29 15:22:44 +00:00
|
|
|
default:
|
2016-08-30 15:10:07 +00:00
|
|
|
{
|
2005-03-29 15:22:44 +00:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
2016-08-30 15:10:07 +00:00
|
|
|
}
|
2005-03-29 15:22:44 +00:00
|
|
|
}
|
2008-07-23 11:19:01 +00:00
|
|
|
}
|
2012-09-20 19:53:14 +00:00
|
|
|
|
|
|
|
if (TypeMask & VER_PLATFORMID)
|
2008-07-23 11:19:01 +00:00
|
|
|
{
|
2016-08-30 15:10:07 +00:00
|
|
|
Comparison = RtlpVerCompare(Version.dwPlatformId,
|
2012-09-20 19:53:14 +00:00
|
|
|
VersionInfo->dwPlatformId,
|
2012-09-20 20:46:08 +00:00
|
|
|
RtlpVerGetCondition(ConditionMask, VER_PLATFORMID));
|
2015-03-16 03:14:16 +00:00
|
|
|
if (!Comparison)
|
2016-08-30 15:10:07 +00:00
|
|
|
{
|
2012-09-20 19:53:14 +00:00
|
|
|
return STATUS_REVISION_MISMATCH;
|
2016-08-30 15:10:07 +00:00
|
|
|
}
|
2008-07-23 11:19:01 +00:00
|
|
|
}
|
2012-09-20 19:53:14 +00:00
|
|
|
|
|
|
|
if (TypeMask & VER_BUILDNUMBER)
|
2008-07-23 11:19:01 +00:00
|
|
|
{
|
2016-08-30 15:10:07 +00:00
|
|
|
Comparison = RtlpVerCompare(Version.dwBuildNumber,
|
2012-09-20 19:53:14 +00:00
|
|
|
VersionInfo->dwBuildNumber,
|
2012-09-20 20:46:08 +00:00
|
|
|
RtlpVerGetCondition(ConditionMask, VER_BUILDNUMBER));
|
2015-03-16 03:14:16 +00:00
|
|
|
if (!Comparison)
|
2016-08-30 15:10:07 +00:00
|
|
|
{
|
2012-09-20 19:53:14 +00:00
|
|
|
return STATUS_REVISION_MISMATCH;
|
2016-08-30 15:10:07 +00:00
|
|
|
}
|
2008-07-23 11:19:01 +00:00
|
|
|
}
|
2012-09-20 19:53:14 +00:00
|
|
|
|
2016-08-30 15:10:07 +00:00
|
|
|
DoNextCheck = TRUE;
|
|
|
|
Condition = VER_EQUAL;
|
|
|
|
|
|
|
|
if (TypeMask & VER_MAJORVERSION)
|
2008-07-23 11:19:01 +00:00
|
|
|
{
|
2016-08-30 15:10:07 +00:00
|
|
|
Condition = RtlpVerGetCondition(ConditionMask, VER_MAJORVERSION);
|
|
|
|
DoNextCheck = (VersionInfo->dwMajorVersion == Version.dwMajorVersion);
|
|
|
|
Comparison = RtlpVerCompare(Version.dwMajorVersion,
|
|
|
|
VersionInfo->dwMajorVersion,
|
|
|
|
Condition);
|
|
|
|
|
|
|
|
if (!Comparison && !DoNextCheck)
|
2005-03-29 15:22:44 +00:00
|
|
|
{
|
2016-08-30 15:10:07 +00:00
|
|
|
return STATUS_REVISION_MISMATCH;
|
2005-03-29 15:22:44 +00:00
|
|
|
}
|
2016-08-30 15:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (DoNextCheck)
|
|
|
|
{
|
|
|
|
if (TypeMask & VER_MINORVERSION)
|
2005-03-29 15:22:44 +00:00
|
|
|
{
|
2016-08-30 15:10:07 +00:00
|
|
|
if (Condition == VER_EQUAL)
|
|
|
|
{
|
2021-06-11 12:29:21 +00:00
|
|
|
Condition = RtlpVerGetCondition(ConditionMask, VER_MINORVERSION);
|
2016-08-30 15:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DoNextCheck = (VersionInfo->dwMinorVersion == Version.dwMinorVersion);
|
|
|
|
Comparison = RtlpVerCompare(Version.dwMinorVersion,
|
2012-09-20 19:53:14 +00:00
|
|
|
VersionInfo->dwMinorVersion,
|
2015-03-16 03:14:16 +00:00
|
|
|
Condition);
|
2016-08-30 15:10:07 +00:00
|
|
|
|
|
|
|
if (!Comparison && !DoNextCheck)
|
|
|
|
{
|
|
|
|
return STATUS_REVISION_MISMATCH;
|
|
|
|
}
|
2005-03-29 15:22:44 +00:00
|
|
|
}
|
2016-08-30 15:10:07 +00:00
|
|
|
|
|
|
|
if (DoNextCheck && (TypeMask & VER_SERVICEPACKMAJOR))
|
2005-03-29 15:22:44 +00:00
|
|
|
{
|
2016-08-30 15:10:07 +00:00
|
|
|
if (Condition == VER_EQUAL)
|
|
|
|
{
|
2021-06-11 12:29:21 +00:00
|
|
|
Condition = RtlpVerGetCondition(ConditionMask, VER_SERVICEPACKMAJOR);
|
2016-08-30 15:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DoNextCheck = (VersionInfo->wServicePackMajor == Version.wServicePackMajor);
|
|
|
|
Comparison = RtlpVerCompare(Version.wServicePackMajor,
|
2012-09-20 19:53:14 +00:00
|
|
|
VersionInfo->wServicePackMajor,
|
2015-03-16 03:14:16 +00:00
|
|
|
Condition);
|
2005-03-29 15:22:44 +00:00
|
|
|
|
2016-08-30 15:10:07 +00:00
|
|
|
if (!Comparison && !DoNextCheck)
|
|
|
|
{
|
|
|
|
return STATUS_REVISION_MISMATCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DoNextCheck && (TypeMask & VER_SERVICEPACKMINOR))
|
|
|
|
{
|
|
|
|
if (Condition == VER_EQUAL)
|
|
|
|
{
|
2021-06-11 12:29:21 +00:00
|
|
|
Condition = RtlpVerGetCondition(ConditionMask, VER_SERVICEPACKMINOR);
|
2016-08-30 15:10:07 +00:00
|
|
|
}
|
|
|
|
|
2016-08-30 16:28:47 +00:00
|
|
|
Comparison = RtlpVerCompare(Version.wServicePackMinor,
|
|
|
|
VersionInfo->wServicePackMinor,
|
2016-08-30 15:10:07 +00:00
|
|
|
Condition);
|
|
|
|
|
|
|
|
if (!Comparison)
|
|
|
|
{
|
|
|
|
return STATUS_REVISION_MISMATCH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-07-23 11:19:01 +00:00
|
|
|
}
|
|
|
|
|
2005-03-29 15:22:44 +00:00
|
|
|
return STATUS_SUCCESS;
|
2004-08-05 18:17:37 +00:00
|
|
|
}
|
2005-03-29 15:22:44 +00:00
|
|
|
|
2015-03-16 03:14:16 +00:00
|
|
|
static UCHAR
|
|
|
|
RtlpVerGetCondition(IN ULONGLONG ConditionMask,
|
|
|
|
IN ULONG TypeMask)
|
2012-09-20 20:46:08 +00:00
|
|
|
{
|
2015-03-16 03:14:16 +00:00
|
|
|
UCHAR Condition = 0;
|
|
|
|
|
|
|
|
if (TypeMask & VER_PRODUCT_TYPE)
|
|
|
|
Condition |= ConditionMask >> (7 * VER_NUM_BITS_PER_CONDITION_MASK);
|
|
|
|
else if (TypeMask & VER_SUITENAME)
|
|
|
|
Condition |= ConditionMask >> (6 * VER_NUM_BITS_PER_CONDITION_MASK);
|
|
|
|
else if (TypeMask & VER_PLATFORMID)
|
|
|
|
Condition |= ConditionMask >> (3 * VER_NUM_BITS_PER_CONDITION_MASK);
|
|
|
|
else if (TypeMask & VER_BUILDNUMBER)
|
|
|
|
Condition |= ConditionMask >> (2 * VER_NUM_BITS_PER_CONDITION_MASK);
|
2012-09-20 20:46:08 +00:00
|
|
|
/*
|
|
|
|
* We choose here the lexicographical order on the 4D space
|
|
|
|
* {(Major ; Minor ; SP Major ; SP Minor)} to select the
|
|
|
|
* appropriate comparison operator.
|
|
|
|
* Therefore the following 'else if' instructions must be in this order.
|
|
|
|
*/
|
2015-03-16 03:14:16 +00:00
|
|
|
else if (TypeMask & VER_MAJORVERSION)
|
|
|
|
Condition |= ConditionMask >> (1 * VER_NUM_BITS_PER_CONDITION_MASK);
|
|
|
|
else if (TypeMask & VER_MINORVERSION)
|
|
|
|
Condition |= ConditionMask >> (0 * VER_NUM_BITS_PER_CONDITION_MASK);
|
|
|
|
else if (TypeMask & VER_SERVICEPACKMAJOR)
|
|
|
|
Condition |= ConditionMask >> (5 * VER_NUM_BITS_PER_CONDITION_MASK);
|
|
|
|
else if (TypeMask & VER_SERVICEPACKMINOR)
|
|
|
|
Condition |= ConditionMask >> (4 * VER_NUM_BITS_PER_CONDITION_MASK);
|
|
|
|
|
|
|
|
Condition &= VER_CONDITION_MASK;
|
|
|
|
|
|
|
|
return Condition;
|
2012-09-20 20:46:08 +00:00
|
|
|
}
|
|
|
|
|
2004-11-07 18:45:52 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2012-09-19 12:20:39 +00:00
|
|
|
ULONGLONG
|
|
|
|
NTAPI
|
2015-03-16 03:14:16 +00:00
|
|
|
VerSetConditionMask(IN ULONGLONG ConditionMask,
|
|
|
|
IN ULONG TypeMask,
|
|
|
|
IN UCHAR Condition)
|
2004-11-07 18:45:52 +00:00
|
|
|
{
|
2012-12-17 12:06:14 +00:00
|
|
|
ULONGLONG ullCondMask;
|
|
|
|
|
2015-03-16 03:14:16 +00:00
|
|
|
if (TypeMask == 0)
|
|
|
|
return ConditionMask;
|
|
|
|
|
|
|
|
Condition &= VER_CONDITION_MASK;
|
|
|
|
|
|
|
|
if (Condition == 0)
|
|
|
|
return ConditionMask;
|
|
|
|
|
|
|
|
ullCondMask = Condition;
|
|
|
|
if (TypeMask & VER_PRODUCT_TYPE)
|
|
|
|
ConditionMask |= ullCondMask << (7 * VER_NUM_BITS_PER_CONDITION_MASK);
|
|
|
|
else if (TypeMask & VER_SUITENAME)
|
|
|
|
ConditionMask |= ullCondMask << (6 * VER_NUM_BITS_PER_CONDITION_MASK);
|
|
|
|
else if (TypeMask & VER_SERVICEPACKMAJOR)
|
|
|
|
ConditionMask |= ullCondMask << (5 * VER_NUM_BITS_PER_CONDITION_MASK);
|
|
|
|
else if (TypeMask & VER_SERVICEPACKMINOR)
|
|
|
|
ConditionMask |= ullCondMask << (4 * VER_NUM_BITS_PER_CONDITION_MASK);
|
|
|
|
else if (TypeMask & VER_PLATFORMID)
|
|
|
|
ConditionMask |= ullCondMask << (3 * VER_NUM_BITS_PER_CONDITION_MASK);
|
|
|
|
else if (TypeMask & VER_BUILDNUMBER)
|
|
|
|
ConditionMask |= ullCondMask << (2 * VER_NUM_BITS_PER_CONDITION_MASK);
|
|
|
|
else if (TypeMask & VER_MAJORVERSION)
|
|
|
|
ConditionMask |= ullCondMask << (1 * VER_NUM_BITS_PER_CONDITION_MASK);
|
|
|
|
else if (TypeMask & VER_MINORVERSION)
|
|
|
|
ConditionMask |= ullCondMask << (0 * VER_NUM_BITS_PER_CONDITION_MASK);
|
|
|
|
|
|
|
|
return ConditionMask;
|
2004-11-07 18:45:52 +00:00
|
|
|
}
|
|
|
|
|
2004-05-31 19:33:59 +00:00
|
|
|
/* EOF */
|