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 STARTUPINFOW StartupInfo
;
30 PROCESS_INFORMATION ProcessInformation
;
31 LPCWSTR ServiceString
= L
"services.exe";
34 /* Start the service control manager (services.exe) */
35 ZeroMemory(&StartupInfo
, sizeof(STARTUPINFOW
));
36 StartupInfo
.cb
= sizeof(StartupInfo
);
37 StartupInfo
.lpReserved
= NULL
;
38 StartupInfo
.lpDesktop
= NULL
;
39 StartupInfo
.lpTitle
= NULL
;
40 StartupInfo
.dwFlags
= 0;
41 StartupInfo
.cbReserved2
= 0;
42 StartupInfo
.lpReserved2
= 0;
44 TRACE("WL: Creating new process - %S\n", ServiceString
);
59 ERR("WL: Failed to execute services (error %lu)\n", GetLastError());
63 TRACE("WL: Created new process - %S\n", ServiceString
);
65 CloseHandle(ProcessInformation
.hThread
);
66 CloseHandle(ProcessInformation
.hProcess
);
68 TRACE("WL: StartServicesManager() done.\n");
77 STARTUPINFOW StartupInfo
;
78 PROCESS_INFORMATION ProcessInformation
;
79 LPCWSTR ServiceString
= L
"lsass.exe";
82 /* Start the local security authority subsystem (lsass.exe) */
83 ZeroMemory(&StartupInfo
, sizeof(STARTUPINFOW
));
84 StartupInfo
.cb
= sizeof(StartupInfo
);
85 StartupInfo
.lpReserved
= NULL
;
86 StartupInfo
.lpDesktop
= NULL
;
87 StartupInfo
.lpTitle
= NULL
;
88 StartupInfo
.dwFlags
= 0;
89 StartupInfo
.cbReserved2
= 0;
90 StartupInfo
.lpReserved2
= 0;
92 TRACE("WL: Creating new process - %S\n", ServiceString
);
104 &ProcessInformation
);
106 TRACE("WL: Created new process - %S\n", ServiceString
);
108 CloseHandle(ProcessInformation
.hThread
);
109 CloseHandle(ProcessInformation
.hProcess
);
121 hEvent
= CreateEventW(NULL
,
124 L
"LSA_RPC_SERVER_ACTIVE");
127 dwError
= GetLastError();
128 TRACE("WL: Failed to create the notication event (Error %lu)\n", dwError
);
130 if (dwError
== ERROR_ALREADY_EXISTS
)
132 hEvent
= OpenEventW(SYNCHRONIZE
,
134 L
"LSA_RPC_SERVER_ACTIVE");
137 ERR("WL: Could not open the notification event (Error %lu)\n", GetLastError());
143 TRACE("WL: Wait for the LSA server!\n");
144 WaitForSingleObject(hEvent
, INFINITE
);
145 TRACE("WL: LSA server running!\n");
152 InitKeyboardLayouts()
154 WCHAR wszKeyName
[12], wszKLID
[10];
155 DWORD dwSize
= sizeof(wszKLID
), dwType
, i
= 1;
160 /* Open registry key with preloaded layouts */
161 if (RegOpenKeyExW(HKEY_CURRENT_USER
, L
"Keyboard Layout\\Preload", 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)
165 /* Read values with integer names only */
166 swprintf(wszKeyName
, L
"%d", i
++);
167 if (RegQueryValueExW(hKey
, wszKeyName
, NULL
, &dwType
, (LPBYTE
)wszKLID
, &dwSize
) != ERROR_SUCCESS
)
169 /* There is no more entries */
173 /* Only REG_SZ values are valid */
174 if (dwType
!= REG_SZ
)
176 ERR("Wrong type: %ws!\n", wszKLID
);
180 /* Load keyboard layout with given locale id */
181 Flags
= KLF_SUBSTITUTE_OK
;
183 Flags
|= KLF_NOTELLSHELL
|KLF_REPLACELANG
;
185 Flags
|= KLF_ACTIVATE
; // |0x40000000
186 if (!LoadKeyboardLayoutW(wszKLID
, Flags
))
188 ERR("LoadKeyboardLayoutW(%ws) failed!\n", wszKLID
);
193 /* We loaded at least one layout - success */
198 /* Close the key now */
202 WARN("RegOpenKeyExW(Keyboard Layout\\Preload) failed!\n");
206 /* If we failed, load US keyboard layout */
207 if (LoadKeyboardLayoutW(L
"00000409", 0x04090409))
216 DisplayStatusMessage(
217 IN PWLSESSION Session
,
221 WCHAR StatusMsg
[MAX_PATH
];
223 if (Session
->Gina
.Version
< WLX_VERSION_1_3
)
226 if (Session
->SuppressStatus
)
229 if (LoadStringW(hAppInstance
, ResourceId
, StatusMsg
, MAX_PATH
) == 0)
232 return Session
->Gina
.Functions
.WlxDisplayStatusMessage(Session
->Gina
.Context
, hDesktop
, 0, NULL
, StatusMsg
);
237 IN PWLSESSION Session
)
239 if (Session
->Gina
.Version
< WLX_VERSION_1_3
)
242 return Session
->Gina
.Functions
.WlxRemoveStatusMessage(Session
->Gina
.Context
);
245 static INT_PTR CALLBACK
246 GinaLoadFailedWindowProc(
256 switch (LOWORD(wParam
))
259 EndDialog(hwndDlg
, IDOK
);
267 WCHAR templateText
[MAX_PATH
], text
[MAX_PATH
];
269 len
= GetDlgItemTextW(hwndDlg
, IDC_GINALOADFAILED
, templateText
, MAX_PATH
);
272 wsprintfW(text
, templateText
, (LPWSTR
)lParam
);
273 SetDlgItemTextW(hwndDlg
, IDC_GINALOADFAILED
, text
);
275 SetFocus(GetDlgItem(hwndDlg
, IDOK
));
280 EndDialog(hwndDlg
, IDCANCEL
);
290 IN HINSTANCE hInstance
,
291 IN HINSTANCE hPrevInstance
,
296 LSA_STRING ProcessName
, PackageName
;
298 LSA_OPERATIONAL_MODE Mode
;
300 ULONG AuthenticationPackage
;
303 ULONG HardErrorResponse
;
306 UNREFERENCED_PARAMETER(hPrevInstance
);
307 UNREFERENCED_PARAMETER(lpCmdLine
);
308 UNREFERENCED_PARAMETER(nShowCmd
);
310 hAppInstance
= hInstance
;
312 if (!RegisterLogonProcess(GetCurrentProcessId(), TRUE
))
314 ERR("WL: Could not register logon process\n");
315 NtShutdownSystem(ShutdownNoReboot
);
319 WLSession
= (PWLSESSION
)HeapAlloc(GetProcessHeap(), 0, sizeof(WLSESSION
));
322 ERR("WL: Could not allocate memory for winlogon instance\n");
323 NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED
, 0, 0, NULL
, OptionOk
, &HardErrorResponse
);
326 ZeroMemory(WLSession
, sizeof(WLSESSION
));
327 WLSession
->DialogTimeout
= 120; /* 2 minutes */
329 if (!CreateWindowStationAndDesktops(WLSession
))
331 ERR("WL: Could not create window station and desktops\n");
332 NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED
, 0, 0, NULL
, OptionOk
, &HardErrorResponse
);
335 LockWorkstation(WLSession
);
337 /* Load default keyboard layouts */
338 if (!InitKeyboardLayouts())
340 ERR("WL: Could not preload keyboard layouts\n");
341 NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED
, 0, 0, NULL
, OptionOk
, &HardErrorResponse
);
345 if (!StartServicesManager())
347 ERR("WL: Could not start services.exe\n");
348 NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED
, 0, 0, NULL
, OptionOk
, &HardErrorResponse
);
354 ERR("WL: Failed to start lsass.exe service (error %lu)\n", GetLastError());
355 NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED
, 0, 0, 0, OptionOk
, &HardErrorResponse
);
359 /* Load and initialize gina */
360 if (!GinaInit(WLSession
))
362 ERR("WL: Failed to initialize Gina\n");
363 DialogBoxParam(hAppInstance
, MAKEINTRESOURCE(IDD_GINALOADFAILED
), GetDesktopWindow(), GinaLoadFailedWindowProc
, (LPARAM
)L
"");
364 HandleShutdown(WLSession
, WLX_SAS_ACTION_SHUTDOWN_REBOOT
);
368 DisplayStatusMessage(WLSession
, WLSession
->WinlogonDesktop
, IDS_REACTOSISSTARTINGUP
);
371 /* Wait for the LSA server */
375 /* Connect to NetLogon service (lsass.exe) */
376 /* Real winlogon uses "Winlogon" */
377 RtlInitUnicodeString((PUNICODE_STRING
)&ProcessName
, L
"Winlogon");
378 Status
= LsaRegisterLogonProcess(&ProcessName
, &LsaHandle
, &Mode
);
379 if (Status
== STATUS_PORT_CONNECTION_REFUSED
)
381 /* Add the 'SeTcbPrivilege' privilege and try again */
382 Status
= RtlAdjustPrivilege(SE_TCB_PRIVILEGE
, TRUE
, TRUE
, &Old
);
383 if (!NT_SUCCESS(Status
))
385 ERR("RtlAdjustPrivilege() failed with error %lu\n", LsaNtStatusToWinError(Status
));
388 Status
= LsaRegisterLogonProcess(&ProcessName
, &LsaHandle
, &Mode
);
390 if (!NT_SUCCESS(Status
))
392 ERR("LsaRegisterLogonProcess() failed with error %lu\n", LsaNtStatusToWinError(Status
));
396 RtlInitUnicodeString((PUNICODE_STRING
)&PackageName
, MICROSOFT_KERBEROS_NAME_W
);
397 Status
= LsaLookupAuthenticationPackage(LsaHandle
, &PackageName
, &AuthenticationPackage
);
398 if (!NT_SUCCESS(Status
))
400 ERR("LsaLookupAuthenticationPackage() failed with error %lu\n", LsaNtStatusToWinError(Status
));
401 LsaDeregisterLogonProcess(LsaHandle
);
406 /* Create a hidden window to get SAS notifications */
407 if (!InitializeSAS(WLSession
))
409 ERR("WL: Failed to initialize SAS\n");
413 //DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_PREPARENETWORKCONNECTIONS);
414 //DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_APPLYINGCOMPUTERSETTINGS);
416 /* Display logged out screen */
417 WLSession
->LogonStatus
= WKSTA_IS_LOGGED_OFF
;
418 RemoveStatusMessage(WLSession
);
420 /* Check for pending setup */
421 if (GetSetupType() != 0)
423 TRACE("WL: Setup mode detected\n");
425 /* Run setup and reboot when done */
426 SwitchDesktop(WLSession
->ApplicationDesktop
);
430 PostMessageW(WLSession
->SASWindow
, WLX_WM_SAS
, WLX_SAS_TYPE_TIMEOUT
, 0);
432 /* Tell kernel that CurrentControlSet is good (needed
433 * to support Last good known configuration boot) */
434 NtInitializeRegistry(CM_BOOT_FLAG_ACCEPTED
| 1);
436 /* Message loop for the SAS window */
437 while (GetMessageW(&Msg
, WLSession
->SASWindow
, 0, 0))
439 TranslateMessage(&Msg
);
440 DispatchMessageW(&Msg
);
443 /* We never go there */