f9ff6a882873c88d71ff4134efdea6a2228ac418
[reactos.git] / reactos / subsys / smss / initss.c
1 /* $Id: init.c 13449 2005-02-06 21:55:07Z ea $
2 *
3 * initss.c - Load the subsystems
4 *
5 * ReactOS Operating System
6 *
7 * --------------------------------------------------------------------
8 *
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.
13 *
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 * General Public License for more details.
18 *
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,
22 * MA 02139, USA.
23 *
24 * --------------------------------------------------------------------
25 */
26
27
28 #include "smss.h"
29
30 #include <rosrtl/string.h>
31
32 #define NDEBUG
33 #include <debug.h>
34
35 /* SM handle for its own \SmApiPort */
36 HANDLE hSmApiPort = (HANDLE) 0;
37
38
39 /* TODO: this file should be totally rewritten
40 *
41 * a) look if a special option is set for smss.exe in
42 * HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options
43 *
44 * b) make smss register with itself for IMAGE_SUBSYSTEM_NATIVE
45 * (programmatically)
46 *
47 * d) make smss initialize Debug (DBGSS) and Windows (CSRSS) as described
48 * in the registry key Required="Debug Windows"
49 * HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\SubSystems
50 *
51 * e) make optional subsystems loadable (again: they must be described in the registry
52 * key Optional="Posix Os2" to be allowed to run)
53 */
54
55 /**********************************************************************
56 * SmpRegisterSmss/0
57 *
58 * DESCRIPTION
59 * Make smss register with itself for IMAGE_SUBSYSTEM_NATIVE
60 * (programmatically). This also open hSmApiPort to be used
61 * in loading required subsystems.
62 */
63 #if 0
64 static NTSTATUS
65 SmpRegisterSmss(VOID)
66 {
67 NTSTATUS Status = STATUS_SUCCESS;
68 UNICODE_STRING SbApiPortName = {0,0,NULL};
69
70 DPRINT("SM: %s called\n",__FUNCTION__);
71
72 Status = SmConnectApiPort(& SbApiPortName,
73 (HANDLE) 0,
74 IMAGE_SUBSYSTEM_NATIVE,
75 & hSmApiPort);
76 if(!NT_SUCCESS(Status))
77 {
78 DPRINT("SM: %s: SMDLL!SmConnectApiPort failed (Status=0x%08lx)\n",
79 __FUNCTION__,Status);
80 return Status;
81 }
82 /*
83 * Note that you don't need to call complete session
84 * because connection handling code autocompletes
85 * the client structure for IMAGE_SUBSYSTEM_NATIVE.
86 */
87 return Status;
88 }
89 #endif
90
91 /**********************************************************************
92 */
93 NTSTATUS
94 SmLoadSubsystems(VOID)
95 {
96 SYSTEM_LOAD_AND_CALL_IMAGE ImageInfo;
97 NTSTATUS Status = STATUS_SUCCESS;
98 WCHAR Data [MAX_PATH + 1];
99 ULONG DataLength = sizeof Data;
100 ULONG DataType = 0;
101
102
103 DPRINT("SM: loading subsystems\n");
104
105 /* SM self registers */
106 #if 0
107 Status = SmpRegisterSmss();
108 if(!NT_SUCCESS(Status))
109 {
110 DPRINT1("SM: SM failed to self register: system is not secure!\n");
111 }
112 #endif
113 /* Load Kmode subsystem (aka win32k.sys) */
114 Status = SmLookupSubsystem (L"Kmode",
115 Data,
116 & DataLength,
117 & DataType,
118 TRUE);
119 if((STATUS_SUCCESS == Status) && (DataLength > sizeof Data[0]))
120 {
121 WCHAR ImagePath [MAX_PATH + 1] = {0};
122
123 wcscpy (ImagePath, L"\\??\\");
124 wcscat (ImagePath, Data);
125 RtlZeroMemory (& ImageInfo, sizeof ImageInfo);
126 RtlInitUnicodeString (& ImageInfo.ModuleName, ImagePath);
127 Status = NtSetSystemInformation(SystemLoadAndCallImage,
128 & ImageInfo,
129 sizeof ImageInfo);
130 if(!NT_SUCCESS(Status))
131 {
132 DPRINT("SM: loading Kmode failed (Status=0x%08lx)\n",
133 Status);
134 return Status;
135 }
136 }
137 /* TODO: load Required subsystems (Debug Windows) */
138 #if 0
139 Status = SmExecuteProgram(L"DEBUG");
140 if(!NT_SUCCESS(Status))
141 {
142 DPRINT1("SM: DBSS failed to initialize!\n");
143 }
144 #endif
145 return Status;
146 }
147
148 NTSTATUS
149 SmRunCsrss(VOID)
150 {
151 NTSTATUS Status;
152 UNICODE_STRING UnicodeString;
153 OBJECT_ATTRIBUTES ObjectAttributes;
154 RTL_PROCESS_INFO ProcessInfo;
155 HANDLE CsrssInitEvent;
156 WCHAR ImagePath [MAX_PATH];
157
158 DPRINT("SM: initializing csrss\n");
159
160 /* Run csrss.exe */
161 RtlRosInitUnicodeStringFromLiteral(&UnicodeString,
162 L"\\CsrssInitDone");
163 InitializeObjectAttributes(&ObjectAttributes,
164 &UnicodeString,
165 EVENT_ALL_ACCESS,
166 0,
167 NULL);
168 Status = NtCreateEvent(&CsrssInitEvent,
169 EVENT_ALL_ACCESS,
170 &ObjectAttributes,
171 NotificationEvent,
172 FALSE);
173 if (!NT_SUCCESS(Status))
174 {
175 DbgPrint("Failed to create csrss notification event\n");
176 }
177
178 /*
179 * Start the Win32 subsystem (csrss.exe)
180 */
181
182 /* initialize executable path */
183 wcscpy(ImagePath, L"\\??\\");
184 wcscat(ImagePath, SharedUserData->NtSystemRoot);
185 wcscat(ImagePath, L"\\system32\\csrss.exe");
186
187 Status = SmCreateUserProcess(ImagePath,
188 L"",
189 FALSE, /* wait */
190 NULL,
191 FALSE, /* terminate */
192 & ProcessInfo);
193
194 if (!NT_SUCCESS(Status))
195 {
196 DPRINT("SM: %s: Loading csrss.exe failed!\n", __FUNCTION__);
197 return(Status);
198 }
199
200 Status = NtWaitForSingleObject(CsrssInitEvent,
201 FALSE,
202 NULL);
203
204 Children[CHILD_CSRSS] = ProcessInfo.ProcessHandle;
205
206 return Status;
207 }
208
209 NTSTATUS
210 SmRunWinlogon(VOID)
211 {
212 NTSTATUS Status = STATUS_SUCCESS;
213 RTL_PROCESS_INFO ProcessInfo;
214 WCHAR ImagePath [MAX_PATH];
215
216 /*
217 * Start the logon process (winlogon.exe)
218 */
219
220 DPRINT("SM: starting winlogon\n");
221
222 /* initialize executable path */
223 wcscpy(ImagePath, L"\\??\\");
224 wcscat(ImagePath, SharedUserData->NtSystemRoot);
225 wcscat(ImagePath, L"\\system32\\winlogon.exe");
226
227 Status = SmCreateUserProcess(ImagePath,
228 L"",
229 FALSE, /* wait */
230 NULL,
231 FALSE, /* terminate */
232 & ProcessInfo);
233 if (!NT_SUCCESS(Status))
234 {
235 DPRINT("SM: %s: Loading winlogon.exe failed!\n", __FUNCTION__);
236 NtTerminateProcess(Children[CHILD_CSRSS], 0);
237 return(Status);
238 }
239
240 Children[CHILD_WINLOGON] = ProcessInfo.ProcessHandle;
241
242 return Status;
243 }
244
245 /* EOF */