ReactOS 0.4.16-dev-835-gd769f56
version.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/ntdll/rtl/process.c
5 * PURPOSE: Process functions
6 * PROGRAMMER: Ariadne (ariadne@xs4all.nl)
7 * UPDATE HISTORY:
8 * Created 01/11/98
9 */
10
11/* INCLUDES *******************************************************************/
12
13#include <ntdll.h>
14
15#define NDEBUG
16#include <debug.h>
17
18/* FUNCTIONS ******************************************************************/
19
20static signed char g_ReportProductType = 0;
21
22/* HACK: ReactOS specific changes, see bug-reports CORE-6611 and CORE-4620 (aka. #5003) */
23static VOID NTAPI
25{
32 UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\ReactOS\\Settings\\Version");
33 UNICODE_STRING ValName = RTL_CONSTANT_STRING(L"ReportAsWorkstation");
34
36 &KeyName,
38 NULL,
39 NULL);
40
41 /* Don't change anything if the key doesn't exist */
43 if (NT_SUCCESS(Status))
44 {
45 /* Get the value from the registry and make sure it's a 32-bit value */
47 &ValName,
49 kvpInfo,
50 sizeof(Buffer),
51 &Length);
52 if (NT_SUCCESS(Status) &&
53 (kvpInfo->Type == REG_DWORD) &&
54 (kvpInfo->DataLength == sizeof(ULONG)))
55 {
56 ULONG IsWorkstation = SharedUserData->NtProductType == NtProductWinNt;
57 ULONG ReportAsWorkstation = (*(PULONG)kvpInfo->Data) != 0;
58 if (IsWorkstation != ReportAsWorkstation)
59 {
60 g_ReportProductType = ReportAsWorkstation ? NtProductWinNt : NtProductServer;
61 }
62 }
63
64 /* Close the handle */
66 }
67
68 if (g_ReportProductType > 0)
69 {
70 VersionInformation->wProductType = g_ReportProductType;
71 DPRINT("We modified the reported OS product type from %d to %d\n",
72 SharedUserData->NtProductType, VersionInformation->wProductType);
73 }
74 else
75 {
77 }
78}
79
80/**********************************************************************
81 * NAME EXPORTED
82 * RtlGetNtProductType
83 *
84 * DESCRIPTION
85 * Retrieves the OS product type.
86 *
87 * ARGUMENTS
88 * ProductType Pointer to the product type variable.
89 *
90 * RETURN VALUE
91 * TRUE if successful, otherwise FALSE
92 *
93 * NOTE
94 * ProductType can be one of the following values:
95 * 1 Workstation (WinNT)
96 * 2 Server (LanmanNT)
97 * 3 Advanced Server (ServerNT)
98 *
99 * REVISIONS
100 * 2000-08-10 ekohl
101 *
102 * @implemented
103 */
106{
107 *ProductType = SharedUserData->NtProductType;
108
109 if (g_ReportProductType == 0)
110 {
111 /* Initialize cached value */
113 ovi.dwOSVersionInfoSize = sizeof(ovi);
114 ovi.wProductType = *ProductType;
115 SetRosSpecificInfo(&ovi);
116 }
117
118 if (g_ReportProductType > 0)
119 {
120 *ProductType = g_ReportProductType;
121 DPRINT("Overriding RtlGetNtProductType to return %d\n", *ProductType);
122 }
123 return TRUE;
124}
125
126/**********************************************************************
127 * NAME EXPORTED
128 * RtlGetNtVersionNumbers
129 *
130 * DESCRIPTION
131 * Get the version numbers of the run time library.
132 *
133 * ARGUMENTS
134 * pMajorVersion [OUT] Destination for the Major version
135 * pMinorVersion [OUT] Destination for the Minor version
136 * pBuildNumber [OUT] Destination for the Build version
137 *
138 * RETURN VALUE
139 * Nothing.
140 *
141 * NOTES
142 * - Introduced in Windows XP (NT 5.1)
143 * - Since this call didn't exist before XP, we report at least the version
144 * 5.1. This fixes the loading of msvcrt.dll as released with XP Home,
145 * which fails in DLLMain() if the major version isn't 5.
146 *
147 * @implemented
148 */
151 OUT PULONG pMinorVersion,
152 OUT PULONG pBuildNumber)
153{
154 PPEB pPeb = NtCurrentPeb();
155
156 if (pMajorVersion)
157 {
158 *pMajorVersion = pPeb->OSMajorVersion < 5 ? 5 : pPeb->OSMajorVersion;
159 }
160
161 if (pMinorVersion)
162 {
163 if ( (pPeb->OSMajorVersion < 5) ||
164 ((pPeb->OSMajorVersion == 5) && (pPeb->OSMinorVersion < 1)) )
165 *pMinorVersion = 1;
166 else
167 *pMinorVersion = pPeb->OSMinorVersion;
168 }
169
170 if (pBuildNumber)
171 {
172 /* Windows really does this! */
173 *pBuildNumber = (0xF0000000 | pPeb->OSBuildNumber);
174 }
175}
176
177/*
178 * @implemented
179 * @note User-mode version of RtlGetVersion in ntoskrnl/rtl/misc.c
180 */
183{
186
187 if (lpVersionInformation->dwOSVersionInfoSize != sizeof(RTL_OSVERSIONINFOW) &&
188 lpVersionInformation->dwOSVersionInfoSize != sizeof(RTL_OSVERSIONINFOEXW))
189 {
191 }
192
193 lpVersionInformation->dwMajorVersion = Peb->OSMajorVersion;
194 lpVersionInformation->dwMinorVersion = Peb->OSMinorVersion;
195 lpVersionInformation->dwBuildNumber = Peb->OSBuildNumber;
196 lpVersionInformation->dwPlatformId = Peb->OSPlatformId;
197 RtlZeroMemory(lpVersionInformation->szCSDVersion, sizeof(lpVersionInformation->szCSDVersion));
198
199 /* If we have a CSD version string, initialized by Application Compatibility... */
201 {
202 /* ... copy it... */
203 Length = min(wcslen(Peb->CSDVersion.Buffer), ARRAYSIZE(lpVersionInformation->szCSDVersion) - 1);
204 wcsncpy(lpVersionInformation->szCSDVersion, Peb->CSDVersion.Buffer, Length);
205 }
206 else
207 {
208 /* ... otherwise we just null-terminate it */
209 Length = 0;
210 }
211
212 /* Always null-terminate the user CSD version string */
213 lpVersionInformation->szCSDVersion[Length] = UNICODE_NULL;
214
215 if (lpVersionInformation->dwOSVersionInfoSize == sizeof(RTL_OSVERSIONINFOEXW))
216 {
217 PRTL_OSVERSIONINFOEXW InfoEx = (PRTL_OSVERSIONINFOEXW)lpVersionInformation;
218 InfoEx->wServicePackMajor = (Peb->OSCSDVersion >> 8) & 0xFF;
219 InfoEx->wServicePackMinor = Peb->OSCSDVersion & 0xFF;
220 InfoEx->wSuiteMask = SharedUserData->SuiteMask & 0xFFFF;
221 InfoEx->wProductType = SharedUserData->NtProductType;
222 InfoEx->wReserved = 0;
223
224 /* HACK: ReactOS specific changes, see bug-reports CORE-6611 and CORE-4620 (aka. #5003) */
225 SetRosSpecificInfo(InfoEx);
226 }
227
228 return STATUS_SUCCESS;
229}
230
231/* EOF */
#define NtCurrentPeb()
Definition: FLS.c:22
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
wcsncpy
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
static signed char g_ReportProductType
Definition: version.c:20
BOOLEAN NTAPI RtlGetNtProductType(_Out_ PNT_PRODUCT_TYPE ProductType)
Definition: version.c:105
static VOID NTAPI SetRosSpecificInfo(IN OUT PRTL_OSVERSIONINFOEXW VersionInformation)
Definition: version.c:24
NTSTATUS NTAPI RtlGetVersion(IN OUT PRTL_OSVERSIONINFOW lpVersionInformation)
Definition: version.c:182
VOID NTAPI RtlGetNtVersionNumbers(OUT PULONG pMajorVersion, OUT PULONG pMinorVersion, OUT PULONG pBuildNumber)
Definition: version.c:150
PPEB Peb
Definition: dllmain.c:27
enum _NT_PRODUCT_TYPE * PNT_PRODUCT_TYPE
@ NtProductWinNt
Definition: shellpath.c:64
@ NtProductServer
Definition: shellpath.c:66
FxAutoRegKey hKey
Status
Definition: gdiplustypes.h:25
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define OBJ_OPENIF
Definition: winternl.h:229
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define min(a, b)
Definition: monoChain.cc:55
#define _Out_
Definition: no_sal2.h:160
NTSYSAPI NTSTATUS NTAPI NtOpenKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: ntapi.c:336
@ KeyValuePartialInformation
Definition: nt_native.h:1182
#define KEY_READ
Definition: nt_native.h:1023
NTSYSAPI NTSTATUS NTAPI NtQueryValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass, IN PVOID KeyValueInformation, IN ULONG Length, IN PULONG ResultLength)
struct _KEY_VALUE_PARTIAL_INFORMATION KEY_VALUE_PARTIAL_INFORMATION
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
#define UNICODE_NULL
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define L(x)
Definition: ntvdm.h:50
#define REG_DWORD
Definition: sdbapi.c:596
#define SharedUserData
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:269
USHORT wServicePackMinor
Definition: rtltypes.h:276
UCHAR wProductType
Definition: rtltypes.h:278
USHORT wSuiteMask
Definition: rtltypes.h:277
USHORT wServicePackMajor
Definition: rtltypes.h:275
UNICODE_STRING CSDVersion
Definition: winternl.h:353
ULONG OSMinorVersion
Definition: ntddk_ex.h:301
ULONG OSMajorVersion
Definition: ntddk_ex.h:300
ULONG OSBuildNumber
Definition: ntddk_ex.h:302
ULONG OSPlatformId
Definition: ntddk_ex.h:303
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
void * PVOID
Definition: typedefs.h:50
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699
struct _OSVERSIONINFOEXW * PRTL_OSVERSIONINFOEXW
char CHAR
Definition: xmlstorage.h:175