Add SetEntriesInAcl()
Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
ad2d67e680
commit
0fea2d1ed7
@ -81,18 +81,27 @@ namespace UnitTests
|
|||||||
Assert::IsTrue(!system_impersonator && GetLastError() == ERROR_ACCESS_DENIED);
|
Assert::IsTrue(!system_impersonator && GetLastError() == ERROR_ACCESS_DENIED);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_METHOD(AllocateAndInitializeSid)
|
TEST_METHOD(ACLsAndSIDs)
|
||||||
{
|
{
|
||||||
|
vector<EXPLICIT_ACCESS> eas;
|
||||||
|
eas.reserve(3);
|
||||||
|
|
||||||
SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_WORLD_SID_AUTHORITY;
|
SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_WORLD_SID_AUTHORITY;
|
||||||
winstd::security_id pSIDEveryone;
|
winstd::security_id pSIDEveryone;
|
||||||
Assert::IsTrue(::AllocateAndInitializeSid(&SIDAuthWorld, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, pSIDEveryone));
|
Assert::IsTrue(::AllocateAndInitializeSid(&SIDAuthWorld, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, pSIDEveryone));
|
||||||
|
eas.push_back(EXPLICIT_ACCESS{ GENERIC_READ, SET_ACCESS, NO_INHERITANCE, { NULL, NO_MULTIPLE_TRUSTEE, TRUSTEE_IS_SID, TRUSTEE_IS_WELL_KNOWN_GROUP, (LPTSTR)(PSID)pSIDEveryone } });
|
||||||
|
|
||||||
SID_IDENTIFIER_AUTHORITY SIDAuthNT = SECURITY_NT_AUTHORITY;
|
SID_IDENTIFIER_AUTHORITY SIDAuthNT = SECURITY_NT_AUTHORITY;
|
||||||
winstd::security_id pSIDSystem;
|
winstd::security_id pSIDSystem;
|
||||||
Assert::IsTrue(::AllocateAndInitializeSid(&SIDAuthNT, 1, SECURITY_LOCAL_SYSTEM_RID, 0, 0, 0, 0, 0, 0, 0, pSIDSystem));
|
Assert::IsTrue(::AllocateAndInitializeSid(&SIDAuthNT, 1, SECURITY_LOCAL_SYSTEM_RID, 0, 0, 0, 0, 0, 0, 0, pSIDSystem));
|
||||||
|
eas.push_back(EXPLICIT_ACCESS{ GENERIC_ALL, SET_ACCESS, NO_INHERITANCE, { NULL, NO_MULTIPLE_TRUSTEE, TRUSTEE_IS_SID, TRUSTEE_IS_WELL_KNOWN_GROUP, (LPTSTR)(PSID)pSIDSystem } });
|
||||||
|
|
||||||
winstd::security_id pSIDAdmin;
|
winstd::security_id pSIDAdmin;
|
||||||
Assert::IsTrue(::AllocateAndInitializeSid(&SIDAuthNT, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, pSIDAdmin));
|
Assert::IsTrue(::AllocateAndInitializeSid(&SIDAuthNT, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, pSIDAdmin));
|
||||||
|
eas.push_back(EXPLICIT_ACCESS{ GENERIC_ALL, SET_ACCESS, NO_INHERITANCE, { NULL, NO_MULTIPLE_TRUSTEE, TRUSTEE_IS_SID, TRUSTEE_IS_GROUP, (LPTSTR)(PSID)pSIDAdmin } });
|
||||||
|
|
||||||
|
unique_ptr<ACL, winstd::LocalFree_delete<ACL>> acl;
|
||||||
|
Assert::AreEqual<DWORD>(ERROR_SUCCESS, ::SetEntriesInAcl((ULONG)eas.size(), eas.data(), NULL, acl));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
|
#include <AclAPI.h>
|
||||||
#include <tlhelp32.h>
|
#include <tlhelp32.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -2444,6 +2445,30 @@ static BOOL AllocateAndInitializeSid(_In_ PSID_IDENTIFIER_AUTHORITY pIdentifierA
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @copydoc SetEntriesInAclW()
|
||||||
|
static DWORD SetEntriesInAclA(_In_ ULONG cCountOfExplicitEntries, _In_reads_opt_(cCountOfExplicitEntries) PEXPLICIT_ACCESS_A pListOfExplicitEntries, _In_opt_ PACL OldAcl, _Inout_ std::unique_ptr<ACL, winstd::LocalFree_delete<ACL>>& Acl)
|
||||||
|
{
|
||||||
|
PACL h;
|
||||||
|
DWORD dwResult = SetEntriesInAclA(cCountOfExplicitEntries, pListOfExplicitEntries, OldAcl, &h);
|
||||||
|
if (dwResult == ERROR_SUCCESS)
|
||||||
|
Acl.reset(h);
|
||||||
|
return ERROR_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Creates a new access control list (ACL) by merging new access control or audit control information into an existing ACL structure.
|
||||||
|
///
|
||||||
|
/// \sa [SetEntriesInAclW function](https://learn.microsoft.com/en-us/windows/win32/api/aclapi/nf-aclapi-setentriesinaclw)
|
||||||
|
///
|
||||||
|
static DWORD SetEntriesInAclW(_In_ ULONG cCountOfExplicitEntries, _In_reads_opt_(cCountOfExplicitEntries) PEXPLICIT_ACCESS_W pListOfExplicitEntries, _In_opt_ PACL OldAcl, _Inout_ std::unique_ptr<ACL, winstd::LocalFree_delete<ACL>>& Acl)
|
||||||
|
{
|
||||||
|
PACL h;
|
||||||
|
DWORD dwResult = SetEntriesInAclW(cCountOfExplicitEntries, pListOfExplicitEntries, OldAcl, &h);
|
||||||
|
if (dwResult == ERROR_SUCCESS)
|
||||||
|
Acl.reset(h);
|
||||||
|
return ERROR_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user