xref: /reactos/win32ss/user/winsrv/usersrv/register.c (revision 8dc90a4c)
1c2c66affSColin Finck /*
2c2c66affSColin Finck  * COPYRIGHT:       See COPYING in the top level directory
3c2c66affSColin Finck  * PROJECT:         ReactOS User API Server DLL
4c2c66affSColin Finck  * FILE:            win32ss/user/winsrv/usersrv/register.c
5c2c66affSColin Finck  * PURPOSE:         Register logon window and services process
6c2c66affSColin Finck  * PROGRAMMERS:     Eric Kohl
7c2c66affSColin Finck  *                  Hermes Belusca-Maito (hermes.belusca@sfr.fr)
8c2c66affSColin Finck  */
9c2c66affSColin Finck 
10c2c66affSColin Finck /* INCLUDES *******************************************************************/
11c2c66affSColin Finck 
12c2c66affSColin Finck #include "usersrv.h"
13c2c66affSColin Finck 
14c2c66affSColin Finck #define NDEBUG
15c2c66affSColin Finck #include <debug.h>
16c2c66affSColin Finck 
17c2c66affSColin Finck /* GLOBALS ********************************************************************/
18c2c66affSColin Finck 
19c2c66affSColin Finck static BOOLEAN ServicesProcessIdValid = FALSE;
20c2c66affSColin Finck ULONG_PTR ServicesProcessId = 0;
21c2c66affSColin Finck ULONG_PTR LogonProcessId = 0;
22c2c66affSColin Finck 
233ec7b163SGiannis Adamopoulos #if 1 //HACK! See use below
243ec7b163SGiannis Adamopoulos extern HANDLE CsrApiPort;
253ec7b163SGiannis Adamopoulos #endif
263ec7b163SGiannis Adamopoulos 
27c2c66affSColin Finck /* PUBLIC SERVER APIS *********************************************************/
28c2c66affSColin Finck 
29*8dc90a4cSKatayama Hirofumi MZ /* API_NUMBER: UserpRegisterLogonProcess */
CSR_API(SrvRegisterLogonProcess)30c2c66affSColin Finck CSR_API(SrvRegisterLogonProcess)
31c2c66affSColin Finck {
32c2c66affSColin Finck     PUSER_REGISTER_LOGON_PROCESS RegisterLogonProcessRequest = &((PUSER_API_MESSAGE)ApiMessage)->Data.RegisterLogonProcessRequest;
33c2c66affSColin Finck 
34c2c66affSColin Finck     if (RegisterLogonProcessRequest->Register)
35c2c66affSColin Finck     {
36c2c66affSColin Finck         if (LogonProcessId != 0)
37c2c66affSColin Finck             return STATUS_LOGON_SESSION_EXISTS;
38c2c66affSColin Finck 
39c2c66affSColin Finck         LogonProcessId = RegisterLogonProcessRequest->ProcessId;
40c2c66affSColin Finck     }
41c2c66affSColin Finck     else
42c2c66affSColin Finck     {
43c2c66affSColin Finck         if (ApiMessage->Header.ClientId.UniqueProcess != UlongToHandle(LogonProcessId))
44c2c66affSColin Finck         {
45c2c66affSColin Finck             DPRINT1("Current logon process 0x%x, can't deregister from process 0x%x\n",
46c2c66affSColin Finck                     LogonProcessId, ApiMessage->Header.ClientId.UniqueProcess);
47c2c66affSColin Finck             return STATUS_NOT_LOGON_PROCESS;
48c2c66affSColin Finck         }
49c2c66affSColin Finck 
50c2c66affSColin Finck         LogonProcessId = 0;
51c2c66affSColin Finck     }
52c2c66affSColin Finck 
533ec7b163SGiannis Adamopoulos #if 1 //HAAAACK. This should be done in UserClientConnect which is never called!
543ec7b163SGiannis Adamopoulos 
553ec7b163SGiannis Adamopoulos     /* Check if we don't have an API port yet */
563ec7b163SGiannis Adamopoulos     if (CsrApiPort == NULL)
573ec7b163SGiannis Adamopoulos     {
583ec7b163SGiannis Adamopoulos         NTSTATUS Status;
593ec7b163SGiannis Adamopoulos 
603ec7b163SGiannis Adamopoulos         /* Query the API port and save it globally */
613ec7b163SGiannis Adamopoulos         CsrApiPort = CsrQueryApiPort();
623ec7b163SGiannis Adamopoulos 
633ec7b163SGiannis Adamopoulos         DPRINT("Giving win32k our api port\n");
643ec7b163SGiannis Adamopoulos 
653ec7b163SGiannis Adamopoulos         /* Inform win32k about the API port */
663ec7b163SGiannis Adamopoulos         Status = NtUserSetInformationThread(NtCurrentThread(),
673ec7b163SGiannis Adamopoulos                                             UserThreadCsrApiPort,
683ec7b163SGiannis Adamopoulos                                             &CsrApiPort,
693ec7b163SGiannis Adamopoulos                                             sizeof(CsrApiPort));
703ec7b163SGiannis Adamopoulos         if (!NT_SUCCESS(Status))
713ec7b163SGiannis Adamopoulos         {
723ec7b163SGiannis Adamopoulos             return Status;
733ec7b163SGiannis Adamopoulos         }
743ec7b163SGiannis Adamopoulos     }
753ec7b163SGiannis Adamopoulos #endif
763ec7b163SGiannis Adamopoulos 
77c2c66affSColin Finck     return STATUS_SUCCESS;
78c2c66affSColin Finck }
79c2c66affSColin Finck 
80*8dc90a4cSKatayama Hirofumi MZ /* API_NUMBER: UserpRegisterServicesProcess */
CSR_API(SrvRegisterServicesProcess)81c2c66affSColin Finck CSR_API(SrvRegisterServicesProcess)
82c2c66affSColin Finck {
83c2c66affSColin Finck     PUSER_REGISTER_SERVICES_PROCESS RegisterServicesProcessRequest = &((PUSER_API_MESSAGE)ApiMessage)->Data.RegisterServicesProcessRequest;
84c2c66affSColin Finck 
85c2c66affSColin Finck     if (ServicesProcessIdValid)
86c2c66affSColin Finck     {
87c2c66affSColin Finck         /* Only accept a single call */
88c2c66affSColin Finck         return STATUS_INVALID_PARAMETER;
89c2c66affSColin Finck     }
90c2c66affSColin Finck     else
91c2c66affSColin Finck     {
92c2c66affSColin Finck         ServicesProcessId = RegisterServicesProcessRequest->ProcessId;
93c2c66affSColin Finck         ServicesProcessIdValid = TRUE;
94c2c66affSColin Finck         return STATUS_SUCCESS;
95c2c66affSColin Finck     }
96c2c66affSColin Finck }
97c2c66affSColin Finck 
98c2c66affSColin Finck /* EOF */
99