extern UNICODE_STRING SystemDirectory;
extern UNICODE_STRING WindowsDirectory;
-
PBASE_STATIC_SERVER_DATA BaseStaticServerData;
BOOLEAN BaseRunningInServerProcess;
return TRUE;
}
-VOID
-WINAPI
-BasepFakeStaticServerData(VOID)
-{
- NTSTATUS Status;
- WCHAR Buffer[MAX_PATH];
- UNICODE_STRING SystemRootString;
- UNICODE_STRING UnexpandedSystemRootString = RTL_CONSTANT_STRING(L"%SystemRoot%");
- UNICODE_STRING BaseSrvCSDString;
- RTL_QUERY_REGISTRY_TABLE BaseServerRegistryConfigurationTable[2] =
- {
- {
- NULL,
- RTL_QUERY_REGISTRY_DIRECT,
- L"CSDVersion",
- &BaseSrvCSDString
- },
- {0}
- };
-
- /* Allocate the fake data */
- BaseStaticServerData = RtlAllocateHeap(RtlGetProcessHeap(),
- HEAP_ZERO_MEMORY,
- sizeof(BASE_STATIC_SERVER_DATA));
- ASSERT(BaseStaticServerData != NULL);
-
- /* Get the Windows directory */
- RtlInitEmptyUnicodeString(&SystemRootString, Buffer, sizeof(Buffer));
- Status = RtlExpandEnvironmentStrings_U(NULL,
- &UnexpandedSystemRootString,
- &SystemRootString,
- NULL);
- DPRINT1("Status: %lx. Root: %wZ\n", Status, &SystemRootString);
- ASSERT(NT_SUCCESS(Status));
-
- Buffer[SystemRootString.Length / sizeof(WCHAR)] = UNICODE_NULL;
- Status = RtlCreateUnicodeString(&BaseStaticServerData->WindowsDirectory,
- SystemRootString.Buffer);
- ASSERT(NT_SUCCESS(Status));
-
- wcscat(SystemRootString.Buffer, L"\\system32");
- Status = RtlCreateUnicodeString(&BaseStaticServerData->WindowsSystemDirectory,
- SystemRootString.Buffer);
- ASSERT(NT_SUCCESS(Status));
-
- if (!SessionId)
- {
- Status = RtlCreateUnicodeString(&BaseStaticServerData->NamedObjectDirectory,
- L"\\BaseNamedObjects");
- ASSERT(NT_SUCCESS(Status));
- }
- else
- {
- /* Hopefully we'll fix CSRSS Before we add multiple sessions... */
- ASSERT(FALSE);
- }
-
- /*
- * Confirmed that in Windows, CSDNumber and RCNumber are actually Length
- * and MaximumLength of the CSD String, since the same UNICODE_STRING is
- * being queried twice, the first time as a ULONG!
- *
- * Somehow, in Windows this doesn't cause a buffer overflow, but it might
- * in ReactOS, so this code is disabled until someone figures out WTF.
- */
- BaseStaticServerData->CSDNumber = 0;
- BaseStaticServerData->RCNumber = 0;
-
- /* Initialize the CSD string */
- RtlInitEmptyUnicodeString(&BaseSrvCSDString, Buffer, sizeof(Buffer));
-
- Status = RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT,
- L"",
- BaseServerRegistryConfigurationTable,
- NULL,
- NULL);
- if (NT_SUCCESS(Status))
- {
- wcsncpy(BaseStaticServerData->CSDVersion,
- BaseSrvCSDString.Buffer,
- BaseSrvCSDString.Length / sizeof(WCHAR));
- }
- else
- {
- BaseStaticServerData->CSDVersion[0] = UNICODE_NULL;
- }
-
- Status = NtQuerySystemInformation(SystemBasicInformation,
- &BaseStaticServerData->SysInfo,
- sizeof(BaseStaticServerData->SysInfo),
- NULL);
- ASSERT(NT_SUCCESS(Status));
-
- BaseStaticServerData->DefaultSeparateVDM = FALSE;
- BaseStaticServerData->IsWowTaskReady = FALSE;
- BaseStaticServerData->LUIDDeviceMapsEnabled = FALSE;
- BaseStaticServerData->TermsrvClientTimeZoneId = TIME_ZONE_ID_INVALID;
- BaseStaticServerData->TermsrvClientTimeZoneChangeNum = 0;
-
- Status = NtQuerySystemInformation(SystemTimeOfDayInformation,
- &BaseStaticServerData->TimeOfDay,
- sizeof(BaseStaticServerData->TimeOfDay),
- NULL);
- ASSERT(NT_SUCCESS(Status));
-}
-
BOOL
WINAPI
DllMain(HANDLE hDll,
}
/* Get the server data */
- if (!Peb->ReadOnlyStaticServerData)
- {
- /* Build fake one for ReactOS */
- BasepFakeStaticServerData();
-
- /* Allocate the array */
- Peb->ReadOnlyStaticServerData = RtlAllocateHeap(RtlGetProcessHeap(),
- HEAP_ZERO_MEMORY,
- 4 * sizeof(PVOID));
-
- /* Set the data for the BASESRV DLL Index */
- Peb->ReadOnlyStaticServerData[CSR_CONSOLE] = BaseStaticServerData;
- }
-
- /* Get the server data */
+ ASSERT(Peb->ReadOnlyStaticServerData);
BaseStaticServerData = Peb->ReadOnlyStaticServerData[CSR_CONSOLE];
ASSERT(BaseStaticServerData);
(VOID)CallHardError(ProcessData, Message);
}
+PVOID CsrSrvSharedSectionHeap;
+PVOID CsrSrvSharedSectionBase;
+PVOID *CsrSrvSharedStaticServerData;
+ULONG CsrSrvSharedSectionSize;
+HANDLE CsrSrvSharedSection;
+
+/*++
+ * @name CsrSrvCreateSharedSection
+ *
+ * The CsrSrvCreateSharedSection creates the Shared Section that all CSR Server
+ * DLLs and Clients can use to share data.
+ *
+ * @param ParameterValue
+ * Specially formatted string from our registry command-line which
+ * specifies various arguments for the shared section.
+ *
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
+ * othwerwise.
+ *
+ * @remarks None.
+ *
+ *--*/
+NTSTATUS
+NTAPI
+CsrSrvCreateSharedSection(IN PCHAR ParameterValue)
+{
+ PCHAR SizeValue = ParameterValue;
+ ULONG Size;
+ NTSTATUS Status;
+ LARGE_INTEGER SectionSize;
+ ULONG ViewSize = 0;
+ SYSTEM_BASIC_INFORMATION CsrNtSysInfo;
+ PPEB Peb = NtCurrentPeb();
+
+ /* ReactOS Hackssss */
+ ParameterValue = "1024,3072,512";
+ Status = NtQuerySystemInformation(SystemBasicInformation,
+ &CsrNtSysInfo,
+ sizeof(SYSTEM_BASIC_INFORMATION),
+ NULL);
+ ASSERT(NT_SUCCESS(Status));
+
+ /* Find the first comma, and null terminate */
+ while (*SizeValue)
+ {
+ if (*SizeValue == ',')
+ {
+ *SizeValue++ = '\0';
+ break;
+ }
+ else
+ {
+ SizeValue++;
+ }
+ }
+
+ /* Make sure it's valid */
+ if (!*SizeValue) return(STATUS_INVALID_PARAMETER);
+
+ /* Convert it to an integer */
+ Status = RtlCharToInteger(SizeValue, 0, &Size);
+ if (!NT_SUCCESS(Status)) return Status;
+
+ /* Multiply by 1024 entries and round to page size */
+ #define ROUND_UP(n,size) (((ULONG)(n) + (size - 1)) & ~(size - 1)) // hax
+ CsrSrvSharedSectionSize = ROUND_UP(Size * 1024, CsrNtSysInfo.PageSize);
+
+ /* Create the Secion */
+ SectionSize.LowPart = CsrSrvSharedSectionSize;
+ SectionSize.HighPart = 0;
+ Status = NtCreateSection(&CsrSrvSharedSection,
+ SECTION_ALL_ACCESS,
+ NULL,
+ &SectionSize,
+ PAGE_EXECUTE_READWRITE,
+ SEC_BASED | SEC_RESERVE,
+ NULL);
+ if (!NT_SUCCESS(Status)) return Status;
+
+ /* Map the section */
+ Status = NtMapViewOfSection(CsrSrvSharedSection,
+ NtCurrentProcess(),
+ &CsrSrvSharedSectionBase,
+ 0,
+ 0,
+ NULL,
+ &ViewSize,
+ ViewUnmap,
+ MEM_TOP_DOWN,
+ PAGE_EXECUTE_READWRITE);
+ if(!NT_SUCCESS(Status))
+ {
+ /* Fail */
+ NtClose(CsrSrvSharedSection);
+ return(Status);
+ }
+
+ /* FIXME: Write the value to registry */
+
+ /* The Heap is the same place as the Base */
+ CsrSrvSharedSectionHeap = CsrSrvSharedSectionBase;
+
+ /* Create the heap */
+ if (!(RtlCreateHeap(HEAP_ZERO_MEMORY,
+ CsrSrvSharedSectionHeap,
+ CsrSrvSharedSectionSize,
+ PAGE_SIZE,
+ 0,
+ 0)))
+ {
+ /* Failure, unmap section and return */
+ NtUnmapViewOfSection(NtCurrentProcess(),
+ CsrSrvSharedSectionBase);
+ NtClose(CsrSrvSharedSection);
+ return STATUS_NO_MEMORY;
+ }
+
+ /* Now allocate space from the heap for the Shared Data */
+ CsrSrvSharedStaticServerData = RtlAllocateHeap(CsrSrvSharedSectionHeap,
+ 0,
+ 4 * // HAX CSR_SERVER_DLL_MAX *
+ sizeof(PVOID));
+
+ /* Write the values to the PEB */
+ Peb->ReadOnlySharedMemoryBase = CsrSrvSharedSectionBase;
+ Peb->ReadOnlySharedMemoryHeap = CsrSrvSharedSectionHeap;
+ Peb->ReadOnlyStaticServerData = CsrSrvSharedStaticServerData;
+
+ /* Return */
+ return STATUS_SUCCESS;
+}
+
+/*++
+ * @name CsrSrvAttachSharedSection
+ *
+ * The CsrSrvAttachSharedSection maps the CSR Shared Section into a new
+ * CSR Process' address space, and returns the pointers to the section
+ * through the Connection Info structure.
+ *
+ * @param CsrProcess
+ * Pointer to the CSR Process that is attempting a connection.
+ *
+ * @param ConnectInfo
+ * Pointer to the CSR Connection Info structure for the incoming
+ * connection.
+ *
+ * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
+ * othwerwise.
+ *
+ * @remarks None.
+ *
+ *--*/
+NTSTATUS
+NTAPI
+CsrSrvAttachSharedSection(IN PCSRSS_PROCESS_DATA CsrProcess OPTIONAL,
+ OUT PCSR_CONNECTION_INFO ConnectInfo)
+{
+ NTSTATUS Status;
+ ULONG ViewSize = 0;
+
+ /* Check if we have a process */
+ if (CsrProcess)
+ {
+ /* Map the sectio into this process */
+ Status = NtMapViewOfSection(CsrSrvSharedSection,
+ CsrProcess->Process,
+ &CsrSrvSharedSectionBase,
+ 0,
+ 0,
+ NULL,
+ &ViewSize,
+ ViewUnmap,
+ SEC_NO_CHANGE,
+ PAGE_EXECUTE_READ);
+ if (!NT_SUCCESS(Status)) return Status;
+ }
+
+ /* Write the values in the Connection Info structure */
+ ConnectInfo->SharedSectionBase = CsrSrvSharedSectionBase;
+ ConnectInfo->SharedSectionHeap = CsrSrvSharedSectionHeap;
+ ConnectInfo->SharedSectionData = CsrSrvSharedStaticServerData;
+
+ /* Return success */
+ return STATUS_SUCCESS;
+}
+
+PBASE_STATIC_SERVER_DATA BaseStaticServerData;
+
+VOID
+WINAPI
+BasepFakeStaticServerData(VOID)
+{
+ NTSTATUS Status;
+ WCHAR Buffer[MAX_PATH];
+ UNICODE_STRING SystemRootString;
+ UNICODE_STRING UnexpandedSystemRootString = RTL_CONSTANT_STRING(L"%SystemRoot%");
+ UNICODE_STRING BaseSrvCSDString;
+ RTL_QUERY_REGISTRY_TABLE BaseServerRegistryConfigurationTable[2] =
+ {
+ {
+ NULL,
+ RTL_QUERY_REGISTRY_DIRECT,
+ L"CSDVersion",
+ &BaseSrvCSDString
+ },
+ {0}
+ };
+
+ /* Allocate the fake data */
+ BaseStaticServerData = RtlAllocateHeap(RtlGetProcessHeap(),
+ HEAP_ZERO_MEMORY,
+ sizeof(BASE_STATIC_SERVER_DATA));
+ ASSERT(BaseStaticServerData != NULL);
+
+ /* Get the Windows directory */
+ RtlInitEmptyUnicodeString(&SystemRootString, Buffer, sizeof(Buffer));
+ Status = RtlExpandEnvironmentStrings_U(NULL,
+ &UnexpandedSystemRootString,
+ &SystemRootString,
+ NULL);
+ DPRINT1("Status: %lx. Root: %wZ\n", Status, &SystemRootString);
+ ASSERT(NT_SUCCESS(Status));
+
+ Buffer[SystemRootString.Length / sizeof(WCHAR)] = UNICODE_NULL;
+ Status = RtlCreateUnicodeString(&BaseStaticServerData->WindowsDirectory,
+ SystemRootString.Buffer);
+ ASSERT(NT_SUCCESS(Status));
+
+ wcscat(SystemRootString.Buffer, L"\\system32");
+ Status = RtlCreateUnicodeString(&BaseStaticServerData->WindowsSystemDirectory,
+ SystemRootString.Buffer);
+ ASSERT(NT_SUCCESS(Status));
+
+ Status = RtlCreateUnicodeString(&BaseStaticServerData->NamedObjectDirectory,
+ L"\\BaseNamedObjects");
+ ASSERT(NT_SUCCESS(Status));
+
+ /*
+ * Confirmed that in Windows, CSDNumber and RCNumber are actually Length
+ * and MaximumLength of the CSD String, since the same UNICODE_STRING is
+ * being queried twice, the first time as a ULONG!
+ *
+ * Somehow, in Windows this doesn't cause a buffer overflow, but it might
+ * in ReactOS, so this code is disabled until someone figures out WTF.
+ */
+ BaseStaticServerData->CSDNumber = 0;
+ BaseStaticServerData->RCNumber = 0;
+
+ /* Initialize the CSD string */
+ RtlInitEmptyUnicodeString(&BaseSrvCSDString, Buffer, sizeof(Buffer));
+
+ Status = RtlQueryRegistryValues(RTL_REGISTRY_WINDOWS_NT,
+ L"",
+ BaseServerRegistryConfigurationTable,
+ NULL,
+ NULL);
+ if (NT_SUCCESS(Status))
+ {
+ wcsncpy(BaseStaticServerData->CSDVersion,
+ BaseSrvCSDString.Buffer,
+ BaseSrvCSDString.Length / sizeof(WCHAR));
+ }
+ else
+ {
+ BaseStaticServerData->CSDVersion[0] = UNICODE_NULL;
+ }
+
+ Status = NtQuerySystemInformation(SystemBasicInformation,
+ &BaseStaticServerData->SysInfo,
+ sizeof(BaseStaticServerData->SysInfo),
+ NULL);
+ ASSERT(NT_SUCCESS(Status));
+
+ BaseStaticServerData->DefaultSeparateVDM = FALSE;
+ BaseStaticServerData->IsWowTaskReady = FALSE;
+ BaseStaticServerData->LUIDDeviceMapsEnabled = FALSE;
+ BaseStaticServerData->TermsrvClientTimeZoneId = TIME_ZONE_ID_INVALID;
+ BaseStaticServerData->TermsrvClientTimeZoneChangeNum = 0;
+
+ Status = NtQuerySystemInformation(SystemTimeOfDayInformation,
+ &BaseStaticServerData->TimeOfDay,
+ sizeof(BaseStaticServerData->TimeOfDay),
+ NULL);
+ ASSERT(NT_SUCCESS(Status));
+
+ CsrSrvSharedStaticServerData[CSR_CONSOLE] = BaseStaticServerData;
+}
+
NTSTATUS WINAPI
CsrpHandleConnectionRequest (PPORT_MESSAGE Request,
IN HANDLE hApiListenPort)
PCSRSS_PROCESS_DATA ProcessData = NULL;
REMOTE_PORT_VIEW LpcRead;
CLIENT_ID ClientId;
+ BOOLEAN AllowConnection = FALSE;
PCSR_CONNECTION_INFO ConnectInfo;
LpcRead.Length = sizeof(LpcRead);
ServerPort = NULL;
DPRINT("CSR: %s: Handling: %p\n", __FUNCTION__, Request);
ConnectInfo = (PCSR_CONNECTION_INFO)(Request + 1);
- DPRINT1("CSR Connect Info: %p\n", ConnectInfo);
/* Save the process ID */
RtlZeroMemory(ConnectInfo, sizeof(CSR_CONNECTION_INFO));
ConnectInfo->ProcessId = NtCurrentTeb()->ClientId.UniqueProcess;
- Status = NtAcceptConnectPort(&ServerPort,
- NULL,
- Request,
- TRUE,
- 0,
- & LpcRead);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("CSR: NtAcceptConnectPort() failed\n");
- return Status;
- }
-
ProcessData = CsrGetProcessData(Request->ClientId.UniqueProcess);
if (ProcessData == NULL)
{
{
DPRINT1("Unable to allocate or find data for process 0x%x\n",
Request->ClientId.UniqueProcess);
- Status = STATUS_UNSUCCESSFUL;
- return Status;
}
+ else
+ {
+ /* Attach the Shared Section */
+ Status = CsrSrvAttachSharedSection(ProcessData, ConnectInfo);
+ if (NT_SUCCESS(Status)) AllowConnection = TRUE;
+ }
+ }
+
+ Status = NtAcceptConnectPort(&ServerPort,
+ NULL,
+ Request,
+ AllowConnection,
+ 0,
+ & LpcRead);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("CSR: NtAcceptConnectPort() failed\n");
+ return Status;
}
ProcessData->CsrSectionViewBase = LpcRead.ViewBase;
ProcessData->CsrSectionViewSize = LpcRead.ViewSize;
ProcessData->ServerCommunicationPort = ServerPort;
- Status = NtCompleteConnectPort(ServerPort);
+ if (AllowConnection) Status = NtCompleteConnectPort(ServerPort);
if (!NT_SUCCESS(Status))
{
DPRINT1("CSR: NtCompleteConnectPort() failed\n");