51adb2cacca8a2ad01b7c643180e0a0e4b95a33c
[reactos.git] / reactos / subsystems / win32 / csrss / csrsrv / init.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS CSR Sub System
4 * FILE: subsys/csr/csrsrv/init.c
5 * PURPOSE: CSR Server DLL Initialization
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9 /* INCLUDES *******************************************************************/
10
11 #include "srv.h"
12 #define NDEBUG
13 #include <debug.h>
14
15 /* DATA ***********************************************************************/
16
17 HANDLE CsrHeap = (HANDLE) 0;
18 HANDLE CsrObjectDirectory = (HANDLE) 0;
19 UNICODE_STRING CsrDirectoryName;
20 extern HANDLE CsrssApiHeap;
21 static unsigned InitCompleteProcCount;
22 static CSRPLUGIN_INIT_COMPLETE_PROC *InitCompleteProcs = NULL;
23 static unsigned HardErrorProcCount;
24 static CSRPLUGIN_HARDERROR_PROC *HardErrorProcs = NULL;
25 HANDLE hSbApiPort = (HANDLE) 0;
26 HANDLE hBootstrapOk = (HANDLE) 0;
27 HANDLE hSmApiPort = (HANDLE) 0;
28 HANDLE hApiPort = (HANDLE) 0;
29
30 /* PRIVATE FUNCTIONS **********************************************************/
31
32 ULONG
33 InitializeVideoAddressSpace(VOID)
34 {
35 OBJECT_ATTRIBUTES ObjectAttributes;
36 UNICODE_STRING PhysMemName = RTL_CONSTANT_STRING(L"\\Device\\PhysicalMemory");
37 NTSTATUS Status;
38 HANDLE PhysMemHandle;
39 PVOID BaseAddress;
40 LARGE_INTEGER Offset;
41 SIZE_T ViewSize;
42 CHAR IVTAndBda[1024+256];
43
44 /* Open the physical memory section */
45 InitializeObjectAttributes(&ObjectAttributes,
46 &PhysMemName,
47 0,
48 NULL,
49 NULL);
50 Status = ZwOpenSection(&PhysMemHandle,
51 SECTION_ALL_ACCESS,
52 &ObjectAttributes);
53 if (!NT_SUCCESS(Status))
54 {
55 DPRINT1("Couldn't open \\Device\\PhysicalMemory\n");
56 return 0;
57 }
58
59 /* Map the BIOS and device registers into the address space */
60 Offset.QuadPart = 0xa0000;
61 ViewSize = 0x100000 - 0xa0000;
62 BaseAddress = (PVOID)0xa0000;
63 Status = ZwMapViewOfSection(PhysMemHandle,
64 NtCurrentProcess(),
65 &BaseAddress,
66 0,
67 ViewSize,
68 &Offset,
69 &ViewSize,
70 ViewUnmap,
71 0,
72 PAGE_EXECUTE_READWRITE);
73 if (!NT_SUCCESS(Status))
74 {
75 DPRINT1("Couldn't map physical memory (%x)\n", Status);
76 ZwClose(PhysMemHandle);
77 return 0;
78 }
79
80 /* Close physical memory section handle */
81 ZwClose(PhysMemHandle);
82
83 if (BaseAddress != (PVOID)0xa0000)
84 {
85 DPRINT1("Couldn't map physical memory at the right address (was %x)\n",
86 BaseAddress);
87 return 0;
88 }
89
90 /* Allocate some low memory to use for the non-BIOS
91 * parts of the v86 mode address space
92 */
93 BaseAddress = (PVOID)0x1;
94 ViewSize = 0xa0000 - 0x1000;
95 Status = ZwAllocateVirtualMemory(NtCurrentProcess(),
96 &BaseAddress,
97 0,
98 &ViewSize,
99 MEM_COMMIT,
100 PAGE_EXECUTE_READWRITE);
101 if (!NT_SUCCESS(Status))
102 {
103 DPRINT1("Failed to allocate virtual memory (Status %x)\n", Status);
104 return 0;
105 }
106 if (BaseAddress != (PVOID)0x0)
107 {
108 DPRINT1("Failed to allocate virtual memory at right address (was %x)\n",
109 BaseAddress);
110 return 0;
111 }
112
113 /* Get the real mode IVT and BDA from the kernel */
114 Status = NtVdmControl(VdmInitialize, IVTAndBda);
115 if (!NT_SUCCESS(Status))
116 {
117 DPRINT1("NtVdmControl failed (status %x)\n", Status);
118 return 0;
119 }
120
121 /* Return success */
122 return 1;
123 }
124
125
126 static NTSTATUS FASTCALL
127 CsrpAddInitCompleteProc(CSRPLUGIN_INIT_COMPLETE_PROC Proc)
128 {
129 CSRPLUGIN_INIT_COMPLETE_PROC *NewProcs;
130
131 DPRINT("CSR: %s called\n", __FUNCTION__);
132
133 NewProcs = RtlAllocateHeap(CsrssApiHeap, 0,
134 (InitCompleteProcCount + 1)
135 * sizeof(CSRPLUGIN_INIT_COMPLETE_PROC));
136 if (NULL == NewProcs)
137 {
138 return STATUS_NO_MEMORY;
139 }
140 if (0 != InitCompleteProcCount)
141 {
142 RtlCopyMemory(NewProcs, InitCompleteProcs,
143 InitCompleteProcCount * sizeof(CSRPLUGIN_INIT_COMPLETE_PROC));
144 RtlFreeHeap(CsrssApiHeap, 0, InitCompleteProcs);
145 }
146 NewProcs[InitCompleteProcCount] = Proc;
147 InitCompleteProcs = NewProcs;
148 InitCompleteProcCount++;
149
150 return STATUS_SUCCESS;
151 }
152
153 static NTSTATUS FASTCALL
154 CsrpAddHardErrorProc(CSRPLUGIN_HARDERROR_PROC Proc)
155 {
156 CSRPLUGIN_HARDERROR_PROC *NewProcs;
157
158 DPRINT("CSR: %s called\n", __FUNCTION__);
159
160 NewProcs = RtlAllocateHeap(CsrssApiHeap, 0,
161 (HardErrorProcCount + 1)
162 * sizeof(CSRPLUGIN_HARDERROR_PROC));
163 if (NULL == NewProcs)
164 {
165 return STATUS_NO_MEMORY;
166 }
167 if (0 != HardErrorProcCount)
168 {
169 RtlCopyMemory(NewProcs, HardErrorProcs,
170 HardErrorProcCount * sizeof(CSRPLUGIN_HARDERROR_PROC));
171 RtlFreeHeap(CsrssApiHeap, 0, HardErrorProcs);
172 }
173
174 NewProcs[HardErrorProcCount] = Proc;
175 HardErrorProcs = NewProcs;
176 HardErrorProcCount++;
177
178 return STATUS_SUCCESS;
179 }
180
181 /**********************************************************************
182 * CallInitComplete/0
183 */
184 static BOOL FASTCALL
185 CallInitComplete(void)
186 {
187 BOOL Ok;
188 unsigned i;
189
190 DPRINT("CSR: %s called\n", __FUNCTION__);
191
192 Ok = TRUE;
193 if (0 != InitCompleteProcCount)
194 {
195 for (i = 0; i < InitCompleteProcCount && Ok; i++)
196 {
197 Ok = (*(InitCompleteProcs[i]))();
198 }
199 RtlFreeHeap(CsrssApiHeap, 0, InitCompleteProcs);
200 }
201
202 return Ok;
203 }
204
205 BOOL
206 CallHardError(IN PCSRSS_PROCESS_DATA ProcessData,
207 IN PHARDERROR_MSG HardErrorMessage)
208 {
209 BOOL Ok;
210 unsigned i;
211
212 DPRINT("CSR: %s called\n", __FUNCTION__);
213
214 Ok = TRUE;
215 if (0 != HardErrorProcCount)
216 {
217 for (i = 0; i < HardErrorProcCount && Ok; i++)
218 {
219 Ok = (*(HardErrorProcs[i]))(ProcessData, HardErrorMessage);
220 }
221 }
222
223 return Ok;
224 }
225
226 ULONG
227 InitializeVideoAddressSpace(VOID);
228
229 /**********************************************************************
230 * CsrpCreateObjectDirectory/3
231 */
232 static NTSTATUS
233 CsrpCreateObjectDirectory (int argc, char ** argv, char ** envp)
234 {
235 NTSTATUS Status;
236 OBJECT_ATTRIBUTES Attributes;
237
238 DPRINT("CSR: %s called\n", __FUNCTION__);
239
240
241 /* create object directory ('\Windows') */
242 RtlCreateUnicodeString (&CsrDirectoryName,
243 L"\\Windows");
244
245 InitializeObjectAttributes (&Attributes,
246 &CsrDirectoryName,
247 OBJ_OPENIF,
248 NULL,
249 NULL);
250
251 Status = NtOpenDirectoryObject(&CsrObjectDirectory,
252 DIRECTORY_ALL_ACCESS,
253 &Attributes);
254 return Status;
255 }
256
257 /**********************************************************************
258 * CsrpInitVideo/3
259 *
260 * TODO: we need a virtual device for sessions other than
261 * TODO: the console one
262 */
263 static NTSTATUS
264 CsrpInitVideo (int argc, char ** argv, char ** envp)
265 {
266 OBJECT_ATTRIBUTES ObjectAttributes;
267 UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\??\\DISPLAY1");
268 IO_STATUS_BLOCK Iosb;
269 HANDLE VideoHandle = (HANDLE) 0;
270 NTSTATUS Status = STATUS_SUCCESS;
271
272 DPRINT("CSR: %s called\n", __FUNCTION__);
273
274 InitializeVideoAddressSpace();
275
276 InitializeObjectAttributes(&ObjectAttributes,
277 &DeviceName,
278 0,
279 NULL,
280 NULL);
281 Status = NtOpenFile(&VideoHandle,
282 FILE_ALL_ACCESS,
283 &ObjectAttributes,
284 &Iosb,
285 0,
286 0);
287 if (NT_SUCCESS(Status))
288 {
289 NtClose(VideoHandle);
290 }
291 return Status;
292 }
293
294 /**********************************************************************
295 * CsrpInitWin32Csr/3
296 *
297 * TODO: this function should be turned more general to load an
298 * TODO: hosted server DLL as received from the command line;
299 * TODO: for instance: ServerDll=winsrv:ConServerDllInitialization,2
300 * TODO: ^method ^dll ^api ^sid
301 * TODO:
302 * TODO: CsrpHostServerDll (LPWSTR DllName,
303 * TODO: LPWSTR ApiName,
304 * TODO: DWORD ServerId)
305 */
306 static NTSTATUS
307 CsrpInitWin32Csr (int argc, char ** argv, char ** envp)
308 {
309 NTSTATUS Status;
310 UNICODE_STRING DllName;
311 HINSTANCE hInst;
312 ANSI_STRING ProcName;
313 CSRPLUGIN_INITIALIZE_PROC InitProc;
314 CSRSS_EXPORTED_FUNCS Exports;
315 PCSRSS_API_DEFINITION ApiDefinitions;
316 PCSRSS_OBJECT_DEFINITION ObjectDefinitions;
317 CSRPLUGIN_INIT_COMPLETE_PROC InitCompleteProc;
318 CSRPLUGIN_HARDERROR_PROC HardErrorProc;
319
320 DPRINT("CSR: %s called\n", __FUNCTION__);
321
322 RtlInitUnicodeString(&DllName, L"win32csr.dll");
323 Status = LdrLoadDll(NULL, 0, &DllName, (PVOID *) &hInst);
324 if (! NT_SUCCESS(Status))
325 {
326 return Status;
327 }
328 RtlInitAnsiString(&ProcName, "Win32CsrInitialization");
329 Status = LdrGetProcedureAddress(hInst, &ProcName, 0, (PVOID *) &InitProc);
330 if (! NT_SUCCESS(Status))
331 {
332 return Status;
333 }
334 Exports.CsrInsertObjectProc = CsrInsertObject;
335 Exports.CsrGetObjectProc = CsrGetObject;
336 Exports.CsrReleaseObjectByPointerProc = CsrReleaseObjectByPointer;
337 Exports.CsrReleaseObjectProc = CsrReleaseObject;
338 Exports.CsrEnumProcessesProc = CsrEnumProcesses;
339 if (! (*InitProc)(&ApiDefinitions, &ObjectDefinitions, &InitCompleteProc,
340 &HardErrorProc, &Exports, CsrssApiHeap))
341 {
342 return STATUS_UNSUCCESSFUL;
343 }
344
345 Status = CsrApiRegisterDefinitions(ApiDefinitions);
346 if (! NT_SUCCESS(Status))
347 {
348 return Status;
349 }
350 Status = CsrRegisterObjectDefinitions(ObjectDefinitions);
351 if (! NT_SUCCESS(Status))
352 {
353 return Status;
354 }
355 if (NULL != InitCompleteProc)
356 {
357 Status = CsrpAddInitCompleteProc(InitCompleteProc);
358 }
359 if (HardErrorProc) Status = CsrpAddHardErrorProc(HardErrorProc);
360
361 return Status;
362 }
363
364 CSRSS_API_DEFINITION NativeDefinitions[] =
365 {
366 CSRSS_DEFINE_API(CREATE_PROCESS, CsrCreateProcess),
367 CSRSS_DEFINE_API(CREATE_THREAD, CsrSrvCreateThread),
368 CSRSS_DEFINE_API(TERMINATE_PROCESS, CsrTerminateProcess),
369 CSRSS_DEFINE_API(CONNECT_PROCESS, CsrConnectProcess),
370 CSRSS_DEFINE_API(REGISTER_SERVICES_PROCESS, CsrRegisterServicesProcess),
371 CSRSS_DEFINE_API(GET_SHUTDOWN_PARAMETERS, CsrGetShutdownParameters),
372 CSRSS_DEFINE_API(SET_SHUTDOWN_PARAMETERS, CsrSetShutdownParameters),
373 CSRSS_DEFINE_API(GET_INPUT_HANDLE, CsrGetInputHandle),
374 CSRSS_DEFINE_API(GET_OUTPUT_HANDLE, CsrGetOutputHandle),
375 CSRSS_DEFINE_API(CLOSE_HANDLE, CsrCloseHandle),
376 CSRSS_DEFINE_API(VERIFY_HANDLE, CsrVerifyHandle),
377 CSRSS_DEFINE_API(DUPLICATE_HANDLE, CsrDuplicateHandle),
378 CSRSS_DEFINE_API(GET_INPUT_WAIT_HANDLE, CsrGetInputWaitHandle),
379 { 0, 0, NULL }
380 };
381
382 static NTSTATUS WINAPI
383 CsrpCreateListenPort (IN LPWSTR Name,
384 IN OUT PHANDLE Port,
385 IN PTHREAD_START_ROUTINE ListenThread)
386 {
387 NTSTATUS Status = STATUS_SUCCESS;
388 OBJECT_ATTRIBUTES PortAttributes;
389 UNICODE_STRING PortName;
390 HANDLE ServerThread;
391 CLIENT_ID ClientId;
392
393 DPRINT("CSR: %s called\n", __FUNCTION__);
394
395 RtlInitUnicodeString (& PortName, Name);
396 InitializeObjectAttributes (& PortAttributes,
397 & PortName,
398 0,
399 NULL,
400 NULL);
401 Status = NtCreatePort ( Port,
402 & PortAttributes,
403 LPC_MAX_DATA_LENGTH, /* TODO: make caller set it*/
404 LPC_MAX_MESSAGE_LENGTH, /* TODO: make caller set it*/
405 0); /* TODO: make caller set it*/
406 if(!NT_SUCCESS(Status))
407 {
408 DPRINT1("CSR: %s: NtCreatePort failed (Status=%08lx)\n",
409 __FUNCTION__, Status);
410 return Status;
411 }
412 Status = RtlCreateUserThread(NtCurrentProcess(),
413 NULL,
414 TRUE,
415 0,
416 0,
417 0,
418 (PTHREAD_START_ROUTINE) ListenThread,
419 *Port,
420 &ServerThread,
421 &ClientId);
422
423 if (ListenThread == (PVOID)ClientConnectionThread)
424 {
425 CsrAddStaticServerThread(ServerThread, &ClientId, 0);
426 }
427
428 NtResumeThread(ServerThread, NULL);
429 NtClose(ServerThread);
430 return Status;
431 }
432
433 /* === INIT ROUTINES === */
434
435 /**********************************************************************
436 * CsrpCreateBNODirectory/3
437 *
438 * These used to be part of kernel32 startup, but that clearly wasn't a good
439 * idea, as races were definately possible. These are moved (as in the
440 * previous fixmes).
441 */
442 static NTSTATUS
443 CsrpCreateBNODirectory (int argc, char ** argv, char ** envp)
444 {
445 NTSTATUS Status;
446 OBJECT_ATTRIBUTES ObjectAttributes;
447 UNICODE_STRING Name = RTL_CONSTANT_STRING(L"\\BaseNamedObjects");
448 UNICODE_STRING SymName = RTL_CONSTANT_STRING(L"Local");
449 UNICODE_STRING SymName2 = RTL_CONSTANT_STRING(L"Global");
450 HANDLE DirHandle, SymHandle;
451
452 /* Seems like a good place to create these objects which are needed by
453 * win32 processes */
454 InitializeObjectAttributes(&ObjectAttributes,
455 &Name,
456 OBJ_CASE_INSENSITIVE,
457 NULL,
458 NULL);
459
460 Status = NtCreateDirectoryObject(&DirHandle,
461 DIRECTORY_ALL_ACCESS,
462 &ObjectAttributes);
463 if (!NT_SUCCESS(Status))
464 {
465 DPRINT1("NtCreateDirectoryObject() failed %08x\n", Status);
466 }
467
468 /* Create the "local" Symbolic Link.
469 * FIXME: CSR should do this -- Fixed */
470 InitializeObjectAttributes(&ObjectAttributes,
471 &SymName,
472 OBJ_CASE_INSENSITIVE,
473 DirHandle,
474 NULL);
475 Status = NtCreateSymbolicLinkObject(&SymHandle,
476 SYMBOLIC_LINK_ALL_ACCESS,
477 &ObjectAttributes,
478 &Name);
479 if (!NT_SUCCESS(Status))
480 {
481 DPRINT1("NtCreateDirectoryObject() failed %08x\n", Status);
482 }
483
484 /* Create the "global" Symbolic Link. */
485 InitializeObjectAttributes(&ObjectAttributes,
486 &SymName2,
487 OBJ_CASE_INSENSITIVE,
488 DirHandle,
489 NULL);
490 Status = NtCreateSymbolicLinkObject(&SymHandle,
491 SYMBOLIC_LINK_ALL_ACCESS,
492 &ObjectAttributes,
493 &Name);
494 if (!NT_SUCCESS(Status))
495 {
496 DPRINT1("NtCreateDirectoryObject() failed %08x\n", Status);
497 }
498
499 return Status;
500 }
501
502 /**********************************************************************
503 * CsrpCreateHeap/3
504 */
505 static NTSTATUS
506 CsrpCreateHeap (int argc, char ** argv, char ** envp)
507 {
508 DPRINT("CSR: %s called\n", __FUNCTION__);
509
510 CsrssApiHeap = RtlCreateHeap(HEAP_GROWABLE,
511 NULL,
512 65536,
513 65536,
514 NULL,
515 NULL);
516 if (CsrssApiHeap == NULL)
517 {
518 return STATUS_UNSUCCESSFUL;
519 }
520 return STATUS_SUCCESS;
521 }
522
523 /**********************************************************************
524 * CsrpCreateCallbackPort/3
525 */
526 static NTSTATUS
527 CsrpCreateCallbackPort (int argc, char ** argv, char ** envp)
528 {
529 DPRINT("CSR: %s called\n", __FUNCTION__);
530
531 return CsrpCreateListenPort (L"\\Windows\\SbApiPort",
532 & hSbApiPort,
533 ServerSbApiPortThread);
534 }
535
536 /**********************************************************************
537 * CsrpRegisterSubsystem/3
538 */
539 static NTSTATUS
540 CsrpRegisterSubsystem (int argc, char ** argv, char ** envp)
541 {
542 NTSTATUS Status = STATUS_SUCCESS;
543 OBJECT_ATTRIBUTES BootstrapOkAttributes;
544 UNICODE_STRING Name;
545
546 DPRINT("CSR: %s called\n", __FUNCTION__);
547
548 /*
549 * Create the event object the callback port
550 * thread will signal *if* the SM will
551 * authorize us to bootstrap.
552 */
553 RtlInitUnicodeString (& Name, L"\\CsrssBooting");
554 InitializeObjectAttributes(& BootstrapOkAttributes,
555 & Name,
556 0, NULL, NULL);
557 Status = NtCreateEvent (& hBootstrapOk,
558 EVENT_ALL_ACCESS,
559 & BootstrapOkAttributes,
560 SynchronizationEvent,
561 FALSE);
562 if(!NT_SUCCESS(Status))
563 {
564 DPRINT("CSR: %s: NtCreateEvent failed (Status=0x%08lx)\n",
565 __FUNCTION__, Status);
566 return Status;
567 }
568 /*
569 * Let's tell the SM a new environment
570 * subsystem server is in the system.
571 */
572 RtlInitUnicodeString (& Name, L"\\Windows\\SbApiPort");
573 DPRINT("CSR: %s: registering with SM for\n IMAGE_SUBSYSTEM_WINDOWS_CUI == 3\n", __FUNCTION__);
574 Status = SmConnectApiPort (& Name,
575 hSbApiPort,
576 IMAGE_SUBSYSTEM_WINDOWS_CUI,
577 & hSmApiPort);
578 if(!NT_SUCCESS(Status))
579 {
580 DPRINT("CSR: %s unable to connect to the SM (Status=0x%08lx)\n",
581 __FUNCTION__, Status);
582 NtClose (hBootstrapOk);
583 return Status;
584 }
585 /*
586 * Wait for SM to reply OK... If the SM
587 * won't answer, we hang here forever!
588 */
589 DPRINT("CSR: %s: waiting for SM to OK boot...\n", __FUNCTION__);
590 Status = NtWaitForSingleObject (hBootstrapOk,
591 FALSE,
592 NULL);
593 NtClose (hBootstrapOk);
594 return Status;
595 }
596
597 /**********************************************************************
598 * CsrpLoadKernelModeDriver/3
599 */
600 static NTSTATUS
601 CsrpLoadKernelModeDriver (int argc, char ** argv, char ** envp)
602 {
603 NTSTATUS Status = STATUS_SUCCESS;
604 WCHAR Data [MAX_PATH + 1];
605 ULONG DataLength = sizeof Data;
606 ULONG DataType = 0;
607 //UNICODE_STRING Environment;
608
609
610 DPRINT1("SM: %s called\n", __FUNCTION__);
611
612
613 //EnvpToUnicodeString (envp, & Environment);
614 Status = SmLookupSubsystem (L"Kmode",
615 Data,
616 & DataLength,
617 & DataType,
618 NULL);
619 //RtlFreeUnicodeString (& Environment);
620 if((STATUS_SUCCESS == Status) && (DataLength > sizeof Data[0]))
621 {
622 WCHAR ImagePath [MAX_PATH + 1] = {0};
623 UNICODE_STRING ModuleName;
624
625 wcscpy (ImagePath, L"\\SYSTEMROOT\\system32\\win32k.sys");
626 // wcscat (ImagePath, Data);
627 RtlInitUnicodeString (& ModuleName, ImagePath);
628 Status = NtSetSystemInformation(/* FIXME: SystemLoadAndCallImage */
629 SystemExtendServiceTableInformation,
630 & ModuleName,
631 sizeof ModuleName);
632 if(!NT_SUCCESS(Status))
633 {
634 DPRINT1("WIN: %s: loading Kmode failed (Status=0x%08lx)\n",
635 __FUNCTION__, Status);
636 }
637 }
638 return Status;
639 }
640
641 /**********************************************************************
642 * CsrpCreateApiPort/2
643 */
644 static NTSTATUS
645 CsrpCreateApiPort (int argc, char ** argv, char ** envp)
646 {
647 DPRINT("CSR: %s called\n", __FUNCTION__);
648
649 CsrInitProcessData();
650
651 return CsrpCreateListenPort(L"\\Windows\\ApiPort", &hApiPort,
652 (PTHREAD_START_ROUTINE)ClientConnectionThread);
653 }
654
655 /**********************************************************************
656 * CsrpApiRegisterDef/0
657 */
658 static NTSTATUS
659 CsrpApiRegisterDef (int argc, char ** argv, char ** envp)
660 {
661 return CsrApiRegisterDefinitions(NativeDefinitions);
662 }
663
664 /**********************************************************************
665 * CsrpCCTS/2
666 */
667 static NTSTATUS
668 CsrpCCTS (int argc, char ** argv, char ** envp)
669 {
670 ULONG Dummy;
671 ULONG DummyLength = sizeof(Dummy);
672 return CsrClientConnectToServer(L"\\Windows",
673 0, &Dummy, &DummyLength, NULL);
674 }
675
676 /**********************************************************************
677 * CsrpRunWinlogon/0
678 *
679 * Start the logon process (winlogon.exe).
680 *
681 * TODO: this should be moved in CsrpCreateSession/x (one per session)
682 * TODO: in its own desktop (one logon desktop per winstation).
683 */
684 static NTSTATUS
685 CsrpRunWinlogon (int argc, char ** argv, char ** envp)
686 {
687 NTSTATUS Status = STATUS_SUCCESS;
688 UNICODE_STRING ImagePath;
689 UNICODE_STRING CommandLine;
690 PRTL_USER_PROCESS_PARAMETERS ProcessParameters = NULL;
691 RTL_USER_PROCESS_INFORMATION ProcessInfo;
692
693
694 DPRINT("CSR: %s called\n", __FUNCTION__);
695
696 /* initialize the process parameters */
697 RtlInitUnicodeString (& ImagePath, L"\\SystemRoot\\system32\\winlogon.exe");
698 RtlInitUnicodeString (& CommandLine, L"");
699 RtlCreateProcessParameters(& ProcessParameters,
700 & ImagePath,
701 NULL,
702 NULL,
703 & CommandLine,
704 NULL,
705 NULL,
706 NULL,
707 NULL,
708 NULL);
709 /* Create the winlogon process */
710 Status = RtlCreateUserProcess (& ImagePath,
711 OBJ_CASE_INSENSITIVE,
712 ProcessParameters,
713 NULL,
714 NULL,
715 NULL,
716 FALSE,
717 NULL,
718 NULL,
719 & ProcessInfo);
720 /* Cleanup */
721 RtlDestroyProcessParameters (ProcessParameters);
722 if (!NT_SUCCESS(Status))
723 {
724 DPRINT1("SM: %s: loading winlogon.exe failed (Status=%08lx)\n",
725 __FUNCTION__, Status);
726 }
727
728 ZwResumeThread(ProcessInfo.ThreadHandle, NULL);
729 return Status;
730 }
731
732 static NTSTATUS
733 CsrpCreateHardErrorPort (int argc, char ** argv, char ** envp)
734 {
735 return NtSetDefaultHardErrorPort(hApiPort);
736 }
737
738 typedef NTSTATUS (* CSR_INIT_ROUTINE)(int,char**,char**);
739
740 struct {
741 BOOL Required;
742 CSR_INIT_ROUTINE EntryPoint;
743 PCHAR ErrorMessage;
744 } InitRoutine [] = {
745 {TRUE, CsrpCreateBNODirectory, "create base named objects directory"},
746 {TRUE, CsrpCreateCallbackPort, "create the callback port \\Windows\\SbApiPort"},
747 {TRUE, CsrpRegisterSubsystem, "register with SM"},
748 {TRUE, CsrpCreateHeap, "create the CSR heap"},
749 {TRUE, CsrpCreateApiPort, "create the api port \\Windows\\ApiPort"},
750 {TRUE, CsrpCreateHardErrorPort, "create the hard error port"},
751 {TRUE, CsrpCreateObjectDirectory,"create the object directory \\Windows"},
752 {TRUE, CsrpLoadKernelModeDriver, "load Kmode driver"},
753 {TRUE, CsrpInitVideo, "initialize video"},
754 {TRUE, CsrpApiRegisterDef, "initialize api definitions"},
755 {TRUE, CsrpCCTS, "connect client to server"},
756 {TRUE, CsrpInitWin32Csr, "load usermode dll"},
757 {TRUE, CsrpRunWinlogon, "run WinLogon"},
758 };
759
760 /* PUBLIC FUNCTIONS ***********************************************************/
761
762 NTSTATUS
763 NTAPI
764 CsrServerInitialization(ULONG ArgumentCount,
765 PCHAR Arguments[])
766 {
767 UINT i = 0;
768 NTSTATUS Status = STATUS_SUCCESS;
769
770 DPRINT("CSR: %s called\n", __FUNCTION__);
771
772 for (i=0; i < (sizeof InitRoutine / sizeof InitRoutine[0]); i++)
773 {
774 Status = InitRoutine[i].EntryPoint(ArgumentCount,Arguments,NULL);
775 if(!NT_SUCCESS(Status))
776 {
777 DPRINT1("CSR: %s: failed to %s (Status=%08lx)\n",
778 __FUNCTION__,
779 InitRoutine[i].ErrorMessage,
780 Status);
781 if (InitRoutine[i].Required)
782 {
783 return FALSE;
784 }
785 }
786 }
787 if (CallInitComplete())
788 {
789 Status = SmCompleteSession (hSmApiPort,hSbApiPort,hApiPort);
790 return STATUS_SUCCESS;
791 }
792
793 return STATUS_UNSUCCESSFUL;
794 }
795
796 BOOL
797 NTAPI
798 DllMainCRTStartup(HANDLE hDll,
799 DWORD dwReason,
800 LPVOID lpReserved)
801 {
802 /* We don't do much */
803 UNREFERENCED_PARAMETER(hDll);
804 UNREFERENCED_PARAMETER(dwReason);
805 UNREFERENCED_PARAMETER(lpReserved);
806 return TRUE;
807 }
808
809 /* EOF */