2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Winlogon
4 * FILE: base/system/winlogon/winlogon.c
6 * PROGRAMMERS: Thomas Weidenmueller (w3seek@users.sourceforge.net)
8 * Hervé Poussineau (hpoussin@reactos.org)
11 /* INCLUDES *****************************************************************/
15 #include <wine/debug.h>
17 WINE_DEFAULT_DEBUG_CHANNEL(winlogon
);
19 /* GLOBALS ******************************************************************/
21 HINSTANCE hAppInstance
;
22 PWLSESSION WLSession
= NULL
;
24 /* FUNCTIONS *****************************************************************/
27 StartServicesManager(VOID
)
29 HANDLE ServicesInitEvent
= NULL
;
30 STARTUPINFOW StartupInfo
;
31 PROCESS_INFORMATION ProcessInformation
;
33 LPCWSTR ServiceString
= L
"services.exe";
36 /* Start the service control manager (services.exe) */
37 StartupInfo
.cb
= sizeof(StartupInfo
);
38 StartupInfo
.lpReserved
= NULL
;
39 StartupInfo
.lpDesktop
= NULL
;
40 StartupInfo
.lpTitle
= NULL
;
41 StartupInfo
.dwFlags
= 0;
42 StartupInfo
.cbReserved2
= 0;
43 StartupInfo
.lpReserved2
= 0;
45 TRACE("WL: Creating new process - %S\n", ServiceString
);
60 ERR("WL: Failed to execute services (error %lu)\n", GetLastError());
64 /* Wait for event creation (by SCM) for max. 20 seconds */
65 for (Count
= 0; Count
< 20; Count
++)
69 TRACE("WL: Attempting to open event \"SvcctrlStartEvent_A3752DX\"\n");
70 ServicesInitEvent
= OpenEventW(
73 L
"SvcctrlStartEvent_A3752DX");
74 if (ServicesInitEvent
)
78 if (!ServicesInitEvent
)
80 ERR("WL: Failed to open event \"SvcctrlStartEvent_A3752DX\"\n");
84 /* Wait for event signalization */
85 WaitForSingleObject(ServicesInitEvent
, INFINITE
);
86 CloseHandle(ServicesInitEvent
);
87 TRACE("WL: StartServicesManager() done.\n");
94 IN LPCWSTR ServiceName
)
96 SC_HANDLE hSCManager
= NULL
;
97 SC_HANDLE hService
= NULL
;
100 hSCManager
= OpenSCManager(NULL
, NULL
, 0);
103 ERR("WL: Failed to OpenSCManager\n");
107 hService
= OpenServiceW(hSCManager
, ServiceName
, SERVICE_START
);
110 ERR("WL: Failed to open the service\n");
113 if (!StartServiceW(hService
, 0, NULL
))
115 ERR("WL: Failed to start the service\n");
123 CloseServiceHandle(hService
);
125 CloseServiceHandle(hSCManager
);
132 HANDLE LsassInitEvent
;
134 LsassInitEvent
= CreateEventW(
138 L
"Global\\SECURITY_SERVICES_STARTED");
141 ERR("WL: Failed to create lsass notification event (error %lu)\n", GetLastError());
145 /* Start the local security authority subsystem (Netlogon service) */
146 if (!StartCustomService(L
"Netlogon"))
148 ERR("WL: Failed to start NetLogon service (error %lu)\n", GetLastError());
152 WaitForSingleObject(LsassInitEvent
, INFINITE
);
153 CloseHandle(LsassInitEvent
);
159 DisplayStatusMessage(
160 IN PWLSESSION Session
,
164 WCHAR StatusMsg
[MAX_PATH
];
166 if (Session
->Gina
.Version
< WLX_VERSION_1_3
)
169 if (Session
->SuppressStatus
)
172 if (LoadStringW(hAppInstance
, ResourceId
, StatusMsg
, MAX_PATH
) == 0)
175 return Session
->Gina
.Functions
.WlxDisplayStatusMessage(Session
->Gina
.Context
, hDesktop
, 0, NULL
, StatusMsg
);
180 IN PWLSESSION Session
)
182 if (Session
->Gina
.Version
< WLX_VERSION_1_3
)
185 return Session
->Gina
.Functions
.WlxRemoveStatusMessage(Session
->Gina
.Context
);
188 static INT_PTR CALLBACK
189 GinaLoadFailedWindowProc(
199 switch (LOWORD(wParam
))
202 EndDialog(hwndDlg
, IDOK
);
210 WCHAR templateText
[MAX_PATH
], text
[MAX_PATH
];
212 len
= GetDlgItemTextW(hwndDlg
, IDC_GINALOADFAILED
, templateText
, MAX_PATH
);
215 wsprintfW(text
, templateText
, (LPWSTR
)lParam
);
216 SetDlgItemTextW(hwndDlg
, IDC_GINALOADFAILED
, text
);
218 SetFocus(GetDlgItem(hwndDlg
, IDOK
));
223 EndDialog(hwndDlg
, IDCANCEL
);
233 IN HINSTANCE hInstance
,
234 IN HINSTANCE hPrevInstance
,
239 LSA_STRING ProcessName
, PackageName
;
241 LSA_OPERATIONAL_MODE Mode
;
243 ULONG AuthenticationPackage
;
246 ULONG HardErrorResponse
;
249 UNREFERENCED_PARAMETER(hPrevInstance
);
250 UNREFERENCED_PARAMETER(lpCmdLine
);
251 UNREFERENCED_PARAMETER(nShowCmd
);
253 hAppInstance
= hInstance
;
255 if (!RegisterLogonProcess(GetCurrentProcessId(), TRUE
))
257 ERR("WL: Could not register logon process\n");
258 HandleShutdown(NULL
, WLX_SAS_ACTION_SHUTDOWN_POWER_OFF
);
259 NtShutdownSystem(ShutdownNoReboot
);
263 WLSession
= (PWLSESSION
)HeapAlloc(GetProcessHeap(), 0, sizeof(WLSESSION
));
266 ERR("WL: Could not allocate memory for winlogon instance\n");
267 NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED
, 0, 0, NULL
, OptionOk
, &HardErrorResponse
);
270 ZeroMemory(WLSession
, sizeof(WLSESSION
));
271 WLSession
->DialogTimeout
= 120; /* 2 minutes */
273 if (!CreateWindowStationAndDesktops(WLSession
))
275 ERR("WL: Could not create window station and desktops\n");
276 NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED
, 0, 0, NULL
, OptionOk
, &HardErrorResponse
);
279 LockWorkstation(WLSession
);
281 if (!StartServicesManager())
283 ERR("WL: Could not start services.exe\n");
284 NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED
, 0, 0, NULL
, OptionOk
, &HardErrorResponse
);
290 ERR("WL: Failed to start lsass.exe service (error %lu)\n", GetLastError());
291 NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED
, 0, 0, 0, OptionOk
, &HardErrorResponse
);
295 /* Load and initialize gina */
296 if (!GinaInit(WLSession
))
298 ERR("WL: Failed to initialize Gina\n");
299 DialogBoxParam(hAppInstance
, MAKEINTRESOURCE(IDD_GINALOADFAILED
), GetDesktopWindow(), GinaLoadFailedWindowProc
, (LPARAM
)L
"");
300 HandleShutdown(WLSession
, WLX_SAS_ACTION_SHUTDOWN_REBOOT
);
304 DisplayStatusMessage(WLSession
, WLSession
->WinlogonDesktop
, IDS_REACTOSISSTARTINGUP
);
307 /* Connect to NetLogon service (lsass.exe) */
308 /* Real winlogon uses "Winlogon" */
309 RtlInitUnicodeString((PUNICODE_STRING
)&ProcessName
, L
"Winlogon");
310 Status
= LsaRegisterLogonProcess(&ProcessName
, &LsaHandle
, &Mode
);
311 if (Status
== STATUS_PORT_CONNECTION_REFUSED
)
313 /* Add the 'SeTcbPrivilege' privilege and try again */
314 Status
= RtlAdjustPrivilege(SE_TCB_PRIVILEGE
, TRUE
, TRUE
, &Old
);
315 if (!NT_SUCCESS(Status
))
317 ERR("RtlAdjustPrivilege() failed with error %lu\n", LsaNtStatusToWinError(Status
));
320 Status
= LsaRegisterLogonProcess(&ProcessName
, &LsaHandle
, &Mode
);
322 if (!NT_SUCCESS(Status
))
324 ERR("LsaRegisterLogonProcess() failed with error %lu\n", LsaNtStatusToWinError(Status
));
328 RtlInitUnicodeString((PUNICODE_STRING
)&PackageName
, MICROSOFT_KERBEROS_NAME_W
);
329 Status
= LsaLookupAuthenticationPackage(LsaHandle
, &PackageName
, &AuthenticationPackage
);
330 if (!NT_SUCCESS(Status
))
332 ERR("LsaLookupAuthenticationPackage() failed with error %lu\n", LsaNtStatusToWinError(Status
));
333 LsaDeregisterLogonProcess(LsaHandle
);
338 /* Create a hidden window to get SAS notifications */
339 if (!InitializeSAS(WLSession
))
341 ERR("WL: Failed to initialize SAS\n");
345 //DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_PREPARENETWORKCONNECTIONS);
346 //DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_APPLYINGCOMPUTERSETTINGS);
348 /* Display logged out screen */
349 WLSession
->LogonStatus
= WKSTA_IS_LOGGED_OFF
;
350 RemoveStatusMessage(WLSession
);
352 /* Check for pending setup */
353 if (GetSetupType() != 0)
355 TRACE("WL: Setup mode detected\n");
357 /* Run setup and reboot when done */
358 SwitchDesktop(WLSession
->ApplicationDesktop
);
362 PostMessageW(WLSession
->SASWindow
, WLX_WM_SAS
, WLX_SAS_TYPE_TIMEOUT
, 0);
364 /* Tell kernel that CurrentControlSet is good (needed
365 * to support Last good known configuration boot) */
366 NtInitializeRegistry(CM_BOOT_FLAG_ACCEPTED
);
368 /* Message loop for the SAS window */
369 while (GetMessageW(&Msg
, WLSession
->SASWindow
, 0, 0))
371 TranslateMessage(&Msg
);
372 DispatchMessageW(&Msg
);
375 /* We never go there */