migrate substitution keywords to SVN
[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 <windows.h>
12 #include <reactos/winlogon.h>
13 #include "api.h"
14 #include "win32csr.h"
15
16 #define NDEBUG
17 #include <debug.h>
18
19 static HWND LogonNotifyWindow = NULL;
20 static DWORD LogonProcess = 0;
21
22 CSR_API(CsrRegisterLogonProcess)
23 {
24 Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY);
25 Reply->Header.DataSize = sizeof(CSRSS_API_REPLY) - LPC_MESSAGE_BASE_SIZE;
26
27 if (Request->Data.RegisterLogonProcessRequest.Register)
28 {
29 if (0 != LogonProcess)
30 {
31 Reply->Status = STATUS_LOGON_SESSION_EXISTS;
32 return Reply->Status;
33 }
34 LogonProcess = Request->Data.RegisterLogonProcessRequest.ProcessId;
35 }
36 else
37 {
38 if ((DWORD) Request->Header.ClientId.UniqueProcess != LogonProcess)
39 {
40 DPRINT1("Current logon process 0x%x, can't deregister from process 0x%x\n",
41 LogonProcess, Request->Header.ClientId.UniqueProcess);
42 Reply->Status = STATUS_NOT_LOGON_PROCESS;
43 return Reply->Status;
44 }
45 LogonProcess = 0;
46 }
47
48 Reply->Status = STATUS_SUCCESS;
49
50 return Reply->Status;
51 }
52
53 CSR_API(CsrSetLogonNotifyWindow)
54 {
55 DWORD WindowCreator;
56
57 Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY);
58 Reply->Header.DataSize = sizeof(CSRSS_API_REPLY) - LPC_MESSAGE_BASE_SIZE;
59
60 if (0 == GetWindowThreadProcessId(Request->Data.SetLogonNotifyWindowRequest.LogonNotifyWindow,
61 &WindowCreator))
62 {
63 DPRINT1("Can't get window creator\n");
64 Reply->Status = STATUS_INVALID_HANDLE;
65 return Reply->Status;
66 }
67 if (WindowCreator != LogonProcess)
68 {
69 DPRINT1("Trying to register window not created by winlogon as notify window\n");
70 Reply->Status = STATUS_ACCESS_DENIED;
71 return Reply->Status;
72 }
73
74 LogonNotifyWindow = Request->Data.SetLogonNotifyWindowRequest.LogonNotifyWindow;
75
76 Reply->Status = STATUS_SUCCESS;
77
78 return Reply->Status;
79 }
80
81 CSR_API(CsrExitReactos)
82 {
83 Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY);
84 Reply->Header.DataSize = sizeof(CSRSS_API_REPLY) - LPC_MESSAGE_BASE_SIZE;
85
86 if (NULL == LogonNotifyWindow)
87 {
88 DPRINT1("No LogonNotifyWindow registered\n");
89 Reply->Status = STATUS_NOT_FOUND;
90 return Reply->Status;
91 }
92
93 /* FIXME Inside 2000 says we should impersonate the caller here */
94 Reply->Status = SendMessageW(LogonNotifyWindow, PM_WINLOGON_EXITWINDOWS,
95 (WPARAM) Request->Header.ClientId.UniqueProcess,
96 (LPARAM) Request->Data.ExitReactosRequest.Flags);
97 /* If the message isn't handled, the return value is 0, so 0 doesn't indicate success.
98 Success is indicated by a 1 return value, if anything besides 0 or 1 it's a
99 NTSTATUS value */
100 if (1 == Reply->Status)
101 {
102 Reply->Status = STATUS_SUCCESS;
103 }
104 else if (0 == Reply->Status)
105 {
106 Reply->Status = STATUS_NOT_IMPLEMENTED;
107 }
108
109 return Reply->Status;
110 }
111
112 /* EOF */