Partial patch of larger rosrtl removal patch. This one merely is a structure fix...
[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 HANDLE hToken;
409 PROFILEINFOW ProfileInfo;
410 BOOL Result;
411 LPVOID lpEnvironment = NULL;
412 MSG Msg;
413
414 Result = LogonUserW (Name,
415 NULL,
416 Password,
417 LOGON32_LOGON_INTERACTIVE,
418 LOGON32_PROVIDER_DEFAULT,
419 &hToken);
420 if (!Result)
421 {
422 DbgPrint ("WL: LogonUserW() failed\n");
423 RtlDestroyEnvironment (lpEnvironment);
424 return FALSE;
425 }
426
427 /* Load the user profile */
428 ProfileInfo.dwSize = sizeof(PROFILEINFOW);
429 ProfileInfo.dwFlags = 0;
430 ProfileInfo.lpUserName = Name;
431 ProfileInfo.lpProfilePath = NULL;
432 ProfileInfo.lpDefaultPath = NULL;
433 ProfileInfo.lpServerName = NULL;
434 ProfileInfo.lpPolicyPath = NULL;
435 ProfileInfo.hProfile = NULL;
436
437 if (!LoadUserProfileW (hToken,
438 &ProfileInfo))
439 {
440 DbgPrint ("WL: LoadUserProfileW() failed\n");
441 CloseHandle (hToken);
442 RtlDestroyEnvironment (lpEnvironment);
443 return FALSE;
444 }
445
446 if (!CreateEnvironmentBlock (&lpEnvironment,
447 hToken,
448 TRUE))
449 {
450 DbgPrint ("WL: CreateEnvironmentBlock() failed\n");
451 return FALSE;
452 }
453
454 if (ImpersonateLoggedOnUser(hToken))
455 {
456 UpdatePerUserSystemParameters(0, TRUE);
457 RevertToSelf();
458 }
459
460 GetWindowsDirectoryW (CurrentDirectory, MAX_PATH);
461
462 StartupInfo.cb = sizeof(StartupInfo);
463 StartupInfo.lpReserved = NULL;
464 StartupInfo.lpDesktop = NULL;
465 StartupInfo.lpTitle = NULL;
466 StartupInfo.dwFlags = 0;
467 StartupInfo.cbReserved2 = 0;
468 StartupInfo.lpReserved2 = 0;
469
470 Result = CreateProcessAsUserW (hToken,
471 NULL,
472 GetUserInit (CommandLine),
473 NULL,
474 NULL,
475 FALSE,
476 CREATE_UNICODE_ENVIRONMENT,
477 lpEnvironment,
478 CurrentDirectory,
479 &StartupInfo,
480 &ProcessInformation);
481 if (!Result)
482 {
483 DbgPrint ("WL: Failed to execute user shell %s\n", CommandLine);
484 if (ImpersonateLoggedOnUser(hToken))
485 {
486 UpdatePerUserSystemParameters(0, FALSE);
487 RevertToSelf();
488 }
489 UnloadUserProfile (hToken,
490 ProfileInfo.hProfile);
491 CloseHandle (hToken);
492 DestroyEnvironmentBlock (lpEnvironment);
493 return FALSE;
494 }
495
496 RegisterHotKeys();
497
498 while (WaitForSingleObject (ProcessInformation.hProcess, 100) != WAIT_OBJECT_0)
499 {
500 if (PeekMessage(&Msg, 0, 0, 0, PM_REMOVE))
501 {
502 if (Msg.message == WM_HOTKEY)
503 HandleHotKey(&Msg);
504 TranslateMessage(&Msg);
505 DispatchMessage(&Msg);
506 }
507 }
508
509 UnregisterHotKeys();
510
511 CloseHandle (ProcessInformation.hProcess);
512 CloseHandle (ProcessInformation.hThread);
513
514 if (ImpersonateLoggedOnUser(hToken))
515 {
516 UpdatePerUserSystemParameters(0, FALSE);
517 RevertToSelf();
518 }
519
520 /* Unload user profile */
521 UnloadUserProfile (hToken,
522 ProfileInfo.hProfile);
523
524 CloseHandle (hToken);
525
526 RtlDestroyEnvironment (lpEnvironment);
527
528 return TRUE;
529 }
530 #endif
531
532 int STDCALL
533 WinMain(HINSTANCE hInstance,
534 HINSTANCE hPrevInstance,
535 LPSTR lpCmdLine,
536 int nShowCmd)
537 {
538 #if SUPPORT_CONSOLESTART
539 // WCHAR LoginName[255];
540 // WCHAR Password[255];
541 #endif
542 #if 0
543 LSA_STRING ProcessName, PackageName;
544 HANDLE LsaHandle;
545 LSA_OPERATIONAL_MODE Mode;
546 ULONG AuthenticationPackage;
547 #endif
548
549 hAppInstance = hInstance;
550
551 if(!RegisterLogonProcess(GetCurrentProcessId(), TRUE))
552 {
553 DbgPrint("WL: Could not register logon process\n");
554 NtShutdownSystem(ShutdownNoReboot);
555 ExitProcess(0);
556 return 0;
557 }
558
559 #if START_LSASS
560 if (StartProcess(L"StartLsass"))
561 {
562 if (!StartLsass())
563 {
564 DbgPrint("WL: Failed to start LSASS (0x%X)\n", GetLastError());
565 }
566 }
567 #endif
568
569 if(!(WLSession = MsGinaInit()))
570 {
571 DbgPrint("WL: Failed to initialize msgina.dll\n");
572 NtShutdownSystem(ShutdownNoReboot);
573 ExitProcess(0);
574 return 0;
575 }
576
577 WLSession->LogonStatus = LOGON_INITIALIZING;
578
579 if(!WlxCreateWindowStationAndDesktops(WLSession))
580 {
581 NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED, 0, 0, 0, 0, 0);
582 ExitProcess(1);
583 return 1;
584 }
585
586 /*
587 * Switch to winlogon desktop
588 */
589 /* FIXME: Do start up in the application desktop for now. */
590 SetThreadDesktop(WLSession->ApplicationDesktop);
591 if(!SwitchDesktop(WLSession->ApplicationDesktop))
592 {
593 DbgPrint("WL: Cannot switch to Winlogon desktop (0x%X)\n", GetLastError());
594 }
595
596 /* Check for pending setup */
597 if (GetSetupType () != 0)
598 {
599 DPRINT ("Winlogon: CheckForSetup() in setup mode\n");
600
601 /* Run setup and reboot when done */
602 RunSetup();
603
604 NtShutdownSystem(ShutdownReboot);
605 ExitProcess(0);
606 return 0;
607 }
608
609 #if SUPPORT_CONSOLESTART
610 StartConsole = !StartIntoGUI();
611 #endif
612 if(!InitializeSAS(WLSession))
613 {
614 DbgPrint("WL: Failed to initialize SAS\n");
615 ExitProcess(2);
616 return 2;
617 }
618
619 InitServices();
620
621 #if 0
622 /* real winlogon uses "Winlogon" */
623 RtlInitUnicodeString((PUNICODE_STRING)&ProcessName, L"Winlogon");
624 Status = LsaRegisterLogonProcess(&ProcessName, &LsaHandle, &Mode);
625 if (!NT_SUCCESS(Status))
626 {
627 switch(Status)
628 {
629 case STATUS_PORT_CONNECTION_REFUSED:
630 /* FIXME - we don't have the 'SeTcbPrivilege' pivilege, so set it or call
631 LsaAddAccountRights() and try again */
632 DbgPrint("WL: LsaRegisterLogonProcess() returned STATUS_PORT_CONNECTION_REFUSED\n");
633 break;
634 case STATUS_NAME_TOO_LONG:
635 DbgPrint("WL: LsaRegisterLogonProcess() returned STATUS_NAME_TOO_LONG\n");
636 break;
637 default:
638 DbgPrint("WL: Failed to connect to LSASS\n");
639 break;
640 }
641 return(1);
642 }
643
644 RtlInitUnicodeString((PUNICODE_STRING)&PackageName, L"Kerberos");
645 Status = LsaLookupAuthenticationPackage(LsaHandle, &PackageName, &AuthenticationPackage);
646 if (!NT_SUCCESS(Status))
647 {
648 LsaDeregisterLogonProcess(LsaHandle);
649 DbgPrint("WL: Failed to lookup authentication package\n");
650 return(1);
651 }
652 #endif
653
654 /* FIXME: Create a window class and associate a Winlogon
655 * window procedure with it.
656 * Register SAS with the window.
657 * Register for logoff notification
658 */
659
660 /* Main loop */
661 #if 0
662 /* Display login prompt */
663 WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),
664 LoginPrompt,
665 strlen(LoginPrompt), // wcslen(LoginPrompt),
666 &Result,
667 NULL);
668 i = 0;
669 do
670 {
671 ReadConsole(GetStdHandle(STD_INPUT_HANDLE),
672 &LoginName[i],
673 1,
674 &Result,
675 NULL);
676 i++;
677 } while (LoginName[i - 1] != '\n');
678 LoginName[i - 1] = 0;
679
680 /* Display password prompt */
681 WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),
682 PasswordPrompt,
683 strlen(PasswordPrompt), // wcslen(PasswordPrompt),
684 &Result,
685 NULL);
686 i = 0;
687 do
688 {
689 ReadConsole(GetStdHandle(STD_INPUT_HANDLE),
690 &Password[i],
691 1,
692 &Result,
693 NULL);
694 i++;
695 } while (Password[i - 1] != '\n');
696 Password[i - 1] =0;
697 #endif
698
699 #if SUPPORT_CONSOLESTART
700 if(StartConsole)
701 {
702 // if (! DoLogonUser(LoginName, Password))
703 if (! DoLogonUser(L"Administrator", L"Secret"))
704 {
705 }
706
707 NtShutdownSystem(ShutdownNoReboot);
708 ExitProcess(0);
709 }
710 else
711 {
712 #endif
713
714 RegisterHotKeys();
715
716 SessionLoop(WLSession);
717
718 UnregisterHotKeys();
719
720 /* FIXME - Flush disks and registry, ... */
721
722 if(WLSession->LogonStatus == LOGON_SHUTDOWN)
723 {
724 /* FIXME - only show this dialog if it's a shutdown and the computer doesn't support APM */
725 switch(DialogBox(hInstance, MAKEINTRESOURCE(IDD_SHUTDOWNCOMPUTER), 0, ShutdownComputerProc))
726 {
727 case IDC_BTNSHTDOWNCOMPUTER:
728 NtShutdownSystem(ShutdownReboot);
729 break;
730 default:
731 NtShutdownSystem(ShutdownNoReboot);
732 break;
733 }
734 ExitProcess(0);
735 }
736 else
737 {
738 DbgPrint("WL: LogonStatus != LOGON_SHUTDOWN!!!\n");
739 ExitProcess(0);
740 }
741 #if SUPPORT_CONSOLESTART
742 }
743 #endif
744
745 return 0;
746 }
747
748 BOOL
749 DisplayStatusMessage(PWLSESSION Session, HDESK hDesktop, DWORD dwOptions, PWSTR pTitle, PWSTR pMessage)
750 {
751 if(Session->SuppressStatus)
752 {
753 return TRUE;
754 }
755
756 #if SUPPORT_CONSOLESTART
757 if(StartConsole)
758 {
759 if(pMessage)
760 {
761 DbgPrint("WL-Status: %ws\n", pMessage);
762 }
763 return TRUE;
764 }
765 #endif
766
767 return Session->MsGina.Functions.WlxDisplayStatusMessage(Session->MsGina.Context, hDesktop, dwOptions, pTitle, pMessage);
768 }
769
770 BOOL
771 InitServices(void)
772 {
773 WCHAR StatusMsg[256];
774
775 LoadString(hAppInstance, IDS_REACTOSISSTARTINGUP, StatusMsg, 256 * sizeof(WCHAR));
776 DisplayStatusMessage(WLSession, WLSession->ApplicationDesktop, 0, NULL, StatusMsg);
777
778 /* start system processes (services.exe & lsass.exe) */
779 if(StartProcess(L"StartServices"))
780 {
781 if(!StartServices())
782 {
783 DbgPrint("WL: Failed to start Services (0x%X)\n", GetLastError());
784 }
785 }
786
787 return TRUE;
788 }
789
790 DWORD
791 DoLogin(PWLSESSION Session)
792 {
793 DWORD WlxAction, Options;
794 WLX_MPR_NOTIFY_INFO MprNotifyInfo;
795 PWLX_PROFILE_V2_0 Profile;
796 PSID LogonSid = NULL;
797 HANDLE Token;
798
799 /* FIXME - Create a Logon Sid
800 if(!(LogonSid = CreateUserLogonSid(NULL)))
801 {
802 return WLX_SAS_ACTION_NONE;
803 }
804 */
805
806 Options = 0;
807 WlxAction = Session->MsGina.Functions.WlxLoggedOutSAS(Session->MsGina.Context,
808 Session->SASAction,
809 &Session->LogonId,
810 LogonSid,
811 &Options,
812 &Token,
813 &MprNotifyInfo,
814 (PVOID*)&Profile);
815
816 return WlxAction;
817 }
818
819 void
820 SessionLoop(PWLSESSION Session)
821 {
822 //WCHAR StatusMsg[256];
823 // HANDLE hShutdownEvent;
824 DWORD WlxAction;
825 MSG Msg;
826
827 WlxAction = WLX_SAS_ACTION_NONE;
828 Session->LogonStatus = LOGON_NONE;
829 while(WlxAction == WLX_SAS_ACTION_NONE)
830 {
831 RemoveStatusMessage(Session);
832 if(Session->LogonStatus == LOGON_NONE)
833 {
834 Session->LogonStatus = LOGON_SHOWINGLOGON;
835 /* we're ready to display a logon window,
836 don't timeout dialogboxes here */
837 WlxSetTimeout(Session->MsGina.Context, 0);
838 Session->SuppressStatus = TRUE;
839 /* tell msgina to show a window telling the user one can logon */
840 #if SUPPORT_CONSOLESTART
841 if(!StartConsole)
842 #endif
843 DisplaySASNotice(Session);
844 Session->SuppressStatus = FALSE;
845
846 if(Session->SASAction == WLX_SAS_ACTION_LOGOFF)
847 {
848 /* the system wants to log off here */
849 Session->LogonStatus = LOGON_SHUTDOWN;
850 break;
851 }
852 }
853
854 WlxAction = DoLogin(Session);
855 if(WlxAction == WLX_SAS_ACTION_LOGOFF)
856 {
857 /* the user doesn't want to login, instead pressed cancel
858 we should display the window again so one can logon again */
859 /* FIXME - disconnect any connections in case we did a remote logon */
860 DbgPrint("WL: DoLogin failed\n");
861 WlxAction = WLX_SAS_ACTION_NONE;
862 }
863 if(WlxAction == WLX_SAS_ACTION_NONE)
864 {
865 if(Session->SASAction == WLX_SAS_ACTION_LOGOFF)
866 {
867 /* system is about to shut down, leave the main loop */
868 Session->LogonStatus = LOGON_SHUTDOWN;
869 break;
870 }
871 Session->LogonStatus = LOGON_NONE;
872 continue;
873 }
874
875 /* FIXME - don't leave the loop when suspending the computer */
876 if(WLX_SUSPENDING(WlxAction))
877 {
878 Session->LogonStatus = LOGON_NONE;
879 WlxAction = WLX_SAS_ACTION_NONE;
880 /* don't leave the loop */
881 continue;
882 }
883
884 if(WLX_SHUTTINGDOWN(WlxAction))
885 {
886 Session->LogonStatus = LOGON_SHUTDOWN;
887 /* leave the loop here */
888 break;
889 }
890
891 /* Message loop for the SAS window */
892 while(GetMessage(&Msg, 0, 0, 0))
893 {
894 if (Msg.message == WM_HOTKEY)
895 HandleHotKey(&Msg);
896 TranslateMessage(&Msg);
897 DispatchMessage(&Msg);
898 }
899 }
900 /*
901 LoadString(hAppInstance, IDS_PREPARENETWORKCONNECTIONS, StatusMsg, 256 * sizeof(WCHAR));
902 MsGinaInst->Functions->WlxDisplayStatusMessage(MsGinaInst->Context,
903 ApplicationDesktop,
904 0,
905 NULL,
906 StatusMsg);
907
908
909 Sleep(150);
910
911 LoadString(hAppInstance, IDS_APPLYINGCOMPUTERSETTINGS, StatusMsg, 256 * sizeof(WCHAR));
912 MsGinaInst->Functions->WlxDisplayStatusMessage(MsGinaInst->Context,
913 ApplicationDesktop,
914 0,
915 NULL,
916 StatusMsg);
917
918
919 Sleep(150);
920
921 MsGinaInst->Functions->WlxRemoveStatusMessage(MsGinaInst->Context);
922 MsGinaInst->Functions->WlxRemoveStatusMessage(MsGinaInst->Context);
923 MsGinaInst->Functions->WlxRemoveStatusMessage(MsGinaInst->Context);
924
925
926 Sleep(250);
927
928 LoadString(hAppInstance, IDS_LOADINGYOURPERSONALSETTINGS, StatusMsg, 256 * sizeof(WCHAR));
929 MsGinaInst->Functions->WlxDisplayStatusMessage(MsGinaInst->Context,
930 ApplicationDesktop,
931 0,
932 NULL,
933 StatusMsg);
934
935 Sleep(150);
936
937 LoadString(hAppInstance, IDS_APPLYINGYOURPERSONALSETTINGS, StatusMsg, 256 * sizeof(WCHAR));
938 MsGinaInst->Functions->WlxDisplayStatusMessage(MsGinaInst->Context,
939 ApplicationDesktop,
940 0,
941 NULL,
942 StatusMsg);
943
944
945 Sleep(150);
946
947 MsGinaInst->Functions->WlxRemoveStatusMessage(MsGinaInst->Context);
948 MsGinaInst->Functions->WlxRemoveStatusMessage(MsGinaInst->Context);
949
950 if(!MsGinaInst->Functions->WlxActivateUserShell(MsGinaInst->Context,
951 L"WinSta0\\Default",
952 NULL,
953 NULL))
954 {
955 LoadString(hAppInstance, IDS_FAILEDACTIVATEUSERSHELL, StatusMsg, 256 * sizeof(WCHAR));
956 MessageBox(0, StatusMsg, NULL, MB_ICONERROR);
957 SetEvent(hShutdownEvent);
958 }
959
960
961 WaitForSingleObject(hShutdownEvent, INFINITE);
962 CloseHandle(hShutdownEvent);
963
964 LoadString(hAppInstance, IDS_SAVEYOURSETTINGS, StatusMsg, 256 * sizeof(WCHAR));
965 MsGinaInst->Functions->WlxDisplayStatusMessage(MsGinaInst->Context,
966 ApplicationDesktop,
967 0,
968 NULL,
969 StatusMsg);
970
971
972 Sleep(150);
973
974 MsGinaInst->Functions->WlxShutdown(MsGinaInst->Context, WLX_SAS_ACTION_SHUTDOWN);
975
976 LoadString(hAppInstance, IDS_REACTOSISSHUTTINGDOWN, StatusMsg, 256 * sizeof(WCHAR));
977 MsGinaInst->Functions->WlxDisplayStatusMessage(MsGinaInst->Context,
978 ApplicationDesktop,
979 0,
980 NULL,
981 StatusMsg);
982
983
984 Sleep(250);
985
986 MsGinaInst->Functions->WlxRemoveStatusMessage(MsGinaInst->Context);
987 MsGinaInst->Functions->WlxRemoveStatusMessage(MsGinaInst->Context);
988 */
989 }
990