3 * subsys/csr/csrsrv/server.c - CSR server - subsystem default server
5 * ReactOS Operating System
7 * --------------------------------------------------------------------
9 * This software is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
14 * This software is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this software; see the file COPYING.LIB. If not, write
21 * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
24 * --------------------------------------------------------------------
31 typedef NTSTATUS (STDCALL
* CSR_SERVER_DLL_INIT_PROC
)(ULONG
,LPWSTR
*);
33 typedef struct _CSRSRV_SERVER_DLL
36 USHORT Sequence
; // initialization order
37 UNICODE_STRING DllName
;
38 UNICODE_STRING DllEntryPoint
;
39 CSR_SERVER_THREAD ServerThread
; // NULL ==> inactive
41 } CSRSRV_SERVER_DLL
, *PCSRSRV_SERVER_DLL
;
43 /*=====================================================================
45 *===================================================================*/
47 CSRSRV_OPTION CsrSrvOption
;
49 HANDLE CsrSrvApiPortHandle
= (HANDLE
) 0;
51 /*=====================================================================
53 *===================================================================*/
55 static HANDLE CsrSrvSbApiPortHandle
= (HANDLE
) 0;
57 static CSRSRV_SERVER_DLL ServerThread
[CSR_SERVER_DLL_MAX
];
59 VOID CALLBACK
CsrSrvServerThread (PVOID
);
61 /**********************************************************************
62 * CsrSrvRegisterServerDll/1
64 NTSTATUS STDCALL
CsrSrvRegisterServerDll (PCSR_SERVER_DLL pServerDll
)
66 static USHORT NextInSequence
= 0;
67 USHORT ServerIndex
= 0;
70 if (0 == NextInSequence
)
72 RtlZeroMemory (ServerThread
, sizeof ServerThread
);
74 // We can not register more than CSR_SERVER_DLL_MAX servers.
75 // Note: # servers >= # DLLs (MS Win32 has 3 servers in 2 DLLs).
76 if (NextInSequence
>= CSR_SERVER_DLL_MAX
)
78 return STATUS_NO_MEMORY
;
80 // Validate the ServerIndex from the command line:
81 // it may be 0, 1, 2, or 3.
82 ServerIndex
= pServerDll
->ServerIndex
;
83 if (ServerIndex
>= CSR_SERVER_DLL_MAX
)
85 return STATUS_INVALID_PARAMETER
;
87 // Register the DLL server.
88 ServerThread
[ServerIndex
].ServerIndex
= ServerIndex
;
89 ServerThread
[ServerIndex
].Sequence
= NextInSequence
++;
92 RtlDuplicateUnicodeString (1, & pServerDll
->DllName
, & ServerThread
[ServerIndex
].DllName
);
93 RtlDuplicateUnicodeString (1, & pServerDll
->DllEntryPoint
, & ServerThread
[ServerIndex
].DllEntryPoint
);
95 // CSRSRV.DLL own static server thread
96 ServerThread
[ServerIndex
].ServerThread
= CsrSrvServerThread
;
98 return STATUS_SUCCESS
;
100 /**********************************************************************
101 * CsrSrvInitializeServerDll/1 PRIVATE
104 * Code dapted from CsrpInitWin32Csr.
106 static NTSTATUS
CsrSrvInitializeServerDll (USHORT ServerIndex
)
108 NTSTATUS Status
= STATUS_SUCCESS
;
110 ANSI_STRING ProcName
;
111 CSR_SERVER_DLL_INIT_PROC InitProc
;
113 DPRINT("CSRSRV: %s called\n", __FUNCTION__
);
115 Status
= LdrLoadDll (NULL
, 0, & ServerThread
[ServerIndex
].DllName
, (PVOID
*) &hInst
);
116 if (!NT_SUCCESS(Status
))
118 DPRINT1("CSRSRV:%s: loading ServerDll '%S' failed (Status=%08lx)\n",
119 __FUNCTION__
, ServerThread
[ServerIndex
].DllName
.Buffer
, Status
);
122 RtlInitAnsiString (& ProcName
, "ServerDllInitialization");
123 Status
= LdrGetProcedureAddress(hInst
, &ProcName
, 0, (PVOID
*) &InitProc
);
124 if (!NT_SUCCESS(Status
))
126 DPRINT1("CSRSRV:%s: ServerDll '%S!%s' not found (Status=%08lx)\n",
128 ServerThread
[ServerIndex
].DllName
.Buffer
,
129 "ServerDllInitialization",
133 Status
= InitProc (0, NULL
);
134 if (!NT_SUCCESS(Status
))
136 DPRINT1("CSRSRV:%s: %S.%s failed with Status=%08lx\n",
138 ServerThread
[ServerIndex
].DllName
.Buffer
,
139 "ServerDllInitialization",
145 /**********************************************************************
146 * CsrpCreateObjectDirectory/1 PRIVATE
148 NTSTATUS STDCALL
CsrpCreateObjectDirectory (PUNICODE_STRING pObjectDirectory
)
150 NTSTATUS Status
= STATUS_SUCCESS
;
151 OBJECT_ATTRIBUTES DirectoryAttributes
;
153 DPRINT("CSRSRV:%s(%S) called\n", __FUNCTION__
, pObjectDirectory
->Buffer
);
155 InitializeObjectAttributes (& DirectoryAttributes
,
161 Status
= NtCreateDirectoryObject (& CsrSrvOption
.NameSpace
.RootHandle
,
162 (DIRECTORY_CREATE_OBJECT
|DIRECTORY_CREATE_SUBDIRECTORY
),
163 & DirectoryAttributes
);
164 if (NT_SUCCESS(Status
))
166 Status
= RtlDuplicateUnicodeString (0, pObjectDirectory
, & CsrSrvOption
.NameSpace
.Root
);
167 if (!NT_SUCCESS(Status
))
169 DPRINT1("CSRSRV:%s: RtlDuplicateUnicodeString failed (Status=0x%08lx)\n",
170 __FUNCTION__
, Status
);
173 DPRINT1("CSRSRV:%s: fatal: NtCreateDirectoryObject failed (Status=0x%08lx)\n",
174 __FUNCTION__
, Status
);
178 /**********************************************************************
182 * This is where a subsystem begins living.
184 NTSTATUS STDCALL
CsrSrvBootstrap (VOID
)
186 NTSTATUS Status
= STATUS_SUCCESS
;
187 ULONG ServerIndex
= 0;
188 ULONG ServerSequence
= 0;
190 DPRINT("CSRSRV: %s called\n", __FUNCTION__
);
192 CsrSrvSbApiPortHandle
= CsrSrvSbApiPortHandle
; //FIXME
195 Status
= CsrpCreateObjectDirectory (& CsrSrvOption
.NameSpace
.Root
);
196 if(!NT_SUCCESS(Status
))
198 DPRINT1("CSRSRV:%s: CsrpCreateObjectDirectory failed (Status=%08lx)\n",
199 __FUNCTION__
, Status
);
203 Status
= CsrSrvInitializeSession ();
204 if(!NT_SUCCESS(Status
))
206 DPRINT1("CSRSRV:%s: CsrSrvInitializeSession failed (Status=%08lx)\n",
207 __FUNCTION__
, Status
);
217 for (ServerSequence
= 0; ServerSequence
< CSR_SERVER_DLL_MAX
; ServerSequence
++)
219 for (ServerIndex
= 0; (ServerIndex
< CSR_SERVER_DLL_MAX
); ++ ServerIndex
)
221 if (ServerSequence
== ServerThread
[ServerIndex
].Sequence
)
223 if (NULL
== ServerThread
[ServerIndex
].ServerThread
)
225 Status
= CsrSrvInitializeServerDll (ServerIndex
);
226 if (!NT_SUCCESS(Status
))
228 DPRINT1("CSRSRV:%s: server thread #%d init failed!\n",
229 __FUNCTION__
, ServerIndex
);
232 DPRINT1("CSRSRV:%s: server thread #%d initialized more than once!\n",
233 __FUNCTION__
, ServerIndex
);
240 /**********************************************************************
241 * CsrSrvServerThread/1
244 * This is actually a function called by the CsrSrvMainServerThread
245 * when the server index is 0. Other server DLLs register their
246 * function with CsrAddStaticServerThread.
248 VOID STDCALL
CsrSrvServerThread (PVOID x
)
250 NTSTATUS Status
= STATUS_SUCCESS
;
251 PPORT_MESSAGE Request
= (PPORT_MESSAGE
) x
;
252 PPORT_MESSAGE Reply
= NULL
;
253 ULONG MessageType
= 0;
255 DPRINT("CSRSRV: %s called\n", __FUNCTION__
);
257 MessageType
= Request
->u2
.s2
.Type
;
258 DPRINT("CSRSRV: %s received a message (Type=%d)\n",
259 __FUNCTION__
, MessageType
);
265 Status
= NtReplyPort (CsrSrvApiPortHandle
, Reply
);
270 /**********************************************************************
272 *********************************************************************/
274 /**********************************************************************
275 * CsrAddStaticServerThread/1
277 NTSTATUS STDCALL
CsrAddStaticServerThread (CSR_SERVER_THREAD ServerThread
)
279 static ULONG StaticServerThreadCount
= 0;
280 NTSTATUS Status
= STATUS_NOT_IMPLEMENTED
;
282 DPRINT("CSRSRV: %s(%08lx) called\n", __FUNCTION__
, ServerThread
);
284 if (StaticServerThreadCount
> CSR_SERVER_DLL_MAX
)
286 DPRINT1("CSRSRV: subsystem tries to add mode than %d static threads!\n",
288 return STATUS_NO_MEMORY
;
290 if (NT_SUCCESS(Status
))
292 // FIXME: do we need to make it reentrant?
293 ++ StaticServerThreadCount
;
298 /**********************************************************************
299 * CsrCallServerFromServer
301 NTSTATUS STDCALL
CsrCallServerFromServer ()
303 NTSTATUS Status
= STATUS_NOT_IMPLEMENTED
;
305 DPRINT("CSRSRV: %s called\n", __FUNCTION__
);
309 /**********************************************************************
310 * CsrExecServerThread
312 NTSTATUS STDCALL
CsrExecServerThread ()
314 NTSTATUS Status
= STATUS_NOT_IMPLEMENTED
;
316 DPRINT("CSRSRV: %s called\n", __FUNCTION__
);
320 /**********************************************************************
321 * CsrImpersonateClient
323 NTSTATUS STDCALL
CsrImpersonateClient ()
325 NTSTATUS Status
= STATUS_NOT_IMPLEMENTED
;
327 DPRINT("CSRSRV: %s called\n", __FUNCTION__
);
331 /**********************************************************************
336 HANDLE STDCALL
CsrQueryApiPort (VOID
)
338 DPRINT("CSRSRV: %s called\n", __FUNCTION__
);
339 return CsrSrvApiPortHandle
;
342 /**********************************************************************
345 NTSTATUS STDCALL
CsrRevertToSelf ()
347 NTSTATUS Status
= STATUS_NOT_IMPLEMENTED
;
349 DPRINT("CSRSRV: %s called\n", __FUNCTION__
);
353 /**********************************************************************
354 * CsrSetBackgroundPriority
356 NTSTATUS STDCALL
CsrSetBackgroundPriority ()
358 NTSTATUS Status
= STATUS_NOT_IMPLEMENTED
;
360 DPRINT("CSRSRV: %s called\n", __FUNCTION__
);
364 /**********************************************************************
365 * CsrSetCallingSpooler
367 NTSTATUS STDCALL
CsrSetCallingSpooler ()
369 NTSTATUS Status
= STATUS_NOT_IMPLEMENTED
;
371 DPRINT("CSRSRV: %s called\n", __FUNCTION__
);
375 /**********************************************************************
376 * CsrSetForegroundPriority
378 NTSTATUS STDCALL
CsrSetForegroundPriority ()
380 NTSTATUS Status
= STATUS_NOT_IMPLEMENTED
;
382 DPRINT("CSRSRV: %s called\n", __FUNCTION__
);
386 /**********************************************************************
387 * CsrUnhandledExceptionFilter
389 NTSTATUS STDCALL
CsrUnhandledExceptionFilter ()
391 NTSTATUS Status
= STATUS_NOT_IMPLEMENTED
;
393 DPRINT("CSRSRV: %s called\n", __FUNCTION__
);
397 /**********************************************************************
398 * CsrValidateMessageBuffer
400 NTSTATUS STDCALL
CsrValidateMessageBuffer ()
402 NTSTATUS Status
= STATUS_NOT_IMPLEMENTED
;
404 DPRINT("CSRSRV: %s called\n", __FUNCTION__
);
408 /**********************************************************************
409 * CsrValidateMessageString
411 NTSTATUS STDCALL
CsrValidateMessageString ()
413 NTSTATUS Status
= STATUS_NOT_IMPLEMENTED
;
415 DPRINT("CSRSRV: %s called\n", __FUNCTION__
);