ReactOS  0.4.15-dev-5606-gf34e425
winsta.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _WINSTATION_OBJECT
 

Macros

#define WINSTA_OBJ_DIR   L"\\Windows\\WindowStations"
 
#define SESSION_DIR   L"\\Sessions"
 
#define WSS_LOCKED   (1)
 
#define WSS_NOINTERACTIVE   (2)
 
#define WSS_NOIO   (4)
 
#define WSS_SHUTDOWN   (8)
 
#define WSS_DYING   (16)
 
#define WSS_REALSHUTDOWN   (32)
 

Typedefs

typedef struct _WINSTATION_OBJECT WINSTATION_OBJECT
 
typedef struct _WINSTATION_OBJECTPWINSTATION_OBJECT
 

Functions

 C_ASSERT (offsetof(WINSTATION_OBJECT, Flags)==0x10)
 
 C_ASSERT (offsetof(WINSTATION_OBJECT, spklList)==0x14)
 
 C_ASSERT (offsetof(WINSTATION_OBJECT, ptiClipLock)==0x18)
 
 C_ASSERT (offsetof(WINSTATION_OBJECT, ptiDrawingClipboard)==0x1c)
 
 C_ASSERT (offsetof(WINSTATION_OBJECT, spwndClipOpen)==0x20)
 
 C_ASSERT (offsetof(WINSTATION_OBJECT, spwndClipViewer)==0x24)
 
 C_ASSERT (offsetof(WINSTATION_OBJECT, spwndClipOwner)==0x28)
 
NTSTATUS NTAPI InitWindowStationImpl (VOID)
 
NTSTATUS NTAPI UserCreateWinstaDirectory (VOID)
 
NTSTATUS NTAPI IntWinStaObjectDelete (_In_ PVOID Parameters)
 
NTSTATUS NTAPI IntWinStaObjectParse (_In_ PVOID Parameters)
 
NTSTATUS NTAPI IntWinStaOkToClose (_In_ PVOID Parameters)
 
NTSTATUS FASTCALL IntValidateWindowStationHandle (HWINSTA WindowStation, KPROCESSOR_MODE AccessMode, ACCESS_MASK DesiredAccess, PWINSTATION_OBJECT *Object, POBJECT_HANDLE_INFORMATION pObjectHandleInfo)
 
NTSTATUS FASTCALL IntCreateWindowStation (OUT HWINSTA *phWinSta, IN POBJECT_ATTRIBUTES ObjectAttributes, IN KPROCESSOR_MODE AccessMode, IN KPROCESSOR_MODE OwnerMode, IN ACCESS_MASK dwDesiredAccess, DWORD Unknown2, DWORD Unknown3, DWORD Unknown4, DWORD Unknown5, DWORD Unknown6)
 
PWINSTATION_OBJECT FASTCALL IntGetProcessWindowStation (HWINSTA *phWinSta OPTIONAL)
 
BOOL FASTCALL UserSetProcessWindowStation (HWINSTA hWindowStation)
 
BOOL FASTCALL co_IntInitializeDesktopGraphics (VOID)
 
VOID FASTCALL IntEndDesktopGraphics (VOID)
 
BOOL FASTCALL CheckWinstaAttributeAccess (ACCESS_MASK)
 

Variables

WINSTATION_OBJECTInputWindowStation
 
HANDLE gpidLogon
 
HWND hwndSAS
 
UNICODE_STRING gustrWindowStationsDir
 

Macro Definition Documentation

◆ SESSION_DIR

#define SESSION_DIR   L"\\Sessions"

Definition at line 4 of file winsta.h.

◆ WINSTA_OBJ_DIR

#define WINSTA_OBJ_DIR   L"\\Windows\\WindowStations"

Definition at line 3 of file winsta.h.

◆ WSS_DYING

#define WSS_DYING   (16)

Definition at line 11 of file winsta.h.

◆ WSS_LOCKED

#define WSS_LOCKED   (1)

Definition at line 7 of file winsta.h.

◆ WSS_NOINTERACTIVE

#define WSS_NOINTERACTIVE   (2)

Definition at line 8 of file winsta.h.

◆ WSS_NOIO

#define WSS_NOIO   (4)

Definition at line 9 of file winsta.h.

◆ WSS_REALSHUTDOWN

#define WSS_REALSHUTDOWN   (32)

Definition at line 12 of file winsta.h.

◆ WSS_SHUTDOWN

#define WSS_SHUTDOWN   (8)

Definition at line 10 of file winsta.h.

Typedef Documentation

◆ PWINSTATION_OBJECT

◆ WINSTATION_OBJECT

Function Documentation

◆ C_ASSERT() [1/7]

C_ASSERT ( offsetof(WINSTATION_OBJECT, Flags = =0x10)

◆ C_ASSERT() [2/7]

C_ASSERT ( offsetof(WINSTATION_OBJECT, spklList)  = =0x14)

◆ C_ASSERT() [3/7]

C_ASSERT ( offsetof(WINSTATION_OBJECT, ptiClipLock)  = =0x18)

◆ C_ASSERT() [4/7]

C_ASSERT ( offsetof(WINSTATION_OBJECT, ptiDrawingClipboard)  = =0x1c)

◆ C_ASSERT() [5/7]

C_ASSERT ( offsetof(WINSTATION_OBJECT, spwndClipOpen)  = =0x20)

◆ C_ASSERT() [6/7]

C_ASSERT ( offsetof(WINSTATION_OBJECT, spwndClipViewer)  = =0x24)

◆ C_ASSERT() [7/7]

C_ASSERT ( offsetof(WINSTATION_OBJECT, spwndClipOwner)  = =0x28)

◆ CheckWinstaAttributeAccess()

BOOL FASTCALL CheckWinstaAttributeAccess ( ACCESS_MASK  )

Definition at line 377 of file winsta.c.

378 {
380  if ( gpidLogon != PsGetCurrentProcessId() )
381  {
382  if (!(ppi->W32PF_flags & W32PF_IOWINSTA))
383  {
384  ERR("Requires Interactive Window Station\n");
386  return FALSE;
387  }
389  {
390  ERR("Access Denied\n");
392  return FALSE;
393  }
394  }
395  return TRUE;
396 }
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2654
#define TRUE
Definition: types.h:120
#define W32PF_IOWINSTA
Definition: win32.h:23
#define ERROR_REQUIRES_INTERACTIVE_WINDOWSTATION
Definition: winerror.h:940
#define FALSE
Definition: types.h:117
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
#define ERR(fmt,...)
Definition: debug.h:110
HANDLE NTAPI PsGetCurrentProcessId(VOID)
Definition: process.c:1123
PVOID NTAPI PsGetCurrentProcessWin32Process(VOID)
Definition: process.c:1183
NTSYSAPI BOOLEAN NTAPI RtlAreAllAccessesGranted(ACCESS_MASK GrantedAccess, ACCESS_MASK DesiredAccess)
ACCESS_MASK amwinsta
Definition: win32.h:268
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:28
HANDLE gpidLogon
Definition: simplecall.c:15

Referenced by NtUserGetClipCursor(), NtUserSetSystemCursor(), and UserClipCursor().

◆ co_IntInitializeDesktopGraphics()

BOOL FASTCALL co_IntInitializeDesktopGraphics ( VOID  )

Definition at line 262 of file winsta.c.

263 {
264  TEXTMETRICW tmw;
265  UNICODE_STRING DriverName = RTL_CONSTANT_STRING(L"DISPLAY");
266  PDESKTOP pdesk;
267 
269  {
270  ERR("PDEVOBJ_lChangeDisplaySettings() failed.\n");
271  return FALSE;
272  }
273 
275  if (NULL == ScreenDeviceContext)
276  {
278  return FALSE;
279  }
281 
283  {
284  return FALSE;
285  }
286 
288 
291 
292  /* Update the system metrics */
293  InitMetrics();
294 
295  /* Set new size of the monitor */
297 
298  /* Update the SERVERINFO */
303  gpsi->BitCount = gpsi->Planes * gpsi->BitsPixel;
306  {
307  gpsi->PUSIFlags |= PUSIF_PALETTEDISPLAY;
308  }
309  else
310  {
311  gpsi->PUSIFlags &= ~PUSIF_PALETTEDISPLAY;
312  }
313  // Font is realized and this dc was previously set to internal DC_ATTR.
314  gpsi->cxSysFontChar = IntGetCharDimensions(hSystemBM, &tmw, (DWORD*)&gpsi->cySysFontChar);
315  gpsi->tmSysFont = tmw;
316 
317  /* Put the pointer in the center of the screen */
318  gpsi->ptCursor.x = gpsi->aiSysMet[SM_CXSCREEN] / 2;
319  gpsi->ptCursor.y = gpsi->aiSysMet[SM_CYSCREEN] / 2;
320 
321  /* Attach monitor */
323 
324  /* Setup the cursor */
326 
327  /* Setup the icons */
329 
330  /* Setup Menu */
331  MenuInit();
332 
333  /* Show the desktop */
334  pdesk = IntGetActiveDesktop();
335  ASSERT(pdesk);
336  co_IntShowDesktop(pdesk, gpsi->aiSysMet[SM_CXSCREEN], gpsi->aiSysMet[SM_CYSCREEN], TRUE);
337 
338  /* HACK: display wallpaper on all secondary displays */
339  {
340  PGRAPHICS_DEVICE pGraphicsDevice;
341  UNICODE_STRING DriverName = RTL_CONSTANT_STRING(L"DISPLAY");
342  UNICODE_STRING DisplayName;
343  HDC hdc;
344  ULONG iDevNum;
345 
346  for (iDevNum = 1; (pGraphicsDevice = EngpFindGraphicsDevice(NULL, iDevNum)) != NULL; iDevNum++)
347  {
348  RtlInitUnicodeString(&DisplayName, pGraphicsDevice->szWinDeviceName);
349  hdc = IntGdiCreateDC(&DriverName, &DisplayName, NULL, NULL, FALSE);
351  }
352  }
353 
354  return TRUE;
355 }
BOOL MenuInit(VOID)
Definition: menu.c:361
#define BITSPIXEL
Definition: wingdi.h:720
NTSTATUS NTAPI UserUpdateMonitorSize(IN HDEV hDev)
Definition: monitor.c:225
WCHAR szWinDeviceName[CCHDEVICENAME/2]
Definition: pdevobj.h:60
#define TRUE
Definition: types.h:120
GDIINFO gdiinfo
Definition: pdevobj.h:123
__kernel_entry W32KAPI HANDLE APIENTRY NtGdiGetStockObject(_In_ INT iObject)
static HDC
Definition: imagelist.c:92
PSERVERINFO gpsi
Definition: imm.c:18
#define RASTERCAPS
Definition: wingdi.h:745
NTSTATUS NTAPI UserAttachMonitor(IN HDEV hDev)
Definition: monitor.c:129
#define SM_CXSCREEN
Definition: winuser.h:953
#define L(x)
Definition: ntvdm.h:50
#define FALSE
Definition: types.h:117
BOOL FASTCALL co_IntSetWndIcons(VOID)
Definition: callback.c:1101
DWORD FASTCALL IntGetCharDimensions(HDC hdc, PTEXTMETRICW ptm, PDWORD height)
Definition: font.c:329
ULONG ulHorzRes
Definition: winddi.h:882
#define SYSTEM_FONT
Definition: wingdi.h:911
BOOL FASTCALL IntPaintDesktop(HDC hDC)
Definition: desktop.c:1835
__kernel_entry W32KAPI HFONT APIENTRY NtGdiSelectFont(_In_ HDC hdc, _In_ HFONT hf)
Definition: dcobjs.c:597
#define SM_CYSCREEN
Definition: winuser.h:954
#define ASSERT(a)
Definition: mode.c:44
HDC hSystemBM
Definition: stockobj.c:52
#define RC_PALETTE
Definition: wingdi.h:790
BOOL NTAPI InitMetrics(VOID)
Definition: metric.c:39
#define DISP_CHANGE_SUCCESSFUL
Definition: winuser.h:190
BOOL APIENTRY co_IntLoadDefaultCursors(VOID)
Definition: callback.c:471
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL FASTCALL IntCreatePrimarySurface(VOID)
Definition: device.c:17
HDC hdc
Definition: main.c:9
PGRAPHICS_DEVICE NTAPI EngpFindGraphicsDevice(_In_opt_ PUNICODE_STRING pustrDevice, _In_ ULONG iDevNum)
Definition: device.c:641
NTSTATUS FASTCALL co_IntShowDesktop(PDESKTOP Desktop, ULONG Width, ULONG Height, BOOL bRedraw)
Definition: desktop.c:1617
__kernel_entry W32KAPI HDC APIENTRY NtGdiCreateCompatibleDC(_In_opt_ HDC hdc)
#define ERR(fmt,...)
Definition: debug.h:110
PPDEVOBJ ppdevGlobal
Definition: mdevobj.h:16
HDC FASTCALL IntGdiCreateDC(PUNICODE_STRING Driver, PUNICODE_STRING pustrDevice, PVOID pUMdhpdev, CONST PDEVMODEW pdmInit, BOOL CreateAsIC)
Definition: dclife.c:1040
PMDEVOBJ gpmdev
Definition: mdevobj.c:14
BOOL NTAPI GreSetDCOwner(HDC hdc, ULONG ulOwner)
Definition: dclife.c:455
#define GDI_OBJ_HMGR_PUBLIC
Definition: ntgdihdl.h:116
#define NULL
Definition: types.h:112
#define PUSIF_PALETTEDISPLAY
Definition: ntuser.h:988
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define LOGPIXELSY
Definition: wingdi.h:719
PDESKTOP FASTCALL IntGetActiveDesktop(VOID)
Definition: desktop.c:1262
__kernel_entry W32KAPI INT APIENTRY NtGdiGetDeviceCaps(_In_ HDC hdc, _In_ INT i)
HDC ScreenDeviceContext
Definition: desktop.c:36
ULONG ulVertRes
Definition: winddi.h:883
VOID FASTCALL IntDestroyPrimarySurface(VOID)
Definition: device.c:32
LONG PDEVOBJ_lChangeDisplaySettings(_In_opt_ PUNICODE_STRING pustrDeviceName, _In_opt_ PDEVMODEW RequestedMode, _In_opt_ PMDEVOBJ pmdevOld, _Out_ PMDEVOBJ *ppmdevNew, _In_ BOOL bSearchClosestMode)
Definition: pdevobj.c:776
#define PLANES
Definition: wingdi.h:721
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by co_AddGuiApp().

◆ InitWindowStationImpl()

NTSTATUS NTAPI InitWindowStationImpl ( VOID  )

Definition at line 34 of file winsta.c.

35 {
36  GENERIC_MAPPING IntWindowStationMapping = { WINSTA_READ,
40 
41  /* Set Winsta Object Attributes */
43  ExWindowStationObjectType->TypeInfo.GenericMapping = IntWindowStationMapping;
45 
46  return STATUS_SUCCESS;
47 }
#define WINSTA_WRITE
Definition: security.h:48
POBJECT_TYPE ExWindowStationObjectType
Definition: win32k.c:21
#define WINSTA_EXECUTE
Definition: security.h:53
#define WINSTA_READ
Definition: security.h:42
struct _WINSTATION_OBJECT WINSTATION_OBJECT
OBJECT_TYPE_INITIALIZER TypeInfo
Definition: obtypes.h:390
GENERIC_MAPPING GenericMapping
Definition: obtypes.h:358
#define WINSTA_ACCESS_ALL
Definition: security.h:57
#define STATUS_SUCCESS
Definition: shellext.h:65
ULONG DefaultNonPagedPoolCharge
Definition: obtypes.h:365

Referenced by DriverEntry().

◆ IntCreateWindowStation()

NTSTATUS FASTCALL IntCreateWindowStation ( OUT HWINSTA *  phWinSta,
IN POBJECT_ATTRIBUTES  ObjectAttributes,
IN KPROCESSOR_MODE  AccessMode,
IN KPROCESSOR_MODE  OwnerMode,
IN ACCESS_MASK  dwDesiredAccess,
DWORD  Unknown2,
DWORD  Unknown3,
DWORD  Unknown4,
DWORD  Unknown5,
DWORD  Unknown6 
)

Definition at line 447 of file winsta.c.

458 {
460  HWINSTA hWinSta;
461  PWINSTATION_OBJECT WindowStation;
462 
463  TRACE("IntCreateWindowStation called\n");
464 
465  ASSERT(phWinSta);
466  *phWinSta = NULL;
467 
470  AccessMode,
471  NULL,
472  dwDesiredAccess,
473  NULL,
474  (PVOID*)&hWinSta);
475  if (NT_SUCCESS(Status))
476  {
477  TRACE("IntCreateWindowStation opened window station '%wZ'\n",
478  ObjectAttributes->ObjectName);
479  *phWinSta = hWinSta;
480  return Status;
481  }
482 
483  /*
484  * No existing window station found, try to create a new one.
485  */
486 
487  /* Create the window station object */
491  OwnerMode,
492  NULL,
493  sizeof(WINSTATION_OBJECT),
494  0,
495  0,
496  (PVOID*)&WindowStation);
497  if (!NT_SUCCESS(Status))
498  {
499  ERR("ObCreateObject failed for window station '%wZ', Status 0x%08lx\n",
500  ObjectAttributes->ObjectName, Status);
502  return Status;
503  }
504 
505  /* Initialize the window station */
506  RtlZeroMemory(WindowStation, sizeof(WINSTATION_OBJECT));
507 
508  InitializeListHead(&WindowStation->DesktopListHead);
509  WindowStation->dwSessionId = NtCurrentPeb()->SessionId;
510  Status = RtlCreateAtomTable(37, &WindowStation->AtomTable);
511  if (!NT_SUCCESS(Status))
512  {
513  ERR("RtlCreateAtomTable failed for window station '%wZ', Status 0x%08lx\n",
514  ObjectAttributes->ObjectName, Status);
515  ObDereferenceObject(WindowStation);
517  return Status;
518  }
519 
520  Status = ObInsertObject(WindowStation,
521  NULL,
522  dwDesiredAccess,
523  0,
524  NULL,
525  (PVOID*)&hWinSta);
526  if (!NT_SUCCESS(Status))
527  {
528  ERR("ObInsertObject failed for window station, Status 0x%08lx\n", Status);
530  return Status;
531  }
532 
533  // FIXME! TODO: Add this new window station to a linked list
534 
535  if (InputWindowStation == NULL)
536  {
537  ERR("Initializing input window station\n");
538 
539  /* Only Winlogon can create the interactive window station */
541 
542  InputWindowStation = WindowStation;
543  WindowStation->Flags &= ~WSS_NOIO;
544 
545  InitCursorImpl();
546 
549 
550  /* Desktop functions require the desktop thread running so wait for it to initialize */
551  UserLeaveCo();
553  UserRequest,
554  UserMode,
555  FALSE,
556  NULL);
557  UserEnterCo();
558  }
559  else
560  {
561  WindowStation->Flags |= WSS_NOIO;
562  }
563 
564  TRACE("IntCreateWindowStation created window station '%wZ' object 0x%p handle 0x%p\n",
565  ObjectAttributes->ObjectName, WindowStation, hWinSta);
566 
567  *phWinSta = hWinSta;
569 
570  return STATUS_SUCCESS;
571 }
NTSTATUS NTAPI ObOpenObjectByName(IN POBJECT_ATTRIBUTES ObjectAttributes, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN OUT PVOID ParseContext, OUT PHANDLE Handle)
Definition: obhandle.c:2532
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
BOOL UserCreateSystemThread(DWORD Type)
Definition: csr.c:247
POBJECT_TYPE ExWindowStationObjectType
Definition: win32k.c:21
#define ERROR_SUCCESS
Definition: deptool.c:10
PWINSTATION_OBJECT InputWindowStation
Definition: winsta.c:21
LONG NTSTATUS
Definition: precomp.h:26
LIST_ENTRY DesktopListHead
Definition: winsta.h:19
NTSYSAPI NTSTATUS NTAPI RtlCreateAtomTable(_In_ ULONG TableSize, _Inout_ PRTL_ATOM_TABLE *AtomTable)
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define FALSE
Definition: types.h:117
BOOL InitCursorImpl(VOID)
Definition: cursoricon.c:64
#define UserLeaveCo
Definition: ntuser.h:9
_In_ PEPROCESS _In_ KPROCESSOR_MODE AccessMode
Definition: mmfuncs.h:395
#define WSS_NOIO
Definition: winsta.h:9
NTSTATUS NTAPI ObCreateObject(IN KPROCESSOR_MODE ProbeMode OPTIONAL, IN POBJECT_TYPE Type, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN KPROCESSOR_MODE AccessMode, IN OUT PVOID ParseContext OPTIONAL, IN ULONG ObjectSize, IN ULONG PagedPoolCharge OPTIONAL, IN ULONG NonPagedPoolCharge OPTIONAL, OUT PVOID *Object)
Definition: oblife.c:951
Status
Definition: gdiplustypes.h:24
#define TRACE(s)
Definition: solgame.cpp:4
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
DWORD dwSessionId
Definition: winsta.h:17
PKEVENT gpDesktopThreadStartedEvent
Definition: desktop.c:39
#define ObDereferenceObject
Definition: obfuncs.h:203
#define UserEnterCo
Definition: ntuser.h:8
#define ST_RIT
Definition: csr.h:35
VOID FASTCALL SetLastNtError(NTSTATUS Status)
Definition: error.c:37
#define ERR(fmt,...)
Definition: debug.h:110
PRTL_ATOM_TABLE AtomTable
Definition: winsta.h:20
NTSTATUS NTAPI ObInsertObject(IN PVOID Object, IN PACCESS_STATE AccessState OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG ObjectPointerBias, OUT PVOID *NewObject OPTIONAL, OUT PHANDLE Handle)
Definition: obhandle.c:2935
#define NtCurrentPeb()
Definition: FLS.c:22
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
HANDLE NTAPI PsGetCurrentProcessId(VOID)
Definition: process.c:1123
#define NULL
Definition: types.h:112
#define ST_DESKTOP_THREAD
Definition: csr.h:36
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_SUCCESS
Definition: shellext.h:65
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:28
HANDLE gpidLogon
Definition: simplecall.c:15

Referenced by IntResolveDesktop(), and NtUserCreateWindowStation().

◆ IntEndDesktopGraphics()

VOID FASTCALL IntEndDesktopGraphics ( VOID  )

Definition at line 358 of file winsta.c.

359 {
360  if (NULL != ScreenDeviceContext)
361  { // No need to allocate a new dcattr.
365  }
368 }
BOOL NTAPI GreDeleteObject(HGDIOBJ hobj)
Definition: gdiobj.c:1158
#define GDI_OBJ_HMGR_POWNED
Definition: ntgdihdl.h:117
BOOL NTAPI GreSetDCOwner(HDC hdc, ULONG ulOwner)
Definition: dclife.c:455
#define NULL
Definition: types.h:112
PDESKTOP FASTCALL IntGetActiveDesktop(VOID)
Definition: desktop.c:1262
HDC ScreenDeviceContext
Definition: desktop.c:36
VOID FASTCALL IntDestroyPrimarySurface(VOID)
Definition: device.c:32
NTSTATUS FASTCALL IntHideDesktop(PDESKTOP Desktop)
Definition: desktop.c:1635

Referenced by RemoveGuiApp().

◆ IntGetProcessWindowStation()

PWINSTATION_OBJECT FASTCALL IntGetProcessWindowStation ( HWINSTA *phWinSta  OPTIONAL)

Definition at line 400 of file winsta.c.

401 {
402  PWINSTATION_OBJECT pWinSta;
404  HWINSTA hWinSta = ppi->hwinsta;
405  if (phWinSta)
406  *phWinSta = hWinSta;
407  IntValidateWindowStationHandle(hWinSta, UserMode, 0, &pWinSta, 0);
408  return pWinSta;
409 }
NTSTATUS FASTCALL IntValidateWindowStationHandle(HWINSTA WindowStation, KPROCESSOR_MODE AccessMode, ACCESS_MASK DesiredAccess, PWINSTATION_OBJECT *Object, POBJECT_HANDLE_INFORMATION pObjectHandleInfo)
Definition: winsta.c:232
struct _PROCESSINFO * GetW32ProcessInfo(VOID)
Definition: misc.c:795
HWINSTA hwinsta
Definition: win32.h:267

Referenced by NtUserActivateKeyboardLayout(), NtUserGetImeInfoEx(), NtUserGetKeyboardLayoutList(), NtUserSetImeInfoEx(), NtUserUnloadKeyboardLayout(), and UserSetDefaultInputLang().

◆ IntValidateWindowStationHandle()

NTSTATUS FASTCALL IntValidateWindowStationHandle ( HWINSTA  WindowStation,
KPROCESSOR_MODE  AccessMode,
ACCESS_MASK  DesiredAccess,
PWINSTATION_OBJECT Object,
POBJECT_HANDLE_INFORMATION  pObjectHandleInfo 
)

Definition at line 232 of file winsta.c.

238 {
240 
241  if (WindowStation == NULL)
242  {
243  ERR("Invalid window station handle\n");
245  return STATUS_INVALID_HANDLE;
246  }
247 
248  Status = ObReferenceObjectByHandle(WindowStation,
251  AccessMode,
252  (PVOID*)Object,
253  pObjectHandleInfo);
254 
255  if (!NT_SUCCESS(Status))
257 
258  return Status;
259 }
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2654
POBJECT_TYPE ExWindowStationObjectType
Definition: win32k.c:21
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:245
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:494
_In_ PEPROCESS _In_ KPROCESSOR_MODE AccessMode
Definition: mmfuncs.h:395
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID FASTCALL SetLastNtError(NTSTATUS Status)
Definition: error.c:37
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
#define ERR(fmt,...)
Definition: debug.h:110
#define NULL
Definition: types.h:112
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:28

Referenced by BuildDesktopNameList(), IntGetProcessWindowStation(), IntGetWinStaForCbAccess(), NtUserCloseWindowStation(), NtUserLockWindowStation(), NtUserSetShellWindowEx(), NtUserSetWindowsHookEx(), NtUserSetWindowStationUser(), NtUserUnlockWindowStation(), UserCreateMenu(), UserGetShellWindow(), and UserSetProcessWindowStation().

◆ IntWinStaObjectDelete()

NTSTATUS NTAPI IntWinStaObjectDelete ( _In_ PVOID  Parameters)

Definition at line 106 of file winsta.c.

108 {
109  PWIN32_DELETEMETHOD_PARAMETERS DeleteParameters = Parameters;
110  PWINSTATION_OBJECT WinSta = (PWINSTATION_OBJECT)DeleteParameters->Object;
111 
112  TRACE("Deleting window station 0x%p\n", WinSta);
113 
114  if (WinSta == InputWindowStation)
115  {
116  ERR("WARNING: Deleting the interactive window station '%wZ'!\n",
118 
119  /* Only Winlogon can close and delete the interactive window station */
121 
123  }
124 
125  WinSta->Flags |= WSS_DYING;
126 
127  UserEmptyClipboardData(WinSta);
128 
130 
131  UserAssignmentUnlock((PVOID*)&WinSta->spklList);
132 
133  return STATUS_SUCCESS;
134 }
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:863
VOID NTAPI UserEmptyClipboardData(PWINSTATION_OBJECT pWinSta)
Definition: clipboard.c:354
PWINSTATION_OBJECT InputWindowStation
Definition: winsta.c:21
#define WSS_DYING
Definition: winsta.h:11
#define OBJECT_HEADER_TO_NAME_INFO(h)
Definition: obtypes.h:114
struct tagKL * spklList
Definition: winsta.h:23
#define OBJECT_TO_OBJECT_HEADER(o)
Definition: obtypes.h:111
#define TRACE(s)
Definition: solgame.cpp:4
#define ASSERT(a)
Definition: mode.c:44
struct _WINSTATION_OBJECT * PWINSTATION_OBJECT
#define ERR(fmt,...)
Definition: debug.h:110
PRTL_ATOM_TABLE AtomTable
Definition: winsta.h:20
HANDLE NTAPI PsGetCurrentProcessId(VOID)
Definition: process.c:1123
#define NULL
Definition: types.h:112
PVOID FASTCALL UserAssignmentUnlock(PVOID *ppvObj)
Definition: object.c:861
NTSYSAPI NTSTATUS NTAPI RtlDestroyAtomTable(IN PRTL_ATOM_TABLE AtomTable)
Definition: atom.c:203
#define STATUS_SUCCESS
Definition: shellext.h:65
HANDLE gpidLogon
Definition: simplecall.c:15

Referenced by DriverEntry().

◆ IntWinStaObjectParse()

NTSTATUS NTAPI IntWinStaObjectParse ( _In_ PVOID  Parameters)

Definition at line 138 of file winsta.c.

140 {
141  PWIN32_PARSEMETHOD_PARAMETERS ParseParameters = Parameters;
142  PUNICODE_STRING RemainingName = ParseParameters->RemainingName;
143 
144  /* Assume we don't find anything */
145  *ParseParameters->Object = NULL;
146 
147  /* Check for an empty name */
148  if (!RemainingName->Length)
149  {
150  /* Make sure this is a window station, can't parse a desktop now */
151  if (ParseParameters->ObjectType != ExWindowStationObjectType)
152  {
153  /* Fail */
155  }
156 
157  /* Reference the window station and return */
158  ObReferenceObject(ParseParameters->ParseObject);
159  *ParseParameters->Object = ParseParameters->ParseObject;
160  return STATUS_SUCCESS;
161  }
162 
163  /* Check for leading slash */
164  if (RemainingName->Buffer[0] == OBJ_NAME_PATH_SEPARATOR)
165  {
166  /* Skip it */
167  RemainingName->Buffer++;
168  RemainingName->Length -= sizeof(WCHAR);
169  RemainingName->MaximumLength -= sizeof(WCHAR);
170  }
171 
172  /* Check if there is still a slash */
174  {
175  /* In this case, fail */
177  }
178 
179  /*
180  * Check if we are parsing a desktop.
181  */
182  if (ParseParameters->ObjectType == ExDesktopObjectType)
183  {
184  /* Then call the desktop parse routine */
185  return IntDesktopObjectParse(ParseParameters->ParseObject,
186  ParseParameters->ObjectType,
187  ParseParameters->AccessState,
188  ParseParameters->AccessMode,
189  ParseParameters->Attributes,
190  ParseParameters->CompleteName,
192  ParseParameters->Context,
193  ParseParameters->SecurityQos,
194  ParseParameters->Object);
195  }
196 
197  /* Should hopefully never get here */
199 }
POBJECT_TYPE ExWindowStationObjectType
Definition: win32k.c:21
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:863
NTSTATUS APIENTRY IntDesktopObjectParse(IN PVOID ParseObject, IN PVOID ObjectType, IN OUT PACCESS_STATE AccessState, IN KPROCESSOR_MODE AccessMode, IN ULONG Attributes, IN OUT PUNICODE_STRING CompleteName, IN OUT PUNICODE_STRING RemainingName, IN OUT PVOID Context OPTIONAL, IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL, OUT PVOID *Object)
Definition: desktop.c:45
POBJECT_TYPE ExDesktopObjectType
Definition: win32k.c:22
KPROCESSOR_MODE AccessMode
Definition: pstypes.h:1672
#define OBJ_NAME_PATH_SEPARATOR
Definition: arcname_tests.c:25
#define STATUS_OBJECT_TYPE_MISMATCH
Definition: ntstatus.h:273
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
__wchar_t WCHAR
Definition: xmlstorage.h:180
PSECURITY_QUALITY_OF_SERVICE SecurityQos
Definition: pstypes.h:1677
#define STATUS_OBJECT_PATH_INVALID
Definition: ntstatus.h:293
#define NULL
Definition: types.h:112
#define ObReferenceObject
Definition: obfuncs.h:204
#define STATUS_SUCCESS
Definition: shellext.h:65
PUNICODE_STRING RemainingName
Definition: pstypes.h:1675
_Out_ PUNICODE_STRING CompleteName
Definition: pstypes.h:1674
_Inout_ PFCB _Inout_ PUNICODE_STRING RemainingName
Definition: cdprocs.h:801

Referenced by DriverEntry().

◆ IntWinStaOkToClose()

NTSTATUS NTAPI IntWinStaOkToClose ( _In_ PVOID  Parameters)

Definition at line 203 of file winsta.c.

205 {
206  PWIN32_OKAYTOCLOSEMETHOD_PARAMETERS OkToCloseParameters = Parameters;
207  PPROCESSINFO ppi;
208 
210 
211  if (ppi && (OkToCloseParameters->Handle == ppi->hwinsta))
212  {
213  return STATUS_ACCESS_DENIED;
214  }
215 
216  return STATUS_SUCCESS;
217 }
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:863
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
HWINSTA hwinsta
Definition: win32.h:267
PVOID NTAPI PsGetCurrentProcessWin32Process(VOID)
Definition: process.c:1183
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by DriverEntry().

◆ UserCreateWinstaDirectory()

NTSTATUS NTAPI UserCreateWinstaDirectory ( VOID  )

Definition at line 51 of file winsta.c.

52 {
54  PPEB Peb;
56  HANDLE hWinstaDir;
57  WCHAR wstrWindowStationsDir[MAX_PATH];
58 
59  /* Create the WindowStations directory and cache its path for later use */
60  Peb = NtCurrentPeb();
61  if(Peb->SessionId == 0)
62  {
64  {
66  }
67  }
68  else
69  {
70  Status = RtlStringCbPrintfW(wstrWindowStationsDir,
71  sizeof(wstrWindowStationsDir),
72  L"%ws\\%lu%ws",
74  Peb->SessionId,
76  if (!NT_SUCCESS(Status))
77  return Status;
78 
79  if (!RtlCreateUnicodeString(&gustrWindowStationsDir, wstrWindowStationsDir))
80  {
82  }
83  }
84 
88  NULL,
89  NULL);
91  if (!NT_SUCCESS(Status))
92  {
93  ERR("Could not create %wZ directory (Status 0x%X)\n", &gustrWindowStationsDir, Status);
94  return Status;
95  }
96 
97  TRACE("Created directory %wZ for session %lu\n", &gustrWindowStationsDir, Peb->SessionId);
98 
99  return Status;
100 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
PPEB Peb
Definition: dllmain.c:27
#define DIRECTORY_CREATE_OBJECT
Definition: nt_native.h:1256
UNICODE_STRING gustrWindowStationsDir
Definition: winsta.c:27
LONG NTSTATUS
Definition: precomp.h:26
#define SESSION_DIR
Definition: dllmain.c:38
#define WINSTA_OBJ_DIR
Definition: winsta.h:3
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define L(x)
Definition: ntvdm.h:50
NTSYSAPI NTSTATUS NTAPI ZwCreateDirectoryObject(_Out_ PHANDLE DirectoryHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
Status
Definition: gdiplustypes.h:24
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTRSAFEVAPI RtlStringCbPrintfW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1173
#define MAX_PATH
Definition: compat.h:34
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
ULONG SessionId
Definition: btrfs_drv.h:1919
#define ERR(fmt,...)
Definition: debug.h:110
#define NtCurrentPeb()
Definition: FLS.c:22
#define NULL
Definition: types.h:112
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106

Referenced by UserInitialize().

◆ UserSetProcessWindowStation()

BOOL FASTCALL UserSetProcessWindowStation ( HWINSTA  hWindowStation)

Definition at line 1382 of file winsta.c.

1383 {
1384  NTSTATUS Status;
1385  PPROCESSINFO ppi;
1386  OBJECT_HANDLE_INFORMATION ObjectHandleInfo;
1387  PWINSTATION_OBJECT NewWinSta = NULL, OldWinSta;
1388  HWINSTA hCacheWinSta;
1389 
1391 
1392  /* Reference the new window station */
1393  if (hWindowStation != NULL)
1394  {
1395  Status = IntValidateWindowStationHandle(hWindowStation,
1396  UserMode,
1397  0,
1398  &NewWinSta,
1399  &ObjectHandleInfo);
1400  if (!NT_SUCCESS(Status))
1401  {
1402  TRACE("Validation of window station handle 0x%p failed\n", hWindowStation);
1404  return FALSE;
1405  }
1406  }
1407 
1408  OldWinSta = ppi->prpwinsta;
1409  hCacheWinSta = PsGetProcessWin32WindowStation(ppi->peProcess);
1410 
1411  /* Dereference the previous window station */
1412  if (OldWinSta != NULL)
1413  {
1414  ObDereferenceObject(OldWinSta);
1415  }
1416 
1417  /*
1418  * FIXME: Don't allow changing the window station if there are threads that are attached to desktops and own GUI objects?
1419  */
1420 
1421  /* Close the cached EPROCESS window station handle if needed */
1422  if (hCacheWinSta != NULL)
1423  {
1424  /* Reference the window station */
1425  Status = ObReferenceObjectByHandle(hCacheWinSta,
1426  0,
1428  UserMode,
1429  (PVOID*)&OldWinSta,
1430  NULL);
1431  if (!NT_SUCCESS(Status))
1432  {
1433  ERR("Failed to reference the inherited window station, Status 0x%08lx\n", Status);
1434  /* We failed, reset the cache */
1435  hCacheWinSta = NULL;
1436  PsSetProcessWindowStation(ppi->peProcess, hCacheWinSta);
1437  }
1438  else
1439  {
1440  /*
1441  * Close the old handle and reset the cache only
1442  * if we are setting a different window station.
1443  */
1444  if (NewWinSta != OldWinSta)
1445  {
1446  ObCloseHandle(hCacheWinSta, UserMode);
1447  hCacheWinSta = NULL;
1448  PsSetProcessWindowStation(ppi->peProcess, hCacheWinSta);
1449  }
1450 
1451  /* Dereference the window station */
1452  ObDereferenceObject(OldWinSta);
1453  }
1454  }
1455 
1456  /* Duplicate and save a new cached EPROCESS window station handle */
1457  if ((hCacheWinSta == NULL) && (hWindowStation != NULL))
1458  {
1459  Status = ZwDuplicateObject(ZwCurrentProcess(),
1460  hWindowStation,
1461  ZwCurrentProcess(),
1462  (PHANDLE)&hCacheWinSta,
1463  0,
1464  0,
1466  if (!NT_SUCCESS(Status))
1467  {
1468  ERR("UserSetProcessWindowStation: Failed to duplicate the window station handle, Status 0x%08lx\n", Status);
1469  }
1470  else
1471  {
1472  PsSetProcessWindowStation(ppi->peProcess, hCacheWinSta);
1473  }
1474  }
1475 
1476  ppi->prpwinsta = NewWinSta;
1477  ppi->hwinsta = hWindowStation;
1478  ppi->amwinsta = hWindowStation != NULL ? ObjectHandleInfo.GrantedAccess : 0;
1479  TRACE("WS : Granted Access 0x%08lx\n",ppi->amwinsta);
1480 
1482  {
1483  ppi->W32PF_flags |= W32PF_READSCREENACCESSGRANTED;
1484  }
1485  else
1486  {
1487  ppi->W32PF_flags &= ~W32PF_READSCREENACCESSGRANTED;
1488  }
1489 
1490  if (NewWinSta && !(NewWinSta->Flags & WSS_NOIO))
1491  {
1492  ppi->W32PF_flags |= W32PF_IOWINSTA;
1493  }
1494  else /* Might be closed if the handle is NULL */
1495  {
1496  ppi->W32PF_flags &= ~W32PF_IOWINSTA;
1497  }
1498  return TRUE;
1499 }
POBJECT_TYPE ExWindowStationObjectType
Definition: win32k.c:21
#define TRUE
Definition: types.h:120
#define ZwCurrentProcess()
#define W32PF_IOWINSTA
Definition: win32.h:23
LONG NTSTATUS
Definition: precomp.h:26
struct _WINSTATION_OBJECT * prpwinsta
Definition: win32.h:266
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:494
#define DUPLICATE_SAME_ACCESS
ACCESS_MASK GrantedAccess
Definition: iotypes.h:181
#define FALSE
Definition: types.h:117
#define WSS_NOIO
Definition: winsta.h:9
NTSTATUS FASTCALL IntValidateWindowStationHandle(HWINSTA WindowStation, KPROCESSOR_MODE AccessMode, ACCESS_MASK DesiredAccess, PWINSTATION_OBJECT *Object, POBJECT_HANDLE_INFORMATION pObjectHandleInfo)
Definition: winsta.c:232
Status
Definition: gdiplustypes.h:24
#define TRACE(s)
Definition: solgame.cpp:4
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ObDereferenceObject
Definition: obfuncs.h:203
VOID NTAPI PsSetProcessWindowStation(PEPROCESS Process, PVOID WindowStation)
Definition: process.c:1314
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3379
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:454
PVOID NTAPI PsGetProcessWin32WindowStation(PEPROCESS Process)
Definition: process.c:1203
VOID FASTCALL SetLastNtError(NTSTATUS Status)
Definition: error.c:37
#define ERR(fmt,...)
Definition: debug.h:110
HWINSTA hwinsta
Definition: win32.h:267
#define W32PF_READSCREENACCESSGRANTED
Definition: win32.h:8
#define NULL
Definition: types.h:112
PVOID NTAPI PsGetCurrentProcessWin32Process(VOID)
Definition: process.c:1183
NTSYSAPI BOOLEAN NTAPI RtlAreAllAccessesGranted(ACCESS_MASK GrantedAccess, ACCESS_MASK DesiredAccess)
ACCESS_MASK amwinsta
Definition: win32.h:268
#define WINSTA_READSCREEN
Definition: winuser.h:415

Referenced by InitThreadCallback(), NtUserSetProcessWindowStation(), RawInputThreadMain(), and UserProcessDestroy().

Variable Documentation

◆ gpidLogon

◆ gustrWindowStationsDir

◆ hwndSAS

◆ InputWindowStation