ReactOS 0.4.15-dev-5863-g1fe3ab7
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
 

Macros

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

Typedefs

typedef struct tagLOGOFF_SHUTDOWN_DATA LOGOFF_SHUTDOWN_DATA
 
typedef struct tagLOGOFF_SHUTDOWN_DATAPLOGOFF_SHUTDOWN_DATA
 

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)
 
DWORD WINAPI PlayLogonSoundThread (IN LPVOID lpParameter)
 
static VOID PlayLogonSound (IN OUT PWLSESSION Session)
 
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 (IN OUT PWLSESSION Session, IN UINT Flags)
 
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)
 
BOOL WINAPI HandleMessageBeep (UINT uType)
 
static LRESULT CALLBACK SASWindowProc (IN HWND hwndDlg, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lParam)
 
BOOL InitializeSAS (IN OUT PWLSESSION Session)
 

Variables

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

Macro Definition Documentation

◆ EWX_ACTION_MASK

#define EWX_ACTION_MASK   0x5C0F

Definition at line 37 of file sas.c.

◆ HK_CTRL_ALT_DEL

#define HK_CTRL_ALT_DEL   0

Definition at line 29 of file sas.c.

◆ HK_CTRL_SHIFT_ESC

#define HK_CTRL_SHIFT_ESC   1

Definition at line 30 of file sas.c.

◆ WIN32_LEAN_AND_MEAN

#define WIN32_LEAN_AND_MEAN

Definition at line 17 of file sas.c.

◆ WINLOGON_SAS_CLASS

#define WINLOGON_SAS_CLASS   L"SAS Window class"

Definition at line 26 of file sas.c.

◆ WINLOGON_SAS_TITLE

#define WINLOGON_SAS_TITLE   L"SAS window"

Definition at line 27 of file sas.c.

Typedef Documentation

◆ LOGOFF_SHUTDOWN_DATA

◆ PLOGOFF_SHUTDOWN_DATA

Function Documentation

◆ CreateLogoffSecurityAttributes()

static NTSTATUS CreateLogoffSecurityAttributes ( OUT PSECURITY_ATTRIBUTES ppsa)
static

Definition at line 700 of file sas.c.

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

Referenced by HandleLogoff().

◆ DestroyLogoffSecurityAttributes()

static VOID DestroyLogoffSecurityAttributes ( IN PSECURITY_ATTRIBUTES  psa)
static

Definition at line 814 of file sas.c.

816{
817 if (psa)
818 {
820 }
821}

Referenced by HandleLogoff().

◆ DispatchSAS()

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

Definition at line 1148 of file sas.c.

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

Referenced by SASWindowProc().

◆ DoGenericAction()

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

Definition at line 1058 of file sas.c.

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

Definition at line 826 of file sas.c.

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

Referenced by DoGenericAction().

◆ HandleLogon()

static BOOL HandleLogon ( IN OUT PWLSESSION  Session)
static

Definition at line 503 of file sas.c.

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

BOOL WINAPI HandleMessageBeep ( UINT  uType)

Definition at line 1279 of file sas.c.

1280{
1281 LPWSTR EventName;
1282
1283 switch(uType)
1284 {
1285 case 0xFFFFFFFF:
1286 EventName = NULL;
1287 break;
1288 case MB_OK:
1289 EventName = L"SystemDefault";
1290 break;
1291 case MB_ICONASTERISK:
1292 EventName = L"SystemAsterisk";
1293 break;
1294 case MB_ICONEXCLAMATION:
1295 EventName = L"SystemExclamation";
1296 break;
1297 case MB_ICONHAND:
1298 EventName = L"SystemHand";
1299 break;
1300 case MB_ICONQUESTION:
1301 EventName = L"SystemQuestion";
1302 break;
1303 default:
1304 WARN("Unhandled type %d\n", uType);
1305 EventName = L"SystemDefault";
1306 }
1307
1309}
#define SND_NOWAIT
Definition: mmsystem.h:159
#define SND_ALIAS
Definition: mmsystem.h:160
#define SND_ASYNC
Definition: mmsystem.h:154
#define SND_NOSTOP
Definition: mmsystem.h:158
#define L(x)
Definition: ntvdm.h:50
BOOL PlaySoundRoutine(IN LPCWSTR FileName, IN UINT bLogon, IN UINT Flags)
Definition: sas.c:240
#define MB_ICONHAND
Definition: winuser.h:782
#define MB_ICONEXCLAMATION
Definition: winuser.h:779
#define MB_OK
Definition: winuser.h:784
#define MB_ICONQUESTION
Definition: winuser.h:783
#define MB_ICONASTERISK
Definition: winuser.h:778
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by SASWindowProc().

◆ HandleShutdown()

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

Definition at line 970 of file sas.c.

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

Referenced by DoGenericAction(), and WinMain().

◆ InitializeSAS()

BOOL InitializeSAS ( IN OUT PWLSESSION  Session)

Definition at line 1514 of file sas.c.

1516{
1517 WNDCLASSEXW swc;
1518 BOOL ret = FALSE;
1519
1520 if (!SwitchDesktop(Session->WinlogonDesktop))
1521 {
1522 ERR("WL: Failed to switch to winlogon desktop\n");
1523 goto cleanup;
1524 }
1525
1526 /* Register SAS window class */
1527 swc.cbSize = sizeof(WNDCLASSEXW);
1528 swc.style = CS_SAVEBITS;
1530 swc.cbClsExtra = 0;
1531 swc.cbWndExtra = 0;
1532 swc.hInstance = hAppInstance;
1533 swc.hIcon = NULL;
1534 swc.hCursor = NULL;
1535 swc.hbrBackground = NULL;
1536 swc.lpszMenuName = NULL;
1538 swc.hIconSm = NULL;
1539 if (RegisterClassExW(&swc) == 0)
1540 {
1541 ERR("WL: Failed to register SAS window class\n");
1542 goto cleanup;
1543 }
1544
1545 /* Create invisible SAS window */
1546 Session->SASWindow = CreateWindowExW(
1547 0,
1550 WS_POPUP,
1551 0, 0, 0, 0, 0, 0,
1552 hAppInstance, Session);
1553 if (!Session->SASWindow)
1554 {
1555 ERR("WL: Failed to create SAS window\n");
1556 goto cleanup;
1557 }
1558
1559 /* Register SAS window to receive SAS notifications */
1560 if (!SetLogonNotifyWindow(Session->SASWindow))
1561 {
1562 ERR("WL: Failed to register SAS window\n");
1563 goto cleanup;
1564 }
1565
1567 return FALSE;
1568
1569 ret = TRUE;
1570
1571cleanup:
1572 if (!ret)
1573 UninitializeSAS(Session);
1574 return ret;
1575}
#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:1314
LPCWSTR lpszClassName
Definition: winuser.h:3216
LPCWSTR lpszMenuName
Definition: winuser.h:3215
HBRUSH hbrBackground
Definition: winuser.h:3214
WNDPROC lpfnWndProc
Definition: winuser.h:3208
UINT cbSize
Definition: winuser.h:3206
int cbWndExtra
Definition: winuser.h:3210
HCURSOR hCursor
Definition: winuser.h:3213
HICON hIconSm
Definition: winuser.h:3217
HINSTANCE hInstance
Definition: winuser.h:3211
UINT style
Definition: winuser.h:3207
int cbClsExtra
Definition: winuser.h:3209
HICON hIcon
Definition: winuser.h:3212
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:652
struct _WNDCLASSEXW WNDCLASSEXW

Referenced by WinMain().

◆ KillComProcesses()

static DWORD WINAPI KillComProcesses ( LPVOID  Parameter)
static

Definition at line 670 of file sas.c.

672{
673 DWORD ret = 1;
675
676 TRACE("In KillComProcesses\n");
677
678 if (LSData->Session->UserToken != NULL &&
680 {
681 ERR("ImpersonateLoggedOnUser() failed with error %lu\n", GetLastError());
682 return 0;
683 }
684
685 /* Attempt to kill remaining processes. No notifications needed. */
687 {
688 ERR("Unable to kill COM apps, error %lu\n", GetLastError());
689 ret = 0;
690 }
691
692 if (LSData->Session->UserToken)
693 RevertToSelf();
694
695 return ret;
696}
BOOL WINAPI ImpersonateLoggedOnUser(HANDLE hToken)
Definition: misc.c:152
_In_ PVOID Parameter
Definition: ldrtypes.h:241
struct tagLOGOFF_SHUTDOWN_DATA * PLOGOFF_SHUTDOWN_DATA
#define TRACE(s)
Definition: solgame.cpp:4
HANDLE UserToken
Definition: winlogon.h:232
#define EWX_NONOTIFY
Definition: undocuser.h:135
#define EWX_CALLER_WINLOGON
Definition: undocuser.h:129
BOOL WINAPI RevertToSelf(void)
Definition: security.c:1610
#define EWX_FORCE
Definition: winuser.h:630
BOOL WINAPI ExitWindowsEx(_In_ UINT, _In_ DWORD)

Referenced by HandleLogoff().

◆ LogoffShutdownThread()

static DWORD WINAPI LogoffShutdownThread ( LPVOID  Parameter)
static

Definition at line 625 of file sas.c.

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

Referenced by HandleLogoff(), and HandleShutdown().

◆ PlayLogonSound()

static VOID PlayLogonSound ( IN OUT PWLSESSION  Session)
static

Definition at line 427 of file sas.c.

429{
431
432 hThread = CreateThread(NULL, 0, PlayLogonSoundThread, (PVOID)Session->UserToken, 0, NULL);
433 if (hThread)
435}
DWORD WINAPI PlayLogonSoundThread(IN LPVOID lpParameter)
Definition: sas.c:290

Referenced by HandleLogon().

◆ PlayLogonSoundThread()

DWORD WINAPI PlayLogonSoundThread ( IN LPVOID  lpParameter)

Definition at line 290 of file sas.c.

292{
293 BYTE TokenUserBuffer[256];
294 PTOKEN_USER pTokenUser = (TOKEN_USER*)TokenUserBuffer;
296 HKEY hKey;
297 WCHAR wszBuffer[MAX_PATH] = {0};
298 WCHAR wszDest[MAX_PATH];
299 DWORD dwSize = sizeof(wszBuffer), dwType;
301 UNICODE_STRING SidString;
303 ULONG Index = 0;
304 SC_HANDLE hSCManager, hService;
305
306 //
307 // FIXME: Isn't it possible to *JUST* impersonate the current user
308 // *AND* open its HKCU??
309 //
310
311 /* Get SID of current user */
313 TokenUser,
314 TokenUserBuffer,
315 sizeof(TokenUserBuffer),
316 &Length);
317 if (!NT_SUCCESS(Status))
318 {
319 ERR("NtQueryInformationToken failed: %x!\n", Status);
320 return 0;
321 }
322
323 /* Convert SID to string */
324 RtlInitEmptyUnicodeString(&SidString, wszBuffer, sizeof(wszBuffer));
325 Status = RtlConvertSidToUnicodeString(&SidString, pTokenUser->User.Sid, FALSE);
326 if (!NT_SUCCESS(Status))
327 {
328 ERR("RtlConvertSidToUnicodeString failed: %x!\n", Status);
329 return 0;
330 }
331
332 /* Build path to logon sound registry key.
333 Note: We can't use HKCU here, because Winlogon is owned by SYSTEM user */
334 if (FAILED(StringCbCopyW(wszBuffer + SidString.Length/sizeof(WCHAR),
335 sizeof(wszBuffer) - SidString.Length,
336 L"\\AppEvents\\Schemes\\Apps\\.Default\\WindowsLogon\\.Current")))
337 {
338 /* SID is too long. Should not happen. */
339 ERR("StringCbCopyW failed!\n");
340 return 0;
341 }
342
343 /* Open registry key and query sound path */
344 if (RegOpenKeyExW(HKEY_USERS, wszBuffer, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
345 {
346 ERR("RegOpenKeyExW(%ls) failed!\n", wszBuffer);
347 return 0;
348 }
349
350 if (RegQueryValueExW(hKey, NULL, NULL, &dwType,
351 (LPBYTE)wszBuffer, &dwSize) != ERROR_SUCCESS ||
352 (dwType != REG_SZ && dwType != REG_EXPAND_SZ))
353 {
354 ERR("RegQueryValueExW failed!\n");
356 return 0;
357 }
358
360
361 if (!wszBuffer[0])
362 {
363 /* No sound has been set */
364 ERR("No sound has been set\n");
365 return 0;
366 }
367
368 /* Expand environment variables */
369 if (!ExpandEnvironmentStringsW(wszBuffer, wszDest, MAX_PATH))
370 {
371 ERR("ExpandEnvironmentStringsW failed!\n");
372 return 0;
373 }
374
375 /* Open the service manager */
377 if (!hSCManager)
378 {
379 ERR("OpenSCManager failed (%x)\n", GetLastError());
380 return 0;
381 }
382
383 /* Open the wdmaud service */
384 hService = OpenServiceW(hSCManager, L"wdmaud", GENERIC_READ);
385 if (!hService)
386 {
387 /* The service is not installed */
388 TRACE("Failed to open wdmaud service (%x)\n", GetLastError());
390 return 0;
391 }
392
393 /* Wait for wdmaud to start */
394 do
395 {
397 {
398 TRACE("QueryServiceStatusEx failed (%x)\n", GetLastError());
399 break;
400 }
401
402 if (Info.dwCurrentState == SERVICE_RUNNING)
403 break;
404
405 Sleep(1000);
406
407 } while (Index++ < 20);
408
409 CloseServiceHandle(hService);
411
412 /* If wdmaud is not running exit */
413 if (Info.dwCurrentState != SERVICE_RUNNING)
414 {
415 WARN("wdmaud has not started!\n");
416 return 0;
417 }
418
419 /* Sound subsystem is running. Play logon sound. */
420 TRACE("Playing logon sound: %ls\n", wszDest);
422 return 0;
423}
#define RegCloseKey(hKey)
Definition: registry.h:47
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3356
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4121
#define GENERIC_READ
Definition: compat.h:135
#define MAX_PATH
Definition: compat.h:34
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
FxAutoRegKey hKey
#define FAILED(hr)
Definition: intsafe.h:51
#define REG_SZ
Definition: layer.c:22
#define SND_FILENAME
Definition: mmsystem.h:162
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define KEY_READ
Definition: nt_native.h:1023
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
NTSYSAPI NTSTATUS NTAPI RtlConvertSidToUnicodeString(OUT PUNICODE_STRING DestinationString, IN PVOID Sid, IN BOOLEAN AllocateDestinationString)
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:2835
SC_HANDLE WINAPI OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2108
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:580
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166
SID_AND_ATTRIBUTES User
Definition: setypes.h:1006
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
_Must_inspect_result_ __kernel_entry NTSTATUS NTAPI NtQueryInformationToken(_In_ HANDLE TokenHandle, _In_ TOKEN_INFORMATION_CLASS TokenInformationClass, _Out_writes_bytes_to_opt_(TokenInformationLength, *ReturnLength) PVOID TokenInformation, _In_ ULONG TokenInformationLength, _Out_ PULONG ReturnLength)
Queries a specific type of information in regard of an access token based upon the information class....
Definition: tokencls.c:473
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 HKEY_USERS
Definition: winreg.h:13
#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
@ TokenUser
Definition: setypes.h:962
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by PlayLogonSound().

◆ PlaySoundRoutine()

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

Definition at line 240 of file sas.c.

244{
245 typedef BOOL (WINAPI *PLAYSOUNDW)(LPCWSTR,HMODULE,DWORD);
246 typedef UINT (WINAPI *WAVEOUTGETNUMDEVS)(VOID);
247 PLAYSOUNDW Play;
248 WAVEOUTGETNUMDEVS waveOutGetNumDevs;
249 UINT NumDevs;
251 BOOL Ret = FALSE;
252
253 hLibrary = LoadLibraryW(L"winmm.dll");
254 if (!hLibrary)
255 return FALSE;
256
257 waveOutGetNumDevs = (WAVEOUTGETNUMDEVS)GetProcAddress(hLibrary, "waveOutGetNumDevs");
258 Play = (PLAYSOUNDW)GetProcAddress(hLibrary, "PlaySoundW");
259
261 {
263 {
264 NumDevs = waveOutGetNumDevs();
265 if (!NumDevs)
266 {
267 if (!bLogon)
268 Beep(440, 125);
270 }
271 }
272
273 if (Play)
274 Ret = Play(FileName, NULL, Flags);
275 }
277 {
278 ERR("WL: Exception while playing sound '%S', Status 0x%08lx\n",
280 }
281 _SEH2_END;
282
284
285 return Ret;
286}
#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 _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define _SEH2_LEAVE
Definition: filesup.c:20
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define BOOL
Definition: nt_native.h:43
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:159
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
HANDLE HMODULE
Definition: typedefs.h:77
#define WINAPI
Definition: msvc.h:6
UINT WINAPI waveOutGetNumDevs(void)
Definition: winmm.c:2140
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by HandleMessageBeep(), and PlayLogonSoundThread().

◆ RegisterHotKeys()

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

Definition at line 1244 of file sas.c.

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

Referenced by SASWindowProc().

◆ RestoreAllConnections()

static VOID RestoreAllConnections ( PWLSESSION  Session)
static

Definition at line 439 of file sas.c.

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

Referenced by HandleLogon().

◆ SASWindowProc()

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

Definition at line 1314 of file sas.c.

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

Referenced by InitializeSAS().

◆ SetDefaultLanguage()

BOOL SetDefaultLanguage ( IN PWLSESSION  Session)

Definition at line 111 of file sas.c.

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

Referenced by HandleLogon(), and InitializeSAS().

◆ ShutdownComputerWindowProc()

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

Definition at line 924 of file sas.c.

929{
931
932 switch (uMsg)
933 {
934 case WM_COMMAND:
935 {
936 switch (LOWORD(wParam))
937 {
940 return TRUE;
941 }
942 break;
943 }
944 case WM_INITDIALOG:
945 {
948 return TRUE;
949 }
950 }
951 return FALSE;
952}
#define IDC_BTNSHTDOWNCOMPUTER
Definition: resource.h:10
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define LOWORD(l)
Definition: pedump.c:82
#define MF_BYCOMMAND
Definition: winuser.h:202
#define WM_COMMAND
Definition: winuser.h:1730
#define WM_INITDIALOG
Definition: winuser.h:1729
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:2582
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)

Referenced by HandleShutdown().

◆ StartTaskManager()

static BOOL StartTaskManager ( IN OUT PWLSESSION  Session)
static

Definition at line 52 of file sas.c.

54{
55 LPVOID lpEnvironment;
56 BOOL ret;
57
58 if (!Session->Gina.Functions.WlxStartApplication)
59 return FALSE;
60
62 &lpEnvironment,
63 Session->UserToken,
64 TRUE))
65 {
66 return FALSE;
67 }
68
69 ret = Session->Gina.Functions.WlxStartApplication(
70 Session->Gina.Context,
71 L"Default",
72 lpEnvironment,
73 L"taskmgr.exe");
74
75 DestroyEnvironmentBlock(lpEnvironment);
76 return ret;
77}
BOOL WINAPI DestroyEnvironmentBlock(IN LPVOID lpEnvironment)
Definition: environment.c:727
BOOL WINAPI CreateEnvironmentBlock(OUT LPVOID *lpEnvironment, IN HANDLE hToken, IN BOOL bInherit)
Definition: environment.c:505

Referenced by DoGenericAction().

◆ StartUserShell()

static BOOL StartUserShell ( IN OUT PWLSESSION  Session)
static

Definition at line 80 of file sas.c.

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

Referenced by HandleLogon(), and SASWindowProc().

◆ UninitializeSAS()

static VOID UninitializeSAS ( IN OUT PWLSESSION  Session)
static

Definition at line 956 of file sas.c.

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

Referenced by HandleShutdown(), and InitializeSAS().

◆ UnregisterHotKeys()

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

Definition at line 1264 of file sas.c.

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

Referenced by SASWindowProc().

Variable Documentation

◆ ExitReactOSInProgress

BOOL ExitReactOSInProgress = FALSE
static

Definition at line 45 of file sas.c.

Referenced by LogoffShutdownThread(), and SASWindowProc().

◆ LuidNone

LUID LuidNone = {0, 0}