14#define DESKTOP_ALL (DESKTOP_READOBJECTS | DESKTOP_CREATEWINDOW | \
15 DESKTOP_CREATEMENU | DESKTOP_HOOKCONTROL | DESKTOP_JOURNALRECORD | \
16 DESKTOP_JOURNALPLAYBACK | DESKTOP_ENUMERATE | DESKTOP_WRITEOBJECTS | \
17 DESKTOP_SWITCHDESKTOP | STANDARD_RIGHTS_REQUIRED)
19#define DESKTOP_ADMINS_LIMITED (DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS | \
20 DESKTOP_CREATEWINDOW | DESKTOP_CREATEMENU | DESKTOP_ENUMERATE)
22#define DESKTOP_INTERACTIVE_LIMITED (STANDARD_RIGHTS_READ | DESKTOP_ENUMERATE | \
23 DESKTOP_READOBJECTS | DESKTOP_CREATEWINDOW)
25#define DESKTOP_WINLOGON_ADMINS_LIMITED (STANDARD_RIGHTS_REQUIRED | DESKTOP_ENUMERATE)
27#define WINSTA_ALL (WINSTA_ENUMDESKTOPS | WINSTA_READATTRIBUTES | \
28 WINSTA_ACCESSCLIPBOARD | WINSTA_CREATEDESKTOP | \
29 WINSTA_WRITEATTRIBUTES | WINSTA_ACCESSGLOBALATOMS | \
30 WINSTA_EXITWINDOWS | WINSTA_ENUMERATE | WINSTA_READSCREEN | \
31 STANDARD_RIGHTS_REQUIRED)
33#define WINSTA_ADMINS_LIMITED (WINSTA_READATTRIBUTES | WINSTA_ENUMERATE)
35#define GENERIC_ACCESS (GENERIC_READ | GENERIC_WRITE | \
36 GENERIC_EXECUTE | GENERIC_ALL)
68 DWORD DescriptorLength = 0;
74 ERR(
"ConvertToSelfRelative(): error %lu, expected ERROR_INSUFFICIENT_BUFFER\n",
GetLastError());
82 if (RelativeSd ==
NULL)
84 ERR(
"ConvertToSelfRelative(): Failed to allocate buffer for relative SD\n");
91 ERR(
"ConvertToSelfRelative(): Failed to convert the security descriptor to a self relative format (error %lu)\n",
GetLastError());
130 ERR(
"CreateWinstaSecurity(): Failed to create the Winlogon SID (error code %lu)\n",
GetLastError());
142 ERR(
"CreateWinstaSecurity(): Failed to create the admins SID (error code %lu)\n",
GetLastError());
153 ERR(
"CreateWinstaSecurity(): Failed to create the network service SID (error code %lu)\n",
GetLastError());
209 ERR(
"CreateWinstaSecurity(): Failed to allocate memory buffer for DACL!\n");
216 ERR(
"CreateWinstaSecurity(): Failed to initialize DACL (error code %lu)\n",
GetLastError());
227 ERR(
"CreateWinstaSecurity(): Failed to set ACE for Winlogon (error code %lu)\n",
GetLastError());
238 ERR(
"CreateWinstaSecurity(): Failed to set ACE for Winlogon (error code %lu)\n",
GetLastError());
249 ERR(
"CreateWinstaSecurity(): Failed to set ACE for admins (error code %lu)\n",
GetLastError());
260 ERR(
"CreateWinstaSecurity(): Failed to set ACE for admins (error code %lu)\n",
GetLastError());
271 ERR(
"CreateWinstaSecurity(): Failed to set ACE for network service (error code %lu)\n",
GetLastError());
282 ERR(
"CreateWinstaSecurity(): Failed to set ACE for network service (error code %lu)\n",
GetLastError());
289 ERR(
"CreateWinstaSecurity(): Failed to initialize absolute security descriptor (error code %lu)\n",
GetLastError());
296 ERR(
"CreateWinstaSecurity(): Failed to set up DACL to absolute security descriptor (error code %lu)\n",
GetLastError());
302 if (RelativeSd ==
NULL)
304 ERR(
"CreateWinstaSecurity(): Failed to convert security descriptor to self relative format!\n");
309 *WinstaSd = RelativeSd;
313 if (WinlogonSid !=
NULL)
318 if (AdminsSid !=
NULL)
337 if (RelativeSd !=
NULL)
377 ERR(
"CreateApplicationDesktopSecurity(): Failed to create the Winlogon SID (error code %lu)\n",
GetLastError());
389 ERR(
"CreateApplicationDesktopSecurity(): Failed to create the admins SID (error code %lu)\n",
GetLastError());
400 ERR(
"CreateApplicationDesktopSecurity(): Failed to create the network service SID (error code %lu)\n",
GetLastError());
421 ERR(
"CreateApplicationDesktopSecurity(): Failed to allocate memory buffer for DACL!\n");
428 ERR(
"CreateApplicationDesktopSecurity(): Failed to initialize DACL (error code %lu)\n",
GetLastError());
439 ERR(
"CreateApplicationDesktopSecurity(): Failed to set ACE for Winlogon (error code %lu)\n",
GetLastError());
450 ERR(
"CreateApplicationDesktopSecurity(): Failed to set ACE for admins (error code %lu)\n",
GetLastError());
461 ERR(
"CreateApplicationDesktopSecurity(): Failed to set ACE for network services (error code %lu)\n",
GetLastError());
468 ERR(
"CreateApplicationDesktopSecurity(): Failed to initialize absolute security descriptor (error code %lu)\n",
GetLastError());
475 ERR(
"CreateApplicationDesktopSecurity(): Failed to set up DACL to absolute security descriptor (error code %lu)\n",
GetLastError());
481 if (RelativeSd ==
NULL)
483 ERR(
"CreateApplicationDesktopSecurity(): Failed to convert security descriptor to self relative format!\n");
488 *ApplicationDesktopSd = RelativeSd;
492 if (WinlogonSid !=
NULL)
497 if (AdminsSid !=
NULL)
516 if (RelativeSd !=
NULL)
559 ERR(
"CreateWinlogonDesktopSecurity(): Failed to create the Winlogon SID (error code %lu)\n",
GetLastError());
571 ERR(
"CreateWinlogonDesktopSecurity(): Failed to create the admins SID (error code %lu)\n",
GetLastError());
591 ERR(
"CreateWinlogonDesktopSecurity(): Failed to allocate memory buffer for DACL!\n");
598 ERR(
"CreateWinlogonDesktopSecurity(): Failed to initialize DACL (error code %lu)\n",
GetLastError());
609 ERR(
"CreateWinlogonDesktopSecurity(): Failed to set ACE for Winlogon (error code %lu)\n",
GetLastError());
620 ERR(
"CreateWinlogonDesktopSecurity(): Failed to set ACE for admins (error code %lu)\n",
GetLastError());
627 ERR(
"CreateWinlogonDesktopSecurity(): Failed to initialize absolute security descriptor (error code %lu)\n",
GetLastError());
634 ERR(
"CreateWinlogonDesktopSecurity(): Failed to set up DACL to absolute security descriptor (error code %lu)\n",
GetLastError());
640 if (RelativeSd ==
NULL)
642 ERR(
"CreateWinlogonDesktopSecurity(): Failed to convert security descriptor to self relative format!\n");
647 *WinlogonDesktopSd = RelativeSd;
651 if (WinlogonSid !=
NULL)
656 if (AdminsSid !=
NULL)
668 if (RelativeSd !=
NULL)
708 ERR(
"CreateScreenSaverSecurity(): Failed to create the Winlogon SID (error code %lu)\n",
GetLastError());
720 ERR(
"CreateScreenSaverSecurity(): Failed to create the admins SID (error code %lu)\n",
GetLastError());
731 ERR(
"CreateScreenSaverSecurity(): Failed to create the interactive SID (error code %lu)\n",
GetLastError());
754 ERR(
"CreateScreenSaverSecurity(): Failed to allocate memory buffer for DACL!\n");
761 ERR(
"CreateScreenSaverSecurity(): Failed to initialize DACL (error code %lu)\n",
GetLastError());
772 ERR(
"CreateScreenSaverSecurity(): Failed to set ACE for Winlogon (error code %lu)\n",
GetLastError());
783 ERR(
"CreateScreenSaverSecurity(): Failed to set ACE for admins (error code %lu)\n",
GetLastError());
794 ERR(
"CreateScreenSaverSecurity(): Failed to set ACE for interactive SID (error code %lu)\n",
GetLastError());
801 ERR(
"CreateScreenSaverSecurity(): Failed to initialize absolute security descriptor (error code %lu)\n",
GetLastError());
808 ERR(
"CreateScreenSaverSecurity(): Failed to set up DACL to absolute security descriptor (error code %lu)\n",
GetLastError());
814 if (RelativeSd ==
NULL)
816 ERR(
"CreateScreenSaverSecurity(): Failed to convert security descriptor to self relative format!\n");
821 *ScreenSaverDesktopSd = RelativeSd;
825 if (WinlogonSid !=
NULL)
830 if (AdminsSid !=
NULL)
847 if (RelativeSd !=
NULL)
894 ERR(
"AllowWinstaAccessToUser(): Failed to create the Winlogon SID (error code %lu)\n",
GetLastError());
906 ERR(
"AllowWinstaAccessToUser(): Failed to create the admins SID (error code %lu)\n",
GetLastError());
917 ERR(
"AllowWinstaAccessToUser(): Failed to create the interactive SID (error code %lu)\n",
GetLastError());
928 ERR(
"AllowWinstaAccessToUser(): Failed to create the network service SID (error code %lu)\n",
GetLastError());
958 ERR(
"AllowWinstaAccessToUser(): Failed to allocate memory buffer for DACL!\n");
965 ERR(
"AllowWinstaAccessToUser(): Failed to initialize DACL (error code %lu)\n",
GetLastError());
976 ERR(
"AllowWinstaAccessToUser(): Failed to set ACE for Winlogon (error code %lu)\n",
GetLastError());
987 ERR(
"AllowWinstaAccessToUser(): Failed to set ACE for Winlogon (error code %lu)\n",
GetLastError());
998 ERR(
"AllowWinstaAccessToUser(): Failed to set ACE for admins (error code %lu)\n",
GetLastError());
1009 ERR(
"AllowWinstaAccessToUser(): Failed to set ACE for admins (error code %lu)\n",
GetLastError());
1020 ERR(
"AllowWinstaAccessToUser(): Failed to set ACE for interactive SID (error code %lu)\n",
GetLastError());
1031 ERR(
"AllowWinstaAccessToUser(): Failed to set ACE for interactive SID (error code %lu)\n",
GetLastError());
1042 ERR(
"AllowWinstaAccessToUser(): Failed to set ACE for logon user SID (error code %lu)\n",
GetLastError());
1053 ERR(
"AllowWinstaAccessToUser(): Failed to set ACE for logon user SID (error code %lu)\n",
GetLastError());
1064 ERR(
"AllowWinstaAccessToUser(): Failed to set ACE for logon network service SID (error code %lu)\n",
GetLastError());
1075 ERR(
"AllowWinstaAccessToUser(): Failed to set ACE for network service SID (error code %lu)\n",
GetLastError());
1082 ERR(
"AllowWinstaAccessToUser(): Failed to initialize absolute security descriptor (error code %lu)\n",
GetLastError());
1089 ERR(
"AllowWinstaAccessToUser(): Failed to set up DACL to absolute security descriptor (error code %lu)\n",
GetLastError());
1095 if (RelativeSd ==
NULL)
1097 ERR(
"AllowWinstaAccessToUser(): Failed to convert security descriptor to self relative format!\n");
1105 ERR(
"AllowWinstaAccessToUser(): Failed to set window station security descriptor (error code %lu)\n",
GetLastError());
1112 if (WinlogonSid !=
NULL)
1117 if (AdminsSid !=
NULL)
1139 if (RelativeSd !=
NULL)
1182 0, 0, 0, 0, 0, 0, 0,
1185 ERR(
"AllowDesktopAccessToUser(): Failed to create the Winlogon SID (error code %lu)\n",
GetLastError());
1197 ERR(
"AllowDesktopAccessToUser(): Failed to create the admins SID (error code %lu)\n",
GetLastError());
1205 0, 0, 0, 0, 0, 0, 0,
1208 ERR(
"AllowDesktopAccessToUser(): Failed to create the interactive SID (error code %lu)\n",
GetLastError());
1216 0, 0, 0, 0, 0, 0, 0,
1219 ERR(
"AllowDesktopAccessToUser(): Failed to create the network service SID (error code %lu)\n",
GetLastError());
1244 ERR(
"AllowDesktopAccessToUser(): Failed to allocate memory buffer for DACL!\n");
1251 ERR(
"AllowDesktopAccessToUser(): Failed to initialize DACL (error code %lu)\n",
GetLastError());
1262 ERR(
"AllowDesktopAccessToUser(): Failed to set ACE for Winlogon (error code %lu)\n",
GetLastError());
1273 ERR(
"AllowDesktopAccessToUser(): Failed to set ACE for admins (error code %lu)\n",
GetLastError());
1284 ERR(
"AllowDesktopAccessToUser(): Failed to set ACE for interactive SID (error code %lu)\n",
GetLastError());
1295 ERR(
"AllowDesktopAccessToUser(): Failed to set ACE for logon user SID (error code %lu)\n",
GetLastError());
1306 ERR(
"AllowDesktopAccessToUser(): Failed to set ACE for network service SID (error code %lu)\n",
GetLastError());
1313 ERR(
"AllowDesktopAccessToUser(): Failed to initialize absolute security descriptor (error code %lu)\n",
GetLastError());
1320 ERR(
"AllowDesktopAccessToUser(): Failed to set up DACL to absolute security descriptor (error code %lu)\n",
GetLastError());
1326 if (RelativeSd ==
NULL)
1328 ERR(
"AllowDesktopAccessToUser(): Failed to convert security descriptor to self relative format!\n");
1336 ERR(
"AllowDesktopAccessToUser(): Failed to set desktop security descriptor (error code %lu)\n",
GetLastError());
1343 if (WinlogonSid !=
NULL)
1348 if (AdminsSid !=
NULL)
1370 if (RelativeSd !=
NULL)
1409 ERR(
"AllowAccessOnSession(): Unexpected error code returned, must be ERROR_INSUFFICIENT_BUFFER (error code %lu)\n",
GetLastError());
1414 if (TokenGroup ==
NULL)
1416 ERR(
"AllowAccessOnSession(): Failed to allocate memory buffer for token group!\n");
1428 ERR(
"AllowAccessOnSession(): Failed to retrieve the token group information (error code %lu)\n",
GetLastError());
1446 ERR(
"AllowAccessOnSession(): Failed to allow winsta access to the logon user!\n");
1453 ERR(
"AllowAccessOnSession(): Failed to allow application desktop access to the logon user!\n");
1466 ERR(
"AllowAccessOnSession(): Failed to assign the window station to the logon user!\n");
1473 if (TokenGroup !=
NULL)
#define DESKTOP_WINLOGON_ADMINS_LIMITED
#define DESKTOP_ADMINS_LIMITED
BOOL AllowWinstaAccessToUser(_In_ HWINSTA WinSta, _In_ PSID LogonSid)
Assigns access to the specific logon user to the default window station. Such access is given to the ...
BOOL CreateApplicationDesktopSecurity(_Out_ PSECURITY_DESCRIPTOR *ApplicationDesktopSd)
Creates a security descriptor for the default application desktop upon its creation.
PSECURITY_DESCRIPTOR ConvertToSelfRelative(_In_ PSECURITY_DESCRIPTOR AbsoluteSd)
Converts an absolute security descriptor to a self-relative format.
#define WINSTA_ADMINS_LIMITED
BOOL CreateWinstaSecurity(_Out_ PSECURITY_DESCRIPTOR *WinstaSd)
Creates a security descriptor for the default window station upon its creation.
static SID_IDENTIFIER_AUTHORITY NtAuthority
BOOL AllowDesktopAccessToUser(_In_ HDESK Desktop, _In_ PSID LogonSid)
Assigns access to the specific logon user to the default desktop. Such access is given to the user wh...
BOOL CreateWinlogonDesktopSecurity(_Out_ PSECURITY_DESCRIPTOR *WinlogonDesktopSd)
Creates a security descriptor for the default Winlogon desktop. This descriptor serves as a security ...
BOOL AllowAccessOnSession(_In_ PWLSESSION Session)
Assigns both window station and desktop access to the specific session currently active on the system...
#define DESKTOP_INTERACTIVE_LIMITED
BOOL CreateScreenSaverSecurity(_Out_ PSECURITY_DESCRIPTOR *ScreenSaverDesktopSd)
Creates a security descriptor for the screen saver desktop.
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
#define ERROR_INSUFFICIENT_BUFFER
BOOL WINAPI GetTokenInformation(HANDLE TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass, LPVOID TokenInformation, DWORD TokenInformationLength, PDWORD ReturnLength)
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)
BOOL WINAPI InitializeAcl(PACL pAcl, DWORD nAclLength, DWORD dwAclRevision)
BOOL WINAPI InitializeSecurityDescriptor(PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD dwRevision)
BOOL WINAPI AddAccessAllowedAceEx(PACL pAcl, DWORD dwAceRevision, DWORD AceFlags, DWORD AccessMask, PSID pSid)
DWORD WINAPI GetLengthSid(PSID pSid)
PVOID WINAPI FreeSid(PSID pSid)
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ SECURITY_INFORMATION SecurityInformation
DWORD SECURITY_INFORMATION
struct _ACCESS_ALLOWED_ACE ACCESS_ALLOWED_ACE
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL Dacl
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL _Inout_ PULONG DaclSize
#define SE_GROUP_LOGON_ID
BOOL WINAPI SetSecurityDescriptorDacl(PSECURITY_DESCRIPTOR pSecurityDescriptor, BOOL bDaclPresent, PACL pDacl, BOOL bDaclDefaulted)
BOOL WINAPI MakeSelfRelativeSD(PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor, PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor, LPDWORD lpdwBufferLength)
SID_AND_ATTRIBUTES Groups[ANYSIZE_ARRAY]
_In_ WDFCOLLECTION _In_ ULONG Index
DWORD WINAPI GetLastError(void)
BOOL WINAPI SetWindowStationUser(IN HWINSTA hWindowStation, IN PLUID pluid, IN PSID psid OPTIONAL, IN DWORD size)
BOOL WINAPI SetUserObjectSecurity(_In_ HANDLE, _In_ PSECURITY_INFORMATION, _In_ PSECURITY_DESCRIPTOR)
#define CONTAINER_INHERIT_ACE
#define SECURITY_BUILTIN_DOMAIN_RID
#define DACL_SECURITY_INFORMATION
#define SECURITY_INTERACTIVE_RID
#define SECURITY_LOCAL_SYSTEM_RID
#define SECURITY_NT_AUTHORITY
#define OBJECT_INHERIT_ACE
#define NO_PROPAGATE_INHERIT_ACE
#define SECURITY_DESCRIPTOR_REVISION
#define SECURITY_NETWORK_SERVICE_RID
#define DOMAIN_ALIAS_RID_ADMINS