ReactOS 0.4.16-dev-1369-gd4d04c8
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 719 of file sas.c.

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

835{
836 if (psa)
837 {
839 }
840}

Referenced by HandleLogoff().

◆ DispatchSAS()

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

Definition at line 1196 of file sas.c.

1199{
1200 DWORD wlxAction = WLX_SAS_ACTION_NONE;
1201 PSID LogonSid = NULL; /* FIXME */
1202 BOOL bSecure = TRUE;
1203
1204 switch (dwSasType)
1205 {
1207 switch (Session->LogonState)
1208 {
1209 case STATE_INIT:
1210 Session->LogonState = STATE_LOGGED_OFF;
1211 Session->Gina.Functions.WlxDisplaySASNotice(Session->Gina.Context);
1212 return;
1213
1214 case STATE_LOGGED_OFF:
1215 Session->LogonState = STATE_LOGGED_OFF_SAS;
1216
1218
1219 Session->Options = 0;
1220
1221 wlxAction = (DWORD)Session->Gina.Functions.WlxLoggedOutSAS(
1222 Session->Gina.Context,
1223 Session->SASAction,
1224 &Session->LogonId,
1225 LogonSid,
1226 &Session->Options,
1227 &Session->UserToken,
1228 &Session->MprNotifyInfo,
1229 (PVOID*)&Session->Profile);
1230 break;
1231
1233 /* Ignore SAS if we are already in an SAS state */
1234 return;
1235
1236 case STATE_LOGGED_ON:
1237 Session->LogonState = STATE_LOGGED_ON_SAS;
1238 SwitchDesktop(Session->WinlogonDesktop);
1239 wlxAction = (DWORD)Session->Gina.Functions.WlxLoggedOnSAS(Session->Gina.Context, dwSasType, NULL);
1240 if ((wlxAction == WLX_SAS_ACTION_NONE) ||
1241 (wlxAction == WLX_SAS_ACTION_TASKLIST))
1242 {
1243 /*
1244 * If the user canceled (WLX_SAS_ACTION_NONE) the
1245 * Logged-On SAS dialog, or clicked on the Task-Manager
1246 * button (WLX_SAS_ACTION_TASKLIST), switch back to
1247 * the application desktop and return to log-on state.
1248 * In the latter case, the Task-Manager is launched
1249 * by DoGenericAction(WLX_SAS_ACTION_TASKLIST), which
1250 * doesn't automatically do the switch back, because
1251 * the user may have also pressed on Ctrl-Shift-Esc
1252 * to start it while being on the Logged-On SAS dialog
1253 * and wanting to stay there.
1254 */
1255 SwitchDesktop(Session->ApplicationDesktop);
1256 Session->LogonState = STATE_LOGGED_ON;
1257 }
1258 break;
1259
1261 /* Ignore SAS if we are already in an SAS state */
1262 return;
1263
1264 case STATE_LOCKED:
1265 Session->LogonState = STATE_LOCKED_SAS;
1266
1268
1269 wlxAction = (DWORD)Session->Gina.Functions.WlxWkstaLockedSAS(Session->Gina.Context, dwSasType);
1270 break;
1271
1272 case STATE_LOCKED_SAS:
1273 /* Ignore SAS if we are already in an SAS state */
1274 return;
1275
1276 default:
1277 return;
1278 }
1279 break;
1280
1282 return;
1283
1285 if (!Session->Gina.Functions.WlxScreenSaverNotify(Session->Gina.Context, &bSecure))
1286 {
1287 /* Skip start of screen saver */
1288 SetEvent(Session->hEndOfScreenSaver);
1289 }
1290 else
1291 {
1292 StartScreenSaver(Session);
1293 if (bSecure)
1294 {
1295 wlxAction = WLX_SAS_ACTION_LOCK_WKSTA;
1296// DoGenericAction(Session, WLX_SAS_ACTION_LOCK_WKSTA);
1297 }
1298 }
1299 break;
1300
1302 SetEvent(Session->hUserActivity);
1303 break;
1304 }
1305
1306 DoGenericAction(Session, wlxAction);
1307}
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:1086
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
BOOL WINAPI SwitchDesktop(_In_ HDESK)
#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_ACTION_TASKLIST
Definition: winwlx.h:59
#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 1086 of file sas.c.

1089{
1090 switch (wlxAction)
1091 {
1092 case WLX_SAS_ACTION_LOGON: /* 0x01 */
1093 if (Session->LogonState == STATE_LOGGED_OFF_SAS)
1094 {
1095 if (!HandleLogon(Session))
1096 {
1097 Session->LogonState = STATE_LOGGED_OFF;
1098 Session->Gina.Functions.WlxDisplaySASNotice(Session->Gina.Context);
1100 }
1101 }
1102 break;
1103 case WLX_SAS_ACTION_NONE: /* 0x02 */
1104 if (Session->LogonState == STATE_LOGGED_OFF_SAS)
1105 {
1106 Session->LogonState = STATE_LOGGED_OFF;
1107 Session->Gina.Functions.WlxDisplaySASNotice(Session->Gina.Context);
1108 }
1109 else if (Session->LogonState == STATE_LOGGED_ON_SAS)
1110 {
1111 Session->LogonState = STATE_LOGGED_ON;
1112 }
1113 else if (Session->LogonState == STATE_LOCKED_SAS)
1114 {
1115 Session->LogonState = STATE_LOCKED;
1116 Session->Gina.Functions.WlxDisplayLockedNotice(Session->Gina.Context);
1117 }
1118 break;
1119 case WLX_SAS_ACTION_LOCK_WKSTA: /* 0x03 */
1120 if ((Session->LogonState == STATE_LOGGED_ON) ||
1121 (Session->LogonState == STATE_LOGGED_ON_SAS))
1122 {
1123 if (Session->Gina.Functions.WlxIsLockOk(Session->Gina.Context))
1124 {
1125 Session->LogonState = STATE_LOCKED;
1126 SwitchDesktop(Session->WinlogonDesktop);
1127 /* We may be on the Logged-On SAS dialog, in which case
1128 * we need to close it if the lock action came via Win-L */
1131 Session->Gina.Functions.WlxDisplayLockedNotice(Session->Gina.Context);
1132 }
1133 }
1134 break;
1135 case WLX_SAS_ACTION_LOGOFF: /* 0x04 */
1136 case WLX_SAS_ACTION_SHUTDOWN: /* 0x05 */
1137 case WLX_SAS_ACTION_FORCE_LOGOFF: /* 0x09 */
1138 case WLX_SAS_ACTION_SHUTDOWN_POWER_OFF: /* 0x0a */
1139 case WLX_SAS_ACTION_SHUTDOWN_REBOOT: /* 0x0b */
1140 if (Session->LogonState != STATE_LOGGED_OFF)
1141 {
1142 if (!Session->Gina.Functions.WlxIsLogoffOk(Session->Gina.Context))
1143 break;
1144 if (!NT_SUCCESS(HandleLogoff(Session, wlxAction)))
1145 {
1146 RemoveStatusMessage(Session);
1147 break;
1148 }
1149 Session->Gina.Functions.WlxLogoff(Session->Gina.Context);
1150 }
1151 if (WLX_SHUTTINGDOWN(wlxAction))
1152 {
1153 // FIXME: WlxShutdown should be done from inside HandleShutdown,
1154 // after having displayed "ReactOS is shutting down" message.
1155 Session->Gina.Functions.WlxShutdown(Session->Gina.Context, wlxAction);
1156 if (!NT_SUCCESS(HandleShutdown(Session, wlxAction)))
1157 {
1158 RemoveStatusMessage(Session);
1159 Session->LogonState = STATE_LOGGED_OFF;
1160 Session->Gina.Functions.WlxDisplaySASNotice(Session->Gina.Context);
1161 }
1162 }
1163 else
1164 {
1165 RemoveStatusMessage(Session);
1166 Session->LogonState = STATE_LOGGED_OFF;
1167 Session->Gina.Functions.WlxDisplaySASNotice(Session->Gina.Context);
1168 }
1169 break;
1170 case WLX_SAS_ACTION_TASKLIST: /* 0x07 */
1171 if ((Session->LogonState == STATE_LOGGED_ON) ||
1172 (Session->LogonState == STATE_LOGGED_ON_SAS))
1173 {
1174 /* Start a Task-Manager instance on the application desktop.
1175 * If the user pressed Ctrl-Shift-Esc while being on the
1176 * Logged-On SAS dialog (on the Winlogon desktop), stay there. */
1177 StartTaskManager(Session);
1178 }
1179 break;
1180 case WLX_SAS_ACTION_UNLOCK_WKSTA: /* 0x08 */
1181 if ((Session->LogonState == STATE_LOCKED) ||
1182 (Session->LogonState == STATE_LOCKED_SAS))
1183 {
1185 SwitchDesktop(Session->ApplicationDesktop);
1186 Session->LogonState = STATE_LOGGED_ON;
1187 }
1188 break;
1189 default:
1190 WARN("Unknown SAS action 0x%lx\n", wlxAction);
1191 }
1192}
#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:995
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:845
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
#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_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 845 of file sas.c.

848{
852 DWORD exitCode;
854
855 /* Prepare data for logoff thread */
856 LSData = HeapAlloc(GetProcessHeap(), 0, sizeof(LOGOFF_SHUTDOWN_DATA));
857 if (!LSData)
858 {
859 ERR("Failed to allocate mem for thread data\n");
860 return STATUS_NO_MEMORY;
861 }
862
863 LSData->Flags = EWX_LOGOFF;
864 if (wlxAction == WLX_SAS_ACTION_FORCE_LOGOFF)
865 {
866 LSData->Flags |= EWX_FORCE;
867 }
868
869 LSData->Session = Session;
870
872 if (!NT_SUCCESS(Status))
873 {
874 ERR("Failed to create a required security descriptor. Status 0x%08lx\n", Status);
875 HeapFree(GetProcessHeap(), 0, LSData);
876 return Status;
877 }
878
879 /* Run logoff thread */
881 if (!hThread)
882 {
883 ERR("Unable to create logoff thread, error %lu\n", GetLastError());
885 HeapFree(GetProcessHeap(), 0, LSData);
886 return STATUS_UNSUCCESSFUL;
887 }
889 if (!GetExitCodeThread(hThread, &exitCode))
890 {
891 ERR("Unable to get exit code of logoff thread (error %lu)\n", GetLastError());
894 HeapFree(GetProcessHeap(), 0, LSData);
895 return STATUS_UNSUCCESSFUL;
896 }
898 if (exitCode == 0)
899 {
900 ERR("Logoff thread returned failure\n");
902 HeapFree(GetProcessHeap(), 0, LSData);
903 return STATUS_UNSUCCESSFUL;
904 }
905
906 SwitchDesktop(Session->WinlogonDesktop);
907
908 PlayLogoffShutdownSound(Session, WLX_SHUTTINGDOWN(wlxAction));
909
910 SetWindowStationUser(Session->InteractiveWindowStation,
911 &LuidNone, NULL, 0);
912
913 // DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_LOGGINGOFF);
914
915 // FIXME: Closing network connections!
916 // DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_CLOSINGNETWORKCONNECTIONS);
917
918 /* Kill remaining COM apps. Only at logoff! */
920 if (hThread)
921 {
924 }
925
926 /* We're done with the SECURITY_DESCRIPTOR */
928 psa = NULL;
929
930 HeapFree(GetProcessHeap(), 0, LSData);
931
932 DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_SAVEYOURSETTINGS);
933
934 UnloadUserProfile(Session->UserToken, Session->hProfileInfo);
935
937
938 CloseHandle(Session->UserToken);
940 Session->LogonState = STATE_LOGGED_OFF;
941 Session->UserToken = NULL;
942
943 return STATUS_SUCCESS;
944}
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:2197
#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:719
static DWORD WINAPI KillComProcesses(LPVOID Parameter)
Definition: sas.c:689
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:833
static DWORD WINAPI LogoffShutdownThread(LPVOID Parameter)
Definition: sas.c:644
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
505 ProfileInfo.hProfile = INVALID_HANDLE_VALUE;
506 if (!(Session->Options & WLX_LOGON_OPT_NO_PROFILE))
507 {
508 HKEY hKey;
509 LONG lError;
510 BOOL bNoPopups = FALSE;
511
512 if (Session->Profile == NULL
513 || (Session->Profile->dwType != WLX_PROFILE_TYPE_V1_0
514 && Session->Profile->dwType != WLX_PROFILE_TYPE_V2_0))
515 {
516 ERR("WL: Wrong profile\n");
517 goto cleanup;
518 }
519
520 /* Check whether error messages may be displayed when loading the user profile */
522 L"System\\CurrentControlSet\\Control\\Windows",
523 0,
525 &hKey);
526 if (lError == ERROR_SUCCESS)
527 {
528 DWORD dwValue, dwType, cbData = sizeof(dwValue);
529 lError = RegQueryValueExW(hKey, L"NoPopupsOnBoot", NULL,
530 &dwType, (PBYTE)&dwValue, &cbData);
531 if ((lError == ERROR_SUCCESS) && (dwType == REG_DWORD) && (cbData == sizeof(dwValue)))
532 bNoPopups = !!dwValue;
533
535 }
536
537 /* Load the user profile */
538 ZeroMemory(&ProfileInfo, sizeof(ProfileInfo));
539 ProfileInfo.dwSize = sizeof(ProfileInfo);
540 if (bNoPopups)
541 ProfileInfo.dwFlags |= PI_NOUI;
542 ProfileInfo.lpUserName = Session->MprNotifyInfo.pszUserName;
543 ProfileInfo.lpProfilePath = Session->Profile->pszProfile;
544 if (Session->Profile->dwType >= WLX_PROFILE_TYPE_V2_0)
545 {
546 ProfileInfo.lpDefaultPath = Session->Profile->pszNetworkDefaultUserProfile;
547 ProfileInfo.lpServerName = Session->Profile->pszServerName;
548 ProfileInfo.lpPolicyPath = Session->Profile->pszPolicy;
549 }
550
551 if (!LoadUserProfileW(Session->UserToken, &ProfileInfo))
552 {
553 ERR("WL: LoadUserProfileW() failed\n");
554 goto cleanup;
555 }
556 }
557
558 /* Create environment block for the user */
559 if (!CreateUserEnvironment(Session))
560 {
561 WARN("WL: SetUserEnvironment() failed\n");
562 goto cleanup;
563 }
564
566
567 DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_APPLYINGYOURPERSONALSETTINGS);
569
570 /* Set default user language */
571 if (!SetDefaultLanguage(Session))
572 {
573 WARN("WL: SetDefaultLanguage() failed\n");
574 goto cleanup;
575 }
576
577 /* Allow winsta and desktop access for this session */
578 if (!AllowAccessOnSession(Session))
579 {
580 WARN("WL: AllowAccessOnSession() failed to give winsta & desktop access for this session\n");
581 goto cleanup;
582 }
583
584 /* Connect remote resources */
585 RestoreAllConnections(Session);
586
587 if (!StartUserShell(Session))
588 {
589 //WCHAR StatusMsg[256];
590 WARN("WL: WlxActivateUserShell() failed\n");
591 //LoadStringW(hAppInstance, IDS_FAILEDACTIVATEUSERSHELL, StatusMsg, sizeof(StatusMsg) / sizeof(StatusMsg[0]));
592 //MessageBoxW(0, StatusMsg, NULL, MB_ICONERROR);
593 goto cleanup;
594 }
595
597
598 if (!InitializeScreenSaver(Session))
599 WARN("WL: Failed to initialize screen saver\n");
600
601 Session->hProfileInfo = ProfileInfo.hProfile;
602
603 /* Logon has succeeded. Play sound. */
604 PlayLogonSound(Session);
605
606 /* NOTE: The logon timestamp has to be set after calling PlayLogonSound
607 * to correctly detect the startup event (first logon) */
608 SetLogonTimestamp(Session);
609 ret = TRUE;
610
611cleanup:
612 if (Session->Profile)
613 {
614 HeapFree(GetProcessHeap(), 0, Session->Profile->pszProfile);
615 HeapFree(GetProcessHeap(), 0, Session->Profile);
616 }
617 Session->Profile = NULL;
618 if (!ret && ProfileInfo.hProfile != INVALID_HANDLE_VALUE)
619 {
620 UnloadUserProfile(Session->UserToken, ProfileInfo.hProfile);
621 }
622 RemoveStatusMessage(Session);
623 if (!ret)
624 {
625 SetWindowStationUser(Session->InteractiveWindowStation,
626 &LuidNone, NULL, 0);
627 CloseHandle(Session->UserToken);
628 Session->UserToken = NULL;
629 }
630
631 if (ret)
632 {
633 SwitchDesktop(Session->ApplicationDesktop);
634 Session->LogonState = STATE_LOGGED_ON;
635 }
636
637 return ret;
638}
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 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 RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
#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
return ret
Definition: mutex.c:146
#define L(x)
Definition: resources.c:13
FxAutoRegKey hKey
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
long LONG
Definition: pedump.c:60
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
#define REG_DWORD
Definition: sdbapi.c:596
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
#define PI_NOUI
Definition: userenv.h:8
FORCEINLINE VOID SetLogonTimestamp(_Inout_ PWLSESSION Session)
Definition: winlogon.h:294
@ StartShellHandler
Definition: winlogon.h:272
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#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 1363 of file sas.c.

1366{
1367 LPWSTR EventName;
1368
1369 switch (uType)
1370 {
1371 case 0xFFFFFFFF:
1372 EventName = NULL;
1373 break;
1374 case MB_OK:
1375 EventName = L"SystemDefault";
1376 break;
1377 case MB_ICONASTERISK:
1378 EventName = L"SystemAsterisk";
1379 break;
1380 case MB_ICONEXCLAMATION:
1381 EventName = L"SystemExclamation";
1382 break;
1383 case MB_ICONHAND:
1384 EventName = L"SystemHand";
1385 break;
1386 case MB_ICONQUESTION:
1387 EventName = L"SystemQuestion";
1388 break;
1389 default:
1390 WARN("Unhandled type %d\n", uType);
1391 EventName = L"SystemDefault";
1392 }
1393
1394 return PlayEventSound(Session, EventName);
1395}
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 995 of file sas.c.

998{
1001 DWORD exitCode;
1002 BOOLEAN Old;
1003
1004 // SwitchDesktop(Session->WinlogonDesktop);
1005
1006 /* If the system is rebooting, show the appropriate string */
1007 if (wlxAction == WLX_SAS_ACTION_SHUTDOWN_REBOOT)
1008 DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_REACTOSISRESTARTING);
1009 else
1010 DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_REACTOSISSHUTTINGDOWN);
1011
1012 /* Prepare data for shutdown thread */
1013 LSData = HeapAlloc(GetProcessHeap(), 0, sizeof(LOGOFF_SHUTDOWN_DATA));
1014 if (!LSData)
1015 {
1016 ERR("Failed to allocate mem for thread data\n");
1017 return STATUS_NO_MEMORY;
1018 }
1019 if (wlxAction == WLX_SAS_ACTION_SHUTDOWN_POWER_OFF)
1020 LSData->Flags = EWX_POWEROFF;
1021 else if (wlxAction == WLX_SAS_ACTION_SHUTDOWN_REBOOT)
1022 LSData->Flags = EWX_REBOOT;
1023 else
1024 LSData->Flags = EWX_SHUTDOWN;
1025 LSData->Session = Session;
1026
1027 // FIXME: We may need to specify this flag to really force application kill
1028 // (we are shutting down ReactOS, not just logging off so no hangs, etc...
1029 // should be allowed).
1030 // LSData->Flags |= EWX_FORCE;
1031
1032 /* Run shutdown thread */
1034 if (!hThread)
1035 {
1036 ERR("Unable to create shutdown thread, error %lu\n", GetLastError());
1037 HeapFree(GetProcessHeap(), 0, LSData);
1038 return STATUS_UNSUCCESSFUL;
1039 }
1041 HeapFree(GetProcessHeap(), 0, LSData);
1042 if (!GetExitCodeThread(hThread, &exitCode))
1043 {
1044 ERR("Unable to get exit code of shutdown thread (error %lu)\n", GetLastError());
1046 return STATUS_UNSUCCESSFUL;
1047 }
1049 if (exitCode == 0)
1050 {
1051 ERR("Shutdown thread returned failure\n");
1052 return STATUS_UNSUCCESSFUL;
1053 }
1054
1056
1057 /* Destroy SAS window */
1058 UninitializeSAS(Session);
1059
1060 /* Now we can shut down NT */
1061 ERR("Shutting down NT...\n");
1063 if (wlxAction == WLX_SAS_ACTION_SHUTDOWN_REBOOT)
1064 {
1066 }
1067 else
1068 {
1069 if (FALSE)
1070 {
1071 /* FIXME - only show this dialog if it's a shutdown and the computer doesn't support APM */
1074 }
1075 if (wlxAction == WLX_SAS_ACTION_SHUTDOWN_POWER_OFF)
1077 else // if (wlxAction == WLX_SAS_ACTION_SHUTDOWN)
1079 }
1081 return STATUS_SUCCESS;
1082}
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
@ ShutdownPowerOff
Definition: extypes.h:178
@ 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:949
static VOID UninitializeSAS(IN OUT PWLSESSION Session)
Definition: sas.c:981
@ 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 1618 of file sas.c.

1620{
1621 WNDCLASSEXW swc;
1622 BOOL ret = FALSE;
1623
1624 if (!SwitchDesktop(Session->WinlogonDesktop))
1625 {
1626 ERR("WL: Failed to switch to winlogon desktop\n");
1627 goto cleanup;
1628 }
1629
1630 /* Register SAS window class */
1631 swc.cbSize = sizeof(WNDCLASSEXW);
1632 swc.style = CS_SAVEBITS;
1634 swc.cbClsExtra = 0;
1635 swc.cbWndExtra = 0;
1636 swc.hInstance = hAppInstance;
1637 swc.hIcon = NULL;
1638 swc.hCursor = NULL;
1639 swc.hbrBackground = NULL;
1640 swc.lpszMenuName = NULL;
1642 swc.hIconSm = NULL;
1643 if (RegisterClassExW(&swc) == 0)
1644 {
1645 ERR("WL: Failed to register SAS window class\n");
1646 goto cleanup;
1647 }
1648
1649 /* Create invisible SAS window */
1650 Session->SASWindow = CreateWindowExW(
1651 0,
1654 WS_POPUP,
1655 0, 0, 0, 0, 0, 0,
1656 hAppInstance, Session);
1657 if (!Session->SASWindow)
1658 {
1659 ERR("WL: Failed to create SAS window\n");
1660 goto cleanup;
1661 }
1662
1663 /* Register SAS window to receive SAS notifications */
1664 if (!SetLogonNotifyWindow(Session->SASWindow))
1665 {
1666 ERR("WL: Failed to register SAS window\n");
1667 goto cleanup;
1668 }
1669
1671 return FALSE;
1672
1673 ret = TRUE;
1674
1675cleanup:
1676 if (!ret)
1677 UninitializeSAS(Session);
1678 return ret;
1679}
#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:1400
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 689 of file sas.c.

691{
692 DWORD ret = 1;
694
695 TRACE("In KillComProcesses\n");
696
697 if (LSData->Session->UserToken != NULL &&
699 {
700 ERR("ImpersonateLoggedOnUser() failed with error %lu\n", GetLastError());
701 return 0;
702 }
703
704 /* Attempt to kill remaining processes. No notifications needed. */
706 {
707 ERR("Unable to kill COM apps, error %lu\n", GetLastError());
708 ret = 0;
709 }
710
711 if (LSData->Session->UserToken)
712 RevertToSelf();
713
714 return ret;
715}
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 644 of file sas.c.

646{
647 DWORD ret = 1;
649 UINT uFlags;
650
651 if (LSData->Session->UserToken != NULL &&
653 {
654 ERR("ImpersonateLoggedOnUser() failed with error %lu\n", GetLastError());
655 return 0;
656 }
657
658 // FIXME: To be really fixed: need to check what needs to be kept and what needs to be removed there.
659 //
660 // uFlags = EWX_INTERNAL_KILL_USER_APPS | (LSData->Flags & EWX_FLAGS_MASK) |
661 // ((LSData->Flags & EWX_ACTION_MASK) == EWX_LOGOFF ? EWX_CALLER_WINLOGON_LOGOFF : 0);
662
663 uFlags = EWX_CALLER_WINLOGON | (LSData->Flags & 0x0F);
664
665 TRACE("In LogoffShutdownThread with uFlags == 0x%x; exit_in_progress == %s\n",
666 uFlags, ExitReactOSInProgress ? "true" : "false");
667
669
670 /* Close processes of the interactive user */
671 if (!ExitWindowsEx(uFlags, 0))
672 {
673 ERR("Unable to kill user apps, error %lu\n", GetLastError());
674 ret = 0;
675 }
676
677 /* Cancel all the user connections */
679
680 if (LSData->Session->UserToken)
681 RevertToSelf();
682
683 return ret;
684}
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 1311 of file sas.c.

1314{
1315 /* Register Ctrl+Alt+Del hotkey */
1317 {
1318 ERR("WL: Unable to register Ctrl+Alt+Del hotkey\n");
1319 return FALSE;
1320 }
1321
1322 /* Register Ctrl+Shift+Esc "Task Manager" hotkey (optional) */
1324 if (!Session->TaskManHotkey)
1325 WARN("WL: Unable to register Ctrl+Shift+Esc hotkey\n");
1326
1327 /* Register Win+L "Lock Workstation" hotkey (optional) */
1328 Session->LockWkStaHotkey = RegisterHotKey(hwndSAS, IDHK_WIN_L, MOD_WIN, 'L');
1329 if (!Session->LockWkStaHotkey)
1330 WARN("WL: Unable to register Win+L hotkey\n");
1331
1332 /* Register Win+U "Accessibility Utility" hotkey (optional) */
1333 Session->UtilManHotkey = RegisterHotKey(hwndSAS, IDHK_WIN_U, MOD_WIN, 'U');
1334 if (!Session->UtilManHotkey)
1335 WARN("WL: Unable to register Win+U hotkey\n");
1336
1337 return TRUE;
1338}
#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 1400 of file sas.c.

1405{
1407
1408 switch (uMsg)
1409 {
1410 case WM_HOTKEY:
1411 {
1412 switch (wParam)
1413 {
1414 case IDHK_CTRL_ALT_DEL:
1415 {
1416 TRACE("SAS: CONTROL+ALT+DELETE\n");
1417 if (!Session->Gina.UseCtrlAltDelete)
1418 break;
1420 return TRUE;
1421 }
1423 {
1424 TRACE("SAS: CONTROL+SHIFT+ESCAPE\n");
1426 return TRUE;
1427 }
1428 case IDHK_WIN_L:
1429 {
1430 TRACE("SAS: WIN+L\n");
1432 return TRUE;
1433 }
1434 case IDHK_WIN_U:
1435 {
1436 TRACE("SAS: WIN+U\n");
1437 // PostMessageW(Session->SASWindow, WM_LOGONNOTIFY, LN_ACCESSIBILITY, 0);
1438 return TRUE;
1439 }
1440 }
1441 break;
1442 }
1443 case WM_CREATE:
1444 {
1445 /* Get the session pointer from the create data */
1446 Session = (PWLSESSION)((LPCREATESTRUCT)lParam)->lpCreateParams;
1447
1448 /* Save the Session pointer */
1449 SetWindowLongPtrW(hwndDlg, GWLP_USERDATA, (LONG_PTR)Session);
1450 if (GetSetupType())
1451 return TRUE;
1452 return RegisterHotKeys(Session, hwndDlg);
1453 }
1454 case WM_DESTROY:
1455 {
1456 if (!GetSetupType())
1457 UnregisterHotKeys(Session, hwndDlg);
1458 return TRUE;
1459 }
1460 case WM_SETTINGCHANGE:
1461 {
1462 UINT uiAction = (UINT)wParam;
1463 if (uiAction == SPI_SETSCREENSAVETIMEOUT
1464 || uiAction == SPI_SETSCREENSAVEACTIVE)
1465 {
1467 }
1468 return TRUE;
1469 }
1470 case WM_LOGONNOTIFY:
1471 {
1472 switch(wParam)
1473 {
1474 case LN_MESSAGE_BEEP:
1475 {
1476 return HandleMessageBeep(Session, lParam);
1477 }
1478 case LN_SHELL_EXITED:
1479 {
1480 /* lParam is the exit code */
1481 if (lParam != 1 &&
1482 Session->LogonState != STATE_LOGGED_OFF &&
1483 Session->LogonState != STATE_LOGGED_OFF_SAS)
1484 {
1485 SetTimer(hwndDlg, 1, 1000, NULL);
1486 }
1487 break;
1488 }
1490 {
1492 break;
1493 }
1494#if 0
1495 case LN_ACCESSIBILITY:
1496 {
1497 ERR("LN_ACCESSIBILITY(lParam = %lu)\n", lParam);
1498 break;
1499 }
1500#endif
1502 {
1504 break;
1505 }
1506 case LN_LOGOFF:
1507 {
1508 UINT Flags = (UINT)lParam;
1510 DWORD wlxAction;
1511
1512 TRACE("\tFlags : 0x%lx\n", lParam);
1513
1514 /*
1515 * Our caller (USERSRV) should have added the shutdown flag
1516 * when setting also poweroff or reboot.
1517 */
1518 if (Action & (EWX_POWEROFF | EWX_REBOOT))
1519 {
1520 if ((Action & EWX_SHUTDOWN) == 0)
1521 {
1522 ERR("Missing EWX_SHUTDOWN flag for poweroff or reboot; action 0x%x\n", Action);
1524 }
1525
1526 /* Now we can locally remove it for performing checks */
1527 Action &= ~EWX_SHUTDOWN;
1528 }
1529
1530 /* Check parameters */
1531 if (Action & EWX_FORCE)
1532 {
1533 // FIXME!
1534 ERR("FIXME: EWX_FORCE present for Winlogon, what to do?\n");
1535 Action &= ~EWX_FORCE;
1536 }
1537 switch (Action)
1538 {
1539 case EWX_LOGOFF:
1540 wlxAction = WLX_SAS_ACTION_LOGOFF;
1541 break;
1542 case EWX_SHUTDOWN:
1543 wlxAction = WLX_SAS_ACTION_SHUTDOWN;
1544 break;
1545 case EWX_REBOOT:
1547 break;
1548 case EWX_POWEROFF:
1550 break;
1551
1552 default:
1553 {
1554 ERR("Invalid ExitWindows action 0x%x\n", Action);
1556 }
1557 }
1558
1559 TRACE("In LN_LOGOFF, exit_in_progress == %s\n",
1560 ExitReactOSInProgress ? "true" : "false");
1561
1562 /*
1563 * In case a parallel shutdown request is done (while we are
1564 * being to shut down) and it was not done by Winlogon itself,
1565 * then just stop here.
1566 */
1567#if 0
1568// This code is commented at the moment (even if it's correct) because
1569// our log-offs do not really work: the shell is restarted, no app is killed
1570// etc... and as a result you just get explorer opening "My Documents". And
1571// if you try now a shut down, it won't work because winlogon thinks it is
1572// still in the middle of a shutdown.
1573// Maybe we also need to reset ExitReactOSInProgress somewhere else??
1575 {
1576 break;
1577 }
1578#endif
1579 /* Now do the shutdown action proper */
1580 DoGenericAction(Session, wlxAction);
1581 return 1;
1582 }
1583 case LN_LOGOFF_CANCELED:
1584 {
1585 ERR("Logoff canceled!!, before: exit_in_progress == %s, after will be false\n",
1586 ExitReactOSInProgress ? "true" : "false");
1587
1589 return 1;
1590 }
1591 default:
1592 {
1593 ERR("WM_LOGONNOTIFY case %d is unimplemented\n", wParam);
1594 }
1595 }
1596 return 0;
1597 }
1598 case WM_TIMER:
1599 {
1600 if (wParam == 1)
1601 {
1602 KillTimer(hwndDlg, 1);
1603 StartUserShell(Session);
1604 }
1605 break;
1606 }
1607 case WLX_WM_SAS:
1608 {
1609 DispatchSAS(Session, (DWORD)wParam);
1610 return TRUE;
1611 }
1612 }
1613
1614 return DefWindowProc(hwndDlg, uMsg, wParam, lParam);
1615}
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:1311
static VOID DispatchSAS(IN OUT PWLSESSION Session, IN DWORD dwSasType)
Definition: sas.c:1196
static BOOL HandleMessageBeep(_In_ PWLSESSION Session, _In_ UINT uType)
Definition: sas.c:1363
#define EWX_ACTION_MASK
Definition: sas.c:39
static BOOL UnregisterHotKeys(IN PWLSESSION Session, IN HWND hwndSAS)
Definition: sas.c:1342
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}
LONG WINAPI RegOpenCurrentUser(IN REGSAM samDesired, OUT PHKEY phkResult)
Definition: reg.c:3209
#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
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
_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 949 of file sas.c.

954{
956
957 switch (uMsg)
958 {
959 case WM_COMMAND:
960 {
961 switch (LOWORD(wParam))
962 {
965 return TRUE;
966 }
967 break;
968 }
969 case WM_INITDIALOG:
970 {
973 return TRUE;
974 }
975 }
976 return FALSE;
977}
#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 981 of file sas.c.

983{
984 if (Session->SASWindow)
985 {
986 DestroyWindow(Session->SASWindow);
987 Session->SASWindow = NULL;
988 }
989 if (Session->hEndOfScreenSaverThread)
990 SetEvent(Session->hEndOfScreenSaverThread);
992}
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 1342 of file sas.c.

1345{
1346 /* Unregister the hotkeys */
1348
1349 if (Session->TaskManHotkey)
1351
1352 if (Session->LockWkStaHotkey)
1354
1355 if (Session->UtilManHotkey)
1357
1358 return TRUE;
1359}
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}