-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
OperationReplaceAccount.cpp
57 lines (47 loc) · 1.87 KB
/
OperationReplaceAccount.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
46
47
48
49
50
51
52
53
54
55
56
57
#include "OperationReplaceAccount.h"
#include "InputOutput.h"
#include "Helpers.h"
ClassFactory<OperationReplaceAccount> OperationReplaceAccount::RegisteredFactory(GetCommand());
OperationReplaceAccount::OperationReplaceAccount(std::queue<std::wstring> & oArgList, const std::wstring & sCommand) : Operation(oArgList)
{
// exit if there are not enough arguments to parse
const std::vector<std::wstring> sSubArgs = ProcessAndCheckArgs(2, oArgList);
// fetch params
tSearchAccount = GetSidFromName(sSubArgs.at(0));
tReplaceAccount = GetSidFromName(sSubArgs.at(1));
// see if names could be resolved
if (tSearchAccount == nullptr)
{
// complain
wprintf(L"ERROR: Invalid search account '%s' specified for parameter '%s'.\n", sSubArgs.at(0).c_str(), GetCommand().c_str());
std::exit(0);
}
// see if names could be resolved
if (tReplaceAccount == nullptr)
{
// complain
wprintf(L"ERROR: Invalid replace account '%s' specified for parameter '%s'.\n", sSubArgs.at(1).c_str(), GetCommand().c_str());
std::exit(0);
}
// store off the names for those entries
sSearchAccount = GetNameFromSidEx(tSearchAccount);
sReplaceAccount = GetNameFromSidEx(tReplaceAccount);
// flag this as being an ace-level action
AppliesToDacl = true;
AppliesToSacl = true;
AppliesToGroup = true;
AppliesToOwner = true;
// target certain parts of the security descriptor
if (sSubArgs.size() > 2) ProcessGranularTargetting(sSubArgs.at(2));
}
SidActionResult OperationReplaceAccount::DetermineSid(const WCHAR * const sSdPart, ObjectEntry & tObjectEntry, PSID const tCurrentSid, PSID & tResultantSid)
{
// check if the sid matches the ace
if (SidMatch(tCurrentSid, tSearchAccount))
{
InputOutput::AddInfo(L"Replacing account '" + sSearchAccount + L"' with '" + sReplaceAccount + L"'", sSdPart);
tResultantSid = tReplaceAccount;
return SidActionResult::Replace;
}
return SidActionResult::Nothing;
}