ReactOS 0.4.16-dev-1279-gc894716
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 IDHK_CTRL_ALT_DEL   0
 
#define IDHK_CTRL_SHIFT_ESC   1
 
#define IDHK_WIN_L   2
 
#define IDHK_WIN_U   3
 
#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 39 of file sas.c.

◆ IDHK_CTRL_ALT_DEL

#define IDHK_CTRL_ALT_DEL   0

Definition at line 29 of file sas.c.

◆ IDHK_CTRL_SHIFT_ESC

#define IDHK_CTRL_SHIFT_ESC   1

Definition at line 30 of file sas.c.

◆ IDHK_WIN_L

#define IDHK_WIN_L   2

Definition at line 31 of file sas.c.

◆ IDHK_WIN_U

#define IDHK_WIN_U   3

Definition at line 32 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 696 of file sas.c.

698{
699 /* The following code is not working yet and messy */
700 /* Still, it gives some ideas about data types and functions involved and */
701 /* required to set up a SECURITY_DESCRIPTOR for a SECURITY_ATTRIBUTES */
702 /* instance for a thread, to allow that thread to ImpersonateLoggedOnUser(). */
703 /* Specifically THREAD_SET_THREAD_TOKEN is required. */
706 BYTE* pMem;
707 PACL pACL;
708 EXPLICIT_ACCESS Access;
709 PSID pEveryoneSID = NULL;
711
712 *ppsa = NULL;
713
714 // Let's first try to enumerate what kind of data we need for this to ever work:
715 // 1. The Winlogon SID, to be able to give it THREAD_SET_THREAD_TOKEN.
716 // 2. The users SID (the user trying to logoff, or rather shut down the system).
717 // 3. At least two EXPLICIT_ACCESS instances:
718 // 3.1 One for Winlogon itself, giving it the rights
719 // required to THREAD_SET_THREAD_TOKEN (as it's needed to successfully call
720 // ImpersonateLoggedOnUser).
721 // 3.2 One for the user, to allow *that* thread to perform its work.
722 // 4. An ACL to hold the these EXPLICIT_ACCESS ACE's.
723 // 5. A SECURITY_DESCRIPTOR to hold the ACL, and finally.
724 // 6. A SECURITY_ATTRIBUTES instance to pull all of this required stuff
725 // together, to hand it to CreateThread.
726 //
727 // However, it seems struct LOGOFF_SHUTDOWN_DATA doesn't contain
728 // these required SID's, why they'd have to be added.
729 // The Winlogon's own SID should probably only be created once,
730 // while the user's SID obviously must be created for each new user.
731 // Might as well store it when the user logs on?
732
734 1,
736 0, 0, 0, 0, 0, 0, 0,
737 &pEveryoneSID))
738 {
739 ERR("Failed to initialize security descriptor for logoff thread!\n");
740 return STATUS_UNSUCCESSFUL;
741 }
742
743 /* set up the required security attributes to be able to shut down */
744 /* To save space and time, allocate a single block of memory holding */
745 /* both SECURITY_ATTRIBUTES and SECURITY_DESCRIPTOR */
746 pMem = HeapAlloc(GetProcessHeap(),
747 0,
748 sizeof(SECURITY_ATTRIBUTES) +
750 sizeof(ACL));
751 if (!pMem)
752 {
753 ERR("Failed to allocate memory for logoff security descriptor!\n");
754 return STATUS_NO_MEMORY;
755 }
756
757 /* Note that the security descriptor needs to be in _absolute_ format, */
758 /* meaning its members must be pointers to other structures, rather */
759 /* than the relative format using offsets */
763
764 // Initialize an EXPLICIT_ACCESS structure for an ACE.
765 // The ACE will allow this thread to log off (and shut down the system, currently).
766 ZeroMemory(&Access, sizeof(Access));
768 Access.grfAccessMode = SET_ACCESS; // GRANT_ACCESS?
772 Access.Trustee.ptstrName = pEveryoneSID;
773
774 if (SetEntriesInAcl(1, &Access, NULL, &pACL) != ERROR_SUCCESS)
775 {
776 ERR("Failed to set Access Rights for logoff thread. Logging out will most likely fail.\n");
777
778 HeapFree(GetProcessHeap(), 0, pMem);
779 return STATUS_UNSUCCESSFUL;
780 }
781
783 {
784 ERR("Failed to initialize security descriptor for logoff thread!\n");
785 HeapFree(GetProcessHeap(), 0, pMem);
786 return STATUS_UNSUCCESSFUL;
787 }
788
790 TRUE, // bDaclPresent flag
791 pACL,
792 FALSE)) // not a default DACL
793 {
794 ERR("SetSecurityDescriptorDacl Error %lu\n", GetLastError());
795 HeapFree(GetProcessHeap(), 0, pMem);
796 return STATUS_UNSUCCESSFUL;
797 }
798
799 psa->nLength = sizeof(SECURITY_ATTRIBUTES);
800 psa->lpSecurityDescriptor = SecurityDescriptor;
801 psa->bInheritHandle = FALSE;
802
803 *ppsa = psa;
804
805 return STATUS_SUCCESS;
806}
@ 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:1753
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:827
unsigned char BYTE
Definition: xxhash.c:193

Referenced by HandleLogoff().

◆ DestroyLogoffSecurityAttributes()

static VOID DestroyLogoffSecurityAttributes ( IN PSECURITY_ATTRIBUTES  psa)
static

Definition at line 810 of file sas.c.

812{
813 if (psa)
814 {
816 }
817}

Referenced by HandleLogoff().

◆ DispatchSAS()

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

Definition at line 1151 of file sas.c.

1154{
1155 DWORD wlxAction = WLX_SAS_ACTION_NONE;
1156 PSID LogonSid = NULL; /* FIXME */
1157 BOOL bSecure = TRUE;
1158
1159 switch (dwSasType)
1160 {
1162 switch (Session->LogonState)
1163 {
1164 case STATE_INIT:
1165 Session->LogonState = STATE_LOGGED_OFF;
1166 Session->Gina.Functions.WlxDisplaySASNotice(Session->Gina.Context);
1167 return;
1168
1169 case STATE_LOGGED_OFF:
1170 Session->LogonState = STATE_LOGGED_OFF_SAS;
1171
1173
1174 Session->Options = 0;
1175
1176 wlxAction = (DWORD)Session->Gina.Functions.WlxLoggedOutSAS(
1177 Session->Gina.Context,
1178 Session->SASAction,
1179 &Session->LogonId,
1180 LogonSid,
1181 &Session->Options,
1182 &Session->UserToken,
1183 &Session->MprNotifyInfo,
1184 (PVOID*)&Session->Profile);
1185 break;
1186
1188 /* Ignore SAS if we are already in an SAS state */
1189 return;
1190
1191 case STATE_LOGGED_ON:
1192 Session->LogonState = STATE_LOGGED_ON_SAS;
1193 wlxAction = (DWORD)Session->Gina.Functions.WlxLoggedOnSAS(Session->Gina.Context, dwSasType, NULL);
1194 break;
1195
1197 /* Ignore SAS if we are already in an SAS state */
1198 return;
1199
1200 case STATE_LOCKED:
1201 Session->LogonState = STATE_LOCKED_SAS;
1202
1204
1205 wlxAction = (DWORD)Session->Gina.Functions.WlxWkstaLockedSAS(Session->Gina.Context, dwSasType);
1206 break;
1207
1208 case STATE_LOCKED_SAS:
1209 /* Ignore SAS if we are already in an SAS state */
1210 return;
1211
1212 default:
1213 return;
1214 }
1215 break;
1216
1218 return;
1219
1221 if (!Session->Gina.Functions.WlxScreenSaverNotify(Session->Gina.Context, &bSecure))
1222 {
1223 /* Skip start of screen saver */
1224 SetEvent(Session->hEndOfScreenSaver);
1225 }
1226 else
1227 {
1228 StartScreenSaver(Session);
1229 if (bSecure)
1230 {
1231 wlxAction = WLX_SAS_ACTION_LOCK_WKSTA;
1232// DoGenericAction(Session, WLX_SAS_ACTION_LOCK_WKSTA);
1233 }
1234 }
1235 break;
1236
1238 SetEvent(Session->hUserActivity);
1239 break;
1240 }
1241
1242 DoGenericAction(Session, wlxAction);
1243}
VOID StartScreenSaver(IN PWLSESSION Session)
Definition: screensaver.c:258
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:1060
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 1060 of file sas.c.

1063{
1064 switch (wlxAction)
1065 {
1066 case WLX_SAS_ACTION_LOGON: /* 0x01 */
1067 if (Session->LogonState == STATE_LOGGED_OFF_SAS)
1068 {
1069 if (!HandleLogon(Session))
1070 {
1071 Session->Gina.Functions.WlxDisplaySASNotice(Session->Gina.Context);
1073 }
1074 }
1075 break;
1076 case WLX_SAS_ACTION_NONE: /* 0x02 */
1077 if (Session->LogonState == STATE_LOGGED_OFF_SAS)
1078 {
1079 Session->LogonState = STATE_LOGGED_OFF;
1080 Session->Gina.Functions.WlxDisplaySASNotice(Session->Gina.Context);
1081 }
1082 else if (Session->LogonState == STATE_LOGGED_ON_SAS)
1083 {
1084 Session->LogonState = STATE_LOGGED_ON;
1085 }
1086 else if (Session->LogonState == STATE_LOCKED_SAS)
1087 {
1088 Session->LogonState = STATE_LOCKED;
1089 Session->Gina.Functions.WlxDisplayLockedNotice(Session->Gina.Context);
1090 }
1091 break;
1092 case WLX_SAS_ACTION_LOCK_WKSTA: /* 0x03 */
1093 if (Session->Gina.Functions.WlxIsLockOk(Session->Gina.Context))
1094 {
1095 SwitchDesktop(Session->WinlogonDesktop);
1096 Session->LogonState = STATE_LOCKED;
1097 Session->Gina.Functions.WlxDisplayLockedNotice(Session->Gina.Context);
1099 }
1100 break;
1101 case WLX_SAS_ACTION_LOGOFF: /* 0x04 */
1102 case WLX_SAS_ACTION_SHUTDOWN: /* 0x05 */
1103 case WLX_SAS_ACTION_FORCE_LOGOFF: /* 0x09 */
1104 case WLX_SAS_ACTION_SHUTDOWN_POWER_OFF: /* 0x0a */
1105 case WLX_SAS_ACTION_SHUTDOWN_REBOOT: /* 0x0b */
1106 if (Session->LogonState != STATE_LOGGED_OFF)
1107 {
1108 if (!Session->Gina.Functions.WlxIsLogoffOk(Session->Gina.Context))
1109 break;
1110 if (!NT_SUCCESS(HandleLogoff(Session, wlxAction)))
1111 {
1112 RemoveStatusMessage(Session);
1113 break;
1114 }
1115 Session->Gina.Functions.WlxLogoff(Session->Gina.Context);
1116 }
1117 if (WLX_SHUTTINGDOWN(wlxAction))
1118 {
1119 // FIXME: WlxShutdown should be done from inside HandleShutdown,
1120 // after having displayed "ReactOS is shutting down" message.
1121 Session->Gina.Functions.WlxShutdown(Session->Gina.Context, wlxAction);
1122 if (!NT_SUCCESS(HandleShutdown(Session, wlxAction)))
1123 {
1124 RemoveStatusMessage(Session);
1125 Session->Gina.Functions.WlxDisplaySASNotice(Session->Gina.Context);
1126 }
1127 }
1128 else
1129 {
1130 RemoveStatusMessage(Session);
1131 Session->Gina.Functions.WlxDisplaySASNotice(Session->Gina.Context);
1132 }
1133 break;
1134 case WLX_SAS_ACTION_TASKLIST: /* 0x07 */
1135 SwitchDesktop(Session->ApplicationDesktop);
1136 Session->LogonState = STATE_LOGGED_ON;
1137 StartTaskManager(Session);
1138 break;
1139 case WLX_SAS_ACTION_UNLOCK_WKSTA: /* 0x08 */
1140 SwitchDesktop(Session->ApplicationDesktop);
1141 Session->LogonState = STATE_LOGGED_ON;
1143 break;
1144 default:
1145 WARN("Unknown SAS action 0x%lx\n", wlxAction);
1146 }
1147}
#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:972
static BOOL StartTaskManager(IN OUT PWLSESSION Session)
Definition: sas.c:60
static BOOL HandleLogon(IN OUT PWLSESSION Session)
Definition: sas.c:496
static NTSTATUS HandleLogoff(_Inout_ PWLSESSION Session, _In_ DWORD wlxAction)
Definition: sas.c:822
BOOL RemoveStatusMessage(IN PWLSESSION Session)
Definition: winlogon.c:370
#define WLX_SHUTTINGDOWN(Status)
Definition: winlogon.h:280
@ LogonHandler
Definition: winlogon.h:262
@ UnlockHandler
Definition: winlogon.h:265
@ LockHandler
Definition: winlogon.h:264
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 822 of file sas.c.

825{
829 DWORD exitCode;
831
832 /* Prepare data for logoff thread */
833 LSData = HeapAlloc(GetProcessHeap(), 0, sizeof(LOGOFF_SHUTDOWN_DATA));
834 if (!LSData)
835 {
836 ERR("Failed to allocate mem for thread data\n");
837 return STATUS_NO_MEMORY;
838 }
839
840 LSData->Flags = EWX_LOGOFF;
841 if (wlxAction == WLX_SAS_ACTION_FORCE_LOGOFF)
842 {
843 LSData->Flags |= EWX_FORCE;
844 }
845
846 LSData->Session = Session;
847
849 if (!NT_SUCCESS(Status))
850 {
851 ERR("Failed to create a required security descriptor. Status 0x%08lx\n", Status);
852 HeapFree(GetProcessHeap(), 0, LSData);
853 return Status;
854 }
855
856 /* Run logoff thread */
858 if (!hThread)
859 {
860 ERR("Unable to create logoff thread, error %lu\n", GetLastError());
862 HeapFree(GetProcessHeap(), 0, LSData);
863 return STATUS_UNSUCCESSFUL;
864 }
866 if (!GetExitCodeThread(hThread, &exitCode))
867 {
868 ERR("Unable to get exit code of logoff thread (error %lu)\n", GetLastError());
871 HeapFree(GetProcessHeap(), 0, LSData);
872 return STATUS_UNSUCCESSFUL;
873 }
875 if (exitCode == 0)
876 {
877 ERR("Logoff thread returned failure\n");
879 HeapFree(GetProcessHeap(), 0, LSData);
880 return STATUS_UNSUCCESSFUL;
881 }
882
883 SwitchDesktop(Session->WinlogonDesktop);
884
885 PlayLogoffShutdownSound(Session, WLX_SHUTTINGDOWN(wlxAction));
886
887 SetWindowStationUser(Session->InteractiveWindowStation,
888 &LuidNone, NULL, 0);
889
890 // DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_LOGGINGOFF);
891
892 // FIXME: Closing network connections!
893 // DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_CLOSINGNETWORKCONNECTIONS);
894
895 /* Kill remaining COM apps. Only at logoff! */
897 if (hThread)
898 {
901 }
902
903 /* We're done with the SECURITY_DESCRIPTOR */
905 psa = NULL;
906
907 HeapFree(GetProcessHeap(), 0, LSData);
908
909 DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_SAVEYOURSETTINGS);
910
911 UnloadUserProfile(Session->UserToken, Session->hProfileInfo);
912
914
915 CloseHandle(Session->UserToken);
917 Session->LogonState = STATE_LOGGED_OFF;
918 Session->UserToken = NULL;
919
920 return STATUS_SUCCESS;
921}
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:696
static DWORD WINAPI KillComProcesses(LPVOID Parameter)
Definition: sas.c:666
LUID LuidNone
Definition: sas.c:49
static VOID PlayLogoffShutdownSound(_In_ PWLSESSION Session, _In_ BOOL bShutdown)
Definition: sas.c:397
static VOID DestroyLogoffSecurityAttributes(IN PSECURITY_ATTRIBUTES psa)
Definition: sas.c:810
static DWORD WINAPI LogoffShutdownThread(LPVOID Parameter)
Definition: sas.c:621
PWLSESSION Session
Definition: sas.c:44
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:263
#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 496 of file sas.c.

498{
499 PROFILEINFOW ProfileInfo;
500 BOOL ret = FALSE;
501
502 /* Loading personal settings */
503 DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_LOADINGYOURPERSONALSETTINGS);
504 ProfileInfo.hProfile = INVALID_HANDLE_VALUE;
505 if (0 == (Session->Options & WLX_LOGON_OPT_NO_PROFILE))
506 {
507 if (Session->Profile == NULL
508 || (Session->Profile->dwType != WLX_PROFILE_TYPE_V1_0
509 && Session->Profile->dwType != WLX_PROFILE_TYPE_V2_0))
510 {
511 ERR("WL: Wrong profile\n");
512 goto cleanup;
513 }
514
515 /* Load the user profile */
516 ZeroMemory(&ProfileInfo, sizeof(PROFILEINFOW));
517 ProfileInfo.dwSize = sizeof(PROFILEINFOW);
518 ProfileInfo.dwFlags = 0;
519 ProfileInfo.lpUserName = Session->MprNotifyInfo.pszUserName;
520 ProfileInfo.lpProfilePath = Session->Profile->pszProfile;
521 if (Session->Profile->dwType >= WLX_PROFILE_TYPE_V2_0)
522 {
523 ProfileInfo.lpDefaultPath = Session->Profile->pszNetworkDefaultUserProfile;
524 ProfileInfo.lpServerName = Session->Profile->pszServerName;
525 ProfileInfo.lpPolicyPath = Session->Profile->pszPolicy;
526 }
527
528 if (!LoadUserProfileW(Session->UserToken, &ProfileInfo))
529 {
530 ERR("WL: LoadUserProfileW() failed\n");
531 goto cleanup;
532 }
533 }
534
535 /* Create environment block for the user */
536 if (!CreateUserEnvironment(Session))
537 {
538 WARN("WL: SetUserEnvironment() failed\n");
539 goto cleanup;
540 }
541
543
544 DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_APPLYINGYOURPERSONALSETTINGS);
546
547 /* Set default user language */
548 if (!SetDefaultLanguage(Session))
549 {
550 WARN("WL: SetDefaultLanguage() failed\n");
551 goto cleanup;
552 }
553
554 /* Allow winsta and desktop access for this session */
555 if (!AllowAccessOnSession(Session))
556 {
557 WARN("WL: AllowAccessOnSession() failed to give winsta & desktop access for this session\n");
558 goto cleanup;
559 }
560
561 /* Connect remote resources */
562 RestoreAllConnections(Session);
563
564 if (!StartUserShell(Session))
565 {
566 //WCHAR StatusMsg[256];
567 WARN("WL: WlxActivateUserShell() failed\n");
568 //LoadStringW(hAppInstance, IDS_FAILEDACTIVATEUSERSHELL, StatusMsg, sizeof(StatusMsg) / sizeof(StatusMsg[0]));
569 //MessageBoxW(0, StatusMsg, NULL, MB_ICONERROR);
570 goto cleanup;
571 }
572
574
575 if (!InitializeScreenSaver(Session))
576 WARN("WL: Failed to initialize screen saver\n");
577
578 Session->hProfileInfo = ProfileInfo.hProfile;
579
580 /* Logon has succeeded. Play sound. */
581 PlayLogonSound(Session);
582
583 /* NOTE: The logon timestamp has to be set after calling PlayLogonSound
584 * to correctly detect the startup event (first logon) */
585 SetLogonTimestamp(Session);
586 ret = TRUE;
587
588cleanup:
589 if (Session->Profile)
590 {
591 HeapFree(GetProcessHeap(), 0, Session->Profile->pszProfile);
592 HeapFree(GetProcessHeap(), 0, Session->Profile);
593 }
594 Session->Profile = NULL;
595 if (!ret && ProfileInfo.hProfile != INVALID_HANDLE_VALUE)
596 {
597 UnloadUserProfile(Session->UserToken, ProfileInfo.hProfile);
598 }
599 RemoveStatusMessage(Session);
600 if (!ret)
601 {
602 SetWindowStationUser(Session->InteractiveWindowStation,
603 &LuidNone, NULL, 0);
604 CloseHandle(Session->UserToken);
605 Session->UserToken = NULL;
606 }
607
608 if (ret)
609 {
610 SwitchDesktop(Session->ApplicationDesktop);
611 Session->LogonState = STATE_LOGGED_ON;
612 }
613
614 return ret;
615}
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:205
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:88
BOOL SetDefaultLanguage(IN PWLSESSION Session)
Definition: sas.c:119
static VOID PlayLogonSound(_In_ PWLSESSION Session)
Definition: sas.c:373
static VOID RestoreAllConnections(PWLSESSION Session)
Definition: sas.c:432
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:294
@ StartShellHandler
Definition: winlogon.h:272
#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 1299 of file sas.c.

1302{
1303 LPWSTR EventName;
1304
1305 switch (uType)
1306 {
1307 case 0xFFFFFFFF:
1308 EventName = NULL;
1309 break;
1310 case MB_OK:
1311 EventName = L"SystemDefault";
1312 break;
1313 case MB_ICONASTERISK:
1314 EventName = L"SystemAsterisk";
1315 break;
1316 case MB_ICONEXCLAMATION:
1317 EventName = L"SystemExclamation";
1318 break;
1319 case MB_ICONHAND:
1320 EventName = L"SystemHand";
1321 break;
1322 case MB_ICONQUESTION:
1323 EventName = L"SystemQuestion";
1324 break;
1325 default:
1326 WARN("Unhandled type %d\n", uType);
1327 EventName = L"SystemDefault";
1328 }
1329
1330 return PlayEventSound(Session, EventName);
1331}
#define L(x)
Definition: ntvdm.h:50
static BOOL PlayEventSound(_In_ PWLSESSION Session, _In_ LPCWSTR EventName)
Definition: sas.c:414
#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 972 of file sas.c.

975{
978 DWORD exitCode;
979 BOOLEAN Old;
980
981 // SwitchDesktop(Session->WinlogonDesktop);
982
983 /* If the system is rebooting, show the appropriate string */
984 if (wlxAction == WLX_SAS_ACTION_SHUTDOWN_REBOOT)
985 DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_REACTOSISRESTARTING);
986 else
987 DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_REACTOSISSHUTTINGDOWN);
988
989 /* Prepare data for shutdown thread */
990 LSData = HeapAlloc(GetProcessHeap(), 0, sizeof(LOGOFF_SHUTDOWN_DATA));
991 if (!LSData)
992 {
993 ERR("Failed to allocate mem for thread data\n");
994 return STATUS_NO_MEMORY;
995 }
996 if (wlxAction == WLX_SAS_ACTION_SHUTDOWN_POWER_OFF)
997 LSData->Flags = EWX_POWEROFF;
998 else if (wlxAction == WLX_SAS_ACTION_SHUTDOWN_REBOOT)
999 LSData->Flags = EWX_REBOOT;
1000 else
1001 LSData->Flags = EWX_SHUTDOWN;
1002 LSData->Session = Session;
1003
1004 // FIXME: We may need to specify this flag to really force application kill
1005 // (we are shutting down ReactOS, not just logging off so no hangs, etc...
1006 // should be allowed).
1007 // LSData->Flags |= EWX_FORCE;
1008
1009 /* Run shutdown thread */
1011 if (!hThread)
1012 {
1013 ERR("Unable to create shutdown thread, error %lu\n", GetLastError());
1014 HeapFree(GetProcessHeap(), 0, LSData);
1015 return STATUS_UNSUCCESSFUL;
1016 }
1018 HeapFree(GetProcessHeap(), 0, LSData);
1019 if (!GetExitCodeThread(hThread, &exitCode))
1020 {
1021 ERR("Unable to get exit code of shutdown thread (error %lu)\n", GetLastError());
1023 return STATUS_UNSUCCESSFUL;
1024 }
1026 if (exitCode == 0)
1027 {
1028 ERR("Shutdown thread returned failure\n");
1029 return STATUS_UNSUCCESSFUL;
1030 }
1031
1033
1034 /* Destroy SAS window */
1035 UninitializeSAS(Session);
1036
1037 /* Now we can shut down NT */
1038 ERR("Shutting down NT...\n");
1040 if (wlxAction == WLX_SAS_ACTION_SHUTDOWN_REBOOT)
1041 {
1043 }
1044 else
1045 {
1046 if (FALSE)
1047 {
1048 /* FIXME - only show this dialog if it's a shutdown and the computer doesn't support APM */
1051 }
1053 }
1055 return STATUS_SUCCESS;
1056}
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:926
static VOID UninitializeSAS(IN OUT PWLSESSION Session)
Definition: sas.c:958
@ ShutdownHandler
Definition: winlogon.h:267
#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:5846

Referenced by DoGenericAction(), and WinMain().

◆ InitializeSAS()

BOOL InitializeSAS ( IN OUT PWLSESSION  Session)

Definition at line 1555 of file sas.c.

1557{
1558 WNDCLASSEXW swc;
1559 BOOL ret = FALSE;
1560
1561 if (!SwitchDesktop(Session->WinlogonDesktop))
1562 {
1563 ERR("WL: Failed to switch to winlogon desktop\n");
1564 goto cleanup;
1565 }
1566
1567 /* Register SAS window class */
1568 swc.cbSize = sizeof(WNDCLASSEXW);
1569 swc.style = CS_SAVEBITS;
1571 swc.cbClsExtra = 0;
1572 swc.cbWndExtra = 0;
1573 swc.hInstance = hAppInstance;
1574 swc.hIcon = NULL;
1575 swc.hCursor = NULL;
1576 swc.hbrBackground = NULL;
1577 swc.lpszMenuName = NULL;
1579 swc.hIconSm = NULL;
1580 if (RegisterClassExW(&swc) == 0)
1581 {
1582 ERR("WL: Failed to register SAS window class\n");
1583 goto cleanup;
1584 }
1585
1586 /* Create invisible SAS window */
1587 Session->SASWindow = CreateWindowExW(
1588 0,
1591 WS_POPUP,
1592 0, 0, 0, 0, 0, 0,
1593 hAppInstance, Session);
1594 if (!Session->SASWindow)
1595 {
1596 ERR("WL: Failed to create SAS window\n");
1597 goto cleanup;
1598 }
1599
1600 /* Register SAS window to receive SAS notifications */
1601 if (!SetLogonNotifyWindow(Session->SASWindow))
1602 {
1603 ERR("WL: Failed to register SAS window\n");
1604 goto cleanup;
1605 }
1606
1608 return FALSE;
1609
1610 ret = TRUE;
1611
1612cleanup:
1613 if (!ret)
1614 UninitializeSAS(Session);
1615 return ret;
1616}
#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:1336
LPCWSTR lpszClassName
Definition: winuser.h:3302
LPCWSTR lpszMenuName
Definition: winuser.h:3301
HBRUSH hbrBackground
Definition: winuser.h:3300
WNDPROC lpfnWndProc
Definition: winuser.h:3294
UINT cbSize
Definition: winuser.h:3292
int cbWndExtra
Definition: winuser.h:3296
HCURSOR hCursor
Definition: winuser.h:3299
HICON hIconSm
Definition: winuser.h:3303
HINSTANCE hInstance
Definition: winuser.h:3297
UINT style
Definition: winuser.h:3293
int cbClsExtra
Definition: winuser.h:3295
HICON hIcon
Definition: winuser.h:3298
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 666 of file sas.c.

668{
669 DWORD ret = 1;
671
672 TRACE("In KillComProcesses\n");
673
674 if (LSData->Session->UserToken != NULL &&
676 {
677 ERR("ImpersonateLoggedOnUser() failed with error %lu\n", GetLastError());
678 return 0;
679 }
680
681 /* Attempt to kill remaining processes. No notifications needed. */
683 {
684 ERR("Unable to kill COM apps, error %lu\n", GetLastError());
685 ret = 0;
686 }
687
688 if (LSData->Session->UserToken)
689 RevertToSelf();
690
691 return ret;
692}
BOOL WINAPI ImpersonateLoggedOnUser(HANDLE hToken)
Definition: misc.c:152
BOOL WINAPI RevertToSelf(void)
Definition: security.c:855
struct tagLOGOFF_SHUTDOWN_DATA * PLOGOFF_SHUTDOWN_DATA
#define TRACE(s)
Definition: solgame.cpp:4
HANDLE UserToken
Definition: winlogon.h:235
#define EWX_NONOTIFY
Definition: undocuser.h:136
#define EWX_CALLER_WINLOGON
Definition: undocuser.h:130
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 621 of file sas.c.

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

417{
418 BOOL bRet;
419
420 if (!ImpersonateLoggedOnUser(Session->UserToken))
421 return FALSE;
422
424
425 RevertToSelf();
426
427 return bRet;
428}
#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:248

Referenced by HandleMessageBeep().

◆ PlayLogoffShutdownSound()

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

Definition at line 397 of file sas.c.

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

Referenced by HandleLogoff().

◆ PlayLogonSound()

static VOID PlayLogonSound ( _In_ PWLSESSION  Session)
static

Definition at line 373 of file sas.c.

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

Referenced by HandleLogon().

◆ PlayLogonSoundThread()

static DWORD WINAPI PlayLogonSoundThread ( _In_ LPVOID  lpParameter)
static

Definition at line 299 of file sas.c.

301{
302 PLOGON_SOUND_DATA SoundData = (PLOGON_SOUND_DATA)lpParameter;
305 ULONG Index = 0;
306 SC_HANDLE hSCManager, hService;
307
308 /* Open the service manager */
310 if (!hSCManager)
311 {
312 ERR("OpenSCManager failed (%x)\n", GetLastError());
313 goto Cleanup;
314 }
315
316 /* Open the wdmaud service */
317 hService = OpenServiceW(hSCManager, L"wdmaud", GENERIC_READ);
318 if (!hService)
319 {
320 /* The service is not installed */
321 TRACE("Failed to open wdmaud service (%x)\n", GetLastError());
323 goto Cleanup;
324 }
325
326 /* Wait for wdmaud to start */
327 do
328 {
330 {
331 TRACE("QueryServiceStatusEx failed (%x)\n", GetLastError());
332 break;
333 }
334
335 if (Info.dwCurrentState == SERVICE_RUNNING)
336 break;
337
338 Sleep(1000);
339
340 } while (Index++ < 20);
341
342 CloseServiceHandle(hService);
344
345 /* If wdmaud is not running exit */
346 if (Info.dwCurrentState != SERVICE_RUNNING)
347 {
348 WARN("wdmaud has not started!\n");
349 goto Cleanup;
350 }
351
352 /* Sound subsystem is running. Play logon sound. */
353 TRACE("Playing %s sound\n", SoundData->IsStartup ? "startup" : "logon");
354 if (!ImpersonateLoggedOnUser(SoundData->UserToken))
355 {
356 ERR("ImpersonateLoggedOnUser failed (%x)\n", GetLastError());
357 }
358 else
359 {
360 PlaySoundRoutine(SoundData->IsStartup ? L"SystemStart" : L"WindowsLogon",
361 TRUE,
363 RevertToSelf();
364 }
365
366Cleanup:
367 HeapFree(GetProcessHeap(), 0, SoundData);
368 return 0;
369}
#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:2926
SC_HANDLE WINAPI OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2199
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 248 of file sas.c.

252{
253 typedef BOOL (WINAPI *PLAYSOUNDW)(LPCWSTR,HMODULE,DWORD);
254 typedef UINT (WINAPI *WAVEOUTGETNUMDEVS)(VOID);
255 PLAYSOUNDW Play;
256 WAVEOUTGETNUMDEVS waveOutGetNumDevs;
257 UINT NumDevs;
259 BOOL Ret = FALSE;
260
261 hLibrary = LoadLibraryW(L"winmm.dll");
262 if (!hLibrary)
263 return FALSE;
264
265 waveOutGetNumDevs = (WAVEOUTGETNUMDEVS)GetProcAddress(hLibrary, "waveOutGetNumDevs");
266 Play = (PLAYSOUNDW)GetProcAddress(hLibrary, "PlaySoundW");
267
269 {
271 {
272 NumDevs = waveOutGetNumDevs();
273 if (!NumDevs)
274 {
275 if (!bLogon)
276 Beep(440, 125);
278 }
279 }
280
281 if (Play)
282 Ret = Play(FileName, NULL, Flags);
283 }
285 {
286 ERR("WL: Exception while playing sound '%S', Status 0x%08lx\n",
288 }
289 _SEH2_END;
290
292
293 return Ret;
294}
#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 1247 of file sas.c.

1250{
1251 /* Register Ctrl+Alt+Del hotkey */
1253 {
1254 ERR("WL: Unable to register Ctrl+Alt+Del hotkey\n");
1255 return FALSE;
1256 }
1257
1258 /* Register Ctrl+Shift+Esc "Task Manager" hotkey (optional) */
1260 if (!Session->TaskManHotkey)
1261 WARN("WL: Unable to register Ctrl+Shift+Esc hotkey\n");
1262
1263 /* Register Win+L "Lock Workstation" hotkey (optional) */
1264 Session->LockWkStaHotkey = RegisterHotKey(hwndSAS, IDHK_WIN_L, MOD_WIN, 'L');
1265 if (!Session->LockWkStaHotkey)
1266 WARN("WL: Unable to register Win+L hotkey\n");
1267
1268 /* Register Win+U "Accessibility Utility" hotkey (optional) */
1269 Session->UtilManHotkey = RegisterHotKey(hwndSAS, IDHK_WIN_U, MOD_WIN, 'U');
1270 if (!Session->UtilManHotkey)
1271 WARN("WL: Unable to register Win+U hotkey\n");
1272
1273 return TRUE;
1274}
#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 IDHK_CTRL_ALT_DEL
Definition: sas.c:29
#define IDHK_WIN_L
Definition: sas.c:31
#define IDHK_CTRL_SHIFT_ESC
Definition: sas.c:30
#define IDHK_WIN_U
Definition: sas.c:32
#define MOD_WIN
Definition: winuser.h:2663
BOOL WINAPI RegisterHotKey(_In_opt_ HWND, _In_ int, _In_ UINT, _In_ UINT)
#define VK_DELETE
Definition: winuser.h:2252
#define VK_ESCAPE
Definition: winuser.h:2233

Referenced by SASWindowProc().

◆ RestoreAllConnections()

static VOID RestoreAllConnections ( PWLSESSION  Session)
static

Definition at line 432 of file sas.c.

433{
434 DWORD dRet;
435 HANDLE hEnum;
436 LPNETRESOURCE lpRes;
437 DWORD dSize = 0x1000;
438 DWORD dCount = -1;
439 LPNETRESOURCE lpCur;
440 BOOL UserProfile;
441
442 UserProfile = (Session && Session->UserToken);
443 if (!UserProfile)
444 {
445 return;
446 }
447
448 if (!ImpersonateLoggedOnUser(Session->UserToken))
449 {
450 ERR("WL: ImpersonateLoggedOnUser() failed with error %lu\n", GetLastError());
451 return;
452 }
453
455 if (dRet != WN_SUCCESS)
456 {
457 ERR("Failed to open enumeration: %lu\n", dRet);
458 goto quit;
459 }
460
461 lpRes = HeapAlloc(GetProcessHeap(), 0, dSize);
462 if (!lpRes)
463 {
464 ERR("Failed to allocate memory\n");
465 WNetCloseEnum(hEnum);
466 goto quit;
467 }
468
469 do
470 {
471 dSize = 0x1000;
472 dCount = -1;
473
474 memset(lpRes, 0, dSize);
475 dRet = WNetEnumResource(hEnum, &dCount, lpRes, &dSize);
476 if (dRet == WN_SUCCESS || dRet == WN_MORE_DATA)
477 {
478 lpCur = lpRes;
479 for (; dCount; dCount--)
480 {
482 lpCur++;
483 }
484 }
485 } while (dRet != WN_NO_MORE_ENTRIES);
486
487 HeapFree(GetProcessHeap(), 0, lpRes);
488 WNetCloseEnum(hEnum);
489
490quit:
491 RevertToSelf();
492}
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 1336 of file sas.c.

1341{
1343
1344 switch (uMsg)
1345 {
1346 case WM_HOTKEY:
1347 {
1348 switch (wParam)
1349 {
1350 case IDHK_CTRL_ALT_DEL:
1351 {
1352 TRACE("SAS: CONTROL+ALT+DELETE\n");
1353 if (!Session->Gina.UseCtrlAltDelete)
1354 break;
1356 return TRUE;
1357 }
1359 {
1360 TRACE("SAS: CONTROL+SHIFT+ESCAPE\n");
1361 if (Session->LogonState == STATE_LOGGED_ON)
1363 return TRUE;
1364 }
1365 case IDHK_WIN_L:
1366 {
1367 TRACE("SAS: WIN+L\n");
1369 return TRUE;
1370 }
1371 case IDHK_WIN_U:
1372 {
1373 TRACE("SAS: WIN+U\n");
1374 // PostMessageW(Session->SASWindow, WM_LOGONNOTIFY, LN_ACCESSIBILITY, 0);
1375 return TRUE;
1376 }
1377 }
1378 break;
1379 }
1380 case WM_CREATE:
1381 {
1382 /* Get the session pointer from the create data */
1383 Session = (PWLSESSION)((LPCREATESTRUCT)lParam)->lpCreateParams;
1384
1385 /* Save the Session pointer */
1386 SetWindowLongPtrW(hwndDlg, GWLP_USERDATA, (LONG_PTR)Session);
1387 if (GetSetupType())
1388 return TRUE;
1389 return RegisterHotKeys(Session, hwndDlg);
1390 }
1391 case WM_DESTROY:
1392 {
1393 if (!GetSetupType())
1394 UnregisterHotKeys(Session, hwndDlg);
1395 return TRUE;
1396 }
1397 case WM_SETTINGCHANGE:
1398 {
1399 UINT uiAction = (UINT)wParam;
1400 if (uiAction == SPI_SETSCREENSAVETIMEOUT
1401 || uiAction == SPI_SETSCREENSAVEACTIVE)
1402 {
1404 }
1405 return TRUE;
1406 }
1407 case WM_LOGONNOTIFY:
1408 {
1409 switch(wParam)
1410 {
1411 case LN_MESSAGE_BEEP:
1412 {
1413 return HandleMessageBeep(Session, lParam);
1414 }
1415 case LN_SHELL_EXITED:
1416 {
1417 /* lParam is the exit code */
1418 if (lParam != 1 &&
1419 Session->LogonState != STATE_LOGGED_OFF &&
1420 Session->LogonState != STATE_LOGGED_OFF_SAS)
1421 {
1422 SetTimer(hwndDlg, 1, 1000, NULL);
1423 }
1424 break;
1425 }
1427 {
1429 break;
1430 }
1431#if 0
1432 case LN_ACCESSIBILITY:
1433 {
1434 ERR("LN_ACCESSIBILITY(lParam = %lu)\n", lParam);
1435 break;
1436 }
1437#endif
1439 {
1441 break;
1442 }
1443 case LN_LOGOFF:
1444 {
1445 UINT Flags = (UINT)lParam;
1447 DWORD wlxAction;
1448
1449 TRACE("\tFlags : 0x%lx\n", lParam);
1450
1451 /*
1452 * Our caller (USERSRV) should have added the shutdown flag
1453 * when setting also poweroff or reboot.
1454 */
1455 if (Action & (EWX_POWEROFF | EWX_REBOOT))
1456 {
1457 if ((Action & EWX_SHUTDOWN) == 0)
1458 {
1459 ERR("Missing EWX_SHUTDOWN flag for poweroff or reboot; action 0x%x\n", Action);
1461 }
1462
1463 /* Now we can locally remove it for performing checks */
1464 Action &= ~EWX_SHUTDOWN;
1465 }
1466
1467 /* Check parameters */
1468 if (Action & EWX_FORCE)
1469 {
1470 // FIXME!
1471 ERR("FIXME: EWX_FORCE present for Winlogon, what to do?\n");
1472 Action &= ~EWX_FORCE;
1473 }
1474 switch (Action)
1475 {
1476 case EWX_LOGOFF:
1477 wlxAction = WLX_SAS_ACTION_LOGOFF;
1478 break;
1479 case EWX_SHUTDOWN:
1480 wlxAction = WLX_SAS_ACTION_SHUTDOWN;
1481 break;
1482 case EWX_REBOOT:
1484 break;
1485 case EWX_POWEROFF:
1487 break;
1488
1489 default:
1490 {
1491 ERR("Invalid ExitWindows action 0x%x\n", Action);
1493 }
1494 }
1495
1496 TRACE("In LN_LOGOFF, exit_in_progress == %s\n",
1497 ExitReactOSInProgress ? "true" : "false");
1498
1499 /*
1500 * In case a parallel shutdown request is done (while we are
1501 * being to shut down) and it was not done by Winlogon itself,
1502 * then just stop here.
1503 */
1504#if 0
1505// This code is commented at the moment (even if it's correct) because
1506// our log-offs do not really work: the shell is restarted, no app is killed
1507// etc... and as a result you just get explorer opening "My Documents". And
1508// if you try now a shut down, it won't work because winlogon thinks it is
1509// still in the middle of a shutdown.
1510// Maybe we also need to reset ExitReactOSInProgress somewhere else??
1512 {
1513 break;
1514 }
1515#endif
1516 /* Now do the shutdown action proper */
1517 DoGenericAction(Session, wlxAction);
1518 return 1;
1519 }
1520 case LN_LOGOFF_CANCELED:
1521 {
1522 ERR("Logoff canceled!!, before: exit_in_progress == %s, after will be false\n",
1523 ExitReactOSInProgress ? "true" : "false");
1524
1526 return 1;
1527 }
1528 default:
1529 {
1530 ERR("WM_LOGONNOTIFY case %d is unimplemented\n", wParam);
1531 }
1532 }
1533 return 0;
1534 }
1535 case WM_TIMER:
1536 {
1537 if (wParam == 1)
1538 {
1539 KillTimer(hwndDlg, 1);
1540 StartUserShell(Session);
1541 }
1542 break;
1543 }
1544 case WLX_WM_SAS:
1545 {
1546 DispatchSAS(Session, (DWORD)wParam);
1547 return TRUE;
1548 }
1549 }
1550
1551 return DefWindowProc(hwndDlg, uMsg, wParam, lParam);
1552}
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:1247
static VOID DispatchSAS(IN OUT PWLSESSION Session, IN DWORD dwSasType)
Definition: sas.c:1151
static BOOL HandleMessageBeep(_In_ PWLSESSION Session, _In_ UINT uType)
Definition: sas.c:1299
#define EWX_ACTION_MASK
Definition: sas.c:39
static BOOL UnregisterHotKeys(IN PWLSESSION Session, IN HWND hwndSAS)
Definition: sas.c:1278
BOOL UseCtrlAltDelete
Definition: winlogon.h:132
HANDLE hScreenSaverParametersChanged
Definition: winlogon.h:247
LOGON_STATE LogonState
Definition: winlogon.h:237
HWND SASWindow
Definition: winlogon.h:228
GINAINSTANCE Gina
Definition: winlogon.h:222
#define GetWindowLongPtr
Definition: treelist.c:73
#define GWLP_USERDATA
Definition: treelist.c:63
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define LN_SHELL_EXITED
Definition: undocuser.h:117
#define LN_LOCK_WORKSTATION
Definition: undocuser.h:119
#define WM_LOGONNOTIFY
Definition: undocuser.h:39
#define LN_START_SCREENSAVE
Definition: undocuser.h:122
#define LN_MESSAGE_BEEP
Definition: undocuser.h:121
#define LN_LOGOFF
Definition: undocuser.h:116
#define LN_LOGOFF_CANCELED
Definition: undocuser.h:123
_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:1627
#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:1648
#define WM_TIMER
Definition: winuser.h:1761
#define WM_HOTKEY
Definition: winuser.h:1898
#define WM_DESTROY
Definition: winuser.h:1628
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)
#define SetWindowLongPtrW
Definition: winuser.h:5431
#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 119 of file sas.c.

121{
122 BOOL ret = FALSE;
123 BOOL UserProfile;
124 LONG rc;
125 HKEY UserKey, hKey = NULL;
126 LPCWSTR SubKey, ValueName;
127 DWORD dwType, dwSize;
128 LPWSTR Value = NULL;
129 UNICODE_STRING ValueString;
131 LCID Lcid;
132
133 UserProfile = (Session && Session->UserToken);
134
135 if (UserProfile && !ImpersonateLoggedOnUser(Session->UserToken))
136 {
137 ERR("WL: ImpersonateLoggedOnUser() failed with error %lu\n", GetLastError());
138 return FALSE;
139 // FIXME: ... or use the default language of the system??
140 // UserProfile = FALSE;
141 }
142
143 if (UserProfile)
144 {
145 rc = RegOpenCurrentUser(MAXIMUM_ALLOWED, &UserKey);
146 if (rc != ERROR_SUCCESS)
147 {
148 TRACE("RegOpenCurrentUser() failed with error %lu\n", rc);
149 goto cleanup;
150 }
151
152 SubKey = L"Control Panel\\International";
153 ValueName = L"Locale";
154 }
155 else
156 {
157 UserKey = NULL;
158 SubKey = L"System\\CurrentControlSet\\Control\\Nls\\Language";
159 ValueName = L"Default";
160 }
161
162 rc = RegOpenKeyExW(UserKey ? UserKey : HKEY_LOCAL_MACHINE,
163 SubKey,
164 0,
165 KEY_READ,
166 &hKey);
167
168 if (UserKey)
169 RegCloseKey(UserKey);
170
171 if (rc != ERROR_SUCCESS)
172 {
173 TRACE("RegOpenKeyEx() failed with error %lu\n", rc);
174 goto cleanup;
175 }
176
178 ValueName,
179 NULL,
180 &dwType,
181 NULL,
182 &dwSize);
183 if (rc != ERROR_SUCCESS)
184 {
185 TRACE("RegQueryValueEx() failed with error %lu\n", rc);
186 goto cleanup;
187 }
188 else if (dwType != REG_SZ)
189 {
190 TRACE("Wrong type for %S\\%S registry entry (got 0x%lx, expected 0x%x)\n",
191 SubKey, ValueName, dwType, REG_SZ);
192 goto cleanup;
193 }
194
196 if (!Value)
197 {
198 TRACE("HeapAlloc() failed\n");
199 goto cleanup;
200 }
202 ValueName,
203 NULL,
204 NULL,
205 (LPBYTE)Value,
206 &dwSize);
207 if (rc != ERROR_SUCCESS)
208 {
209 TRACE("RegQueryValueEx() failed with error %lu\n", rc);
210 goto cleanup;
211 }
212
213 /* Convert Value to a Lcid */
214 ValueString.Length = ValueString.MaximumLength = (USHORT)dwSize;
215 ValueString.Buffer = Value;
216 Status = RtlUnicodeStringToInteger(&ValueString, 16, (PULONG)&Lcid);
217 if (!NT_SUCCESS(Status))
218 {
219 TRACE("RtlUnicodeStringToInteger() failed with status 0x%08lx\n", Status);
220 goto cleanup;
221 }
222
223 TRACE("%s language is 0x%08lx\n",
224 UserProfile ? "User" : "System", Lcid);
225 Status = NtSetDefaultLocale(UserProfile, Lcid);
226 if (!NT_SUCCESS(Status))
227 {
228 TRACE("NtSetDefaultLocale() failed with status 0x%08lx\n", Status);
229 goto cleanup;
230 }
231
232 ret = TRUE;
233
234cleanup:
235 if (Value)
237
238 if (hKey)
240
241 if (UserProfile)
242 RevertToSelf();
243
244 return ret;
245}
#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 926 of file sas.c.

931{
933
934 switch (uMsg)
935 {
936 case WM_COMMAND:
937 {
938 switch (LOWORD(wParam))
939 {
942 return TRUE;
943 }
944 break;
945 }
946 case WM_INITDIALOG:
947 {
950 return TRUE;
951 }
952 }
953 return FALSE;
954}
#define IDC_BTNSHTDOWNCOMPUTER
Definition: resource.h:10
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329
#define LOWORD(l)
Definition: pedump.c:82
#define MF_BYCOMMAND
Definition: winuser.h:202
#define WM_COMMAND
Definition: winuser.h:1759
#define WM_INITDIALOG
Definition: winuser.h:1758
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:2611
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)

Referenced by HandleShutdown().

◆ StartTaskManager()

static BOOL StartTaskManager ( IN OUT PWLSESSION  Session)
static

Definition at line 60 of file sas.c.

62{
63 LPVOID lpEnvironment;
64 BOOL ret;
65
66 if (!Session->Gina.Functions.WlxStartApplication)
67 return FALSE;
68
70 &lpEnvironment,
71 Session->UserToken,
72 TRUE))
73 {
74 return FALSE;
75 }
76
77 ret = Session->Gina.Functions.WlxStartApplication(
78 Session->Gina.Context,
79 L"Default",
80 lpEnvironment,
81 L"taskmgr.exe");
82
83 DestroyEnvironmentBlock(lpEnvironment);
84 return ret;
85}
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 88 of file sas.c.

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

960{
961 if (Session->SASWindow)
962 {
963 DestroyWindow(Session->SASWindow);
964 Session->SASWindow = NULL;
965 }
966 if (Session->hEndOfScreenSaverThread)
967 SetEvent(Session->hEndOfScreenSaverThread);
969}
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 1278 of file sas.c.

1281{
1282 /* Unregister the hotkeys */
1284
1285 if (Session->TaskManHotkey)
1287
1288 if (Session->LockWkStaHotkey)
1290
1291 if (Session->UtilManHotkey)
1293
1294 return TRUE;
1295}
BOOL WINAPI UnregisterHotKey(_In_opt_ HWND, _In_ int)

Referenced by SASWindowProc().

Variable Documentation

◆ ExitReactOSInProgress

BOOL ExitReactOSInProgress = FALSE
static

Definition at line 47 of file sas.c.

Referenced by LogoffShutdownThread(), and SASWindowProc().

◆ LuidNone

LUID LuidNone = {0, 0}