ReactOS  0.4.15-dev-313-g8fde48b
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 #include <versionhelpers.h>
11 
12 #define ntv6(x) (LOBYTE(LOWORD(GetVersion())) >= 6 ? (x) : 0)
13 
14 static
15 void
17 {
20  ULONG Flags;
21  ULONG Buffer[2];
22  ULONG Buffer2[2];
24  BOOLEAN PrivilegeEnabled;
25 
26  /* Make sure we don't have debug privileges initially, otherwise WHS testbot fails */
28  ok(Status == STATUS_SUCCESS, "RtlAdjustPrivilege returned %lx\n", Status);
29 
30  /* Query */
31  ReturnLength = 0x55555555;
33  ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtQuerySystemInformation returned %lx\n", Status);
34  ok(ReturnLength == 0 ||
35  ntv6(ReturnLength == sizeof(SYSTEM_FLAGS_INFORMATION)), "ReturnLength = %lu\n", ReturnLength);
36 
37  ReturnLength = 0x55555555;
39  ok(Status == STATUS_ACCESS_VIOLATION, "NtQuerySystemInformation returned %lx\n", Status);
40  ok(ReturnLength == 0x55555555, "ReturnLength = %lu\n", ReturnLength);
41 
42  ReturnLength = 0x55555555;
44  ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtQuerySystemInformation returned %lx\n", Status);
45  ok(ReturnLength == 0 ||
46  ntv6(ReturnLength == sizeof(SYSTEM_FLAGS_INFORMATION)), "ReturnLength = %lu\n", ReturnLength);
47 
48  ReturnLength = 0x55555555;
50  ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtQuerySystemInformation returned %lx\n", Status);
51  ok(ReturnLength == 0 ||
52  ntv6(ReturnLength == sizeof(SYSTEM_FLAGS_INFORMATION)), "ReturnLength = %lu\n", ReturnLength);
53 
54  ReturnLength = 0x55555555;
55  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
57  ok(Status == STATUS_DATATYPE_MISALIGNMENT, "NtQuerySystemInformation returned %lx\n", Status);
58  ok(ReturnLength == 0x55555555, "ReturnLength = %lu\n", ReturnLength);
59  ok(Buffer[0] == 0x55555555, "Buffer[0] = %lx\n", Buffer[0]);
60  ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
61 
62  ReturnLength = 0x55555555;
63  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
65  ok(Status == STATUS_DATATYPE_MISALIGNMENT, "NtQuerySystemInformation returned %lx\n", Status);
66  ok(ReturnLength == 0x55555555, "ReturnLength = %lu\n", ReturnLength);
67  ok(Buffer[0] == 0x55555555, "Buffer[0] = %lx\n", Buffer[0]);
68  ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
69 
70  ReturnLength = 0x55555555;
71  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
73  ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtQuerySystemInformation returned %lx\n", Status);
74  ok(ReturnLength == 0 ||
75  ntv6(ReturnLength == sizeof(SYSTEM_FLAGS_INFORMATION)), "ReturnLength = %lu\n", ReturnLength);
76  ok(Buffer[0] == 0x55555555, "Buffer[0] = %lx\n", Buffer[0]);
77  ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
78 
79  ReturnLength = 0x55555555;
80  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
82  ok(Status == STATUS_SUCCESS, "NtQuerySystemInformation returned %lx\n", Status);
83  ok(ReturnLength == sizeof(SYSTEM_FLAGS_INFORMATION), "ReturnLength = %lu\n", ReturnLength);
84  ok(FlagsInfo->Flags != 0x55555555, "Flags = %lx\n", FlagsInfo->Flags);
85  ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
86  Flags = FlagsInfo->Flags;
87 
88  ReturnLength = 0x55555555;
89  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
91  ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtQuerySystemInformation returned %lx\n", Status);
92  ok(ReturnLength == 0 ||
93  ntv6(ReturnLength == sizeof(SYSTEM_FLAGS_INFORMATION)), "ReturnLength = %lu\n", ReturnLength);
94  ok(Buffer[0] == 0x55555555, "Buffer[0] = %lx\n", Buffer[0]);
95  ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
96 
97  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
99  ok(Status == STATUS_SUCCESS, "NtQuerySystemInformation returned %lx\n", Status);
100  ok(FlagsInfo->Flags == Flags, "Flags = %lx, expected %lx\n", FlagsInfo->Flags, Flags);
101  ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
102 
103  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
105  ok(Status == STATUS_ACCESS_VIOLATION, "NtQuerySystemInformation returned %lx\n", Status);
106  ok(Buffer[0] == 0x55555555, "Buffer[0] = %lx\n", Buffer[0]);
107  ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
108 
109  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
111  ok(Status == STATUS_ACCESS_VIOLATION, "NtQuerySystemInformation returned %lx\n", Status);
112  ok(Buffer[0] == 0x55555555, "Buffer[0] = %lx\n", Buffer[0]);
113  ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
114 
115  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
117  ok(Status == STATUS_ACCESS_VIOLATION, "NtQuerySystemInformation returned %lx\n", Status);
118  ok(Buffer[0] == 0x55555555, "Buffer[0] = %lx\n", Buffer[0]);
119  ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
120 
121  RtlFillMemory(Buffer2, sizeof(Buffer2), 0x55);
122  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
124  ok(Status == STATUS_SUCCESS, "NtQuerySystemInformation returned %lx\n", Status);
125  ok(FlagsInfo->Flags == Flags, "Flags = %lx, expected %lx\n", FlagsInfo->Flags, Flags);
126  ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
127  ok(Buffer2[0] == 0x00000455, "Buffer2[0] = %lx\n", Buffer2[0]);
128  ok(Buffer2[1] == 0x55555500, "Buffer2[1] = %lx\n", Buffer2[1]);
129 
130  /* Set */
132  ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtSetSystemInformation returned %lx\n", Status);
133 
135  ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtSetSystemInformation returned %lx\n", Status);
136 
138  ok(Status == (IsWindows7OrGreater() ? STATUS_ACCESS_DENIED : STATUS_ACCESS_VIOLATION), "NtSetSystemInformation returned %lx\n", Status);
139 
141  ok(Status == STATUS_DATATYPE_MISALIGNMENT, "NtSetSystemInformation returned %lx\n", Status);
142 
143  Status = RtlAdjustPrivilege(SE_DEBUG_PRIVILEGE, TRUE, FALSE, &PrivilegeEnabled);
144  if (!NT_SUCCESS(Status))
145  {
146  skip("Cannot acquire SeDebugPrivilege\n");
147  return;
148  }
149 
151  ok(Status == STATUS_ACCESS_VIOLATION, "NtSetSystemInformation returned %lx\n", Status);
152 
154  ok(Status == STATUS_DATATYPE_MISALIGNMENT, "NtSetSystemInformation returned %lx\n", Status);
155 
157  ok(Status == STATUS_ACCESS_VIOLATION, "NtSetSystemInformation returned %lx\n", Status);
158 
159  FlagsInfo->Flags = Flags;
161  ok(Status == STATUS_DATATYPE_MISALIGNMENT, "NtSetSystemInformation returned %lx\n", Status);
162 
164  ok(Status == STATUS_DATATYPE_MISALIGNMENT, "NtSetSystemInformation returned %lx\n", Status);
165 
167  ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtSetSystemInformation returned %lx\n", Status);
168 
170  ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtSetSystemInformation returned %lx\n", Status);
171 
173  ok(Status == STATUS_SUCCESS, "NtSetSystemInformation returned %lx\n", Status);
174 
175  ok(FlagsInfo->Flags == Flags, "Flags = %lx, expected %lu\n", FlagsInfo->Flags, Flags);
176 
177  Status = RtlAdjustPrivilege(SE_DEBUG_PRIVILEGE, PrivilegeEnabled, FALSE, &PrivilegeEnabled);
178  ok(Status == STATUS_SUCCESS, "RtlAdjustPrivilege returned %lx\n", Status);
179 }
180 
181 static
182 void
184 {
185  SYSTEM_QUERY_TIME_ADJUST_INFORMATION TimeInfoOrg, GetTimeInfo;
189  BOOLEAN PrivilegeEnabled;
190 
191  /* Make sure we don't have debug privileges initially, otherwise WHS testbot fails */
193  ok(Status == STATUS_SUCCESS, "RtlAdjustPrivilege returned %lx\n", Status);
194 
195  SetTimeInfo.TimeAdjustment = 0;
196  SetTimeInfo.Enable = 0;
197 
198  /* Query original values */
200  &TimeInfoOrg,
201  sizeof(TimeInfoOrg),
202  &ReturnLength);
203 
204  /* Test without privilege */
206  &SetTimeInfo,
207  sizeof(SetTimeInfo));
209 
210  /* Get the required privilege */
212  if (!NT_SUCCESS(Status))
213  {
214  skip("Cannot acquire SeSystemTimePrivilege\n");
215  return;
216  }
217 
218  /* Test wrong length */
220  &SetTimeInfo,
221  sizeof(SetTimeInfo) + 1);
223 
224  /* Test both members 0 */
226  &SetTimeInfo,
227  sizeof(SetTimeInfo));
229 
230  /* Set huge value */
231  SetTimeInfo.TimeAdjustment = -1;
232  SetTimeInfo.Enable = 0;
234  &SetTimeInfo,
235  sizeof(SetTimeInfo));
237 
238  /* Query the result */
240  &GetTimeInfo,
241  sizeof(GetTimeInfo),
242  &ReturnLength);
244  ok_long(GetTimeInfo.TimeAdjustment, IsWindows7OrGreater() ? 0x7076cc : -1);
245  ok_long(GetTimeInfo.Enable, 0);
246 
247  /* set Enable to 1 */
248  SetTimeInfo.TimeAdjustment = -1;
249  SetTimeInfo.Enable = 1;
251  &SetTimeInfo,
252  sizeof(SetTimeInfo));
254 
255  /* Query the result */
257  &GetTimeInfo,
258  sizeof(GetTimeInfo),
259  &ReturnLength);
261  ok_long(GetTimeInfo.TimeAdjustment, GetTimeInfo.TimeIncrement);
262  ok_long(GetTimeInfo.Enable, 1);
263 
264  /* Restore original values */
265  SetTimeInfo.TimeAdjustment = TimeInfoOrg.TimeAdjustment;
266  SetTimeInfo.Enable = TimeInfoOrg.Enable;
268  &SetTimeInfo,
269  sizeof(SetTimeInfo));
271 
272  Status = RtlAdjustPrivilege(SE_SYSTEMTIME_PRIVILEGE, PrivilegeEnabled, FALSE, &PrivilegeEnabled);
273  ok(Status == STATUS_SUCCESS, "RtlAdjustPrivilege returned %lx\n", Status);
274 }
275 
276 static
277 void
279 {
282  ULONG Buffer[2];
284 
285  /* Query */
286  ReturnLength = 0x55555555;
288  ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtQuerySystemInformation returned %lx\n", Status);
289  ok(ReturnLength == 0 ||
290  ntv6(ReturnLength == sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION)), "ReturnLength = %lu\n", ReturnLength);
291 
292  ReturnLength = 0x55555555;
293  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
295  ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtQuerySystemInformation returned %lx\n", Status);
296  ok(ReturnLength == 0 ||
297  ntv6(ReturnLength == sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION)), "ReturnLength = %lu\n", ReturnLength);
298  ok(Buffer[0] == 0x55555555, "Buffer[0] = %lx\n", Buffer[0]);
299  ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
300 
301  ReturnLength = 0x55555555;
302  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
304  ok(Status == STATUS_SUCCESS, "NtQuerySystemInformation returned %lx\n", Status);
305  ok(ReturnLength == sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION), "ReturnLength = %lu\n", ReturnLength);
306  ok((Buffer[0] & 0x55fefe55) == 0x55000055, "Buffer[0] = %lx\n", Buffer[0]);
307  ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
308 
309  ReturnLength = 0x55555555;
310  RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
312  ok(Status == STATUS_SUCCESS, "NtQuerySystemInformation returned %lx\n", Status);
313  ok(ReturnLength == sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION), "ReturnLength = %lu\n", ReturnLength);
314  ok(DebuggerInfo->KernelDebuggerEnabled == FALSE ||
315  DebuggerInfo->KernelDebuggerEnabled == TRUE, "KernelDebuggerEnabled = %u\n", DebuggerInfo->KernelDebuggerEnabled);
316  ok(DebuggerInfo->KernelDebuggerNotPresent == FALSE ||
317  DebuggerInfo->KernelDebuggerNotPresent == TRUE, "KernelDebuggerNotPresent = %u\n", DebuggerInfo->KernelDebuggerNotPresent);
318 
319  /* Set - not supported */
320  DebuggerInfo->KernelDebuggerEnabled = FALSE;
321  DebuggerInfo->KernelDebuggerNotPresent = TRUE;
323  ok(Status == STATUS_INVALID_INFO_CLASS, "NtSetSystemInformation returned %lx\n", Status);
324 }
325 
326 START_TEST(NtSystemInformation)
327 {
330 
332  ok(Status == STATUS_INVALID_INFO_CLASS, "NtQuerySystemInformation returned %lx\n", Status);
333 
334  Status = NtQuerySystemInformation(9999, NULL, 0, (PVOID)1);
336  ntv6(Status == STATUS_INVALID_INFO_CLASS), "NtQuerySystemInformation returned %lx\n", Status);
337 
338  ReturnLength = 0x55555555;
340  ok(Status == STATUS_INVALID_INFO_CLASS, "NtQuerySystemInformation returned %lx\n", Status);
341  ok(ReturnLength == 0 ||
342  ntv6(ReturnLength == 0x55555555), "ReturnLength = %lu\n", ReturnLength);
343 
344  ReturnLength = 0x55555555;
347  ntv6(Status == STATUS_INVALID_INFO_CLASS), "NtQuerySystemInformation returned %lx\n", Status);
348  ok(ReturnLength == 0x55555555, "ReturnLength = %lu\n", ReturnLength);
349 
350  ReturnLength = 0x55555555;
353  ntv6(Status == STATUS_INVALID_INFO_CLASS), "NtQuerySystemInformation returned %lx\n", Status);
354  ok(ReturnLength == 0x55555555, "ReturnLength = %lu\n", ReturnLength);
355 
356  Status = NtQuerySystemInformation(9999, NULL, 1, (PVOID)1);
358  ntv6(Status == STATUS_INVALID_INFO_CLASS), "NtQuerySystemInformation returned %lx\n", Status);
359 
360  Status = NtQuerySystemInformation(9999, (PVOID)1, 1, (PVOID)1);
362  ntv6(Status == STATUS_INVALID_INFO_CLASS), "NtQuerySystemInformation returned %lx\n", Status);
363 
364  Test_Flags();
367 }
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:16
#define ntv6(x)
Definition: SystemInfo.c:12
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)
#define ok_long(expression, result)
Definition: atltest.h:133
static void Test_TimeAdjustment(void)
Definition: SystemInfo.c:183
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define STATUS_INTEGER_DIVIDE_BY_ZERO
Definition: ntstatus.h:370
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_INVALID_PARAMETER_2
Definition: ntstatus.h:462
Definition: bufpool.h:45
void * PVOID
Definition: retypes.h:9
NTSYSAPI NTSTATUS NTAPI NtSetSystemInformation(IN INT SystemInformationClass, IN PVOID SystemInformation, IN ULONG SystemInformationLength)
START_TEST(NtSystemInformation)
Definition: SystemInfo.c:326
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
static void Test_KernelDebugger(void)
Definition: SystemInfo.c:278
#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 ok(value,...)
Definition: atltest.h:57
unsigned int * PULONG
Definition: retypes.h:1
#define skip(...)
Definition: atltest.h:64
VERSIONHELPERAPI IsWindows7OrGreater()
#define ok_ntstatus(status, expected)
Definition: atltest.h:135
#define STATUS_DATATYPE_MISALIGNMENT
Definition: ntstatus.h:171
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:3014