ReactOS 0.4.17-dev-470-gf9e3448
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)
 
PWINSTATION_OBJECT FASTCALL IntGetProcessWindowStation (HWINSTA *phWinSta OPTIONAL)
 
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
 
HANDLE ghWinStaDir
 

Function Documentation

◆ BuildDesktopNameList()

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

Definition at line 1814 of file winsta.c.

1819{
1821 PWINSTATION_OBJECT WindowStation;
1822 PLIST_ENTRY DesktopEntry;
1823 PDESKTOP DesktopObject;
1824 DWORD EntryCount;
1826 WCHAR NullWchar;
1827 UNICODE_STRING DesktopName;
1828
1829 Status = IntValidateWindowStationHandle(hWindowStation,
1830 UserMode,
1831 0,
1832 &WindowStation,
1833 NULL);
1834 if (! NT_SUCCESS(Status))
1835 {
1836 return Status;
1837 }
1838
1839 /*
1840 * Count the required size of buffer.
1841 */
1842 ReturnLength = sizeof(DWORD);
1843 EntryCount = 0;
1844 for (DesktopEntry = WindowStation->DesktopListHead.Flink;
1845 DesktopEntry != &WindowStation->DesktopListHead;
1846 DesktopEntry = DesktopEntry->Flink)
1847 {
1848 DesktopObject = CONTAINING_RECORD(DesktopEntry, DESKTOP, ListEntry);
1849 RtlInitUnicodeString(&DesktopName, DesktopObject->pDeskInfo->szDesktopName);
1850 ReturnLength += DesktopName.Length + sizeof(WCHAR);
1851 EntryCount++;
1852 }
1853 TRACE("Required size: %lu Entry count: %lu\n", ReturnLength, EntryCount);
1854 if (NULL != pRequiredSize)
1855 {
1856 Status = MmCopyToCaller(pRequiredSize, &ReturnLength, sizeof(ULONG));
1857 if (! NT_SUCCESS(Status))
1858 {
1859 ObDereferenceObject(WindowStation);
1861 }
1862 }
1863
1864 /*
1865 * Check if the supplied buffer is large enough.
1866 */
1867 if (dwSize < ReturnLength)
1868 {
1869 ObDereferenceObject(WindowStation);
1871 }
1872
1873 /*
1874 * Generate the resulting buffer contents.
1875 */
1876 Status = MmCopyToCaller(lpBuffer, &EntryCount, sizeof(DWORD));
1877 if (! NT_SUCCESS(Status))
1878 {
1879 ObDereferenceObject(WindowStation);
1880 return Status;
1881 }
1882 lpBuffer = (PVOID) ((PCHAR) lpBuffer + sizeof(DWORD));
1883
1884 NullWchar = L'\0';
1885 for (DesktopEntry = WindowStation->DesktopListHead.Flink;
1886 DesktopEntry != &WindowStation->DesktopListHead;
1887 DesktopEntry = DesktopEntry->Flink)
1888 {
1889 DesktopObject = CONTAINING_RECORD(DesktopEntry, DESKTOP, ListEntry);
1890 RtlInitUnicodeString(&DesktopName, DesktopObject->pDeskInfo->szDesktopName);
1891 Status = MmCopyToCaller(lpBuffer, DesktopName.Buffer, DesktopName.Length);
1892 if (! NT_SUCCESS(Status))
1893 {
1894 ObDereferenceObject(WindowStation);
1895 return Status;
1896 }
1897 lpBuffer = (PVOID) ((PCHAR)lpBuffer + DesktopName.Length);
1898 Status = MmCopyToCaller(lpBuffer, &NullWchar, sizeof(WCHAR));
1899 if (! NT_SUCCESS(Status))
1900 {
1901 ObDereferenceObject(WindowStation);
1902 return Status;
1903 }
1904 lpBuffer = (PVOID) ((PCHAR) lpBuffer + sizeof(WCHAR));
1905 }
1906
1907 /*
1908 * Clean up and return
1909 */
1910 ObDereferenceObject(WindowStation);
1911 return STATUS_SUCCESS;
1912}
_In_ PVOID _In_ ULONG _Out_ PVOID _In_ ULONG _Inout_ PULONG ReturnLength
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define L(x)
Definition: resources.c:13
unsigned long DWORD
Definition: ntddk_ex.h:95
Status
Definition: gdiplustypes.h:24
#define MmCopyToCaller(x, y, z)
Definition: mmcopy.h:19
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define UserMode
Definition: asm.h:39
_Out_ LPWSTR lpBuffer
Definition: netsh.h:68
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define DWORD
Definition: nt_native.h:44
NTSTATUS FASTCALL IntValidateWindowStationHandle(HWINSTA WindowStation, KPROCESSOR_MODE AccessMode, ACCESS_MASK DesiredAccess, PWINSTATION_OBJECT *Object, POBJECT_HANDLE_INFORMATION pObjectHandleInfo)
Definition: winsta.c:225
short WCHAR
Definition: pedump.c:58
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define TRACE(s)
Definition: solgame.cpp:4
WCHAR szDesktopName[1]
Definition: ntuser.h:158
PDESKTOPINFO pDeskInfo
Definition: desktop.h:8
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
LIST_ENTRY DesktopListHead
Definition: winsta.h:19
void * PVOID
Definition: typedefs.h:50
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51
#define ObDereferenceObject
Definition: obfuncs.h:203

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 612 of file winsta.c.

617{
619 SIZE_T MemSize;
620
621 LUID CallerLuid;
622 PTEB Teb;
623 USHORT StrSize;
624
625 *WindowStationName = NULL;
626 *TebStaticUnicodeString = NULL;
627
628 /* Retrieve the current process LUID */
629 Status = GetProcessLuid(NULL, NULL, &CallerLuid);
630 if (!NT_SUCCESS(Status))
631 {
632 ERR("Failed to retrieve the caller LUID, Status 0x%08lx\n", Status);
633 return Status;
634 }
635
636 /* Compute the needed string size */
637 MemSize = _scwprintf(L"%wZ\\Service-0x%x-%x$",
639 CallerLuid.HighPart,
640 CallerLuid.LowPart);
641 MemSize = MemSize * sizeof(WCHAR) + sizeof(UNICODE_NULL);
642 if (MemSize > MAXUSHORT)
643 {
644 ERR("Window station name length is too long.\n");
646 }
647 StrSize = (USHORT)MemSize;
648
649 /*
650 * Check whether it's short enough so that we can use the static buffer
651 * in the TEB. Otherwise continue with virtual memory allocation.
652 */
653 Teb = NtCurrentTeb();
654 if (Teb && (StrSize <= sizeof(Teb->StaticUnicodeBuffer)))
655 {
656 /* We can use the TEB's static unicode string */
659
660 /* Remember the TEB's static unicode string address for later */
661 *TebStaticUnicodeString = &Teb->StaticUnicodeString;
662
663 *WindowStationName = *TebStaticUnicodeString;
664 (*WindowStationName)->Length = 0;
665 }
666 else
667 {
668 /* The TEB's static unicode string is too small, allocate some user-mode virtual memory */
669 MemSize += ALIGN_UP(sizeof(UNICODE_STRING), sizeof(PVOID));
670
671 /* Allocate the memory in user-mode */
672 Status = ZwAllocateVirtualMemory(ZwCurrentProcess(),
673 (PVOID*)WindowStationName,
674 0,
675 &MemSize,
678 if (!NT_SUCCESS(Status))
679 {
680 ERR("ZwAllocateVirtualMemory() failed, Status 0x%08lx\n", Status);
681 return Status;
682 }
683
684 RtlInitEmptyUnicodeString(*WindowStationName,
685 (PWCHAR)((ULONG_PTR)*WindowStationName +
686 ALIGN_UP(sizeof(UNICODE_STRING), sizeof(PVOID))),
687 StrSize);
688 }
689
690 /* Build a valid window station name from the LUID */
691 Status = RtlStringCbPrintfW((*WindowStationName)->Buffer,
692 (*WindowStationName)->MaximumLength,
693 L"%wZ\\Service-0x%x-%x$",
695 CallerLuid.HighPart,
696 CallerLuid.LowPart);
697 if (!NT_SUCCESS(Status))
698 {
699 ERR("Impossible to build a valid window station name, Status 0x%08lx\n", Status);
700 goto Quit;
701 }
702 (*WindowStationName)->Length = (USHORT)(wcslen((*WindowStationName)->Buffer) * sizeof(WCHAR));
703
704 /* Try to update the user's UserModeObjectAttributes */
706 {
707 ProbeForWrite(UserModeObjectAttributes, sizeof(OBJECT_ATTRIBUTES), sizeof(ULONG));
708 *LocalObjectAttributes = *UserModeObjectAttributes;
709
710 UserModeObjectAttributes->ObjectName = *WindowStationName;
711 UserModeObjectAttributes->RootDirectory = NULL;
712
714 }
716 {
718 }
719 _SEH2_END;
720
721Quit:
722 if (!NT_SUCCESS(Status))
723 {
724 /* Release the window station name */
725 FreeUserModeWindowStationName(*WindowStationName,
726 *TebStaticUnicodeString,
727 NULL, NULL);
728 }
729
730 return Status;
731}
#define ERR(fmt,...)
Definition: precomp.h:57
_ACRTIMP int __cdecl _scwprintf(const wchar_t *,...)
Definition: wcs.c:1678
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2988
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
#define NtCurrentTeb
#define ASSERT(a)
Definition: mode.c:44
#define PAGE_READWRITE
Definition: nt_native.h:1307
#define MEM_COMMIT
Definition: nt_native.h:1316
#define UNICODE_NULL
#define STATUS_NAME_TOO_LONG
Definition: ntstatus.h:592
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
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:578
UNICODE_STRING gustrWindowStationsDir
Definition: winsta.c:27
unsigned short USHORT
Definition: pedump.c:61
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:204
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:104
#define _SEH2_END
Definition: pseh2_64.h:194
#define _SEH2_TRY
Definition: pseh2_64.h:93
LONG HighPart
DWORD LowPart
Definition: compat.h:836
WCHAR StaticUnicodeBuffer[261]
Definition: compat.h:877
UNICODE_STRING StaticUnicodeString
Definition: compat.h:876
USHORT MaximumLength
Definition: env_spec_w32.h:370
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define MAXUSHORT
Definition: typedefs.h:83
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint16_t * PWCHAR
Definition: typedefs.h:56
#define ALIGN_UP(size, type)
Definition: umtypes.h:91
NTSTATUS GetProcessLuid(IN PETHREAD Thread OPTIONAL, IN PEPROCESS Process OPTIONAL, OUT PLUID Luid)
Definition: misc.c:814
#define ZwCurrentProcess()

Referenced by NtUserCreateWindowStation(), and NtUserOpenWindowStation().

◆ BuildWindowStationNameList()

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

Definition at line 1626 of file winsta.c.

1630{
1634 char InitialBuffer[256], *Buffer;
1636 DWORD EntryCount;
1638 WCHAR NullWchar;
1639
1640 //
1641 // FIXME: Fully wrong! Since, by calling NtUserCreateWindowStation
1642 // with judicious parameters one can create window stations elsewhere
1643 // than in Windows\WindowStations directory, Win32k definitely MUST
1644 // maintain a list of window stations it has created, and not rely
1645 // on the enumeration of Windows\WindowStations !!!
1646 //
1647
1648 /*
1649 * Try to open the directory.
1650 */
1654 NULL,
1655 NULL);
1656
1660
1661 if (!NT_SUCCESS(Status))
1662 {
1663 return Status;
1664 }
1665
1666 /* First try to query the directory using a fixed-size buffer */
1667 Context = 0;
1668 Buffer = NULL;
1669 Status = ZwQueryDirectoryObject(DirectoryHandle,
1670 InitialBuffer,
1671 sizeof(InitialBuffer),
1672 FALSE,
1673 TRUE,
1674 &Context,
1675 &ReturnLength);
1676 if (NT_SUCCESS(Status))
1677 {
1678 if (STATUS_NO_MORE_ENTRIES == ZwQueryDirectoryObject(DirectoryHandle, NULL, 0, FALSE,
1679 FALSE, &Context, NULL))
1680 {
1681 /* Our fixed-size buffer is large enough */
1682 Buffer = InitialBuffer;
1683 }
1684 }
1685
1686 if (NULL == Buffer)
1687 {
1688 /* Need a larger buffer, check how large exactly */
1689 Status = ZwQueryDirectoryObject(DirectoryHandle, NULL, 0, FALSE, TRUE, &Context,
1690 &ReturnLength);
1691 if (!NT_SUCCESS(Status))
1692 {
1693 ERR("ZwQueryDirectoryObject failed\n");
1695 return Status;
1696 }
1697
1700 if (NULL == Buffer)
1701 {
1703 return STATUS_NO_MEMORY;
1704 }
1705
1706 /* We should have a sufficiently large buffer now */
1707 Context = 0;
1708 Status = ZwQueryDirectoryObject(DirectoryHandle, Buffer, BufferSize,
1710 if (! NT_SUCCESS(Status) ||
1711 STATUS_NO_MORE_ENTRIES != ZwQueryDirectoryObject(DirectoryHandle, NULL, 0, FALSE,
1712 FALSE, &Context, NULL))
1713 {
1714 /* Something went wrong, maybe someone added a directory entry? Just give up. */
1718 }
1719 }
1720
1722
1723 /*
1724 * Count the required size of buffer.
1725 */
1726 ReturnLength = sizeof(DWORD);
1727 EntryCount = 0;
1729 0 != DirEntry->Name.Length;
1730 DirEntry++)
1731 {
1732 ReturnLength += DirEntry->Name.Length + sizeof(WCHAR);
1733 EntryCount++;
1734 }
1735 TRACE("Required size: %lu Entry count: %lu\n", ReturnLength, EntryCount);
1736 if (NULL != pRequiredSize)
1737 {
1738 Status = MmCopyToCaller(pRequiredSize, &ReturnLength, sizeof(ULONG));
1739 if (! NT_SUCCESS(Status))
1740 {
1741 if (Buffer != InitialBuffer)
1742 {
1744 }
1746 }
1747 }
1748
1749 /*
1750 * Check if the supplied buffer is large enough.
1751 */
1752 if (dwSize < ReturnLength)
1753 {
1754 if (Buffer != InitialBuffer)
1755 {
1757 }
1759 }
1760
1761 /*
1762 * Generate the resulting buffer contents.
1763 */
1764 Status = MmCopyToCaller(lpBuffer, &EntryCount, sizeof(DWORD));
1765 if (! NT_SUCCESS(Status))
1766 {
1767 if (Buffer != InitialBuffer)
1768 {
1770 }
1771 return Status;
1772 }
1773 lpBuffer = (PVOID) ((PCHAR) lpBuffer + sizeof(DWORD));
1774
1775 NullWchar = L'\0';
1777 0 != DirEntry->Name.Length;
1778 DirEntry++)
1779 {
1780 Status = MmCopyToCaller(lpBuffer, DirEntry->Name.Buffer, DirEntry->Name.Length);
1781 if (! NT_SUCCESS(Status))
1782 {
1783 if (Buffer != InitialBuffer)
1784 {
1786 }
1787 return Status;
1788 }
1789 lpBuffer = (PVOID) ((PCHAR) lpBuffer + DirEntry->Name.Length);
1790 Status = MmCopyToCaller(lpBuffer, &NullWchar, sizeof(WCHAR));
1791 if (! NT_SUCCESS(Status))
1792 {
1793 if (Buffer != InitialBuffer)
1794 {
1796 }
1797 return Status;
1798 }
1799 lpBuffer = (PVOID) ((PCHAR) lpBuffer + sizeof(WCHAR));
1800 }
1801
1802 /*
1803 * Clean up
1804 */
1805 if (Buffer != InitialBuffer)
1806 {
1808 }
1809
1810 return STATUS_SUCCESS;
1811}
static HANDLE DirectoryHandle
Definition: ObType.c:48
Definition: bufpool.h:45
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define BufferSize
Definition: mmc.h:75
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:115
NTSYSAPI NTSTATUS NTAPI ZwOpenDirectoryObject(_Out_ PHANDLE FileHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define DIRECTORY_QUERY
Definition: nt_native.h:1257
#define STATUS_INTERNAL_ERROR
Definition: ntstatus.h:559
#define STATUS_NO_MORE_ENTRIES
Definition: ntstatus.h:285
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
_In_ PVOID Context
Definition: storport.h:2269
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
#define TAG_WINSTA
Definition: tags.h:11

Referenced by NtUserBuildNameList().

◆ CheckWinstaAttributeAccess()

BOOL FASTCALL CheckWinstaAttributeAccess ( ACCESS_MASK  DesiredAccess)

Definition at line 381 of file winsta.c.

382{
385 {
386 if (!(ppi->W32PF_flags & W32PF_IOWINSTA))
387 {
388 ERR("Requires Interactive Window Station\n");
390 return FALSE;
391 }
393 {
394 ERR("Access Denied\n");
396 return FALSE;
397 }
398 }
399 return TRUE;
400}
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
NTSYSAPI BOOLEAN NTAPI RtlAreAllAccessesGranted(ACCESS_MASK GrantedAccess, ACCESS_MASK DesiredAccess)
PVOID NTAPI PsGetCurrentProcessWin32Process(VOID)
Definition: process.c:1183
HANDLE NTAPI PsGetCurrentProcessId(VOID)
Definition: process.c:1123
HANDLE gpidLogon
Definition: simplecall.c:15
ACCESS_MASK amwinsta
Definition: win32.h:269
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2664
#define W32PF_IOWINSTA
Definition: win32.h:23
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:21
#define ERROR_REQUIRES_INTERACTIVE_WINDOWSTATION
Definition: winerror.h:1285

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

◆ co_IntInitializeDesktopGraphics()

BOOL FASTCALL co_IntInitializeDesktopGraphics ( VOID  )

Definition at line 255 of file winsta.c.

256{
257 TEXTMETRICW tmw;
258 UNICODE_STRING DriverName = RTL_CONSTANT_STRING(L"DISPLAY");
259 PDESKTOP pdesk;
260 LONG lRet;
261
263 if (lRet != DISP_CHANGE_SUCCESSFUL && !gbBaseVideo)
264 {
265 ERR("Failed to initialize graphics, switching to base video\n");
271 }
272 if (lRet != DISP_CHANGE_SUCCESSFUL)
273 {
274 ERR("PDEVOBJ_lChangeDisplaySettings() failed.\n");
275 return FALSE;
276 }
277
280 {
282 return FALSE;
283 }
285
287 {
288 return FALSE;
289 }
290
292
295
296 /* Update the system metrics */
297 InitMetrics();
298
299 /* Set new size of the monitor */
301
302 /* Update the SERVERINFO */
307 gpsi->BitCount = gpsi->Planes * gpsi->BitsPixel;
310 {
311 gpsi->PUSIFlags |= PUSIF_PALETTEDISPLAY;
312 }
313 else
314 {
315 gpsi->PUSIFlags &= ~PUSIF_PALETTEDISPLAY;
316 }
317 // Font is realized and this dc was previously set to internal DC_ATTR.
318 gpsi->cxSysFontChar = IntGetCharDimensions(hSystemBM, &tmw, (DWORD*)&gpsi->cySysFontChar);
319 gpsi->tmSysFont = tmw;
320
321 /* Put the pointer in the center of the screen */
322 gpsi->ptCursor.x = gpsi->aiSysMet[SM_CXSCREEN] / 2;
323 gpsi->ptCursor.y = gpsi->aiSysMet[SM_CYSCREEN] / 2;
324
325 /* Attach monitor */
327
328 /* Setup the cursor */
330
331 /* Setup the icons */
333
334 /* Setup Menu */
335 MenuInit();
336
337 /* Show the desktop */
338 pdesk = IntGetActiveDesktop();
339 ASSERT(pdesk);
340 co_IntShowDesktop(pdesk, gpsi->aiSysMet[SM_CXSCREEN], gpsi->aiSysMet[SM_CYSCREEN], TRUE);
341
342 /* HACK: display wallpaper on all secondary displays */
343 {
344 PGRAPHICS_DEVICE pGraphicsDevice;
345 UNICODE_STRING DriverName = RTL_CONSTANT_STRING(L"DISPLAY");
346 UNICODE_STRING DisplayName;
347 HDC hdc;
348 ULONG iDevNum;
349
350 for (iDevNum = 1; (pGraphicsDevice = EngpFindGraphicsDevice(NULL, iDevNum)) != NULL; iDevNum++)
351 {
352 RtlInitUnicodeString(&DisplayName, pGraphicsDevice->szWinDeviceName);
353 hdc = IntGdiCreateDC(&DriverName, &DisplayName, NULL, NULL, FALSE);
355 }
356 }
357
358 return TRUE;
359}
BOOL NTAPI GreSetDCOwner(HDC hdc, ULONG ulOwner)
Definition: dclife.c:455
HDC FASTCALL IntGdiCreateDC(PUNICODE_STRING Driver, PUNICODE_STRING pustrDevice, PVOID pUMdhpdev, CONST PDEVMODEW pdmInit, BOOL CreateAsIC)
Definition: dclife.c:1040
#define RTL_CONSTANT_STRING(s)
Definition: combase.c:35
PSERVERINFO gpsi
Definition: imm.c:18
#define PUSIF_PALETTEDISPLAY
Definition: ntuser.h:993
HDC hSystemBM
Definition: stockobj.c:52
PMDEVOBJ gpmdev
Definition: mdevobj.c:14
HDC hdc
Definition: main.c:9
static HDC
Definition: imagelist.c:88
#define GDI_OBJ_HMGR_PUBLIC
Definition: ntgdihdl.h:116
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:849
long LONG
Definition: pedump.c:60
__kernel_entry W32KAPI HDC APIENTRY NtGdiCreateCompatibleDC(_In_opt_ HDC hdc)
__kernel_entry W32KAPI INT APIENTRY NtGdiGetDeviceCaps(_In_ HDC hdc, _In_ INT i)
__kernel_entry W32KAPI HANDLE APIENTRY NtGdiGetStockObject(_In_ INT iObject)
__kernel_entry W32KAPI HFONT APIENTRY NtGdiSelectFont(_In_ HDC hdc, _In_ HFONT hf)
Definition: dcobjs.c:597
ULONG ulVertRes
Definition: winddi.h:883
ULONG ulHorzRes
Definition: winddi.h:882
WCHAR szWinDeviceName[CCHDEVICENAME/2]
Definition: pdevobj.h:60
PPDEVOBJ ppdevGlobal
Definition: mdevobj.h:16
GDIINFO gdiinfo
Definition: pdevobj.h:123
PGRAPHICS_DEVICE NTAPI EngpFindGraphicsDevice(_In_opt_ PUNICODE_STRING pustrDevice, _In_ ULONG iDevNum)
Definition: device.c:795
NTSTATUS EngpUpdateGraphicsDeviceList(VOID)
Definition: device.c:182
BOOL FASTCALL IntCreatePrimarySurface(VOID)
Definition: device.c:17
VOID FASTCALL IntDestroyPrimarySurface(VOID)
Definition: device.c:32
DWORD FASTCALL IntGetCharDimensions(_In_ HDC hdc, _Out_opt_ PTEXTMETRICW ptm, _Out_opt_ PDWORD height)
Definition: font.c:337
BOOL APIENTRY co_IntLoadDefaultCursors(VOID)
Definition: callback.c:471
BOOL FASTCALL co_IntSetWndIcons(VOID)
Definition: callback.c:1101
PDESKTOP FASTCALL IntGetActiveDesktop(VOID)
Definition: desktop.c:1285
HDC ScreenDeviceContext
Definition: desktop.c:53
NTSTATUS FASTCALL co_IntShowDesktop(PDESKTOP Desktop, ULONG Width, ULONG Height, BOOL bRedraw)
Definition: desktop.c:1632
BOOL FASTCALL IntPaintDesktop(HDC hDC)
Definition: desktop.c:1852
BOOL gbBaseVideo
Definition: display.c:12
BOOL MenuInit(VOID)
Definition: menu.c:359
BOOL NTAPI InitMetrics(VOID)
Definition: metric.c:40
NTSTATUS NTAPI UserAttachMonitor(IN HDEV hDev)
Definition: monitor.c:129
NTSTATUS NTAPI UserUpdateMonitorSize(IN HDEV hDev)
Definition: monitor.c:225
#define RASTERCAPS
Definition: wingdi.h:745
#define LOGPIXELSY
Definition: wingdi.h:719
#define PLANES
Definition: wingdi.h:721
#define SYSTEM_FONT
Definition: wingdi.h:911
#define BITSPIXEL
Definition: wingdi.h:720
#define RC_PALETTE
Definition: wingdi.h:790
#define SM_CYSCREEN
Definition: winuser.h:971
#define DISP_CHANGE_SUCCESSFUL
Definition: winuser.h:190
#define SM_CXSCREEN
Definition: winuser.h:970

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 578 of file winsta.c.

583{
584 SIZE_T MemSize = 0;
585
586 /* Try to restore the user's UserModeObjectAttributes */
587 if (UserModeObjectAttributes && LocalObjectAttributes)
588 {
590 {
591 ProbeForWrite(UserModeObjectAttributes, sizeof(OBJECT_ATTRIBUTES), sizeof(ULONG));
592 *UserModeObjectAttributes = *LocalObjectAttributes;
593 }
595 {
596 NOTHING;
597 }
598 _SEH2_END;
599 }
600
601 /* Free the user-mode memory */
602 if (WindowStationName && (WindowStationName != TebStaticUnicodeString))
603 {
604 ZwFreeVirtualMemory(ZwCurrentProcess(),
605 (PVOID*)&WindowStationName,
606 &MemSize,
608 }
609}
#define NOTHING
Definition: input_list.c:10
#define MEM_RELEASE
Definition: nt_native.h:1319

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

◆ InitWindowStationImpl()

NTSTATUS NTAPI InitWindowStationImpl ( VOID  )

Definition at line 35 of file winsta.c.

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

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 450 of file winsta.c.

461{
463 HWINSTA hWinSta;
464 PWINSTATION_OBJECT WindowStation;
465
466 TRACE("IntCreateWindowStation called\n");
467
468 ASSERT(phWinSta);
469 *phWinSta = NULL;
470
474 NULL,
475 dwDesiredAccess,
476 NULL,
477 (PVOID*)&hWinSta);
478 if (NT_SUCCESS(Status))
479 {
480 TRACE("IntCreateWindowStation opened window station '%wZ'\n",
481 ObjectAttributes->ObjectName);
482 *phWinSta = hWinSta;
483 return Status;
484 }
485
486 /*
487 * No existing window station found, try to create a new one.
488 */
489
490 /* Create the window station object */
494 OwnerMode,
495 NULL,
496 sizeof(WINSTATION_OBJECT),
497 0,
498 0,
499 (PVOID*)&WindowStation);
500 if (!NT_SUCCESS(Status))
501 {
502 ERR("ObCreateObject failed for window station '%wZ', Status 0x%08lx\n",
503 ObjectAttributes->ObjectName, Status);
505 return Status;
506 }
507 RtlZeroMemory(WindowStation, sizeof(WINSTATION_OBJECT));
508
509 /* Assign the session ID to the window station */
510 WindowStation->dwSessionId = PsGetCurrentProcessSessionId(); // gSessionId
511
512 /* Initialize the window station */
513 InitializeListHead(&WindowStation->DesktopListHead);
514 Status = RtlCreateAtomTable(37, &WindowStation->AtomTable);
515 if (!NT_SUCCESS(Status))
516 {
517 ERR("RtlCreateAtomTable failed for window station '%wZ', Status 0x%08lx\n",
518 ObjectAttributes->ObjectName, Status);
519 ObDereferenceObject(WindowStation);
521 return Status;
522 }
523
524 Status = ObInsertObject(WindowStation,
525 NULL,
526 dwDesiredAccess,
527 0,
528 NULL,
529 (PVOID*)&hWinSta);
530 if (!NT_SUCCESS(Status))
531 {
532 ERR("ObInsertObject failed for window station, Status 0x%08lx\n", Status);
534 return Status;
535 }
536
537 // FIXME! TODO: Add this new window station to a linked list
538
540 {
541 ERR("Initializing input window station\n");
542
543 /* Only Winlogon can create the interactive window station */
545
546 InputWindowStation = WindowStation;
547 WindowStation->Flags &= ~WSS_NOIO;
548
550
553
554 /* Desktop functions require the desktop thread running so wait for it to initialize */
555 UserLeaveCo();
558 UserMode,
559 FALSE,
560 NULL);
561 UserEnterCo();
562 }
563 else
564 {
565 WindowStation->Flags |= WSS_NOIO;
566 }
567
568 TRACE("IntCreateWindowStation created window station '%wZ' object 0x%p handle 0x%p\n",
569 ObjectAttributes->ObjectName, WindowStation, hWinSta);
570
571 *phWinSta = hWinSta;
573
574 return STATUS_SUCCESS;
575}
BOOL UserCreateSystemThread(DWORD Type)
Definition: csr.c:247
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
NTSYSAPI NTSTATUS NTAPI RtlCreateAtomTable(_In_ ULONG TableSize, _Inout_ PRTL_ATOM_TABLE *AtomTable)
ULONG NTAPI PsGetCurrentProcessSessionId(VOID)
Definition: process.c:1133
PWINSTATION_OBJECT InputWindowStation
Definition: winsta.c:21
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:2938
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:2535
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:1039
DWORD dwSessionId
Definition: winsta.h:17
PRTL_ATOM_TABLE AtomTable
Definition: winsta.h:20
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define UserEnterCo
Definition: ntuser.h:3
#define UserLeaveCo
Definition: ntuser.h:4
VOID FASTCALL SetLastNtError(_In_ NTSTATUS Status)
Definition: error.c:30
#define ST_DESKTOP_THREAD
Definition: csr.h:36
#define ST_RIT
Definition: csr.h:35
BOOL InitCursorImpl(VOID)
Definition: cursoricon.c:64
PKEVENT gpDesktopThreadStartedEvent
Definition: desktop.c:56
#define WSS_NOIO
Definition: winsta.h:9
@ UserRequest
Definition: ketypes.h:473
_In_ PEPROCESS _In_ KPROCESSOR_MODE AccessMode
Definition: mmfuncs.h:396

Referenced by IntResolveDesktop(), and NtUserCreateWindowStation().

◆ IntEndDesktopGraphics()

VOID FASTCALL IntEndDesktopGraphics ( VOID  )

Definition at line 362 of file winsta.c.

363{
365 { // No need to allocate a new dcattr.
369 }
372}
#define GDI_OBJ_HMGR_POWNED
Definition: ntgdihdl.h:117
BOOL NTAPI GreDeleteObject(HGDIOBJ hobj)
Definition: gdiobj.c:1165
NTSTATUS FASTCALL IntHideDesktop(PDESKTOP Desktop)
Definition: desktop.c:1650

Referenced by RemoveGuiApp().

◆ IntGetProcessWindowStation()

PWINSTATION_OBJECT FASTCALL IntGetProcessWindowStation ( HWINSTA *phWinSta  OPTIONAL)

Definition at line 403 of file winsta.c.

404{
405 PWINSTATION_OBJECT pWinSta;
407 HWINSTA hWinSta = ppi->hwinsta;
408 if (phWinSta)
409 *phWinSta = hWinSta;
410 IntValidateWindowStationHandle(hWinSta, UserMode, 0, &pWinSta, 0);
411 return pWinSta;
412}
struct _PROCESSINFO * GetW32ProcessInfo(VOID)
Definition: misc.c:800
HWINSTA hwinsta
Definition: win32.h:268

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

◆ IntGetScreenDC()

HDC FASTCALL IntGetScreenDC ( VOID  )

Definition at line 375 of file winsta.c.

376{
377 return ScreenDeviceContext;
378}

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 225 of file winsta.c.

231{
233
234 if (WindowStation == NULL)
235 {
236 ERR("Invalid window station handle\n");
239 }
240
241 Status = ObReferenceObjectByHandle(WindowStation,
245 (PVOID*)Object,
246 pObjectHandleInfo);
247
248 if (!NT_SUCCESS(Status))
250
251 return Status;
252}
#define STATUS_INVALID_HANDLE
Definition: d3dkmdt.h:40
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
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:493
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object

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 99 of file winsta.c.

101{
103 PWINSTATION_OBJECT WinSta = (PWINSTATION_OBJECT)DeleteParameters->Object;
104
105 TRACE("Deleting window station 0x%p\n", WinSta);
106
107 if (WinSta == InputWindowStation)
108 {
109 ERR("WARNING: Deleting the interactive window station '%wZ'!\n",
111
112 /* Only Winlogon can close and delete the interactive window station */
114
116 }
117
118 WinSta->Flags |= WSS_DYING;
119
121
123
125
126 return STATUS_SUCCESS;
127}
LPWSTR Name
Definition: desk.c:124
#define OBJECT_HEADER_TO_NAME_INFO(h)
Definition: obtypes.h:114
#define OBJECT_TO_OBJECT_HEADER(o)
Definition: obtypes.h:111
NTSYSAPI NTSTATUS NTAPI RtlDestroyAtomTable(IN PRTL_ATOM_TABLE AtomTable)
Definition: atom.c:204
struct tagKL * spklList
Definition: winsta.h:23
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:869
VOID NTAPI UserEmptyClipboardData(PWINSTATION_OBJECT pWinSta)
Definition: clipboard.c:354
PVOID FASTCALL UserAssignmentUnlock(PVOID *ppvObj)
Definition: object.c:857
struct _WINSTATION_OBJECT * PWINSTATION_OBJECT
#define WSS_DYING
Definition: winsta.h:11

Referenced by DriverEntry().

◆ IntWinStaObjectParse()

NTSTATUS NTAPI IntWinStaObjectParse ( _In_ PVOID  Parameters)

Definition at line 131 of file winsta.c.

133{
136
137 /* Assume we don't find anything */
138 *ParseParameters->Object = NULL;
139
140 /* Check for an empty name */
141 if (!RemainingName->Length)
142 {
143 /* Make sure this is a window station, can't parse a desktop now */
144 if (ParseParameters->ObjectType != ExWindowStationObjectType)
145 {
146 /* Fail */
148 }
149
150 /* Reference the window station and return */
151 ObReferenceObject(ParseParameters->ParseObject);
152 *ParseParameters->Object = ParseParameters->ParseObject;
153 return STATUS_SUCCESS;
154 }
155
156 /* Check for leading slash */
157 if (RemainingName->Buffer[0] == OBJ_NAME_PATH_SEPARATOR)
158 {
159 /* Skip it */
160 RemainingName->Buffer++;
161 RemainingName->Length -= sizeof(WCHAR);
162 RemainingName->MaximumLength -= sizeof(WCHAR);
163 }
164
165 /* Check if there is still a slash */
167 {
168 /* In this case, fail */
170 }
171
172 /*
173 * Check if we are parsing a desktop.
174 */
175 if (ParseParameters->ObjectType == ExDesktopObjectType)
176 {
177 /* Then call the desktop parse routine */
178 return IntDesktopObjectParse(ParseParameters->ParseObject,
179 ParseParameters->ObjectType,
180 ParseParameters->AccessState,
181 ParseParameters->AccessMode,
182 ParseParameters->Attributes,
183 ParseParameters->CompleteName,
185 ParseParameters->Context,
186 ParseParameters->SecurityQos,
187 ParseParameters->Object);
188 }
189
190 /* Should hopefully never get here */
192}
#define OBJ_NAME_PATH_SEPARATOR
Definition: arcname_tests.c:25
_Inout_ PFCB _Inout_ PUNICODE_STRING RemainingName
Definition: cdprocs.h:802
#define STATUS_OBJECT_TYPE_MISMATCH
Definition: d3dkmdt.h:46
#define wcschr
Definition: compat.h:17
#define STATUS_OBJECT_PATH_INVALID
Definition: ntstatus.h:387
PUNICODE_STRING RemainingName
Definition: pstypes.h:1761
_Out_ PUNICODE_STRING CompleteName
Definition: pstypes.h:1760
PSECURITY_QUALITY_OF_SERVICE SecurityQos
Definition: pstypes.h:1763
KPROCESSOR_MODE AccessMode
Definition: pstypes.h:1758
POBJECT_TYPE ExDesktopObjectType
Definition: win32k.c:22
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:62
#define ObReferenceObject
Definition: obfuncs.h:204

Referenced by DriverEntry().

◆ IntWinStaOkToClose()

NTSTATUS NTAPI IntWinStaOkToClose ( _In_ PVOID  Parameters)

Definition at line 196 of file winsta.c.

198{
200 PPROCESSINFO ppi;
201
203
204 if (ppi && (OkToCloseParameters->Handle == ppi->hwinsta))
205 {
207 }
208
209 return STATUS_SUCCESS;
210}
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145

Referenced by DriverEntry().

◆ NtUserBuildNameList()

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

Definition at line 1941 of file winsta.c.

1946{
1947 /* The WindowStation name list and desktop name list are build in completely
1948 different ways. Call the appropriate function */
1949 return NULL == hWindowStation ? BuildWindowStationNameList(dwSize, lpBuffer, pRequiredSize) :
1950 BuildDesktopNameList(hWindowStation, dwSize, lpBuffer, pRequiredSize);
1951}
static NTSTATUS FASTCALL BuildWindowStationNameList(ULONG dwSize, PVOID lpBuffer, PULONG pRequiredSize)
Definition: winsta.c:1626
static NTSTATUS FASTCALL BuildDesktopNameList(HWINSTA hWindowStation, ULONG dwSize, PVOID lpBuffer, PULONG pRequiredSize)
Definition: winsta.c:1814

Referenced by EnumNamesW().

◆ NtUserCloseWindowStation()

BOOL APIENTRY NtUserCloseWindowStation ( HWINSTA  hWinSta)

Definition at line 1023 of file winsta.c.

1025{
1028
1029 TRACE("NtUserCloseWindowStation called (%p)\n", hWinSta);
1030
1031 if (hWinSta == UserGetProcessWindowStation())
1032 {
1033 ERR("Attempted to close process window station\n");
1034 return FALSE;
1035 }
1036
1038 UserMode,
1039 0,
1040 &Object,
1041 NULL);
1042 if (!NT_SUCCESS(Status))
1043 {
1044 ERR("Validation of window station handle (%p) failed\n", hWinSta);
1045 return FALSE;
1046 }
1047
1049
1050 TRACE("Closing window station handle (%p)\n", hWinSta);
1051
1052 Status = ObCloseHandle(hWinSta, UserMode);
1053 if (!NT_SUCCESS(Status))
1054 {
1056 return FALSE;
1057 }
1058
1059 return TRUE;
1060}
HWINSTA FASTCALL UserGetProcessWindowStation(VOID)
Definition: winsta.c:1357
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3388

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 735 of file winsta.c.

743{
745 HWINSTA hWinSta = NULL;
746 OBJECT_ATTRIBUTES LocalObjectAttributes;
747 PUNICODE_STRING WindowStationName = NULL;
748 PUNICODE_STRING TebStaticUnicodeString = NULL;
749 KPROCESSOR_MODE OwnerMode = UserMode;
750
751 TRACE("NtUserCreateWindowStation called\n");
752
753 /* Capture the object attributes and the window station name */
755 {
757 LocalObjectAttributes = *ObjectAttributes;
758 if (LocalObjectAttributes.Length != sizeof(OBJECT_ATTRIBUTES))
759 {
760 ERR("Invalid ObjectAttributes length!\n");
763 }
764
765 /*
766 * Check whether the caller provided a window station name together
767 * with a RootDirectory handle.
768 *
769 * If the caller did not provide a window station name, build a new one
770 * based on the logon session identifier for the calling process.
771 * The new name is allocated in user-mode, as the rest of ObjectAttributes
772 * already is, so that the validation performed by the Object Manager
773 * can be done adequately.
774 */
775 if ((LocalObjectAttributes.ObjectName == NULL ||
776 LocalObjectAttributes.ObjectName->Buffer == NULL ||
777 LocalObjectAttributes.ObjectName->Length == 0 ||
778 LocalObjectAttributes.ObjectName->Buffer[0] == UNICODE_NULL)
779 /* &&
780 LocalObjectAttributes.RootDirectory == NULL */)
781 {
782 /* No, build the new window station name */
784 &LocalObjectAttributes,
785 &WindowStationName,
786 &TebStaticUnicodeString);
787 if (!NT_SUCCESS(Status))
788 {
789 ERR("BuildUserModeWindowStationName() failed, Status 0x%08lx\n", Status);
791 }
792 OwnerMode = KernelMode;
793 }
794 }
796 {
798 ERR("ObjectAttributes capture failed, Status 0x%08lx\n", Status);
799 }
800 _SEH2_END;
801
802 if (!NT_SUCCESS(Status))
803 {
805 return NULL;
806 }
807
809
810 /* Create the window station */
813 UserMode,
814 OwnerMode,
815 dwDesiredAccess,
816 Unknown2,
817 Unknown3,
818 Unknown4,
819 Unknown5,
820 Unknown6);
821 UserLeave();
822
823 if (NT_SUCCESS(Status))
824 {
825 TRACE("NtUserCreateWindowStation created window station '%wZ' with handle 0x%p\n",
826 ObjectAttributes->ObjectName, hWinSta);
827 }
828 else
829 {
830 ASSERT(hWinSta == NULL);
831 ERR("NtUserCreateWindowStation failed to create window station '%wZ', Status 0x%08lx\n",
832 ObjectAttributes->ObjectName, Status);
833 }
834
835 /* Try to restore the user's ObjectAttributes and release the window station name */
836 FreeUserModeWindowStationName(WindowStationName,
837 TebStaticUnicodeString,
838 (OwnerMode == KernelMode ? ObjectAttributes : NULL),
839 &LocalObjectAttributes);
840
841 if (!NT_SUCCESS(Status))
842 {
843 ASSERT(hWinSta == NULL);
845 }
846
847 return hWinSta;
848}
PRTL_UNICODE_STRING_BUFFER PULONG PULONG Unknown4
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES IN DWORD IN DWORD IN DWORD IN DWORD Unknown6
Definition: conport.c:40
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES IN DWORD IN DWORD IN DWORD Unknown5
Definition: conport.c:39
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES IN DWORD Unknown3
Definition: conport.c:37
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
#define KernelMode
Definition: asm.h:38
static NTSTATUS BuildUserModeWindowStationName(IN OUT POBJECT_ATTRIBUTES UserModeObjectAttributes, IN OUT POBJECT_ATTRIBUTES LocalObjectAttributes, OUT PUNICODE_STRING *WindowStationName, OUT PUNICODE_STRING *TebStaticUnicodeString)
Definition: winsta.c:612
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:450
VOID FASTCALL UserLeave(VOID)
Definition: ntuser.c:255
VOID FASTCALL UserEnterExclusive(VOID)
Definition: ntuser.c:247
#define _SEH2_LEAVE
Definition: pseh2_64.h:206
PUNICODE_STRING ObjectName
Definition: umtypes.h:187
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7

Referenced by CreateWindowStationW().

◆ NtUserGetObjectInformation()

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

Definition at line 1103 of file winsta.c.

1109{
1111 PWINSTATION_OBJECT WinStaObject = NULL;
1112 PDESKTOP DesktopObject = NULL;
1113 POBJECT_HEADER ObjectHeader;
1114 POBJECT_HEADER_NAME_INFO NameInfo;
1115 OBJECT_HANDLE_INFORMATION HandleInfo;
1116 USEROBJECTFLAGS ObjectFlags;
1117 PUNICODE_STRING pStrNameU = NULL;
1118 PVOID pvData = NULL;
1119 SIZE_T nDataSize = 0;
1120
1121 _SEH2_TRY
1122 {
1123 if (nLengthNeeded)
1124 ProbeForWrite(nLengthNeeded, sizeof(*nLengthNeeded), 1);
1125 ProbeForWrite(pvInformation, nLength, 1);
1126 }
1128 {
1130 return FALSE;
1131 }
1132 _SEH2_END;
1133
1134 /* Try window station */
1135 TRACE("Trying to open window station 0x%p\n", hObject);
1137 0,
1139 UserMode,
1140 (PVOID*)&WinStaObject,
1141 &HandleInfo);
1142
1144 {
1145 /* Try desktop */
1146 TRACE("Trying to open desktop %p\n", hObject);
1147 WinStaObject = NULL;
1149 UserMode,
1150 0,
1151 &DesktopObject);
1152 }
1153
1154 if (!NT_SUCCESS(Status))
1155 {
1156 ERR("Failed: 0x%x\n", Status);
1157 goto Exit;
1158 }
1159
1160 TRACE("WinSta or Desktop opened!\n");
1161
1162 /* Get data */
1163 switch (nIndex)
1164 {
1165 case UOI_FLAGS:
1166 {
1167 ObjectFlags.fReserved = FALSE;
1168 ObjectFlags.fInherit = !!(HandleInfo.HandleAttributes & OBJ_INHERIT);
1169
1170 ObjectFlags.dwFlags = 0;
1171 if (WinStaObject != NULL)
1172 {
1173 if (!(WinStaObject->Flags & WSS_NOIO))
1174 ObjectFlags.dwFlags |= WSF_VISIBLE;
1175 }
1176 else if (DesktopObject != NULL)
1177 {
1178 FIXME("Setting DF_ALLOWOTHERACCOUNTHOOK is unimplemented.\n");
1179 }
1180 else
1181 {
1182 ERR("No associated WinStaObject nor DesktopObject!\n");
1183 }
1184
1185 pvData = &ObjectFlags;
1186 nDataSize = sizeof(ObjectFlags);
1188 break;
1189 }
1190
1191 case UOI_NAME:
1192 {
1193 if (WinStaObject != NULL)
1194 {
1195 ObjectHeader = OBJECT_TO_OBJECT_HEADER(WinStaObject);
1196 NameInfo = OBJECT_HEADER_TO_NAME_INFO(ObjectHeader);
1197
1198 if (NameInfo && (NameInfo->Name.Length > 0))
1199 {
1200 /* Named window station */
1201 pStrNameU = &NameInfo->Name;
1202 nDataSize = pStrNameU->Length + sizeof(UNICODE_NULL);
1203 }
1204 else
1205 {
1206 /* Unnamed window station (should never happen!) */
1207 ASSERT(FALSE);
1208 pStrNameU = NULL;
1209 nDataSize = sizeof(UNICODE_NULL);
1210 }
1212 }
1213 else if (DesktopObject != NULL)
1214 {
1215 pvData = DesktopObject->pDeskInfo->szDesktopName;
1216 nDataSize = (wcslen(DesktopObject->pDeskInfo->szDesktopName) + 1) * sizeof(WCHAR);
1218 }
1219 else
1220 {
1222 }
1223 break;
1224 }
1225
1226 case UOI_TYPE:
1227 {
1228 if (WinStaObject != NULL)
1229 {
1230 ObjectHeader = OBJECT_TO_OBJECT_HEADER(WinStaObject);
1231 pStrNameU = &ObjectHeader->Type->Name;
1232 nDataSize = pStrNameU->Length + sizeof(UNICODE_NULL);
1234 }
1235 else if (DesktopObject != NULL)
1236 {
1237 ObjectHeader = OBJECT_TO_OBJECT_HEADER(DesktopObject);
1238 pStrNameU = &ObjectHeader->Type->Name;
1239 nDataSize = pStrNameU->Length + sizeof(UNICODE_NULL);
1241 }
1242 else
1243 {
1245 }
1246 break;
1247 }
1248
1249 case UOI_USER_SID:
1251 ERR("UOI_USER_SID unimplemented!\n");
1252 break;
1253
1254 default:
1256 break;
1257 }
1258
1259Exit:
1260 if ((Status == STATUS_SUCCESS) && (nLength < nDataSize))
1262
1263 _SEH2_TRY
1264 {
1265 if (nLengthNeeded)
1266 *nLengthNeeded = nDataSize;
1267
1268 /* Try to copy data to caller */
1269 if (Status == STATUS_SUCCESS && (nDataSize > 0))
1270 {
1271 TRACE("Trying to copy data to caller (len = %lu, len needed = %lu)\n", nLength, nDataSize);
1272 if (pvData)
1273 {
1274 /* Copy the data */
1275 RtlCopyMemory(pvInformation, pvData, nDataSize);
1276 }
1277 else if (pStrNameU)
1278 {
1279 /* Copy and NULL-terminate the string */
1280 RtlCopyMemory(pvInformation, pStrNameU->Buffer, pStrNameU->Length);
1281 ((PWCHAR)pvInformation)[pStrNameU->Length / sizeof(WCHAR)] = UNICODE_NULL;
1282 }
1283 else
1284 {
1285 /* Zero the memory */
1286 RtlZeroMemory(pvInformation, nDataSize);
1287 }
1288 }
1289 }
1291 {
1293 }
1294 _SEH2_END;
1295
1296 /* Release objects */
1297 if (DesktopObject != NULL)
1298 ObDereferenceObject(DesktopObject);
1299 if (WinStaObject != NULL)
1300 ObDereferenceObject(WinStaObject);
1301
1302 if (!NT_SUCCESS(Status))
1303 {
1305 return FALSE;
1306 }
1307
1308 return TRUE;
1309}
#define FIXME(fmt,...)
Definition: precomp.h:53
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42
_In_ LPWSTR _In_ DWORD _In_ LPCVOID pvData
Definition: netsh.h:116
#define OBJ_INHERIT
Definition: winternl.h:225
static void Exit(void)
Definition: sock.c:1330
UNICODE_STRING Name
Definition: obtypes.h:433
POBJECT_TYPE Type
Definition: obtypes.h:493
UNICODE_STRING Name
Definition: obtypes.h:383
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
NTSTATUS FASTCALL IntValidateDesktopHandle(HDESK Desktop, KPROCESSOR_MODE AccessMode, ACCESS_MASK DesiredAccess, PDESKTOP *Object)
Definition: desktop.c:1260
WINBASEAPI _In_ DWORD nLength
Definition: wincon.h:682
#define UOI_NAME
Definition: winuser.h:1095
#define UOI_TYPE
Definition: winuser.h:1096
#define UOI_USER_SID
Definition: winuser.h:1097
#define WSF_VISIBLE
Definition: winuser.h:2488
#define UOI_FLAGS
Definition: winuser.h:1094

Referenced by GetUserObjectInformationW().

◆ NtUserGetProcessWindowStation()

HWINSTA APIENTRY NtUserGetProcessWindowStation ( VOID  )

Definition at line 1380 of file winsta.c.

1381{
1383}

Referenced by CreateDesktopW(), and GetProcessWindowStation().

◆ NtUserLockWindowStation()

BOOL APIENTRY NtUserLockWindowStation ( HWINSTA  hWindowStation)

Definition at line 1545 of file winsta.c.

1546{
1549
1550 TRACE("About to set process window station with handle (%p)\n",
1551 hWindowStation);
1552
1554 {
1555 ERR("Unauthorized process attempted to lock the window station!\n");
1557 return FALSE;
1558 }
1559
1560 Status = IntValidateWindowStationHandle(hWindowStation,
1561 UserMode,
1562 0,
1563 &Object,
1564 NULL);
1565 if (!NT_SUCCESS(Status))
1566 {
1567 TRACE("Validation of window station handle (%p) failed\n",
1568 hWindowStation);
1570 return FALSE;
1571 }
1572
1573 Object->Flags |= WSS_LOCKED;
1574
1576 return TRUE;
1577}
#define WSS_LOCKED
Definition: winsta.h:7

Referenced by LockWindowStation().

◆ NtUserLockWorkStation()

BOOL APIENTRY NtUserLockWorkStation ( VOID  )

Definition at line 1982 of file winsta.c.

1983{
1984 BOOL ret;
1986
1988
1989 if (pti->rpdesk == IntGetActiveDesktop())
1990 {
1992 }
1993 else
1994 {
1995 ret = FALSE;
1996 }
1997
1998 UserLeave();
1999
2000 return ret;
2001}
return ret
Definition: mutex.c:146
unsigned int BOOL
Definition: ntddk_ex.h:94
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
HWND hwndSAS
Definition: winsta.c:24
struct _DESKTOP * rpdesk
Definition: win32.h:92
#define LN_LOCK_WORKSTATION
Definition: undocuser.h:119
#define WM_LOGONNOTIFY
Definition: undocuser.h:39
BOOL FASTCALL UserPostMessage(HWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: message.c:1395

Referenced by LockWorkStation().

◆ NtUserOpenWindowStation()

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

Definition at line 876 of file winsta.c.

879{
881 HWINSTA hWinSta = NULL;
882 OBJECT_ATTRIBUTES LocalObjectAttributes;
883 PUNICODE_STRING WindowStationName = NULL;
884 PUNICODE_STRING TebStaticUnicodeString = NULL;
885 KPROCESSOR_MODE OwnerMode = UserMode;
886
887 TRACE("NtUserOpenWindowStation called\n");
888
889 /* Capture the object attributes and the window station name */
891 {
893 LocalObjectAttributes = *ObjectAttributes;
894 if (LocalObjectAttributes.Length != sizeof(OBJECT_ATTRIBUTES))
895 {
896 ERR("Invalid ObjectAttributes length!\n");
899 }
900
901 /*
902 * Check whether the caller did not provide a window station name,
903 * or provided the special "Service-0x00000000-00000000$" name.
904 *
905 * NOTE: On Windows, the special "Service-0x00000000-00000000$" string
906 * is used instead of an empty name (observed when API-monitoring
907 * OpenWindowStation() called with an empty window station name).
908 */
909 if ((LocalObjectAttributes.ObjectName == NULL ||
910 LocalObjectAttributes.ObjectName->Buffer == NULL ||
911 LocalObjectAttributes.ObjectName->Length == 0 ||
912 LocalObjectAttributes.ObjectName->Buffer[0] == UNICODE_NULL)
913 /* &&
914 LocalObjectAttributes.RootDirectory == NULL */)
915 {
916 /* No, remember that for later */
917 LocalObjectAttributes.ObjectName = NULL;
918 }
919 if (LocalObjectAttributes.ObjectName &&
920 LocalObjectAttributes.ObjectName->Length ==
921 sizeof(L"Service-0x00000000-00000000$") - sizeof(UNICODE_NULL) &&
922 _wcsnicmp(LocalObjectAttributes.ObjectName->Buffer,
923 L"Service-0x00000000-00000000$",
924 LocalObjectAttributes.ObjectName->Length / sizeof(WCHAR)) == 0)
925 {
926 /* No, remember that for later */
927 LocalObjectAttributes.ObjectName = NULL;
928 }
929
930 /*
931 * If the caller did not provide a window station name, build a new one
932 * based on the logon session identifier for the calling process.
933 * The new name is allocated in user-mode, as the rest of ObjectAttributes
934 * already is, so that the validation performed by the Object Manager
935 * can be done adequately.
936 */
937 if (!LocalObjectAttributes.ObjectName)
938 {
939 /* No, build the new window station name */
941 &LocalObjectAttributes,
942 &WindowStationName,
943 &TebStaticUnicodeString);
944 if (!NT_SUCCESS(Status))
945 {
946 ERR("BuildUserModeWindowStationName() failed, Status 0x%08lx\n", Status);
948 }
949 OwnerMode = KernelMode;
950 }
951 }
953 {
955 ERR("ObjectAttributes capture failed, Status 0x%08lx\n", Status);
956 }
957 _SEH2_END;
958
959 if (!NT_SUCCESS(Status))
960 {
962 return NULL;
963 }
964
965 /* Open the window station */
968 UserMode,
969 NULL,
970 dwDesiredAccess,
971 NULL,
972 (PVOID*)&hWinSta);
973 if (NT_SUCCESS(Status))
974 {
975 TRACE("NtUserOpenWindowStation opened window station '%wZ' with handle 0x%p\n",
976 ObjectAttributes->ObjectName, hWinSta);
977 }
978 else
979 {
980 ASSERT(hWinSta == NULL);
981 ERR("NtUserOpenWindowStation failed to open window station '%wZ', Status 0x%08lx\n",
982 ObjectAttributes->ObjectName, Status);
983 }
984
985 /* Try to restore the user's ObjectAttributes and release the window station name */
986 FreeUserModeWindowStationName(WindowStationName,
987 TebStaticUnicodeString,
988 (OwnerMode == KernelMode ? ObjectAttributes : NULL),
989 &LocalObjectAttributes);
990
991 if (!NT_SUCCESS(Status))
992 {
993 ASSERT(hWinSta == NULL);
995 }
996
997 return hWinSta;
998}
_ACRTIMP int __cdecl _wcsnicmp(const wchar_t *, const wchar_t *, size_t)
Definition: wcs.c:200

Referenced by OpenWindowStationW().

◆ NtUserSetLogonNotifyWindow()

BOOL APIENTRY NtUserSetLogonNotifyWindow ( HWND  hWnd)

Definition at line 1957 of file winsta.c.

1958{
1959 BOOL Ret = FALSE;
1960
1962
1963 if (!IntIsWindow(hWnd))
1964 goto Leave;
1965
1967 {
1969 goto Leave;
1970 }
1971
1972 hwndSAS = hWnd;
1973 Ret = TRUE;
1974
1975Leave:
1976 UserLeave();
1977 return Ret;
1978}
HWND hWnd
Definition: settings.c:17
BOOL FASTCALL IntIsWindow(HWND hWnd)
Definition: window.c:177

Referenced by SetLogonNotifyWindow().

◆ NtUserSetObjectInformation()

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

Definition at line 1343 of file winsta.c.

1348{
1349 /* FIXME: ZwQueryObject */
1350 /* FIXME: ZwSetInformationObject */
1352 return FALSE;
1353}
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

◆ NtUserSetProcessWindowStation()

BOOL APIENTRY NtUserSetProcessWindowStation ( HWINSTA  hWindowStation)

Definition at line 1522 of file winsta.c.

1523{
1524 BOOL ret;
1525
1527
1528 ret = UserSetProcessWindowStation(hWindowStation);
1529
1530 UserLeave();
1531
1532 return ret;
1533}
BOOL FASTCALL UserSetProcessWindowStation(HWINSTA hWindowStation)
Definition: winsta.c:1386

Referenced by SetProcessWindowStation().

◆ NtUserSetWindowStationUser()

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

Definition at line 2005 of file winsta.c.

2010{
2011 BOOL Ret = FALSE;
2013 PWINSTATION_OBJECT WindowStation = NULL;
2014 LUID luidUser;
2015
2017
2019 {
2021 goto Leave;
2022 }
2023
2024 /* Validate the window station */
2025 Status = IntValidateWindowStationHandle(hWindowStation,
2026 UserMode,
2027 0,
2028 &WindowStation,
2029 NULL);
2030 if (!NT_SUCCESS(Status))
2031 {
2032 goto Leave;
2033 }
2034
2035 /* Capture the user LUID */
2036 _SEH2_TRY
2037 {
2038 ProbeForRead(pluid, sizeof(LUID), 1);
2039 luidUser = *pluid;
2040 }
2042 {
2044 _SEH2_YIELD(goto Leave);
2045 }
2046 _SEH2_END;
2047
2048 /* Reset the window station user LUID */
2049 RtlZeroMemory(&WindowStation->luidUser, sizeof(LUID));
2050
2051 /* Reset the window station user SID */
2052 if (WindowStation->psidUser)
2053 {
2055 WindowStation->psidUser = NULL;
2056 }
2057
2058 /* Copy the new user SID if one has been provided */
2059 if (psid)
2060 {
2062 if (WindowStation->psidUser == NULL)
2063 {
2065 goto Leave;
2066 }
2067
2069 _SEH2_TRY
2070 {
2071 ProbeForRead(psid, size, 1);
2072 RtlCopyMemory(WindowStation->psidUser, psid, size);
2073 }
2075 {
2077 }
2078 _SEH2_END;
2079
2080 if (!NT_SUCCESS(Status))
2081 {
2083 WindowStation->psidUser = NULL;
2084 goto Leave;
2085 }
2086 }
2087
2088 /* Copy the new user LUID */
2089 WindowStation->luidUser = luidUser;
2090
2091 Ret = TRUE;
2092
2093Leave:
2094 if (WindowStation)
2095 ObDereferenceObject(WindowStation);
2096
2097 UserLeave();
2098 return Ret;
2099}
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
GLsizeiptr size
Definition: glext.h:5919
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:207
PVOID psidUser
Definition: winsta.h:39
#define USERTAG_SECURITY
Definition: tags.h:275

Referenced by SetWindowStationUser().

◆ NtUserUnlockWindowStation()

BOOL APIENTRY NtUserUnlockWindowStation ( HWINSTA  hWindowStation)

Definition at line 1589 of file winsta.c.

1590{
1593 BOOL Ret;
1594
1595 TRACE("About to set process window station with handle (%p)\n",
1596 hWindowStation);
1597
1599 {
1600 ERR("Unauthorized process attempted to unlock the window station!\n");
1602 return FALSE;
1603 }
1604
1605 Status = IntValidateWindowStationHandle(hWindowStation,
1606 UserMode,
1607 0,
1608 &Object,
1609 NULL);
1610 if (!NT_SUCCESS(Status))
1611 {
1612 TRACE("Validation of window station handle (%p) failed\n",
1613 hWindowStation);
1615 return FALSE;
1616 }
1617
1618 Ret = (Object->Flags & WSS_LOCKED) == WSS_LOCKED;
1619 Object->Flags &= ~WSS_LOCKED;
1620
1622 return Ret;
1623}

Referenced by UnlockWindowStation().

◆ UserCreateWinstaDirectory()

NTSTATUS NTAPI UserCreateWinstaDirectory ( VOID  )

Definition at line 52 of file winsta.c.

53{
57 WCHAR wstrWindowStationsDir[MAX_PATH];
58
59 /* Create the WindowStations directory and cache its path for later use */
61 if (SessionId == 0)
62 {
65 }
66 else
67 {
68 Status = RtlStringCbPrintfW(wstrWindowStationsDir,
69 sizeof(wstrWindowStationsDir),
70 L"%ws\\%lu%ws",
74 if (!NT_SUCCESS(Status))
75 return Status;
76
77 if (!RtlCreateUnicodeString(&gustrWindowStationsDir, wstrWindowStationsDir))
79 }
80
84 NULL,
85 NULL);
87 if (!NT_SUCCESS(Status))
88 ERR("Could not create %wZ directory (Status 0x%X)\n", &gustrWindowStationsDir, Status);
89 else
90 TRACE("Created directory %wZ for session %lu\n", &gustrWindowStationsDir, SessionId);
91
92 return Status;
93}
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define MAX_PATH
Definition: compat.h:34
ULONG SessionId
Definition: dllmain.c:28
#define SESSION_DIR
Definition: dllmain.c:38
NTSYSAPI NTSTATUS NTAPI ZwCreateDirectoryObject(_Out_ PHANDLE DirectoryHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
#define DIRECTORY_CREATE_OBJECT
Definition: nt_native.h:1259
HANDLE ghWinStaDir
Definition: winsta.c:28
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define WINSTA_OBJ_DIR
Definition: winsta.h:3

Referenced by UserInitialize().

◆ UserGetProcessWindowStation()

HWINSTA FASTCALL UserGetProcessWindowStation ( VOID  )

Definition at line 1357 of file winsta.c.

1358{
1360
1361 return ppi->hwinsta;
1362}

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

◆ UserSetProcessWindowStation()

BOOL FASTCALL UserSetProcessWindowStation ( HWINSTA  hWindowStation)

Definition at line 1386 of file winsta.c.

1387{
1389 PPROCESSINFO ppi;
1390 OBJECT_HANDLE_INFORMATION ObjectHandleInfo;
1391 PWINSTATION_OBJECT NewWinSta = NULL, OldWinSta;
1392 HWINSTA hCacheWinSta;
1393
1395
1396 /* Reference the new window station */
1397 if (hWindowStation != NULL)
1398 {
1399 Status = IntValidateWindowStationHandle(hWindowStation,
1400 UserMode,
1401 0,
1402 &NewWinSta,
1403 &ObjectHandleInfo);
1404 if (!NT_SUCCESS(Status))
1405 {
1406 TRACE("Validation of window station handle 0x%p failed\n", hWindowStation);
1408 return FALSE;
1409 }
1410 }
1411
1412 OldWinSta = ppi->prpwinsta;
1413 hCacheWinSta = PsGetProcessWin32WindowStation(ppi->peProcess);
1414
1415 /* Dereference the previous window station */
1416 if (OldWinSta != NULL)
1417 {
1418 ObDereferenceObject(OldWinSta);
1419 }
1420
1421 /*
1422 * FIXME: Don't allow changing the window station if there are threads that are attached to desktops and own GUI objects?
1423 */
1424
1425 /* Close the cached EPROCESS window station handle if needed */
1426 if (hCacheWinSta != NULL)
1427 {
1428 /* Reference the window station */
1429 Status = ObReferenceObjectByHandle(hCacheWinSta,
1430 0,
1432 UserMode,
1433 (PVOID*)&OldWinSta,
1434 NULL);
1435 if (!NT_SUCCESS(Status))
1436 {
1437 ERR("Failed to reference the inherited window station, Status 0x%08lx\n", Status);
1438 /* We failed, reset the cache */
1439 hCacheWinSta = NULL;
1440 PsSetProcessWindowStation(ppi->peProcess, hCacheWinSta);
1441 }
1442 else
1443 {
1444 /*
1445 * Close the old handle and reset the cache only
1446 * if we are setting a different window station.
1447 */
1448 if (NewWinSta != OldWinSta)
1449 {
1450 ObCloseHandle(hCacheWinSta, UserMode);
1451 hCacheWinSta = NULL;
1452 PsSetProcessWindowStation(ppi->peProcess, hCacheWinSta);
1453 }
1454
1455 /* Dereference the window station */
1456 ObDereferenceObject(OldWinSta);
1457 }
1458 }
1459
1460 /* Duplicate and save a new cached EPROCESS window station handle */
1461 if ((hCacheWinSta == NULL) && (hWindowStation != NULL))
1462 {
1463 Status = ZwDuplicateObject(ZwCurrentProcess(),
1464 hWindowStation,
1466 (PHANDLE)&hCacheWinSta,
1467 0,
1468 0,
1470 if (!NT_SUCCESS(Status))
1471 {
1472 ERR("UserSetProcessWindowStation: Failed to duplicate the window station handle, Status 0x%08lx\n", Status);
1473 }
1474 else
1475 {
1476 PsSetProcessWindowStation(ppi->peProcess, hCacheWinSta);
1477 }
1478 }
1479
1480 ppi->prpwinsta = NewWinSta;
1481 ppi->hwinsta = hWindowStation;
1482 ppi->amwinsta = hWindowStation != NULL ? ObjectHandleInfo.GrantedAccess : 0;
1483 TRACE("WS : Granted Access 0x%08lx\n",ppi->amwinsta);
1484
1486 {
1487 ppi->W32PF_flags |= W32PF_READSCREENACCESSGRANTED;
1488 }
1489 else
1490 {
1491 ppi->W32PF_flags &= ~W32PF_READSCREENACCESSGRANTED;
1492 }
1493
1494 if (NewWinSta && !(NewWinSta->Flags & WSS_NOIO))
1495 {
1496 ppi->W32PF_flags |= W32PF_IOWINSTA;
1497 }
1498 else /* Might be closed if the handle is NULL */
1499 {
1500 ppi->W32PF_flags &= ~W32PF_IOWINSTA;
1501 }
1502 return TRUE;
1503}
VOID NTAPI PsSetProcessWindowStation(PEPROCESS Process, PVOID WindowStation)
Definition: process.c:1314
PVOID NTAPI PsGetProcessWin32WindowStation(PEPROCESS Process)
Definition: process.c:1203
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
ACCESS_MASK GrantedAccess
Definition: iotypes.h:181
struct _WINSTATION_OBJECT * prpwinsta
Definition: win32.h:267
#define W32PF_READSCREENACCESSGRANTED
Definition: win32.h:8
#define WINSTA_READSCREEN
Definition: winuser.h:415
#define DUPLICATE_SAME_ACCESS

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

Variable Documentation

◆ ghWinStaDir

HANDLE ghWinStaDir

Definition at line 28 of file winsta.c.

Referenced by UserCreateWinstaDirectory().

◆ gustrWindowStationsDir

◆ hwndSAS

◆ InputWindowStation