1 /*
2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Kernel mode tests for object information querying
5 * COPYRIGHT: Copyright 2023 George Bișoc <george.bisoc@reactos.org>
6 */
7
8 #include <kmt_test.h>
9
10 #define OBJ_WINSTA_DIRECTORY_NAME_INFO_SIZE (sizeof(UNICODE_STRING) + sizeof(L"\\Windows"))
11 #define OBJ_DIRECTORY_TYPE_INFO_SIZE (sizeof(OBJECT_TYPE_INFORMATION) + sizeof(L"Directory"))
12
13 static
14 VOID
ObjectBasicInformationTests(VOID)15 ObjectBasicInformationTests(VOID)
16 {
17 NTSTATUS Status;
18 HANDLE WinStaDirHandle;
19 OBJECT_BASIC_INFORMATION BasicInfo;
20 ULONG ReturnLength;
21 OBJECT_ATTRIBUTES ObjectAttributes;
22 static UNICODE_STRING WinStaDir = RTL_CONSTANT_STRING(L"\\Windows");
23
24 /* We must be in PASSIVE_LEVEL to do all of this stuff */
25 ok_irql(PASSIVE_LEVEL);
26
27 /* Create a path to \Windows directory */
28 InitializeObjectAttributes(&ObjectAttributes,
29 &WinStaDir,
30 OBJ_CASE_INSENSITIVE | OBJ_OPENIF | OBJ_KERNEL_HANDLE,
31 NULL,
32 NULL);
33 Status = ZwOpenDirectoryObject(&WinStaDirHandle,
34 DIRECTORY_QUERY | DIRECTORY_TRAVERSE,
35 &ObjectAttributes);
36 if (!NT_SUCCESS(Status))
37 {
38 ok(FALSE, "Failed to open \\Windows directory (Status 0x%lx)\n", Status);
39 return;
40 }
41
42 /* Give 0 as information length, this must fail */
43 Status = ZwQueryObject(WinStaDirHandle,
44 ObjectBasicInformation,
45 &BasicInfo,
46 0,
47 &ReturnLength);
48 ok_eq_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
49
50 /* Do a proper query now */
51 Status = ZwQueryObject(WinStaDirHandle,
52 ObjectBasicInformation,
53 &BasicInfo,
54 sizeof(BasicInfo),
55 &ReturnLength);
56 ok_eq_hex(Status, STATUS_SUCCESS);
57
58 /* \Windows is currently used */
59 ok(BasicInfo.HandleCount != 0, "\\Windows is in use but HandleCount is 0!\n");
60 ok(BasicInfo.PointerCount != 0, "\\Windows is in use but PointerCount is 0!\n");
61
62 ok_eq_ulong(BasicInfo.NameInfoSize, OBJ_WINSTA_DIRECTORY_NAME_INFO_SIZE);
63 ok_eq_ulong(BasicInfo.TypeInfoSize, OBJ_DIRECTORY_TYPE_INFO_SIZE);
64
65 ZwClose(WinStaDirHandle);
66 }
67
START_TEST(ObQuery)68 START_TEST(ObQuery)
69 {
70 ObjectBasicInformationTests();
71 }
72