https://git.reactos.org/?p=reactos.git;a=commitdiff;h=60448f83fb65d055b2391d89c26479d3a7a6de97
commit 60448f83fb65d055b2391d89c26479d3a7a6de97 Author: Giannis Adamopoulos <gadamopou...@reactos.org> AuthorDate: Wed Jan 2 16:50:35 2019 +0200 Commit: Giannis Adamopoulos <gadamopou...@reactos.org> CommitDate: Wed Jan 2 17:15:40 2019 +0200 [NTUSER] Fix a few tests related to desktops and window stations - NtUserOpenInputDesktop: Don't crash if there is no input desktop yet - NtUserOpenInputDesktop: Fail if the process doesn't belong to the interactive window station - NtUserCreateWindowStation: Clear error on success - DesktopWindowProc: Use UserOpenInputDesktop to get a handle to the input desktop --- win32ss/user/ntuser/desktop.c | 66 +++++++++++++++++++++++++++++-------------- win32ss/user/ntuser/desktop.h | 1 + win32ss/user/ntuser/winsta.c | 2 ++ 3 files changed, 48 insertions(+), 21 deletions(-) diff --git a/win32ss/user/ntuser/desktop.c b/win32ss/user/ntuser/desktop.c index e066198226..875cc4b69c 100644 --- a/win32ss/user/ntuser/desktop.c +++ b/win32ss/user/ntuser/desktop.c @@ -1471,7 +1471,7 @@ DesktopWindowProc(PWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT *lRe PWINDOWPOS pWindowPos = (PWINDOWPOS)lParam; if ((pWindowPos->flags & SWP_SHOWWINDOW) != 0) { - HDESK hdesk = IntGetDesktopObjectHandle(gpdeskInputDesktop); + HDESK hdesk = UserOpenInputDesktop(0, FALSE, DESKTOP_ALL_ACCESS); IntSetThreadDesktop(hdesk, FALSE); } break; @@ -2569,6 +2569,48 @@ NtUserOpenDesktop( return Desktop; } +HDESK UserOpenInputDesktop(DWORD dwFlags, + BOOL fInherit, + ACCESS_MASK dwDesiredAccess) +{ + PTHREADINFO pti = PsGetCurrentThreadWin32Thread(); + NTSTATUS Status; + ULONG HandleAttributes = 0; + HDESK hdesk = NULL; + + if (!gpdeskInputDesktop) + { + return NULL; + } + + if (pti->ppi->prpwinsta != InputWindowStation) + { + ERR("Tried to open input desktop from non interactive winsta!\n"); + EngSetLastError(ERROR_INVALID_FUNCTION); + return NULL; + } + + if (fInherit) HandleAttributes = OBJ_INHERIT; + + /* Create a new handle to the object */ + Status = ObOpenObjectByPointer( + gpdeskInputDesktop, + HandleAttributes, + NULL, + dwDesiredAccess, + ExDesktopObjectType, + UserMode, + (PHANDLE)&hdesk); + + if (!NT_SUCCESS(Status)) + { + ERR("Failed to open input desktop object\n"); + SetLastNtError(Status); + } + + return hdesk; +} + /* * NtUserOpenInputDesktop * @@ -2597,30 +2639,12 @@ NtUserOpenInputDesktop( BOOL fInherit, ACCESS_MASK dwDesiredAccess) { - NTSTATUS Status; - HDESK hdesk = NULL; - ULONG HandleAttributes = 0; + HDESK hdesk; UserEnterExclusive(); TRACE("Enter NtUserOpenInputDesktop gpdeskInputDesktop 0x%p\n",gpdeskInputDesktop); - if (fInherit) HandleAttributes = OBJ_INHERIT; - - /* Create a new handle to the object */ - Status = ObOpenObjectByPointer( - gpdeskInputDesktop, - HandleAttributes, - NULL, - dwDesiredAccess, - ExDesktopObjectType, - UserMode, - (PHANDLE)&hdesk); - - if (!NT_SUCCESS(Status)) - { - ERR("Failed to open input desktop object\n"); - SetLastNtError(Status); - } + hdesk = UserOpenInputDesktop(dwFlags, fInherit, dwDesiredAccess); TRACE("NtUserOpenInputDesktop returning 0x%p\n",hdesk); UserLeave(); diff --git a/win32ss/user/ntuser/desktop.h b/win32ss/user/ntuser/desktop.h index 6f15bb12a3..8ec595af86 100644 --- a/win32ss/user/ntuser/desktop.h +++ b/win32ss/user/ntuser/desktop.h @@ -357,5 +357,6 @@ BOOL FASTCALL IntPaintDesktop(HDC); BOOL FASTCALL DesktopWindowProc(PWND, UINT, WPARAM, LPARAM, LRESULT *); BOOL FASTCALL UserMessageWindowProc(PWND pwnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT *lResult); VOID NTAPI DesktopThreadMain(VOID); +HDESK UserOpenInputDesktop(DWORD dwFlags, BOOL fInherit, ACCESS_MASK dwDesiredAccess); /* EOF */ diff --git a/win32ss/user/ntuser/winsta.c b/win32ss/user/ntuser/winsta.c index 63325fe800..4556e7412e 100644 --- a/win32ss/user/ntuser/winsta.c +++ b/win32ss/user/ntuser/winsta.c @@ -521,6 +521,8 @@ IntCreateWindowStation( ObjectAttributes->ObjectName, WindowStation, hWinSta); *phWinSta = hWinSta; + EngSetLastError(ERROR_SUCCESS); + return STATUS_SUCCESS; }