ReactOS  0.4.15-dev-3165-gdf6fff7
winsta.c File Reference
#include <win32k.h>
Include dependency graph for winsta.c:

Go to the source code of this file.

Functions

 DBG_DEFAULT_CHANNEL (UserWinsta)
 
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)
 
BOOL FASTCALL co_IntInitializeDesktopGraphics (VOID)
 
VOID FASTCALL IntEndDesktopGraphics (VOID)
 
HDC FASTCALL IntGetScreenDC (VOID)
 
BOOL FASTCALL CheckWinstaAttributeAccess (ACCESS_MASK DesiredAccess)
 
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)
 
static VOID FreeUserModeWindowStationName (IN OUT PUNICODE_STRING WindowStationName, IN PUNICODE_STRING TebStaticUnicodeString, IN OUT POBJECT_ATTRIBUTES UserModeObjectAttributes OPTIONAL, IN POBJECT_ATTRIBUTES LocalObjectAttributes OPTIONAL)
 
static NTSTATUS BuildUserModeWindowStationName (IN OUT POBJECT_ATTRIBUTES UserModeObjectAttributes, IN OUT POBJECT_ATTRIBUTES LocalObjectAttributes, OUT PUNICODE_STRING *WindowStationName, OUT PUNICODE_STRING *TebStaticUnicodeString)
 
HWINSTA APIENTRY NtUserCreateWindowStation (IN POBJECT_ATTRIBUTES ObjectAttributes, IN ACCESS_MASK dwDesiredAccess, DWORD Unknown2, DWORD Unknown3, DWORD Unknown4, DWORD Unknown5, DWORD Unknown6)
 
HWINSTA APIENTRY NtUserOpenWindowStation (IN POBJECT_ATTRIBUTES ObjectAttributes, IN ACCESS_MASK dwDesiredAccess)
 
BOOL APIENTRY NtUserCloseWindowStation (HWINSTA hWinSta)
 
BOOL APIENTRY NtUserGetObjectInformation (HANDLE hObject, DWORD nIndex, PVOID pvInformation, DWORD nLength, PDWORD nLengthNeeded)
 
BOOL APIENTRY NtUserSetObjectInformation (HANDLE hObject, DWORD nIndex, PVOID pvInformation, DWORD nLength)
 
HWINSTA FASTCALL UserGetProcessWindowStation (VOID)
 
HWINSTA APIENTRY NtUserGetProcessWindowStation (VOID)
 
BOOL FASTCALL UserSetProcessWindowStation (HWINSTA hWindowStation)
 
BOOL APIENTRY NtUserSetProcessWindowStation (HWINSTA hWindowStation)
 
BOOL APIENTRY NtUserLockWindowStation (HWINSTA hWindowStation)
 
BOOL APIENTRY NtUserUnlockWindowStation (HWINSTA hWindowStation)
 
static NTSTATUS FASTCALL BuildWindowStationNameList (ULONG dwSize, PVOID lpBuffer, PULONG pRequiredSize)
 
static NTSTATUS FASTCALL BuildDesktopNameList (HWINSTA hWindowStation, ULONG dwSize, PVOID lpBuffer, PULONG pRequiredSize)
 
NTSTATUS APIENTRY NtUserBuildNameList (HWINSTA hWindowStation, ULONG dwSize, PVOID lpBuffer, PULONG pRequiredSize)
 
BOOL APIENTRY NtUserSetLogonNotifyWindow (HWND hWnd)
 
BOOL APIENTRY NtUserLockWorkStation (VOID)
 
BOOL NTAPI NtUserSetWindowStationUser (IN HWINSTA hWindowStation, IN PLUID pluid, IN PSID psid OPTIONAL, IN DWORD size)
 

Variables

PWINSTATION_OBJECT InputWindowStation = NULL
 
HWND hwndSAS = NULL
 
UNICODE_STRING gustrWindowStationsDir
 

Function Documentation

◆ BuildDesktopNameList()

static NTSTATUS FASTCALL BuildDesktopNameList ( HWINSTA  hWindowStation,
ULONG  dwSize,
PVOID  lpBuffer,
PULONG  pRequiredSize 
)
static

Definition at line 1790 of file winsta.c.

1795 {
1796  NTSTATUS Status;
1797  PWINSTATION_OBJECT WindowStation;
1798  PLIST_ENTRY DesktopEntry;
1799  PDESKTOP DesktopObject;
1800  DWORD EntryCount;
1802  WCHAR NullWchar;
1803  UNICODE_STRING DesktopName;
1804 
1805  Status = IntValidateWindowStationHandle(hWindowStation,
1806  UserMode,
1807  0,
1808  &WindowStation,
1809  NULL);
1810  if (! NT_SUCCESS(Status))
1811  {
1812  return Status;
1813  }
1814 
1815  /*
1816  * Count the required size of buffer.
1817  */
1818  ReturnLength = sizeof(DWORD);
1819  EntryCount = 0;
1820  for (DesktopEntry = WindowStation->DesktopListHead.Flink;
1821  DesktopEntry != &WindowStation->DesktopListHead;
1822  DesktopEntry = DesktopEntry->Flink)
1823  {
1824  DesktopObject = CONTAINING_RECORD(DesktopEntry, DESKTOP, ListEntry);
1825  RtlInitUnicodeString(&DesktopName, DesktopObject->pDeskInfo->szDesktopName);
1826  ReturnLength += DesktopName.Length + sizeof(WCHAR);
1827  EntryCount++;
1828  }
1829  TRACE("Required size: %lu Entry count: %lu\n", ReturnLength, EntryCount);
1830  if (NULL != pRequiredSize)
1831  {
1832  Status = MmCopyToCaller(pRequiredSize, &ReturnLength, sizeof(ULONG));
1833  if (! NT_SUCCESS(Status))
1834  {
1835  ObDereferenceObject(WindowStation);
1836  return STATUS_BUFFER_TOO_SMALL;
1837  }
1838  }
1839 
1840  /*
1841  * Check if the supplied buffer is large enough.
1842  */
1843  if (dwSize < ReturnLength)
1844  {
1845  ObDereferenceObject(WindowStation);
1846  return STATUS_BUFFER_TOO_SMALL;
1847  }
1848 
1849  /*
1850  * Generate the resulting buffer contents.
1851  */
1852  Status = MmCopyToCaller(lpBuffer, &EntryCount, sizeof(DWORD));
1853  if (! NT_SUCCESS(Status))
1854  {
1855  ObDereferenceObject(WindowStation);
1856  return Status;
1857  }
1858  lpBuffer = (PVOID) ((PCHAR) lpBuffer + sizeof(DWORD));
1859 
1860  NullWchar = L'\0';
1861  for (DesktopEntry = WindowStation->DesktopListHead.Flink;
1862  DesktopEntry != &WindowStation->DesktopListHead;
1863  DesktopEntry = DesktopEntry->Flink)
1864  {
1865  DesktopObject = CONTAINING_RECORD(DesktopEntry, DESKTOP, ListEntry);
1866  RtlInitUnicodeString(&DesktopName, DesktopObject->pDeskInfo->szDesktopName);
1867  Status = MmCopyToCaller(lpBuffer, DesktopName.Buffer, DesktopName.Length);
1868  if (! NT_SUCCESS(Status))
1869  {
1870  ObDereferenceObject(WindowStation);
1871  return Status;
1872  }
1873  lpBuffer = (PVOID) ((PCHAR)lpBuffer + DesktopName.Length);
1874  Status = MmCopyToCaller(lpBuffer, &NullWchar, sizeof(WCHAR));
1875  if (! NT_SUCCESS(Status))
1876  {
1877  ObDereferenceObject(WindowStation);
1878  return Status;
1879  }
1880  lpBuffer = (PVOID) ((PCHAR) lpBuffer + sizeof(WCHAR));
1881  }
1882 
1883  /*
1884  * Clean up and return
1885  */
1886  ObDereferenceObject(WindowStation);
1887  return STATUS_SUCCESS;
1888 }
signed char * PCHAR
Definition: retypes.h:7
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:39
PDESKTOPINFO pDeskInfo
Definition: desktop.h:8
LONG NTSTATUS
Definition: precomp.h:26
#define MmCopyToCaller(x, y, z)
Definition: mmcopy.h:19
LIST_ENTRY DesktopListHead
Definition: winsta.h:18
#define DWORD
Definition: nt_native.h:44
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:175
NTSTATUS FASTCALL IntValidateWindowStationHandle(HWINSTA WindowStation, KPROCESSOR_MODE AccessMode, ACCESS_MASK DesiredAccess, PWINSTATION_OBJECT *Object, POBJECT_HANDLE_INFORMATION pObjectHandleInfo)
Definition: winsta.c:230
void * PVOID
Definition: retypes.h:9
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
Status
Definition: gdiplustypes.h:24
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ObDereferenceObject
Definition: obfuncs.h:203
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
Definition: typedefs.h:119
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define STATUS_SUCCESS
Definition: shellext.h:65
WCHAR szDesktopName[1]
Definition: ntuser.h:154
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56

Referenced by NtUserBuildNameList().

◆ BuildUserModeWindowStationName()

static NTSTATUS BuildUserModeWindowStationName ( IN OUT POBJECT_ATTRIBUTES  UserModeObjectAttributes,
IN OUT POBJECT_ATTRIBUTES  LocalObjectAttributes,
OUT PUNICODE_STRING WindowStationName,
OUT PUNICODE_STRING TebStaticUnicodeString 
)
static

Definition at line 588 of file winsta.c.

593 {
595  SIZE_T MemSize;
596 
597  LUID CallerLuid;
598  PTEB Teb;
599  USHORT StrSize;
600 
601  *WindowStationName = NULL;
602  *TebStaticUnicodeString = NULL;
603 
604  /* Retrieve the current process LUID */
605  Status = GetProcessLuid(NULL, NULL, &CallerLuid);
606  if (!NT_SUCCESS(Status))
607  {
608  ERR("Failed to retrieve the caller LUID, Status 0x%08lx\n", Status);
609  return Status;
610  }
611 
612  /* Compute the needed string size */
613  MemSize = _scwprintf(L"%wZ\\Service-0x%x-%x$",
615  CallerLuid.HighPart,
616  CallerLuid.LowPart);
617  MemSize = MemSize * sizeof(WCHAR) + sizeof(UNICODE_NULL);
618  if (MemSize > MAXUSHORT)
619  {
620  ERR("Window station name length is too long.\n");
621  return STATUS_NAME_TOO_LONG;
622  }
623  StrSize = (USHORT)MemSize;
624 
625  /*
626  * Check whether it's short enough so that we can use the static buffer
627  * in the TEB. Otherwise continue with virtual memory allocation.
628  */
629  Teb = NtCurrentTeb();
630  if (Teb && (StrSize <= sizeof(Teb->StaticUnicodeBuffer)))
631  {
632  /* We can use the TEB's static unicode string */
635 
636  /* Remember the TEB's static unicode string address for later */
637  *TebStaticUnicodeString = &Teb->StaticUnicodeString;
638 
639  *WindowStationName = *TebStaticUnicodeString;
640  (*WindowStationName)->Length = 0;
641  }
642  else
643  {
644  /* The TEB's static unicode string is too small, allocate some user-mode virtual memory */
645  MemSize += ALIGN_UP(sizeof(UNICODE_STRING), sizeof(PVOID));
646 
647  /* Allocate the memory in user-mode */
648  Status = ZwAllocateVirtualMemory(ZwCurrentProcess(),
649  (PVOID*)WindowStationName,
650  0,
651  &MemSize,
652  MEM_COMMIT,
654  if (!NT_SUCCESS(Status))
655  {
656  ERR("ZwAllocateVirtualMemory() failed, Status 0x%08lx\n", Status);
657  return Status;
658  }
659 
660  RtlInitEmptyUnicodeString(*WindowStationName,
661  (PWCHAR)((ULONG_PTR)*WindowStationName +
662  ALIGN_UP(sizeof(UNICODE_STRING), sizeof(PVOID))),
663  StrSize);
664  }
665 
666  /* Build a valid window station name from the LUID */
667  Status = RtlStringCbPrintfW((*WindowStationName)->Buffer,
668  (*WindowStationName)->MaximumLength,
669  L"%wZ\\Service-0x%x-%x$",
671  CallerLuid.HighPart,
672  CallerLuid.LowPart);
673  if (!NT_SUCCESS(Status))
674  {
675  ERR("Impossible to build a valid window station name, Status 0x%08lx\n", Status);
676  goto Quit;
677  }
678  (*WindowStationName)->Length = (USHORT)(wcslen((*WindowStationName)->Buffer) * sizeof(WCHAR));
679 
680  /* Try to update the user's UserModeObjectAttributes */
681  _SEH2_TRY
682  {
683  ProbeForWrite(UserModeObjectAttributes, sizeof(OBJECT_ATTRIBUTES), sizeof(ULONG));
684  *LocalObjectAttributes = *UserModeObjectAttributes;
685 
686  UserModeObjectAttributes->ObjectName = *WindowStationName;
687  UserModeObjectAttributes->RootDirectory = NULL;
688 
690  }
692  {
694  }
695  _SEH2_END;
696 
697 Quit:
698  if (!NT_SUCCESS(Status))
699  {
700  /* Release the window station name */
701  FreeUserModeWindowStationName(*WindowStationName,
702  *TebStaticUnicodeString,
703  NULL, NULL);
704  }
705 
706  return Status;
707 }
WCHAR StaticUnicodeBuffer[261]
Definition: compat.h:736
#define ALIGN_UP(size, type)
Definition: umtypes.h:91
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define ZwCurrentProcess()
UNICODE_STRING gustrWindowStationsDir
Definition: winsta.c:27
LONG NTSTATUS
Definition: precomp.h:26
uint16_t * PWCHAR
Definition: typedefs.h:56
#define MEM_COMMIT
Definition: nt_native.h:1313
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
_SEH2_TRY
Definition: create.c:4226
uint32_t ULONG_PTR
Definition: typedefs.h:65
UNICODE_STRING StaticUnicodeString
Definition: compat.h:735
#define UNICODE_NULL
#define STATUS_NAME_TOO_LONG
Definition: ntstatus.h:498
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
DWORD LowPart
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 EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
static const WCHAR L[]
Definition: oid.c:1250
LONG HighPart
#define ERR(fmt,...)
Definition: debug.h:110
ULONG_PTR SIZE_T
Definition: typedefs.h:80
Definition: compat.h:694
_SEH2_END
Definition: create.c:4400
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
unsigned short USHORT
Definition: pedump.c:61
NTSTATUS GetProcessLuid(IN PETHREAD Thread OPTIONAL, IN PEPROCESS Process OPTIONAL, OUT PLUID Luid)
Definition: misc.c:790
#define NULL
Definition: types.h:112
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define MAXUSHORT
Definition: typedefs.h:83
static VOID FreeUserModeWindowStationName(IN OUT PUNICODE_STRING WindowStationName, IN PUNICODE_STRING TebStaticUnicodeString, IN OUT POBJECT_ATTRIBUTES UserModeObjectAttributes OPTIONAL, IN POBJECT_ATTRIBUTES LocalObjectAttributes OPTIONAL)
Definition: winsta.c:554
unsigned int ULONG
Definition: retypes.h:1
_Check_return_ _CRTIMP int __cdecl _scwprintf(_In_z_ _Printf_format_string_ const wchar_t *_Format,...)
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define PAGE_READWRITE
Definition: nt_native.h:1304

Referenced by NtUserCreateWindowStation(), and NtUserOpenWindowStation().

◆ BuildWindowStationNameList()

static NTSTATUS FASTCALL BuildWindowStationNameList ( ULONG  dwSize,
PVOID  lpBuffer,
PULONG  pRequiredSize 
)
static

Definition at line 1602 of file winsta.c.

1606 {
1608  NTSTATUS Status;
1610  char InitialBuffer[256], *Buffer;
1612  DWORD EntryCount;
1614  WCHAR NullWchar;
1615 
1616  //
1617  // FIXME: Fully wrong! Since, by calling NtUserCreateWindowStation
1618  // with judicious parameters one can create window stations elsewhere
1619  // than in Windows\WindowStations directory, Win32k definitely MUST
1620  // maintain a list of window stations it has created, and not rely
1621  // on the enumeration of Windows\WindowStations !!!
1622  //
1623 
1624  /*
1625  * Try to open the directory.
1626  */
1630  NULL,
1631  NULL);
1632 
1635  &ObjectAttributes);
1636 
1637  if (!NT_SUCCESS(Status))
1638  {
1639  return Status;
1640  }
1641 
1642  /* First try to query the directory using a fixed-size buffer */
1643  Context = 0;
1644  Buffer = NULL;
1645  Status = ZwQueryDirectoryObject(DirectoryHandle,
1646  InitialBuffer,
1647  sizeof(InitialBuffer),
1648  FALSE,
1649  TRUE,
1650  &Context,
1651  &ReturnLength);
1652  if (NT_SUCCESS(Status))
1653  {
1654  if (STATUS_NO_MORE_ENTRIES == ZwQueryDirectoryObject(DirectoryHandle, NULL, 0, FALSE,
1655  FALSE, &Context, NULL))
1656  {
1657  /* Our fixed-size buffer is large enough */
1658  Buffer = InitialBuffer;
1659  }
1660  }
1661 
1662  if (NULL == Buffer)
1663  {
1664  /* Need a larger buffer, check how large exactly */
1665  Status = ZwQueryDirectoryObject(DirectoryHandle, NULL, 0, FALSE, TRUE, &Context,
1666  &ReturnLength);
1667  if (!NT_SUCCESS(Status))
1668  {
1669  ERR("ZwQueryDirectoryObject failed\n");
1671  return Status;
1672  }
1673 
1676  if (NULL == Buffer)
1677  {
1679  return STATUS_NO_MEMORY;
1680  }
1681 
1682  /* We should have a sufficiently large buffer now */
1683  Context = 0;
1684  Status = ZwQueryDirectoryObject(DirectoryHandle, Buffer, BufferSize,
1686  if (! NT_SUCCESS(Status) ||
1687  STATUS_NO_MORE_ENTRIES != ZwQueryDirectoryObject(DirectoryHandle, NULL, 0, FALSE,
1688  FALSE, &Context, NULL))
1689  {
1690  /* Something went wrong, maybe someone added a directory entry? Just give up. */
1694  }
1695  }
1696 
1698 
1699  /*
1700  * Count the required size of buffer.
1701  */
1702  ReturnLength = sizeof(DWORD);
1703  EntryCount = 0;
1705  0 != DirEntry->Name.Length;
1706  DirEntry++)
1707  {
1708  ReturnLength += DirEntry->Name.Length + sizeof(WCHAR);
1709  EntryCount++;
1710  }
1711  TRACE("Required size: %lu Entry count: %lu\n", ReturnLength, EntryCount);
1712  if (NULL != pRequiredSize)
1713  {
1714  Status = MmCopyToCaller(pRequiredSize, &ReturnLength, sizeof(ULONG));
1715  if (! NT_SUCCESS(Status))
1716  {
1717  if (Buffer != InitialBuffer)
1718  {
1720  }
1721  return STATUS_BUFFER_TOO_SMALL;
1722  }
1723  }
1724 
1725  /*
1726  * Check if the supplied buffer is large enough.
1727  */
1728  if (dwSize < ReturnLength)
1729  {
1730  if (Buffer != InitialBuffer)
1731  {
1733  }
1734  return STATUS_BUFFER_TOO_SMALL;
1735  }
1736 
1737  /*
1738  * Generate the resulting buffer contents.
1739  */
1740  Status = MmCopyToCaller(lpBuffer, &EntryCount, sizeof(DWORD));
1741  if (! NT_SUCCESS(Status))
1742  {
1743  if (Buffer != InitialBuffer)
1744  {
1746  }
1747  return Status;
1748  }
1749  lpBuffer = (PVOID) ((PCHAR) lpBuffer + sizeof(DWORD));
1750 
1751  NullWchar = L'\0';
1753  0 != DirEntry->Name.Length;
1754  DirEntry++)
1755  {
1756  Status = MmCopyToCaller(lpBuffer, DirEntry->Name.Buffer, DirEntry->Name.Length);
1757  if (! NT_SUCCESS(Status))
1758  {
1759  if (Buffer != InitialBuffer)
1760  {
1762  }
1763  return Status;
1764  }
1765  lpBuffer = (PVOID) ((PCHAR) lpBuffer + DirEntry->Name.Length);
1766  Status = MmCopyToCaller(lpBuffer, &NullWchar, sizeof(WCHAR));
1767  if (! NT_SUCCESS(Status))
1768  {
1769  if (Buffer != InitialBuffer)
1770  {
1772  }
1773  return Status;
1774  }
1775  lpBuffer = (PVOID) ((PCHAR) lpBuffer + sizeof(WCHAR));
1776  }
1777 
1778  /*
1779  * Clean up
1780  */
1781  if (Buffer != InitialBuffer)
1782  {
1784  }
1785 
1786  return STATUS_SUCCESS;
1787 }
signed char * PCHAR
Definition: retypes.h:7
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:39
#define STATUS_NO_MORE_ENTRIES
Definition: ntstatus.h:205
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define TRUE
Definition: types.h:120
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define TAG_WINSTA
Definition: tags.h:11
UNICODE_STRING gustrWindowStationsDir
Definition: winsta.c:27
LONG NTSTATUS
Definition: precomp.h:26
static HANDLE DirectoryHandle
Definition: ObType.c:48
NTSYSAPI NTSTATUS NTAPI ZwOpenDirectoryObject(_Out_ PHANDLE FileHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
#define MmCopyToCaller(x, y, z)
Definition: mmcopy.h:19
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define DWORD
Definition: nt_native.h:44
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define STATUS_INTERNAL_ERROR
Definition: ntstatus.h:465
#define FALSE
Definition: types.h:117
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:175
Definition: bufpool.h:45
void * PVOID
Definition: retypes.h:9
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
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
static const WCHAR L[]
Definition: oid.c:1250
struct DirEntry DirEntry
Definition: storage32.h:133
#define ERR(fmt,...)
Definition: debug.h:110
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define NULL
Definition: types.h:112
struct tagContext Context
Definition: acpixf.h:1034
unsigned int ULONG
Definition: retypes.h:1
#define DIRECTORY_QUERY
Definition: nt_native.h:1254
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define STATUS_SUCCESS
Definition: shellext.h:65
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define BufferSize
Definition: mmc.h:75
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:251

Referenced by NtUserBuildNameList().

◆ CheckWinstaAttributeAccess()

BOOL FASTCALL CheckWinstaAttributeAccess ( ACCESS_MASK  DesiredAccess)

Definition at line 369 of file winsta.c.

370 {
372  if ( gpidLogon != PsGetCurrentProcessId() )
373  {
374  if (!(ppi->W32PF_flags & W32PF_IOWINSTA))
375  {
376  ERR("Requires Interactive Window Station\n");
378  return FALSE;
379  }
381  {
382  ERR("Access Denied\n");
384  return FALSE;
385  }
386  }
387  return TRUE;
388 }
_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:266
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:27
HANDLE gpidLogon
Definition: simplecall.c:15

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

◆ co_IntInitializeDesktopGraphics()

BOOL FASTCALL co_IntInitializeDesktopGraphics ( VOID  )

Definition at line 260 of file winsta.c.

261 {
262  TEXTMETRICW tmw;
263  UNICODE_STRING DriverName = RTL_CONSTANT_STRING(L"DISPLAY");
264  PDESKTOP pdesk;
265 
267  if (NULL == ScreenDeviceContext)
268  {
270  return FALSE;
271  }
273 
275  {
276  return FALSE;
277  }
278 
280 
283 
284  /* Update the system metrics */
285  InitMetrics();
286 
287  /* Set new size of the monitor */
289 
290  /* Update the SERVERINFO */
295  gpsi->BitCount = gpsi->Planes * gpsi->BitsPixel;
298  {
299  gpsi->PUSIFlags |= PUSIF_PALETTEDISPLAY;
300  }
301  else
302  {
303  gpsi->PUSIFlags &= ~PUSIF_PALETTEDISPLAY;
304  }
305  // Font is realized and this dc was previously set to internal DC_ATTR.
306  gpsi->cxSysFontChar = IntGetCharDimensions(hSystemBM, &tmw, (DWORD*)&gpsi->cySysFontChar);
307  gpsi->tmSysFont = tmw;
308 
309  /* Put the pointer in the center of the screen */
310  gpsi->ptCursor.x = gpsi->aiSysMet[SM_CXSCREEN] / 2;
311  gpsi->ptCursor.y = gpsi->aiSysMet[SM_CYSCREEN] / 2;
312 
313  /* Attach monitor */
315 
316  /* Setup the cursor */
318 
319  /* Setup the icons */
321 
322  /* Setup Menu */
323  MenuInit();
324 
325  /* Show the desktop */
326  pdesk = IntGetActiveDesktop();
327  ASSERT(pdesk);
328  co_IntShowDesktop(pdesk, gpsi->aiSysMet[SM_CXSCREEN], gpsi->aiSysMet[SM_CYSCREEN], TRUE);
329 
330  /* HACK: display wallpaper on all secondary displays */
331  {
332  PGRAPHICS_DEVICE pGraphicsDevice;
333  UNICODE_STRING DriverName = RTL_CONSTANT_STRING(L"DISPLAY");
334  UNICODE_STRING DisplayName;
335  HDC hdc;
336  ULONG iDevNum;
337 
338  for (iDevNum = 1; (pGraphicsDevice = EngpFindGraphicsDevice(NULL, iDevNum, 0)) != NULL; iDevNum++)
339  {
340  RtlInitUnicodeString(&DisplayName, pGraphicsDevice->szWinDeviceName);
341  hdc = IntGdiCreateDC(&DriverName, &DisplayName, NULL, NULL, FALSE);
343  }
344  }
345 
346  return TRUE;
347 }
BOOL MenuInit(VOID)
Definition: menu.c:359
#define BITSPIXEL
Definition: wingdi.h:719
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:124
PPDEVOBJ gppdevPrimary
Definition: pdevobj.c:13
__kernel_entry W32KAPI HANDLE APIENTRY NtGdiGetStockObject(_In_ INT iObject)
static HDC
Definition: imagelist.c:92
#define RASTERCAPS
Definition: wingdi.h:744
PSERVERINFO gpsi
Definition: main.c:27
NTSTATUS NTAPI UserAttachMonitor(IN HDEV hDev)
Definition: monitor.c:129
#define SM_CXSCREEN
Definition: winuser.h:949
PGRAPHICS_DEVICE NTAPI EngpFindGraphicsDevice(_In_opt_ PUNICODE_STRING pustrDevice, _In_ ULONG iDevNum, _In_ DWORD dwFlags)
Definition: device.c:469
#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:910
BOOL FASTCALL IntPaintDesktop(HDC hDC)
Definition: desktop.c:1795
__kernel_entry W32KAPI HFONT APIENTRY NtGdiSelectFont(_In_ HDC hdc, _In_ HFONT hf)
Definition: dcobjs.c:597
#define SM_CYSCREEN
Definition: winuser.h:950
#define ASSERT(a)
Definition: mode.c:44
HDC hSystemBM
Definition: stockobj.c:52
#define RC_PALETTE
Definition: wingdi.h:789
BOOL NTAPI InitMetrics(VOID)
Definition: metric.c:19
BOOL APIENTRY co_IntLoadDefaultCursors(VOID)
Definition: callback.c:471
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL FASTCALL IntCreatePrimarySurface(VOID)
Definition: device.c:29
static const WCHAR L[]
Definition: oid.c:1250
HDC hdc
Definition: main.c:9
NTSTATUS FASTCALL co_IntShowDesktop(PDESKTOP Desktop, ULONG Width, ULONG Height, BOOL bRedraw)
Definition: desktop.c:1585
__kernel_entry W32KAPI HDC APIENTRY NtGdiCreateCompatibleDC(_In_opt_ HDC hdc)
HDC FASTCALL IntGdiCreateDC(PUNICODE_STRING Driver, PUNICODE_STRING pustrDevice, PVOID pUMdhpdev, CONST PDEVMODEW pdmInit, BOOL CreateAsIC)
Definition: dclife.c:1040
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:963
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define LOGPIXELSY
Definition: wingdi.h:718
PDESKTOP FASTCALL IntGetActiveDesktop(VOID)
Definition: desktop.c:1230
__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:44
#define PLANES
Definition: wingdi.h:720
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by co_AddGuiApp().

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( UserWinsta  )

◆ FreeUserModeWindowStationName()

static VOID FreeUserModeWindowStationName ( IN OUT PUNICODE_STRING  WindowStationName,
IN PUNICODE_STRING  TebStaticUnicodeString,
IN OUT POBJECT_ATTRIBUTES UserModeObjectAttributes  OPTIONAL,
IN POBJECT_ATTRIBUTES LocalObjectAttributes  OPTIONAL 
)
static

Definition at line 554 of file winsta.c.

559 {
560  SIZE_T MemSize = 0;
561 
562  /* Try to restore the user's UserModeObjectAttributes */
563  if (UserModeObjectAttributes && LocalObjectAttributes)
564  {
565  _SEH2_TRY
566  {
567  ProbeForWrite(UserModeObjectAttributes, sizeof(OBJECT_ATTRIBUTES), sizeof(ULONG));
568  *UserModeObjectAttributes = *LocalObjectAttributes;
569  }
571  {
572  NOTHING;
573  }
574  _SEH2_END;
575  }
576 
577  /* Free the user-mode memory */
578  if (WindowStationName && (WindowStationName != TebStaticUnicodeString))
579  {
580  ZwFreeVirtualMemory(ZwCurrentProcess(),
581  (PVOID*)&WindowStationName,
582  &MemSize,
583  MEM_RELEASE);
584  }
585 }
#define ZwCurrentProcess()
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
_SEH2_TRY
Definition: create.c:4226
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define NOTHING
Definition: env_spec_w32.h:461
ULONG_PTR SIZE_T
Definition: typedefs.h:80
_SEH2_END
Definition: create.c:4400
#define MEM_RELEASE
Definition: nt_native.h:1316
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40

Referenced by BuildUserModeWindowStationName(), NtUserCreateWindowStation(), and NtUserOpenWindowStation().

◆ 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_READ
Definition: winsta.h:50
POBJECT_TYPE ExWindowStationObjectType
Definition: win32k.c:21
#define WINSTA_EXECUTE
Definition: winsta.h:61
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: winsta.h:65
#define WINSTA_WRITE
Definition: winsta.h:56
#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 427 of file winsta.c.

438 {
440  HWINSTA hWinSta;
441  PWINSTATION_OBJECT WindowStation;
442 
443  TRACE("IntCreateWindowStation called\n");
444 
445  ASSERT(phWinSta);
446  *phWinSta = NULL;
447 
450  AccessMode,
451  NULL,
452  dwDesiredAccess,
453  NULL,
454  (PVOID*)&hWinSta);
455  if (NT_SUCCESS(Status))
456  {
457  TRACE("IntCreateWindowStation opened window station '%wZ'\n",
458  ObjectAttributes->ObjectName);
459  *phWinSta = hWinSta;
460  return Status;
461  }
462 
463  /*
464  * No existing window station found, try to create a new one.
465  */
466 
467  /* Create the window station object */
471  OwnerMode,
472  NULL,
473  sizeof(WINSTATION_OBJECT),
474  0,
475  0,
476  (PVOID*)&WindowStation);
477  if (!NT_SUCCESS(Status))
478  {
479  ERR("ObCreateObject failed for window station '%wZ', Status 0x%08lx\n",
480  ObjectAttributes->ObjectName, Status);
482  return Status;
483  }
484 
485  /* Initialize the window station */
486  RtlZeroMemory(WindowStation, sizeof(WINSTATION_OBJECT));
487 
488  InitializeListHead(&WindowStation->DesktopListHead);
489  WindowStation->dwSessionId = NtCurrentPeb()->SessionId;
490  Status = RtlCreateAtomTable(37, &WindowStation->AtomTable);
491  if (!NT_SUCCESS(Status))
492  {
493  ERR("RtlCreateAtomTable failed for window station '%wZ', Status 0x%08lx\n",
494  ObjectAttributes->ObjectName, Status);
495  ObDereferenceObject(WindowStation);
497  return Status;
498  }
499 
500  Status = ObInsertObject(WindowStation,
501  NULL,
502  dwDesiredAccess,
503  0,
504  NULL,
505  (PVOID*)&hWinSta);
506  if (!NT_SUCCESS(Status))
507  {
508  ERR("ObInsertObject failed for window station, Status 0x%08lx\n", Status);
510  return Status;
511  }
512 
513  // FIXME! TODO: Add this new window station to a linked list
514 
515  if (InputWindowStation == NULL)
516  {
517  ERR("Initializing input window station\n");
518 
519  /* Only Winlogon can create the interactive window station */
521 
522  InputWindowStation = WindowStation;
523  WindowStation->Flags &= ~WSS_NOIO;
524 
525  InitCursorImpl();
526 
529 
530  /* Desktop functions require the desktop thread running so wait for it to initialize */
531  UserLeaveCo();
533  UserRequest,
534  UserMode,
535  FALSE,
536  NULL);
537  UserEnterCo();
538  }
539  else
540  {
541  WindowStation->Flags |= WSS_NOIO;
542  }
543 
544  TRACE("IntCreateWindowStation created window station '%wZ' object 0x%p handle 0x%p\n",
545  ObjectAttributes->ObjectName, WindowStation, hWinSta);
546 
547  *phWinSta = hWinSta;
549 
550  return STATUS_SUCCESS;
551 }
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:2528
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:18
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:10
_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:952
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:16
PKEVENT gpDesktopThreadStartedEvent
Definition: desktop.c:39
#define ObDereferenceObject
Definition: obfuncs.h:203
#define UserEnterCo
Definition: ntuser.h:9
#define ST_RIT
Definition: csr.h:35
VOID FASTCALL SetLastNtError(NTSTATUS Status)
Definition: error.c:36
#define ERR(fmt,...)
Definition: debug.h:110
PRTL_ATOM_TABLE AtomTable
Definition: winsta.h:19
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:2931
#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:27
HANDLE gpidLogon
Definition: simplecall.c:15

Referenced by IntResolveDesktop(), and NtUserCreateWindowStation().

◆ IntEndDesktopGraphics()

VOID FASTCALL IntEndDesktopGraphics ( VOID  )

Definition at line 350 of file winsta.c.

351 {
352  if (NULL != ScreenDeviceContext)
353  { // No need to allocate a new dcattr.
357  }
360 }
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:1230
HDC ScreenDeviceContext
Definition: desktop.c:36
VOID FASTCALL IntDestroyPrimarySurface(VOID)
Definition: device.c:44
NTSTATUS FASTCALL IntHideDesktop(PDESKTOP Desktop)
Definition: desktop.c:1603

Referenced by RemoveGuiApp().

◆ IntGetScreenDC()

HDC FASTCALL IntGetScreenDC ( VOID  )

Definition at line 363 of file winsta.c.

364 {
365  return ScreenDeviceContext;
366 }
HDC ScreenDeviceContext
Definition: desktop.c:36

Referenced by co_MsqInsertMouseMessage(), MsqCleanupMessageQueue(), UserSetCursor(), and UserShowCursor().

◆ IntValidateWindowStationHandle()

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

Definition at line 230 of file winsta.c.

236 {
238 
239  if (WindowStation == NULL)
240  {
241  ERR("Invalid window station handle\n");
243  return STATUS_INVALID_HANDLE;
244  }
245 
246  Status = ObReferenceObjectByHandle(WindowStation,
249  AccessMode,
250  (PVOID*)Object,
251  pObjectHandleInfo);
252 
253  if (!NT_SUCCESS(Status))
255 
256  return Status;
257 }
_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:36
_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:27

Referenced by BuildDesktopNameList(), 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  return STATUS_SUCCESS;
132 }
_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
#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:19
HANDLE NTAPI PsGetCurrentProcessId(VOID)
Definition: process.c:1123
#define NULL
Definition: types.h:112
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 136 of file winsta.c.

138 {
139  PWIN32_PARSEMETHOD_PARAMETERS ParseParameters = Parameters;
140  PUNICODE_STRING RemainingName = ParseParameters->RemainingName;
141 
142  /* Assume we don't find anything */
143  *ParseParameters->Object = NULL;
144 
145  /* Check for an empty name */
146  if (!RemainingName->Length)
147  {
148  /* Make sure this is a window station, can't parse a desktop now */
149  if (ParseParameters->ObjectType != ExWindowStationObjectType)
150  {
151  /* Fail */
153  }
154 
155  /* Reference the window station and return */
156  ObReferenceObject(ParseParameters->ParseObject);
157  *ParseParameters->Object = ParseParameters->ParseObject;
158  return STATUS_SUCCESS;
159  }
160 
161  /* Check for leading slash */
162  if (RemainingName->Buffer[0] == OBJ_NAME_PATH_SEPARATOR)
163  {
164  /* Skip it */
165  RemainingName->Buffer++;
166  RemainingName->Length -= sizeof(WCHAR);
167  RemainingName->MaximumLength -= sizeof(WCHAR);
168  }
169 
170  /* Check if there is still a slash */
172  {
173  /* In this case, fail */
175  }
176 
177  /*
178  * Check if we are parsing a desktop.
179  */
180  if (ParseParameters->ObjectType == ExDesktopObjectType)
181  {
182  /* Then call the desktop parse routine */
183  return IntDesktopObjectParse(ParseParameters->ParseObject,
184  ParseParameters->ObjectType,
185  ParseParameters->AccessState,
186  ParseParameters->AccessMode,
187  ParseParameters->Attributes,
188  ParseParameters->CompleteName,
190  ParseParameters->Context,
191  ParseParameters->SecurityQos,
192  ParseParameters->Object);
193  }
194 
195  /* Should hopefully never get here */
197 }
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 201 of file winsta.c.

203 {
204  PWIN32_OKAYTOCLOSEMETHOD_PARAMETERS OkToCloseParameters = Parameters;
205  PPROCESSINFO ppi;
206 
208 
209  if (ppi && (OkToCloseParameters->Handle == ppi->hwinsta))
210  {
211  return STATUS_ACCESS_DENIED;
212  }
213 
214  return STATUS_SUCCESS;
215 }
_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:265
PVOID NTAPI PsGetCurrentProcessWin32Process(VOID)
Definition: process.c:1183
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by DriverEntry().

◆ NtUserBuildNameList()

NTSTATUS APIENTRY NtUserBuildNameList ( HWINSTA  hWindowStation,
ULONG  dwSize,
PVOID  lpBuffer,
PULONG  pRequiredSize 
)

Definition at line 1917 of file winsta.c.

1922 {
1923  /* The WindowStation name list and desktop name list are build in completely
1924  different ways. Call the appropriate function */
1925  return NULL == hWindowStation ? BuildWindowStationNameList(dwSize, lpBuffer, pRequiredSize) :
1926  BuildDesktopNameList(hWindowStation, dwSize, lpBuffer, pRequiredSize);
1927 }
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:175
static NTSTATUS FASTCALL BuildDesktopNameList(HWINSTA hWindowStation, ULONG dwSize, PVOID lpBuffer, PULONG pRequiredSize)
Definition: winsta.c:1790
static NTSTATUS FASTCALL BuildWindowStationNameList(ULONG dwSize, PVOID lpBuffer, PULONG pRequiredSize)
Definition: winsta.c:1602
#define NULL
Definition: types.h:112
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56

Referenced by EnumNamesW().

◆ NtUserCloseWindowStation()

BOOL APIENTRY NtUserCloseWindowStation ( HWINSTA  hWinSta)

Definition at line 999 of file winsta.c.

1001 {
1003  NTSTATUS Status;
1004 
1005  TRACE("NtUserCloseWindowStation called (%p)\n", hWinSta);
1006 
1007  if (hWinSta == UserGetProcessWindowStation())
1008  {
1009  ERR("Attempted to close process window station\n");
1010  return FALSE;
1011  }
1012 
1014  UserMode,
1015  0,
1016  &Object,
1017  NULL);
1018  if (!NT_SUCCESS(Status))
1019  {
1020  ERR("Validation of window station handle (%p) failed\n", hWinSta);
1021  return FALSE;
1022  }
1023 
1025 
1026  TRACE("Closing window station handle (%p)\n", hWinSta);
1027 
1028  Status = ObCloseHandle(hWinSta, UserMode);
1029  if (!NT_SUCCESS(Status))
1030  {
1032  return FALSE;
1033  }
1034 
1035  return TRUE;
1036 }
HWINSTA FASTCALL UserGetProcessWindowStation(VOID)
Definition: winsta.c:1333
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define FALSE
Definition: types.h:117
NTSTATUS FASTCALL IntValidateWindowStationHandle(HWINSTA WindowStation, KPROCESSOR_MODE AccessMode, ACCESS_MASK DesiredAccess, PWINSTATION_OBJECT *Object, POBJECT_HANDLE_INFORMATION pObjectHandleInfo)
Definition: winsta.c:230
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
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3375
VOID FASTCALL SetLastNtError(NTSTATUS Status)
Definition: error.c:36
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
#define ERR(fmt,...)
Definition: debug.h:110
#define NULL
Definition: types.h:112

Referenced by CloseWindowStation().

◆ NtUserCreateWindowStation()

HWINSTA APIENTRY NtUserCreateWindowStation ( IN POBJECT_ATTRIBUTES  ObjectAttributes,
IN ACCESS_MASK  dwDesiredAccess,
DWORD  Unknown2,
DWORD  Unknown3,
DWORD  Unknown4,
DWORD  Unknown5,
DWORD  Unknown6 
)

Definition at line 711 of file winsta.c.

719 {
721  HWINSTA hWinSta = NULL;
722  OBJECT_ATTRIBUTES LocalObjectAttributes;
723  PUNICODE_STRING WindowStationName = NULL;
724  PUNICODE_STRING TebStaticUnicodeString = NULL;
725  KPROCESSOR_MODE OwnerMode = UserMode;
726 
727  TRACE("NtUserCreateWindowStation called\n");
728 
729  /* Capture the object attributes and the window station name */
730  _SEH2_TRY
731  {
733  LocalObjectAttributes = *ObjectAttributes;
734  if (LocalObjectAttributes.Length != sizeof(OBJECT_ATTRIBUTES))
735  {
736  ERR("Invalid ObjectAttributes length!\n");
738  _SEH2_LEAVE;
739  }
740 
741  /*
742  * Check whether the caller provided a window station name together
743  * with a RootDirectory handle.
744  *
745  * If the caller did not provide a window station name, build a new one
746  * based on the logon session identifier for the calling process.
747  * The new name is allocated in user-mode, as the rest of ObjectAttributes
748  * already is, so that the validation performed by the Object Manager
749  * can be done adequately.
750  */
751  if ((LocalObjectAttributes.ObjectName == NULL ||
752  LocalObjectAttributes.ObjectName->Buffer == NULL ||
753  LocalObjectAttributes.ObjectName->Length == 0 ||
754  LocalObjectAttributes.ObjectName->Buffer[0] == UNICODE_NULL)
755  /* &&
756  LocalObjectAttributes.RootDirectory == NULL */)
757  {
758  /* No, build the new window station name */
760  &LocalObjectAttributes,
761  &WindowStationName,
762  &TebStaticUnicodeString);
763  if (!NT_SUCCESS(Status))
764  {
765  ERR("BuildUserModeWindowStationName() failed, Status 0x%08lx\n", Status);
766  _SEH2_LEAVE;
767  }
768  OwnerMode = KernelMode;
769  }
770  }
772  {
774  ERR("ObjectAttributes capture failed, Status 0x%08lx\n", Status);
775  }
776  _SEH2_END;
777 
778  if (!NT_SUCCESS(Status))
779  {
781  return NULL;
782  }
783 
785 
786  /* Create the window station */
787  Status = IntCreateWindowStation(&hWinSta,
789  UserMode,
790  OwnerMode,
791  dwDesiredAccess,
792  Unknown2,
793  Unknown3,
794  Unknown4,
795  Unknown5,
796  Unknown6);
797  UserLeave();
798 
799  if (NT_SUCCESS(Status))
800  {
801  TRACE("NtUserCreateWindowStation created window station '%wZ' with handle 0x%p\n",
802  ObjectAttributes->ObjectName, hWinSta);
803  }
804  else
805  {
806  ASSERT(hWinSta == NULL);
807  ERR("NtUserCreateWindowStation failed to create window station '%wZ', Status 0x%08lx\n",
808  ObjectAttributes->ObjectName, Status);
809  }
810 
811  /* Try to restore the user's ObjectAttributes and release the window station name */
812  FreeUserModeWindowStationName(WindowStationName,
813  TebStaticUnicodeString,
814  (OwnerMode == KernelMode ? ObjectAttributes : NULL),
815  &LocalObjectAttributes);
816 
817  if (!NT_SUCCESS(Status))
818  {
819  ASSERT(hWinSta == NULL);
821  }
822 
823  return hWinSta;
824 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES IN DWORD Unknown3
Definition: conport.c:35
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES IN DWORD IN DWORD IN DWORD IN DWORD Unknown6
Definition: conport.c:35
_SEH2_TRY
Definition: create.c:4226
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: winsta.c:427
#define UNICODE_NULL
PRTL_UNICODE_STRING_BUFFER PULONG PULONG Unknown4
VOID FASTCALL UserEnterExclusive(VOID)
Definition: ntuser.c:245
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
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
VOID FASTCALL SetLastNtError(NTSTATUS Status)
Definition: error.c:36
#define ERR(fmt,...)
Definition: debug.h:110
VOID FASTCALL UserLeave(VOID)
Definition: ntuser.c:253
_SEH2_END
Definition: create.c:4400
static NTSTATUS BuildUserModeWindowStationName(IN OUT POBJECT_ATTRIBUTES UserModeObjectAttributes, IN OUT POBJECT_ATTRIBUTES LocalObjectAttributes, OUT PUNICODE_STRING *WindowStationName, OUT PUNICODE_STRING *TebStaticUnicodeString)
Definition: winsta.c:588
#define NULL
Definition: types.h:112
static VOID FreeUserModeWindowStationName(IN OUT PUNICODE_STRING WindowStationName, IN PUNICODE_STRING TebStaticUnicodeString, IN OUT POBJECT_ATTRIBUTES UserModeObjectAttributes OPTIONAL, IN POBJECT_ATTRIBUTES LocalObjectAttributes OPTIONAL)
Definition: winsta.c:554
PUNICODE_STRING ObjectName
Definition: umtypes.h:185
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_LEAVE
Definition: filesup.c:20
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES IN DWORD IN DWORD IN DWORD Unknown5
Definition: conport.c:35

Referenced by CreateWindowStationW().

◆ NtUserGetObjectInformation()

BOOL APIENTRY NtUserGetObjectInformation ( HANDLE  hObject,
DWORD  nIndex,
PVOID  pvInformation,
DWORD  nLength,
PDWORD  nLengthNeeded 
)

Definition at line 1079 of file winsta.c.

1085 {
1086  NTSTATUS Status;
1087  PWINSTATION_OBJECT WinStaObject = NULL;
1088  PDESKTOP DesktopObject = NULL;
1089  POBJECT_HEADER ObjectHeader;
1090  POBJECT_HEADER_NAME_INFO NameInfo;
1091  OBJECT_HANDLE_INFORMATION HandleInfo;
1092  USEROBJECTFLAGS ObjectFlags;
1093  PUNICODE_STRING pStrNameU = NULL;
1094  PVOID pvData = NULL;
1095  SIZE_T nDataSize = 0;
1096 
1097  _SEH2_TRY
1098  {
1099  if (nLengthNeeded)
1100  ProbeForWrite(nLengthNeeded, sizeof(*nLengthNeeded), 1);
1101  ProbeForWrite(pvInformation, nLength, 1);
1102  }
1104  {
1106  return FALSE;
1107  }
1108  _SEH2_END;
1109 
1110  /* Try window station */
1111  TRACE("Trying to open window station 0x%p\n", hObject);
1113  0,
1115  UserMode,
1116  (PVOID*)&WinStaObject,
1117  &HandleInfo);
1118 
1120  {
1121  /* Try desktop */
1122  TRACE("Trying to open desktop %p\n", hObject);
1123  WinStaObject = NULL;
1124  Status = IntValidateDesktopHandle(hObject,
1125  UserMode,
1126  0,
1127  &DesktopObject);
1128  }
1129 
1130  if (!NT_SUCCESS(Status))
1131  {
1132  ERR("Failed: 0x%x\n", Status);
1133  goto Exit;
1134  }
1135 
1136  TRACE("WinSta or Desktop opened!\n");
1137 
1138  /* Get data */
1139  switch (nIndex)
1140  {
1141  case UOI_FLAGS:
1142  {
1143  ObjectFlags.fReserved = FALSE;
1144  ObjectFlags.fInherit = !!(HandleInfo.HandleAttributes & OBJ_INHERIT);
1145 
1146  ObjectFlags.dwFlags = 0;
1147  if (WinStaObject != NULL)
1148  {
1149  if (!(WinStaObject->Flags & WSS_NOIO))
1150  ObjectFlags.dwFlags |= WSF_VISIBLE;
1151  }
1152  else if (DesktopObject != NULL)
1153  {
1154  FIXME("Setting DF_ALLOWOTHERACCOUNTHOOK is unimplemented.\n");
1155  }
1156  else
1157  {
1158  ERR("No associated WinStaObject nor DesktopObject!\n");
1159  }
1160 
1161  pvData = &ObjectFlags;
1162  nDataSize = sizeof(ObjectFlags);
1164  break;
1165  }
1166 
1167  case UOI_NAME:
1168  {
1169  if (WinStaObject != NULL)
1170  {
1171  ObjectHeader = OBJECT_TO_OBJECT_HEADER(WinStaObject);
1172  NameInfo = OBJECT_HEADER_TO_NAME_INFO(ObjectHeader);
1173 
1174  if (NameInfo && (NameInfo->Name.Length > 0))
1175  {
1176  /* Named window station */
1177  pStrNameU = &NameInfo->Name;
1178  nDataSize = pStrNameU->Length + sizeof(UNICODE_NULL);
1179  }
1180  else
1181  {
1182  /* Unnamed window station (should never happen!) */
1183  ASSERT(FALSE);
1184  pStrNameU = NULL;
1185  nDataSize = sizeof(UNICODE_NULL);
1186  }
1188  }
1189  else if (DesktopObject != NULL)
1190  {
1191  pvData = DesktopObject->pDeskInfo->szDesktopName;
1192  nDataSize = (wcslen(DesktopObject->pDeskInfo->szDesktopName) + 1) * sizeof(WCHAR);
1194  }
1195  else
1196  {
1198  }
1199  break;
1200  }
1201 
1202  case UOI_TYPE:
1203  {
1204  if (WinStaObject != NULL)
1205  {
1206  ObjectHeader = OBJECT_TO_OBJECT_HEADER(WinStaObject);
1207  pStrNameU = &ObjectHeader->Type->Name;
1208  nDataSize = pStrNameU->Length + sizeof(UNICODE_NULL);
1210  }
1211  else if (DesktopObject != NULL)
1212  {
1213  ObjectHeader = OBJECT_TO_OBJECT_HEADER(DesktopObject);
1214  pStrNameU = &ObjectHeader->Type->Name;
1215  nDataSize = pStrNameU->Length + sizeof(UNICODE_NULL);
1217  }
1218  else
1219  {
1221  }
1222  break;
1223  }
1224 
1225  case UOI_USER_SID:
1227  ERR("UOI_USER_SID unimplemented!\n");
1228  break;
1229 
1230  default:
1232  break;
1233  }
1234 
1235 Exit:
1236  if ((Status == STATUS_SUCCESS) && (nLength < nDataSize))
1238 
1239  _SEH2_TRY
1240  {
1241  if (nLengthNeeded)
1242  *nLengthNeeded = nDataSize;
1243 
1244  /* Try to copy data to caller */
1245  if (Status == STATUS_SUCCESS && (nDataSize > 0))
1246  {
1247  TRACE("Trying to copy data to caller (len = %lu, len needed = %lu)\n", nLength, nDataSize);
1248  if (pvData)
1249  {
1250  /* Copy the data */
1251  RtlCopyMemory(pvInformation, pvData, nDataSize);
1252  }
1253  else if (pStrNameU)
1254  {
1255  /* Copy and NULL-terminate the string */
1256  RtlCopyMemory(pvInformation, pStrNameU->Buffer, pStrNameU->Length);
1257  ((PWCHAR)pvInformation)[pStrNameU->Length / sizeof(WCHAR)] = UNICODE_NULL;
1258  }
1259  else
1260  {
1261  /* Zero the memory */
1262  RtlZeroMemory(pvInformation, nDataSize);
1263  }
1264  }
1265  }
1267  {
1269  }
1270  _SEH2_END;
1271 
1272  /* Release objects */
1273  if (DesktopObject != NULL)
1274  ObDereferenceObject(DesktopObject);
1275  if (WinStaObject != NULL)
1276  ObDereferenceObject(WinStaObject);
1277 
1278  if (!NT_SUCCESS(Status))
1279  {
1281  return FALSE;
1282  }
1283 
1284  return TRUE;
1285 }
PDESKTOPINFO pDeskInfo
Definition: desktop.h:8
POBJECT_TYPE ExWindowStationObjectType
Definition: win32k.c:21
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
#define UOI_USER_SID
Definition: winuser.h:1076
_In_ DWORD nLength
Definition: wincon.h:473
UNICODE_STRING Name
Definition: obtypes.h:433
#define OBJECT_HEADER_TO_NAME_INFO(h)
Definition: obtypes.h:114
uint16_t * PWCHAR
Definition: typedefs.h:56
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
_SEH2_TRY
Definition: create.c:4226
#define OBJECT_TO_OBJECT_HEADER(o)
Definition: obtypes.h:111
return STATUS_NOT_IMPLEMENTED
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 FALSE
Definition: types.h:117
#define UNICODE_NULL
#define FIXME(fmt,...)
Definition: debug.h:111
#define WSS_NOIO
Definition: winsta.h:9
_In_ ULONG _In_opt_ PVOID pvData
Definition: winddi.h:3748
Status
Definition: gdiplustypes.h:24
#define WSF_VISIBLE
Definition: winuser.h:2428
#define STATUS_OBJECT_TYPE_MISMATCH
Definition: ntstatus.h:273
#define TRACE(s)
Definition: solgame.cpp:4
#define ASSERT(a)
Definition: mode.c:44
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define OBJ_INHERIT
Definition: winternl.h:225
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
static void Exit(void)
Definition: sock.c:1331
#define UOI_NAME
Definition: winuser.h:1074
#define ObDereferenceObject
Definition: obfuncs.h:203
VOID FASTCALL SetLastNtError(NTSTATUS Status)
Definition: error.c:36
#define ERR(fmt,...)
Definition: debug.h:110
ULONG_PTR SIZE_T
Definition: typedefs.h:80
_SEH2_END
Definition: create.c:4400
#define UOI_TYPE
Definition: winuser.h:1075
#define UOI_FLAGS
Definition: winuser.h:1073
NTSTATUS FASTCALL IntValidateDesktopHandle(HDESK Desktop, KPROCESSOR_MODE AccessMode, ACCESS_MASK DesiredAccess, PDESKTOP *Object)
Definition: desktop.c:1204
#define NULL
Definition: types.h:112
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
UNICODE_STRING Name
Definition: obtypes.h:383
POBJECT_TYPE Type
Definition: obtypes.h:493
WCHAR szDesktopName[1]
Definition: ntuser.h:154

Referenced by GetUserObjectInformationW().

◆ NtUserGetProcessWindowStation()

HWINSTA APIENTRY NtUserGetProcessWindowStation ( VOID  )

Definition at line 1356 of file winsta.c.

1357 {
1358  return UserGetProcessWindowStation();
1359 }
HWINSTA FASTCALL UserGetProcessWindowStation(VOID)
Definition: winsta.c:1333

Referenced by CreateDesktopW(), and GetProcessWindowStation().

◆ NtUserLockWindowStation()

BOOL APIENTRY NtUserLockWindowStation ( HWINSTA  hWindowStation)

Definition at line 1521 of file winsta.c.

1522 {
1524  NTSTATUS Status;
1525 
1526  TRACE("About to set process window station with handle (%p)\n",
1527  hWindowStation);
1528 
1530  {
1531  ERR("Unauthorized process attempted to lock the window station!\n");
1533  return FALSE;
1534  }
1535 
1536  Status = IntValidateWindowStationHandle(hWindowStation,
1537  UserMode,
1538  0,
1539  &Object,
1540  NULL);
1541  if (!NT_SUCCESS(Status))
1542  {
1543  TRACE("Validation of window station handle (%p) failed\n",
1544  hWindowStation);
1546  return FALSE;
1547  }
1548 
1549  Object->Flags |= WSS_LOCKED;
1550 
1552  return TRUE;
1553 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define FALSE
Definition: types.h:117
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
NTSTATUS FASTCALL IntValidateWindowStationHandle(HWINSTA WindowStation, KPROCESSOR_MODE AccessMode, ACCESS_MASK DesiredAccess, PWINSTATION_OBJECT *Object, POBJECT_HANDLE_INFORMATION pObjectHandleInfo)
Definition: winsta.c:230
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
#define WSS_LOCKED
Definition: winsta.h:7
VOID FASTCALL SetLastNtError(NTSTATUS Status)
Definition: error.c:36
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
#define ERR(fmt,...)
Definition: debug.h:110
HANDLE NTAPI PsGetCurrentProcessId(VOID)
Definition: process.c:1123
#define NULL
Definition: types.h:112
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:27
HANDLE gpidLogon
Definition: simplecall.c:15

Referenced by LockWindowStation().

◆ NtUserLockWorkStation()

BOOL APIENTRY NtUserLockWorkStation ( VOID  )

Definition at line 1952 of file winsta.c.

1953 {
1954  BOOL ret;
1956 
1958 
1959  if (pti->rpdesk == IntGetActiveDesktop())
1960  {
1962  }
1963  else
1964  {
1965  ret = FALSE;
1966  }
1967 
1968  UserLeave();
1969 
1970  return ret;
1971 }
BOOL FASTCALL UserPostMessage(HWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: message.c:1346
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
struct _DESKTOP * rpdesk
Definition: win32.h:93
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define LN_LOCK_WORKSTATION
Definition: undocuser.h:117
VOID FASTCALL UserEnterExclusive(VOID)
Definition: ntuser.c:245
HWND hwndSAS
Definition: winsta.c:24
int ret
#define WM_LOGONNOTIFY
Definition: undocuser.h:37
VOID FASTCALL UserLeave(VOID)
Definition: ntuser.c:253
PDESKTOP FASTCALL IntGetActiveDesktop(VOID)
Definition: desktop.c:1230

Referenced by LockWorkStation().

◆ NtUserOpenWindowStation()

HWINSTA APIENTRY NtUserOpenWindowStation ( IN POBJECT_ATTRIBUTES  ObjectAttributes,
IN ACCESS_MASK  dwDesiredAccess 
)

Definition at line 852 of file winsta.c.

855 {
857  HWINSTA hWinSta = NULL;
858  OBJECT_ATTRIBUTES LocalObjectAttributes;
859  PUNICODE_STRING WindowStationName = NULL;
860  PUNICODE_STRING TebStaticUnicodeString = NULL;
861  KPROCESSOR_MODE OwnerMode = UserMode;
862 
863  TRACE("NtUserOpenWindowStation called\n");
864 
865  /* Capture the object attributes and the window station name */
866  _SEH2_TRY
867  {
869  LocalObjectAttributes = *ObjectAttributes;
870  if (LocalObjectAttributes.Length != sizeof(OBJECT_ATTRIBUTES))
871  {
872  ERR("Invalid ObjectAttributes length!\n");
874  _SEH2_LEAVE;
875  }
876 
877  /*
878  * Check whether the caller did not provide a window station name,
879  * or provided the special "Service-0x00000000-00000000$" name.
880  *
881  * NOTE: On Windows, the special "Service-0x00000000-00000000$" string
882  * is used instead of an empty name (observed when API-monitoring
883  * OpenWindowStation() called with an empty window station name).
884  */
885  if ((LocalObjectAttributes.ObjectName == NULL ||
886  LocalObjectAttributes.ObjectName->Buffer == NULL ||
887  LocalObjectAttributes.ObjectName->Length == 0 ||
888  LocalObjectAttributes.ObjectName->Buffer[0] == UNICODE_NULL)
889  /* &&
890  LocalObjectAttributes.RootDirectory == NULL */)
891  {
892  /* No, remember that for later */
893  LocalObjectAttributes.ObjectName = NULL;
894  }
895  if (LocalObjectAttributes.ObjectName &&
896  LocalObjectAttributes.ObjectName->Length ==
897  sizeof(L"Service-0x00000000-00000000$") - sizeof(UNICODE_NULL) &&
898  _wcsnicmp(LocalObjectAttributes.ObjectName->Buffer,
899  L"Service-0x00000000-00000000$",
900  LocalObjectAttributes.ObjectName->Length / sizeof(WCHAR)) == 0)
901  {
902  /* No, remember that for later */
903  LocalObjectAttributes.ObjectName = NULL;
904  }
905 
906  /*
907  * If the caller did not provide a window station name, build a new one
908  * based on the logon session identifier for the calling process.
909  * The new name is allocated in user-mode, as the rest of ObjectAttributes
910  * already is, so that the validation performed by the Object Manager
911  * can be done adequately.
912  */
913  if (!LocalObjectAttributes.ObjectName)
914  {
915  /* No, build the new window station name */
917  &LocalObjectAttributes,
918  &WindowStationName,
919  &TebStaticUnicodeString);
920  if (!NT_SUCCESS(Status))
921  {
922  ERR("BuildUserModeWindowStationName() failed, Status 0x%08lx\n", Status);
923  _SEH2_LEAVE;
924  }
925  OwnerMode = KernelMode;
926  }
927  }
929  {
931  ERR("ObjectAttributes capture failed, Status 0x%08lx\n", Status);
932  }
933  _SEH2_END;
934 
935  if (!NT_SUCCESS(Status))
936  {
938  return NULL;
939  }
940 
941  /* Open the window station */
944  UserMode,
945  NULL,
946  dwDesiredAccess,
947  NULL,
948  (PVOID*)&hWinSta);
949  if (NT_SUCCESS(Status))
950  {
951  TRACE("NtUserOpenWindowStation opened window station '%wZ' with handle 0x%p\n",
952  ObjectAttributes->ObjectName, hWinSta);
953  }
954  else
955  {
956  ASSERT(hWinSta == NULL);
957  ERR("NtUserOpenWindowStation failed to open window station '%wZ', Status 0x%08lx\n",
958  ObjectAttributes->ObjectName, Status);
959  }
960 
961  /* Try to restore the user's ObjectAttributes and release the window station name */
962  FreeUserModeWindowStationName(WindowStationName,
963  TebStaticUnicodeString,
964  (OwnerMode == KernelMode ? ObjectAttributes : NULL),
965  &LocalObjectAttributes);
966 
967  if (!NT_SUCCESS(Status))
968  {
969  ASSERT(hWinSta == NULL);
971  }
972 
973  return hWinSta;
974 }
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:2528
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
POBJECT_TYPE ExWindowStationObjectType
Definition: win32k.c:21
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
_SEH2_TRY
Definition: create.c:4226
#define UNICODE_NULL
Status
Definition: gdiplustypes.h:24
#define TRACE(s)
Definition: solgame.cpp:4
#define ASSERT(a)
Definition: mode.c:44
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
static const WCHAR L[]
Definition: oid.c:1250
VOID FASTCALL SetLastNtError(NTSTATUS Status)
Definition: error.c:36
#define ERR(fmt,...)
Definition: debug.h:110
_SEH2_END
Definition: create.c:4400
static NTSTATUS BuildUserModeWindowStationName(IN OUT POBJECT_ATTRIBUTES UserModeObjectAttributes, IN OUT POBJECT_ATTRIBUTES LocalObjectAttributes, OUT PUNICODE_STRING *WindowStationName, OUT PUNICODE_STRING *TebStaticUnicodeString)
Definition: winsta.c:588
#define NULL
Definition: types.h:112
static VOID FreeUserModeWindowStationName(IN OUT PUNICODE_STRING WindowStationName, IN PUNICODE_STRING TebStaticUnicodeString, IN OUT POBJECT_ATTRIBUTES UserModeObjectAttributes OPTIONAL, IN POBJECT_ATTRIBUTES LocalObjectAttributes OPTIONAL)
Definition: winsta.c:554
PUNICODE_STRING ObjectName
Definition: umtypes.h:185
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_LEAVE
Definition: filesup.c:20

Referenced by OpenWindowStationW().

◆ NtUserSetLogonNotifyWindow()

BOOL APIENTRY NtUserSetLogonNotifyWindow ( HWND  hWnd)

Definition at line 1933 of file winsta.c.

1934 {
1936  {
1937  return FALSE;
1938  }
1939 
1940  if (!IntIsWindow(hWnd))
1941  {
1942  return FALSE;
1943  }
1944 
1945  hwndSAS = hWnd;
1946 
1947  return TRUE;
1948 }
#define TRUE
Definition: types.h:120
HWND hWnd
Definition: settings.c:17
#define FALSE
Definition: types.h:117
HWND hwndSAS
Definition: winsta.c:24
BOOL FASTCALL IntIsWindow(HWND hWnd)
Definition: window.c:157
HANDLE NTAPI PsGetCurrentProcessId(VOID)
Definition: process.c:1123
HANDLE gpidLogon
Definition: simplecall.c:15

Referenced by SetLogonNotifyWindow().

◆ NtUserSetObjectInformation()

BOOL APIENTRY NtUserSetObjectInformation ( HANDLE  hObject,
DWORD  nIndex,
PVOID  pvInformation,
DWORD  nLength 
)

Definition at line 1319 of file winsta.c.

1324 {
1325  /* FIXME: ZwQueryObject */
1326  /* FIXME: ZwSetInformationObject */
1328  return FALSE;
1329 }
#define FALSE
Definition: types.h:117
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
VOID FASTCALL SetLastNtError(NTSTATUS Status)
Definition: error.c:36

◆ NtUserSetProcessWindowStation()

BOOL APIENTRY NtUserSetProcessWindowStation ( HWINSTA  hWindowStation)

Definition at line 1498 of file winsta.c.

1499 {
1500  BOOL ret;
1501 
1503 
1504  ret = UserSetProcessWindowStation(hWindowStation);
1505 
1506  UserLeave();
1507 
1508  return ret;
1509 }
unsigned int BOOL
Definition: ntddk_ex.h:94
VOID FASTCALL UserEnterExclusive(VOID)
Definition: ntuser.c:245
int ret
BOOL FASTCALL UserSetProcessWindowStation(HWINSTA hWindowStation)
Definition: winsta.c:1362
VOID FASTCALL UserLeave(VOID)
Definition: ntuser.c:253

Referenced by SetProcessWindowStation().

◆ NtUserSetWindowStationUser()

BOOL NTAPI NtUserSetWindowStationUser ( IN HWINSTA  hWindowStation,
IN PLUID  pluid,
IN PSID psid  OPTIONAL,
IN DWORD  size 
)

Definition at line 1975 of file winsta.c.

1980 {
1981  BOOL Ret = FALSE;
1982  NTSTATUS Status;
1983  PWINSTATION_OBJECT WindowStation = NULL;
1984  LUID luidUser;
1985 
1987 
1989  {
1991  goto Leave;
1992  }
1993 
1994  /* Validate the window station */
1995  Status = IntValidateWindowStationHandle(hWindowStation,
1996  UserMode,
1997  0,
1998  &WindowStation,
1999  NULL);
2000  if (!NT_SUCCESS(Status))
2001  {
2002  goto Leave;
2003  }
2004 
2005  /* Capture the user LUID */
2006  _SEH2_TRY
2007  {
2008  ProbeForRead(pluid, sizeof(LUID), 1);
2009  luidUser = *pluid;
2010  }
2012  {
2014  _SEH2_YIELD(goto Leave);
2015  }
2016  _SEH2_END;
2017 
2018  /* Reset the window station user LUID */
2019  RtlZeroMemory(&WindowStation->luidUser, sizeof(LUID));
2020 
2021  /* Reset the window station user SID */
2022  if (WindowStation->psidUser)
2023  {
2024  ExFreePoolWithTag(WindowStation->psidUser, USERTAG_SECURITY);
2025  WindowStation->psidUser = NULL;
2026  }
2027 
2028  /* Copy the new user SID if one has been provided */
2029  if (psid)
2030  {
2032  if (WindowStation->psidUser == NULL)
2033  {
2035  goto Leave;
2036  }
2037 
2039  _SEH2_TRY
2040  {
2041  ProbeForRead(psid, size, 1);
2042  RtlCopyMemory(WindowStation->psidUser, psid, size);
2043  }
2045  {
2047  }
2048  _SEH2_END;
2049 
2050  if (!NT_SUCCESS(Status))
2051  {
2052  ExFreePoolWithTag(WindowStation->psidUser, USERTAG_SECURITY);
2053  WindowStation->psidUser = NULL;
2054  goto Leave;
2055  }
2056  }
2057 
2058  /* Copy the new user LUID */
2059  WindowStation->luidUser = luidUser;
2060 
2061  Ret = TRUE;
2062 
2063 Leave:
2064  if (WindowStation)
2065  ObDereferenceObject(WindowStation);
2066 
2067  UserLeave();
2068  return Ret;
2069 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
_SEH2_TRY
Definition: create.c:4226
#define FALSE
Definition: types.h:117
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
unsigned int BOOL
Definition: ntddk_ex.h:94
NTSTATUS FASTCALL IntValidateWindowStationHandle(HWINSTA WindowStation, KPROCESSOR_MODE AccessMode, ACCESS_MASK DesiredAccess, PWINSTATION_OBJECT *Object, POBJECT_HANDLE_INFORMATION pObjectHandleInfo)
Definition: winsta.c:230
VOID FASTCALL UserEnterExclusive(VOID)
Definition: ntuser.c:245
Status
Definition: gdiplustypes.h:24
GLsizeiptr size
Definition: glext.h:5919
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define ObDereferenceObject
Definition: obfuncs.h:203
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
VOID FASTCALL UserLeave(VOID)
Definition: ntuser.c:253
_SEH2_END
Definition: create.c:4400
HANDLE NTAPI PsGetCurrentProcessId(VOID)
Definition: process.c:1123
#define NULL
Definition: types.h:112
#define USERTAG_SECURITY
Definition: tags.h:274
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
PVOID psidUser
Definition: winsta.h:41
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:27
HANDLE gpidLogon
Definition: simplecall.c:15
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13

Referenced by SetWindowStationUser().

◆ NtUserUnlockWindowStation()

BOOL APIENTRY NtUserUnlockWindowStation ( HWINSTA  hWindowStation)

Definition at line 1565 of file winsta.c.

1566 {
1568  NTSTATUS Status;
1569  BOOL Ret;
1570 
1571  TRACE("About to set process window station with handle (%p)\n",
1572  hWindowStation);
1573 
1575  {
1576  ERR("Unauthorized process attempted to unlock the window station!\n");
1578  return FALSE;
1579  }
1580 
1581  Status = IntValidateWindowStationHandle(hWindowStation,
1582  UserMode,
1583  0,
1584  &Object,
1585  NULL);
1586  if (!NT_SUCCESS(Status))
1587  {
1588  TRACE("Validation of window station handle (%p) failed\n",
1589  hWindowStation);
1591  return FALSE;
1592  }
1593 
1594  Ret = (Object->Flags & WSS_LOCKED) == WSS_LOCKED;
1595  Object->Flags &= ~WSS_LOCKED;
1596 
1598  return Ret;
1599 }
LONG NTSTATUS
Definition: precomp.h:26
#define FALSE
Definition: types.h:117
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
unsigned int BOOL
Definition: ntddk_ex.h:94
NTSTATUS FASTCALL IntValidateWindowStationHandle(HWINSTA WindowStation, KPROCESSOR_MODE AccessMode, ACCESS_MASK DesiredAccess, PWINSTATION_OBJECT *Object, POBJECT_HANDLE_INFORMATION pObjectHandleInfo)
Definition: winsta.c:230
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
#define WSS_LOCKED
Definition: winsta.h:7
VOID FASTCALL SetLastNtError(NTSTATUS Status)
Definition: error.c:36
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
#define ERR(fmt,...)
Definition: debug.h:110
HANDLE NTAPI PsGetCurrentProcessId(VOID)
Definition: process.c:1123
#define NULL
Definition: types.h:112
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:27
HANDLE gpidLogon
Definition: simplecall.c:15

Referenced by UnlockWindowStation().

◆ 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
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:1965
static const WCHAR L[]
Definition: oid.c:1250
#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().

◆ UserGetProcessWindowStation()

HWINSTA FASTCALL UserGetProcessWindowStation ( VOID  )

Definition at line 1333 of file winsta.c.

1334 {
1336 
1337  return ppi->hwinsta;
1338 }
HWINSTA hwinsta
Definition: win32.h:265
PVOID NTAPI PsGetCurrentProcessWin32Process(VOID)
Definition: process.c:1183

Referenced by IntGetWinStaForCbAccess(), NtUserCloseWindowStation(), and NtUserGetProcessWindowStation().

◆ UserSetProcessWindowStation()

BOOL FASTCALL UserSetProcessWindowStation ( HWINSTA  hWindowStation)

Definition at line 1362 of file winsta.c.

1363 {
1364  NTSTATUS Status;
1365  PPROCESSINFO ppi;
1366  OBJECT_HANDLE_INFORMATION ObjectHandleInfo;
1367  PWINSTATION_OBJECT NewWinSta = NULL, OldWinSta;
1368  HWINSTA hCacheWinSta;
1369 
1371 
1372  /* Reference the new window station */
1373  if (hWindowStation != NULL)
1374  {
1375  Status = IntValidateWindowStationHandle(hWindowStation,
1376  UserMode,
1377  0,
1378  &NewWinSta,
1379  &ObjectHandleInfo);
1380  if (!NT_SUCCESS(Status))
1381  {
1382  TRACE("Validation of window station handle 0x%p failed\n", hWindowStation);
1384  return FALSE;
1385  }
1386  }
1387 
1388  OldWinSta = ppi->prpwinsta;
1389  hCacheWinSta = PsGetProcessWin32WindowStation(ppi->peProcess);
1390 
1391  /* Dereference the previous window station */
1392  if (OldWinSta != NULL)
1393  {
1394  ObDereferenceObject(OldWinSta);
1395  }
1396 
1397  /*
1398  * FIXME: Don't allow changing the window station if there are threads that are attached to desktops and own GUI objects?
1399  */
1400 
1401  /* Close the cached EPROCESS window station handle if needed */
1402  if (hCacheWinSta != NULL)
1403  {
1404  /* Reference the window station */
1405  Status = ObReferenceObjectByHandle(hCacheWinSta,
1406  0,
1408  UserMode,
1409  (PVOID*)&OldWinSta,
1410  NULL);
1411  if (!NT_SUCCESS(Status))
1412  {
1413  ERR("Failed to reference the inherited window station, Status 0x%08lx\n", Status);
1414  /* We failed, reset the cache */
1415  hCacheWinSta = NULL;
1416  PsSetProcessWindowStation(ppi->peProcess, hCacheWinSta);
1417  }
1418  else
1419  {
1420  /*
1421  * Close the old handle and reset the cache only
1422  * if we are setting a different window station.
1423  */
1424  if (NewWinSta != OldWinSta)
1425  {
1426  ObCloseHandle(hCacheWinSta, UserMode);
1427  hCacheWinSta = NULL;
1428  PsSetProcessWindowStation(ppi->peProcess, hCacheWinSta);
1429  }
1430 
1431  /* Dereference the window station */
1432  ObDereferenceObject(OldWinSta);
1433  }
1434  }
1435 
1436  /* Duplicate and save a new cached EPROCESS window station handle */
1437  if ((hCacheWinSta == NULL) && (hWindowStation != NULL))
1438  {
1439  Status = ZwDuplicateObject(ZwCurrentProcess(),
1440  hWindowStation,
1441  ZwCurrentProcess(),
1442  (PHANDLE)&hCacheWinSta,
1443  0,
1444  0,
1446  if (!NT_SUCCESS(Status))
1447  {
1448  ERR("UserSetProcessWindowStation: Failed to duplicate the window station handle, Status 0x%08lx\n", Status);
1449  }
1450  else
1451  {
1452  PsSetProcessWindowStation(ppi->peProcess, hCacheWinSta);
1453  }
1454  }
1455 
1456  ppi->prpwinsta = NewWinSta;
1457  ppi->hwinsta = hWindowStation;
1458  ppi->amwinsta = hWindowStation != NULL ? ObjectHandleInfo.GrantedAccess : 0;
1459  TRACE("WS : Granted Access 0x%08lx\n",ppi->amwinsta);
1460 
1462  {
1463  ppi->W32PF_flags |= W32PF_READSCREENACCESSGRANTED;
1464  }
1465  else
1466  {
1467  ppi->W32PF_flags &= ~W32PF_READSCREENACCESSGRANTED;
1468  }
1469 
1470  if (NewWinSta && !(NewWinSta->Flags & WSS_NOIO))
1471  {
1472  ppi->W32PF_flags |= W32PF_IOWINSTA;
1473  }
1474  else /* Might be closed if the handle is NULL */
1475  {
1476  ppi->W32PF_flags &= ~W32PF_IOWINSTA;
1477  }
1478  return TRUE;
1479 }
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:264
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:230
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:3375
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:454
PVOID NTAPI PsGetProcessWin32WindowStation(PEPROCESS Process)
Definition: process.c:1203
VOID FASTCALL SetLastNtError(NTSTATUS Status)
Definition: error.c:36
#define ERR(fmt,...)
Definition: debug.h:110
HWINSTA hwinsta
Definition: win32.h:265
#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:266
#define WINSTA_READSCREEN
Definition: winuser.h:415

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

Variable Documentation

◆ gustrWindowStationsDir

◆ hwndSAS

◆ InputWindowStation