diff --git a/reactos/include/reactos/winlogon.h b/reactos/include/reactos/winlogon.h new file mode 100644 index 00000000000..9c385be649e --- /dev/null +++ b/reactos/include/reactos/winlogon.h @@ -0,0 +1,28 @@ +/* $Id: winlogon.h,v 1.1 2004/07/12 20:09:35 gvg Exp $ + * + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * FILE: include/reactos/winlogon.h + * PURPOSE: Interface to winlogon + * PROGRAMMER: David Welch (welch@mcmail.com) + * REVISIONS: + * 1999-11-06 (ea) + * Moved from include/internal in include/reactos + * to be used by buildno. + * 2002-01-17 (ea) + * KERNEL_VERSION removed. Use + * reactos/buildno.h:KERNEL_VERSION_STR instead. + */ + +#ifndef REACTOS_WINLOGON_H_INCLUDED +#define REACTOS_WINLOGON_H_INCLUDED + +#define WINLOGON_DESKTOP L"Winlogon" +#define WINLOGON_SAS_CLASS L"SAS window class" +#define WINLOGON_SAS_TITLE L"SAS" + +#define PM_WINLOGON_EXITWINDOWS WM_APP + +#endif /* REACTOS_WINLOGON_H_INCLUDED */ + +/* EOF */ diff --git a/reactos/lib/user32/misc/exit.c b/reactos/lib/user32/misc/exit.c index aecca3bf529..138d68cae46 100644 --- a/reactos/lib/user32/misc/exit.c +++ b/reactos/lib/user32/misc/exit.c @@ -1,4 +1,4 @@ -/* $Id: exit.c,v 1.4 2004/04/09 20:03:14 navaraf Exp $ +/* $Id: exit.c,v 1.5 2004/07/12 20:09:34 gvg Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS user32.dll @@ -13,6 +13,60 @@ #include #include +/* + * Sequence of events: + * + * - App (usually explorer) calls ExitWindowsEx() + * - ExitWindowsEx() sends a message to CSRSS (note: investigation shows it + * doesn't transfer to kernel mode) + * - CSRSS impersonates the caller and sends a message to a hidden WinLogon window + * - WinLogon sends a SAS event to the GINA, asking for permission (e.g. if the + * required rights are granted) to proceed + * - WinLogon enters pending log-out state + * - WinLogon impersonates the interactive user and calls ExitWindowsEx() again, + * passing some special internal flags + * - CSRSS loops over all processes of the interactive user (sorted by their + * SetProcessShutdownParameters() level), sending WM_QUERYENDSESSION and + * WM_ENDSESSION messages to its top-level windows. If the messages aren't + * processed within the timeout period (registry key HKCU\Control Panel\Desktop\HungAppTimeout) + * CSRSS will put up a dialog box asking if the process should be terminated. + * Using the registry key HKCU\Control Panel\Desktop\AutoEndTask you can + * specify that the dialog box shouldn't be shown and CSRSS should just + * terminates the thread. If the the WM_ENDSESSION message is processed + * but the thread doesn't terminate within the timeout specified by + * HKCU\Control Panel\Desktop\WaitToKillAppTimeout CSRSS will terminate + * the thread. When all the top-level windows have been destroyed CSRSS + * will terminate the process. + * If the process is a console process, CSRSS will send a CTRL_LOGOFF_EVENT + * to the console control handler on logoff. No event is sent on shutdown. + * If the handler doesn't respond in time the same activities as for GUI + * apps (i.e. display dialog box etc) take place. This also happens if + * the handler returns TRUE. + * - This ends the processing for the first ExitWindowsEx() call from WinLogon. + * Execution continues in WinLogon, which calls ExitWindowsEx() again to + * terminate COM processes in the interactive user's session. + * - WinLogon stops impersonating the interactive user (whos processes are + * all dead by now). and enters log-out state + * - If the ExitWindowsEx() request was for a logoff, WinLogon sends a SAS + * event (to display the "press ctrl+alt+del") to the GINA. WinLogon then + * waits for the GINA to send a SAS event to login. + * - If the ExitWindowsEx() request was for shutdown/restart, WinLogon calls + * ExitWindowsEx() again in the system process context. + * - CSRSS goes through the motions of sending WM_QUERYENDSESSION/WM_ENDSESSION + * to GUI processes running in the system process context but won't display + * dialog boxes or kill threads/processes. Same for console processes, + * using the CTRL_SHUTDOWN_EVENT. The Service Control Manager is one of + * these console processes and has a special timeout value WaitToKillServiceTimeout. + * - WinLogon calls ADVAPI32.InitiateSystemShutdown() + * - ADVAPI32.InitiateSystemShutdown*() issues a "InitiateSystemShutdown" request + * to the SM (SMSS API # 1) + * - the SM propagates the shutdown request to every environment subsystem it + * started since bootstrap time (still active ones, of course) + * - each environment subsystem, on shutdown request, releases every resource + * it aquired during its life (processes, memory etc), then dies + * - when every environment subsystem has gone to bed, the SM actually initiates + * to shutdown the kernel and executive by calling NtShutdownSystem. + */ /* * @implemented */ diff --git a/reactos/lib/user32/misc/misc.c b/reactos/lib/user32/misc/misc.c index 1ad07afabed..6327c48bc25 100644 --- a/reactos/lib/user32/misc/misc.c +++ b/reactos/lib/user32/misc/misc.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: misc.c,v 1.6 2004/07/08 14:35:10 ekohl Exp $ +/* $Id: misc.c,v 1.7 2004/07/12 20:09:34 gvg Exp $ * * PROJECT: ReactOS user32.dll * FILE: lib/user32/misc/misc.c @@ -31,6 +31,7 @@ #include #include #include +#include /* FUNCTIONS *****************************************************************/ @@ -76,3 +77,31 @@ RegisterLogonProcess(DWORD dwProcessId, BOOL bRegister) (DWORD)bRegister, TWOPARAM_ROUTINE_REGISTERLOGONPROC); } + +/* + * @implemented + */ +BOOL +STDCALL +SetLogonNotifyWindow (HWND Wnd, HWINSTA WinSta) +{ + /* Maybe we should call NtUserSetLogonNotifyWindow and let that one inform CSRSS??? */ + CSRSS_API_REQUEST Request; + CSRSS_API_REPLY Reply; + NTSTATUS Status; + + Request.Type = CSRSS_SET_LOGON_NOTIFY_WINDOW; + Request.Data.SetLogonNotifyWindowRequest.LogonNotifyWindow = Wnd; + + Status = CsrClientCallServer(&Request, + &Reply, + sizeof(CSRSS_API_REQUEST), + sizeof(CSRSS_API_REPLY)); + if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Reply.Status)) + { + SetLastError(RtlNtStatusToDosError(Status)); + return(FALSE); + } + + return(TRUE); +} diff --git a/reactos/subsys/csrss/api/user.c b/reactos/subsys/csrss/api/user.c index 9a8b9760b08..5b5969b5c7c 100644 --- a/reactos/subsys/csrss/api/user.c +++ b/reactos/subsys/csrss/api/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.3 2004/04/09 20:03:15 navaraf Exp $ +/* $Id: user.c,v 1.4 2004/07/12 20:09:34 gvg Exp $ * * reactos/subsys/csrss/api/user.c * @@ -51,15 +51,4 @@ CSR_API(CsrRegisterServicesProcess) return(Status); } - -CSR_API(CsrExitReactos) -{ - Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY); - Reply->Header.DataSize = sizeof(CSRSS_API_REPLY) - LPC_MESSAGE_BASE_SIZE; - - Reply->Status = STATUS_NOT_IMPLEMENTED; - - return(STATUS_NOT_IMPLEMENTED); -} - /* EOF */ diff --git a/reactos/subsys/csrss/include/api.h b/reactos/subsys/csrss/include/api.h index 5aa8f6f3090..aac6096faac 100644 --- a/reactos/subsys/csrss/include/api.h +++ b/reactos/subsys/csrss/include/api.h @@ -1,4 +1,4 @@ -/* $Id: api.h,v 1.5 2004/07/03 17:15:02 hbirr Exp $ +/* $Id: api.h,v 1.6 2004/07/12 20:09:34 gvg Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -131,6 +131,9 @@ CSR_API(CsrExitReactos); CSR_API(CsrGetShutdownParameters); CSR_API(CsrSetShutdownParameters); +CSR_API(CsrSetLogonNotifyWindow); +CSR_API(CsrRegisterLogonProcess); + #endif /* ndef API_H_INCLUDED */ /* EOF */ diff --git a/reactos/subsys/csrss/init.c b/reactos/subsys/csrss/init.c index 220e88383b0..ac08b1e4bdf 100644 --- a/reactos/subsys/csrss/init.c +++ b/reactos/subsys/csrss/init.c @@ -1,4 +1,4 @@ -/* $Id: init.c,v 1.28 2004/07/03 17:15:02 hbirr Exp $ +/* $Id: init.c,v 1.29 2004/07/12 20:09:34 gvg Exp $ * * reactos/subsys/csrss/init.c * @@ -207,7 +207,6 @@ CSRSS_API_DEFINITION NativeDefinitions[] = CSRSS_DEFINE_API(CSRSS_TERMINATE_PROCESS, CsrTerminateProcess), CSRSS_DEFINE_API(CSRSS_CONNECT_PROCESS, CsrConnectProcess), CSRSS_DEFINE_API(CSRSS_REGISTER_SERVICES_PROCESS, CsrRegisterServicesProcess), - CSRSS_DEFINE_API(CSRSS_EXIT_REACTOS, CsrExitReactos), CSRSS_DEFINE_API(CSRSS_GET_SHUTDOWN_PARAMETERS, CsrGetShutdownParameters), CSRSS_DEFINE_API(CSRSS_SET_SHUTDOWN_PARAMETERS, CsrSetShutdownParameters), CSRSS_DEFINE_API(CSRSS_GET_INPUT_HANDLE, CsrGetInputHandle), diff --git a/reactos/subsys/csrss/makefile b/reactos/subsys/csrss/makefile index 886a8af589b..351a67b221e 100644 --- a/reactos/subsys/csrss/makefile +++ b/reactos/subsys/csrss/makefile @@ -1,4 +1,4 @@ -# $Id: makefile,v 1.29 2004/05/28 21:33:41 gvg Exp $ +# $Id: makefile,v 1.30 2004/07/12 20:09:34 gvg Exp $ PATH_TO_TOP = ../.. @@ -13,7 +13,7 @@ TARGET_SDKLIBS = rosrtl.a ntdll.a TARGET_INSTALLDIR = system32 -TARGET_CFLAGS = -D__NTAPP__ -Wall -Werror -Iinclude +TARGET_CFLAGS = -D__NTAPP__ -D__USE_W32API -Wall -Werror -Iinclude TARGET_LFLAGS = -nostdlib diff --git a/reactos/subsys/csrss/win32csr/Makefile b/reactos/subsys/csrss/win32csr/Makefile index 084a56bcc13..778dd782218 100644 --- a/reactos/subsys/csrss/win32csr/Makefile +++ b/reactos/subsys/csrss/win32csr/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.3 2004/01/11 17:31:15 gvg Exp $ +# $Id: Makefile,v 1.4 2004/07/12 20:09:34 gvg Exp $ PATH_TO_TOP = ../../.. @@ -9,13 +9,13 @@ TARGET_NAME = win32csr TARGET_BASE = 0x5ffb0000 # require os code to explicitly request A/W version of structs/functions -TARGET_CFLAGS += -D_DISABLE_TIDENTS -Wall -Werror -I../include +TARGET_CFLAGS += -D__USE_W32API -D_DISABLE_TIDENTS -Wall -Werror -I../include TARGET_LFLAGS = -nostartfiles -nostdlib TARGET_SDKLIBS = ntdll.a kernel32.a user32.a gdi32.a -TARGET_OBJECTS = dllmain.o conio.o desktopbg.o guiconsole.o tuiconsole.o +TARGET_OBJECTS = dllmain.o conio.o desktopbg.o exitros.o guiconsole.o tuiconsole.o TARGET_ENTRY = _DllMain@12 diff --git a/reactos/subsys/csrss/win32csr/dllmain.c b/reactos/subsys/csrss/win32csr/dllmain.c index 2de47cf71e8..a084b5b55dd 100644 --- a/reactos/subsys/csrss/win32csr/dllmain.c +++ b/reactos/subsys/csrss/win32csr/dllmain.c @@ -1,4 +1,4 @@ -/* $Id: dllmain.c,v 1.5 2004/05/28 21:33:41 gvg Exp $ +/* $Id: dllmain.c,v 1.6 2004/07/12 20:09:34 gvg Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -55,6 +55,7 @@ static CSRSS_API_DEFINITION Win32CsrApiDefinitions[] = CSRSS_DEFINE_API(CSRSS_READ_CONSOLE_OUTPUT_CHAR, CsrReadConsoleOutputChar), CSRSS_DEFINE_API(CSRSS_READ_CONSOLE_OUTPUT_ATTRIB, CsrReadConsoleOutputAttrib), CSRSS_DEFINE_API(CSRSS_GET_NUM_INPUT_EVENTS, CsrGetNumberOfConsoleInputEvents), + CSRSS_DEFINE_API(CSRSS_EXIT_REACTOS, CsrExitReactos), CSRSS_DEFINE_API(CSRSS_PEEK_CONSOLE_INPUT, CsrPeekConsoleInput), CSRSS_DEFINE_API(CSRSS_READ_CONSOLE_OUTPUT, CsrReadConsoleOutput), CSRSS_DEFINE_API(CSRSS_WRITE_CONSOLE_INPUT, CsrWriteConsoleInput), @@ -62,6 +63,8 @@ static CSRSS_API_DEFINITION Win32CsrApiDefinitions[] = CSRSS_DEFINE_API(CSRSS_CREATE_DESKTOP, CsrCreateDesktop), CSRSS_DEFINE_API(CSRSS_SHOW_DESKTOP, CsrShowDesktop), CSRSS_DEFINE_API(CSRSS_HIDE_DESKTOP, CsrHideDesktop), + CSRSS_DEFINE_API(CSRSS_SET_LOGON_NOTIFY_WINDOW, CsrSetLogonNotifyWindow), + CSRSS_DEFINE_API(CSRSS_REGISTER_LOGON_PROCESS, CsrRegisterLogonProcess), { 0, 0, 0, NULL } }; diff --git a/reactos/subsys/csrss/win32csr/exitros.c b/reactos/subsys/csrss/win32csr/exitros.c new file mode 100644 index 00000000000..523ae875d72 --- /dev/null +++ b/reactos/subsys/csrss/win32csr/exitros.c @@ -0,0 +1,112 @@ +/* $Id: exitros.c,v 1.1 2004/07/12 20:09:34 gvg Exp $ + * + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS CSRSS subsystem + * FILE: subsys/csrss/win32csr/exitros.c + * PURPOSE: Logout/shutdown + */ + +/* INCLUDES ******************************************************************/ + +#include +#include +#include "api.h" +#include "win32csr.h" + +#define NDEBUG +#include + +static HWND LogonNotifyWindow = NULL; +static DWORD LogonProcess = 0; + +CSR_API(CsrRegisterLogonProcess) +{ + Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY); + Reply->Header.DataSize = sizeof(CSRSS_API_REPLY) - LPC_MESSAGE_BASE_SIZE; + + if (Request->Data.RegisterLogonProcessRequest.Register) + { + if (0 != LogonProcess) + { + Reply->Status = STATUS_LOGON_SESSION_EXISTS; + return Reply->Status; + } + LogonProcess = Request->Data.RegisterLogonProcessRequest.ProcessId; + } + else + { + if ((DWORD) Request->Header.ClientId.UniqueProcess != LogonProcess) + { + DPRINT1("Current logon process 0x%x, can't deregister from process 0x%x\n", + LogonProcess, Request->Header.ClientId.UniqueProcess); + Reply->Status = STATUS_NOT_LOGON_PROCESS; + return Reply->Status; + } + LogonProcess = 0; + } + + Reply->Status = STATUS_SUCCESS; + + return Reply->Status; +} + +CSR_API(CsrSetLogonNotifyWindow) +{ + DWORD WindowCreator; + + Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY); + Reply->Header.DataSize = sizeof(CSRSS_API_REPLY) - LPC_MESSAGE_BASE_SIZE; + + if (0 == GetWindowThreadProcessId(Request->Data.SetLogonNotifyWindowRequest.LogonNotifyWindow, + &WindowCreator)) + { + DPRINT1("Can't get window creator\n"); + Reply->Status = STATUS_INVALID_HANDLE; + return Reply->Status; + } + if (WindowCreator != LogonProcess) + { + DPRINT1("Trying to register window not created by winlogon as notify window\n"); + Reply->Status = STATUS_ACCESS_DENIED; + return Reply->Status; + } + + LogonNotifyWindow = Request->Data.SetLogonNotifyWindowRequest.LogonNotifyWindow; + + Reply->Status = STATUS_SUCCESS; + + return Reply->Status; +} + +CSR_API(CsrExitReactos) +{ + Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY); + Reply->Header.DataSize = sizeof(CSRSS_API_REPLY) - LPC_MESSAGE_BASE_SIZE; + + if (NULL == LogonNotifyWindow) + { + DPRINT1("No LogonNotifyWindow registered\n"); + Reply->Status = STATUS_NOT_FOUND; + return Reply->Status; + } + + /* FIXME Inside 2000 says we should impersonate the caller here */ + Reply->Status = SendMessageW(LogonNotifyWindow, PM_WINLOGON_EXITWINDOWS, + (WPARAM) Request->Header.ClientId.UniqueProcess, + (LPARAM) Request->Data.ExitReactosRequest.Flags); + /* If the message isn't handled, the return value is 0, so 0 doesn't indicate success. + Success is indicated by a 1 return value, if anything besides 0 or 1 it's a + NTSTATUS value */ + if (1 == Reply->Status) + { + Reply->Status = STATUS_SUCCESS; + } + else if (0 == Reply->Status) + { + Reply->Status = STATUS_NOT_IMPLEMENTED; + } + + return Reply->Status; +} + +/* EOF */ diff --git a/reactos/subsys/system/winlogon/makefile b/reactos/subsys/system/winlogon/makefile index 54cc7098998..6470e0be2c9 100644 --- a/reactos/subsys/system/winlogon/makefile +++ b/reactos/subsys/system/winlogon/makefile @@ -1,4 +1,4 @@ -# $Id: makefile,v 1.10 2004/03/28 12:21:41 weiden Exp $ +# $Id: makefile,v 1.11 2004/07/12 20:09:35 gvg Exp $ PATH_TO_TOP = ../../.. @@ -14,10 +14,15 @@ TARGET_SDKLIBS = ntdll.a kernel32.a user32.a advapi32.a userenv.a secur32.a TARGET_OBJECTS = setup.o winlogon.o wlx.o sas.o -TARGET_CFLAGS = -Wall -Werror -DUNICODE -D_UNICODE -I./ -I../../../include +TARGET_CFLAGS = -Wall -Werror -D__USE_W32API -DUNICODE -D_UNICODE -I./ include $(PATH_TO_TOP)/rules.mak include $(TOOLS_PATH)/helper.mk +# Automatic dependency tracking +DEP_OBJECTS := $(TARGET_OBJECTS) + +include $(PATH_TO_TOP)/tools/depend.mk + # EOF diff --git a/reactos/subsys/system/winlogon/sas.c b/reactos/subsys/system/winlogon/sas.c index 739baaf39b1..db26fecf1b9 100644 --- a/reactos/subsys/system/winlogon/sas.c +++ b/reactos/subsys/system/winlogon/sas.c @@ -1,4 +1,4 @@ -/* $Id: sas.c,v 1.1 2004/03/28 12:21:41 weiden Exp $ +/* $Id: sas.c,v 1.2 2004/07/12 20:09:35 gvg Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -16,15 +16,22 @@ #include #include #include +#include #include "setup.h" #include "winlogon.h" #include "resource.h" -#define SAS_CLASS L"SAS window class" +#define NDEBUG +#include + #define HK_CTRL_ALT_DEL 0 #define HK_CTRL_SHIFT_ESC 1 +#ifdef __USE_W32API +extern BOOL STDCALL SetLogonNotifyWindow(HWND Wnd, HWINSTA WinSta); +#endif + void DispatchSAS(PWLSESSION Session, DWORD dwSasType) { @@ -48,7 +55,7 @@ SetupSAS(PWLSESSION Session, HWND hwndSAS) /* Register Ctrl+Alt+Del Hotkey */ if(!RegisterHotKey(hwndSAS, HK_CTRL_ALT_DEL, MOD_CONTROL | MOD_ALT, VK_DELETE)) { - DbgPrint("WL-SAS: Unable to register Ctrl+Alt+Del hotkey!\n"); + DPRINT1("WL-SAS: Unable to register Ctrl+Alt+Del hotkey!\n"); return FALSE; } @@ -56,7 +63,7 @@ SetupSAS(PWLSESSION Session, HWND hwndSAS) Session->TaskManHotkey = RegisterHotKey(hwndSAS, HK_CTRL_SHIFT_ESC, MOD_CONTROL | MOD_SHIFT, VK_ESCAPE); if(!Session->TaskManHotkey) { - DbgPrint("WL-SAS: Warning: Unable to register Ctrl+Alt+Esc hotkey!\n"); + DPRINT1("WL-SAS: Warning: Unable to register Ctrl+Alt+Esc hotkey!\n"); } return TRUE; } @@ -76,6 +83,78 @@ DestroySAS(PWLSESSION Session, HWND hwndSAS) return TRUE; } +#define EWX_ACTION_MASK 0x0b +static LRESULT +HandleExitWindows(DWORD RequestingProcessId, UINT Flags) +{ + UINT Action; + HANDLE Process; + HANDLE Token; + BOOL CheckResult; + PPRIVILEGE_SET PrivSet; + + /* Check parameters */ + Action = Flags & EWX_ACTION_MASK; + if (EWX_LOGOFF != Action && EWX_SHUTDOWN != Action && EWX_REBOOT != Action + && EWX_POWEROFF != Action) + { + DPRINT1("Invalid ExitWindows action 0x%x\n", Action); + return STATUS_INVALID_PARAMETER; + } + + /* Check privilege */ + if (EWX_LOGOFF != Action) + { + Process = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, RequestingProcessId); + if (NULL == Process) + { + DPRINT1("OpenProcess failed with error %d\n", GetLastError()); + return STATUS_INVALID_HANDLE; + } + if (! OpenProcessToken(Process, TOKEN_QUERY, &Token)) + { + DPRINT1("OpenProcessToken failed with error %d\n", GetLastError()); + CloseHandle(Process); + return STATUS_INVALID_HANDLE; + } + CloseHandle(Process); + PrivSet = HeapAlloc(GetProcessHeap(), 0, sizeof(PRIVILEGE_SET) + sizeof(LUID_AND_ATTRIBUTES)); + if (NULL == PrivSet) + { + DPRINT1("Failed to allocate mem for privilege set\n"); + CloseHandle(Token); + return STATUS_NO_MEMORY; + } + PrivSet->PrivilegeCount = 1; + PrivSet->Control = PRIVILEGE_SET_ALL_NECESSARY; + if (! LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &PrivSet->Privilege[0].Luid)) + { + DPRINT1("LookupPrivilegeValue failed with error %d\n", GetLastError()); + HeapFree(GetProcessHeap(), 0, PrivSet); + CloseHandle(Token); + return STATUS_UNSUCCESSFUL; + } + if (! PrivilegeCheck(Token, PrivSet, &CheckResult)) + { + DPRINT1("PrivilegeCheck failed with error %d\n", GetLastError()); + HeapFree(GetProcessHeap(), 0, PrivSet); + CloseHandle(Token); + return STATUS_ACCESS_DENIED; + } + HeapFree(GetProcessHeap(), 0, PrivSet); + CloseHandle(Token); + if (! CheckResult) + { + DPRINT1("SE_SHUTDOWN privilege not enabled\n"); + return STATUS_ACCESS_DENIED; + } + } + + /* FIXME actually start logoff/shutdown now */ + + return 1; +} + LRESULT CALLBACK SASProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { @@ -91,10 +170,10 @@ SASProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) switch(wParam) { case HK_CTRL_ALT_DEL: - DbgPrint("SAS: CTR+ALT+DEL\n"); + DPRINT1("SAS: CTR+ALT+DEL\n"); break; case HK_CTRL_SHIFT_ESC: - DbgPrint("SAS: CTR+SHIFT+ESC\n"); + DPRINT1("SAS: CTR+SHIFT+ESC\n"); break; } return 0; @@ -108,6 +187,10 @@ SASProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) } return 0; } + case PM_WINLOGON_EXITWINDOWS: + { + return HandleExitWindows((DWORD) wParam, (UINT) lParam); + } case WM_DESTROY: { DestroySAS(Session, hwnd); @@ -134,33 +217,29 @@ InitializeSAS(PWLSESSION Session) swc.hCursor = NULL; swc.hbrBackground = NULL; swc.lpszMenuName = NULL; - swc.lpszClassName = SAS_CLASS; + swc.lpszClassName = WINLOGON_SAS_CLASS; swc.hIconSm = NULL; RegisterClassEx(&swc); /* create invisible SAS window */ - Session->SASWindow = CreateWindowEx(0, SAS_CLASS, L"SAS", WS_OVERLAPPEDWINDOW, + Session->SASWindow = CreateWindowEx(0, WINLOGON_SAS_CLASS, WINLOGON_SAS_TITLE, WS_POPUP, 0, 0, 0, 0, 0, 0, hAppInstance, NULL); if(!Session->SASWindow) { - DbgPrint("WL: Failed to create SAS window\n"); + DPRINT1("WL: Failed to create SAS window\n"); return FALSE; } /* Save the Session pointer so the window proc can access it */ SetWindowLong(Session->SASWindow, GWL_USERDATA, (LONG)Session); - #if 0 - /* Register SAS window to receive SAS notifications - FIXME - SetLogonNotifyWindow() takes only one parameter, - definition in funcs.h is wrong! */ - if(!SetLogonNotifyWindow(Session->SASWindow)) + /* Register SAS window to receive SAS notifications */ + if(!SetLogonNotifyWindow(Session->SASWindow, Session->InteractiveWindowStation)) { UninitSAS(Session); - DbgPrint("WL: Failed to register SAS window\n"); + DPRINT1("WL: Failed to register SAS window\n"); return FALSE; } - #endif return TRUE; } diff --git a/reactos/subsys/system/winlogon/setup.c b/reactos/subsys/system/winlogon/setup.c index 610f0b9d2b8..70ea348b37c 100644 --- a/reactos/subsys/system/winlogon/setup.c +++ b/reactos/subsys/system/winlogon/setup.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: setup.c,v 1.3 2004/06/04 23:46:02 navaraf Exp $ +/* $Id: setup.c,v 1.4 2004/07/12 20:09:35 gvg Exp $ * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS winlogon * FILE: subsys/system/winlogon/setup.h @@ -43,7 +43,7 @@ DWORD GetSetupType(VOID) { DWORD dwError; - HANDLE hKey; + HKEY hKey; DWORD dwType; DWORD dwSize; DWORD dwSetupType; @@ -79,7 +79,7 @@ BOOL SetSetupType (DWORD dwSetupType) { DWORD dwError; - HANDLE hKey; + HKEY hKey; dwError = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SYSTEM\\Setup", //TEXT("SYSTEM\\Setup"), @@ -116,7 +116,7 @@ RunSetup (VOID) WCHAR CommandLine[MAX_PATH]; BOOLEAN Result; DWORD dwError; - HANDLE hKey; + HKEY hKey; DWORD dwType; DWORD dwSize; DWORD dwExitCode; diff --git a/reactos/subsys/system/winlogon/winlogon.c b/reactos/subsys/system/winlogon/winlogon.c index 5ad3267aa3c..61aae7db220 100644 --- a/reactos/subsys/system/winlogon/winlogon.c +++ b/reactos/subsys/system/winlogon/winlogon.c @@ -1,4 +1,4 @@ -/* $Id: winlogon.c,v 1.33 2004/07/11 13:31:28 weiden Exp $ +/* $Id: winlogon.c,v 1.34 2004/07/12 20:09:35 gvg Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -219,7 +219,7 @@ StartLsass (VOID) static BOOLEAN -OpenRegistryKey (HANDLE *WinLogonKey) +OpenRegistryKey (HKEY *WinLogonKey) { return ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\ReactOS\\Windows NT\\CurrentVersion\\WinLogon", @@ -232,7 +232,7 @@ OpenRegistryKey (HANDLE *WinLogonKey) static BOOLEAN StartProcess(PWCHAR ValueName) { BOOL StartIt; - HANDLE WinLogonKey; + HKEY WinLogonKey; DWORD Type; DWORD Size; DWORD StartValue; @@ -262,7 +262,7 @@ static BOOLEAN StartProcess(PWCHAR ValueName) /* static BOOL RestartShell(void) { - HANDLE WinLogonKey; + HKEY WinLogonKey; DWORD Type, Size, Value; if(OpenRegistryKey(&WinLogonKey)) @@ -338,7 +338,7 @@ HandleHotKey(MSG *Msg) #if SUPPORT_CONSOLESTART static BOOL StartIntoGUI(VOID) { - HANDLE WinLogonKey; + HKEY WinLogonKey; DWORD Type, Size, Value; if(OpenRegistryKey(&WinLogonKey)) @@ -366,7 +366,7 @@ static BOOL StartIntoGUI(VOID) static PWCHAR GetShell (WCHAR *CommandLine) { - HANDLE WinLogonKey; + HKEY WinLogonKey; BOOL GotCommandLine; DWORD Type; DWORD Size; @@ -492,10 +492,6 @@ DoLogonUser (PWCHAR Name, return FALSE; } - /* Process the global hotkeys on #if 0 */ -#if 0 - WaitForSingleObject (ProcessInformation.hProcess, INFINITE); -#else RegisterHotKeys(); while (WaitForSingleObject (ProcessInformation.hProcess, 100) != WAIT_OBJECT_0) @@ -510,7 +506,7 @@ DoLogonUser (PWCHAR Name, } UnregisterHotKeys(); -#endif + CloseHandle (ProcessInformation.hProcess); CloseHandle (ProcessInformation.hThread); @@ -543,7 +539,7 @@ WinMain(HINSTANCE hInstance, ULONG AuthenticationPackage; #endif NTSTATUS Status; - + hAppInstance = hInstance; if(!RegisterLogonProcess(GetCurrentProcessId(), TRUE)) @@ -614,18 +610,13 @@ WinMain(HINSTANCE hInstance, #if SUPPORT_CONSOLESTART StartConsole = !StartIntoGUI(); - if(!StartConsole) - { #endif - if(!InitializeSAS(WLSession)) + if(!InitializeSAS(WLSession)) { DbgPrint("WL: Failed to initialize SAS\n"); ExitProcess(2); return 2; } -#if SUPPORT_CONSOLESTART - } -#endif InitServices(); diff --git a/reactos/subsys/system/winlogon/winlogon.h b/reactos/subsys/system/winlogon/winlogon.h index be205c49a5c..b6aaeebaa0f 100644 --- a/reactos/subsys/system/winlogon/winlogon.h +++ b/reactos/subsys/system/winlogon/winlogon.h @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: winlogon.h,v 1.3 2004/03/28 12:21:41 weiden Exp $ +/* $Id: winlogon.h,v 1.4 2004/07/12 20:09:35 gvg Exp $ * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS winlogon * FILE: subsys/system/winlogon/winlogon.h @@ -110,7 +110,7 @@ typedef struct _MSGINAFUNCTIONS typedef struct _MSGINAINSTANCE { - HANDLE hDllInstance; + HMODULE hDllInstance; MSGINAFUNCTIONS Functions; PVOID Context; DWORD Version; @@ -125,6 +125,7 @@ typedef struct _WLSESSION BOOL TaskManHotkey; HWND SASWindow; HWINSTA InteractiveWindowStation; + LPWSTR InteractiveWindowStationName; HDESK ApplicationDesktop; HDESK WinlogonDesktop; HDESK ScreenSaverDesktop; diff --git a/reactos/subsys/system/winlogon/wlx.c b/reactos/subsys/system/winlogon/wlx.c index 494bb7916d9..1be312b0ca8 100644 --- a/reactos/subsys/system/winlogon/wlx.c +++ b/reactos/subsys/system/winlogon/wlx.c @@ -1,4 +1,4 @@ -/* $Id: wlx.c,v 1.4 2004/03/28 12:21:41 weiden Exp $ +/* $Id: wlx.c,v 1.5 2004/07/12 20:09:35 gvg Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -16,6 +16,7 @@ #include #include #include +#include #include "setup.h" #include "winlogon.h" @@ -493,7 +494,7 @@ static void GetMsGinaPath(WCHAR *path) { DWORD Status, Type, Size; - HANDLE hKey; + HKEY hKey; Status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon", @@ -652,7 +653,7 @@ MsGinaInit(void) WLSession->MsGina.Version = GinaDllVersion; WLSession->SuppressStatus = FALSE; - if(!WLSession->MsGina.Functions.WlxInitialize(WLSession->InteractiveWindowStation, + if(!WLSession->MsGina.Functions.WlxInitialize(WLSession->InteractiveWindowStationName, (HANDLE)WLSession, NULL, (PVOID)&FunctionTable, @@ -670,7 +671,9 @@ WlxCreateWindowStationAndDesktops(PWLSESSION Session) /* * Create the interactive window station */ - Session->InteractiveWindowStation = CreateWindowStation(L"WinSta0", 0, GENERIC_ALL, NULL); + Session->InteractiveWindowStationName = L"WinSta0"; + Session->InteractiveWindowStation = CreateWindowStation(Session->InteractiveWindowStationName, + 0, GENERIC_ALL, NULL); if(!Session->InteractiveWindowStation) { DbgPrint("WL: Failed to create window station (0x%X)\n", GetLastError()); @@ -696,7 +699,7 @@ WlxCreateWindowStationAndDesktops(PWLSESSION Session) /* * Create the winlogon desktop */ - Session->WinlogonDesktop = CreateDesktop(L"Winlogon", + Session->WinlogonDesktop = CreateDesktop(WINLOGON_DESKTOP, NULL, NULL, 0, /* FIXME: Set some flags */ diff --git a/reactos/subsys/win32k/ntuser/csr.c b/reactos/subsys/win32k/ntuser/csr.c index abf1ee9680a..e42d650ebec 100644 --- a/reactos/subsys/win32k/ntuser/csr.c +++ b/reactos/subsys/win32k/ntuser/csr.c @@ -1,4 +1,4 @@ -/* $Id: csr.c,v 1.1 2004/05/28 21:33:41 gvg Exp $ +/* $Id: csr.c,v 1.2 2004/07/12 20:09:35 gvg Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -73,7 +73,7 @@ CsrNotify(PCSRSS_API_REQUEST Request, PCSRSS_API_REPLY Reply) Status = Reply->Status; } - return STATUS_SUCCESS; + return Status; } /* EOF */ diff --git a/reactos/subsys/win32k/ntuser/misc.c b/reactos/subsys/win32k/ntuser/misc.c index e786c0be3fa..67841b6e12a 100644 --- a/reactos/subsys/win32k/ntuser/misc.c +++ b/reactos/subsys/win32k/ntuser/misc.c @@ -1,4 +1,4 @@ -/* $Id: misc.c,v 1.82 2004/07/08 14:36:18 ekohl Exp $ +/* $Id: misc.c,v 1.83 2004/07/12 20:09:35 gvg Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -37,12 +37,14 @@ PUSER_MESSAGE_QUEUE W32kGetPrimitiveMessageQueue() { } BOOL FASTCALL -IntRegisterLogonProcess(DWORD dwProcessId, BOOL bRegister) +IntRegisterLogonProcess(DWORD ProcessId, BOOL Register) { PEPROCESS Process; NTSTATUS Status; + CSRSS_API_REQUEST Request; + CSRSS_API_REPLY Reply; - Status = PsLookupProcessByProcessId((PVOID)dwProcessId, + Status = PsLookupProcessByProcessId((PVOID)ProcessId, &Process); if (!NT_SUCCESS(Status)) { @@ -50,7 +52,7 @@ IntRegisterLogonProcess(DWORD dwProcessId, BOOL bRegister) return FALSE; } - if (bRegister) + if (Register) { /* Register the logon process */ if (LogonProcess != NULL) @@ -75,6 +77,17 @@ IntRegisterLogonProcess(DWORD dwProcessId, BOOL bRegister) ObDereferenceObject(Process); + Request.Type = CSRSS_REGISTER_LOGON_PROCESS; + Request.Data.RegisterLogonProcessRequest.ProcessId = ProcessId; + Request.Data.RegisterLogonProcessRequest.Register = Register; + + Status = CsrNotify(&Request, &Reply); + if (! NT_SUCCESS(Status)) + { + DPRINT1("Failed to register logon process with CSRSS\n"); + return FALSE; + } + return TRUE; }