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 struct _CSRSRV_SERVER_DLL
34 USHORT Sequence
; // initialization order
35 UNICODE_STRING DllName
;
36 UNICODE_STRING DllEntryPoint
;
37 CSR_SERVER_THREAD ServerThread
; // NULL ==> inactive
39 } CSRSRV_SERVER_DLL
, *PCSRSRV_SERVER_DLL
;
41 /*=====================================================================
43 *===================================================================*/
45 CSRSRV_OPTION CsrSrvOption
;
47 HANDLE CsrSrvApiPortHandle
= (HANDLE
) 0;
49 /*=====================================================================
51 *===================================================================*/
53 static HANDLE CsrSrvSbApiPortHandle
= (HANDLE
) 0;
55 static CSRSRV_SERVER_DLL ServerThread
[CSR_SERVER_DLL_MAX
];
57 VOID CALLBACK
CsrSrvServerThread (PVOID
);
59 /**********************************************************************
60 * CsrSrvRegisterServerDll/1
62 NTSTATUS STDCALL
CsrSrvRegisterServerDll (PCSR_SERVER_DLL pServerDll
)
64 static USHORT NextInSequence
= 0;
65 USHORT ServerIndex
= 0;
68 if (0 == NextInSequence
)
70 RtlZeroMemory (ServerThread
, sizeof ServerThread
);
72 // We can not register more than CSR_SERVER_DLL_MAX servers.
73 // Note: # servers >= # DLLs (MS Win32 has 3 servers in 2 DLLs).
74 if (NextInSequence
>= CSR_SERVER_DLL_MAX
)
76 return STATUS_NO_MEMORY
;
78 // Validate the ServerIndex from the command line:
79 // it may be 0, 1, 2, or 3.
80 ServerIndex
= pServerDll
->ServerIndex
;
81 if (ServerIndex
>= CSR_SERVER_DLL_MAX
)
83 return STATUS_INVALID_PARAMETER
;
85 // Register the DLL server.
86 ServerThread
[ServerIndex
].ServerIndex
= ServerIndex
;
87 ServerThread
[ServerIndex
].Sequence
= NextInSequence
++;
90 RtlDuplicateUnicodeString (1, & pServerDll
->DllName
, & ServerThread
[ServerIndex
].DllName
);
91 RtlDuplicateUnicodeString (1, & pServerDll
->DllEntryPoint
, & ServerThread
[ServerIndex
].DllEntryPoint
);
93 // CSRSRV.DLL own static server thread
94 ServerThread
[ServerIndex
].ServerThread
= CsrSrvServerThread
;
96 return STATUS_SUCCESS
;
98 /**********************************************************************
99 * CsrpCreateObjectDirectory/1 PRIVATE
101 NTSTATUS STDCALL
CsrpCreateObjectDirectory (PUNICODE_STRING pObjectDirectory
)
103 NTSTATUS Status
= STATUS_SUCCESS
;
104 OBJECT_ATTRIBUTES DirectoryAttributes
;
106 DPRINT("CSRSRV:%s(%S) called\n", __FUNCTION__
, pObjectDirectory
->Buffer
);
108 InitializeObjectAttributes (& DirectoryAttributes
,
114 Status
= NtCreateDirectoryObject (& CsrSrvOption
.NameSpace
.RootHandle
,
115 (DIRECTORY_CREATE_OBJECT
|DIRECTORY_CREATE_SUBDIRECTORY
),
116 & DirectoryAttributes
);
117 if (NT_SUCCESS(Status
))
119 Status
= RtlDuplicateUnicodeString (0, pObjectDirectory
, & CsrSrvOption
.NameSpace
.Root
);
120 if (!NT_SUCCESS(Status
))
122 DPRINT1("CSRSRV:%s: RtlDuplicateUnicodeString failed (Status=0x%08lx)\n",
123 __FUNCTION__
, Status
);
126 DPRINT1("CSRSRV:%s: fatal: NtCreateDirectoryObject failed (Status=0x%08lx)\n",
127 __FUNCTION__
, Status
);
131 /**********************************************************************
135 * This is where a subsystem begins living.
137 NTSTATUS STDCALL
CsrSrvBootstrap (VOID
)
139 NTSTATUS Status
= STATUS_SUCCESS
;
140 ULONG ServerIndex
= 0;
141 ULONG ServerSequence
= 0;
143 DPRINT("CSRSRV: %s called\n", __FUNCTION__
);
145 CsrSrvSbApiPortHandle
= CsrSrvSbApiPortHandle
; //FIXME
148 Status
= CsrpCreateObjectDirectory (& CsrSrvOption
.NameSpace
.Root
);
149 if(!NT_SUCCESS(Status
))
151 DPRINT1("CSRSRV:%s: CsrpCreateObjectDirectory failed (Status=%08lx)\n",
152 __FUNCTION__
, Status
);
156 Status
= CsrSrvInitializeSession ();
157 if(!NT_SUCCESS(Status
))
159 DPRINT1("CSRSRV:%s: CsrSrvInitializeSession failed (Status=%08lx)\n",
160 __FUNCTION__
, Status
);
170 for (ServerSequence
= 0; ServerSequence
< CSR_SERVER_DLL_MAX
; ServerSequence
++)
172 for (ServerIndex
= 0; (ServerIndex
< CSR_SERVER_DLL_MAX
); ++ ServerIndex
)
174 if (ServerSequence
== ServerThread
[ServerIndex
].Sequence
)
176 if (NULL
== ServerThread
[ServerIndex
].ServerThread
)
178 //TODO: load DLL and call ServerDllInitialize
185 /**********************************************************************
186 * CsrSrvServerThread/1
189 * This is actually a function called by the CsrSrvMainServerThread
190 * when the server index is 0. Other server DLLs register their
191 * function with CsrAddStaticServerThread.
193 VOID STDCALL
CsrSrvServerThread (PVOID x
)
195 NTSTATUS Status
= STATUS_SUCCESS
;
196 PPORT_MESSAGE Request
= (PPORT_MESSAGE
) x
;
197 PPORT_MESSAGE Reply
= NULL
;
198 ULONG MessageType
= 0;
200 DPRINT("CSRSRV: %s called\n", __FUNCTION__
);
202 MessageType
= Request
->u2
.s2
.Type
;
203 DPRINT("CSRSRV: %s received a message (Type=%d)\n",
204 __FUNCTION__
, MessageType
);
210 Status
= NtReplyPort (CsrSrvApiPortHandle
, Reply
);
215 /**********************************************************************
217 *********************************************************************/
219 /**********************************************************************
220 * CsrAddStaticServerThread/1
222 NTSTATUS STDCALL
CsrAddStaticServerThread (CSR_SERVER_THREAD ServerThread
)
224 static ULONG StaticServerThreadCount
= 0;
225 NTSTATUS Status
= STATUS_NOT_IMPLEMENTED
;
227 DPRINT("CSRSRV: %s(%08lx) called\n", __FUNCTION__
, ServerThread
);
229 if (StaticServerThreadCount
> CSR_SERVER_DLL_MAX
)
231 DPRINT1("CSRSRV: subsystem tries to add mode than %d static threads!\n",
233 return STATUS_NO_MEMORY
;
235 if (NT_SUCCESS(Status
))
237 // FIXME: do we need to make it reentrant?
238 ++ StaticServerThreadCount
;
243 /**********************************************************************
244 * CsrCallServerFromServer
246 NTSTATUS STDCALL
CsrCallServerFromServer ()
248 NTSTATUS Status
= STATUS_NOT_IMPLEMENTED
;
250 DPRINT("CSRSRV: %s called\n", __FUNCTION__
);
254 /**********************************************************************
255 * CsrExecServerThread
257 NTSTATUS STDCALL
CsrExecServerThread ()
259 NTSTATUS Status
= STATUS_NOT_IMPLEMENTED
;
261 DPRINT("CSRSRV: %s called\n", __FUNCTION__
);
265 /**********************************************************************
266 * CsrImpersonateClient
268 NTSTATUS STDCALL
CsrImpersonateClient ()
270 NTSTATUS Status
= STATUS_NOT_IMPLEMENTED
;
272 DPRINT("CSRSRV: %s called\n", __FUNCTION__
);
276 /**********************************************************************
281 HANDLE STDCALL
CsrQueryApiPort (VOID
)
283 DPRINT("CSRSRV: %s called\n", __FUNCTION__
);
284 return CsrSrvApiPortHandle
;
287 /**********************************************************************
290 NTSTATUS STDCALL
CsrRevertToSelf ()
292 NTSTATUS Status
= STATUS_NOT_IMPLEMENTED
;
294 DPRINT("CSRSRV: %s called\n", __FUNCTION__
);
298 /**********************************************************************
299 * CsrSetBackgroundPriority
301 NTSTATUS STDCALL
CsrSetBackgroundPriority ()
303 NTSTATUS Status
= STATUS_NOT_IMPLEMENTED
;
305 DPRINT("CSRSRV: %s called\n", __FUNCTION__
);
309 /**********************************************************************
310 * CsrSetCallingSpooler
312 NTSTATUS STDCALL
CsrSetCallingSpooler ()
314 NTSTATUS Status
= STATUS_NOT_IMPLEMENTED
;
316 DPRINT("CSRSRV: %s called\n", __FUNCTION__
);
320 /**********************************************************************
321 * CsrSetForegroundPriority
323 NTSTATUS STDCALL
CsrSetForegroundPriority ()
325 NTSTATUS Status
= STATUS_NOT_IMPLEMENTED
;
327 DPRINT("CSRSRV: %s called\n", __FUNCTION__
);
331 /**********************************************************************
332 * CsrUnhandledExceptionFilter
334 NTSTATUS STDCALL
CsrUnhandledExceptionFilter ()
336 NTSTATUS Status
= STATUS_NOT_IMPLEMENTED
;
338 DPRINT("CSRSRV: %s called\n", __FUNCTION__
);
342 /**********************************************************************
343 * CsrValidateMessageBuffer
345 NTSTATUS STDCALL
CsrValidateMessageBuffer ()
347 NTSTATUS Status
= STATUS_NOT_IMPLEMENTED
;
349 DPRINT("CSRSRV: %s called\n", __FUNCTION__
);
353 /**********************************************************************
354 * CsrValidateMessageString
356 NTSTATUS STDCALL
CsrValidateMessageString ()
358 NTSTATUS Status
= STATUS_NOT_IMPLEMENTED
;
360 DPRINT("CSRSRV: %s called\n", __FUNCTION__
);