mirror of
https://github.com/reactos/reactos.git
synced 2024-12-27 17:44:45 +00:00
svn: eol-style + keywords
svn path=/trunk/; revision=18051
This commit is contained in:
parent
294b660b25
commit
887b19bebf
3 changed files with 530 additions and 527 deletions
|
@ -1,89 +1,90 @@
|
||||||
/*
|
/* $Id$
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
*
|
||||||
* PROJECT: ReactOS kernel
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* FILE: lib/ntdll/csr/api.c
|
* PROJECT: ReactOS kernel
|
||||||
* PURPOSE: CSR APIs exported through NTDLL
|
* FILE: lib/ntdll/csr/api.c
|
||||||
* PROGRAMMER: Alex Ionescu (alex@relsoft.net)
|
* PURPOSE: CSR APIs exported through NTDLL
|
||||||
*/
|
* PROGRAMMER: Alex Ionescu (alex@relsoft.net)
|
||||||
|
*/
|
||||||
/* INCLUDES *****************************************************************/
|
|
||||||
|
/* INCLUDES *****************************************************************/
|
||||||
#include <ntdll.h>
|
|
||||||
#define NDEBUG
|
#include <ntdll.h>
|
||||||
#include <debug.h>
|
#define NDEBUG
|
||||||
|
#include <debug.h>
|
||||||
/* GLOBALS *******************************************************************/
|
|
||||||
extern HANDLE CsrApiPort;
|
/* GLOBALS *******************************************************************/
|
||||||
|
extern HANDLE CsrApiPort;
|
||||||
/* FUNCTIONS *****************************************************************/
|
|
||||||
|
/* FUNCTIONS *****************************************************************/
|
||||||
/*
|
|
||||||
* @implemented
|
/*
|
||||||
*/
|
* @implemented
|
||||||
NTSTATUS
|
*/
|
||||||
NTAPI
|
NTSTATUS
|
||||||
CsrNewThread(VOID)
|
NTAPI
|
||||||
{
|
CsrNewThread(VOID)
|
||||||
/* Register the termination port to CSR's */
|
{
|
||||||
return NtRegisterThreadTerminatePort(CsrApiPort);
|
/* Register the termination port to CSR's */
|
||||||
}
|
return NtRegisterThreadTerminatePort(CsrApiPort);
|
||||||
|
}
|
||||||
/*
|
|
||||||
* @implemented
|
/*
|
||||||
*/
|
* @implemented
|
||||||
NTSTATUS
|
*/
|
||||||
NTAPI
|
NTSTATUS
|
||||||
CsrSetPriorityClass(HANDLE hProcess,
|
NTAPI
|
||||||
PULONG PriorityClass)
|
CsrSetPriorityClass(HANDLE hProcess,
|
||||||
{
|
PULONG PriorityClass)
|
||||||
NTSTATUS Status;
|
{
|
||||||
CSR_API_MESSAGE2 ApiMessage; /* <- Remove the "2" when CSR is commited */
|
NTSTATUS Status;
|
||||||
PCSR_SET_PRIORITY_CLASS SetPriorityClass = &ApiMessage.SetPriorityClass;
|
CSR_API_MESSAGE2 ApiMessage; /* <- Remove the "2" when CSR is commited */
|
||||||
|
PCSR_SET_PRIORITY_CLASS SetPriorityClass = &ApiMessage.SetPriorityClass;
|
||||||
/* Set up the data for CSR */
|
|
||||||
DbgBreakPoint();
|
/* Set up the data for CSR */
|
||||||
SetPriorityClass->hProcess = hProcess;
|
DbgBreakPoint();
|
||||||
SetPriorityClass->PriorityClass = *PriorityClass;
|
SetPriorityClass->hProcess = hProcess;
|
||||||
|
SetPriorityClass->PriorityClass = *PriorityClass;
|
||||||
/* Call it */
|
|
||||||
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
/* Call it */
|
||||||
NULL,
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
||||||
CSR_MAKE_OPCODE(CsrSrvSetPriorityClass,
|
NULL,
|
||||||
CSR_SRV_SERVER),
|
CSR_MAKE_OPCODE(CsrSrvSetPriorityClass,
|
||||||
sizeof(CSR_SET_PRIORITY_CLASS));
|
CSR_SRV_SERVER),
|
||||||
|
sizeof(CSR_SET_PRIORITY_CLASS));
|
||||||
/* Return what we got, if requested */
|
|
||||||
if (*PriorityClass) *PriorityClass = SetPriorityClass->PriorityClass;
|
/* Return what we got, if requested */
|
||||||
|
if (*PriorityClass) *PriorityClass = SetPriorityClass->PriorityClass;
|
||||||
/* Return to caller */
|
|
||||||
return Status;
|
/* Return to caller */
|
||||||
}
|
return Status;
|
||||||
|
}
|
||||||
/*
|
|
||||||
* @implemented
|
/*
|
||||||
*/
|
* @implemented
|
||||||
NTSTATUS
|
*/
|
||||||
NTAPI
|
NTSTATUS
|
||||||
CsrIdentifyAlertableThread (VOID)
|
NTAPI
|
||||||
{
|
CsrIdentifyAlertableThread (VOID)
|
||||||
NTSTATUS Status;
|
{
|
||||||
CSR_API_MESSAGE2 ApiMessage; /* <- Remove the "2" when CSR is commited */
|
NTSTATUS Status;
|
||||||
PCSR_IDENTIFY_ALTERTABLE_THREAD IdentifyAlertableThread;
|
CSR_API_MESSAGE2 ApiMessage; /* <- Remove the "2" when CSR is commited */
|
||||||
|
PCSR_IDENTIFY_ALTERTABLE_THREAD IdentifyAlertableThread;
|
||||||
/* Set up the data for CSR */
|
|
||||||
DbgBreakPoint();
|
/* Set up the data for CSR */
|
||||||
IdentifyAlertableThread = &ApiMessage.IdentifyAlertableThread;
|
DbgBreakPoint();
|
||||||
IdentifyAlertableThread->Cid = NtCurrentTeb()->Cid;
|
IdentifyAlertableThread = &ApiMessage.IdentifyAlertableThread;
|
||||||
|
IdentifyAlertableThread->Cid = NtCurrentTeb()->Cid;
|
||||||
/* Call it */
|
|
||||||
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
/* Call it */
|
||||||
NULL,
|
Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
||||||
CSR_MAKE_OPCODE(CsrSrvIdentifyAlertableThread,
|
NULL,
|
||||||
CSR_SRV_SERVER),
|
CSR_MAKE_OPCODE(CsrSrvIdentifyAlertableThread,
|
||||||
sizeof(CSR_SET_PRIORITY_CLASS));
|
CSR_SRV_SERVER),
|
||||||
|
sizeof(CSR_SET_PRIORITY_CLASS));
|
||||||
/* Return to caller */
|
|
||||||
return Status;
|
/* Return to caller */
|
||||||
}
|
return Status;
|
||||||
|
}
|
||||||
/* EOF */
|
|
||||||
|
/* EOF */
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
/*
|
/* $Id$
|
||||||
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS kernel
|
||||||
* FILE: lib/ntdll/csr/capture.c
|
* FILE: lib/ntdll/csr/capture.c
|
||||||
|
|
|
@ -1,437 +1,438 @@
|
||||||
/*
|
/* $Id$
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
*
|
||||||
* PROJECT: ReactOS kernel
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* FILE: lib/ntdll/csr/connect.c
|
* PROJECT: ReactOS kernel
|
||||||
* PURPOSE: Routines for connecting and calling CSR
|
* FILE: lib/ntdll/csr/connect.c
|
||||||
* PROGRAMMER: Alex Ionescu (alex@relsoft.net)
|
* PURPOSE: Routines for connecting and calling CSR
|
||||||
*/
|
* PROGRAMMER: Alex Ionescu (alex@relsoft.net)
|
||||||
|
*/
|
||||||
/* INCLUDES *****************************************************************/
|
|
||||||
|
/* INCLUDES *****************************************************************/
|
||||||
#include <ntdll.h>
|
|
||||||
#define NDEBUG
|
#include <ntdll.h>
|
||||||
#include <debug.h>
|
#define NDEBUG
|
||||||
|
#include <debug.h>
|
||||||
/* GLOBALS *******************************************************************/
|
|
||||||
|
/* GLOBALS *******************************************************************/
|
||||||
HANDLE CsrApiPort;
|
|
||||||
HANDLE CsrProcessId;
|
HANDLE CsrApiPort;
|
||||||
HANDLE CsrPortHeap;
|
HANDLE CsrProcessId;
|
||||||
ULONG_PTR CsrPortMemoryDelta;
|
HANDLE CsrPortHeap;
|
||||||
BOOLEAN InsideCsrProcess = FALSE;
|
ULONG_PTR CsrPortMemoryDelta;
|
||||||
BOOLEAN UsingOldCsr = TRUE;
|
BOOLEAN InsideCsrProcess = FALSE;
|
||||||
|
BOOLEAN UsingOldCsr = TRUE;
|
||||||
typedef NTSTATUS
|
|
||||||
(NTAPI *PCSR_SERVER_API_ROUTINE)(IN PPORT_MESSAGE Request,
|
typedef NTSTATUS
|
||||||
IN PPORT_MESSAGE Reply);
|
(NTAPI *PCSR_SERVER_API_ROUTINE)(IN PPORT_MESSAGE Request,
|
||||||
|
IN PPORT_MESSAGE Reply);
|
||||||
PCSR_SERVER_API_ROUTINE CsrServerApiRoutine;
|
|
||||||
|
PCSR_SERVER_API_ROUTINE CsrServerApiRoutine;
|
||||||
#define UNICODE_PATH_SEP L"\\"
|
|
||||||
#define CSR_PORT_NAME L"ApiPort"
|
#define UNICODE_PATH_SEP L"\\"
|
||||||
|
#define CSR_PORT_NAME L"ApiPort"
|
||||||
/* FUNCTIONS *****************************************************************/
|
|
||||||
|
/* FUNCTIONS *****************************************************************/
|
||||||
/*
|
|
||||||
* @implemented
|
/*
|
||||||
*/
|
* @implemented
|
||||||
HANDLE
|
*/
|
||||||
NTAPI
|
HANDLE
|
||||||
CsrGetProcessId(VOID)
|
NTAPI
|
||||||
{
|
CsrGetProcessId(VOID)
|
||||||
return CsrProcessId;
|
{
|
||||||
}
|
return CsrProcessId;
|
||||||
|
}
|
||||||
/*
|
|
||||||
* @implemented
|
/*
|
||||||
*/
|
* @implemented
|
||||||
NTSTATUS
|
*/
|
||||||
NTAPI
|
NTSTATUS
|
||||||
CsrClientCallServer(PCSR_API_MESSAGE ApiMessage,
|
NTAPI
|
||||||
PCSR_CAPTURE_BUFFER CaptureBuffer OPTIONAL,
|
CsrClientCallServer(PCSR_API_MESSAGE ApiMessage,
|
||||||
CSR_API_NUMBER ApiNumber,
|
PCSR_CAPTURE_BUFFER CaptureBuffer OPTIONAL,
|
||||||
ULONG RequestLength)
|
CSR_API_NUMBER ApiNumber,
|
||||||
{
|
ULONG RequestLength)
|
||||||
NTSTATUS Status;
|
{
|
||||||
ULONG PointerCount;
|
NTSTATUS Status;
|
||||||
PULONG_PTR Pointers;
|
ULONG PointerCount;
|
||||||
ULONG_PTR CurrentPointer;
|
PULONG_PTR Pointers;
|
||||||
DPRINT("CsrClientCallServer\n");
|
ULONG_PTR CurrentPointer;
|
||||||
|
DPRINT("CsrClientCallServer\n");
|
||||||
/* Fill out the Port Message Header */
|
|
||||||
ApiMessage->Header.u1.s1.DataLength = RequestLength - sizeof(PORT_MESSAGE);
|
/* Fill out the Port Message Header */
|
||||||
ApiMessage->Header.u1.s1.TotalLength = RequestLength;
|
ApiMessage->Header.u1.s1.DataLength = RequestLength - sizeof(PORT_MESSAGE);
|
||||||
|
ApiMessage->Header.u1.s1.TotalLength = RequestLength;
|
||||||
/* Fill out the CSR Header */
|
|
||||||
ApiMessage->Type = ApiNumber;
|
/* Fill out the CSR Header */
|
||||||
//ApiMessage->Opcode = ApiNumber; <- Activate with new CSR
|
ApiMessage->Type = ApiNumber;
|
||||||
ApiMessage->CsrCaptureData = NULL;
|
//ApiMessage->Opcode = ApiNumber; <- Activate with new CSR
|
||||||
|
ApiMessage->CsrCaptureData = NULL;
|
||||||
DPRINT("API: %x, u1.s1.DataLength: %x, u1.s1.TotalLength: %x\n",
|
|
||||||
ApiNumber,
|
DPRINT("API: %x, u1.s1.DataLength: %x, u1.s1.TotalLength: %x\n",
|
||||||
ApiMessage->Header.u1.s1.DataLength,
|
ApiNumber,
|
||||||
ApiMessage->Header.u1.s1.TotalLength);
|
ApiMessage->Header.u1.s1.DataLength,
|
||||||
|
ApiMessage->Header.u1.s1.TotalLength);
|
||||||
/* Check if we are already inside a CSR Server */
|
|
||||||
if (!InsideCsrProcess)
|
/* Check if we are already inside a CSR Server */
|
||||||
{
|
if (!InsideCsrProcess)
|
||||||
/* Check if we got a a Capture Buffer */
|
{
|
||||||
if (CaptureBuffer)
|
/* Check if we got a a Capture Buffer */
|
||||||
{
|
if (CaptureBuffer)
|
||||||
/* We have to convert from our local view to the remote view */
|
{
|
||||||
DPRINT1("Converting CaptureBuffer\n");
|
/* We have to convert from our local view to the remote view */
|
||||||
ApiMessage->CsrCaptureData = (PVOID)((ULONG_PTR)CaptureBuffer +
|
DPRINT1("Converting CaptureBuffer\n");
|
||||||
CsrPortMemoryDelta);
|
ApiMessage->CsrCaptureData = (PVOID)((ULONG_PTR)CaptureBuffer +
|
||||||
|
CsrPortMemoryDelta);
|
||||||
/* Lock the buffer */
|
|
||||||
CaptureBuffer->BufferEnd = 0;
|
/* Lock the buffer */
|
||||||
|
CaptureBuffer->BufferEnd = 0;
|
||||||
/* Get the pointer information */
|
|
||||||
PointerCount = CaptureBuffer->PointerCount;
|
/* Get the pointer information */
|
||||||
Pointers = CaptureBuffer->PointerArray;
|
PointerCount = CaptureBuffer->PointerCount;
|
||||||
|
Pointers = CaptureBuffer->PointerArray;
|
||||||
/* Loop through every pointer and convert it */
|
|
||||||
while (PointerCount--)
|
/* Loop through every pointer and convert it */
|
||||||
{
|
while (PointerCount--)
|
||||||
/* Get this pointer and check if it's valid */
|
{
|
||||||
if ((CurrentPointer = *Pointers++))
|
/* Get this pointer and check if it's valid */
|
||||||
{
|
if ((CurrentPointer = *Pointers++))
|
||||||
/* Update it */
|
{
|
||||||
*(PULONG_PTR)CurrentPointer += CsrPortMemoryDelta;
|
/* Update it */
|
||||||
Pointers[-1] = CurrentPointer - (ULONG_PTR)ApiMessage;
|
*(PULONG_PTR)CurrentPointer += CsrPortMemoryDelta;
|
||||||
}
|
Pointers[-1] = CurrentPointer - (ULONG_PTR)ApiMessage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/* Send the LPC Message */
|
|
||||||
Status = NtRequestWaitReplyPort(CsrApiPort,
|
/* Send the LPC Message */
|
||||||
&ApiMessage->Header,
|
Status = NtRequestWaitReplyPort(CsrApiPort,
|
||||||
&ApiMessage->Header);
|
&ApiMessage->Header,
|
||||||
|
&ApiMessage->Header);
|
||||||
/* Check if we got a a Capture Buffer */
|
|
||||||
if (CaptureBuffer)
|
/* Check if we got a a Capture Buffer */
|
||||||
{
|
if (CaptureBuffer)
|
||||||
/* We have to convert from the remote view to our remote view */
|
{
|
||||||
DPRINT1("Reconverting CaptureBuffer\n");
|
/* We have to convert from the remote view to our remote view */
|
||||||
ApiMessage->CsrCaptureData = (PVOID)((ULONG_PTR)
|
DPRINT1("Reconverting CaptureBuffer\n");
|
||||||
ApiMessage->CsrCaptureData -
|
ApiMessage->CsrCaptureData = (PVOID)((ULONG_PTR)
|
||||||
CsrPortMemoryDelta);
|
ApiMessage->CsrCaptureData -
|
||||||
|
CsrPortMemoryDelta);
|
||||||
/* Get the pointer information */
|
|
||||||
PointerCount = CaptureBuffer->PointerCount;
|
/* Get the pointer information */
|
||||||
Pointers = CaptureBuffer->PointerArray;
|
PointerCount = CaptureBuffer->PointerCount;
|
||||||
|
Pointers = CaptureBuffer->PointerArray;
|
||||||
/* Loop through every pointer and convert it */
|
|
||||||
while (PointerCount--)
|
/* Loop through every pointer and convert it */
|
||||||
{
|
while (PointerCount--)
|
||||||
/* Get this pointer and check if it's valid */
|
{
|
||||||
if ((CurrentPointer = *Pointers++))
|
/* Get this pointer and check if it's valid */
|
||||||
{
|
if ((CurrentPointer = *Pointers++))
|
||||||
/* Update it */
|
{
|
||||||
CurrentPointer += (ULONG_PTR)ApiMessage;
|
/* Update it */
|
||||||
Pointers[-1] = CurrentPointer;
|
CurrentPointer += (ULONG_PTR)ApiMessage;
|
||||||
*(PULONG_PTR)CurrentPointer -= CsrPortMemoryDelta;
|
Pointers[-1] = CurrentPointer;
|
||||||
}
|
*(PULONG_PTR)CurrentPointer -= CsrPortMemoryDelta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/* Check for success */
|
|
||||||
if (!NT_SUCCESS(Status))
|
/* Check for success */
|
||||||
{
|
if (!NT_SUCCESS(Status))
|
||||||
/* We failed. Overwrite the return value with the failure */
|
{
|
||||||
DPRINT1("LPC Failed: %lx\n", Status);
|
/* We failed. Overwrite the return value with the failure */
|
||||||
ApiMessage->Status = Status;
|
DPRINT1("LPC Failed: %lx\n", Status);
|
||||||
}
|
ApiMessage->Status = Status;
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
/* This is a server-to-server call. Save our CID and do a direct call */
|
{
|
||||||
DbgBreakPoint();
|
/* This is a server-to-server call. Save our CID and do a direct call */
|
||||||
ApiMessage->Header.ClientId = NtCurrentTeb()->Cid;
|
DbgBreakPoint();
|
||||||
Status = CsrServerApiRoutine(&ApiMessage->Header,
|
ApiMessage->Header.ClientId = NtCurrentTeb()->Cid;
|
||||||
&ApiMessage->Header);
|
Status = CsrServerApiRoutine(&ApiMessage->Header,
|
||||||
|
&ApiMessage->Header);
|
||||||
/* Check for success */
|
|
||||||
if (!NT_SUCCESS(Status))
|
/* Check for success */
|
||||||
{
|
if (!NT_SUCCESS(Status))
|
||||||
/* We failed. Overwrite the return value with the failure */
|
{
|
||||||
ApiMessage->Status = Status;
|
/* We failed. Overwrite the return value with the failure */
|
||||||
}
|
ApiMessage->Status = Status;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/* Return the CSR Result */
|
|
||||||
DPRINT("Got back: %x\n", ApiMessage->Status);
|
/* Return the CSR Result */
|
||||||
return ApiMessage->Status;
|
DPRINT("Got back: %x\n", ApiMessage->Status);
|
||||||
}
|
return ApiMessage->Status;
|
||||||
|
}
|
||||||
NTSTATUS
|
|
||||||
NTAPI
|
NTSTATUS
|
||||||
CsrConnectToServer(IN PWSTR ObjectDirectory)
|
NTAPI
|
||||||
{
|
CsrConnectToServer(IN PWSTR ObjectDirectory)
|
||||||
ULONG PortNameLength;
|
{
|
||||||
UNICODE_STRING PortName;
|
ULONG PortNameLength;
|
||||||
LARGE_INTEGER CsrSectionViewSize;
|
UNICODE_STRING PortName;
|
||||||
NTSTATUS Status;
|
LARGE_INTEGER CsrSectionViewSize;
|
||||||
HANDLE CsrSectionHandle;
|
NTSTATUS Status;
|
||||||
PORT_VIEW LpcWrite;
|
HANDLE CsrSectionHandle;
|
||||||
REMOTE_PORT_VIEW LpcRead;
|
PORT_VIEW LpcWrite;
|
||||||
SECURITY_QUALITY_OF_SERVICE SecurityQos;
|
REMOTE_PORT_VIEW LpcRead;
|
||||||
SID_IDENTIFIER_AUTHORITY NtSidAuthority = {SECURITY_NT_AUTHORITY};
|
SECURITY_QUALITY_OF_SERVICE SecurityQos;
|
||||||
PSID SystemSid = NULL;
|
SID_IDENTIFIER_AUTHORITY NtSidAuthority = {SECURITY_NT_AUTHORITY};
|
||||||
CSR_CONNECTION_INFO ConnectionInfo;
|
PSID SystemSid = NULL;
|
||||||
ULONG ConnectionInfoLength = sizeof(CSR_CONNECTION_INFO);
|
CSR_CONNECTION_INFO ConnectionInfo;
|
||||||
|
ULONG ConnectionInfoLength = sizeof(CSR_CONNECTION_INFO);
|
||||||
DPRINT("%s(%S)\n", __FUNCTION__, ObjectDirectory);
|
|
||||||
|
DPRINT("%s(%S)\n", __FUNCTION__, ObjectDirectory);
|
||||||
/* Binary compatibility with MS KERNEL32 */
|
|
||||||
if (NULL == ObjectDirectory)
|
/* Binary compatibility with MS KERNEL32 */
|
||||||
{
|
if (NULL == ObjectDirectory)
|
||||||
ObjectDirectory = L"\\Windows";
|
{
|
||||||
}
|
ObjectDirectory = L"\\Windows";
|
||||||
|
}
|
||||||
/* Calculate the total port name size */
|
|
||||||
PortNameLength = ((wcslen(ObjectDirectory) + 1) * sizeof(WCHAR)) +
|
/* Calculate the total port name size */
|
||||||
sizeof(CSR_PORT_NAME);
|
PortNameLength = ((wcslen(ObjectDirectory) + 1) * sizeof(WCHAR)) +
|
||||||
|
sizeof(CSR_PORT_NAME);
|
||||||
/* Set the port name */
|
|
||||||
PortName.Length = 0;
|
/* Set the port name */
|
||||||
PortName.MaximumLength = PortNameLength;
|
PortName.Length = 0;
|
||||||
|
PortName.MaximumLength = PortNameLength;
|
||||||
/* Allocate a buffer for it */
|
|
||||||
PortName.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, PortNameLength);
|
/* Allocate a buffer for it */
|
||||||
|
PortName.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, PortNameLength);
|
||||||
/* Create the name */
|
|
||||||
RtlAppendUnicodeToString(&PortName, ObjectDirectory );
|
/* Create the name */
|
||||||
RtlAppendUnicodeToString(&PortName, UNICODE_PATH_SEP);
|
RtlAppendUnicodeToString(&PortName, ObjectDirectory );
|
||||||
RtlAppendUnicodeToString(&PortName, CSR_PORT_NAME);
|
RtlAppendUnicodeToString(&PortName, UNICODE_PATH_SEP);
|
||||||
|
RtlAppendUnicodeToString(&PortName, CSR_PORT_NAME);
|
||||||
/* Create a section for the port memory */
|
|
||||||
CsrSectionViewSize.QuadPart = CSR_CSRSS_SECTION_SIZE;
|
/* Create a section for the port memory */
|
||||||
Status = NtCreateSection(&CsrSectionHandle,
|
CsrSectionViewSize.QuadPart = CSR_CSRSS_SECTION_SIZE;
|
||||||
SECTION_ALL_ACCESS,
|
Status = NtCreateSection(&CsrSectionHandle,
|
||||||
NULL,
|
SECTION_ALL_ACCESS,
|
||||||
&CsrSectionViewSize,
|
NULL,
|
||||||
PAGE_READWRITE,
|
&CsrSectionViewSize,
|
||||||
SEC_COMMIT,
|
PAGE_READWRITE,
|
||||||
NULL);
|
SEC_COMMIT,
|
||||||
if (!NT_SUCCESS(Status))
|
NULL);
|
||||||
{
|
if (!NT_SUCCESS(Status))
|
||||||
DPRINT1("Failure allocating CSR Section\n");
|
{
|
||||||
return Status;
|
DPRINT1("Failure allocating CSR Section\n");
|
||||||
}
|
return Status;
|
||||||
|
}
|
||||||
/* Set up the port view structures to match them with the section */
|
|
||||||
LpcWrite.Length = sizeof(PORT_VIEW);
|
/* Set up the port view structures to match them with the section */
|
||||||
LpcWrite.SectionHandle = CsrSectionHandle;
|
LpcWrite.Length = sizeof(PORT_VIEW);
|
||||||
LpcWrite.SectionOffset = 0;
|
LpcWrite.SectionHandle = CsrSectionHandle;
|
||||||
LpcWrite.ViewSize = CsrSectionViewSize.u.LowPart;
|
LpcWrite.SectionOffset = 0;
|
||||||
LpcWrite.ViewBase = 0;
|
LpcWrite.ViewSize = CsrSectionViewSize.u.LowPart;
|
||||||
LpcWrite.ViewRemoteBase = 0;
|
LpcWrite.ViewBase = 0;
|
||||||
LpcRead.Length = sizeof(REMOTE_PORT_VIEW);
|
LpcWrite.ViewRemoteBase = 0;
|
||||||
LpcRead.ViewSize = 0;
|
LpcRead.Length = sizeof(REMOTE_PORT_VIEW);
|
||||||
LpcRead.ViewBase = 0;
|
LpcRead.ViewSize = 0;
|
||||||
|
LpcRead.ViewBase = 0;
|
||||||
/* Setup the QoS */
|
|
||||||
SecurityQos.ImpersonationLevel = SecurityImpersonation;
|
/* Setup the QoS */
|
||||||
SecurityQos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
|
SecurityQos.ImpersonationLevel = SecurityImpersonation;
|
||||||
SecurityQos.EffectiveOnly = TRUE;
|
SecurityQos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
|
||||||
|
SecurityQos.EffectiveOnly = TRUE;
|
||||||
/* Setup the connection info */
|
|
||||||
ConnectionInfo.Version = 0x10000;
|
/* Setup the connection info */
|
||||||
|
ConnectionInfo.Version = 0x10000;
|
||||||
/* Create a SID for us */
|
|
||||||
Status = RtlAllocateAndInitializeSid(&NtSidAuthority,
|
/* Create a SID for us */
|
||||||
1,
|
Status = RtlAllocateAndInitializeSid(&NtSidAuthority,
|
||||||
SECURITY_LOCAL_SYSTEM_RID,
|
1,
|
||||||
0,
|
SECURITY_LOCAL_SYSTEM_RID,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
&SystemSid);
|
0,
|
||||||
|
&SystemSid);
|
||||||
/* Connect to the port */
|
|
||||||
Status = NtSecureConnectPort(&CsrApiPort,
|
/* Connect to the port */
|
||||||
&PortName,
|
Status = NtSecureConnectPort(&CsrApiPort,
|
||||||
&SecurityQos,
|
&PortName,
|
||||||
&LpcWrite,
|
&SecurityQos,
|
||||||
SystemSid,
|
&LpcWrite,
|
||||||
&LpcRead,
|
SystemSid,
|
||||||
NULL,
|
&LpcRead,
|
||||||
&ConnectionInfo,
|
NULL,
|
||||||
&ConnectionInfoLength);
|
&ConnectionInfo,
|
||||||
NtClose(CsrSectionHandle);
|
&ConnectionInfoLength);
|
||||||
if (!NT_SUCCESS(Status))
|
NtClose(CsrSectionHandle);
|
||||||
{
|
if (!NT_SUCCESS(Status))
|
||||||
/* Failure */
|
{
|
||||||
DPRINT1("Couldn't connect to CSR port\n");
|
/* Failure */
|
||||||
return Status;
|
DPRINT1("Couldn't connect to CSR port\n");
|
||||||
}
|
return Status;
|
||||||
|
}
|
||||||
/* Save the delta between the sections, for capture usage later */
|
|
||||||
CsrPortMemoryDelta = (ULONG_PTR)LpcWrite.ViewRemoteBase -
|
/* Save the delta between the sections, for capture usage later */
|
||||||
(ULONG_PTR)LpcWrite.ViewBase;
|
CsrPortMemoryDelta = (ULONG_PTR)LpcWrite.ViewRemoteBase -
|
||||||
|
(ULONG_PTR)LpcWrite.ViewBase;
|
||||||
/* Save the Process */
|
|
||||||
CsrProcessId = ConnectionInfo.ProcessId;
|
/* Save the Process */
|
||||||
|
CsrProcessId = ConnectionInfo.ProcessId;
|
||||||
/* Save CSR Section data */
|
|
||||||
NtCurrentPeb()->ReadOnlySharedMemoryBase = ConnectionInfo.SharedSectionBase;
|
/* Save CSR Section data */
|
||||||
NtCurrentPeb()->ReadOnlySharedMemoryHeap = ConnectionInfo.SharedSectionHeap;
|
NtCurrentPeb()->ReadOnlySharedMemoryBase = ConnectionInfo.SharedSectionBase;
|
||||||
NtCurrentPeb()->ReadOnlyStaticServerData = ConnectionInfo.SharedSectionData;
|
NtCurrentPeb()->ReadOnlySharedMemoryHeap = ConnectionInfo.SharedSectionHeap;
|
||||||
|
NtCurrentPeb()->ReadOnlyStaticServerData = ConnectionInfo.SharedSectionData;
|
||||||
/* Create the port heap */
|
|
||||||
CsrPortHeap = RtlCreateHeap(0,
|
/* Create the port heap */
|
||||||
LpcWrite.ViewBase,
|
CsrPortHeap = RtlCreateHeap(0,
|
||||||
LpcWrite.ViewSize,
|
LpcWrite.ViewBase,
|
||||||
PAGE_SIZE,
|
LpcWrite.ViewSize,
|
||||||
0,
|
PAGE_SIZE,
|
||||||
0);
|
0,
|
||||||
|
0);
|
||||||
/* Return success */
|
|
||||||
return STATUS_SUCCESS;
|
/* Return success */
|
||||||
}
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
/*
|
|
||||||
* @implemented
|
/*
|
||||||
*/
|
* @implemented
|
||||||
NTSTATUS
|
*/
|
||||||
NTAPI
|
NTSTATUS
|
||||||
CsrClientConnectToServer(PWSTR ObjectDirectory,
|
NTAPI
|
||||||
ULONG ServerId,
|
CsrClientConnectToServer(PWSTR ObjectDirectory,
|
||||||
PVOID ConnectionInfo,
|
ULONG ServerId,
|
||||||
PULONG ConnectionInfoSize,
|
PVOID ConnectionInfo,
|
||||||
PBOOLEAN ServerToServerCall)
|
PULONG ConnectionInfoSize,
|
||||||
{
|
PBOOLEAN ServerToServerCall)
|
||||||
NTSTATUS Status;
|
{
|
||||||
PIMAGE_NT_HEADERS NtHeader;
|
NTSTATUS Status;
|
||||||
UNICODE_STRING CsrSrvName;
|
PIMAGE_NT_HEADERS NtHeader;
|
||||||
HANDLE hCsrSrv;
|
UNICODE_STRING CsrSrvName;
|
||||||
ANSI_STRING CsrServerRoutineName;
|
HANDLE hCsrSrv;
|
||||||
PCSR_CAPTURE_BUFFER CaptureBuffer;
|
ANSI_STRING CsrServerRoutineName;
|
||||||
CSR_API_MESSAGE RosApiMessage;
|
PCSR_CAPTURE_BUFFER CaptureBuffer;
|
||||||
CSR_API_MESSAGE2 ApiMessage;
|
CSR_API_MESSAGE RosApiMessage;
|
||||||
PCSR_CLIENT_CONNECT ClientConnect = &ApiMessage.ClientConnect;
|
CSR_API_MESSAGE2 ApiMessage;
|
||||||
|
PCSR_CLIENT_CONNECT ClientConnect = &ApiMessage.ClientConnect;
|
||||||
/* Validate the Connection Info */
|
|
||||||
DPRINT("CsrClientConnectToServer: %lx %p\n", ServerId, ConnectionInfo);
|
/* Validate the Connection Info */
|
||||||
if (ConnectionInfo && (!ConnectionInfoSize || !*ConnectionInfoSize))
|
DPRINT("CsrClientConnectToServer: %lx %p\n", ServerId, ConnectionInfo);
|
||||||
{
|
if (ConnectionInfo && (!ConnectionInfoSize || !*ConnectionInfoSize))
|
||||||
DPRINT1("Connection info given, but no length\n");
|
{
|
||||||
return STATUS_INVALID_PARAMETER;
|
DPRINT1("Connection info given, but no length\n");
|
||||||
}
|
return STATUS_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
/* Check if we're inside a CSR Process */
|
|
||||||
if (InsideCsrProcess)
|
/* Check if we're inside a CSR Process */
|
||||||
{
|
if (InsideCsrProcess)
|
||||||
/* Tell the client that we're already inside CSR */
|
{
|
||||||
if (ServerToServerCall) *ServerToServerCall = TRUE;
|
/* Tell the client that we're already inside CSR */
|
||||||
return STATUS_SUCCESS;
|
if (ServerToServerCall) *ServerToServerCall = TRUE;
|
||||||
}
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
/*
|
|
||||||
* We might be in a CSR Process but not know it, if this is the first call.
|
/*
|
||||||
* So let's find out.
|
* We might be in a CSR Process but not know it, if this is the first call.
|
||||||
*/
|
* So let's find out.
|
||||||
if (!(NtHeader = RtlImageNtHeader(NtCurrentPeb()->ImageBaseAddress)))
|
*/
|
||||||
{
|
if (!(NtHeader = RtlImageNtHeader(NtCurrentPeb()->ImageBaseAddress)))
|
||||||
/* The image isn't valid */
|
{
|
||||||
DPRINT1("Invalid image\n");
|
/* The image isn't valid */
|
||||||
return STATUS_INVALID_IMAGE_FORMAT;
|
DPRINT1("Invalid image\n");
|
||||||
}
|
return STATUS_INVALID_IMAGE_FORMAT;
|
||||||
InsideCsrProcess = (NtHeader->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_NATIVE);
|
}
|
||||||
|
InsideCsrProcess = (NtHeader->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_NATIVE);
|
||||||
/* Now we can check if we are inside or not */
|
|
||||||
if (InsideCsrProcess && !UsingOldCsr)
|
/* Now we can check if we are inside or not */
|
||||||
{
|
if (InsideCsrProcess && !UsingOldCsr)
|
||||||
/* We're inside, so let's find csrsrv */
|
{
|
||||||
DbgBreakPoint();
|
/* We're inside, so let's find csrsrv */
|
||||||
RtlInitUnicodeString(&CsrSrvName, L"csrsrv");
|
DbgBreakPoint();
|
||||||
Status = LdrGetDllHandle(NULL,
|
RtlInitUnicodeString(&CsrSrvName, L"csrsrv");
|
||||||
NULL,
|
Status = LdrGetDllHandle(NULL,
|
||||||
&CsrSrvName,
|
NULL,
|
||||||
&hCsrSrv);
|
&CsrSrvName,
|
||||||
RtlFreeUnicodeString(&CsrSrvName);
|
&hCsrSrv);
|
||||||
|
RtlFreeUnicodeString(&CsrSrvName);
|
||||||
/* Now get the Server to Server routine */
|
|
||||||
RtlInitAnsiString(&CsrServerRoutineName, "CsrCallServerFromServer");
|
/* Now get the Server to Server routine */
|
||||||
Status = LdrGetProcedureAddress(hCsrSrv,
|
RtlInitAnsiString(&CsrServerRoutineName, "CsrCallServerFromServer");
|
||||||
&CsrServerRoutineName,
|
Status = LdrGetProcedureAddress(hCsrSrv,
|
||||||
0L,
|
&CsrServerRoutineName,
|
||||||
(PVOID*)&CsrServerApiRoutine);
|
0L,
|
||||||
|
(PVOID*)&CsrServerApiRoutine);
|
||||||
/* Use the local heap as port heap */
|
|
||||||
CsrPortHeap = RtlGetProcessHeap();
|
/* Use the local heap as port heap */
|
||||||
|
CsrPortHeap = RtlGetProcessHeap();
|
||||||
/* Tell the caller we're inside the server */
|
|
||||||
*ServerToServerCall = InsideCsrProcess;
|
/* Tell the caller we're inside the server */
|
||||||
return STATUS_SUCCESS;
|
*ServerToServerCall = InsideCsrProcess;
|
||||||
}
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
/* Now check if connection info is given */
|
|
||||||
if (ConnectionInfo)
|
/* Now check if connection info is given */
|
||||||
{
|
if (ConnectionInfo)
|
||||||
/* Well, we're defintely in a client now */
|
{
|
||||||
InsideCsrProcess = FALSE;
|
/* Well, we're defintely in a client now */
|
||||||
|
InsideCsrProcess = FALSE;
|
||||||
/* Do we have a connection to CSR yet? */
|
|
||||||
if (!CsrApiPort)
|
/* Do we have a connection to CSR yet? */
|
||||||
{
|
if (!CsrApiPort)
|
||||||
/* No, set it up now */
|
{
|
||||||
if (!NT_SUCCESS(Status = CsrConnectToServer(ObjectDirectory)))
|
/* No, set it up now */
|
||||||
{
|
if (!NT_SUCCESS(Status = CsrConnectToServer(ObjectDirectory)))
|
||||||
/* Failed */
|
{
|
||||||
DPRINT1("Failure to connect to CSR\n");
|
/* Failed */
|
||||||
return Status;
|
DPRINT1("Failure to connect to CSR\n");
|
||||||
}
|
return Status;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/* Setup the connect message header */
|
|
||||||
ClientConnect->ServerId = ServerId;
|
/* Setup the connect message header */
|
||||||
ClientConnect->ConnectionInfoSize = *ConnectionInfoSize;
|
ClientConnect->ServerId = ServerId;
|
||||||
|
ClientConnect->ConnectionInfoSize = *ConnectionInfoSize;
|
||||||
/* Setup a buffer for the connection info */
|
|
||||||
CaptureBuffer = CsrAllocateCaptureBuffer(1,
|
/* Setup a buffer for the connection info */
|
||||||
ClientConnect->ConnectionInfoSize);
|
CaptureBuffer = CsrAllocateCaptureBuffer(1,
|
||||||
|
ClientConnect->ConnectionInfoSize);
|
||||||
/* Allocate a pointer for the connection info*/
|
|
||||||
CsrAllocateMessagePointer(CaptureBuffer,
|
/* Allocate a pointer for the connection info*/
|
||||||
ClientConnect->ConnectionInfoSize,
|
CsrAllocateMessagePointer(CaptureBuffer,
|
||||||
&ClientConnect->ConnectionInfo);
|
ClientConnect->ConnectionInfoSize,
|
||||||
|
&ClientConnect->ConnectionInfo);
|
||||||
/* Copy the data into the buffer */
|
|
||||||
RtlMoveMemory(ClientConnect->ConnectionInfo,
|
/* Copy the data into the buffer */
|
||||||
ConnectionInfo,
|
RtlMoveMemory(ClientConnect->ConnectionInfo,
|
||||||
ClientConnect->ConnectionInfoSize);
|
ConnectionInfo,
|
||||||
|
ClientConnect->ConnectionInfoSize);
|
||||||
/* Return the allocated length */
|
|
||||||
*ConnectionInfoSize = ClientConnect->ConnectionInfoSize;
|
/* Return the allocated length */
|
||||||
|
*ConnectionInfoSize = ClientConnect->ConnectionInfoSize;
|
||||||
/* Call CSR */
|
|
||||||
#if 0
|
/* Call CSR */
|
||||||
Status = CsrClientCallServer(&ApiMessage,
|
#if 0
|
||||||
CaptureBuffer,
|
Status = CsrClientCallServer(&ApiMessage,
|
||||||
CSR_MAKE_OPCODE(CsrSrvClientConnect,
|
CaptureBuffer,
|
||||||
CSR_SRV_DLL),
|
CSR_MAKE_OPCODE(CsrSrvClientConnect,
|
||||||
sizeof(CSR_CLIENT_CONNECT));
|
CSR_SRV_DLL),
|
||||||
#endif
|
sizeof(CSR_CLIENT_CONNECT));
|
||||||
Status = CsrClientCallServer(&RosApiMessage,
|
#endif
|
||||||
NULL,
|
Status = CsrClientCallServer(&RosApiMessage,
|
||||||
MAKE_CSR_API(CONNECT_PROCESS, CSR_NATIVE),
|
NULL,
|
||||||
sizeof(CSR_API_MESSAGE));
|
MAKE_CSR_API(CONNECT_PROCESS, CSR_NATIVE),
|
||||||
}
|
sizeof(CSR_API_MESSAGE));
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
/* No connection info, just return */
|
{
|
||||||
Status = STATUS_SUCCESS;
|
/* No connection info, just return */
|
||||||
}
|
Status = STATUS_SUCCESS;
|
||||||
|
}
|
||||||
/* Let the caller know if this was server to server */
|
|
||||||
DPRINT("Status was: %lx. Are we in server: %lx\n", Status, InsideCsrProcess);
|
/* Let the caller know if this was server to server */
|
||||||
if (ServerToServerCall) *ServerToServerCall = InsideCsrProcess;
|
DPRINT("Status was: %lx. Are we in server: %lx\n", Status, InsideCsrProcess);
|
||||||
return Status;
|
if (ServerToServerCall) *ServerToServerCall = InsideCsrProcess;
|
||||||
}
|
return Status;
|
||||||
|
}
|
||||||
/* EOF */
|
|
||||||
|
/* EOF */
|
||||||
|
|
Loading…
Reference in a new issue