ReactOS  0.4.15-dev-5487-ge7bbbf0
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;
76  LONG Result;
77  HKEY Key;
78  DWORD dwSize;
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);
118  RegCloseKey(Key);
119  return FALSE;
120  }
121 
122  RegCloseKey(Key);
123  return TRUE;
124 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define TRUE
Definition: types.h:120
uint16_t * PWSTR
Definition: typedefs.h:56
#define DWORD
Definition: nt_native.h:44
#define L(x)
Definition: ntvdm.h:50
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
_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:426
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFKEY * Key
Definition: wdfdevice.h:2654
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:4899
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define ok(value,...)
Definition: atltest.h:57
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3356
BYTE * PBYTE
Definition: pedump.c:66
#define RegCloseKey(hKey)
Definition: registry.h:47
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define REG_SZ
Definition: layer.c:22

Referenced by START_TEST().

◆ ReturnNtProduct()

static BOOLEAN ReturnNtProduct ( PDWORD  ProductNtType)
static

Definition at line 14 of file RtlGetNtProductType.c.

15 {
16  LONG Result;
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 ERROR_SUCCESS
Definition: deptool.c:10
#define TRUE
Definition: types.h:120
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG _In_opt_ PVOID Data
Definition: wdfdevice.h:4527
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define L(x)
Definition: ntvdm.h:50
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
_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:426
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFKEY * Key
Definition: wdfdevice.h:2654
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4120
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define NULL
Definition: types.h:112
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3356
BYTE * PBYTE
Definition: pedump.c:66
#define RegCloseKey(hKey)
Definition: registry.h:47
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

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  /*
133  * Wrap the call in SEH. This ensures the testcase won't crash but also
134  * it proves to us that RtlGetNtProductType() throws an exception if a NULL
135  * argument is being passed to caller as output.
136  */
137  StartSeh()
140 
141  /* Query the product type normally from the Registry */
142  Ret = ReturnNtProduct(&ProductNtType);
143  if (!Ret)
144  {
145  ok(Ret, "Failed to query the product type value!\n");
146  }
147 
148  /* Now, get the product type from the NTDLL system call */
149  Ret = RtlGetNtProductType(&ProductType);
150  ok(Ret == TRUE, "Expected a valid product type value (and TRUE as returned success code) but got %u as status.\n", Ret);
151  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);
152 
153  /* Change product type in the registry */
155  ok_char(RtlGetNtProductType(&ProductType2), TRUE);
156  ok_long(ProductType2, ProductType);
157 
159  ok_char(RtlGetNtProductType(&ProductType2), TRUE);
160  ok_long(ProductType2, ProductType);
161 
163  ok_char(RtlGetNtProductType(&ProductType2), TRUE);
164  ok_long(ProductType2, ProductType);
165 
166  ok_char(ChangeNtProductType(ProductType), TRUE);
167 }
#define TRUE
Definition: types.h:120
if(dx==0 &&dy==0)
Definition: linetemp.h:174
#define ok_long(expression, result)
Definition: atltest.h:133
#define StartSeh()
Definition: _sntprintf.h:16
static BOOLEAN ReturnNtProduct(PDWORD ProductNtType)
unsigned char BOOLEAN
#define ok_char(expression, result)
Definition: atltest.h:122
BOOLEAN NTAPI RtlGetNtProductType(_Out_ PNT_PRODUCT_TYPE ProductType)
Definition: version.c:96
static BOOLEAN ChangeNtProductType(DWORD NtProductType)
unsigned long DWORD
Definition: ntddk_ex.h:95
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
enum _NT_PRODUCT_TYPE NT_PRODUCT_TYPE
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17