ReactOS  0.4.12-dev-685-gf36cbf7
SystemInfo.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS api tests
3  * LICENSE: GPL - See COPYING in the top level directory
4  * PURPOSE: Test for NtQuery/SetSystemInformation
5  * PROGRAMMERS: Timo Kreuzer
6  * Thomas Faber <thomas.faber@reactos.org>
7  */
8 
9 #include "precomp.h"
10 
11 #define ntv6(x) (LOBYTE(LOWORD(GetVersion())) >= 6 ? (x) : 0)
12 
13 static
14 void
16 {
19  ULONG Flags;
20  ULONG Buffer[2];
21  ULONG Buffer2[2];
23  BOOLEAN PrivilegeEnabled;
24 
25  /* Query */
26  ReturnLength = 0x55555555;
28  ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtQuerySystemInformation returned %lx\n", Status);
29  ok(ReturnLength == 0 ||
30  ntv6(ReturnLength == sizeof(SYSTEM_FLAGS_INFORMATION)), "ReturnLength = %lu\n", ReturnLength);
31 
32  ReturnLength = 0x55555555;
34  ok(Status == STATUS_ACCESS_VIOLATION, "NtQuerySystemInformation returned %lx\n", Status);
35  ok(ReturnLength == 0x55555555, "ReturnLength = %lu\n", ReturnLength);
36 
37  ReturnLength = 0x55555555;
39  ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtQuerySystemInformation returned %lx\n", Status);
40  ok(ReturnLength == 0 ||
41  ntv6(ReturnLength == sizeof(SYSTEM_FLAGS_INFORMATION)), "ReturnLength = %lu\n", ReturnLength);
42 
43  ReturnLength = 0x55555555;
45  ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtQuerySystemInformation returned %lx\n", Status);
46  ok(ReturnLength == 0 ||
47  ntv6(ReturnLength == sizeof(SYSTEM_FLAGS_INFORMATION)), "ReturnLength = %lu\n", ReturnLength);
48 
49  ReturnLength = 0x55555555;
50  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
52  ok(Status == STATUS_DATATYPE_MISALIGNMENT, "NtQuerySystemInformation returned %lx\n", Status);
53  ok(ReturnLength == 0x55555555, "ReturnLength = %lu\n", ReturnLength);
54  ok(Buffer[0] == 0x55555555, "Buffer[0] = %lx\n", Buffer[0]);
55  ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
56 
57  ReturnLength = 0x55555555;
58  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
60  ok(Status == STATUS_DATATYPE_MISALIGNMENT, "NtQuerySystemInformation returned %lx\n", Status);
61  ok(ReturnLength == 0x55555555, "ReturnLength = %lu\n", ReturnLength);
62  ok(Buffer[0] == 0x55555555, "Buffer[0] = %lx\n", Buffer[0]);
63  ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
64 
65  ReturnLength = 0x55555555;
66  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
68  ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtQuerySystemInformation returned %lx\n", Status);
69  ok(ReturnLength == 0 ||
70  ntv6(ReturnLength == sizeof(SYSTEM_FLAGS_INFORMATION)), "ReturnLength = %lu\n", ReturnLength);
71  ok(Buffer[0] == 0x55555555, "Buffer[0] = %lx\n", Buffer[0]);
72  ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
73 
74  ReturnLength = 0x55555555;
75  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
77  ok(Status == STATUS_SUCCESS, "NtQuerySystemInformation returned %lx\n", Status);
78  ok(ReturnLength == sizeof(SYSTEM_FLAGS_INFORMATION), "ReturnLength = %lu\n", ReturnLength);
79  ok(FlagsInfo->Flags != 0x55555555, "Flags = %lx\n", FlagsInfo->Flags);
80  ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
81  Flags = FlagsInfo->Flags;
82 
83  ReturnLength = 0x55555555;
84  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
86  ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtQuerySystemInformation returned %lx\n", Status);
87  ok(ReturnLength == 0 ||
88  ntv6(ReturnLength == sizeof(SYSTEM_FLAGS_INFORMATION)), "ReturnLength = %lu\n", ReturnLength);
89  ok(Buffer[0] == 0x55555555, "Buffer[0] = %lx\n", Buffer[0]);
90  ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
91 
92  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
94  ok(Status == STATUS_SUCCESS, "NtQuerySystemInformation returned %lx\n", Status);
95  ok(FlagsInfo->Flags == Flags, "Flags = %lx, expected %lx\n", FlagsInfo->Flags, Flags);
96  ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
97 
98  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
100  ok(Status == STATUS_ACCESS_VIOLATION, "NtQuerySystemInformation returned %lx\n", Status);
101  ok(Buffer[0] == 0x55555555, "Buffer[0] = %lx\n", Buffer[0]);
102  ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
103 
104  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
106  ok(Status == STATUS_ACCESS_VIOLATION, "NtQuerySystemInformation returned %lx\n", Status);
107  ok(Buffer[0] == 0x55555555, "Buffer[0] = %lx\n", Buffer[0]);
108  ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
109 
110  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
112  ok(Status == STATUS_ACCESS_VIOLATION, "NtQuerySystemInformation returned %lx\n", Status);
113  ok(Buffer[0] == 0x55555555, "Buffer[0] = %lx\n", Buffer[0]);
114  ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
115 
116  RtlFillMemory(Buffer2, sizeof(Buffer2), 0x55);
117  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
119  ok(Status == STATUS_SUCCESS, "NtQuerySystemInformation returned %lx\n", Status);
120  ok(FlagsInfo->Flags == Flags, "Flags = %lx, expected %lx\n", FlagsInfo->Flags, Flags);
121  ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
122  ok(Buffer2[0] == 0x00000455, "Buffer2[0] = %lx\n", Buffer2[0]);
123  ok(Buffer2[1] == 0x55555500, "Buffer2[1] = %lx\n", Buffer2[1]);
124 
125  /* Set */
127  ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtSetSystemInformation returned %lx\n", Status);
128 
130  ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtSetSystemInformation returned %lx\n", Status);
131 
133  ok(Status == STATUS_ACCESS_DENIED, "NtSetSystemInformation returned %lx\n", Status);
134 
136  ok(Status == STATUS_DATATYPE_MISALIGNMENT, "NtSetSystemInformation returned %lx\n", Status);
137 
138  Status = RtlAdjustPrivilege(SE_DEBUG_PRIVILEGE, TRUE, FALSE, &PrivilegeEnabled);
139  if (!NT_SUCCESS(Status))
140  {
141  skip("Cannot acquire SeDebugPrivilege\n");
142  return;
143  }
144 
146  ok(Status == STATUS_ACCESS_VIOLATION, "NtSetSystemInformation returned %lx\n", Status);
147 
149  ok(Status == STATUS_DATATYPE_MISALIGNMENT, "NtSetSystemInformation returned %lx\n", Status);
150 
152  ok(Status == STATUS_ACCESS_VIOLATION, "NtSetSystemInformation returned %lx\n", Status);
153 
154  FlagsInfo->Flags = Flags;
156  ok(Status == STATUS_DATATYPE_MISALIGNMENT, "NtSetSystemInformation returned %lx\n", Status);
157 
159  ok(Status == STATUS_DATATYPE_MISALIGNMENT, "NtSetSystemInformation returned %lx\n", Status);
160 
162  ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtSetSystemInformation returned %lx\n", Status);
163 
165  ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtSetSystemInformation returned %lx\n", Status);
166 
168  ok(Status == STATUS_SUCCESS, "NtSetSystemInformation returned %lx\n", Status);
169 
170  ok(FlagsInfo->Flags == Flags, "Flags = %lx, expected %lu\n", FlagsInfo->Flags, Flags);
171 
172  Status = RtlAdjustPrivilege(SE_DEBUG_PRIVILEGE, PrivilegeEnabled, FALSE, &PrivilegeEnabled);
173  ok(Status == STATUS_SUCCESS, "RtlAdjustPrivilege returned %lx\n", Status);
174 }
175 
176 static
177 void
179 {
180  SYSTEM_QUERY_TIME_ADJUST_INFORMATION TimeInfoOrg, GetTimeInfo;
184  BOOLEAN PrivilegeEnabled;
185 
186  SetTimeInfo.TimeAdjustment = 0;
187  SetTimeInfo.Enable = 0;
188 
189  /* Query original values */
191  &TimeInfoOrg,
192  sizeof(TimeInfoOrg),
193  &ReturnLength);
194 
195  /* Test without privilege */
197  &SetTimeInfo,
198  sizeof(SetTimeInfo));
200 
201  /* Get the required privilege */
203  if (!NT_SUCCESS(Status))
204  {
205  skip("Cannot acquire SeSystemTimePrivilege\n");
206  return;
207  }
208 
209  /* Test wrong length */
211  &SetTimeInfo,
212  sizeof(SetTimeInfo) + 1);
214 
215  /* Test both members 0 */
217  &SetTimeInfo,
218  sizeof(SetTimeInfo));
220 
221  /* Set huge value */
222  SetTimeInfo.TimeAdjustment = -1;
223  SetTimeInfo.Enable = 0;
225  &SetTimeInfo,
226  sizeof(SetTimeInfo));
228 
229  /* Query the result */
231  &GetTimeInfo,
232  sizeof(GetTimeInfo),
233  &ReturnLength);
235  ok_long(GetTimeInfo.TimeAdjustment, -1);
236  ok_long(GetTimeInfo.Enable, 0);
237 
238  /* set Enable to 1 */
239  SetTimeInfo.TimeAdjustment = -1;
240  SetTimeInfo.Enable = 1;
242  &SetTimeInfo,
243  sizeof(SetTimeInfo));
245 
246  /* Query the result */
248  &GetTimeInfo,
249  sizeof(GetTimeInfo),
250  &ReturnLength);
252  ok_long(GetTimeInfo.TimeAdjustment, GetTimeInfo.TimeIncrement);
253  ok_long(GetTimeInfo.Enable, 1);
254 
255  /* Restore original values */
256  SetTimeInfo.TimeAdjustment = TimeInfoOrg.TimeAdjustment;
257  SetTimeInfo.Enable = TimeInfoOrg.Enable;
259  &SetTimeInfo,
260  sizeof(SetTimeInfo));
262 
263  Status = RtlAdjustPrivilege(SE_SYSTEMTIME_PRIVILEGE, PrivilegeEnabled, FALSE, &PrivilegeEnabled);
264  ok(Status == STATUS_SUCCESS, "RtlAdjustPrivilege returned %lx\n", Status);
265 }
266 
267 static
268 void
270 {
273  ULONG Buffer[2];
275 
276  /* Query */
277  ReturnLength = 0x55555555;
279  ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtQuerySystemInformation returned %lx\n", Status);
280  ok(ReturnLength == 0 ||
281  ntv6(ReturnLength == sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION)), "ReturnLength = %lu\n", ReturnLength);
282 
283  ReturnLength = 0x55555555;
284  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
286  ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtQuerySystemInformation returned %lx\n", Status);
287  ok(ReturnLength == 0 ||
288  ntv6(ReturnLength == sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION)), "ReturnLength = %lu\n", ReturnLength);
289  ok(Buffer[0] == 0x55555555, "Buffer[0] = %lx\n", Buffer[0]);
290  ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
291 
292  ReturnLength = 0x55555555;
293  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
295  ok(Status == STATUS_SUCCESS, "NtQuerySystemInformation returned %lx\n", Status);
296  ok(ReturnLength == sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION), "ReturnLength = %lu\n", ReturnLength);
297  ok((Buffer[0] & 0x55fefe55) == 0x55000055, "Buffer[0] = %lx\n", Buffer[0]);
298  ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
299 
300  ReturnLength = 0x55555555;
301  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
303  ok(Status == STATUS_SUCCESS, "NtQuerySystemInformation returned %lx\n", Status);
304  ok(ReturnLength == sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION), "ReturnLength = %lu\n", ReturnLength);
305  ok(DebuggerInfo->KernelDebuggerEnabled == FALSE ||
306  DebuggerInfo->KernelDebuggerEnabled == TRUE, "KernelDebuggerEnabled = %u\n", DebuggerInfo->KernelDebuggerEnabled);
307  ok(DebuggerInfo->KernelDebuggerNotPresent == FALSE ||
308  DebuggerInfo->KernelDebuggerNotPresent == TRUE, "KernelDebuggerNotPresent = %u\n", DebuggerInfo->KernelDebuggerNotPresent);
309 
310  /* Set - not supported */
311  DebuggerInfo->KernelDebuggerEnabled = FALSE;
312  DebuggerInfo->KernelDebuggerNotPresent = TRUE;
314  ok(Status == STATUS_INVALID_INFO_CLASS, "NtSetSystemInformation returned %lx\n", Status);
315 }
316 
317 START_TEST(NtSystemInformation)
318 {
321 
323  ok(Status == STATUS_INVALID_INFO_CLASS, "NtQuerySystemInformation returned %lx\n", Status);
324 
325  Status = NtQuerySystemInformation(9999, NULL, 0, (PVOID)1);
327  ntv6(Status == STATUS_INVALID_INFO_CLASS), "NtQuerySystemInformation returned %lx\n", Status);
328 
329  ReturnLength = 0x55555555;
331  ok(Status == STATUS_INVALID_INFO_CLASS, "NtQuerySystemInformation returned %lx\n", Status);
332  ok(ReturnLength == 0 ||
333  ntv6(ReturnLength == 0x55555555), "ReturnLength = %lu\n", ReturnLength);
334 
335  ReturnLength = 0x55555555;
338  ntv6(Status == STATUS_INVALID_INFO_CLASS), "NtQuerySystemInformation returned %lx\n", Status);
339  ok(ReturnLength == 0x55555555, "ReturnLength = %lu\n", ReturnLength);
340 
341  ReturnLength = 0x55555555;
344  ntv6(Status == STATUS_INVALID_INFO_CLASS), "NtQuerySystemInformation returned %lx\n", Status);
345  ok(ReturnLength == 0x55555555, "ReturnLength = %lu\n", ReturnLength);
346 
347  Status = NtQuerySystemInformation(9999, NULL, 1, (PVOID)1);
349  ntv6(Status == STATUS_INVALID_INFO_CLASS), "NtQuerySystemInformation returned %lx\n", Status);
350 
351  Status = NtQuerySystemInformation(9999, (PVOID)1, 1, (PVOID)1);
353  ntv6(Status == STATUS_INVALID_INFO_CLASS), "NtQuerySystemInformation returned %lx\n", Status);
354 
355  Test_Flags();
358 }
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:39
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
#define TRUE
Definition: types.h:120
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
static void Test_Flags(void)
Definition: SystemInfo.c:15
#define ntv6(x)
Definition: SystemInfo.c:11
unsigned char * PUCHAR
Definition: retypes.h:3
#define SE_DEBUG_PRIVILEGE
Definition: security.c:674
LONG NTSTATUS
Definition: precomp.h:26
#define SE_SYSTEMTIME_PRIVILEGE
Definition: security.c:666
NTSYSAPI NTSTATUS NTAPI RtlAdjustPrivilege(_In_ ULONG Privilege, _In_ BOOLEAN NewValue, _In_ BOOLEAN ForThread, _Out_ PBOOLEAN OldValue)
static void Test_TimeAdjustment(void)
Definition: SystemInfo.c:178
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_INVALID_PARAMETER_2
Definition: ntstatus.h:462
Definition: bufpool.h:45
#define ok_ntstatus(status, expected)
Definition: test.h:800
void * PVOID
Definition: retypes.h:9
NTSYSAPI NTSTATUS NTAPI NtSetSystemInformation(IN INT SystemInformationClass, IN PVOID SystemInformation, IN ULONG SystemInformationLength)
#define ok(value,...)
Definition: CComObject.cpp:34
START_TEST(NtSystemInformation)
Definition: SystemInfo.c:317
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
static void Test_KernelDebugger(void)
Definition: SystemInfo.c:269
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define STATUS_INVALID_INFO_CLASS
Definition: ntstatus.h:226
Status
Definition: gdiplustypes.h:24
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
#define skip(...)
Definition: CString.cpp:57
unsigned int * PULONG
Definition: retypes.h:1
#define ok_long(expression, result)
Definition: test.h:798
#define STATUS_DATATYPE_MISALIGNMENT
Definition: ntstatus.h:171
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2725
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593