6 #ifndef _INC_cSecurityAttributes_H
7 #define _INC_cSecurityAttributes_H
14 #if defined(_WIN32) && ! defined(UNDER_CE)
18 #define SDDL_REVISION_1 1
19 enum WELL_KNOWN_SID_TYPE
25 #define SID_MAX_SUB_AUTHORITIES 15
26 #define SECURITY_MAX_SID_SIZE (sizeof(SID) - sizeof(DWORD) + (SID_MAX_SUB_AUTHORITIES * sizeof(DWORD)))
45 typedef CWinLocalT<SID> SUPER_t;
48 cSecurityId(WELL_KNOWN_SID_TYPE eWellKnownSidType);
54 return SUPER_t::get_Data();
62 if (get_Data() ==
nullptr)
64 return ::IsValidSid(get_Data());
67 size_t get_Length()
const
69 return ::GetLengthSid(get_SID());
72 bool SetSID(SID* pSID);
74 bool SetStringSID(
const GChar_t* pszSID);
87 typedef CWinLocalT<ACL> SUPER_t;
89 cSecurityACL(SID* pSidFirst =
nullptr, DWORD dwAccessMask = GENERIC_ALL);
94 return SUPER_t::get_Data();
102 if (get_ACL() ==
nullptr)
104 return(::IsValidAcl(get_ACL()));
106 int get_AceCount()
const
108 if (get_ACL() ==
nullptr)
110 return get_ACL()->AceCount;
113 bool AddAllowedAce(SID* pSid, DWORD dwAccessMask = GENERIC_ALL);
116 class GRAYCORE_LINK cSecurityDesc :
public CWinLocalT < SECURITY_DESCRIPTOR >
127 cSecurityDesc(ACL* pDacl =
nullptr);
131 bool InitSecurityDesc(
const FILECHAR_t* pszSaclName);
132 bool InitLowIntegrity();
134 operator SECURITY_DESCRIPTOR*()
138 static bool GRAYCALL IsValid(SECURITY_DESCRIPTOR* pSD) noexcept
142 return ::IsValidSecurityDescriptor(pSD);
144 bool isValid() const noexcept
146 return IsValid(get_Data());
148 ACL* GetSacl(BOOL* pbSaclPresent =
nullptr, BOOL* pbSaclDefaulted =
nullptr)
const
151 ACL* pSacl =
nullptr;
152 if (!::GetSecurityDescriptorSacl(get_Data(), pbSaclPresent, &pSacl, pbSaclDefaulted))
158 BOOL SetSacl(ACL* pSacl,
bool bSaclPresent =
true,
bool bSaclDefaulted =
false)
160 return ::SetSecurityDescriptorSacl(get_Data(), bSaclPresent, pSacl, bSaclDefaulted);
163 BOOL SetSaclRules(
size_t nCount, EXPLICIT_ACCESS* pRules)
165 ACL* pSacl =
nullptr;
166 LSTATUS iRet = ::SetEntriesInAcl(nCount, pRules,
nullptr, &pSacl);
167 if (iRet != NO_ERROR)
169 return SetSacl(pSacl);
173 ACL* GetDacl(BOOL* pbDaclPresent =
nullptr, BOOL* pbDaclDefaulted =
nullptr)
const
176 ACL* pDacl =
nullptr;
177 if (!::GetSecurityDescriptorDacl(get_Data(), pbDaclPresent, &pDacl, pbDaclDefaulted))
183 BOOL SetDacl(ACL* pDacl,
bool bDaclPresent =
true,
bool bDaclDefaulted =
false)
185 return ::SetSecurityDescriptorDacl(get_Data(), bDaclPresent, pDacl, bDaclDefaulted);
187 BOOL SetOwner(PSID pOwner =
nullptr, BOOL bOwnerDefaulted =
true)
190 return ::SetSecurityDescriptorOwner(get_Data(), pOwner, bOwnerDefaulted);
193 bool AttachToObject(HANDLE hObject, SE_OBJECT_TYPE type = SE_KERNEL_OBJECT)
const;
196 class GRAYCORE_LINK cSecurityAttributes :
public SECURITY_ATTRIBUTES
207 void UpdateSecurityDescriptor();
210 cSecurityAttributes(
bool bInheritHandle =
false, ACL* pDacl =
nullptr);
211 cSecurityAttributes(
bool bInheritHandle,
const FILECHAR_t* pszSaclName);
212 ~cSecurityAttributes(
void);
214 operator SECURITY_ATTRIBUTES*()
216 return static_cast<SECURITY_ATTRIBUTES*
>(
this);
218 bool isValid() const noexcept;
223 class
GRAYCORE_LINK cSecurityAttribsLowIntegrity : public cSecurityAttributes
228 cSecurityAttribsLowIntegrity(
bool bInheritHandle =
false)
229 : cSecurityAttributes(bInheritHandle, cSecurityDesc::k_szLowIntegrity)
232 ~cSecurityAttribsLowIntegrity()
237 class GRAYCORE_LINK cSecurityAttribsWKS :
public cSecurityAttributes
243 cSecurityAttribsWKS(WELL_KNOWN_SID_TYPE eWellKnownSidType = WinLocalSid, DWORD dwAccess = GENERIC_ALL,
bool bInheritHandle =
true)
244 : cSecurityAttributes(bInheritHandle)
245 , m_sid(eWellKnownSidType)
246 , m_dacl(m_sid, dwAccess)
248 m_sd.SetDacl(m_dacl);
249 UpdateSecurityDescriptor();
251 ~cSecurityAttribsWKS()
#define GRAYCORE_LINK
Definition: GrayCore.h:47
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define UNITTEST_FRIEND(n)
Define this in the class body to be unit tested. Allow the unit test to access private/protected stuf...
Definition: cUnitTestDecl.h:17
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14
LONG LSTATUS
AKA error_status_t. FACILITY_WIN32 codes returned from RegCreateKeyEx() etc. Maybe NOT GetLastError()...
Definition: HResult.h:74
char FILECHAR_t
a UTF8 char in a file name. like TCHAR
Definition: FileName.h:22
char GChar_t
My version of TCHAR, _TCHAR.
Definition: StrConst.h:26
cStringT< GChar_t > cString
Definition: cString.h:636