[USERSRV] Hard-error improvements 3/7
[reactos.git] / win32ss / user / winsrv / usersrv / register.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS User API Server DLL
4 * FILE: win32ss/user/winsrv/usersrv/register.c
5 * PURPOSE: Register logon window and services process
6 * PROGRAMMERS: Eric Kohl
7 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
8 */
9
10 /* INCLUDES *******************************************************************/
11
12 #include "usersrv.h"
13
14 #define NDEBUG
15 #include <debug.h>
16
17 /* GLOBALS ********************************************************************/
18
19 static BOOLEAN ServicesProcessIdValid = FALSE;
20 ULONG_PTR ServicesProcessId = 0;
21 ULONG_PTR LogonProcessId = 0;
22
23 /* PUBLIC SERVER APIS *********************************************************/
24
25 CSR_API(SrvRegisterLogonProcess)
26 {
27 PUSER_REGISTER_LOGON_PROCESS RegisterLogonProcessRequest = &((PUSER_API_MESSAGE)ApiMessage)->Data.RegisterLogonProcessRequest;
28
29 if (RegisterLogonProcessRequest->Register)
30 {
31 if (LogonProcessId != 0)
32 return STATUS_LOGON_SESSION_EXISTS;
33
34 LogonProcessId = RegisterLogonProcessRequest->ProcessId;
35 }
36 else
37 {
38 if (ApiMessage->Header.ClientId.UniqueProcess != UlongToHandle(LogonProcessId))
39 {
40 DPRINT1("Current logon process 0x%x, can't deregister from process 0x%x\n",
41 LogonProcessId, ApiMessage->Header.ClientId.UniqueProcess);
42 return STATUS_NOT_LOGON_PROCESS;
43 }
44
45 LogonProcessId = 0;
46 }
47
48 return STATUS_SUCCESS;
49 }
50
51 CSR_API(SrvRegisterServicesProcess)
52 {
53 PUSER_REGISTER_SERVICES_PROCESS RegisterServicesProcessRequest = &((PUSER_API_MESSAGE)ApiMessage)->Data.RegisterServicesProcessRequest;
54
55 if (ServicesProcessIdValid)
56 {
57 /* Only accept a single call */
58 return STATUS_INVALID_PARAMETER;
59 }
60 else
61 {
62 ServicesProcessId = RegisterServicesProcessRequest->ProcessId;
63 ServicesProcessIdValid = TRUE;
64 return STATUS_SUCCESS;
65 }
66 }
67
68 /* EOF */