ReactOS  0.4.14-dev-41-g31d7680
connect.c File Reference
#include <ntdll.h>
#include <ndk/lpcfuncs.h>
#include <csr/csrsrv.h>
#include <debug.h>
Include dependency graph for connect.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define UNICODE_PATH_SEP   L"\\"
 

Typedefs

typedef NTSTATUS(NTAPIPCSR_SERVER_API_ROUTINE) (IN PPORT_MESSAGE Request, IN PPORT_MESSAGE Reply)
 

Functions

NTSTATUS NTAPI CsrpConnectToServer (IN PWSTR ObjectDirectory)
 
NTSTATUS NTAPI CsrClientConnectToServer (IN PWSTR ObjectDirectory, IN ULONG ServerId, IN PVOID ConnectionInfo, IN OUT PULONG ConnectionInfoSize, OUT PBOOLEAN ServerToServerCall)
 
NTSTATUS NTAPI CsrClientCallServer (IN OUT PCSR_API_MESSAGE ApiMessage, IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer OPTIONAL, IN CSR_API_NUMBER ApiNumber, IN ULONG DataLength)
 
HANDLE NTAPI CsrGetProcessId (VOID)
 

Variables

HANDLE CsrApiPort
 
HANDLE CsrProcessId
 
HANDLE CsrPortHeap
 
ULONG_PTR CsrPortMemoryDelta
 
BOOLEAN InsideCsrProcess = FALSE
 
PCSR_SERVER_API_ROUTINE CsrServerApiRoutine
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 16 of file connect.c.

◆ UNICODE_PATH_SEP

#define UNICODE_PATH_SEP   L"\\"

Definition at line 33 of file connect.c.

Typedef Documentation

◆ PCSR_SERVER_API_ROUTINE

typedef NTSTATUS(NTAPI * PCSR_SERVER_API_ROUTINE) (IN PPORT_MESSAGE Request, IN PPORT_MESSAGE Reply)

Definition at line 28 of file connect.c.

Function Documentation

◆ CsrClientCallServer()

NTSTATUS NTAPI CsrClientCallServer ( IN OUT PCSR_API_MESSAGE  ApiMessage,
IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer  OPTIONAL,
IN CSR_API_NUMBER  ApiNumber,
IN ULONG  DataLength 
)

Definition at line 365 of file connect.c.

369 {
371  ULONG PointerCount;
372  PULONG_PTR OffsetPointer;
373 
374  /* Make sure the length is valid */
375  if (DataLength > (MAXSHORT - sizeof(CSR_API_MESSAGE)))
376  {
377  DPRINT1("DataLength too big: %lu", DataLength);
379  }
380 
381  /* Fill out the Port Message Header */
382  ApiMessage->Header.u2.ZeroInit = 0;
383  ApiMessage->Header.u1.s1.TotalLength = (CSHORT)DataLength +
384  sizeof(CSR_API_MESSAGE) - sizeof(ApiMessage->Data); // FIELD_OFFSET(CSR_API_MESSAGE, Data) + DataLength;
385  ApiMessage->Header.u1.s1.DataLength = (CSHORT)DataLength +
386  FIELD_OFFSET(CSR_API_MESSAGE, Data) - sizeof(ApiMessage->Header); // ApiMessage->Header.u1.s1.TotalLength - sizeof(PORT_MESSAGE);
387 
388  /* Fill out the CSR Header */
389  ApiMessage->ApiNumber = ApiNumber;
390  ApiMessage->CsrCaptureData = NULL;
391 
392  DPRINT("API: %lx, u1.s1.DataLength: %x, u1.s1.TotalLength: %x\n",
393  ApiNumber,
394  ApiMessage->Header.u1.s1.DataLength,
395  ApiMessage->Header.u1.s1.TotalLength);
396 
397  /* Check if we are already inside a CSR Server */
398  if (!InsideCsrProcess)
399  {
400  /* Check if we got a Capture Buffer */
401  if (CaptureBuffer)
402  {
403  /*
404  * We have to convert from our local (client) view
405  * to the remote (server) view.
406  */
407  ApiMessage->CsrCaptureData = (PCSR_CAPTURE_BUFFER)
408  ((ULONG_PTR)CaptureBuffer + CsrPortMemoryDelta);
409 
410  /* Lock the buffer. */
411  CaptureBuffer->BufferEnd = NULL;
412 
413  /*
414  * Each client pointer inside the CSR message is converted into
415  * a server pointer, and each pointer to these message pointers
416  * is converted into an offset.
417  */
418  PointerCount = CaptureBuffer->PointerCount;
419  OffsetPointer = CaptureBuffer->PointerOffsetsArray;
420  while (PointerCount--)
421  {
422  if (*OffsetPointer != 0)
423  {
424  *(PULONG_PTR)*OffsetPointer += CsrPortMemoryDelta;
425  *OffsetPointer -= (ULONG_PTR)ApiMessage;
426  }
427  ++OffsetPointer;
428  }
429  }
430 
431  /* Send the LPC Message */
433  &ApiMessage->Header,
434  &ApiMessage->Header);
435 
436  /* Check if we got a Capture Buffer */
437  if (CaptureBuffer)
438  {
439  /*
440  * We have to convert back from the remote (server) view
441  * to our local (client) view.
442  */
443  ApiMessage->CsrCaptureData = (PCSR_CAPTURE_BUFFER)
444  ((ULONG_PTR)ApiMessage->CsrCaptureData - CsrPortMemoryDelta);
445 
446  /*
447  * Convert back the offsets into pointers to CSR message
448  * pointers, and convert back these message server pointers
449  * into client pointers.
450  */
451  PointerCount = CaptureBuffer->PointerCount;
452  OffsetPointer = CaptureBuffer->PointerOffsetsArray;
453  while (PointerCount--)
454  {
455  if (*OffsetPointer != 0)
456  {
457  *OffsetPointer += (ULONG_PTR)ApiMessage;
458  *(PULONG_PTR)*OffsetPointer -= CsrPortMemoryDelta;
459  }
460  ++OffsetPointer;
461  }
462  }
463 
464  /* Check for success */
465  if (!NT_SUCCESS(Status))
466  {
467  /* We failed. Overwrite the return value with the failure. */
468  DPRINT1("LPC Failed: %lx\n", Status);
469  ApiMessage->Status = Status;
470  }
471  }
472  else
473  {
474  /* This is a server-to-server call. Save our CID and do a direct call. */
475  DPRINT("Next gen server-to-server call\n");
476 
477  /* We check this equality inside CsrValidateMessageBuffer */
478  ApiMessage->Header.ClientId = NtCurrentTeb()->ClientId;
479 
480  Status = CsrServerApiRoutine(&ApiMessage->Header,
481  &ApiMessage->Header);
482 
483  /* Check for success */
484  if (!NT_SUCCESS(Status))
485  {
486  /* We failed. Overwrite the return value with the failure. */
487  ApiMessage->Status = Status;
488  }
489  }
490 
491  /* Return the CSR Result */
492  DPRINT("Got back: 0x%lx\n", ApiMessage->Status);
493  return ApiMessage->Status;
494 }
PCSR_SERVER_API_ROUTINE CsrServerApiRoutine
Definition: connect.c:31
NTSTATUS NTAPI NtRequestWaitReplyPort(IN HANDLE PortHandle, IN PPORT_MESSAGE LpcRequest, IN OUT PPORT_MESSAGE LpcReply)
Definition: send.c:695
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
struct _CSR_CAPTURE_BUFFER * PCSR_CAPTURE_BUFFER
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
BOOLEAN InsideCsrProcess
Definition: connect.c:25
ULONG_PTR CsrPortMemoryDelta
Definition: connect.c:24
Status
Definition: gdiplustypes.h:24
#define MAXSHORT
Definition: umtypes.h:114
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
HANDLE CsrApiPort
Definition: connect.c:21
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
uint32_t * PULONG_PTR
Definition: typedefs.h:63
_Must_inspect_result_ _Out_writes_to_ DataLength PHIDP_DATA _Inout_ PULONG DataLength
Definition: hidpi.h:333
short CSHORT
Definition: umtypes.h:127

Referenced by BaseCheckForVDM(), BaseCheckVDM(), BasepNotifyCsrOfThread(), BaseUpdateVDMEntry(), CloseConsoleHandle(), ConsoleMenuControl(), CreateConsoleScreenBuffer(), CreateProcessInternalW(), CsrClientConnectToServer(), CsrIdentifyAlertableThread(), CsrSetPriorityClass(), DefineDosDeviceW(), DuplicateConsoleHandle(), EndTask(), ExitProcess(), ExitVDM(), ExitWindowsWorker(), FlushConsoleInputBuffer(), FreeConsole(), GenerateConsoleCtrlEvent(), GetConsoleCP(), GetConsoleCursorInfo(), GetConsoleDisplayMode(), GetConsoleFontInfo(), GetConsoleFontSize(), GetConsoleHandleInformation(), GetConsoleHardwareState(), GetConsoleMode(), GetConsoleOutputCP(), GetConsoleProcessList(), GetConsoleScreenBufferInfo(), GetConsoleSelectionInfo(), GetConsoleWindow(), GetCurrentConsoleFont(), GetLargestConsoleWindowSize(), GetNextVDMCommand(), GetNumberOfConsoleFonts(), GetNumberOfConsoleInputEvents(), GetNumberOfConsoleMouseButtons(), GetProcessShutdownParameters(), GetTempFileNameW(), GetThreadDesktop(), GetVDMCurrentDirectories(), IntAddConsoleAlias(), IntAllocConsole(), IntAttachConsole(), IntExpungeConsoleCommandHistory(), IntFillConsoleOutputCode(), IntGetConsoleAlias(), IntGetConsoleAliases(), IntGetConsoleAliasesLength(), IntGetConsoleAliasExes(), IntGetConsoleAliasExesLength(), IntGetConsoleCommandHistory(), IntGetConsoleCommandHistoryLength(), IntGetConsoleInput(), IntGetConsoleKeyboardLayoutName(), IntGetConsoleTitle(), IntReadConsole(), IntReadConsoleOutput(), IntReadConsoleOutputCode(), IntScrollConsoleScreenBuffer(), IntSetConsoleNumberOfCommands(), IntSetConsoleTitle(), IntWriteConsole(), IntWriteConsoleInput(), IntWriteConsoleOutput(), IntWriteConsoleOutputCode(), InvalidateConsoleDIBits(), Logon(), NotifySoundSentry(), OpenConsoleW(), RegisterConsoleVDM(), RegisterLogonProcess(), RegisterServicesProcess(), SetConsoleActiveScreenBuffer(), SetConsoleCommandHistoryMode(), SetConsoleCP(), SetConsoleCursor(), SetConsoleCursorInfo(), SetConsoleCursorPosition(), SetConsoleDisplayMode(), SetConsoleFont(), SetConsoleHandleInformation(), SetConsoleHardwareState(), SetConsoleIcon(), SetConsoleMenuClose(), SetConsoleMode(), SetConsoleOutputCP(), SetConsolePalette(), SetConsoleScreenBufferSize(), SetConsoleTextAttribute(), SetConsoleWindowInfo(), SetLastConsoleEventActive(), SetProcessShutdownParameters(), SetVDMCurrentDirectories(), ShowConsoleCursor(), and VerifyConsoleIoHandle().

◆ CsrClientConnectToServer()

NTSTATUS NTAPI CsrClientConnectToServer ( IN PWSTR  ObjectDirectory,
IN ULONG  ServerId,
IN PVOID  ConnectionInfo,
IN OUT PULONG  ConnectionInfoSize,
OUT PBOOLEAN  ServerToServerCall 
)

Definition at line 197 of file connect.c.

202 {
204  PIMAGE_NT_HEADERS NtHeader;
205  UNICODE_STRING CsrSrvName;
206  HANDLE hCsrSrv;
207  ANSI_STRING CsrServerRoutineName;
208  CSR_API_MESSAGE ApiMessage;
209  PCSR_CLIENT_CONNECT ClientConnect = &ApiMessage.Data.CsrClientConnect;
210  PCSR_CAPTURE_BUFFER CaptureBuffer;
211 
212  DPRINT("CsrClientConnectToServer: %lx %p\n", ServerId, ConnectionInfo);
213 
214  /* Validate the Connection Info */
215  if (ConnectionInfo && (!ConnectionInfoSize || !*ConnectionInfoSize))
216  {
217  DPRINT1("Connection info given, but no length\n");
219  }
220 
221  /* Check if we're inside a CSR Process */
222  if (InsideCsrProcess)
223  {
224  /* Tell the client that we're already inside CSR */
225  if (ServerToServerCall) *ServerToServerCall = TRUE;
226  return STATUS_SUCCESS;
227  }
228 
229  /*
230  * We might be in a CSR Process but not know it, if this is the first call.
231  * So let's find out.
232  */
233  if (!(NtHeader = RtlImageNtHeader(NtCurrentPeb()->ImageBaseAddress)))
234  {
235  /* The image isn't valid */
236  DPRINT1("Invalid image\n");
238  }
240 
241  /* Now we can check if we are inside or not */
242  if (InsideCsrProcess)
243  {
244  /* We're inside, so let's find csrsrv */
245  DPRINT("Next-GEN CSRSS support\n");
246  RtlInitUnicodeString(&CsrSrvName, L"csrsrv");
248  NULL,
249  &CsrSrvName,
250  &hCsrSrv);
251 
252  /* Now get the Server to Server routine */
253  RtlInitAnsiString(&CsrServerRoutineName, "CsrCallServerFromServer");
254  Status = LdrGetProcedureAddress(hCsrSrv,
255  &CsrServerRoutineName,
256  0L,
258 
259  /* Use the local heap as port heap */
260  CsrPortHeap = RtlGetProcessHeap();
261 
262  /* Tell the caller we're inside the server */
263  if (ServerToServerCall) *ServerToServerCall = InsideCsrProcess;
264  return STATUS_SUCCESS;
265  }
266 
267  /* Now check if connection info is given */
268  if (ConnectionInfo)
269  {
270  /* Well, we're definitely in a client now */
272 
273  /* Do we have a connection to CSR yet? */
274  if (!CsrApiPort)
275  {
276  /* No, set it up now */
277  Status = CsrpConnectToServer(ObjectDirectory);
278  if (!NT_SUCCESS(Status))
279  {
280  /* Failed */
281  DPRINT1("Failure to connect to CSR\n");
282  return Status;
283  }
284  }
285 
286  /* Setup the connect message header */
287  ClientConnect->ServerId = ServerId;
288  ClientConnect->ConnectionInfoSize = *ConnectionInfoSize;
289 
290  /* Setup a buffer for the connection info */
291  CaptureBuffer = CsrAllocateCaptureBuffer(1, ClientConnect->ConnectionInfoSize);
292  if (CaptureBuffer == NULL)
293  {
295  }
296 
297  /* Capture the connection info data */
298  CsrCaptureMessageBuffer(CaptureBuffer,
299  ConnectionInfo,
300  ClientConnect->ConnectionInfoSize,
301  &ClientConnect->ConnectionInfo);
302 
303  /* Return the allocated length */
304  *ConnectionInfoSize = ClientConnect->ConnectionInfoSize;
305 
306  /* Call CSR */
307  Status = CsrClientCallServer(&ApiMessage,
308  CaptureBuffer,
310  sizeof(CSR_CLIENT_CONNECT));
311 
312  /* Copy the updated connection info data back into the user buffer */
313  RtlMoveMemory(ConnectionInfo,
314  ClientConnect->ConnectionInfo,
315  *ConnectionInfoSize);
316 
317  /* Free the capture buffer */
318  CsrFreeCaptureBuffer(CaptureBuffer);
319  }
320  else
321  {
322  /* No connection info, just return */
324  }
325 
326  /* Let the caller know if this was server to server */
327  DPRINT("Status was: 0x%lx. Are we in server: 0x%x\n", Status, InsideCsrProcess);
328  if (ServerToServerCall) *ServerToServerCall = InsideCsrProcess;
329 
330  return Status;
331 }
VOID NTAPI CsrFreeCaptureBuffer(IN PCSR_CAPTURE_BUFFER CaptureBuffer)
Definition: capture.c:189
union _CSR_API_MESSAGE::@3326::@3328::@3330 Data
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
NTSTATUS NTAPI LdrGetDllHandle(IN PWSTR DllPath OPTIONAL, IN PULONG DllCharacteristics OPTIONAL, IN PUNICODE_STRING DllName, OUT PVOID *DllHandle)
Definition: ldrapi.c:805
PCSR_SERVER_API_ROUTINE CsrServerApiRoutine
Definition: connect.c:31
PCSR_CAPTURE_BUFFER NTAPI CsrAllocateCaptureBuffer(IN ULONG ArgumentCount, IN ULONG BufferSize)
Definition: capture.c:90
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSTATUS NTAPI CsrClientCallServer(IN OUT PCSR_API_MESSAGE ApiMessage, IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer OPTIONAL, IN CSR_API_NUMBER ApiNumber, IN ULONG DataLength)
Definition: connect.c:365
LONG NTSTATUS
Definition: precomp.h:26
PVOID ConnectionInfo
Definition: csrmsg.h:88
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
VOID NTAPI CsrCaptureMessageBuffer(IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer, IN PVOID MessageBuffer OPTIONAL, IN ULONG MessageLength, OUT PVOID *CapturedData)
Definition: capture.c:169
NTSTATUS NTAPI LdrGetProcedureAddress(IN PVOID BaseAddress, IN PANSI_STRING Name, IN ULONG Ordinal, OUT PVOID *ProcedureAddress)
Definition: ldrapi.c:823
smooth NULL
Definition: ftsmooth.c:416
#define IMAGE_SUBSYSTEM_NATIVE
Definition: ntimage.h:436
void DPRINT(...)
Definition: polytest.cpp:61
#define CSR_CREATE_API_NUMBER(ServerId, ApiId)
Definition: csrmsg.h:37
#define STATUS_INVALID_IMAGE_FORMAT
Definition: ntstatus.h:345
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG ConnectionInfoSize
Definition: csrmsg.h:89
BOOLEAN InsideCsrProcess
Definition: connect.c:25
NTSTATUS NTAPI CsrpConnectToServer(IN PWSTR ObjectDirectory)
Definition: connect.c:39
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
#define NtCurrentPeb()
Definition: FLS.c:20
#define CSRSRV_SERVERDLL_INDEX
Definition: csrmsg.h:20
HANDLE CsrApiPort
Definition: connect.c:21
#define DPRINT1
Definition: precomp.h:8
#define RtlImageNtHeader
Definition: compat.h:457
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
return STATUS_SUCCESS
Definition: btrfs.c:2966
HANDLE CsrPortHeap
Definition: connect.c:23

Referenced by ConnectConsole(), and DllMain().

◆ CsrGetProcessId()

HANDLE NTAPI CsrGetProcessId ( VOID  )

Definition at line 501 of file connect.c.

502 {
503  return CsrProcessId;
504 }
HANDLE CsrProcessId
Definition: connect.c:22

Referenced by ProcessIdToHandle().

◆ CsrpConnectToServer()

NTSTATUS NTAPI CsrpConnectToServer ( IN PWSTR  ObjectDirectory)

Definition at line 39 of file connect.c.

40 {
42  SIZE_T PortNameLength;
44  LARGE_INTEGER CsrSectionViewSize;
45  HANDLE CsrSectionHandle;
46  PORT_VIEW LpcWrite;
47  REMOTE_PORT_VIEW LpcRead;
48  SECURITY_QUALITY_OF_SERVICE SecurityQos;
50  PSID SystemSid = NULL;
51  CSR_API_CONNECTINFO ConnectionInfo;
52  ULONG ConnectionInfoLength = sizeof(CSR_API_CONNECTINFO);
53 
54  DPRINT("%s(%S)\n", __FUNCTION__, ObjectDirectory);
55 
56  /* Binary compatibility with MS KERNEL32 */
57  if (NULL == ObjectDirectory)
58  {
59  ObjectDirectory = L"\\Windows";
60  }
61 
62  /* Calculate the total port name size */
63  PortNameLength = ((wcslen(ObjectDirectory) + 1) * sizeof(WCHAR)) +
64  sizeof(CSR_PORT_NAME);
65  if (PortNameLength > UNICODE_STRING_MAX_BYTES)
66  {
67  DPRINT1("PortNameLength too big: %Iu", PortNameLength);
68  return STATUS_NAME_TOO_LONG;
69  }
70 
71  /* Set the port name */
72  PortName.Length = 0;
73  PortName.MaximumLength = (USHORT)PortNameLength;
74 
75  /* Allocate a buffer for it */
76  PortName.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, PortNameLength);
77  if (PortName.Buffer == NULL)
78  {
80  }
81 
82  /* Create the name */
83  RtlAppendUnicodeToString(&PortName, ObjectDirectory );
86 
87  /* Create a section for the port memory */
88  CsrSectionViewSize.QuadPart = CSR_CSRSS_SECTION_SIZE;
89  Status = NtCreateSection(&CsrSectionHandle,
91  NULL,
92  &CsrSectionViewSize,
95  NULL);
96  if (!NT_SUCCESS(Status))
97  {
98  DPRINT1("Failure allocating CSR Section\n");
99  return Status;
100  }
101 
102  /* Set up the port view structures to match them with the section */
103  LpcWrite.Length = sizeof(PORT_VIEW);
104  LpcWrite.SectionHandle = CsrSectionHandle;
105  LpcWrite.SectionOffset = 0;
106  LpcWrite.ViewSize = CsrSectionViewSize.u.LowPart;
107  LpcWrite.ViewBase = 0;
108  LpcWrite.ViewRemoteBase = 0;
109  LpcRead.Length = sizeof(REMOTE_PORT_VIEW);
110  LpcRead.ViewSize = 0;
111  LpcRead.ViewBase = 0;
112 
113  /* Setup the QoS */
116  SecurityQos.EffectiveOnly = TRUE;
117 
118  /* Setup the connection info */
119  ConnectionInfo.DebugFlags = 0;
120 
121  /* Create a SID for us */
123  1,
125  0,
126  0,
127  0,
128  0,
129  0,
130  0,
131  0,
132  &SystemSid);
133  if (!NT_SUCCESS(Status))
134  {
135  /* Failure */
136  DPRINT1("Couldn't allocate SID\n");
137  NtClose(CsrSectionHandle);
138  return Status;
139  }
140 
141  /* Connect to the port */
143  &PortName,
144  &SecurityQos,
145  &LpcWrite,
146  SystemSid,
147  &LpcRead,
148  NULL,
149  &ConnectionInfo,
150  &ConnectionInfoLength);
151  RtlFreeSid(SystemSid);
152  NtClose(CsrSectionHandle);
153  if (!NT_SUCCESS(Status))
154  {
155  /* Failure */
156  DPRINT1("Couldn't connect to CSR port\n");
157  return Status;
158  }
159 
160  /* Save the delta between the sections, for capture usage later */
162  (ULONG_PTR)LpcWrite.ViewBase;
163 
164  /* Save the Process */
165  CsrProcessId = ConnectionInfo.ServerProcessId;
166 
167  /* Save CSR Section data */
168  NtCurrentPeb()->ReadOnlySharedMemoryBase = ConnectionInfo.SharedSectionBase;
169  NtCurrentPeb()->ReadOnlySharedMemoryHeap = ConnectionInfo.SharedSectionHeap;
170  NtCurrentPeb()->ReadOnlyStaticServerData = ConnectionInfo.SharedStaticServerData;
171 
172  /* Create the port heap */
174  LpcWrite.ViewBase,
175  LpcWrite.ViewSize,
176  PAGE_SIZE,
177  0,
178  0);
179  if (CsrPortHeap == NULL)
180  {
181  /* Failure */
182  DPRINT1("Couldn't create heap for CSR port\n");
184  CsrApiPort = NULL;
186  }
187 
188  /* Return success */
189  return STATUS_SUCCESS;
190 }
struct _PORT_VIEW PORT_VIEW
#define SECURITY_LOCAL_SYSTEM_RID
Definition: setypes.h:546
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
NTSTATUS NTAPI NtCreateSection(OUT PHANDLE SectionHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN PLARGE_INTEGER MaximumSize OPTIONAL, IN ULONG SectionPageProtection OPTIONAL, IN ULONG AllocationAttributes, IN HANDLE FileHandle OPTIONAL)
Definition: section.c:3373
USHORT MaximumLength
Definition: env_spec_w32.h:370
HANDLE CsrProcessId
Definition: connect.c:22
NTSYSAPI PVOID NTAPI RtlFreeSid(_In_ _Post_invalid_ PSID Sid)
PVOID SharedStaticServerData
Definition: csrmsg.h:51
LONG NTSTATUS
Definition: precomp.h:26
#define CSR_PORT_NAME
Definition: csrmsg.h:17
ULONG SectionOffset
#define UNICODE_STRING_MAX_BYTES
NTSYSAPI NTSTATUS NTAPI RtlAllocateAndInitializeSid(IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, IN UCHAR SubAuthorityCount, IN ULONG SubAuthority0, IN ULONG SubAuthority1, IN ULONG SubAuthority2, IN ULONG SubAuthority3, IN ULONG SubAuthority4, IN ULONG SubAuthority5, IN ULONG SubAuthority6, IN ULONG SubAuthority7, OUT PSID *Sid)
Definition: sid.c:290
SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode
Definition: lsa.idl:66
uint32_t ULONG_PTR
Definition: typedefs.h:63
PVOID SharedSectionBase
Definition: csrmsg.h:50
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
HANDLE ServerProcessId
Definition: csrmsg.h:57
NTSTATUS NTAPI NtSecureConnectPort(OUT PHANDLE PortHandle, IN PUNICODE_STRING PortName, IN PSECURITY_QUALITY_OF_SERVICE SecurityQos, IN OUT PPORT_VIEW ClientView OPTIONAL, IN PSID ServerSid OPTIONAL, IN OUT PREMOTE_PORT_VIEW ServerView OPTIONAL, OUT PULONG MaxMessageLength OPTIONAL, IN OUT PVOID ConnectionInformation OPTIONAL, IN OUT PULONG ConnectionInformationLength OPTIONAL)
Definition: connect.c:80
PVOID SharedSectionHeap
Definition: csrmsg.h:52
#define SEC_RESERVE
Definition: nt_native.h:1323
struct _LARGE_INTEGER::@2201 u
LPC_PVOID ViewRemoteBase
smooth NULL
Definition: ftsmooth.c:416
static SID_IDENTIFIER_AUTHORITY NtSidAuthority
Definition: samrpc.c:14
struct _REMOTE_PORT_VIEW REMOTE_PORT_VIEW
void DPRINT(...)
Definition: polytest.cpp:61
#define SECURITY_NT_AUTHORITY
Definition: setypes.h:526
#define STATUS_NAME_TOO_LONG
Definition: ntstatus.h:484
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
LPC_SIZE_T ViewSize
struct _CSR_API_CONNECTINFO CSR_API_CONNECTINFO
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define CSR_CSRSS_SECTION_SIZE
Definition: csrsrv.h:27
ULONG_PTR CsrPortMemoryDelta
Definition: connect.c:24
#define SECURITY_DYNAMIC_TRACKING
Definition: setypes.h:103
static const WCHAR L[]
Definition: oid.c:1250
NTSYSAPI PVOID NTAPI RtlCreateHeap(IN ULONG Flags, IN PVOID HeapBase OPTIONAL, IN ULONG ReserveSize OPTIONAL, IN ULONG CommitSize OPTIONAL, IN PVOID Lock OPTIONAL, IN PRTL_HEAP_PARAMETERS Parameters OPTIONAL)
#define PAGE_SIZE
Definition: env_spec_w32.h:49
Status
Definition: gdiplustypes.h:24
ULONG_PTR SIZE_T
Definition: typedefs.h:78
LPC_PVOID ViewBase
#define NtCurrentPeb()
Definition: FLS.c:20
unsigned short USHORT
Definition: pedump.c:61
#define UNICODE_PATH_SEP
Definition: connect.c:33
HANDLE CsrApiPort
Definition: connect.c:21
SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
Definition: lsa.idl:65
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
LPC_HANDLE SectionHandle
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define __FUNCTION__
Definition: types.h:112
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
LONGLONG QuadPart
Definition: typedefs.h:112
#define PAGE_READWRITE
Definition: nt_native.h:1304
IN PUNICODE_STRING PortName
Definition: conport.c:35
HANDLE CsrPortHeap
Definition: connect.c:23

Referenced by CsrClientConnectToServer().

Variable Documentation

◆ CsrApiPort

HANDLE CsrApiPort

Definition at line 21 of file connect.c.

Referenced by CsrClientCallServer(), CsrClientConnectToServer(), and CsrpConnectToServer().

◆ CsrPortHeap

◆ CsrPortMemoryDelta

ULONG_PTR CsrPortMemoryDelta

Definition at line 24 of file connect.c.

Referenced by CsrClientCallServer(), and CsrpConnectToServer().

◆ CsrProcessId

HANDLE CsrProcessId

Definition at line 22 of file connect.c.

Referenced by CsrGetProcessId(), and CsrpConnectToServer().

◆ CsrServerApiRoutine

PCSR_SERVER_API_ROUTINE CsrServerApiRoutine

Definition at line 31 of file connect.c.

Referenced by CsrClientCallServer(), and CsrClientConnectToServer().

◆ InsideCsrProcess

BOOLEAN InsideCsrProcess = FALSE

Definition at line 25 of file connect.c.

Referenced by CsrClientCallServer(), and CsrClientConnectToServer().