mirror of
https://github.com/reactos/reactos.git
synced 2025-02-24 17:34:57 +00:00
[CSRSRV]: No longer accept connections from unknown processes.
svn path=/trunk/; revision=55697
This commit is contained in:
parent
e403a8e2e1
commit
86597860d2
1 changed files with 52 additions and 24 deletions
|
@ -743,11 +743,10 @@ CsrpHandleConnectionRequest (PPORT_MESSAGE Request)
|
|||
NTSTATUS Status;
|
||||
HANDLE ServerPort = NULL, ServerThread = NULL;
|
||||
PCSR_PROCESS ProcessData = NULL;
|
||||
REMOTE_PORT_VIEW LpcRead;
|
||||
REMOTE_PORT_VIEW RemotePortView;
|
||||
CLIENT_ID ClientId;
|
||||
BOOLEAN AllowConnection = FALSE;
|
||||
PCSR_CONNECTION_INFO ConnectInfo;
|
||||
LpcRead.Length = sizeof(LpcRead);
|
||||
ServerPort = NULL;
|
||||
|
||||
DPRINT("CSR: %s: Handling: %p\n", __FUNCTION__, Request);
|
||||
|
@ -756,18 +755,16 @@ CsrpHandleConnectionRequest (PPORT_MESSAGE Request)
|
|||
|
||||
/* Save the process ID */
|
||||
RtlZeroMemory(ConnectInfo, sizeof(CSR_CONNECTION_INFO));
|
||||
ConnectInfo->ProcessId = NtCurrentTeb()->ClientId.UniqueProcess;
|
||||
|
||||
ProcessData = CsrGetProcessData(Request->ClientId.UniqueProcess);
|
||||
if (ProcessData == NULL)
|
||||
if (!ProcessData)
|
||||
{
|
||||
ProcessData = CsrCreateProcessData(Request->ClientId.UniqueProcess);
|
||||
if (ProcessData == NULL)
|
||||
{
|
||||
DPRINT1("Unable to allocate or find data for process 0x%x\n",
|
||||
DPRINT1("CSRSRV: Unknown process: %lx. Will be rejecting connection\n",
|
||||
Request->ClientId.UniqueProcess);
|
||||
}
|
||||
}
|
||||
|
||||
/* Acquire the Process Lock */
|
||||
CsrAcquireProcessLock();
|
||||
|
||||
if ((ProcessData) && (ProcessData != CsrRootProcess))
|
||||
{
|
||||
|
@ -788,28 +785,59 @@ CsrpHandleConnectionRequest (PPORT_MESSAGE Request)
|
|||
AllowConnection = TRUE;
|
||||
}
|
||||
|
||||
/* Release the lock */
|
||||
CsrReleaseProcessLock();
|
||||
|
||||
/* Setup the Port View Structure */
|
||||
RemotePortView.Length = sizeof(REMOTE_PORT_VIEW);
|
||||
RemotePortView.ViewSize = 0;
|
||||
RemotePortView.ViewBase = NULL;
|
||||
|
||||
/* Save the Process ID */
|
||||
ConnectInfo->ProcessId = NtCurrentTeb()->ClientId.UniqueProcess;
|
||||
|
||||
Status = NtAcceptConnectPort(&ServerPort,
|
||||
NULL,
|
||||
AllowConnection ? UlongToPtr(ProcessData->SequenceNumber) : 0,
|
||||
Request,
|
||||
AllowConnection,
|
||||
0,
|
||||
& LpcRead);
|
||||
NULL,
|
||||
&RemotePortView);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("CSR: NtAcceptConnectPort() failed\n");
|
||||
return Status;
|
||||
DPRINT1("CSRSS: NtAcceptConnectPort - failed. Status == %X\n", Status);
|
||||
}
|
||||
else if (AllowConnection)
|
||||
{
|
||||
if (CsrDebug & 2)
|
||||
{
|
||||
DPRINT1("CSRSS: ClientId: %lx.%lx has ClientView: Base=%p, Size=%lx\n",
|
||||
Request->ClientId.UniqueProcess,
|
||||
Request->ClientId.UniqueThread,
|
||||
RemotePortView.ViewBase,
|
||||
RemotePortView.ViewSize);
|
||||
}
|
||||
|
||||
ProcessData->ClientViewBase = (ULONG_PTR)LpcRead.ViewBase;
|
||||
ProcessData->ClientViewBounds = LpcRead.ViewSize;
|
||||
/* Set some Port Data in the Process */
|
||||
ProcessData->ClientPort = ServerPort;
|
||||
ProcessData->ClientViewBase = (ULONG_PTR)RemotePortView.ViewBase;
|
||||
ProcessData->ClientViewBounds = (ULONG_PTR)((ULONG_PTR)RemotePortView.ViewBase +
|
||||
(ULONG_PTR)RemotePortView.ViewSize);
|
||||
|
||||
if (AllowConnection) Status = NtCompleteConnectPort(ServerPort);
|
||||
/* Complete the connection */
|
||||
Status = NtCompleteConnectPort(ServerPort);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("CSR: NtCompleteConnectPort() failed\n");
|
||||
return Status;
|
||||
DPRINT1("CSRSS: NtCompleteConnectPort - failed. Status == %X\n", Status);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DPRINT1("CSRSS: Rejecting Connection Request from ClientId: %lx.%lx\n",
|
||||
Request->ClientId.UniqueProcess,
|
||||
Request->ClientId.UniqueThread);
|
||||
}
|
||||
|
||||
if (!NT_SUCCESS(Status)) return Status;
|
||||
|
||||
Status = RtlCreateUserThread(NtCurrentProcess(),
|
||||
NULL,
|
||||
|
|
Loading…
Reference in a new issue