-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
OperationCanonicalizeAcls.cpp
45 lines (39 loc) · 1.62 KB
/
OperationCanonicalizeAcls.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "OperationCanonicalizeAcls.h"
#include "OperationCheckCanonical.h"
#include "DriverKitPartial.h"
#include "InputOutput.h"
ClassFactory<OperationCanonicalizeAcls> OperationCanonicalizeAcls::RegisteredFactory(GetCommand());
OperationCanonicalizeAcls::OperationCanonicalizeAcls(std::queue<std::wstring> & oArgList, const std::wstring & sCommand) : Operation(oArgList)
{
// flag this as being an ace-level action
AppliesToDacl = true;
}
bool OperationCanonicalizeAcls::ProcessAclAction(const WCHAR * const sSdPart, ObjectEntry & tObjectEntry, PACL & tCurrentAcl, bool & bAclReplacement)
{
// sanity check (null acl is considered valid)
if (tCurrentAcl == nullptr) return false;
// if no problem, then no need to perform a reorder
if (OperationCheckCanonical::IsAclCanonical(tCurrentAcl))
{
return false;
}
BYTE tNewAclBuffer[MAXWORD];
PACE_ACCESS_HEADER tNewAce = (PACE_ACCESS_HEADER) &tNewAclBuffer;
for (int iAceOrder = 0; iAceOrder < OperationCheckCanonical::MaxAceOrder; iAceOrder++)
{
PACE_ACCESS_HEADER tAce = FirstAce(tCurrentAcl);
for (ULONG iEntry = 0; iEntry < tCurrentAcl->AceCount; tAce = NextAce(tAce), iEntry++)
{
// copy the ace if it matches the sequential order (explicit deny, explicit allow, ...)
if (iAceOrder == OperationCheckCanonical::DetermineAceOrder(tAce))
{
memcpy(tNewAce, tAce, tAce->AceSize);
tNewAce = NextAce(tNewAce);
}
}
}
// recopy the updated list back into the original dacl memory space
memcpy(FirstAce(tCurrentAcl), &tNewAclBuffer, (PBYTE) tNewAce - (PBYTE) &tNewAclBuffer);
InputOutput::AddInfo(L"Access control list was canonicalized", sSdPart);
return true;
}