2012-02-16 06:57:27 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
2012-10-25 20:40:41 +00:00
|
|
|
* PROJECT: ReactOS Client/Server Runtime SubSystem
|
|
|
|
* FILE: subsystems/win32/csrsrv/session.c
|
2012-02-16 06:57:27 +00:00
|
|
|
* PURPOSE: CSR Server DLL Session Implementation
|
|
|
|
* PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
|
|
|
|
*/
|
|
|
|
|
2012-10-27 14:30:32 +00:00
|
|
|
/* INCLUDES *******************************************************************/
|
2012-02-16 06:57:27 +00:00
|
|
|
|
|
|
|
#include "srv.h"
|
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2012-10-27 14:30:32 +00:00
|
|
|
/* DATA ***********************************************************************/
|
2012-02-16 06:57:27 +00:00
|
|
|
|
|
|
|
RTL_CRITICAL_SECTION CsrNtSessionLock;
|
|
|
|
LIST_ENTRY CsrNtSessionList;
|
|
|
|
|
2013-03-10 19:37:33 +00:00
|
|
|
PSB_API_ROUTINE CsrServerSbApiDispatch[SbpMaxApiNumber - SbpCreateSession] =
|
2012-10-20 13:00:41 +00:00
|
|
|
{
|
|
|
|
CsrSbCreateSession,
|
|
|
|
CsrSbTerminateSession,
|
|
|
|
CsrSbForeignSessionComplete,
|
2013-03-10 19:37:33 +00:00
|
|
|
CsrSbCreateProcess
|
2012-10-20 13:00:41 +00:00
|
|
|
};
|
|
|
|
|
2013-03-10 19:37:33 +00:00
|
|
|
PCHAR CsrServerSbApiName[SbpMaxApiNumber - SbpCreateSession] =
|
2012-02-16 16:21:48 +00:00
|
|
|
{
|
|
|
|
"SbCreateSession",
|
|
|
|
"SbTerminateSession",
|
|
|
|
"SbForeignSessionComplete",
|
2013-03-10 19:37:33 +00:00
|
|
|
"SbCreateProcess"
|
2012-02-16 16:21:48 +00:00
|
|
|
};
|
|
|
|
|
2012-10-27 14:30:32 +00:00
|
|
|
/* PRIVATE FUNCTIONS **********************************************************/
|
2012-02-16 06:57:27 +00:00
|
|
|
|
|
|
|
/*++
|
|
|
|
* @name CsrInitializeNtSessionList
|
|
|
|
*
|
|
|
|
* The CsrInitializeNtSessionList routine sets up support for CSR Sessions.
|
|
|
|
*
|
|
|
|
* @param None
|
|
|
|
*
|
|
|
|
* @return None
|
|
|
|
*
|
|
|
|
* @remarks None.
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
CsrInitializeNtSessionList(VOID)
|
|
|
|
{
|
|
|
|
/* Initialize the Session List */
|
|
|
|
InitializeListHead(&CsrNtSessionList);
|
|
|
|
|
|
|
|
/* Initialize the Session Lock */
|
|
|
|
return RtlInitializeCriticalSection(&CsrNtSessionLock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*++
|
|
|
|
* @name CsrAllocateNtSession
|
|
|
|
*
|
|
|
|
* The CsrAllocateNtSession routine allocates a new CSR NT Session.
|
|
|
|
*
|
|
|
|
* @param SessionId
|
|
|
|
* Session ID of the CSR NT Session to allocate.
|
|
|
|
*
|
|
|
|
* @return Pointer to the newly allocated CSR NT Session.
|
|
|
|
*
|
|
|
|
* @remarks None.
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
PCSR_NT_SESSION
|
|
|
|
NTAPI
|
|
|
|
CsrAllocateNtSession(IN ULONG SessionId)
|
|
|
|
{
|
|
|
|
PCSR_NT_SESSION NtSession;
|
|
|
|
|
|
|
|
/* Allocate an NT Session Object */
|
2013-01-26 21:23:10 +00:00
|
|
|
NtSession = RtlAllocateHeap(CsrHeap, HEAP_ZERO_MEMORY, sizeof(CSR_NT_SESSION));
|
2012-02-16 06:57:27 +00:00
|
|
|
if (NtSession)
|
|
|
|
{
|
|
|
|
/* Setup the Session Object */
|
|
|
|
NtSession->SessionId = SessionId;
|
|
|
|
NtSession->ReferenceCount = 1;
|
|
|
|
|
|
|
|
/* Insert it into the Session List */
|
|
|
|
CsrAcquireNtSessionLock();
|
|
|
|
InsertHeadList(&CsrNtSessionList, &NtSession->SessionLink);
|
|
|
|
CsrReleaseNtSessionLock();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ASSERT(NtSession != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the Session (or NULL) */
|
|
|
|
return NtSession;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*++
|
|
|
|
* @name CsrReferenceNtSession
|
|
|
|
*
|
|
|
|
* The CsrReferenceNtSession increases the reference count of a CSR NT Session.
|
|
|
|
*
|
|
|
|
* @param Session
|
|
|
|
* Pointer to the CSR NT Session to reference.
|
|
|
|
*
|
|
|
|
* @return None.
|
|
|
|
*
|
|
|
|
* @remarks None.
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
CsrReferenceNtSession(IN PCSR_NT_SESSION Session)
|
|
|
|
{
|
|
|
|
/* Acquire the lock */
|
|
|
|
CsrAcquireNtSessionLock();
|
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(!IsListEmpty(&Session->SessionLink));
|
|
|
|
ASSERT(Session->SessionId != 0);
|
|
|
|
ASSERT(Session->ReferenceCount != 0);
|
|
|
|
|
|
|
|
/* Increase the reference count */
|
|
|
|
Session->ReferenceCount++;
|
|
|
|
|
|
|
|
/* Release the lock */
|
|
|
|
CsrReleaseNtSessionLock();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*++
|
|
|
|
* @name CsrDereferenceNtSession
|
|
|
|
*
|
|
|
|
* The CsrDereferenceNtSession decreases the reference count of a
|
|
|
|
* CSR NT Session.
|
|
|
|
*
|
|
|
|
* @param Session
|
|
|
|
* Pointer to the CSR NT Session to reference.
|
|
|
|
*
|
|
|
|
* @param ExitStatus
|
|
|
|
* If this is the last reference to the session, this argument
|
|
|
|
* specifies the exit status.
|
|
|
|
*
|
|
|
|
* @return None.
|
|
|
|
*
|
|
|
|
* @remarks CsrDereferenceNtSession will complete the session if
|
|
|
|
* the last reference to it has been closed.
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
CsrDereferenceNtSession(IN PCSR_NT_SESSION Session,
|
|
|
|
IN NTSTATUS ExitStatus)
|
|
|
|
{
|
|
|
|
/* Acquire the lock */
|
|
|
|
CsrAcquireNtSessionLock();
|
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(!IsListEmpty(&Session->SessionLink));
|
|
|
|
ASSERT(Session->SessionId != 0);
|
|
|
|
ASSERT(Session->ReferenceCount != 0);
|
|
|
|
|
|
|
|
/* Dereference the Session Object */
|
2013-03-10 19:37:33 +00:00
|
|
|
if ((--Session->ReferenceCount) == 0)
|
2012-02-16 06:57:27 +00:00
|
|
|
{
|
|
|
|
/* Remove it from the list */
|
|
|
|
RemoveEntryList(&Session->SessionLink);
|
|
|
|
|
|
|
|
/* Release the lock */
|
|
|
|
CsrReleaseNtSessionLock();
|
|
|
|
|
|
|
|
/* Tell SM that we're done here */
|
|
|
|
SmSessionComplete(CsrSmApiPort, Session->SessionId, ExitStatus);
|
|
|
|
|
|
|
|
/* Free the Session Object */
|
|
|
|
RtlFreeHeap(CsrHeap, 0, Session);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Release the lock, the Session is still active */
|
|
|
|
CsrReleaseNtSessionLock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-27 14:30:32 +00:00
|
|
|
/* SESSION MANAGER FUNCTIONS **************************************************/
|
2012-02-16 16:21:48 +00:00
|
|
|
|
|
|
|
/*++
|
|
|
|
* @name CsrSbCreateSession
|
|
|
|
*
|
|
|
|
* The CsrSbCreateSession API is called by the Session Manager whenever a new
|
|
|
|
* session is created.
|
|
|
|
*
|
|
|
|
* @param ApiMessage
|
|
|
|
* Pointer to the Session Manager API Message.
|
|
|
|
*
|
2012-10-13 20:32:44 +00:00
|
|
|
* @return TRUE in case of success, FALSE otherwise.
|
2012-02-16 16:21:48 +00:00
|
|
|
*
|
|
|
|
* @remarks The CsrSbCreateSession routine will initialize a new CSR NT
|
|
|
|
* Session and allocate a new CSR Process for the subsystem process.
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
CsrSbCreateSession(IN PSB_API_MSG ApiMessage)
|
|
|
|
{
|
|
|
|
PSB_CREATE_SESSION_MSG CreateSession = &ApiMessage->CreateSession;
|
|
|
|
HANDLE hProcess, hThread;
|
|
|
|
PCSR_PROCESS CsrProcess;
|
|
|
|
PCSR_THREAD CsrThread;
|
2012-11-13 21:08:19 +00:00
|
|
|
PCSR_SERVER_DLL ServerDll;
|
2012-10-20 13:00:41 +00:00
|
|
|
PVOID ProcessData;
|
2012-11-13 21:08:19 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
KERNEL_USER_TIMES KernelTimes;
|
2012-10-20 13:00:41 +00:00
|
|
|
ULONG i;
|
2012-02-16 16:21:48 +00:00
|
|
|
|
|
|
|
/* Save the Process and Thread Handles */
|
|
|
|
hProcess = CreateSession->ProcessInfo.ProcessHandle;
|
|
|
|
hThread = CreateSession->ProcessInfo.ThreadHandle;
|
|
|
|
|
|
|
|
/* Lock the Processes */
|
|
|
|
CsrAcquireProcessLock();
|
|
|
|
|
|
|
|
/* Allocate a new process */
|
|
|
|
CsrProcess = CsrAllocateProcess();
|
|
|
|
if (!CsrProcess)
|
|
|
|
{
|
|
|
|
/* Fail */
|
|
|
|
ApiMessage->ReturnValue = STATUS_NO_MEMORY;
|
|
|
|
CsrReleaseProcessLock();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-08-15 16:34:21 +00:00
|
|
|
/* Set the Exception Port for us */
|
2012-02-16 16:21:48 +00:00
|
|
|
Status = NtSetInformationProcess(hProcess,
|
|
|
|
ProcessExceptionPort,
|
2012-02-19 06:32:17 +00:00
|
|
|
&CsrApiPort,
|
2015-08-15 16:34:21 +00:00
|
|
|
sizeof(CsrApiPort));
|
2012-02-16 16:21:48 +00:00
|
|
|
|
|
|
|
/* Check for success */
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Fail the request */
|
|
|
|
CsrDeallocateProcess(CsrProcess);
|
|
|
|
CsrReleaseProcessLock();
|
|
|
|
|
|
|
|
/* Strange as it seems, NTSTATUSes are actually returned */
|
|
|
|
return (BOOLEAN)STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the Create Time */
|
|
|
|
Status = NtQueryInformationThread(hThread,
|
|
|
|
ThreadTimes,
|
|
|
|
&KernelTimes,
|
2015-08-15 16:34:21 +00:00
|
|
|
sizeof(KernelTimes),
|
2012-02-16 16:21:48 +00:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* Check for success */
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Fail the request */
|
|
|
|
CsrDeallocateProcess(CsrProcess);
|
|
|
|
CsrReleaseProcessLock();
|
|
|
|
|
|
|
|
/* Strange as it seems, NTSTATUSes are actually returned */
|
|
|
|
return (BOOLEAN)Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate a new Thread */
|
|
|
|
CsrThread = CsrAllocateThread(CsrProcess);
|
|
|
|
if (!CsrThread)
|
|
|
|
{
|
|
|
|
/* Fail the request */
|
|
|
|
CsrDeallocateProcess(CsrProcess);
|
|
|
|
CsrReleaseProcessLock();
|
|
|
|
|
|
|
|
ApiMessage->ReturnValue = STATUS_NO_MEMORY;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup the Thread Object */
|
|
|
|
CsrThread->CreateTime = KernelTimes.CreateTime;
|
|
|
|
CsrThread->ClientId = CreateSession->ProcessInfo.ClientId;
|
|
|
|
CsrThread->ThreadHandle = hThread;
|
|
|
|
ProtectHandle(hThread);
|
|
|
|
CsrThread->Flags = 0;
|
|
|
|
|
|
|
|
/* Insert it into the Process List */
|
2013-09-12 09:02:48 +00:00
|
|
|
Status = CsrInsertThread(CsrProcess, CsrThread);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Bail out */
|
|
|
|
CsrDeallocateProcess(CsrProcess);
|
|
|
|
CsrDeallocateThread(CsrThread);
|
|
|
|
CsrReleaseProcessLock();
|
2013-09-22 21:04:06 +00:00
|
|
|
|
|
|
|
/* Strange as it seems, NTSTATUSes are actually returned */
|
|
|
|
return (BOOLEAN)Status;
|
2013-09-12 09:02:48 +00:00
|
|
|
}
|
2012-02-16 16:21:48 +00:00
|
|
|
|
|
|
|
/* Setup Process Data */
|
|
|
|
CsrProcess->ClientId = CreateSession->ProcessInfo.ClientId;
|
|
|
|
CsrProcess->ProcessHandle = hProcess;
|
|
|
|
CsrProcess->NtSession = CsrAllocateNtSession(CreateSession->SessionId);
|
|
|
|
|
|
|
|
/* Set the Process Priority */
|
|
|
|
CsrSetBackgroundPriority(CsrProcess);
|
2012-10-20 13:00:41 +00:00
|
|
|
|
2012-02-16 16:21:48 +00:00
|
|
|
/* Get the first data location */
|
|
|
|
ProcessData = &CsrProcess->ServerData[CSR_SERVER_DLL_MAX];
|
|
|
|
|
|
|
|
/* Loop every DLL */
|
|
|
|
for (i = 0; i < CSR_SERVER_DLL_MAX; i++)
|
|
|
|
{
|
2012-11-13 21:08:19 +00:00
|
|
|
/* Get the current Server */
|
|
|
|
ServerDll = CsrLoadedServerDll[i];
|
|
|
|
|
2012-02-16 16:21:48 +00:00
|
|
|
/* Check if the DLL is loaded and has Process Data */
|
2012-11-13 21:08:19 +00:00
|
|
|
if (ServerDll && ServerDll->SizeOfProcessData)
|
2012-02-16 16:21:48 +00:00
|
|
|
{
|
|
|
|
/* Write the pointer to the data */
|
|
|
|
CsrProcess->ServerData[i] = ProcessData;
|
|
|
|
|
|
|
|
/* Move to the next data location */
|
|
|
|
ProcessData = (PVOID)((ULONG_PTR)ProcessData +
|
2012-11-13 21:08:19 +00:00
|
|
|
ServerDll->SizeOfProcessData);
|
2012-02-16 16:21:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Nothing for this Process */
|
|
|
|
CsrProcess->ServerData[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
2012-10-20 13:00:41 +00:00
|
|
|
|
2012-02-16 16:21:48 +00:00
|
|
|
/* Insert the Process */
|
2013-01-26 21:23:10 +00:00
|
|
|
CsrInsertProcess(NULL, CsrProcess);
|
2012-02-16 16:21:48 +00:00
|
|
|
|
|
|
|
/* Activate the Thread */
|
|
|
|
ApiMessage->ReturnValue = NtResumeThread(hThread, NULL);
|
|
|
|
|
|
|
|
/* Release lock and return */
|
|
|
|
CsrReleaseProcessLock();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*++
|
|
|
|
* @name CsrSbForeignSessionComplete
|
|
|
|
*
|
|
|
|
* The CsrSbForeignSessionComplete API is called by the Session Manager
|
|
|
|
* whenever a foreign session is completed (ie: terminated).
|
|
|
|
*
|
|
|
|
* @param ApiMessage
|
|
|
|
* Pointer to the Session Manager API Message.
|
|
|
|
*
|
2012-10-13 20:32:44 +00:00
|
|
|
* @return TRUE in case of success, FALSE otherwise.
|
2012-02-16 16:21:48 +00:00
|
|
|
*
|
|
|
|
* @remarks The CsrSbForeignSessionComplete API is not yet implemented.
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
CsrSbForeignSessionComplete(IN PSB_API_MSG ApiMessage)
|
|
|
|
{
|
|
|
|
/* Deprecated/Unimplemented in NT */
|
|
|
|
ApiMessage->ReturnValue = STATUS_NOT_IMPLEMENTED;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*++
|
|
|
|
* @name CsrSbTerminateSession
|
|
|
|
*
|
|
|
|
* The CsrSbTerminateSession API is called by the Session Manager
|
|
|
|
* whenever a foreign session should be destroyed.
|
|
|
|
*
|
|
|
|
* @param ApiMessage
|
|
|
|
* Pointer to the Session Manager API Message.
|
|
|
|
*
|
2012-10-13 20:32:44 +00:00
|
|
|
* @return TRUE in case of success, FALSE otherwise.
|
2012-02-16 16:21:48 +00:00
|
|
|
*
|
|
|
|
* @remarks The CsrSbTerminateSession API is not yet implemented.
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
CsrSbTerminateSession(IN PSB_API_MSG ApiMessage)
|
|
|
|
{
|
|
|
|
ApiMessage->ReturnValue = STATUS_NOT_IMPLEMENTED;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*++
|
|
|
|
* @name CsrSbCreateProcess
|
|
|
|
*
|
|
|
|
* The CsrSbCreateProcess API is called by the Session Manager
|
|
|
|
* whenever a foreign session is created and a new process should be started.
|
|
|
|
*
|
|
|
|
* @param ApiMessage
|
|
|
|
* Pointer to the Session Manager API Message.
|
|
|
|
*
|
2012-10-13 20:32:44 +00:00
|
|
|
* @return TRUE in case of success, FALSE otherwise.
|
2012-02-16 16:21:48 +00:00
|
|
|
*
|
|
|
|
* @remarks The CsrSbCreateProcess API is not yet implemented.
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
CsrSbCreateProcess(IN PSB_API_MSG ApiMessage)
|
|
|
|
{
|
|
|
|
ApiMessage->ReturnValue = STATUS_NOT_IMPLEMENTED;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*++
|
|
|
|
* @name CsrSbApiHandleConnectionRequest
|
|
|
|
*
|
|
|
|
* The CsrSbApiHandleConnectionRequest routine handles and accepts a new
|
|
|
|
* connection request to the SM API LPC Port.
|
|
|
|
*
|
|
|
|
* @param ApiMessage
|
|
|
|
* Pointer to the incoming CSR API Message which contains the
|
|
|
|
* connection request.
|
|
|
|
*
|
|
|
|
* @return STATUS_SUCCESS in case of success, or status code which caused
|
|
|
|
* the routine to error.
|
|
|
|
*
|
|
|
|
* @remarks None.
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
CsrSbApiHandleConnectionRequest(IN PSB_API_MSG Message)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
REMOTE_PORT_VIEW RemotePortView;
|
|
|
|
HANDLE hPort;
|
|
|
|
|
|
|
|
/* Set the Port View Structure Length */
|
|
|
|
RemotePortView.Length = sizeof(REMOTE_PORT_VIEW);
|
|
|
|
|
|
|
|
/* Accept the connection */
|
|
|
|
Status = NtAcceptConnectPort(&hPort,
|
|
|
|
NULL,
|
2013-10-06 00:04:18 +00:00
|
|
|
&Message->h,
|
2012-02-16 16:21:48 +00:00
|
|
|
TRUE,
|
|
|
|
NULL,
|
|
|
|
&RemotePortView);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("CSRSS: Sb Accept Connection failed %lx\n", Status);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Complete the Connection */
|
|
|
|
Status = NtCompleteConnectPort(hPort);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("CSRSS: Sb Complete Connection failed %lx\n",Status);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return status */
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*++
|
|
|
|
* @name CsrSbApiRequestThread
|
|
|
|
*
|
|
|
|
* The CsrSbApiRequestThread routine handles incoming messages or connection
|
|
|
|
* requests on the SM API LPC Port.
|
|
|
|
*
|
|
|
|
* @param Parameter
|
|
|
|
* System-default user-defined parameter. Unused.
|
|
|
|
*
|
|
|
|
* @return The thread exit code, if the thread is terminated.
|
|
|
|
*
|
|
|
|
* @remarks Before listening on the port, the routine will first attempt
|
|
|
|
* to connect to the user subsystem.
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
CsrSbApiRequestThread(IN PVOID Parameter)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
SB_API_MSG ReceiveMsg;
|
|
|
|
PSB_API_MSG ReplyMsg = NULL;
|
|
|
|
PVOID PortContext;
|
|
|
|
ULONG MessageType;
|
|
|
|
|
|
|
|
/* Start the loop */
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
/* Wait for a message to come in */
|
|
|
|
Status = NtReplyWaitReceivePort(CsrSbApiPort,
|
|
|
|
&PortContext,
|
|
|
|
&ReplyMsg->h,
|
|
|
|
&ReceiveMsg.h);
|
|
|
|
|
|
|
|
/* Check if we didn't get success */
|
|
|
|
if (Status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
/* If we only got a warning, keep going */
|
|
|
|
if (NT_SUCCESS(Status)) continue;
|
|
|
|
|
|
|
|
/* We failed big time, so start out fresh */
|
|
|
|
ReplyMsg = NULL;
|
|
|
|
DPRINT1("CSRSS: ReceivePort failed - Status == %X\n", Status);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Save the message type */
|
|
|
|
MessageType = ReceiveMsg.h.u2.s2.Type;
|
|
|
|
|
|
|
|
/* Check if this is a connection request */
|
|
|
|
if (MessageType == LPC_CONNECTION_REQUEST)
|
|
|
|
{
|
|
|
|
/* Handle connection request */
|
|
|
|
CsrSbApiHandleConnectionRequest(&ReceiveMsg);
|
|
|
|
|
|
|
|
/* Start over */
|
|
|
|
ReplyMsg = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the port died */
|
|
|
|
if (MessageType == LPC_PORT_CLOSED)
|
|
|
|
{
|
|
|
|
/* Close the handle if we have one */
|
|
|
|
if (PortContext) NtClose((HANDLE)PortContext);
|
|
|
|
|
|
|
|
/* Client died, start over */
|
|
|
|
ReplyMsg = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (MessageType == LPC_CLIENT_DIED)
|
|
|
|
{
|
|
|
|
/* Client died, start over */
|
|
|
|
ReplyMsg = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2013-03-10 19:37:33 +00:00
|
|
|
* It's an API Message, check if it's within limits. If it's not,
|
|
|
|
* the NT Behaviour is to set this to the Maximum API.
|
2012-02-16 16:21:48 +00:00
|
|
|
*/
|
|
|
|
if (ReceiveMsg.ApiNumber > SbpMaxApiNumber)
|
|
|
|
{
|
|
|
|
ReceiveMsg.ApiNumber = SbpMaxApiNumber;
|
|
|
|
DPRINT1("CSRSS: %lx is invalid Sb ApiNumber\n", ReceiveMsg.ApiNumber);
|
2012-10-22 00:09:51 +00:00
|
|
|
}
|
2012-02-16 16:21:48 +00:00
|
|
|
|
|
|
|
/* Reuse the message */
|
|
|
|
ReplyMsg = &ReceiveMsg;
|
|
|
|
|
|
|
|
/* Make sure that the message is supported */
|
|
|
|
if (ReceiveMsg.ApiNumber < SbpMaxApiNumber)
|
|
|
|
{
|
|
|
|
/* Call the API */
|
|
|
|
if (!CsrServerSbApiDispatch[ReceiveMsg.ApiNumber](&ReceiveMsg))
|
|
|
|
{
|
2013-03-10 19:37:33 +00:00
|
|
|
DPRINT1("CSRSS: %s Session Api called and failed\n",
|
|
|
|
CsrServerSbApiName[ReceiveMsg.ApiNumber]);
|
|
|
|
|
2012-02-16 16:21:48 +00:00
|
|
|
/* It failed, so return nothing */
|
|
|
|
ReplyMsg = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We don't support this API Number */
|
|
|
|
ReplyMsg->ReturnValue = STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-16 06:57:27 +00:00
|
|
|
/* EOF */
|