ReactOS 0.4.16-dev-975-g3b8cfa4
RtlGetNtProductType.c File Reference
#include "precomp.h"
#include <winbase.h>
#include <winreg.h>
Include dependency graph for RtlGetNtProductType.c:

Go to the source code of this file.

Functions

static BOOLEAN ReturnNtProduct (PDWORD ProductNtType)
 
static BOOLEAN ChangeNtProductType (DWORD NtProductType)
 
 START_TEST (RtlGetNtProductType)
 

Function Documentation

◆ ChangeNtProductType()

static BOOLEAN ChangeNtProductType ( DWORD  NtProductType)
static

Definition at line 73 of file RtlGetNtProductType.c.

74{
75 PWSTR ProductTypeString;
77 HKEY Key;
79
80 if (NtProductType == NtProductWinNt)
81 {
82 ProductTypeString = L"WinNT";
83 }
84 else if (NtProductType == NtProductLanManNt)
85 {
86 ProductTypeString = L"LanmanNT";
87 }
88 else if (NtProductType == NtProductServer)
89 {
90 ProductTypeString = L"ServerNT";
91 }
92 else
93 {
94 ok(FALSE, "Passed invalid product type to ChangeNtProduct: %lu", NtProductType);
95 }
96
98 L"SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
99 0,
101 &Key);
102 if (Result != ERROR_SUCCESS)
103 {
104 ok(FALSE, "RegOpenKeyExW failed with 0x%lx\n", Result);
105 return FALSE;
106 }
107
108 dwSize = ((DWORD)wcslen(ProductTypeString) + 1) * sizeof(WCHAR);
110 L"ProductType",
111 0,
112 REG_SZ,
113 (PBYTE)ProductTypeString,
114 dwSize);
115 if (Result != ERROR_SUCCESS)
116 {
117 ok(FALSE, "RegSetValueExW failed with 0x%lx\n", Result);
119 return FALSE;
120 }
121
123 return TRUE;
124}
#define ok(value,...)
Definition: atltest.h:57
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4882
@ NtProductWinNt
Definition: shellpath.c:64
@ NtProductLanManNt
Definition: shellpath.c:65
@ NtProductServer
Definition: shellpath.c:66
unsigned long DWORD
Definition: ntddk_ex.h:95
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define REG_SZ
Definition: layer.c:22
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define DWORD
Definition: nt_native.h:44
#define L(x)
Definition: ntvdm.h:50
BYTE * PBYTE
Definition: pedump.c:66
long LONG
Definition: pedump.c:60
uint16_t * PWSTR
Definition: typedefs.h:56
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by START_TEST().

◆ ReturnNtProduct()

static BOOLEAN ReturnNtProduct ( PDWORD  ProductNtType)
static

Definition at line 14 of file RtlGetNtProductType.c.

15{
17 HKEY Key;
18 WCHAR Data[20];
19 DWORD Size = sizeof(Data);
20
22 L"SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
23 0,
25 &Key);
26 if (Result != ERROR_SUCCESS)
27 {
28 *ProductNtType = 0;
29 return FALSE;
30 }
31
33 L"ProductType",
34 NULL,
35 NULL,
36 (PBYTE)&Data,
37 &Size);
38 if (Result != ERROR_SUCCESS)
39 {
41 *ProductNtType = 0;
42 return FALSE;
43 }
44
45 if (wcscmp(Data, L"WinNT") == 0)
46 {
47 *ProductNtType = NtProductWinNt;
49 return TRUE;
50 }
51
52 if (wcscmp(Data, L"LanmanNT") == 0)
53 {
54 *ProductNtType = NtProductLanManNt;
56 return TRUE;
57 }
58
59 if (wcscmp(Data, L"ServerNT") == 0)
60 {
61 *ProductNtType = NtProductServer;
63 return TRUE;
64 }
65
66 *ProductNtType = 0;
68 return FALSE;
69}
#define NULL
Definition: types.h:112
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( RtlGetNtProductType  )

Definition at line 126 of file RtlGetNtProductType.c.

127{
128 BOOLEAN Ret;
129 DWORD ProductNtType;
130 NT_PRODUCT_TYPE ProductType = NtProductWinNt, ProductType2;
131
132 /* Remove ReportAsWorkstation override during tests */
133 DWORD ReportAsWorkstation = 0xbaadf00d;
134 HKEY hKey;
135 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\ReactOS\\Settings\\Version",
137 {
138 DWORD cb = sizeof(DWORD);
139 if (RegQueryValueExW(hKey, L"ReportAsWorkstation", NULL, NULL, (PBYTE)&ReportAsWorkstation, &cb))
140 ReportAsWorkstation = 0xbaadf00d;
141 RegDeleteValueW(hKey, L"ReportAsWorkstation");
143 }
144
145 /*
146 * Wrap the call in SEH. This ensures the testcase won't crash but also
147 * it proves to us that RtlGetNtProductType() throws an exception if a NULL
148 * argument is being passed to caller as output.
149 */
150 StartSeh()
153
154 /* Query the product type normally from the Registry */
155 Ret = ReturnNtProduct(&ProductNtType);
156 if (!Ret)
157 {
158 ok(Ret, "Failed to query the product type value!\n");
159 }
160
161 /* Now, get the product type from the NTDLL system call */
162 Ret = RtlGetNtProductType(&ProductType);
163 ok(Ret == TRUE, "Expected a valid product type value (and TRUE as returned success code) but got %u as status.\n", Ret);
164 ok(ProductNtType == ProductType, "Expected the product type value to be the same but got %lu (original value pointed by RtlGetNtProductType() is %d).\n", ProductNtType, ProductType);
165
166 /* Change product type in the registry */
168 ok_char(RtlGetNtProductType(&ProductType2), TRUE);
169 ok_long(ProductType2, ProductType);
170
172 ok_char(RtlGetNtProductType(&ProductType2), TRUE);
173 ok_long(ProductType2, ProductType);
174
176 ok_char(RtlGetNtProductType(&ProductType2), TRUE);
177 ok_long(ProductType2, ProductType);
178
179 ok_char(ChangeNtProductType(ProductType), TRUE);
180
181
182 /* Restore ReportAsWorkstation */
183 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\ReactOS\\Settings\\Version",
185 {
186 if (ReportAsWorkstation != 0xbaadf00d)
187 RegSetValueExW(hKey, L"ReportAsWorkstation", 0, REG_DWORD, (PBYTE)&ReportAsWorkstation, sizeof(DWORD));
189 }
190}
unsigned char BOOLEAN
static BOOLEAN ChangeNtProductType(DWORD NtProductType)
static BOOLEAN ReturnNtProduct(PDWORD ProductNtType)
#define StartSeh()
Definition: _sntprintf.h:16
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17
#define ok_long(expression, result)
Definition: atltest.h:133
#define ok_char(expression, result)
Definition: atltest.h:122
BOOLEAN NTAPI RtlGetNtProductType(_Out_ PNT_PRODUCT_TYPE ProductType)
Definition: version.c:105
LONG WINAPI RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName)
Definition: reg.c:2330
enum _NT_PRODUCT_TYPE NT_PRODUCT_TYPE
FxAutoRegKey hKey
if(dx< 0)
Definition: linetemp.h:194
static HMODULE MODULEINFO DWORD cb
Definition: module.c:33
#define KEY_READ
Definition: nt_native.h:1023
#define KEY_WRITE
Definition: nt_native.h:1031
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define REG_DWORD
Definition: sdbapi.c:596