no message
[reactos.git] / reactos / services / winlogon / winlogon.c
1 /* $Id: winlogon.c,v 1.6 2000/08/12 19:33:23 dwelch Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: services/winlogon/winlogon.c
6 * PURPOSE: Logon
7 * PROGRAMMER: David Welch (welch@cwcom.net)
8 * UPDATE HISTORY:
9 * Created 22/05/98
10 */
11
12 /* INCLUDES *****************************************************************/
13
14 #include <ntos.h>
15 #include <windows.h>
16 #include <stdio.h>
17 #include <lsass/ntsecapi.h>
18
19 #include <wchar.h>
20
21
22 /* GLOBALS ******************************************************************/
23
24 /* FUNCTIONS *****************************************************************/
25
26 BOOLEAN StartServices(VOID)
27 {
28 HANDLE ServicesInitEvent;
29 BOOLEAN Result;
30 STARTUPINFO StartupInfo;
31 PROCESS_INFORMATION ProcessInformation;
32
33 ServicesInitEvent = CreateEvent(NULL,
34 TRUE,
35 FALSE,
36 "\\ServicesInitDone");
37
38 if (ServicesInitEvent == NULL)
39 {
40 DbgPrint("Failed to create services notification event\n");
41 return(FALSE);
42 }
43
44 /* Start the Win32 subsystem (csrss.exe) */
45 DbgPrint("WL: Executing services.exe\n");
46
47 StartupInfo.cb = sizeof(StartupInfo);
48 StartupInfo.lpReserved = NULL;
49 StartupInfo.lpDesktop = NULL;
50 StartupInfo.lpTitle = NULL;
51 StartupInfo.dwFlags = 0;
52 StartupInfo.cbReserved2 = 0;
53 StartupInfo.lpReserved2 = 0;
54
55 Result = CreateProcess("C:\\reactos\\system32\\services.exe",
56 NULL,
57 NULL,
58 NULL,
59 FALSE,
60 DETACHED_PROCESS,
61 NULL,
62 NULL,
63 &StartupInfo,
64 &ProcessInformation);
65 if (!Result)
66 {
67 DbgPrint("WL: Failed to execute services\n");
68 return(FALSE);
69 }
70
71 DbgPrint("WL: Waiting for services\n");
72 WaitForSingleObject(ServicesInitEvent, INFINITE);
73
74 DbgPrint("WL: Finished waiting for services\n");
75 return(TRUE);
76 }
77
78 BOOLEAN StartLsass(VOID)
79 {
80 HANDLE LsassInitEvent;
81 BOOLEAN Result;
82 STARTUPINFO StartupInfo;
83 PROCESS_INFORMATION ProcessInformation;
84
85 LsassInitEvent = CreateEvent(NULL,
86 TRUE,
87 FALSE,
88 "\\LsassInitDone");
89
90 if (LsassInitEvent == NULL)
91 {
92 DbgPrint("Failed to create lsass notification event\n");
93 return(FALSE);
94 }
95
96 /* Start the Win32 subsystem (csrss.exe) */
97 DbgPrint("WL: Executing lsass.exe\n");
98
99 StartupInfo.cb = sizeof(StartupInfo);
100 StartupInfo.lpReserved = NULL;
101 StartupInfo.lpDesktop = NULL;
102 StartupInfo.lpTitle = NULL;
103 StartupInfo.dwFlags = 0;
104 StartupInfo.cbReserved2 = 0;
105 StartupInfo.lpReserved2 = 0;
106
107 Result = CreateProcess("C:\\reactos\\system32\\lsass.exe",
108 NULL,
109 NULL,
110 NULL,
111 FALSE,
112 DETACHED_PROCESS,
113 NULL,
114 NULL,
115 &StartupInfo,
116 &ProcessInformation);
117 if (!Result)
118 {
119 DbgPrint("WL: Failed to execute lsass\n");
120 return(FALSE);
121 }
122
123 DbgPrint("WL: Waiting for lsass\n");
124 WaitForSingleObject(LsassInitEvent, INFINITE);
125
126 DbgPrint("WL: Finished waiting for lsass\n");
127 return(TRUE);
128 }
129
130 VOID DoLoginUser(PCHAR Name, PCHAR Password)
131 {
132 PROCESS_INFORMATION ProcessInformation;
133 STARTUPINFO StartupInfo;
134 BOOLEAN Result;
135
136 StartupInfo.cb = sizeof(StartupInfo);
137 StartupInfo.lpReserved = NULL;
138 StartupInfo.lpDesktop = NULL;
139 StartupInfo.lpTitle = NULL;
140 StartupInfo.dwFlags = 0;
141 StartupInfo.cbReserved2 = 0;
142 StartupInfo.lpReserved2 = 0;
143
144 Result = CreateProcess("C:\\reactos\\system32\\shell.exe",
145 NULL,
146 NULL,
147 NULL,
148 FALSE,
149 DETACHED_PROCESS,
150 NULL,
151 NULL,
152 &StartupInfo,
153 &ProcessInformation);
154 if (!Result)
155 {
156 DbgPrint("WL: Failed to execute user shell\n");
157 return;
158 }
159 WaitForSingleObject(ProcessInformation.hProcess, INFINITE);
160 }
161
162 int STDCALL
163 WinMain(HINSTANCE hInstance,
164 HINSTANCE hPrevInstance,
165 LPSTR lpCmdLine,
166 int nShowCmd)
167 {
168 #if 0
169 LSA_STRING ProcessName;
170 NTSTATUS Status;
171 HANDLE LsaHandle;
172 LSA_OPERATIONAL_MODE Mode;
173 #endif
174 CHAR LoginPrompt[] = "login:";
175 CHAR PasswordPrompt[] = "password:";
176 ULONG Result;
177 CHAR LoginName[255];
178 CHAR Password[255];
179 ULONG i;
180
181 /*
182 * FIXME: Create WindowStations here. At the moment lsass and services
183 * share ours
184 */
185
186 StartLsass();
187 StartServices();
188
189 /* FIXME: What name does the real WinLogon use? */
190 #if 0
191 RtlInitUnicodeString((PUNICODE_STRING)&ProcessName, L"WinLogon");
192 Status = LsaRegisterLogonProcess(&ProcessName, &LsaHandle, &Mode);
193 if (!NT_SUCCESS(Status))
194 {
195 DbgPrint("WL: Failed to connect to lsass\n");
196 return(1);
197 }
198 #endif
199
200 /* smss wouldn't have created a console for us */
201 AllocConsole();
202
203 /* Main loop */
204 for (;;)
205 {
206 /* Display login prompt */
207 WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),
208 LoginPrompt,
209 wcslen(LoginPrompt),
210 &Result,
211 NULL);
212 i = 0;
213 do
214 {
215 ReadConsole(GetStdHandle(STD_INPUT_HANDLE),
216 &LoginName[i],
217 1,
218 &Result,
219 NULL);
220 i++;
221 } while (LoginName[i - 1] != '\n');
222 LoginName[i - 1] = 0;
223
224 /* Display password prompt */
225 WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),
226 PasswordPrompt,
227 wcslen(PasswordPrompt),
228 &Result,
229 NULL);
230 i = 0;
231 do
232 {
233 ReadConsole(GetStdHandle(STD_INPUT_HANDLE),
234 &Password[i],
235 1,
236 &Result,
237 NULL);
238 i++;
239 } while (Password[i - 1] != '\n');
240 Password[i - 1] =0;
241
242 DoLoginUser(LoginName, Password);
243 }
244 }