ReactOS 0.4.15-dev-7131-ge4d03f4
GetUserObjectInformation.c File Reference
#include "precomp.h"
#include <apitest_guard.h>
#include <ndk/mmfuncs.h>
#include <ndk/pstypes.h>
#include <strsafe.h>
Include dependency graph for GetUserObjectInformation.c:

Go to the source code of this file.

Macros

#define xok   ok
 
#define NOTSET   1234
 
#define TestUserObjectInfo(Handle, Index, Buffer, Length, Ret, Error, LengthNeeded)
 
#define TestUserObjectInfoWithString(Handle, Index, Buffer, BufferSize, String)
 
#define TestUserObjectInfo(Handle, Index, Buffer, Length, Ret, Error, LengthNeeded)
 
#define TestUserObjectInfoWithString(Handle, Index, Buffer, BufferSize, String)
 

Functions

static BOOLEAN CheckBuffer (PVOID Buffer, SIZE_T Size, UCHAR Value)
 
static void TestGetUserObjectInfoW (void)
 
static void TestGetUserObjectInfoA (void)
 
 START_TEST (GetUserObjectInformation)
 

Macro Definition Documentation

◆ NOTSET

#define NOTSET   1234

Definition at line 36 of file GetUserObjectInformation.c.

◆ TestUserObjectInfo [1/2]

#define TestUserObjectInfo (   Handle,
  Index,
  Buffer,
  Length,
  Ret,
  Error,
  LengthNeeded 
)

Definition at line 282 of file GetUserObjectInformation.c.

◆ TestUserObjectInfo [2/2]

#define TestUserObjectInfo (   Handle,
  Index,
  Buffer,
  Length,
  Ret,
  Error,
  LengthNeeded 
)

Definition at line 282 of file GetUserObjectInformation.c.

◆ TestUserObjectInfoWithString [1/2]

#define TestUserObjectInfoWithString (   Handle,
  Index,
  Buffer,
  BufferSize,
  String 
)
Value:
do \
{ \
BOOLEAN _Check; \
SIZE_T SizeOfString = wcslen(String) * sizeof(WCHAR) + sizeof(UNICODE_NULL); \
TestUserObjectInfo(Handle, Index, NULL, 0, FALSE, ERROR_INSUFFICIENT_BUFFER, SizeOfString); \
TestUserObjectInfo(Handle, Index, UlongToPtr(1), 0, FALSE, ERROR_INSUFFICIENT_BUFFER, SizeOfString); \
TestUserObjectInfo(Handle, Index, NULL, 1, FALSE, ERROR_NOACCESS, NOTSET); \
TestUserObjectInfo(Handle, Index, UlongToPtr(1), 1, FALSE, ERROR_NOACCESS, NOTSET); \
RtlFillMemory(Buffer, BufferSize, 0x55); \
TestUserObjectInfo(Handle, Index, Buffer, SizeOfString - 2, FALSE, ERROR_INSUFFICIENT_BUFFER, SizeOfString); \
_Check = CheckBuffer(Buffer, BufferSize, 0x55); \
ok(_Check == TRUE, "CheckBuffer failed\n"); \
RtlFillMemory(Buffer, BufferSize, 0x55); \
TestUserObjectInfo(Handle, Index, Buffer, SizeOfString - 1, FALSE, ERROR_INSUFFICIENT_BUFFER, SizeOfString); \
_Check = CheckBuffer(Buffer, BufferSize, 0x55); \
ok(_Check == TRUE, "CheckBuffer failed\n"); \
RtlFillMemory(Buffer, BufferSize, 0x55); \
Buffer[BufferSize / sizeof(WCHAR) - 1] = UNICODE_NULL; \
TestUserObjectInfo(Handle, Index, Buffer, SizeOfString, TRUE, 0xdeadbeef, SizeOfString); \
ok(wcscmp(Buffer, String) == 0, "Buffer '%ls', expected '%ls'\n", Buffer, String); \
_Check = CheckBuffer(Buffer + SizeOfString / sizeof(Buffer[0]), BufferSize - SizeOfString - sizeof(WCHAR), 0x55); \
ok(_Check == TRUE, "CheckBuffer failed\n"); \
RtlFillMemory(Buffer, BufferSize, 0x55); \
Buffer[BufferSize / sizeof(WCHAR) - 1] = UNICODE_NULL; \
TestUserObjectInfo(Handle, Index, Buffer, BufferSize, TRUE, 0xdeadbeef, SizeOfString); \
ok(wcscmp(Buffer, String) == 0, "Buffer '%ls', expected '%ls'\n", Buffer, String); \
_Check = CheckBuffer(Buffer + SizeOfString / sizeof(Buffer[0]), BufferSize - SizeOfString - sizeof(WCHAR), 0x55); \
ok(_Check == TRUE, "CheckBuffer failed\n"); \
} while (0)
#define NOTSET
static BOOLEAN CheckBuffer(PVOID Buffer, SIZE_T Size, UCHAR Value)
unsigned char BOOLEAN
Definition: bufpool.h:45
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define UlongToPtr(u)
Definition: config.h:106
ULONG Handle
Definition: gdb_input.c:15
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define UNICODE_NULL
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
ULONG_PTR SIZE_T
Definition: typedefs.h:80
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
#define ERROR_NOACCESS
Definition: winerror.h:578
__wchar_t WCHAR
Definition: xmlstorage.h:180

Definition at line 320 of file GetUserObjectInformation.c.

◆ TestUserObjectInfoWithString [2/2]

#define TestUserObjectInfoWithString (   Handle,
  Index,
  Buffer,
  BufferSize,
  String 
)
Value:
do \
{ \
BOOLEAN _Check; \
TestUserObjectInfo(Handle, Index, NULL, 0, FALSE, ERROR_INSUFFICIENT_BUFFER, sizeof(String) * sizeof(WCHAR));\
TestUserObjectInfo(Handle, Index, (PVOID)1, 0, FALSE, ERROR_INSUFFICIENT_BUFFER, sizeof(String) * sizeof(WCHAR));\
TestUserObjectInfo(Handle, Index, NULL, 1, FALSE, ERROR_INSUFFICIENT_BUFFER, sizeof(String) * sizeof(WCHAR));\
TestUserObjectInfo(Handle, Index, (PVOID)1, 1, FALSE, ERROR_INSUFFICIENT_BUFFER, sizeof(String) * sizeof(WCHAR));\
RtlFillMemory(Buffer, BufferSize, 0x55); \
TestUserObjectInfo(Handle, Index, Buffer, sizeof(String) - 2, FALSE, ERROR_INSUFFICIENT_BUFFER, sizeof(String) * sizeof(WCHAR));\
_Check = CheckBuffer(Buffer, BufferSize, 0x55); \
ok(_Check == TRUE, "CheckBuffer failed\n"); \
RtlFillMemory(Buffer, BufferSize, 0x55); \
TestUserObjectInfo(Handle, Index, Buffer, sizeof(String) - 1, FALSE, ERROR_INSUFFICIENT_BUFFER, sizeof(String) * sizeof(WCHAR));\
_Check = CheckBuffer(Buffer, BufferSize, 0x55); \
ok(_Check == TRUE, "CheckBuffer failed\n"); \
RtlFillMemory(Buffer, BufferSize, 0x55); \
TestUserObjectInfo(Handle, Index, Buffer, sizeof(String), TRUE, 0xdeadbeef, sizeof(String)); \
ok(strcmp(Buffer, String) == 0, "Buffer '%s'\n", Buffer); \
_Check = CheckBuffer(Buffer + sizeof(String), BufferSize - sizeof(String), 0x55); \
ok(_Check == TRUE, "CheckBuffer failed\n"); \
RtlFillMemory(Buffer, BufferSize, 0x55); \
TestUserObjectInfo(Handle, Index, Buffer, BufferSize, TRUE, 0xdeadbeef, sizeof(String)); \
ok(strcmp(Buffer, String) == 0, "Buffer '%s'\n", Buffer); \
_Check = CheckBuffer(Buffer + sizeof(String), BufferSize - sizeof(String), 0x55); \
ok(_Check == TRUE, "CheckBuffer failed\n"); \
} while (0)
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469

Definition at line 320 of file GetUserObjectInformation.c.

◆ xok

#define xok   ok

Definition at line 34 of file GetUserObjectInformation.c.

Function Documentation

◆ CheckBuffer()

static BOOLEAN CheckBuffer ( PVOID  Buffer,
SIZE_T  Size,
UCHAR  Value 
)
static

Definition at line 17 of file GetUserObjectInformation.c.

21{
22 PUCHAR Array = Buffer;
23 SIZE_T i;
24
25 for (i = 0; i < Size; i++)
26 if (Array[i] != Value)
27 {
28 trace("Expected %x, found %x at offset %lu\n", Value, Array[i], (ULONG)i);
29 return FALSE;
30 }
31 return TRUE;
32}
#define trace
Definition: atltest.h:70
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

◆ START_TEST()

START_TEST ( GetUserObjectInformation  )

Definition at line 417 of file GetUserObjectInformation.c.

418{
421}
static void TestGetUserObjectInfoW(void)
static void TestGetUserObjectInfoA(void)

◆ TestGetUserObjectInfoA()

static void TestGetUserObjectInfoA ( void  )
static

Definition at line 349 of file GetUserObjectInformation.c.

350{
351 USEROBJECTFLAGS UserObjectFlags;
353 ULONG BufferSize = 64;
354 HDESK Desktop;
355 HWINSTA WinSta;
356
358
364 TestUserObjectInfo(NULL, UOI_FLAGS, &UserObjectFlags, sizeof(UserObjectFlags), FALSE, ERROR_INVALID_HANDLE, 0);
365
371
377
379 if (!Desktop)
380 {
381 skip("Failed to get desktop handle\n");
383 return;
384 }
385
386 WinSta = GetProcessWindowStation();
387 if (!WinSta)
388 {
389 skip("Failed to get winsta handle\n");
391 return;
392 }
393
399 TestUserObjectInfo(Desktop, UOI_FLAGS, &UserObjectFlags, sizeof(UserObjectFlags), TRUE, 0xdeadbeef, sizeof(USEROBJECTFLAGS));
400
403
404 TestUserObjectInfoWithString(WinSta, UOI_TYPE, Buffer, BufferSize, "WindowStation");
406
408
409 /* Make sure nothing behind the needed buffer is touched */
410 BufferSize = sizeof("Desktop");
412 TestUserObjectInfo(Desktop, UOI_TYPE, Buffer, BufferSize, TRUE, 0xdeadbeef, sizeof("Desktop"));
413 TestUserObjectInfo(Desktop, UOI_TYPE, Buffer, BufferSize + 1, TRUE, 0xdeadbeef, sizeof("Desktop"));
415}
#define TestUserObjectInfo(Handle, Index, Buffer, Length, Ret, Error, LengthNeeded)
#define TestUserObjectInfoWithString(Handle, Index, Buffer, BufferSize, String)
static VOID FreeGuarded(_In_ PVOID Pointer)
Definition: apitest_guard.h:45
static PVOID AllocateGuarded(_In_ SIZE_T SizeRequested)
Definition: apitest_guard.h:10
#define skip(...)
Definition: atltest.h:64
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
char * PCHAR
Definition: typedefs.h:51
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459
HWINSTA WINAPI GetProcessWindowStation(void)
Definition: ntwrapper.h:124
HDESK WINAPI GetThreadDesktop(_In_ DWORD)
#define UOI_NAME
Definition: winuser.h:1083
#define UOI_TYPE
Definition: winuser.h:1084
#define UOI_FLAGS
Definition: winuser.h:1082

Referenced by START_TEST().

◆ TestGetUserObjectInfoW()

static void TestGetUserObjectInfoW ( void  )
static

Definition at line 107 of file GetUserObjectInformation.c.

108{
109 USEROBJECTFLAGS UserObjectFlags;
111 ULONG BufferSize = 64 * sizeof(WCHAR);
112 HDESK Desktop;
113 HDESK Desktop2;
114 HWINSTA WinSta;
116 TOKEN_STATISTICS Statistics;
117 WCHAR WinStaName[64];
120
122
128 TestUserObjectInfo(NULL, UOI_FLAGS, &UserObjectFlags, sizeof(UserObjectFlags), FALSE, ERROR_INVALID_HANDLE, 0);
129
135
141
143 if (!Desktop)
144 {
145 skip("Failed to get desktop handle\n");
147 return;
148 }
149
150 WinSta = GetProcessWindowStation();
151 if (!WinSta)
152 {
153 skip("Failed to get winsta handle\n");
155 return;
156 }
157
163 TestUserObjectInfo(Desktop, UOI_FLAGS, &UserObjectFlags, sizeof(UserObjectFlags), TRUE, 0xdeadbeef, sizeof(USEROBJECTFLAGS));
164
167
168 TestUserObjectInfoWithString(WinSta, UOI_TYPE, Buffer, BufferSize, L"WindowStation");
170
171 /* Autogenerated name will be Service-0x<luidhigh>-<luidlow>$ */
172 StringCbCopyW(WinStaName, sizeof(WinStaName), L"<failed>");
174 ok(Success == TRUE, "OpenProcessToken failed with %lu\n", GetLastError());
175 if (Success)
176 {
179 &Statistics,
180 sizeof(Statistics),
181 &Length);
182 ok(Success == TRUE, "GetTokenInformation failed with %lu\n", GetLastError());
183 if (Success)
184 {
185 StringCbPrintfW(WinStaName,
186 sizeof(WinStaName),
187 L"Service-0x%lx-%lx$",
188 Statistics.AuthenticationId.HighPart,
189 Statistics.AuthenticationId.LowPart);
190 trace("Expected autogenerated Winsta name: %ls\n", WinStaName);
191 }
193 }
194
195 /* Create our own Winsta */
197 ok(WinSta != NULL, "CreateWindowStationW failed with %lu\n", GetLastError());
198 if (WinSta)
199 {
200 TestUserObjectInfoWithString(WinSta, UOI_TYPE, Buffer, BufferSize, L"WindowStation");
202 CloseWindowStation(WinSta);
203 }
204 else
205 {
206 skip("Failed to create winsta\n");
207 }
208
210 ok(WinSta != NULL, "CreateWindowStationW failed with %lu\n", GetLastError());
211 if (WinSta)
212 {
213 TestUserObjectInfoWithString(WinSta, UOI_TYPE, Buffer, BufferSize, L"WindowStation");
215 CloseWindowStation(WinSta);
216 }
217 else
218 {
219 skip("Failed to create winsta\n");
220 }
221
222 WinSta = CreateWindowStationW(L"GetUserObjectInformation_apitest_winsta", 0, WINSTA_READATTRIBUTES, NULL);
223 ok(WinSta != NULL, "CreateWindowStationW failed with %lu\n", GetLastError());
224 if (WinSta)
225 {
226 TestUserObjectInfoWithString(WinSta, UOI_TYPE, Buffer, BufferSize, L"WindowStation");
227 TestUserObjectInfoWithString(WinSta, UOI_NAME, Buffer, BufferSize, L"GetUserObjectInformation_apitest_winsta");
228 CloseWindowStation(WinSta);
229 }
230 else
231 {
232 skip("Failed to create winsta\n");
233 }
234
236 ok(WinSta != NULL, "CreateWindowStationW failed with %lu\n", GetLastError());
237 if (WinSta)
238 {
239 TestUserObjectInfoWithString(WinSta, UOI_TYPE, Buffer, BufferSize, L"WindowStation");
241 CloseWindowStation(WinSta);
242 }
243 else
244 {
245 skip("Failed to create winsta\n");
246 }
247
248 /* Create our own desktop */
250 ok(Desktop2 == NULL, "CreateDesktopW succeeded\n");
251 if (Desktop2) CloseDesktop(Desktop2);
252
254 ok(Desktop2 == NULL, "CreateDesktopW succeeded\n");
255 if (Desktop2) CloseDesktop(Desktop2);
256
258 ok(Desktop2 != NULL, "CreateDesktopW failed with %lu\n", GetLastError());
259 if (Desktop2)
260 {
263 }
264 else
265 {
266 skip("Failed to create winsta\n");
267 }
268
269 CloseDesktop(Desktop2);
270
272
273 /* Make sure nothing behind the needed buffer is touched */
274 BufferSize = sizeof(L"Desktop");
276 TestUserObjectInfo(Desktop, UOI_TYPE, Buffer, BufferSize, TRUE, 0xdeadbeef, sizeof(L"Desktop"));
279}
#define ok(value,...)
Definition: atltest.h:57
BOOL WINAPI GetTokenInformation(HANDLE TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass, LPVOID TokenInformation, DWORD TokenInformationLength, PDWORD ReturnLength)
Definition: security.c:411
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:294
#define CloseHandle
Definition: compat.h:739
#define GetCurrentProcess()
Definition: compat.h:759
@ Success
Definition: eventcreate.c:712
unsigned int BOOL
Definition: ntddk_ex.h:94
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define L(x)
Definition: ntvdm.h:50
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166
STRSAFEAPI StringCbPrintfW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:557
LONG HighPart
DWORD LowPart
LUID AuthenticationId
Definition: setypes.h:1087
uint16_t * PWCHAR
Definition: typedefs.h:56
HDESK WINAPI CreateDesktopW(LPCWSTR lpszDesktop, LPCWSTR lpszDevice, LPDEVMODEW pDevmode, DWORD dwFlags, ACCESS_MASK dwDesiredAccess, LPSECURITY_ATTRIBUTES lpsa)
Definition: desktop.c:473
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define DESKTOP_CREATEWINDOW
Definition: winuser.h:217
HWINSTA WINAPI CreateWindowStationW(_In_opt_ LPCWSTR lpwinsta, _In_ DWORD dwFlags, _In_ ACCESS_MASK dwDesiredAccess, _In_opt_ LPSECURITY_ATTRIBUTES lpsa)
BOOL WINAPI CloseWindowStation(_In_ HWINSTA)
#define WINSTA_READATTRIBUTES
Definition: winuser.h:414
#define DESKTOP_READOBJECTS
Definition: winuser.h:222
BOOL WINAPI CloseDesktop(_In_ HDESK)
#define TOKEN_QUERY
Definition: setypes.h:928
@ TokenStatistics
Definition: setypes.h:975

Referenced by START_TEST().