Send proper messages/events to processes during logoff and kill them if they
[reactos.git] / reactos / subsys / system / winlogon / winlogon.c
1 /* $Id$
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 #include "winlogon.h"
14
15 #define NDEBUG
16 #include <debug.h>
17
18 #define SUPPORT_CONSOLESTART 1
19 #define START_LSASS 0
20
21 /* GLOBALS ******************************************************************/
22
23 BOOL
24 LoadGina(PMSGINAFUNCTIONS Functions, DWORD *DllVersion);
25 PWLSESSION
26 MsGinaInit(void);
27 void
28 SessionLoop(PWLSESSION Session);
29 BOOL
30 InitServices(void);
31 BOOL
32 WlxCreateWindowStationAndDesktops(PWLSESSION Session);
33
34 HINSTANCE hAppInstance;
35 PWLSESSION WLSession = NULL;
36
37 #if SUPPORT_CONSOLESTART
38 BOOL StartConsole = TRUE;
39 #endif
40
41 /* FUNCTIONS *****************************************************************/
42
43 static void
44 PrintString (WCHAR* fmt,...)
45 {
46 WCHAR buffer[512];
47 va_list ap;
48
49 va_start(ap, fmt);
50 wsprintf(buffer, fmt, ap);
51 va_end(ap);
52
53 OutputDebugString(buffer);
54 }
55
56
57 INT_PTR CALLBACK
58 ShutdownComputerProc (HWND hwndDlg,
59 UINT uMsg,
60 WPARAM wParam,
61 LPARAM lParam)
62 {
63 switch(uMsg)
64 {
65 case WM_COMMAND:
66 {
67 switch(LOWORD(wParam))
68 {
69 case IDC_BTNSHTDOWNCOMPUTER:
70 EndDialog(hwndDlg, IDC_BTNSHTDOWNCOMPUTER);
71 break;
72 }
73 break;
74 }
75 case WM_INITDIALOG:
76 {
77 RemoveMenu(GetSystemMenu(hwndDlg, FALSE), SC_CLOSE, MF_BYCOMMAND);
78 SetFocus(GetDlgItem(hwndDlg, IDC_BTNSHTDOWNCOMPUTER));
79 break;
80 }
81 }
82 return FALSE;
83 }
84
85 static BOOLEAN
86 StartServices (VOID)
87 {
88 HANDLE ServicesInitEvent;
89 BOOLEAN Result;
90 STARTUPINFO StartupInfo;
91 PROCESS_INFORMATION ProcessInformation;
92 DWORD Count;
93 WCHAR ServiceString[] = L"services.exe";
94
95 /* Start the service control manager (services.exe) */
96
97 StartupInfo.cb = sizeof(StartupInfo);
98 StartupInfo.lpReserved = NULL;
99 StartupInfo.lpDesktop = NULL;
100 StartupInfo.lpTitle = NULL;
101 StartupInfo.dwFlags = 0;
102 StartupInfo.cbReserved2 = 0;
103 StartupInfo.lpReserved2 = 0;
104
105 #if 0
106 PrintString(L"WL: Creating new process - \"services.exe\".\n");
107 #endif
108
109 Result = CreateProcess(NULL,
110 ServiceString,
111 NULL,
112 NULL,
113 FALSE,
114 DETACHED_PROCESS,
115 NULL,
116 NULL,
117 &StartupInfo,
118 &ProcessInformation);
119 if (!Result)
120 {
121 PrintString(L"WL: Failed to execute services\n");
122 return FALSE;
123 }
124
125 /* wait for event creation (by SCM) for max. 20 seconds */
126 for (Count = 0; Count < 20; Count++)
127 {
128 Sleep(1000);
129
130 //DbgPrint("WL: Attempting to open event \"SvcctrlStartEvent_A3725DX\"\n");
131 ServicesInitEvent = OpenEvent(EVENT_ALL_ACCESS, //SYNCHRONIZE,
132 FALSE,
133 L"SvcctrlStartEvent_A3725DX");
134 if (ServicesInitEvent != NULL)
135 {
136 break;
137 }
138 }
139
140 if (ServicesInitEvent == NULL)
141 {
142 DbgPrint("WL: Failed to open event \"SvcctrlStartEvent_A3725DX\"\n");
143 return FALSE;
144 }
145
146 /* wait for event signalization */
147 //DbgPrint("WL: Waiting forever on event handle: %x\n", ServicesInitEvent);
148 WaitForSingleObject(ServicesInitEvent, INFINITE);
149 //DbgPrint("WL: Closing event object \"SvcctrlStartEvent_A3725DX\"\n");
150 CloseHandle(ServicesInitEvent);
151 //DbgPrint("WL: StartServices() Done.\n");
152
153 return TRUE;
154 }
155
156 #if START_LSASS
157 static BOOLEAN
158 StartLsass (VOID)
159 {
160 HANDLE LsassInitEvent;
161 BOOLEAN Result;
162 STARTUPINFO StartupInfo;
163 PROCESS_INFORMATION ProcessInformation;
164
165 LsassInitEvent = CreateEvent(NULL,
166 TRUE,
167 FALSE,
168 L"\\LsassInitDone");
169
170 if (LsassInitEvent == NULL)
171 {
172 DbgPrint("WL: Failed to create lsass notification event\n");
173 return(FALSE);
174 }
175
176 /* Start the local security authority subsystem (lsass.exe) */
177
178 StartupInfo.cb = sizeof(StartupInfo);
179 StartupInfo.lpReserved = NULL;
180 StartupInfo.lpDesktop = NULL;
181 StartupInfo.lpTitle = NULL;
182 StartupInfo.dwFlags = 0;
183 StartupInfo.cbReserved2 = 0;
184 StartupInfo.lpReserved2 = 0;
185
186 Result = CreateProcess(L"lsass.exe",
187 NULL,
188 NULL,
189 NULL,
190 FALSE,
191 DETACHED_PROCESS,
192 NULL,
193 NULL,
194 &StartupInfo,
195 &ProcessInformation);
196 if (!Result)
197 {
198 DbgPrint("WL: Failed to execute lsass\n");
199 return(FALSE);
200 }
201
202 DPRINT("WL: Waiting for lsass\n");
203 WaitForSingleObject(LsassInitEvent, INFINITE);
204 CloseHandle(LsassInitEvent);
205
206 return(TRUE);
207 }
208 #endif
209
210
211 static BOOLEAN
212 OpenRegistryKey (HKEY *WinLogonKey)
213 {
214 return ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,
215 L"SOFTWARE\\ReactOS\\Windows NT\\CurrentVersion\\WinLogon",
216 0,
217 KEY_QUERY_VALUE,
218 WinLogonKey);
219 }
220
221
222 static BOOLEAN StartProcess(PWCHAR ValueName)
223 {
224 BOOL StartIt;
225 HKEY WinLogonKey;
226 DWORD Type;
227 DWORD Size;
228 DWORD StartValue;
229
230 StartIt = TRUE;
231 if (OpenRegistryKey(&WinLogonKey))
232 {
233 Size = sizeof(DWORD);
234 if (ERROR_SUCCESS == RegQueryValueEx(WinLogonKey,
235 ValueName,
236 NULL,
237 &Type,
238 (LPBYTE) &StartValue,
239 &Size))
240 {
241 if (REG_DWORD == Type)
242 {
243 StartIt = (0 != StartValue);
244 }
245 }
246 RegCloseKey(WinLogonKey);
247 }
248
249 return StartIt;
250 }
251
252 /*
253 static BOOL RestartShell(void)
254 {
255 HKEY WinLogonKey;
256 DWORD Type, Size, Value;
257
258 if(OpenRegistryKey(&WinLogonKey))
259 {
260 Size = sizeof(DWORD);
261 if(ERROR_SUCCESS == RegQueryValueEx(WinLogonKey,
262 L"AutoRestartShell",
263 NULL,
264 &Type,
265 (LPBYTE)&Value,
266 &Size))
267 {
268 if(Type == REG_DWORD)
269 {
270 RegCloseKey(WinLogonKey);
271 return (Value != 0);
272 }
273 }
274 RegCloseKey(WinLogonKey);
275 }
276 return FALSE;
277 }
278 */
279
280 VOID STDCALL
281 RegisterHotKeys(VOID)
282 {
283 RegisterHotKey(NULL, 0, MOD_ALT | MOD_CONTROL, VK_DELETE);
284 }
285
286 VOID STDCALL
287 UnregisterHotKeys(VOID)
288 {
289 UnregisterHotKey(NULL, 0);
290 }
291
292 VOID STDCALL
293 HandleHotKey(MSG *Msg)
294 {
295 DbgPrint("HOTKEY: Got hot key (%d)\n", Msg->wParam);
296
297 /* CTRL-ALT-DEL */
298 if (Msg->wParam == 0)
299 {
300 STARTUPINFO StartupInfo;
301 PROCESS_INFORMATION ProcessInformation;
302
303 StartupInfo.cb = sizeof(StartupInfo);
304 StartupInfo.lpReserved = NULL;
305 StartupInfo.lpDesktop = NULL;
306 StartupInfo.lpTitle = NULL;
307 StartupInfo.dwFlags = 0;
308 StartupInfo.cbReserved2 = 0;
309 StartupInfo.lpReserved2 = 0;
310
311 CreateProcessW(
312 L"taskmgr.exe",
313 NULL,
314 NULL,
315 NULL,
316 FALSE,
317 CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS,
318 NULL,
319 NULL,
320 &StartupInfo,
321 &ProcessInformation);
322
323 CloseHandle (ProcessInformation.hProcess);
324 CloseHandle (ProcessInformation.hThread);
325 }
326 }
327
328 #if SUPPORT_CONSOLESTART
329 static BOOL StartIntoGUI(VOID)
330 {
331 HKEY WinLogonKey;
332 DWORD Type, Size, Value;
333
334 if(OpenRegistryKey(&WinLogonKey))
335 {
336 Size = sizeof(DWORD);
337 if(ERROR_SUCCESS == RegQueryValueEx(WinLogonKey,
338 L"StartGUI",
339 NULL,
340 &Type,
341 (LPBYTE)&Value,
342 &Size))
343 {
344 if(Type == REG_DWORD)
345 {
346 RegCloseKey(WinLogonKey);
347 return (Value != 0);
348 }
349 }
350 RegCloseKey(WinLogonKey);
351 }
352 return FALSE;
353 }
354
355
356 static PWCHAR
357 GetUserInit (WCHAR *CommandLine)
358 {
359 HKEY WinLogonKey;
360 BOOL GotCommandLine;
361 DWORD Type;
362 DWORD Size;
363 WCHAR Shell[_MAX_PATH];
364
365 GotCommandLine = FALSE;
366 if (OpenRegistryKey(&WinLogonKey))
367 {
368 Size = MAX_PATH;
369 if (ERROR_SUCCESS == RegQueryValueEx(WinLogonKey,
370 L"UserInit",
371 NULL,
372 &Type,
373 (LPBYTE) Shell,
374 &Size))
375 {
376 if (REG_EXPAND_SZ == Type)
377 {
378 ExpandEnvironmentStrings(Shell, CommandLine, _MAX_PATH);
379 GotCommandLine = TRUE;
380 }
381 else if (REG_SZ == Type)
382 {
383 wcscpy(CommandLine, Shell);
384 GotCommandLine = TRUE;
385 }
386 }
387 RegCloseKey(WinLogonKey);
388 }
389
390 if (! GotCommandLine)
391 {
392 GetSystemDirectory(CommandLine, MAX_PATH - 15);
393 wcscat(CommandLine, L"\\userinit.exe");
394 }
395
396 return CommandLine;
397 }
398
399
400 static BOOL
401 DoLogonUser (PWCHAR Name,
402 PWCHAR Password)
403 {
404 PROCESS_INFORMATION ProcessInformation;
405 STARTUPINFO StartupInfo;
406 WCHAR CommandLine[MAX_PATH];
407 WCHAR CurrentDirectory[MAX_PATH];
408 PROFILEINFOW ProfileInfo;
409 BOOL Result;
410 LPVOID lpEnvironment = NULL;
411 MSG Msg;
412
413 Result = LogonUserW (Name,
414 NULL,
415 Password,
416 LOGON32_LOGON_INTERACTIVE,
417 LOGON32_PROVIDER_DEFAULT,
418 &WLSession->UserToken);
419 if (!Result)
420 {
421 DbgPrint ("WL: LogonUserW() failed\n");
422 RtlDestroyEnvironment (lpEnvironment);
423 return FALSE;
424 }
425
426 /* Load the user profile */
427 ProfileInfo.dwSize = sizeof(PROFILEINFOW);
428 ProfileInfo.dwFlags = 0;
429 ProfileInfo.lpUserName = Name;
430 ProfileInfo.lpProfilePath = NULL;
431 ProfileInfo.lpDefaultPath = NULL;
432 ProfileInfo.lpServerName = NULL;
433 ProfileInfo.lpPolicyPath = NULL;
434 ProfileInfo.hProfile = NULL;
435
436 if (!LoadUserProfileW (WLSession->UserToken,
437 &ProfileInfo))
438 {
439 DbgPrint ("WL: LoadUserProfileW() failed\n");
440 CloseHandle (WLSession->UserToken);
441 RtlDestroyEnvironment (lpEnvironment);
442 return FALSE;
443 }
444
445 if (!CreateEnvironmentBlock (&lpEnvironment,
446 WLSession->UserToken,
447 TRUE))
448 {
449 DbgPrint ("WL: CreateEnvironmentBlock() failed\n");
450 return FALSE;
451 }
452
453 if (ImpersonateLoggedOnUser(WLSession->UserToken))
454 {
455 UpdatePerUserSystemParameters(0, TRUE);
456 RevertToSelf();
457 }
458
459 GetWindowsDirectoryW (CurrentDirectory, MAX_PATH);
460
461 StartupInfo.cb = sizeof(StartupInfo);
462 StartupInfo.lpReserved = NULL;
463 StartupInfo.lpDesktop = NULL;
464 StartupInfo.lpTitle = NULL;
465 StartupInfo.dwFlags = 0;
466 StartupInfo.cbReserved2 = 0;
467 StartupInfo.lpReserved2 = 0;
468
469 Result = CreateProcessAsUserW (WLSession->UserToken,
470 NULL,
471 GetUserInit (CommandLine),
472 NULL,
473 NULL,
474 FALSE,
475 CREATE_UNICODE_ENVIRONMENT,
476 lpEnvironment,
477 CurrentDirectory,
478 &StartupInfo,
479 &ProcessInformation);
480 if (!Result)
481 {
482 DbgPrint ("WL: Failed to execute user shell %s\n", CommandLine);
483 if (ImpersonateLoggedOnUser(WLSession->UserToken))
484 {
485 UpdatePerUserSystemParameters(0, FALSE);
486 RevertToSelf();
487 }
488 UnloadUserProfile (WLSession->UserToken,
489 ProfileInfo.hProfile);
490 CloseHandle (WLSession->UserToken);
491 DestroyEnvironmentBlock (lpEnvironment);
492 return FALSE;
493 }
494
495 RegisterHotKeys();
496
497 while (WaitForSingleObject (ProcessInformation.hProcess, 100) != WAIT_OBJECT_0)
498 {
499 if (PeekMessage(&Msg, 0, 0, 0, PM_REMOVE))
500 {
501 if (Msg.message == WM_HOTKEY)
502 HandleHotKey(&Msg);
503 TranslateMessage(&Msg);
504 DispatchMessage(&Msg);
505 }
506 }
507
508 UnregisterHotKeys();
509
510 CloseHandle (ProcessInformation.hProcess);
511 CloseHandle (ProcessInformation.hThread);
512
513 if (ImpersonateLoggedOnUser(WLSession->UserToken))
514 {
515 UpdatePerUserSystemParameters(0, FALSE);
516 RevertToSelf();
517 }
518
519 /* Unload user profile */
520 UnloadUserProfile (WLSession->UserToken,
521 ProfileInfo.hProfile);
522
523 CloseHandle (WLSession->UserToken);
524
525 RtlDestroyEnvironment (lpEnvironment);
526
527 return TRUE;
528 }
529 #endif
530
531 int STDCALL
532 WinMain(HINSTANCE hInstance,
533 HINSTANCE hPrevInstance,
534 LPSTR lpCmdLine,
535 int nShowCmd)
536 {
537 #if SUPPORT_CONSOLESTART
538 // WCHAR LoginName[255];
539 // WCHAR Password[255];
540 #endif
541 #if 0
542 LSA_STRING ProcessName, PackageName;
543 HANDLE LsaHandle;
544 LSA_OPERATIONAL_MODE Mode;
545 ULONG AuthenticationPackage;
546 #endif
547
548 hAppInstance = hInstance;
549
550 if(!RegisterLogonProcess(GetCurrentProcessId(), TRUE))
551 {
552 DbgPrint("WL: Could not register logon process\n");
553 NtShutdownSystem(ShutdownNoReboot);
554 ExitProcess(0);
555 return 0;
556 }
557
558 #if START_LSASS
559 if (StartProcess(L"StartLsass"))
560 {
561 if (!StartLsass())
562 {
563 DbgPrint("WL: Failed to start LSASS (0x%X)\n", GetLastError());
564 }
565 }
566 #endif
567
568 if(!(WLSession = MsGinaInit()))
569 {
570 DbgPrint("WL: Failed to initialize msgina.dll\n");
571 NtShutdownSystem(ShutdownNoReboot);
572 ExitProcess(0);
573 return 0;
574 }
575
576 WLSession->LogonStatus = LOGON_INITIALIZING;
577
578 if(!WlxCreateWindowStationAndDesktops(WLSession))
579 {
580 NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED, 0, 0, 0, 0, 0);
581 ExitProcess(1);
582 return 1;
583 }
584
585 /*
586 * Switch to winlogon desktop
587 */
588 /* FIXME: Do start up in the application desktop for now. */
589 SetThreadDesktop(WLSession->ApplicationDesktop);
590 if(!SwitchDesktop(WLSession->ApplicationDesktop))
591 {
592 DbgPrint("WL: Cannot switch to Winlogon desktop (0x%X)\n", GetLastError());
593 }
594
595 InitServices();
596
597 /* Check for pending setup */
598 if (GetSetupType () != 0)
599 {
600 DPRINT ("Winlogon: CheckForSetup() in setup mode\n");
601
602 /* Run setup and reboot when done */
603 RunSetup();
604
605 NtShutdownSystem(ShutdownReboot);
606 ExitProcess(0);
607 return 0;
608 }
609
610 #if SUPPORT_CONSOLESTART
611 StartConsole = !StartIntoGUI();
612 #endif
613 if(!InitializeSAS(WLSession))
614 {
615 DbgPrint("WL: Failed to initialize SAS\n");
616 ExitProcess(2);
617 return 2;
618 }
619
620 #if 0
621 /* real winlogon uses "Winlogon" */
622 RtlInitUnicodeString((PUNICODE_STRING)&ProcessName, L"Winlogon");
623 Status = LsaRegisterLogonProcess(&ProcessName, &LsaHandle, &Mode);
624 if (!NT_SUCCESS(Status))
625 {
626 switch(Status)
627 {
628 case STATUS_PORT_CONNECTION_REFUSED:
629 /* FIXME - we don't have the 'SeTcbPrivilege' pivilege, so set it or call
630 LsaAddAccountRights() and try again */
631 DbgPrint("WL: LsaRegisterLogonProcess() returned STATUS_PORT_CONNECTION_REFUSED\n");
632 break;
633 case STATUS_NAME_TOO_LONG:
634 DbgPrint("WL: LsaRegisterLogonProcess() returned STATUS_NAME_TOO_LONG\n");
635 break;
636 default:
637 DbgPrint("WL: Failed to connect to LSASS\n");
638 break;
639 }
640 return(1);
641 }
642
643 RtlInitUnicodeString((PUNICODE_STRING)&PackageName, L"Kerberos");
644 Status = LsaLookupAuthenticationPackage(LsaHandle, &PackageName, &AuthenticationPackage);
645 if (!NT_SUCCESS(Status))
646 {
647 LsaDeregisterLogonProcess(LsaHandle);
648 DbgPrint("WL: Failed to lookup authentication package\n");
649 return(1);
650 }
651 #endif
652
653 /* FIXME: Create a window class and associate a Winlogon
654 * window procedure with it.
655 * Register SAS with the window.
656 * Register for logoff notification
657 */
658
659 /* Main loop */
660 #if 0
661 /* Display login prompt */
662 WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),
663 LoginPrompt,
664 strlen(LoginPrompt), // wcslen(LoginPrompt),
665 &Result,
666 NULL);
667 i = 0;
668 do
669 {
670 ReadConsole(GetStdHandle(STD_INPUT_HANDLE),
671 &LoginName[i],
672 1,
673 &Result,
674 NULL);
675 i++;
676 } while (LoginName[i - 1] != '\n');
677 LoginName[i - 1] = 0;
678
679 /* Display password prompt */
680 WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),
681 PasswordPrompt,
682 strlen(PasswordPrompt), // wcslen(PasswordPrompt),
683 &Result,
684 NULL);
685 i = 0;
686 do
687 {
688 ReadConsole(GetStdHandle(STD_INPUT_HANDLE),
689 &Password[i],
690 1,
691 &Result,
692 NULL);
693 i++;
694 } while (Password[i - 1] != '\n');
695 Password[i - 1] =0;
696 #endif
697
698 #if SUPPORT_CONSOLESTART
699 if(StartConsole)
700 {
701 // if (! DoLogonUser(LoginName, Password))
702 if (! DoLogonUser(L"Administrator", L"Secret"))
703 {
704 }
705
706 NtShutdownSystem(ShutdownNoReboot);
707 ExitProcess(0);
708 }
709 else
710 {
711 #endif
712
713 RegisterHotKeys();
714
715 SessionLoop(WLSession);
716
717 UnregisterHotKeys();
718
719 /* FIXME - Flush disks and registry, ... */
720
721 if(WLSession->LogonStatus == LOGON_SHUTDOWN)
722 {
723 /* FIXME - only show this dialog if it's a shutdown and the computer doesn't support APM */
724 switch(DialogBox(hInstance, MAKEINTRESOURCE(IDD_SHUTDOWNCOMPUTER), 0, ShutdownComputerProc))
725 {
726 case IDC_BTNSHTDOWNCOMPUTER:
727 NtShutdownSystem(ShutdownReboot);
728 break;
729 default:
730 NtShutdownSystem(ShutdownNoReboot);
731 break;
732 }
733 ExitProcess(0);
734 }
735 else
736 {
737 DbgPrint("WL: LogonStatus != LOGON_SHUTDOWN!!!\n");
738 ExitProcess(0);
739 }
740 #if SUPPORT_CONSOLESTART
741 }
742 #endif
743
744 return 0;
745 }
746
747 BOOL
748 DisplayStatusMessage(PWLSESSION Session, HDESK hDesktop, DWORD dwOptions, PWSTR pTitle, PWSTR pMessage)
749 {
750 if(Session->SuppressStatus)
751 {
752 return TRUE;
753 }
754
755 #if SUPPORT_CONSOLESTART
756 if(StartConsole)
757 {
758 if(pMessage)
759 {
760 DbgPrint("WL-Status: %ws\n", pMessage);
761 }
762 return TRUE;
763 }
764 #endif
765
766 return Session->MsGina.Functions.WlxDisplayStatusMessage(Session->MsGina.Context, hDesktop, dwOptions, pTitle, pMessage);
767 }
768
769 BOOL
770 InitServices(void)
771 {
772 WCHAR StatusMsg[256];
773
774 LoadString(hAppInstance, IDS_REACTOSISSTARTINGUP, StatusMsg, 256 * sizeof(WCHAR));
775 DisplayStatusMessage(WLSession, WLSession->ApplicationDesktop, 0, NULL, StatusMsg);
776
777 /* start system processes (services.exe & lsass.exe) */
778 if(StartProcess(L"StartServices"))
779 {
780 if(!StartServices())
781 {
782 DbgPrint("WL: Failed to start Services (0x%X)\n", GetLastError());
783 }
784 }
785
786 return TRUE;
787 }
788
789 DWORD
790 DoLogin(PWLSESSION Session)
791 {
792 DWORD WlxAction, Options;
793 WLX_MPR_NOTIFY_INFO MprNotifyInfo;
794 PWLX_PROFILE_V2_0 Profile;
795 PSID LogonSid = NULL;
796 HANDLE Token;
797
798 /* FIXME - Create a Logon Sid
799 if(!(LogonSid = CreateUserLogonSid(NULL)))
800 {
801 return WLX_SAS_ACTION_NONE;
802 }
803 */
804
805 Options = 0;
806 WlxAction = Session->MsGina.Functions.WlxLoggedOutSAS(Session->MsGina.Context,
807 Session->SASAction,
808 &Session->LogonId,
809 LogonSid,
810 &Options,
811 &Token,
812 &MprNotifyInfo,
813 (PVOID*)&Profile);
814
815 return WlxAction;
816 }
817
818 void
819 SessionLoop(PWLSESSION Session)
820 {
821 //WCHAR StatusMsg[256];
822 // HANDLE hShutdownEvent;
823 DWORD WlxAction;
824 MSG Msg;
825
826 WlxAction = WLX_SAS_ACTION_NONE;
827 Session->LogonStatus = LOGON_NONE;
828 while(WlxAction == WLX_SAS_ACTION_NONE)
829 {
830 RemoveStatusMessage(Session);
831 if(Session->LogonStatus == LOGON_NONE)
832 {
833 Session->LogonStatus = LOGON_SHOWINGLOGON;
834 /* we're ready to display a logon window,
835 don't timeout dialogboxes here */
836 WlxSetTimeout(Session->MsGina.Context, 0);
837 Session->SuppressStatus = TRUE;
838 /* tell msgina to show a window telling the user one can logon */
839 #if SUPPORT_CONSOLESTART
840 if(!StartConsole)
841 #endif
842 DisplaySASNotice(Session);
843 Session->SuppressStatus = FALSE;
844
845 if(Session->SASAction == WLX_SAS_ACTION_LOGOFF)
846 {
847 /* the system wants to log off here */
848 Session->LogonStatus = LOGON_SHUTDOWN;
849 break;
850 }
851 }
852
853 WlxAction = DoLogin(Session);
854 if(WlxAction == WLX_SAS_ACTION_LOGOFF)
855 {
856 /* the user doesn't want to login, instead pressed cancel
857 we should display the window again so one can logon again */
858 /* FIXME - disconnect any connections in case we did a remote logon */
859 DbgPrint("WL: DoLogin failed\n");
860 WlxAction = WLX_SAS_ACTION_NONE;
861 }
862 if(WlxAction == WLX_SAS_ACTION_NONE)
863 {
864 if(Session->SASAction == WLX_SAS_ACTION_LOGOFF)
865 {
866 /* system is about to shut down, leave the main loop */
867 Session->LogonStatus = LOGON_SHUTDOWN;
868 break;
869 }
870 Session->LogonStatus = LOGON_NONE;
871 continue;
872 }
873
874 /* FIXME - don't leave the loop when suspending the computer */
875 if(WLX_SUSPENDING(WlxAction))
876 {
877 Session->LogonStatus = LOGON_NONE;
878 WlxAction = WLX_SAS_ACTION_NONE;
879 /* don't leave the loop */
880 continue;
881 }
882
883 if(WLX_SHUTTINGDOWN(WlxAction))
884 {
885 Session->LogonStatus = LOGON_SHUTDOWN;
886 /* leave the loop here */
887 break;
888 }
889
890 /* Message loop for the SAS window */
891 while(GetMessage(&Msg, 0, 0, 0))
892 {
893 if (Msg.message == WM_HOTKEY)
894 HandleHotKey(&Msg);
895 TranslateMessage(&Msg);
896 DispatchMessage(&Msg);
897 }
898 }
899 /*
900 LoadString(hAppInstance, IDS_PREPARENETWORKCONNECTIONS, StatusMsg, 256 * sizeof(WCHAR));
901 MsGinaInst->Functions->WlxDisplayStatusMessage(MsGinaInst->Context,
902 ApplicationDesktop,
903 0,
904 NULL,
905 StatusMsg);
906
907
908 Sleep(150);
909
910 LoadString(hAppInstance, IDS_APPLYINGCOMPUTERSETTINGS, StatusMsg, 256 * sizeof(WCHAR));
911 MsGinaInst->Functions->WlxDisplayStatusMessage(MsGinaInst->Context,
912 ApplicationDesktop,
913 0,
914 NULL,
915 StatusMsg);
916
917
918 Sleep(150);
919
920 MsGinaInst->Functions->WlxRemoveStatusMessage(MsGinaInst->Context);
921 MsGinaInst->Functions->WlxRemoveStatusMessage(MsGinaInst->Context);
922 MsGinaInst->Functions->WlxRemoveStatusMessage(MsGinaInst->Context);
923
924
925 Sleep(250);
926
927 LoadString(hAppInstance, IDS_LOADINGYOURPERSONALSETTINGS, StatusMsg, 256 * sizeof(WCHAR));
928 MsGinaInst->Functions->WlxDisplayStatusMessage(MsGinaInst->Context,
929 ApplicationDesktop,
930 0,
931 NULL,
932 StatusMsg);
933
934 Sleep(150);
935
936 LoadString(hAppInstance, IDS_APPLYINGYOURPERSONALSETTINGS, StatusMsg, 256 * sizeof(WCHAR));
937 MsGinaInst->Functions->WlxDisplayStatusMessage(MsGinaInst->Context,
938 ApplicationDesktop,
939 0,
940 NULL,
941 StatusMsg);
942
943
944 Sleep(150);
945
946 MsGinaInst->Functions->WlxRemoveStatusMessage(MsGinaInst->Context);
947 MsGinaInst->Functions->WlxRemoveStatusMessage(MsGinaInst->Context);
948
949 if(!MsGinaInst->Functions->WlxActivateUserShell(MsGinaInst->Context,
950 L"WinSta0\\Default",
951 NULL,
952 NULL))
953 {
954 LoadString(hAppInstance, IDS_FAILEDACTIVATEUSERSHELL, StatusMsg, 256 * sizeof(WCHAR));
955 MessageBox(0, StatusMsg, NULL, MB_ICONERROR);
956 SetEvent(hShutdownEvent);
957 }
958
959
960 WaitForSingleObject(hShutdownEvent, INFINITE);
961 CloseHandle(hShutdownEvent);
962
963 LoadString(hAppInstance, IDS_SAVEYOURSETTINGS, StatusMsg, 256 * sizeof(WCHAR));
964 MsGinaInst->Functions->WlxDisplayStatusMessage(MsGinaInst->Context,
965 ApplicationDesktop,
966 0,
967 NULL,
968 StatusMsg);
969
970
971 Sleep(150);
972
973 MsGinaInst->Functions->WlxShutdown(MsGinaInst->Context, WLX_SAS_ACTION_SHUTDOWN);
974
975 LoadString(hAppInstance, IDS_REACTOSISSHUTTINGDOWN, StatusMsg, 256 * sizeof(WCHAR));
976 MsGinaInst->Functions->WlxDisplayStatusMessage(MsGinaInst->Context,
977 ApplicationDesktop,
978 0,
979 NULL,
980 StatusMsg);
981
982
983 Sleep(250);
984
985 MsGinaInst->Functions->WlxRemoveStatusMessage(MsGinaInst->Context);
986 MsGinaInst->Functions->WlxRemoveStatusMessage(MsGinaInst->Context);
987 */
988 }
989