3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: services/winlogon/winlogon.c
7 * PROGRAMMER: David Welch (welch@cwcom.net)
12 /* INCLUDES *****************************************************************/
17 #include <lsass/ntsecapi.h>
24 /* GLOBALS ******************************************************************/
26 HWINSTA InteractiveWindowStation; /* WinSta0 */
27 HDESK ApplicationDesktop; /* WinSta0\Default */
28 HDESK WinlogonDesktop; /* WinSta0\Winlogon */
29 HDESK ScreenSaverDesktop; /* WinSta0\Screen-Saver */
31 /* FUNCTIONS *****************************************************************/
33 void PrintString (char* fmt,...)
39 vsprintf(buffer, fmt, ap);
42 OutputDebugString(buffer);
46 BOOLEAN StartServices(VOID)
48 HANDLE ServicesInitEvent;
50 STARTUPINFO StartupInfo;
51 PROCESS_INFORMATION ProcessInformation;
52 CHAR CommandLine[MAX_PATH];
55 /* Start the service control manager (services.exe) */
56 GetSystemDirectory(CommandLine, MAX_PATH);
57 strcat(CommandLine, "\\services.exe");
59 StartupInfo.cb = sizeof(StartupInfo);
60 StartupInfo.lpReserved = NULL;
61 StartupInfo.lpDesktop = NULL;
62 StartupInfo.lpTitle = NULL;
63 StartupInfo.dwFlags = 0;
64 StartupInfo.cbReserved2 = 0;
65 StartupInfo.lpReserved2 = 0;
67 Result = CreateProcess(CommandLine,
79 PrintString("WL: Failed to execute services\n");
83 /* wait for event creation (by SCM) for max. 20 seconds */
84 for (Count = 0; Count < 20; Count++)
88 ServicesInitEvent = OpenEvent(EVENT_ALL_ACCESS, //SYNCHRONIZE,
90 "SvcctrlStartEvent_A3725DX");
91 if (ServicesInitEvent != NULL)
97 /* wait for event signalization */
98 WaitForSingleObject(ServicesInitEvent, INFINITE);
99 CloseHandle(ServicesInitEvent);
104 BOOLEAN StartLsass(VOID)
106 HANDLE LsassInitEvent;
108 STARTUPINFO StartupInfo;
109 PROCESS_INFORMATION ProcessInformation;
110 CHAR CommandLine[MAX_PATH];
112 LsassInitEvent = CreateEvent(NULL,
117 if (LsassInitEvent == NULL)
119 DbgPrint("Failed to create lsass notification event\n");
123 /* Start the local security authority subsystem (lsass.exe) */
125 GetSystemDirectory(CommandLine, MAX_PATH);
126 strcat(CommandLine, "\\lsass.exe");
128 StartupInfo.cb = sizeof(StartupInfo);
129 StartupInfo.lpReserved = NULL;
130 StartupInfo.lpDesktop = NULL;
131 StartupInfo.lpTitle = NULL;
132 StartupInfo.dwFlags = 0;
133 StartupInfo.cbReserved2 = 0;
134 StartupInfo.lpReserved2 = 0;
136 Result = CreateProcess(CommandLine,
145 &ProcessInformation);
148 DbgPrint("WL: Failed to execute lsass\n");
152 DPRINT("WL: Waiting for lsass\n");
153 WaitForSingleObject(LsassInitEvent, INFINITE);
154 CloseHandle(LsassInitEvent);
159 VOID DoLoginUser(PCHAR Name, PCHAR Password)
161 PROCESS_INFORMATION ProcessInformation;
162 STARTUPINFO StartupInfo;
164 CHAR CommandLine[MAX_PATH];
165 CHAR CurrentDirectory[MAX_PATH];
167 GetSystemDirectory(CommandLine, MAX_PATH);
168 strcat(CommandLine, "\\shell.exe");
170 GetWindowsDirectory(CurrentDirectory, MAX_PATH);
172 StartupInfo.cb = sizeof(StartupInfo);
173 StartupInfo.lpReserved = NULL;
174 StartupInfo.lpDesktop = NULL;
175 StartupInfo.lpTitle = NULL;
176 StartupInfo.dwFlags = 0;
177 StartupInfo.cbReserved2 = 0;
178 StartupInfo.lpReserved2 = 0;
180 Result = CreateProcess(CommandLine,
189 &ProcessInformation);
192 DbgPrint("WL: Failed to execute user shell\n");
195 WaitForSingleObject(ProcessInformation.hProcess, INFINITE);
196 CloseHandle( ProcessInformation.hProcess );
197 CloseHandle( ProcessInformation.hThread );
201 WinMain(HINSTANCE hInstance,
202 HINSTANCE hPrevInstance,
207 LSA_STRING ProcessName;
210 LSA_OPERATIONAL_MODE Mode;
212 CHAR LoginPrompt[] = "login:";
213 CHAR PasswordPrompt[] = "password:";
222 * FIXME: Create a security descriptor with
223 * one ACE containing the Winlogon SID
227 * Create the interactive window station
229 InteractiveWindowStation =
230 CreateWindowStationW(L"WinSta0", 0, GENERIC_ALL, NULL);
231 if (InteractiveWindowStation == NULL)
233 DbgPrint("Failed to create window station (0x%X)\n", GetLastError());
234 NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED, 0, 0, 0, 0, 0);
239 * Set the process window station
241 SetProcessWindowStation(InteractiveWindowStation);
244 * Create the application desktop
247 CreateDesktopW(L"Default",
250 0, /* FIXME: Set some flags */
255 * Create the winlogon desktop
257 WinlogonDesktop = CreateDesktopW(L"Winlogon",
260 0, /* FIXME: Set some flags */
265 * Create the screen saver desktop
267 ScreenSaverDesktop = CreateDesktopW(L"Screen-Saver",
270 0, /* FIXME: Set some flags */
275 * Switch to winlogon desktop
277 /* FIXME: Do start up in the application desktop for now. */
278 Status = NtSetInformationProcess(NtCurrentProcess(),
281 sizeof(ApplicationDesktop));
282 if (!NT_SUCCESS(Status))
284 DbgPrint("WL: Cannot set default desktop for winlogon.\n");
286 SetThreadDesktop(ApplicationDesktop);
287 Success = SwitchDesktop(ApplicationDesktop);
290 DbgPrint("Cannot switch to Winlogon desktop (0x%X)\n", GetLastError());
294 SetConsoleTitle( "Winlogon" );
295 /* start system processes (services.exe & lsass.exe) */
301 /* FIXME: What name does the real WinLogon use? */
303 RtlInitUnicodeString((PUNICODE_STRING)&ProcessName, L"WinLogon");
304 Status = LsaRegisterLogonProcess(&ProcessName, &LsaHandle, &Mode);
305 if (!NT_SUCCESS(Status))
307 DbgPrint("WL: Failed to connect to lsass\n");
312 /* FIXME: Create a window class and associate a Winlogon
313 * window procedure with it.
314 * Register SAS with the window.
315 * Register for logoff notification
322 /* Display login prompt */
323 WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),
325 strlen(LoginPrompt), // wcslen(LoginPrompt),
331 ReadConsole(GetStdHandle(STD_INPUT_HANDLE),
337 } while (LoginName[i - 1] != '\n');
338 LoginName[i - 1] = 0;
340 /* Display password prompt */
341 WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),
343 strlen(PasswordPrompt), // wcslen(PasswordPrompt),
349 ReadConsole(GetStdHandle(STD_INPUT_HANDLE),
355 } while (Password[i - 1] != '\n');
358 DoLoginUser(LoginName, Password);