ReactOS 0.4.16-dev-555-g690643f
ObQuery.c File Reference
#include <kmt_test.h>
Include dependency graph for ObQuery.c:

Go to the source code of this file.

Macros

#define OBJ_WINSTA_DIRECTORY_NAME_INFO_SIZE   (sizeof(UNICODE_STRING) + sizeof(L"\\Windows"))
 
#define OBJ_DIRECTORY_TYPE_INFO_SIZE   (sizeof(OBJECT_TYPE_INFORMATION) + sizeof(L"Directory"))
 
#define FILE_SHARE_ALL    (FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE)
 
#define ok_ntstatus   ok_eq_hex
 

Functions

static VOID ObjectBasicInformationTests (VOID)
 
static VOID ObjectNameInformationTests (VOID)
 
 START_TEST (ObQuery)
 

Macro Definition Documentation

◆ FILE_SHARE_ALL

Definition at line 71 of file ObQuery.c.

◆ OBJ_DIRECTORY_TYPE_INFO_SIZE

#define OBJ_DIRECTORY_TYPE_INFO_SIZE   (sizeof(OBJECT_TYPE_INFORMATION) + sizeof(L"Directory"))

Definition at line 12 of file ObQuery.c.

◆ OBJ_WINSTA_DIRECTORY_NAME_INFO_SIZE

#define OBJ_WINSTA_DIRECTORY_NAME_INFO_SIZE   (sizeof(UNICODE_STRING) + sizeof(L"\\Windows"))

Definition at line 11 of file ObQuery.c.

◆ ok_ntstatus

#define ok_ntstatus   ok_eq_hex

Definition at line 74 of file ObQuery.c.

Function Documentation

◆ ObjectBasicInformationTests()

static VOID ObjectBasicInformationTests ( VOID  )
static

Definition at line 16 of file ObQuery.c.

17{
19 HANDLE WinStaDirHandle;
23 static UNICODE_STRING WinStaDir = RTL_CONSTANT_STRING(L"\\Windows");
24
25 /* We must be in PASSIVE_LEVEL to do all of this stuff */
26 ok_irql(PASSIVE_LEVEL);
27
28 /* Create a path to \Windows directory */
30 &WinStaDir,
32 NULL,
33 NULL);
34 Status = ZwOpenDirectoryObject(&WinStaDirHandle,
37 if (!NT_SUCCESS(Status))
38 {
39 ok(FALSE, "Failed to open \\Windows directory (Status 0x%lx)\n", Status);
40 return;
41 }
42
43 /* Give 0 as information length, this must fail */
44 Status = ZwQueryObject(WinStaDirHandle,
46 &BasicInfo,
47 0,
50
51 /* Do a proper query now */
52 Status = ZwQueryObject(WinStaDirHandle,
54 &BasicInfo,
55 sizeof(BasicInfo),
58
59 /* \Windows is currently used */
60 ok(BasicInfo.HandleCount != 0, "\\Windows is in use but HandleCount is 0!\n");
61 ok(BasicInfo.PointerCount != 0, "\\Windows is in use but PointerCount is 0!\n");
62
65
66 ZwClose(WinStaDirHandle);
67}
@ ObjectBasicInformation
Definition: DriverTester.h:54
#define OBJ_WINSTA_DIRECTORY_NAME_INFO_SIZE
Definition: ObQuery.c:11
#define OBJ_DIRECTORY_TYPE_INFO_SIZE
Definition: ObQuery.c:12
#define ok_eq_hex(value, expected)
Definition: apitest.h:58
#define ok_eq_ulong(value, expected)
Definition: apitest.h:44
#define ok(value,...)
Definition: atltest.h:57
LONG NTSTATUS
Definition: precomp.h:26
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:43
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
Status
Definition: gdiplustypes.h:25
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_OPENIF
Definition: winternl.h:229
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSYSAPI NTSTATUS NTAPI ZwOpenDirectoryObject(_Out_ PHANDLE FileHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define DIRECTORY_QUERY
Definition: nt_native.h:1254
#define DIRECTORY_TRAVERSE
Definition: nt_native.h:1255
#define L(x)
Definition: ntvdm.h:50
#define STATUS_SUCCESS
Definition: shellext.h:65
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133

Referenced by START_TEST().

◆ ObjectNameInformationTests()

static VOID ObjectNameInformationTests ( VOID  )
static

Definition at line 80 of file ObQuery.c.

81{
83 SharedUserData->NtMajorVersion << 8 | SharedUserData->NtMinorVersion;
84
90
91 ULONG BufferSize1, BufferSize2, BufferSize3;
94
95 /* Test the drive containing SystemRoot */
96 WCHAR NtDeviceName[] = L"\\DosDevices\\?:";
97 NtDeviceName[sizeof("\\DosDevices\\")-1] = SharedUserData->NtSystemRoot[0];
98
99 /* We must be in PASSIVE_LEVEL to do all of this stuff */
100 ok_irql(PASSIVE_LEVEL);
101
102 /* Open a handle to the device */
103 RtlInitUnicodeString(&DeviceName, NtDeviceName);
105 &DeviceName,
107 NULL,
108 NULL);
116 if (skip(NT_SUCCESS(Status), "Device '%wZ': Opening failed\n", &DeviceName))
117 return;
118
119 /* Invoke ObjectNameInformation that retrieves the canonical device name */
120 Status = ZwQueryObject(DeviceHandle,
123 0,
124 &BufferSize1);
126
127 Status = ZwQueryObject(DeviceHandle,
131 &BufferSize2);
133
134 Status = ZwQueryObject(DeviceHandle,
137 sizeof(ObjectNameBuffer),
138 &BufferSize3);
140
142
143 /* Compare the returned buffer sizes */
144
145 /* The returned size behaviour changed (when ZwQueryObject()'s
146 * input Length is zero) between Windows <= 2003 and Vista+ */
148 ok_eq_ulong(BufferSize1, sizeof(OBJECT_NAME_INFORMATION));
149 else
150 ok_eq_ulong(BufferSize1, sizeof(OBJECT_NAME_INFORMATION) + ObjectName->MaximumLength);
151
152 ok_eq_ulong(BufferSize2, BufferSize3);
153 ok_eq_ulong(BufferSize3, sizeof(OBJECT_NAME_INFORMATION) + ObjectName->MaximumLength);
154
155 /* Test the name buffer */
156 ok(ObjectName->Length > 0, "ObjectName->Length == %hu, expected > 0\n", ObjectName->Length);
157 ok_eq_uint(ObjectName->MaximumLength, ObjectName->Length + sizeof(WCHAR));
158 ok(ObjectName->Buffer[ObjectName->Length / sizeof(WCHAR)] == UNICODE_NULL,
159 "UNICODE_NULL not found at end of ObjectName->Buffer\n");
160 if (skip(ObjectName->Buffer[ObjectName->Length / sizeof(WCHAR)] == UNICODE_NULL,
161 "ObjectName->Buffer string length check skipped\n"))
162 {
163 return;
164 }
165 /* Verify that ObjectName->Length doesn't count extra NUL-terminators */
166 {
167 SIZE_T strLen = wcslen(ObjectName->Buffer) * sizeof(WCHAR);
168 ok_eq_size(strLen, (SIZE_T)ObjectName->Length);
169 }
170}
@ ObjectNameInformation
Definition: DriverTester.h:55
static ULONG g_OsVersion
#define FILE_SHARE_ALL
Definition: ObQuery.c:71
#define ok_ntstatus
Definition: ObQuery.c:74
#define ok_eq_uint(value, expected)
Definition: apitest.h:42
#define ok_eq_size(value, expected)
Definition: apitest.h:50
#define skip(...)
Definition: atltest.h:64
Definition: bufpool.h:45
_In_z_ PCCHAR ObjectNameBuffer
Definition: classpnp.h:982
#define MAX_PATH
Definition: compat.h:34
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
NTSYSAPI NTSTATUS NTAPI ZwOpenFile(_Out_ PHANDLE FileHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes, _Out_ PIO_STATUS_BLOCK IoStatusBlock, _In_ ULONG ShareAccess, _In_ ULONG OpenOptions)
#define SYNCHRONIZE
Definition: nt_native.h:61
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
struct _OBJECT_NAME_INFORMATION OBJECT_NAME_INFORMATION
#define UNICODE_NULL
#define SharedUserData
#define _WIN32_WINNT_VISTA
Definition: sdkddkver.h:25
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
ULONG_PTR SIZE_T
Definition: typedefs.h:80
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275
_In_ PVOID _Out_opt_ PULONG_PTR _Outptr_opt_ PCUNICODE_STRING * ObjectName
Definition: cmfuncs.h:64
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( ObQuery  )

Definition at line 172 of file ObQuery.c.

173{
176}
static VOID ObjectBasicInformationTests(VOID)
Definition: ObQuery.c:16
static VOID ObjectNameInformationTests(VOID)
Definition: ObQuery.c:80