ReactOS 0.4.16-dev-981-g80eb313
sas.c File Reference
#include "winlogon.h"
#include <aclapi.h>
#include <mmsystem.h>
#include <userenv.h>
#include <ndk/setypes.h>
#include <ndk/sefuncs.h>
Include dependency graph for sas.c:

Go to the source code of this file.

Classes

struct  tagLOGOFF_SHUTDOWN_DATA
 
struct  tagLOGON_SOUND_DATA
 

Macros

#define WIN32_LEAN_AND_MEAN
 
#define WINLOGON_SAS_CLASS   L"SAS Window class"
 
#define WINLOGON_SAS_TITLE   L"SAS window"
 
#define HK_CTRL_ALT_DEL   0
 
#define HK_CTRL_SHIFT_ESC   1
 
#define EWX_ACTION_MASK   0x5C0F
 

Typedefs

typedef struct tagLOGOFF_SHUTDOWN_DATA LOGOFF_SHUTDOWN_DATA
 
typedef struct tagLOGOFF_SHUTDOWN_DATAPLOGOFF_SHUTDOWN_DATA
 
typedef struct tagLOGON_SOUND_DATA LOGON_SOUND_DATA
 
typedef struct tagLOGON_SOUND_DATAPLOGON_SOUND_DATA
 

Functions

static BOOL StartTaskManager (IN OUT PWLSESSION Session)
 
static BOOL StartUserShell (IN OUT PWLSESSION Session)
 
BOOL SetDefaultLanguage (IN PWLSESSION Session)
 
BOOL PlaySoundRoutine (IN LPCWSTR FileName, IN UINT bLogon, IN UINT Flags)
 
static DWORD WINAPI PlayLogonSoundThread (_In_ LPVOID lpParameter)
 
static VOID PlayLogonSound (_In_ PWLSESSION Session)
 
static VOID PlayLogoffShutdownSound (_In_ PWLSESSION Session, _In_ BOOL bShutdown)
 
static BOOL PlayEventSound (_In_ PWLSESSION Session, _In_ LPCWSTR EventName)
 
static VOID RestoreAllConnections (PWLSESSION Session)
 
static BOOL HandleLogon (IN OUT PWLSESSION Session)
 
static DWORD WINAPI LogoffShutdownThread (LPVOID Parameter)
 
static DWORD WINAPI KillComProcesses (LPVOID Parameter)
 
static NTSTATUS CreateLogoffSecurityAttributes (OUT PSECURITY_ATTRIBUTES *ppsa)
 
static VOID DestroyLogoffSecurityAttributes (IN PSECURITY_ATTRIBUTES psa)
 
static NTSTATUS HandleLogoff (_Inout_ PWLSESSION Session, _In_ DWORD wlxAction)
 
static INT_PTR CALLBACK ShutdownComputerWindowProc (IN HWND hwndDlg, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lParam)
 
static VOID UninitializeSAS (IN OUT PWLSESSION Session)
 
NTSTATUS HandleShutdown (IN OUT PWLSESSION Session, IN DWORD wlxAction)
 
static VOID DoGenericAction (IN OUT PWLSESSION Session, IN DWORD wlxAction)
 
static VOID DispatchSAS (IN OUT PWLSESSION Session, IN DWORD dwSasType)
 
static BOOL RegisterHotKeys (IN PWLSESSION Session, IN HWND hwndSAS)
 
static BOOL UnregisterHotKeys (IN PWLSESSION Session, IN HWND hwndSAS)
 
static BOOL HandleMessageBeep (_In_ PWLSESSION Session, _In_ UINT uType)
 
static LRESULT CALLBACK SASWindowProc (IN HWND hwndDlg, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lParam)
 
BOOL InitializeSAS (IN OUT PWLSESSION Session)
 

Variables

static BOOL ExitReactOSInProgress = FALSE
 
LUID LuidNone = {0, 0}
 

Macro Definition Documentation

◆ EWX_ACTION_MASK

#define EWX_ACTION_MASK   0x5C0F

Definition at line 37 of file sas.c.

◆ HK_CTRL_ALT_DEL

#define HK_CTRL_ALT_DEL   0

Definition at line 29 of file sas.c.

◆ HK_CTRL_SHIFT_ESC

#define HK_CTRL_SHIFT_ESC   1

Definition at line 30 of file sas.c.

◆ WIN32_LEAN_AND_MEAN

#define WIN32_LEAN_AND_MEAN

Definition at line 17 of file sas.c.

◆ WINLOGON_SAS_CLASS

#define WINLOGON_SAS_CLASS   L"SAS Window class"

Definition at line 26 of file sas.c.

◆ WINLOGON_SAS_TITLE

#define WINLOGON_SAS_TITLE   L"SAS window"

Definition at line 27 of file sas.c.

Typedef Documentation

◆ LOGOFF_SHUTDOWN_DATA

◆ LOGON_SOUND_DATA

◆ PLOGOFF_SHUTDOWN_DATA

◆ PLOGON_SOUND_DATA

Function Documentation

◆ CreateLogoffSecurityAttributes()

static NTSTATUS CreateLogoffSecurityAttributes ( OUT PSECURITY_ATTRIBUTES ppsa)
static

Definition at line 694 of file sas.c.

696{
697 /* The following code is not working yet and messy */
698 /* Still, it gives some ideas about data types and functions involved and */
699 /* required to set up a SECURITY_DESCRIPTOR for a SECURITY_ATTRIBUTES */
700 /* instance for a thread, to allow that thread to ImpersonateLoggedOnUser(). */
701 /* Specifically THREAD_SET_THREAD_TOKEN is required. */
704 BYTE* pMem;
705 PACL pACL;
706 EXPLICIT_ACCESS Access;
707 PSID pEveryoneSID = NULL;
709
710 *ppsa = NULL;
711
712 // Let's first try to enumerate what kind of data we need for this to ever work:
713 // 1. The Winlogon SID, to be able to give it THREAD_SET_THREAD_TOKEN.
714 // 2. The users SID (the user trying to logoff, or rather shut down the system).
715 // 3. At least two EXPLICIT_ACCESS instances:
716 // 3.1 One for Winlogon itself, giving it the rights
717 // required to THREAD_SET_THREAD_TOKEN (as it's needed to successfully call
718 // ImpersonateLoggedOnUser).
719 // 3.2 One for the user, to allow *that* thread to perform its work.
720 // 4. An ACL to hold the these EXPLICIT_ACCESS ACE's.
721 // 5. A SECURITY_DESCRIPTOR to hold the ACL, and finally.
722 // 6. A SECURITY_ATTRIBUTES instance to pull all of this required stuff
723 // together, to hand it to CreateThread.
724 //
725 // However, it seems struct LOGOFF_SHUTDOWN_DATA doesn't contain
726 // these required SID's, why they'd have to be added.
727 // The Winlogon's own SID should probably only be created once,
728 // while the user's SID obviously must be created for each new user.
729 // Might as well store it when the user logs on?
730
732 1,
734 0, 0, 0, 0, 0, 0, 0,
735 &pEveryoneSID))
736 {
737 ERR("Failed to initialize security descriptor for logoff thread!\n");
738 return STATUS_UNSUCCESSFUL;
739 }
740
741 /* set up the required security attributes to be able to shut down */
742 /* To save space and time, allocate a single block of memory holding */
743 /* both SECURITY_ATTRIBUTES and SECURITY_DESCRIPTOR */
744 pMem = HeapAlloc(GetProcessHeap(),
745 0,
746 sizeof(SECURITY_ATTRIBUTES) +
748 sizeof(ACL));
749 if (!pMem)
750 {
751 ERR("Failed to allocate memory for logoff security descriptor!\n");
752 return STATUS_NO_MEMORY;
753 }
754
755 /* Note that the security descriptor needs to be in _absolute_ format, */
756 /* meaning its members must be pointers to other structures, rather */
757 /* than the relative format using offsets */
761
762 // Initialize an EXPLICIT_ACCESS structure for an ACE.
763 // The ACE will allow this thread to log off (and shut down the system, currently).
764 ZeroMemory(&Access, sizeof(Access));
766 Access.grfAccessMode = SET_ACCESS; // GRANT_ACCESS?
770 Access.Trustee.ptstrName = pEveryoneSID;
771
772 if (SetEntriesInAcl(1, &Access, NULL, &pACL) != ERROR_SUCCESS)
773 {
774 ERR("Failed to set Access Rights for logoff thread. Logging out will most likely fail.\n");
775
776 HeapFree(GetProcessHeap(), 0, pMem);
777 return STATUS_UNSUCCESSFUL;
778 }
779
781 {
782 ERR("Failed to initialize security descriptor for logoff thread!\n");
783 HeapFree(GetProcessHeap(), 0, pMem);
784 return STATUS_UNSUCCESSFUL;
785 }
786
788 TRUE, // bDaclPresent flag
789 pACL,
790 FALSE)) // not a default DACL
791 {
792 ERR("SetSecurityDescriptorDacl Error %lu\n", GetLastError());
793 HeapFree(GetProcessHeap(), 0, pMem);
794 return STATUS_UNSUCCESSFUL;
795 }
796
797 psa->nLength = sizeof(SECURITY_ATTRIBUTES);
798 psa->lpSecurityDescriptor = SecurityDescriptor;
799 psa->bInheritHandle = FALSE;
800
801 *ppsa = psa;
802
803 return STATUS_SUCCESS;
804}
@ TRUSTEE_IS_SID
Definition: accctrl.h:189
@ TRUSTEE_IS_WELL_KNOWN_GROUP
Definition: accctrl.h:181
#define NO_INHERITANCE
Definition: accctrl.h:103
@ SET_ACCESS
Definition: accctrl.h:150
#define SetEntriesInAcl
Definition: aclapi.h:240
#define ERR(fmt,...)
Definition: precomp.h:57
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOL WINAPI AllocateAndInitializeSid(PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority, BYTE nSubAuthorityCount, DWORD nSubAuthority0, DWORD nSubAuthority1, DWORD nSubAuthority2, DWORD nSubAuthority3, DWORD nSubAuthority4, DWORD nSubAuthority5, DWORD nSubAuthority6, DWORD nSubAuthority7, PSID *pSid)
Definition: security.c:674
BOOL WINAPI InitializeSecurityDescriptor(PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD dwRevision)
Definition: security.c:929
#define GetProcessHeap()
Definition: compat.h:736
struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES
#define HeapAlloc
Definition: compat.h:733
struct _SECURITY_ATTRIBUTES * PSECURITY_ATTRIBUTES
#define HeapFree(x, y, z)
Definition: compat.h:735
static SID_IDENTIFIER_AUTHORITY WorldAuthority
Definition: security.c:14
#define THREAD_SET_THREAD_TOKEN
Definition: pstypes.h:151
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
struct _SECURITY_DESCRIPTOR * PSECURITY_DESCRIPTOR
Definition: security.c:98
struct _ACL * PACL
Definition: security.c:105
BYTE * PBYTE
Definition: pedump.c:66
BOOL WINAPI SetSecurityDescriptorDacl(PSECURITY_DESCRIPTOR pSecurityDescriptor, BOOL bDaclPresent, PACL pDacl, BOOL bDaclDefaulted)
Definition: sec.c:262
#define STATUS_SUCCESS
Definition: shellext.h:65
DWORD grfAccessPermissions
Definition: accctrl.h:332
TRUSTEE_A Trustee
Definition: accctrl.h:335
DWORD grfInheritance
Definition: accctrl.h:334
ACCESS_MODE grfAccessMode
Definition: accctrl.h:333
TRUSTEE_TYPE TrusteeType
Definition: accctrl.h:207
TRUSTEE_FORM TrusteeForm
Definition: accctrl.h:206
LPSTR ptstrName
Definition: accctrl.h:208
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ZeroMemory
Definition: winbase.h:1743
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
_In_ USHORT _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _Reserved_ ULONG _In_opt_ PVOID _In_opt_ const WSK_CLIENT_CONNECTION_DISPATCH _In_opt_ PEPROCESS _In_opt_ PETHREAD _In_opt_ PSECURITY_DESCRIPTOR SecurityDescriptor
Definition: wsk.h:191
#define SECURITY_WORLD_SID_AUTHORITY
Definition: setypes.h:527
#define SECURITY_WORLD_RID
Definition: setypes.h:541
#define SECURITY_DESCRIPTOR_REVISION
Definition: setypes.h:58
#define SECURITY_DESCRIPTOR_MIN_LENGTH
Definition: setypes.h:815
unsigned char BYTE
Definition: xxhash.c:193

Referenced by HandleLogoff().

◆ DestroyLogoffSecurityAttributes()

static VOID DestroyLogoffSecurityAttributes ( IN PSECURITY_ATTRIBUTES  psa)
static

Definition at line 808 of file sas.c.

810{
811 if (psa)
812 {
814 }
815}

Referenced by HandleLogoff().

◆ DispatchSAS()

static VOID DispatchSAS ( IN OUT PWLSESSION  Session,
IN DWORD  dwSasType 
)
static

Definition at line 1149 of file sas.c.

1152{
1153 DWORD wlxAction = WLX_SAS_ACTION_NONE;
1154 PSID LogonSid = NULL; /* FIXME */
1155 BOOL bSecure = TRUE;
1156
1157 switch (dwSasType)
1158 {
1160 switch (Session->LogonState)
1161 {
1162 case STATE_INIT:
1163 Session->LogonState = STATE_LOGGED_OFF;
1164 Session->Gina.Functions.WlxDisplaySASNotice(Session->Gina.Context);
1165 return;
1166
1167 case STATE_LOGGED_OFF:
1168 Session->LogonState = STATE_LOGGED_OFF_SAS;
1169
1171
1172 Session->Options = 0;
1173
1174 wlxAction = (DWORD)Session->Gina.Functions.WlxLoggedOutSAS(
1175 Session->Gina.Context,
1176 Session->SASAction,
1177 &Session->LogonId,
1178 LogonSid,
1179 &Session->Options,
1180 &Session->UserToken,
1181 &Session->MprNotifyInfo,
1182 (PVOID*)&Session->Profile);
1183 break;
1184
1186 /* Ignore SAS if we are already in an SAS state */
1187 return;
1188
1189 case STATE_LOGGED_ON:
1190 Session->LogonState = STATE_LOGGED_ON_SAS;
1191 wlxAction = (DWORD)Session->Gina.Functions.WlxLoggedOnSAS(Session->Gina.Context, dwSasType, NULL);
1192 break;
1193
1195 /* Ignore SAS if we are already in an SAS state */
1196 return;
1197
1198 case STATE_LOCKED:
1199 Session->LogonState = STATE_LOCKED_SAS;
1200
1202
1203 wlxAction = (DWORD)Session->Gina.Functions.WlxWkstaLockedSAS(Session->Gina.Context, dwSasType);
1204 break;
1205
1206 case STATE_LOCKED_SAS:
1207 /* Ignore SAS if we are already in an SAS state */
1208 return;
1209
1210 default:
1211 return;
1212 }
1213 break;
1214
1216 return;
1217
1219 if (!Session->Gina.Functions.WlxScreenSaverNotify(Session->Gina.Context, &bSecure))
1220 {
1221 /* Skip start of screen saver */
1222 SetEvent(Session->hEndOfScreenSaver);
1223 }
1224 else
1225 {
1226 StartScreenSaver(Session);
1227 if (bSecure)
1228 {
1229 wlxAction = WLX_SAS_ACTION_LOCK_WKSTA;
1230// DoGenericAction(Session, WLX_SAS_ACTION_LOCK_WKSTA);
1231 }
1232 }
1233 break;
1234
1236 SetEvent(Session->hUserActivity);
1237 break;
1238 }
1239
1240 DoGenericAction(Session, wlxAction);
1241}
VOID StartScreenSaver(IN PWLSESSION Session)
Definition: screensaver.c:257
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define DWORD
Definition: nt_native.h:44
static VOID DoGenericAction(IN OUT PWLSESSION Session, IN DWORD wlxAction)
Definition: sas.c:1058
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
@ STATE_LOGGED_ON
Definition: winlogon.h:207
@ STATE_LOGGED_OFF_SAS
Definition: winlogon.h:206
@ STATE_LOCKED_SAS
Definition: winlogon.h:210
@ STATE_INIT
Definition: winlogon.h:204
@ STATE_LOGGED_OFF
Definition: winlogon.h:205
@ STATE_LOGGED_ON_SAS
Definition: winlogon.h:208
@ STATE_LOCKED
Definition: winlogon.h:209
VOID CloseAllDialogWindows(VOID)
Definition: wlx.c:95
#define WLX_SAS_TYPE_TIMEOUT
Definition: winwlx.h:35
#define WLX_SAS_ACTION_NONE
Definition: winwlx.h:54
#define WLX_SAS_TYPE_CTRL_ALT_DEL
Definition: winwlx.h:36
#define WLX_SAS_TYPE_SCRNSVR_TIMEOUT
Definition: winwlx.h:37
#define WLX_SAS_TYPE_SCRNSVR_ACTIVITY
Definition: winwlx.h:38
#define WLX_SAS_ACTION_LOCK_WKSTA
Definition: winwlx.h:55

Referenced by SASWindowProc().

◆ DoGenericAction()

static VOID DoGenericAction ( IN OUT PWLSESSION  Session,
IN DWORD  wlxAction 
)
static

Definition at line 1058 of file sas.c.

1061{
1062 switch (wlxAction)
1063 {
1064 case WLX_SAS_ACTION_LOGON: /* 0x01 */
1065 if (Session->LogonState == STATE_LOGGED_OFF_SAS)
1066 {
1067 if (!HandleLogon(Session))
1068 {
1069 Session->Gina.Functions.WlxDisplaySASNotice(Session->Gina.Context);
1071 }
1072 }
1073 break;
1074 case WLX_SAS_ACTION_NONE: /* 0x02 */
1075 if (Session->LogonState == STATE_LOGGED_OFF_SAS)
1076 {
1077 Session->LogonState = STATE_LOGGED_OFF;
1078 Session->Gina.Functions.WlxDisplaySASNotice(Session->Gina.Context);
1079 }
1080 else if (Session->LogonState == STATE_LOGGED_ON_SAS)
1081 {
1082 Session->LogonState = STATE_LOGGED_ON;
1083 }
1084 else if (Session->LogonState == STATE_LOCKED_SAS)
1085 {
1086 Session->LogonState = STATE_LOCKED;
1087 Session->Gina.Functions.WlxDisplayLockedNotice(Session->Gina.Context);
1088 }
1089 break;
1090 case WLX_SAS_ACTION_LOCK_WKSTA: /* 0x03 */
1091 if (Session->Gina.Functions.WlxIsLockOk(Session->Gina.Context))
1092 {
1093 SwitchDesktop(Session->WinlogonDesktop);
1094 Session->LogonState = STATE_LOCKED;
1095 Session->Gina.Functions.WlxDisplayLockedNotice(Session->Gina.Context);
1097 }
1098 break;
1099 case WLX_SAS_ACTION_LOGOFF: /* 0x04 */
1100 case WLX_SAS_ACTION_SHUTDOWN: /* 0x05 */
1101 case WLX_SAS_ACTION_FORCE_LOGOFF: /* 0x09 */
1102 case WLX_SAS_ACTION_SHUTDOWN_POWER_OFF: /* 0x0a */
1103 case WLX_SAS_ACTION_SHUTDOWN_REBOOT: /* 0x0b */
1104 if (Session->LogonState != STATE_LOGGED_OFF)
1105 {
1106 if (!Session->Gina.Functions.WlxIsLogoffOk(Session->Gina.Context))
1107 break;
1108 if (!NT_SUCCESS(HandleLogoff(Session, wlxAction)))
1109 {
1110 RemoveStatusMessage(Session);
1111 break;
1112 }
1113 Session->Gina.Functions.WlxLogoff(Session->Gina.Context);
1114 }
1115 if (WLX_SHUTTINGDOWN(wlxAction))
1116 {
1117 // FIXME: WlxShutdown should be done from inside HandleShutdown,
1118 // after having displayed "ReactOS is shutting down" message.
1119 Session->Gina.Functions.WlxShutdown(Session->Gina.Context, wlxAction);
1120 if (!NT_SUCCESS(HandleShutdown(Session, wlxAction)))
1121 {
1122 RemoveStatusMessage(Session);
1123 Session->Gina.Functions.WlxDisplaySASNotice(Session->Gina.Context);
1124 }
1125 }
1126 else
1127 {
1128 RemoveStatusMessage(Session);
1129 Session->Gina.Functions.WlxDisplaySASNotice(Session->Gina.Context);
1130 }
1131 break;
1132 case WLX_SAS_ACTION_TASKLIST: /* 0x07 */
1133 SwitchDesktop(Session->ApplicationDesktop);
1134 Session->LogonState = STATE_LOGGED_ON;
1135 StartTaskManager(Session);
1136 break;
1137 case WLX_SAS_ACTION_UNLOCK_WKSTA: /* 0x08 */
1138 SwitchDesktop(Session->ApplicationDesktop);
1139 Session->LogonState = STATE_LOGGED_ON;
1141 break;
1142 default:
1143 WARN("Unknown SAS action 0x%lx\n", wlxAction);
1144 }
1145}
#define WARN(fmt,...)
Definition: precomp.h:61
VOID CallNotificationDlls(PWLSESSION pSession, NOTIFICATION_TYPE Type)
Definition: notify.c:390
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
NTSTATUS HandleShutdown(IN OUT PWLSESSION Session, IN DWORD wlxAction)
Definition: sas.c:970
static BOOL StartTaskManager(IN OUT PWLSESSION Session)
Definition: sas.c:58
static BOOL HandleLogon(IN OUT PWLSESSION Session)
Definition: sas.c:494
static NTSTATUS HandleLogoff(_Inout_ PWLSESSION Session, _In_ DWORD wlxAction)
Definition: sas.c:820
BOOL RemoveStatusMessage(IN PWLSESSION Session)
Definition: winlogon.c:370
#define WLX_SHUTTINGDOWN(Status)
Definition: winlogon.h:278
@ LogonHandler
Definition: winlogon.h:260
@ UnlockHandler
Definition: winlogon.h:263
@ LockHandler
Definition: winlogon.h:262
BOOL WINAPI SwitchDesktop(_In_ HDESK)
#define WLX_SAS_ACTION_FORCE_LOGOFF
Definition: winwlx.h:61
#define WLX_SAS_ACTION_UNLOCK_WKSTA
Definition: winwlx.h:60
#define WLX_SAS_ACTION_LOGON
Definition: winwlx.h:53
#define WLX_SAS_ACTION_TASKLIST
Definition: winwlx.h:59
#define WLX_SAS_ACTION_SHUTDOWN_POWER_OFF
Definition: winwlx.h:62
#define WLX_SAS_ACTION_SHUTDOWN
Definition: winwlx.h:57
#define WLX_SAS_ACTION_SHUTDOWN_REBOOT
Definition: winwlx.h:63
#define WLX_SAS_ACTION_LOGOFF
Definition: winwlx.h:56

Referenced by DispatchSAS(), and SASWindowProc().

◆ HandleLogoff()

static NTSTATUS HandleLogoff ( _Inout_ PWLSESSION  Session,
_In_ DWORD  wlxAction 
)
static

Definition at line 820 of file sas.c.

823{
827 DWORD exitCode;
829
830 /* Prepare data for logoff thread */
831 LSData = HeapAlloc(GetProcessHeap(), 0, sizeof(LOGOFF_SHUTDOWN_DATA));
832 if (!LSData)
833 {
834 ERR("Failed to allocate mem for thread data\n");
835 return STATUS_NO_MEMORY;
836 }
837
838 LSData->Flags = EWX_LOGOFF;
839 if (wlxAction == WLX_SAS_ACTION_FORCE_LOGOFF)
840 {
841 LSData->Flags |= EWX_FORCE;
842 }
843
844 LSData->Session = Session;
845
847 if (!NT_SUCCESS(Status))
848 {
849 ERR("Failed to create a required security descriptor. Status 0x%08lx\n", Status);
850 HeapFree(GetProcessHeap(), 0, LSData);
851 return Status;
852 }
853
854 /* Run logoff thread */
856 if (!hThread)
857 {
858 ERR("Unable to create logoff thread, error %lu\n", GetLastError());
860 HeapFree(GetProcessHeap(), 0, LSData);
861 return STATUS_UNSUCCESSFUL;
862 }
864 if (!GetExitCodeThread(hThread, &exitCode))
865 {
866 ERR("Unable to get exit code of logoff thread (error %lu)\n", GetLastError());
869 HeapFree(GetProcessHeap(), 0, LSData);
870 return STATUS_UNSUCCESSFUL;
871 }
873 if (exitCode == 0)
874 {
875 ERR("Logoff thread returned failure\n");
877 HeapFree(GetProcessHeap(), 0, LSData);
878 return STATUS_UNSUCCESSFUL;
879 }
880
881 SwitchDesktop(Session->WinlogonDesktop);
882
883 PlayLogoffShutdownSound(Session, WLX_SHUTTINGDOWN(wlxAction));
884
885 SetWindowStationUser(Session->InteractiveWindowStation,
886 &LuidNone, NULL, 0);
887
888 // DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_LOGGINGOFF);
889
890 // FIXME: Closing network connections!
891 // DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_CLOSINGNETWORKCONNECTIONS);
892
893 /* Kill remaining COM apps. Only at logoff! */
895 if (hThread)
896 {
899 }
900
901 /* We're done with the SECURITY_DESCRIPTOR */
903 psa = NULL;
904
905 HeapFree(GetProcessHeap(), 0, LSData);
906
907 DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_SAVEYOURSETTINGS);
908
909 UnloadUserProfile(Session->UserToken, Session->hProfileInfo);
910
912
913 CloseHandle(Session->UserToken);
915 Session->LogonState = STATE_LOGGED_OFF;
916 Session->UserToken = NULL;
917
918 return STATUS_SUCCESS;
919}
DWORD WINAPI UpdatePerUserSystemParameters(DWORD dw1, DWORD dw2)
LONG NTSTATUS
Definition: precomp.h:26
#define IDS_SAVEYOURSETTINGS
Definition: resource.h:34
#define CloseHandle
Definition: compat.h:739
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:137
BOOL WINAPI GetExitCodeThread(IN HANDLE hThread, OUT LPDWORD lpExitCode)
Definition: thread.c:541
BOOL WINAPI UnloadUserProfile(_In_ HANDLE hToken, _In_ HANDLE hProfile)
Definition: profile.c:2184
#define INFINITE
Definition: serial.h:102
Status
Definition: gdiplustypes.h:25
HANDLE hThread
Definition: wizard.c:28
static NTSTATUS CreateLogoffSecurityAttributes(OUT PSECURITY_ATTRIBUTES *ppsa)
Definition: sas.c:694
static DWORD WINAPI KillComProcesses(LPVOID Parameter)
Definition: sas.c:664
LUID LuidNone
Definition: sas.c:47
static VOID PlayLogoffShutdownSound(_In_ PWLSESSION Session, _In_ BOOL bShutdown)
Definition: sas.c:395
static VOID DestroyLogoffSecurityAttributes(IN PSECURITY_ATTRIBUTES psa)
Definition: sas.c:808
static DWORD WINAPI LogoffShutdownThread(LPVOID Parameter)
Definition: sas.c:619
PWLSESSION Session
Definition: sas.c:42
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
BOOL DisplayStatusMessage(IN PWLSESSION Session, IN HDESK hDesktop, IN UINT ResourceId)
Definition: winlogon.c:349
BOOL WINAPI SetWindowStationUser(IN HWINSTA hWindowStation, IN PLUID pluid, IN PSID psid OPTIONAL, IN DWORD size)
Definition: winsta.c:419
@ LogoffHandler
Definition: winlogon.h:261
#define EWX_LOGOFF
Definition: winuser.h:644
#define EWX_FORCE
Definition: winuser.h:643

Referenced by DoGenericAction().

◆ HandleLogon()

static BOOL HandleLogon ( IN OUT PWLSESSION  Session)
static

Definition at line 494 of file sas.c.

496{
497 PROFILEINFOW ProfileInfo;
498 BOOL ret = FALSE;
499
500 /* Loading personal settings */
501 DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_LOADINGYOURPERSONALSETTINGS);
502 ProfileInfo.hProfile = INVALID_HANDLE_VALUE;
503 if (0 == (Session->Options & WLX_LOGON_OPT_NO_PROFILE))
504 {
505 if (Session->Profile == NULL
506 || (Session->Profile->dwType != WLX_PROFILE_TYPE_V1_0
507 && Session->Profile->dwType != WLX_PROFILE_TYPE_V2_0))
508 {
509 ERR("WL: Wrong profile\n");
510 goto cleanup;
511 }
512
513 /* Load the user profile */
514 ZeroMemory(&ProfileInfo, sizeof(PROFILEINFOW));
515 ProfileInfo.dwSize = sizeof(PROFILEINFOW);
516 ProfileInfo.dwFlags = 0;
517 ProfileInfo.lpUserName = Session->MprNotifyInfo.pszUserName;
518 ProfileInfo.lpProfilePath = Session->Profile->pszProfile;
519 if (Session->Profile->dwType >= WLX_PROFILE_TYPE_V2_0)
520 {
521 ProfileInfo.lpDefaultPath = Session->Profile->pszNetworkDefaultUserProfile;
522 ProfileInfo.lpServerName = Session->Profile->pszServerName;
523 ProfileInfo.lpPolicyPath = Session->Profile->pszPolicy;
524 }
525
526 if (!LoadUserProfileW(Session->UserToken, &ProfileInfo))
527 {
528 ERR("WL: LoadUserProfileW() failed\n");
529 goto cleanup;
530 }
531 }
532
533 /* Create environment block for the user */
534 if (!CreateUserEnvironment(Session))
535 {
536 WARN("WL: SetUserEnvironment() failed\n");
537 goto cleanup;
538 }
539
541
542 DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_APPLYINGYOURPERSONALSETTINGS);
544
545 /* Set default user language */
546 if (!SetDefaultLanguage(Session))
547 {
548 WARN("WL: SetDefaultLanguage() failed\n");
549 goto cleanup;
550 }
551
552 /* Allow winsta and desktop access for this session */
553 if (!AllowAccessOnSession(Session))
554 {
555 WARN("WL: AllowAccessOnSession() failed to give winsta & desktop access for this session\n");
556 goto cleanup;
557 }
558
559 /* Connect remote resources */
560 RestoreAllConnections(Session);
561
562 if (!StartUserShell(Session))
563 {
564 //WCHAR StatusMsg[256];
565 WARN("WL: WlxActivateUserShell() failed\n");
566 //LoadStringW(hAppInstance, IDS_FAILEDACTIVATEUSERSHELL, StatusMsg, sizeof(StatusMsg) / sizeof(StatusMsg[0]));
567 //MessageBoxW(0, StatusMsg, NULL, MB_ICONERROR);
568 goto cleanup;
569 }
570
572
573 if (!InitializeScreenSaver(Session))
574 WARN("WL: Failed to initialize screen saver\n");
575
576 Session->hProfileInfo = ProfileInfo.hProfile;
577
578 /* Logon has succeeded. Play sound. */
579 PlayLogonSound(Session);
580
581 /* NOTE: The logon timestamp has to be set after calling PlayLogonSound
582 * to correctly detect the startup event (first logon) */
583 SetLogonTimestamp(Session);
584 ret = TRUE;
585
586cleanup:
587 if (Session->Profile)
588 {
589 HeapFree(GetProcessHeap(), 0, Session->Profile->pszProfile);
590 HeapFree(GetProcessHeap(), 0, Session->Profile);
591 }
592 Session->Profile = NULL;
593 if (!ret && ProfileInfo.hProfile != INVALID_HANDLE_VALUE)
594 {
595 UnloadUserProfile(Session->UserToken, ProfileInfo.hProfile);
596 }
597 RemoveStatusMessage(Session);
598 if (!ret)
599 {
600 SetWindowStationUser(Session->InteractiveWindowStation,
601 &LuidNone, NULL, 0);
602 CloseHandle(Session->UserToken);
603 Session->UserToken = NULL;
604 }
605
606 if (ret)
607 {
608 SwitchDesktop(Session->ApplicationDesktop);
609 Session->LogonState = STATE_LOGGED_ON;
610 }
611
612 return ret;
613}
BOOL CreateUserEnvironment(IN PWLSESSION Session)
Definition: environment.c:128
#define IDS_APPLYINGYOURPERSONALSETTINGS
Definition: resource.h:26
#define IDS_LOADINGYOURPERSONALSETTINGS
Definition: resource.h:29
BOOL InitializeScreenSaver(IN OUT PWLSESSION Session)
Definition: screensaver.c:204
BOOL AllowAccessOnSession(_In_ PWLSESSION Session)
Assigns both window station and desktop access to the specific session currently active on the system...
Definition: security.c:1391
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
static void cleanup(void)
Definition: main.c:1335
BOOL WINAPI LoadUserProfileW(_In_ HANDLE hToken, _Inout_ LPPROFILEINFOW lpProfileInfo)
Definition: profile.c:2005
static BOOL StartUserShell(IN OUT PWLSESSION Session)
Definition: sas.c:86
BOOL SetDefaultLanguage(IN PWLSESSION Session)
Definition: sas.c:117
static VOID PlayLogonSound(_In_ PWLSESSION Session)
Definition: sas.c:371
static VOID RestoreAllConnections(PWLSESSION Session)
Definition: sas.c:430
LPWSTR lpPolicyPath
Definition: userenv.h:42
LPWSTR lpServerName
Definition: userenv.h:41
LPWSTR lpProfilePath
Definition: userenv.h:39
DWORD dwFlags
Definition: userenv.h:37
DWORD dwSize
Definition: userenv.h:36
HANDLE hProfile
Definition: userenv.h:43
LPWSTR lpUserName
Definition: userenv.h:38
LPWSTR lpDefaultPath
Definition: userenv.h:40
struct _PROFILEINFOW PROFILEINFOW
int ret
FORCEINLINE VOID SetLogonTimestamp(_Inout_ PWLSESSION Session)
Definition: winlogon.h:292
@ StartShellHandler
Definition: winlogon.h:270
#define WLX_PROFILE_TYPE_V1_0
Definition: winwlx.h:50
#define WLX_PROFILE_TYPE_V2_0
Definition: winwlx.h:51
#define WLX_LOGON_OPT_NO_PROFILE
Definition: winwlx.h:48

Referenced by DoGenericAction().

◆ HandleMessageBeep()

static BOOL HandleMessageBeep ( _In_ PWLSESSION  Session,
_In_ UINT  uType 
)
static

Definition at line 1280 of file sas.c.

1283{
1284 LPWSTR EventName;
1285
1286 switch (uType)
1287 {
1288 case 0xFFFFFFFF:
1289 EventName = NULL;
1290 break;
1291 case MB_OK:
1292 EventName = L"SystemDefault";
1293 break;
1294 case MB_ICONASTERISK:
1295 EventName = L"SystemAsterisk";
1296 break;
1297 case MB_ICONEXCLAMATION:
1298 EventName = L"SystemExclamation";
1299 break;
1300 case MB_ICONHAND:
1301 EventName = L"SystemHand";
1302 break;
1303 case MB_ICONQUESTION:
1304 EventName = L"SystemQuestion";
1305 break;
1306 default:
1307 WARN("Unhandled type %d\n", uType);
1308 EventName = L"SystemDefault";
1309 }
1310
1311 return PlayEventSound(Session, EventName);
1312}
#define L(x)
Definition: ntvdm.h:50
static BOOL PlayEventSound(_In_ PWLSESSION Session, _In_ LPCWSTR EventName)
Definition: sas.c:412
#define MB_ICONHAND
Definition: winuser.h:799
#define MB_ICONEXCLAMATION
Definition: winuser.h:796
#define MB_OK
Definition: winuser.h:801
#define MB_ICONQUESTION
Definition: winuser.h:800
#define MB_ICONASTERISK
Definition: winuser.h:795
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by SASWindowProc().

◆ HandleShutdown()

NTSTATUS HandleShutdown ( IN OUT PWLSESSION  Session,
IN DWORD  wlxAction 
)

Definition at line 970 of file sas.c.

973{
976 DWORD exitCode;
977 BOOLEAN Old;
978
979 // SwitchDesktop(Session->WinlogonDesktop);
980
981 /* If the system is rebooting, show the appropriate string */
982 if (wlxAction == WLX_SAS_ACTION_SHUTDOWN_REBOOT)
983 DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_REACTOSISRESTARTING);
984 else
985 DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_REACTOSISSHUTTINGDOWN);
986
987 /* Prepare data for shutdown thread */
988 LSData = HeapAlloc(GetProcessHeap(), 0, sizeof(LOGOFF_SHUTDOWN_DATA));
989 if (!LSData)
990 {
991 ERR("Failed to allocate mem for thread data\n");
992 return STATUS_NO_MEMORY;
993 }
994 if (wlxAction == WLX_SAS_ACTION_SHUTDOWN_POWER_OFF)
995 LSData->Flags = EWX_POWEROFF;
996 else if (wlxAction == WLX_SAS_ACTION_SHUTDOWN_REBOOT)
997 LSData->Flags = EWX_REBOOT;
998 else
999 LSData->Flags = EWX_SHUTDOWN;
1000 LSData->Session = Session;
1001
1002 // FIXME: We may need to specify this flag to really force application kill
1003 // (we are shutting down ReactOS, not just logging off so no hangs, etc...
1004 // should be allowed).
1005 // LSData->Flags |= EWX_FORCE;
1006
1007 /* Run shutdown thread */
1009 if (!hThread)
1010 {
1011 ERR("Unable to create shutdown thread, error %lu\n", GetLastError());
1012 HeapFree(GetProcessHeap(), 0, LSData);
1013 return STATUS_UNSUCCESSFUL;
1014 }
1016 HeapFree(GetProcessHeap(), 0, LSData);
1017 if (!GetExitCodeThread(hThread, &exitCode))
1018 {
1019 ERR("Unable to get exit code of shutdown thread (error %lu)\n", GetLastError());
1021 return STATUS_UNSUCCESSFUL;
1022 }
1024 if (exitCode == 0)
1025 {
1026 ERR("Shutdown thread returned failure\n");
1027 return STATUS_UNSUCCESSFUL;
1028 }
1029
1031
1032 /* Destroy SAS window */
1033 UninitializeSAS(Session);
1034
1035 /* Now we can shut down NT */
1036 ERR("Shutting down NT...\n");
1038 if (wlxAction == WLX_SAS_ACTION_SHUTDOWN_REBOOT)
1039 {
1041 }
1042 else
1043 {
1044 if (FALSE)
1045 {
1046 /* FIXME - only show this dialog if it's a shutdown and the computer doesn't support APM */
1049 }
1051 }
1053 return STATUS_SUCCESS;
1054}
unsigned char BOOLEAN
HINSTANCE hAppInstance
Definition: mmc.c:23
#define IDS_REACTOSISSHUTTINGDOWN
Definition: resource.h:31
#define IDD_SHUTDOWNCOMPUTER
Definition: resource.h:7
#define IDS_REACTOSISRESTARTING
Definition: resource.h:38
#define SE_SHUTDOWN_PRIVILEGE
Definition: security.c:673
@ ShutdownReboot
Definition: extypes.h:177
@ ShutdownNoReboot
Definition: extypes.h:176
NTSYSAPI NTSTATUS NTAPI RtlAdjustPrivilege(_In_ ULONG Privilege, _In_ BOOLEAN NewValue, _In_ BOOLEAN ForThread, _Out_ PBOOLEAN OldValue)
NTSTATUS NTAPI NtShutdownSystem(IN SHUTDOWN_ACTION Action)
Definition: shutdown.c:43
#define MAKEINTRESOURCE(i)
Definition: ntverrsrc.c:25
static INT_PTR CALLBACK ShutdownComputerWindowProc(IN HWND hwndDlg, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lParam)
Definition: sas.c:924
static VOID UninitializeSAS(IN OUT PWLSESSION Session)
Definition: sas.c:956
@ ShutdownHandler
Definition: winlogon.h:265
#define EWX_POWEROFF
Definition: winuser.h:645
#define EWX_SHUTDOWN
Definition: winuser.h:647
HWND WINAPI GetDesktopWindow(void)
Definition: window.c:628
#define EWX_REBOOT
Definition: winuser.h:646
#define DialogBox
Definition: winuser.h:5781

Referenced by DoGenericAction(), and WinMain().

◆ InitializeSAS()

BOOL InitializeSAS ( IN OUT PWLSESSION  Session)

Definition at line 1517 of file sas.c.

1519{
1520 WNDCLASSEXW swc;
1521 BOOL ret = FALSE;
1522
1523 if (!SwitchDesktop(Session->WinlogonDesktop))
1524 {
1525 ERR("WL: Failed to switch to winlogon desktop\n");
1526 goto cleanup;
1527 }
1528
1529 /* Register SAS window class */
1530 swc.cbSize = sizeof(WNDCLASSEXW);
1531 swc.style = CS_SAVEBITS;
1533 swc.cbClsExtra = 0;
1534 swc.cbWndExtra = 0;
1535 swc.hInstance = hAppInstance;
1536 swc.hIcon = NULL;
1537 swc.hCursor = NULL;
1538 swc.hbrBackground = NULL;
1539 swc.lpszMenuName = NULL;
1541 swc.hIconSm = NULL;
1542 if (RegisterClassExW(&swc) == 0)
1543 {
1544 ERR("WL: Failed to register SAS window class\n");
1545 goto cleanup;
1546 }
1547
1548 /* Create invisible SAS window */
1549 Session->SASWindow = CreateWindowExW(
1550 0,
1553 WS_POPUP,
1554 0, 0, 0, 0, 0, 0,
1555 hAppInstance, Session);
1556 if (!Session->SASWindow)
1557 {
1558 ERR("WL: Failed to create SAS window\n");
1559 goto cleanup;
1560 }
1561
1562 /* Register SAS window to receive SAS notifications */
1563 if (!SetLogonNotifyWindow(Session->SASWindow))
1564 {
1565 ERR("WL: Failed to register SAS window\n");
1566 goto cleanup;
1567 }
1568
1570 return FALSE;
1571
1572 ret = TRUE;
1573
1574cleanup:
1575 if (!ret)
1576 UninitializeSAS(Session);
1577 return ret;
1578}
#define WS_POPUP
Definition: pedump.c:616
#define WINLOGON_SAS_TITLE
Definition: sas.c:27
#define WINLOGON_SAS_CLASS
Definition: sas.c:26
static LRESULT CALLBACK SASWindowProc(IN HWND hwndDlg, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lParam)
Definition: sas.c:1317
LPCWSTR lpszClassName
Definition: winuser.h:3237
LPCWSTR lpszMenuName
Definition: winuser.h:3236
HBRUSH hbrBackground
Definition: winuser.h:3235
WNDPROC lpfnWndProc
Definition: winuser.h:3229
UINT cbSize
Definition: winuser.h:3227
int cbWndExtra
Definition: winuser.h:3231
HCURSOR hCursor
Definition: winuser.h:3234
HICON hIconSm
Definition: winuser.h:3238
HINSTANCE hInstance
Definition: winuser.h:3232
UINT style
Definition: winuser.h:3228
int cbClsExtra
Definition: winuser.h:3230
HICON hIcon
Definition: winuser.h:3233
BOOL WINAPI SetLogonNotifyWindow(HWND Wnd)
Definition: logon.c:91
HWND WINAPI CreateWindowExW(_In_ DWORD dwExStyle, _In_opt_ LPCWSTR lpClassName, _In_opt_ LPCWSTR lpWindowName, _In_ DWORD dwStyle, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, _In_opt_ HWND hWndParent, _In_opt_ HMENU hMenu, _In_opt_ HINSTANCE hInstance, _In_opt_ LPVOID lpParam)
ATOM WINAPI RegisterClassExW(_In_ CONST WNDCLASSEXW *)
#define CS_SAVEBITS
Definition: winuser.h:665
struct _WNDCLASSEXW WNDCLASSEXW

Referenced by WinMain().

◆ KillComProcesses()

static DWORD WINAPI KillComProcesses ( LPVOID  Parameter)
static

Definition at line 664 of file sas.c.

666{
667 DWORD ret = 1;
669
670 TRACE("In KillComProcesses\n");
671
672 if (LSData->Session->UserToken != NULL &&
674 {
675 ERR("ImpersonateLoggedOnUser() failed with error %lu\n", GetLastError());
676 return 0;
677 }
678
679 /* Attempt to kill remaining processes. No notifications needed. */
681 {
682 ERR("Unable to kill COM apps, error %lu\n", GetLastError());
683 ret = 0;
684 }
685
686 if (LSData->Session->UserToken)
687 RevertToSelf();
688
689 return ret;
690}
BOOL WINAPI ImpersonateLoggedOnUser(HANDLE hToken)
Definition: misc.c:152
struct tagLOGOFF_SHUTDOWN_DATA * PLOGOFF_SHUTDOWN_DATA
#define TRACE(s)
Definition: solgame.cpp:4
HANDLE UserToken
Definition: winlogon.h:233
#define EWX_NONOTIFY
Definition: undocuser.h:135
#define EWX_CALLER_WINLOGON
Definition: undocuser.h:129
BOOL WINAPI RevertToSelf(void)
Definition: security.c:1608
BOOL WINAPI ExitWindowsEx(_In_ UINT, _In_ DWORD)
_Inout_opt_ PVOID Parameter
Definition: rtltypes.h:336

Referenced by HandleLogoff().

◆ LogoffShutdownThread()

static DWORD WINAPI LogoffShutdownThread ( LPVOID  Parameter)
static

Definition at line 619 of file sas.c.

621{
622 DWORD ret = 1;
624 UINT uFlags;
625
626 if (LSData->Session->UserToken != NULL &&
628 {
629 ERR("ImpersonateLoggedOnUser() failed with error %lu\n", GetLastError());
630 return 0;
631 }
632
633 // FIXME: To be really fixed: need to check what needs to be kept and what needs to be removed there.
634 //
635 // uFlags = EWX_INTERNAL_KILL_USER_APPS | (LSData->Flags & EWX_FLAGS_MASK) |
636 // ((LSData->Flags & EWX_ACTION_MASK) == EWX_LOGOFF ? EWX_CALLER_WINLOGON_LOGOFF : 0);
637
638 uFlags = EWX_CALLER_WINLOGON | (LSData->Flags & 0x0F);
639
640 TRACE("In LogoffShutdownThread with uFlags == 0x%x; exit_in_progress == %s\n",
641 uFlags, ExitReactOSInProgress ? "true" : "false");
642
644
645 /* Close processes of the interactive user */
646 if (!ExitWindowsEx(uFlags, 0))
647 {
648 ERR("Unable to kill user apps, error %lu\n", GetLastError());
649 ret = 0;
650 }
651
652 /* Cancel all the user connections */
654
655 if (LSData->Session->UserToken)
656 RevertToSelf();
657
658 return ret;
659}
UINT uFlags
Definition: api.c:59
unsigned int UINT
Definition: ndis.h:50
static BOOL ExitReactOSInProgress
Definition: sas.c:45
DWORD WINAPI WNetClearConnections(HWND owner)
Definition: wnet.c:2827

Referenced by HandleLogoff(), and HandleShutdown().

◆ PlayEventSound()

static BOOL PlayEventSound ( _In_ PWLSESSION  Session,
_In_ LPCWSTR  EventName 
)
static

Definition at line 412 of file sas.c.

415{
416 BOOL bRet;
417
418 if (!ImpersonateLoggedOnUser(Session->UserToken))
419 return FALSE;
420
422
423 RevertToSelf();
424
425 return bRet;
426}
#define SND_ALIAS
Definition: mmsystem.h:160
#define SND_ASYNC
Definition: mmsystem.h:154
#define SND_NODEFAULT
Definition: mmsystem.h:155
BOOL PlaySoundRoutine(IN LPCWSTR FileName, IN UINT bLogon, IN UINT Flags)
Definition: sas.c:246

Referenced by HandleMessageBeep().

◆ PlayLogoffShutdownSound()

static VOID PlayLogoffShutdownSound ( _In_ PWLSESSION  Session,
_In_ BOOL  bShutdown 
)
static

Definition at line 395 of file sas.c.

398{
399 if (!ImpersonateLoggedOnUser(Session->UserToken))
400 return;
401
402 /* NOTE: Logoff and shutdown sounds play synchronously */
403 PlaySoundRoutine(bShutdown ? L"SystemExit" : L"WindowsLogoff",
404 FALSE,
406
407 RevertToSelf();
408}
volatile BOOL bShutdown
Definition: tcpsvcs.c:16

Referenced by HandleLogoff().

◆ PlayLogonSound()

static VOID PlayLogonSound ( _In_ PWLSESSION  Session)
static

Definition at line 371 of file sas.c.

373{
374 PLOGON_SOUND_DATA SoundData;
376
377 SoundData = HeapAlloc(GetProcessHeap(), 0, sizeof(LOGON_SOUND_DATA));
378 if (!SoundData)
379 return;
380
381 SoundData->UserToken = Session->UserToken;
382 SoundData->IsStartup = IsFirstLogon(Session);
383
384 hThread = CreateThread(NULL, 0, PlayLogonSoundThread, SoundData, 0, NULL);
385 if (!hThread)
386 {
387 HeapFree(GetProcessHeap(), 0, SoundData);
388 return;
389 }
391}
static DWORD WINAPI PlayLogonSoundThread(_In_ LPVOID lpParameter)
Definition: sas.c:297
BOOL IsStartup
Definition: sas.c:52
HANDLE UserToken
Definition: sas.c:51
FORCEINLINE BOOL IsFirstLogon(_In_ PWLSESSION Session)
Definition: winlogon.h:300

Referenced by HandleLogon().

◆ PlayLogonSoundThread()

static DWORD WINAPI PlayLogonSoundThread ( _In_ LPVOID  lpParameter)
static

Definition at line 297 of file sas.c.

299{
300 PLOGON_SOUND_DATA SoundData = (PLOGON_SOUND_DATA)lpParameter;
303 ULONG Index = 0;
304 SC_HANDLE hSCManager, hService;
305
306 /* Open the service manager */
308 if (!hSCManager)
309 {
310 ERR("OpenSCManager failed (%x)\n", GetLastError());
311 goto Cleanup;
312 }
313
314 /* Open the wdmaud service */
315 hService = OpenServiceW(hSCManager, L"wdmaud", GENERIC_READ);
316 if (!hService)
317 {
318 /* The service is not installed */
319 TRACE("Failed to open wdmaud service (%x)\n", GetLastError());
321 goto Cleanup;
322 }
323
324 /* Wait for wdmaud to start */
325 do
326 {
328 {
329 TRACE("QueryServiceStatusEx failed (%x)\n", GetLastError());
330 break;
331 }
332
333 if (Info.dwCurrentState == SERVICE_RUNNING)
334 break;
335
336 Sleep(1000);
337
338 } while (Index++ < 20);
339
340 CloseServiceHandle(hService);
342
343 /* If wdmaud is not running exit */
344 if (Info.dwCurrentState != SERVICE_RUNNING)
345 {
346 WARN("wdmaud has not started!\n");
347 goto Cleanup;
348 }
349
350 /* Sound subsystem is running. Play logon sound. */
351 TRACE("Playing %s sound\n", SoundData->IsStartup ? "startup" : "logon");
352 if (!ImpersonateLoggedOnUser(SoundData->UserToken))
353 {
354 ERR("ImpersonateLoggedOnUser failed (%x)\n", GetLastError());
355 }
356 else
357 {
358 PlaySoundRoutine(SoundData->IsStartup ? L"SystemStart" : L"WindowsLogon",
359 TRUE,
361 RevertToSelf();
362 }
363
364Cleanup:
365 HeapFree(GetProcessHeap(), 0, SoundData);
366 return 0;
367}
#define GENERIC_READ
Definition: compat.h:135
static const WCHAR Cleanup[]
Definition: register.c:80
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
struct tagLOGON_SOUND_DATA * PLOGON_SOUND_DATA
SC_HANDLE hSCManager
Definition: sc.c:12
BOOL WINAPI QueryServiceStatusEx(SC_HANDLE hService, SC_STATUS_TYPE InfoLevel, LPBYTE lpBuffer, DWORD cbBufSize, LPDWORD pcbBytesNeeded)
Definition: scm.c:2887
SC_HANDLE WINAPI OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2160
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:580
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
unsigned char * LPBYTE
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690
_In_ WDFCOLLECTION _In_ ULONG Index
#define OpenSCManager
Definition: winsvc.h:575
@ SC_STATUS_PROCESS_INFO
Definition: winsvc.h:119
#define SC_MANAGER_CONNECT
Definition: winsvc.h:14
#define SERVICE_RUNNING
Definition: winsvc.h:24

Referenced by PlayLogonSound().

◆ PlaySoundRoutine()

BOOL PlaySoundRoutine ( IN LPCWSTR  FileName,
IN UINT  bLogon,
IN UINT  Flags 
)

Definition at line 246 of file sas.c.

250{
251 typedef BOOL (WINAPI *PLAYSOUNDW)(LPCWSTR,HMODULE,DWORD);
252 typedef UINT (WINAPI *WAVEOUTGETNUMDEVS)(VOID);
253 PLAYSOUNDW Play;
254 WAVEOUTGETNUMDEVS waveOutGetNumDevs;
255 UINT NumDevs;
257 BOOL Ret = FALSE;
258
259 hLibrary = LoadLibraryW(L"winmm.dll");
260 if (!hLibrary)
261 return FALSE;
262
263 waveOutGetNumDevs = (WAVEOUTGETNUMDEVS)GetProcAddress(hLibrary, "waveOutGetNumDevs");
264 Play = (PLAYSOUNDW)GetProcAddress(hLibrary, "PlaySoundW");
265
267 {
269 {
270 NumDevs = waveOutGetNumDevs();
271 if (!NumDevs)
272 {
273 if (!bLogon)
274 Beep(440, 125);
276 }
277 }
278
279 if (Play)
280 Ret = Play(FileName, NULL, Flags);
281 }
283 {
284 ERR("WL: Exception while playing sound '%S', Status 0x%08lx\n",
286 }
287 _SEH2_END;
288
290
291 return Ret;
292}
#define VOID
Definition: acefi.h:82
HMODULE hLibrary
Definition: odbccp32.c:12
BOOL WINAPI Beep(IN DWORD dwFreq, IN DWORD dwDuration)
Definition: deviceio.c:48
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
#define LoadLibraryW(x)
Definition: compat.h:747
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
#define BOOL
Definition: nt_native.h:43
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:181
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:82
#define _SEH2_END
Definition: pseh2_64.h:171
#define _SEH2_TRY
Definition: pseh2_64.h:71
#define _SEH2_LEAVE
Definition: pseh2_64.h:183
HANDLE HMODULE
Definition: typedefs.h:77
#define WINAPI
Definition: msvc.h:6
UINT WINAPI waveOutGetNumDevs(void)
Definition: winmm.c:2137
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by PlayEventSound(), PlayLogoffShutdownSound(), and PlayLogonSoundThread().

◆ RegisterHotKeys()

static BOOL RegisterHotKeys ( IN PWLSESSION  Session,
IN HWND  hwndSAS 
)
static

Definition at line 1245 of file sas.c.

1248{
1249 /* Register Ctrl+Alt+Del Hotkey */
1251 {
1252 ERR("WL: Unable to register Ctrl+Alt+Del hotkey!\n");
1253 return FALSE;
1254 }
1255
1256 /* Register Ctrl+Shift+Esc (optional) */
1258 if (!Session->TaskManHotkey)
1259 WARN("WL: Warning: Unable to register Ctrl+Alt+Esc hotkey!\n");
1260 return TRUE;
1261}
#define MOD_ALT
Definition: imm.h:184
#define MOD_SHIFT
Definition: imm.h:186
#define MOD_CONTROL
Definition: imm.h:185
HWND hwndSAS
Definition: winsta.c:24
#define HK_CTRL_SHIFT_ESC
Definition: sas.c:30
#define HK_CTRL_ALT_DEL
Definition: sas.c:29
BOOL WINAPI RegisterHotKey(_In_opt_ HWND, _In_ int, _In_ UINT, _In_ UINT)
#define VK_DELETE
Definition: winuser.h:2244
#define VK_ESCAPE
Definition: winuser.h:2225

Referenced by SASWindowProc().

◆ RestoreAllConnections()

static VOID RestoreAllConnections ( PWLSESSION  Session)
static

Definition at line 430 of file sas.c.

431{
432 DWORD dRet;
433 HANDLE hEnum;
434 LPNETRESOURCE lpRes;
435 DWORD dSize = 0x1000;
436 DWORD dCount = -1;
437 LPNETRESOURCE lpCur;
438 BOOL UserProfile;
439
440 UserProfile = (Session && Session->UserToken);
441 if (!UserProfile)
442 {
443 return;
444 }
445
446 if (!ImpersonateLoggedOnUser(Session->UserToken))
447 {
448 ERR("WL: ImpersonateLoggedOnUser() failed with error %lu\n", GetLastError());
449 return;
450 }
451
453 if (dRet != WN_SUCCESS)
454 {
455 ERR("Failed to open enumeration: %lu\n", dRet);
456 goto quit;
457 }
458
459 lpRes = HeapAlloc(GetProcessHeap(), 0, dSize);
460 if (!lpRes)
461 {
462 ERR("Failed to allocate memory\n");
463 WNetCloseEnum(hEnum);
464 goto quit;
465 }
466
467 do
468 {
469 dSize = 0x1000;
470 dCount = -1;
471
472 memset(lpRes, 0, dSize);
473 dRet = WNetEnumResource(hEnum, &dCount, lpRes, &dSize);
474 if (dRet == WN_SUCCESS || dRet == WN_MORE_DATA)
475 {
476 lpCur = lpRes;
477 for (; dCount; dCount--)
478 {
480 lpCur++;
481 }
482 }
483 } while (dRet != WN_NO_MORE_ENTRIES);
484
485 HeapFree(GetProcessHeap(), 0, lpRes);
486 WNetCloseEnum(hEnum);
487
488quit:
489 RevertToSelf();
490}
void quit(int argc, const char *argv[])
Definition: cmds.c:1606
#define memset(x, y, z)
Definition: compat.h:39
LPSTR lpLocalName
Definition: winnetwk.h:171
LPSTR lpRemoteName
Definition: winnetwk.h:172
#define RESOURCETYPE_DISK
Definition: winnetwk.h:64
#define WN_MORE_DATA
Definition: winnetwk.h:117
#define WN_SUCCESS
Definition: winnetwk.h:111
#define RESOURCE_REMEMBERED
Definition: winnetwk.h:60
#define WNetEnumResource
Definition: winnetwk.h:599
#define WNetOpenEnum
Definition: winnetwk.h:598
#define WNetAddConnection
Definition: winnetwk.h:611
#define WN_NO_MORE_ENTRIES
Definition: winnetwk.h:146
DWORD WINAPI WNetCloseEnum(HANDLE hEnum)
Definition: wnet.c:1762

Referenced by HandleLogon().

◆ SASWindowProc()

static LRESULT CALLBACK SASWindowProc ( IN HWND  hwndDlg,
IN UINT  uMsg,
IN WPARAM  wParam,
IN LPARAM  lParam 
)
static

Definition at line 1317 of file sas.c.

1322{
1324
1325 switch (uMsg)
1326 {
1327 case WM_HOTKEY:
1328 {
1329 switch (lParam)
1330 {
1332 {
1333 TRACE("SAS: CONTROL+ALT+DELETE\n");
1334 if (!Session->Gina.UseCtrlAltDelete)
1335 break;
1337 return TRUE;
1338 }
1340 {
1341 TRACE("SAS: CONTROL+SHIFT+ESCAPE\n");
1342 if (Session->LogonState == STATE_LOGGED_ON)
1344 return TRUE;
1345 }
1346 }
1347 break;
1348 }
1349 case WM_CREATE:
1350 {
1351 /* Get the session pointer from the create data */
1352 Session = (PWLSESSION)((LPCREATESTRUCT)lParam)->lpCreateParams;
1353
1354 /* Save the Session pointer */
1355 SetWindowLongPtrW(hwndDlg, GWLP_USERDATA, (LONG_PTR)Session);
1356 if (GetSetupType())
1357 return TRUE;
1358 return RegisterHotKeys(Session, hwndDlg);
1359 }
1360 case WM_DESTROY:
1361 {
1362 if (!GetSetupType())
1363 UnregisterHotKeys(Session, hwndDlg);
1364 return TRUE;
1365 }
1366 case WM_SETTINGCHANGE:
1367 {
1368 UINT uiAction = (UINT)wParam;
1369 if (uiAction == SPI_SETSCREENSAVETIMEOUT
1370 || uiAction == SPI_SETSCREENSAVEACTIVE)
1371 {
1373 }
1374 return TRUE;
1375 }
1376 case WM_LOGONNOTIFY:
1377 {
1378 switch(wParam)
1379 {
1380 case LN_MESSAGE_BEEP:
1381 {
1382 return HandleMessageBeep(Session, lParam);
1383 }
1384 case LN_SHELL_EXITED:
1385 {
1386 /* lParam is the exit code */
1387 if (lParam != 1 &&
1388 Session->LogonState != STATE_LOGGED_OFF &&
1389 Session->LogonState != STATE_LOGGED_OFF_SAS)
1390 {
1391 SetTimer(hwndDlg, 1, 1000, NULL);
1392 }
1393 break;
1394 }
1396 {
1398 break;
1399 }
1401 {
1403 break;
1404 }
1405 case LN_LOGOFF:
1406 {
1407 UINT Flags = (UINT)lParam;
1409 DWORD wlxAction;
1410
1411 TRACE("\tFlags : 0x%lx\n", lParam);
1412
1413 /*
1414 * Our caller (USERSRV) should have added the shutdown flag
1415 * when setting also poweroff or reboot.
1416 */
1417 if (Action & (EWX_POWEROFF | EWX_REBOOT))
1418 {
1419 if ((Action & EWX_SHUTDOWN) == 0)
1420 {
1421 ERR("Missing EWX_SHUTDOWN flag for poweroff or reboot; action 0x%x\n", Action);
1423 }
1424
1425 /* Now we can locally remove it for performing checks */
1426 Action &= ~EWX_SHUTDOWN;
1427 }
1428
1429 /* Check parameters */
1430 if (Action & EWX_FORCE)
1431 {
1432 // FIXME!
1433 ERR("FIXME: EWX_FORCE present for Winlogon, what to do?\n");
1434 Action &= ~EWX_FORCE;
1435 }
1436 switch (Action)
1437 {
1438 case EWX_LOGOFF:
1439 wlxAction = WLX_SAS_ACTION_LOGOFF;
1440 break;
1441 case EWX_SHUTDOWN:
1442 wlxAction = WLX_SAS_ACTION_SHUTDOWN;
1443 break;
1444 case EWX_REBOOT:
1446 break;
1447 case EWX_POWEROFF:
1449 break;
1450
1451 default:
1452 {
1453 ERR("Invalid ExitWindows action 0x%x\n", Action);
1455 }
1456 }
1457
1458 TRACE("In LN_LOGOFF, exit_in_progress == %s\n",
1459 ExitReactOSInProgress ? "true" : "false");
1460
1461 /*
1462 * In case a parallel shutdown request is done (while we are
1463 * being to shut down) and it was not done by Winlogon itself,
1464 * then just stop here.
1465 */
1466#if 0
1467// This code is commented at the moment (even if it's correct) because
1468// our log-offs do not really work: the shell is restarted, no app is killed
1469// etc... and as a result you just get explorer opening "My Documents". And
1470// if you try now a shut down, it won't work because winlogon thinks it is
1471// still in the middle of a shutdown.
1472// Maybe we also need to reset ExitReactOSInProgress somewhere else??
1474 {
1475 break;
1476 }
1477#endif
1478 /* Now do the shutdown action proper */
1479 DoGenericAction(Session, wlxAction);
1480 return 1;
1481 }
1482 case LN_LOGOFF_CANCELED:
1483 {
1484 ERR("Logoff canceled!!, before: exit_in_progress == %s, after will be false\n",
1485 ExitReactOSInProgress ? "true" : "false");
1486
1488 return 1;
1489 }
1490 default:
1491 {
1492 ERR("WM_LOGONNOTIFY case %d is unimplemented\n", wParam);
1493 }
1494 }
1495 return 0;
1496 }
1497 case WM_TIMER:
1498 {
1499 if (wParam == 1)
1500 {
1501 KillTimer(hwndDlg, 1);
1502 StartUserShell(Session);
1503 }
1504 break;
1505 }
1506 case WLX_WM_SAS:
1507 {
1508 DispatchSAS(Session, (DWORD)wParam);
1509 return TRUE;
1510 }
1511 }
1512
1513 return DefWindowProc(hwndDlg, uMsg, wParam, lParam);
1514}
DWORD GetSetupType(VOID)
Definition: setup.c:16
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define DefWindowProc
Definition: ros2win.h:31
static BOOL RegisterHotKeys(IN PWLSESSION Session, IN HWND hwndSAS)
Definition: sas.c:1245
static VOID DispatchSAS(IN OUT PWLSESSION Session, IN DWORD dwSasType)
Definition: sas.c:1149
static BOOL HandleMessageBeep(_In_ PWLSESSION Session, _In_ UINT uType)
Definition: sas.c:1280
#define EWX_ACTION_MASK
Definition: sas.c:37
static BOOL UnregisterHotKeys(IN PWLSESSION Session, IN HWND hwndSAS)
Definition: sas.c:1265
BOOL UseCtrlAltDelete
Definition: winlogon.h:132
HANDLE hScreenSaverParametersChanged
Definition: winlogon.h:245
LOGON_STATE LogonState
Definition: winlogon.h:235
HWND SASWindow
Definition: winlogon.h:226
GINAINSTANCE Gina
Definition: winlogon.h:222
#define GetWindowLongPtr
Definition: treelist.c:73
#define GWLP_USERDATA
Definition: treelist.c:63
#define MAKELONG(a, b)
Definition: typedefs.h:249
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define LN_SHELL_EXITED
Definition: undocuser.h:116
#define LN_LOCK_WORKSTATION
Definition: undocuser.h:118
#define WM_LOGONNOTIFY
Definition: undocuser.h:37
#define LN_START_SCREENSAVE
Definition: undocuser.h:121
#define LN_MESSAGE_BEEP
Definition: undocuser.h:120
#define LN_LOGOFF
Definition: undocuser.h:115
#define LN_LOGOFF_CANCELED
Definition: undocuser.h:122
_In_ WDFIOTARGET _In_ _Strict_type_match_ WDF_IO_TARGET_SENT_IO_ACTION Action
Definition: wdfiotarget.h:510
struct _WLSESSION * PWLSESSION
BOOL WINAPI PostMessageW(_In_opt_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define WM_CREATE
Definition: winuser.h:1619
#define SPI_SETSCREENSAVEACTIVE
Definition: winuser.h:1377
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
#define WM_SETTINGCHANGE
Definition: winuser.h:1640
#define WM_TIMER
Definition: winuser.h:1753
#define WM_HOTKEY
Definition: winuser.h:1890
#define WM_DESTROY
Definition: winuser.h:1620
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)
#define SetWindowLongPtrW
Definition: winuser.h:5366
#define SPI_SETSCREENSAVETIMEOUT
Definition: winuser.h:1375
#define WLX_WM_SAS
Definition: winwlx.h:71

Referenced by InitializeSAS().

◆ SetDefaultLanguage()

BOOL SetDefaultLanguage ( IN PWLSESSION  Session)

Definition at line 117 of file sas.c.

119{
120 BOOL ret = FALSE;
121 BOOL UserProfile;
122 LONG rc;
123 HKEY UserKey, hKey = NULL;
124 LPCWSTR SubKey, ValueName;
125 DWORD dwType, dwSize;
126 LPWSTR Value = NULL;
127 UNICODE_STRING ValueString;
129 LCID Lcid;
130
131 UserProfile = (Session && Session->UserToken);
132
133 if (UserProfile && !ImpersonateLoggedOnUser(Session->UserToken))
134 {
135 ERR("WL: ImpersonateLoggedOnUser() failed with error %lu\n", GetLastError());
136 return FALSE;
137 // FIXME: ... or use the default language of the system??
138 // UserProfile = FALSE;
139 }
140
141 if (UserProfile)
142 {
143 rc = RegOpenCurrentUser(MAXIMUM_ALLOWED, &UserKey);
144 if (rc != ERROR_SUCCESS)
145 {
146 TRACE("RegOpenCurrentUser() failed with error %lu\n", rc);
147 goto cleanup;
148 }
149
150 SubKey = L"Control Panel\\International";
151 ValueName = L"Locale";
152 }
153 else
154 {
155 UserKey = NULL;
156 SubKey = L"System\\CurrentControlSet\\Control\\Nls\\Language";
157 ValueName = L"Default";
158 }
159
160 rc = RegOpenKeyExW(UserKey ? UserKey : HKEY_LOCAL_MACHINE,
161 SubKey,
162 0,
163 KEY_READ,
164 &hKey);
165
166 if (UserKey)
167 RegCloseKey(UserKey);
168
169 if (rc != ERROR_SUCCESS)
170 {
171 TRACE("RegOpenKeyEx() failed with error %lu\n", rc);
172 goto cleanup;
173 }
174
176 ValueName,
177 NULL,
178 &dwType,
179 NULL,
180 &dwSize);
181 if (rc != ERROR_SUCCESS)
182 {
183 TRACE("RegQueryValueEx() failed with error %lu\n", rc);
184 goto cleanup;
185 }
186 else if (dwType != REG_SZ)
187 {
188 TRACE("Wrong type for %S\\%S registry entry (got 0x%lx, expected 0x%x)\n",
189 SubKey, ValueName, dwType, REG_SZ);
190 goto cleanup;
191 }
192
194 if (!Value)
195 {
196 TRACE("HeapAlloc() failed\n");
197 goto cleanup;
198 }
200 ValueName,
201 NULL,
202 NULL,
203 (LPBYTE)Value,
204 &dwSize);
205 if (rc != ERROR_SUCCESS)
206 {
207 TRACE("RegQueryValueEx() failed with error %lu\n", rc);
208 goto cleanup;
209 }
210
211 /* Convert Value to a Lcid */
212 ValueString.Length = ValueString.MaximumLength = (USHORT)dwSize;
213 ValueString.Buffer = Value;
214 Status = RtlUnicodeStringToInteger(&ValueString, 16, (PULONG)&Lcid);
215 if (!NT_SUCCESS(Status))
216 {
217 TRACE("RtlUnicodeStringToInteger() failed with status 0x%08lx\n", Status);
218 goto cleanup;
219 }
220
221 TRACE("%s language is 0x%08lx\n",
222 UserProfile ? "User" : "System", Lcid);
223 Status = NtSetDefaultLocale(UserProfile, Lcid);
224 if (!NT_SUCCESS(Status))
225 {
226 TRACE("NtSetDefaultLocale() failed with status 0x%08lx\n", Status);
227 goto cleanup;
228 }
229
230 ret = TRUE;
231
232cleanup:
233 if (Value)
235
236 if (hKey)
238
239 if (UserProfile)
240 RevertToSelf();
241
242 return ret;
243}
#define RegCloseKey(hKey)
Definition: registry.h:49
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegOpenCurrentUser(IN REGSAM samDesired, OUT PHKEY phkResult)
Definition: reg.c:3209
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
FxAutoRegKey hKey
#define REG_SZ
Definition: layer.c:22
#define KEY_READ
Definition: nt_native.h:1023
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToInteger(PUNICODE_STRING String, ULONG Base, PULONG Value)
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
NTSTATUS NTAPI NtSetDefaultLocale(IN BOOLEAN UserProfile, IN LCID DefaultLocaleId)
Definition: locale.c:437
long LONG
Definition: pedump.c:60
unsigned short USHORT
Definition: pedump.c:61
DWORD LCID
Definition: nls.h:13
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint32_t * PULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
_In_ CONST DEVPROPKEY _In_ LCID Lcid
Definition: iofuncs.h:2415

Referenced by HandleLogon(), and InitializeSAS().

◆ ShutdownComputerWindowProc()

static INT_PTR CALLBACK ShutdownComputerWindowProc ( IN HWND  hwndDlg,
IN UINT  uMsg,
IN WPARAM  wParam,
IN LPARAM  lParam 
)
static

Definition at line 924 of file sas.c.

929{
931
932 switch (uMsg)
933 {
934 case WM_COMMAND:
935 {
936 switch (LOWORD(wParam))
937 {
940 return TRUE;
941 }
942 break;
943 }
944 case WM_INITDIALOG:
945 {
948 return TRUE;
949 }
950 }
951 return FALSE;
952}
#define IDC_BTNSHTDOWNCOMPUTER
Definition: resource.h:10
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:325
#define LOWORD(l)
Definition: pedump.c:82
#define MF_BYCOMMAND
Definition: winuser.h:202
#define WM_COMMAND
Definition: winuser.h:1751
#define WM_INITDIALOG
Definition: winuser.h:1750
HMENU WINAPI GetSystemMenu(_In_ HWND, _In_ BOOL)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
HWND WINAPI SetFocus(_In_opt_ HWND)
BOOL WINAPI RemoveMenu(_In_ HMENU, _In_ UINT, _In_ UINT)
#define SC_CLOSE
Definition: winuser.h:2603
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)

Referenced by HandleShutdown().

◆ StartTaskManager()

static BOOL StartTaskManager ( IN OUT PWLSESSION  Session)
static

Definition at line 58 of file sas.c.

60{
61 LPVOID lpEnvironment;
62 BOOL ret;
63
64 if (!Session->Gina.Functions.WlxStartApplication)
65 return FALSE;
66
68 &lpEnvironment,
69 Session->UserToken,
70 TRUE))
71 {
72 return FALSE;
73 }
74
75 ret = Session->Gina.Functions.WlxStartApplication(
76 Session->Gina.Context,
77 L"Default",
78 lpEnvironment,
79 L"taskmgr.exe");
80
81 DestroyEnvironmentBlock(lpEnvironment);
82 return ret;
83}
BOOL WINAPI DestroyEnvironmentBlock(IN LPVOID lpEnvironment)
Definition: environment.c:725
BOOL WINAPI CreateEnvironmentBlock(OUT LPVOID *lpEnvironment, IN HANDLE hToken, IN BOOL bInherit)
Definition: environment.c:503

Referenced by DoGenericAction().

◆ StartUserShell()

static BOOL StartUserShell ( IN OUT PWLSESSION  Session)
static

Definition at line 86 of file sas.c.

88{
89 LPVOID lpEnvironment = NULL;
90 BOOLEAN Old;
91 BOOL ret;
92
93 /* Create environment block for the user */
94 if (!CreateEnvironmentBlock(&lpEnvironment, Session->UserToken, TRUE))
95 {
96 WARN("WL: CreateEnvironmentBlock() failed\n");
97 return FALSE;
98 }
99
100 /* Get privilege */
101 /* FIXME: who should do it? winlogon or gina? */
102 /* FIXME: reverting to lower privileges after creating user shell? */
104
105 ret = Session->Gina.Functions.WlxActivateUserShell(
106 Session->Gina.Context,
107 L"Default",
108 NULL, /* FIXME */
109 lpEnvironment);
110
111 DestroyEnvironmentBlock(lpEnvironment);
112 return ret;
113}
#define SE_ASSIGNPRIMARYTOKEN_PRIVILEGE
Definition: security.c:657

Referenced by HandleLogon(), and SASWindowProc().

◆ UninitializeSAS()

static VOID UninitializeSAS ( IN OUT PWLSESSION  Session)
static

Definition at line 956 of file sas.c.

958{
959 if (Session->SASWindow)
960 {
961 DestroyWindow(Session->SASWindow);
962 Session->SASWindow = NULL;
963 }
964 if (Session->hEndOfScreenSaverThread)
965 SetEvent(Session->hEndOfScreenSaverThread);
967}
BOOL WINAPI UnregisterClassW(_In_ LPCWSTR, HINSTANCE)
BOOL WINAPI DestroyWindow(_In_ HWND)

Referenced by HandleShutdown(), and InitializeSAS().

◆ UnregisterHotKeys()

static BOOL UnregisterHotKeys ( IN PWLSESSION  Session,
IN HWND  hwndSAS 
)
static

Definition at line 1265 of file sas.c.

1268{
1269 /* Unregister hotkeys */
1271
1272 if (Session->TaskManHotkey)
1274
1275 return TRUE;
1276}
BOOL WINAPI UnregisterHotKey(_In_opt_ HWND, _In_ int)

Referenced by SASWindowProc().

Variable Documentation

◆ ExitReactOSInProgress

BOOL ExitReactOSInProgress = FALSE
static

Definition at line 45 of file sas.c.

Referenced by LogoffShutdownThread(), and SASWindowProc().

◆ LuidNone

LUID LuidNone = {0, 0}