e8e5e80c36c2dae1ad27aa0d39e95d2f5c5d7c65
[reactos.git] / reactos / subsys / csrss / win32csr / exitros.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS CSRSS subsystem
5 * FILE: subsys/csrss/win32csr/exitros.c
6 * PURPOSE: Logout/shutdown
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include "w32csr.h"
12
13 #define NDEBUG
14 #include <debug.h>
15
16 static HWND LogonNotifyWindow = NULL;
17 static HANDLE LogonProcess = NULL;
18
19 CSR_API(CsrRegisterLogonProcess)
20 {
21 Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE);
22 Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE);
23
24 if (Request->Data.RegisterLogonProcessRequest.Register)
25 {
26 if (0 != LogonProcess)
27 {
28 Request->Status = STATUS_LOGON_SESSION_EXISTS;
29 return Request->Status;
30 }
31 LogonProcess = Request->Data.RegisterLogonProcessRequest.ProcessId;
32 }
33 else
34 {
35 if (Request->Header.ClientId.UniqueProcess != LogonProcess)
36 {
37 DPRINT1("Current logon process 0x%x, can't deregister from process 0x%x\n",
38 LogonProcess, Request->Header.ClientId.UniqueProcess);
39 Request->Status = STATUS_NOT_LOGON_PROCESS;
40 return Request->Status;
41 }
42 LogonProcess = 0;
43 }
44
45 Request->Status = STATUS_SUCCESS;
46
47 return Request->Status;
48 }
49
50 CSR_API(CsrSetLogonNotifyWindow)
51 {
52 DWORD WindowCreator;
53
54 Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE);
55 Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE);
56
57 if (0 == GetWindowThreadProcessId(Request->Data.SetLogonNotifyWindowRequest.LogonNotifyWindow,
58 &WindowCreator))
59 {
60 DPRINT1("Can't get window creator\n");
61 Request->Status = STATUS_INVALID_HANDLE;
62 return Request->Status;
63 }
64 if (WindowCreator != (DWORD)LogonProcess)
65 {
66 DPRINT1("Trying to register window not created by winlogon as notify window\n");
67 Request->Status = STATUS_ACCESS_DENIED;
68 return Request->Status;
69 }
70
71 LogonNotifyWindow = Request->Data.SetLogonNotifyWindowRequest.LogonNotifyWindow;
72
73 Request->Status = STATUS_SUCCESS;
74
75 return Request->Status;
76 }
77
78 CSR_API(CsrExitReactos)
79 {
80 Request->Header.u1.s1.TotalLength = sizeof(CSR_API_MESSAGE);
81 Request->Header.u1.s1.DataLength = sizeof(CSR_API_MESSAGE) - sizeof(PORT_MESSAGE);
82
83 if (NULL == LogonNotifyWindow)
84 {
85 DPRINT1("No LogonNotifyWindow registered\n");
86 Request->Status = STATUS_NOT_FOUND;
87 return Request->Status;
88 }
89
90 /* FIXME Inside 2000 says we should impersonate the caller here */
91 Request->Status = SendMessageW(LogonNotifyWindow, PM_WINLOGON_EXITWINDOWS,
92 (WPARAM) Request->Header.ClientId.UniqueProcess,
93 (LPARAM) Request->Data.ExitReactosRequest.Flags);
94 /* If the message isn't handled, the return value is 0, so 0 doesn't indicate success.
95 Success is indicated by a 1 return value, if anything besides 0 or 1 it's a
96 NTSTATUS value */
97 if (1 == Request->Status)
98 {
99 Request->Status = STATUS_SUCCESS;
100 }
101 else if (0 == Request->Status)
102 {
103 Request->Status = STATUS_NOT_IMPLEMENTED;
104 }
105
106 return Request->Status;
107 }
108
109 /* EOF */