Author: ion Date: Wed Aug 3 03:09:02 2011 New Revision: 53040
URL: http://svn.reactos.org/svn/reactos?rev=53040&view=rev Log: [CSRSRV/KERNEL32]: Have CSRSS create a proper shared section (Based on code taken from the CSRSS rewrite in trunk) and attach it to every client. [CSRSRV/KERNEL32]: Have CSRSS fill out the base server static data. Still a bit of a hack since we should have a basesrv to do this, but it'll fix the "can't install any drivers" bug as well as increase performance since we now cache a bunch of data system-wide. [KERNEL32]: Remove all related hacks in kernel32. [CSRSRV]: Only accept the incoming connection if we found CSR process data about it.
Modified: trunk/reactos/dll/win32/kernel32/client/dllmain.c trunk/reactos/dll/win32/kernel32/include/kernel32.h trunk/reactos/include/reactos/subsys/csrss/csrss.h trunk/reactos/subsystems/win32/csrss/csrsrv/api/wapi.c
Modified: trunk/reactos/dll/win32/kernel32/client/dllmain.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/d... ============================================================================== --- trunk/reactos/dll/win32/kernel32/client/dllmain.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/kernel32/client/dllmain.c [iso-8859-1] Wed Aug 3 03:09:02 2011 @@ -21,7 +21,6 @@
extern UNICODE_STRING SystemDirectory; extern UNICODE_STRING WindowsDirectory; -
PBASE_STATIC_SERVER_DATA BaseStaticServerData;
@@ -250,112 +249,6 @@ 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, @@ -417,21 +310,7 @@ }
/* 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);
Modified: trunk/reactos/dll/win32/kernel32/include/kernel32.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/include/... ============================================================================== --- trunk/reactos/dll/win32/kernel32/include/kernel32.h [iso-8859-1] (original) +++ trunk/reactos/dll/win32/kernel32/include/kernel32.h [iso-8859-1] Wed Aug 3 03:09:02 2011 @@ -80,73 +80,6 @@ CPTABLEINFO CodePageTable; } CODEPAGE_ENTRY, *PCODEPAGE_ENTRY;
-typedef struct _NLS_USER_INFO -{ - WCHAR iCountry[80]; - WCHAR sCountry[80]; - WCHAR sList[80]; - WCHAR iMeasure[80]; - WCHAR iPaperSize[80]; - WCHAR sDecimal[80]; - WCHAR sThousand[80]; - WCHAR sGrouping[80]; - WCHAR iDigits[80]; - WCHAR iLZero[80]; - WCHAR iNegNumber[80]; - WCHAR sNativeDigits[80]; - WCHAR iDigitSubstitution[80]; - WCHAR sCurrency[80]; - WCHAR sMonDecSep[80]; - WCHAR sMonThouSep[80]; - WCHAR sMonGrouping[80]; - WCHAR iCurrDigits[80]; - WCHAR iCurrency[80]; - WCHAR iNegCurr[80]; - WCHAR sPosSign[80]; - WCHAR sNegSign[80]; - WCHAR sTimeFormat[80]; - WCHAR s1159[80]; - WCHAR s2359[80]; - WCHAR sShortDate[80]; - WCHAR sYearMonth[80]; - WCHAR sLongDate[80]; - WCHAR iCalType[80]; - WCHAR iFirstDay[80]; - WCHAR iFirstWeek[80]; - WCHAR sLocale[80]; - WCHAR sLocaleName[85]; - LCID UserLocaleId; - LUID InteractiveUserLuid; - CHAR InteractiveUserSid[SECURITY_MAX_SID_SIZE]; - ULONG ulCacheUpdateCount; -} NLS_USER_INFO, *PNLS_USER_INFO; - -typedef struct _BASE_STATIC_SERVER_DATA -{ - UNICODE_STRING WindowsDirectory; - UNICODE_STRING WindowsSystemDirectory; - UNICODE_STRING NamedObjectDirectory; - USHORT WindowsMajorVersion; - USHORT WindowsMinorVersion; - USHORT BuildNumber; - USHORT CSDNumber; - USHORT RCNumber; - WCHAR CSDVersion[128]; - SYSTEM_BASIC_INFORMATION SysInfo; - SYSTEM_TIMEOFDAY_INFORMATION TimeOfDay; - PVOID IniFileMapping; - NLS_USER_INFO NlsUserInfo; - BOOLEAN DefaultSeparateVDM; - BOOLEAN IsWowTaskReady; - UNICODE_STRING WindowsSys32x86Directory; - BOOLEAN fTermsrvAppInstallMode; - TIME_ZONE_INFORMATION tziTermsrvClientTimeZone; - KSYSTEM_TIME ktTermsrvClientBias; - ULONG TermsrvClientTimeZoneId; - BOOLEAN LUIDDeviceMapsEnabled; - ULONG TermsrvClientTimeZoneChangeNum; -} BASE_STATIC_SERVER_DATA, *PBASE_STATIC_SERVER_DATA; - extern PBASE_STATIC_SERVER_DATA BaseStaticServerData;
typedef
Modified: trunk/reactos/include/reactos/subsys/csrss/csrss.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/include/reactos/subsys/csrs... ============================================================================== --- trunk/reactos/include/reactos/subsys/csrss/csrss.h [iso-8859-1] (original) +++ trunk/reactos/include/reactos/subsys/csrss/csrss.h [iso-8859-1] Wed Aug 3 03:09:02 2011 @@ -692,6 +692,76 @@ } Data; } CSR_API_MESSAGE, *PCSR_API_MESSAGE;
+ +typedef struct _NLS_USER_INFO +{ + WCHAR iCountry[80]; + WCHAR sCountry[80]; + WCHAR sList[80]; + WCHAR iMeasure[80]; + WCHAR iPaperSize[80]; + WCHAR sDecimal[80]; + WCHAR sThousand[80]; + WCHAR sGrouping[80]; + WCHAR iDigits[80]; + WCHAR iLZero[80]; + WCHAR iNegNumber[80]; + WCHAR sNativeDigits[80]; + WCHAR iDigitSubstitution[80]; + WCHAR sCurrency[80]; + WCHAR sMonDecSep[80]; + WCHAR sMonThouSep[80]; + WCHAR sMonGrouping[80]; + WCHAR iCurrDigits[80]; + WCHAR iCurrency[80]; + WCHAR iNegCurr[80]; + WCHAR sPosSign[80]; + WCHAR sNegSign[80]; + WCHAR sTimeFormat[80]; + WCHAR s1159[80]; + WCHAR s2359[80]; + WCHAR sShortDate[80]; + WCHAR sYearMonth[80]; + WCHAR sLongDate[80]; + WCHAR iCalType[80]; + WCHAR iFirstDay[80]; + WCHAR iFirstWeek[80]; + WCHAR sLocale[80]; + WCHAR sLocaleName[85]; + LCID UserLocaleId; + LUID InteractiveUserLuid; + CHAR InteractiveUserSid[SECURITY_MAX_SID_SIZE]; + ULONG ulCacheUpdateCount; +} NLS_USER_INFO, *PNLS_USER_INFO; + + +typedef struct _BASE_STATIC_SERVER_DATA +{ + UNICODE_STRING WindowsDirectory; + UNICODE_STRING WindowsSystemDirectory; + UNICODE_STRING NamedObjectDirectory; + USHORT WindowsMajorVersion; + USHORT WindowsMinorVersion; + USHORT BuildNumber; + USHORT CSDNumber; + USHORT RCNumber; + WCHAR CSDVersion[128]; + SYSTEM_BASIC_INFORMATION SysInfo; + SYSTEM_TIMEOFDAY_INFORMATION TimeOfDay; + PVOID IniFileMapping; + NLS_USER_INFO NlsUserInfo; + BOOLEAN DefaultSeparateVDM; + BOOLEAN IsWowTaskReady; + UNICODE_STRING WindowsSys32x86Directory; + BOOLEAN fTermsrvAppInstallMode; + TIME_ZONE_INFORMATION tziTermsrvClientTimeZone; + KSYSTEM_TIME ktTermsrvClientBias; + ULONG TermsrvClientTimeZoneId; + BOOLEAN LUIDDeviceMapsEnabled; + ULONG TermsrvClientTimeZoneChangeNum; +} BASE_STATIC_SERVER_DATA, *PBASE_STATIC_SERVER_DATA; + + /* Types used in the new CSR. Temporarly here for proper compile of NTDLL */ #define CSR_SRV_SERVER 0
Modified: trunk/reactos/subsystems/win32/csrss/csrsrv/api/wapi.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/csrss/csrs... ============================================================================== --- trunk/reactos/subsystems/win32/csrss/csrsrv/api/wapi.c [iso-8859-1] (original) +++ trunk/reactos/subsystems/win32/csrss/csrsrv/api/wapi.c [iso-8859-1] Wed Aug 3 03:09:02 2011 @@ -118,6 +118,294 @@ (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) @@ -127,6 +415,7 @@ 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; @@ -134,16 +423,32 @@ 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;
+ ProcessData = CsrGetProcessData(Request->ClientId.UniqueProcess); + if (ProcessData == NULL) + { + ProcessData = CsrCreateProcessData(Request->ClientId.UniqueProcess); + if (ProcessData == NULL) + { + DPRINT1("Unable to allocate or find data for process 0x%x\n", + Request->ClientId.UniqueProcess); + } + else + { + /* Attach the Shared Section */ + Status = CsrSrvAttachSharedSection(ProcessData, ConnectInfo); + if (NT_SUCCESS(Status)) AllowConnection = TRUE; + } + } + Status = NtAcceptConnectPort(&ServerPort, NULL, Request, - TRUE, + AllowConnection, 0, & LpcRead); if (!NT_SUCCESS(Status)) @@ -152,24 +457,11 @@ return Status; }
- ProcessData = CsrGetProcessData(Request->ClientId.UniqueProcess); - if (ProcessData == NULL) - { - ProcessData = CsrCreateProcessData(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; - } - } - 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");