00117 :
00118
00119 This function
is called by
the client side DLL to connect with its
00120 server side DLL.
00121
00122 Arguments:
00123
00124 ObjectDirectory - Points to a null terminate string that
is the same
00125 as
the value of
the ObjectDirectory= argument passed to
the CSRSS
00126 program.
00127
00128 ServerDllIndex -
Index of
the server DLL that
is being connected to.
00129 It should match one of
the ServerDll= arguments passed to
the CSRSS
00130 program.
00131
00132 CallbackInformation - An optional pointer to a structure that contains
00133 a pointer to
the client callback function dispatch table.
00134
00135 ConnectionInformation - An optional pointer to uninterpreted data.
00136 This data
is intended
for clients to pass package, version and
00137 protocol identification information to
the server to allow
the
00138 server to determine
if it can satisify
the client before
00139 accepting
the connection. Upon
return to
the client,
the
00140 ConnectionInformation data block contains any information passed
00141 back from
the server DLL by its call to
the
00142 CsrCompleteConnection call. The output data overwrites
the
00143 input data.
00144
00145 ConnectionInformationLength - Pointer to
the length of
the
00146 ConnectionInformation data block. The output value
is the
00147 length of
the data stored in
the ConnectionInformation data
00148 block by
the server's call to
the NtCompleteConnectPort
00149 service. This parameter
is OPTIONAL
only if the
00150 ConnectionInformation parameter
is NULL, otherwise
it is
00151 required.
00152
00153 CalledFromServer - On output,
TRUE if the dll has been called from
00154 a server process.
00155
00156 Return Value:
00157
00158
Status value.
00159
00160 --*/
00161
00162 {
00163
NTSTATUS Status;
00164 CSR_API_MSG m;
00165 PCSR_CLIENTCONNECT_MSG a = &m.u.ClientConnect;
00166 PCSR_CAPTURE_HEADER CaptureBuffer;
00167 HANDLE CsrServerModuleHandle;
00168 STRING ProcedureName;
00169 ANSI_STRING DllName;
00170 UNICODE_STRING DllName_U;
00171 PIMAGE_NT_HEADERS NtHeaders;
00172
00173
if (ARGUMENT_PRESENT( ConnectionInformation ) &&
00174 (!ARGUMENT_PRESENT( ConnectionInformationLength ) ||
00175 *ConnectionInformationLength == 0
00176 )
00177 ) {
00178
return( STATUS_INVALID_PARAMETER );
00179 }
00180
00181
if (!
CsrInitOnceDone) {
00182
Status =
CsrOneTimeInitialize();
00183
if (!
NT_SUCCESS( Status )) {
00184
return(
Status );
00185 }
00186 }
00187
00188
if (ARGUMENT_PRESENT( CallbackInformation )) {
00189
CsrLoadedClientDll[ ServerDllIndex ] =
RtlAllocateHeap( CsrHeap,
MAKE_TAG( CSR_TAG ),
sizeof(CSR_CALLBACK_INFO) );
00190
if ( !
CsrLoadedClientDll[ ServerDllIndex ] ) {
00191
return STATUS_NO_MEMORY;
00192 }
00193
CsrLoadedClientDll[ ServerDllIndex ]->ApiNumberBase =
00194 CallbackInformation->ApiNumberBase;
00195
CsrLoadedClientDll[ ServerDllIndex ]->MaxApiNumber =
00196 CallbackInformation->MaxApiNumber;
00197
CsrLoadedClientDll[ ServerDllIndex ]->CallbackDispatchTable =
00198 CallbackInformation->CallbackDispatchTable;
00199 }
00200
00201
00202
00203
00204
00205
00206
00207
00208
if (
CsrServerProcess ==
TRUE ) {
00209 *CalledFromServer =
CsrServerProcess;
00210
return STATUS_SUCCESS;
00211 }
00212
00213
00214
00215
00216
00217
00218 NtHeaders =
RtlImageNtHeader(NtCurrentPeb()->ImageBaseAddress);
00219
CsrServerProcess =
00220 (NtHeaders->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_NATIVE) ?
TRUE :
FALSE;
00221
00222
if (
CsrServerProcess ) {
00223
extern PVOID
NtDllBase;
00224
RtlInitAnsiString( &DllName,
"csrsrv" );
00225
Status =
RtlAnsiStringToUnicodeString(&DllName_U, &DllName, TRUE);
00226
ASSERT(
NT_SUCCESS(Status));
00227
00228
LdrDisableThreadCalloutsForDll(NtDllBase);
00229
00230
Status =
LdrGetDllHandle(
00231 UNICODE_NULL,
00232 NULL,
00233 &DllName_U,
00234 (PVOID *)&CsrServerModuleHandle
00235 );
00236
00237
RtlFreeUnicodeString(&DllName_U);
00238
00239
CsrServerProcess =
TRUE;
00240
00241
RtlInitString(&ProcedureName,
"CsrCallServerFromServer");
00242
Status =
LdrGetProcedureAddress(
00243 CsrServerModuleHandle,
00244 &ProcedureName,
00245 0L,
00246 (PVOID *)&CsrServerApiRoutine
00247 );
00248
ASSERT(
NT_SUCCESS(Status));
00249
00250
ASSERT (CsrPortHeap==NULL);
00251
CsrPortHeap = RtlProcessHeap();
00252
00253
CsrPortBaseTag =
RtlCreateTagHeap( CsrPortHeap,
00254 0,
00255 L
"CSRPORT!",
00256 L
"CAPTURE\0"
00257 );
00258
00259
if (ARGUMENT_PRESENT(CalledFromServer)) {
00260 *CalledFromServer =
CsrServerProcess;
00261 }
00262
return STATUS_SUCCESS;
00263 }
00264
00265
if ( ARGUMENT_PRESENT(ConnectionInformation) ) {
00266
CsrServerProcess =
FALSE;
00267
if (
CsrPortHandle ==
NULL) {
00268
Status =
CsrpConnectToServer( ObjectDirectory );
00269
if (!
NT_SUCCESS( Status )) {
00270
return(
Status );
00271 }
00272 }
00273
00274 a->ServerDllIndex = ServerDllIndex;
00275 a->ConnectionInformationLength = *ConnectionInformationLength;
00276
if (ARGUMENT_PRESENT( ConnectionInformation )) {
00277 CaptureBuffer =
CsrAllocateCaptureBuffer( 1,
00278 a->ConnectionInformationLength
00279 );
00280
if (CaptureBuffer ==
NULL) {
00281
return( STATUS_NO_MEMORY );
00282 }
00283
00284
CsrAllocateMessagePointer( CaptureBuffer,
00285 a->ConnectionInformationLength,
00286 (PVOID *)&a->ConnectionInformation
00287 );
00288 RtlMoveMemory( a->ConnectionInformation,
00289 ConnectionInformation,
00290 a->ConnectionInformationLength
00291 );
00292
00293 *ConnectionInformationLength = a->ConnectionInformationLength;
00294 }
00295
else {
00296 CaptureBuffer =
NULL;
00297 }
00298
00299
Status =
CsrClientCallServer( &m,
00300 CaptureBuffer,
00301 CSR_MAKE_API_NUMBER( CSRSRV_SERVERDLL_INDEX,
00302 CsrpClientConnect
00303 ),
00304
sizeof( *a )
00305 );
00306
00307
if (CaptureBuffer !=
NULL) {
00308
if (ARGUMENT_PRESENT( ConnectionInformation )) {
00309 RtlMoveMemory( ConnectionInformation,
00310 a->ConnectionInformation,
00311 *ConnectionInformationLength
00312 );
00313 }
00314
00315
CsrFreeCaptureBuffer( CaptureBuffer );
00316 }
00317 }
00318
else {
00319
Status = STATUS_SUCCESS;
00320 }
00321
00322
if (ARGUMENT_PRESENT(CalledFromServer)) {
00323 *CalledFromServer =
CsrServerProcess;
00324 }
00325
return(
Status );
00326 }