Skip to content

Commit

Permalink
Enhanced /SharePaths
Browse files Browse the repository at this point in the history
  • Loading branch information
NoMoreFood committed Aug 21, 2016
1 parent b4b7785 commit dc2f770
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 12 deletions.
11 changes: 8 additions & 3 deletions Operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ bool Operation::ProcessAclAction(WCHAR * const sSdPart, ObjectEntry & tObjectEnt
return bMadeChange;
}

std::vector<std::wstring> Operation::SplitArgs(std::wstring sInput, std::wstring sDelimiter)
{
std::wregex oRegex(sDelimiter);
std::wsregex_token_iterator oFirst{ sInput.begin(), sInput.end(), oRegex, -1 }, oLast;
return { oFirst, oLast };
}

bool Operation::ProcessSidAction(WCHAR * const sSdPart, ObjectEntry & tObjectEntry, PSID & tCurrentSid, bool & bSidReplacement)
{
PSID tResultantSid;
Expand Down Expand Up @@ -142,9 +149,7 @@ std::vector<std::wstring> Operation::ProcessAndCheckArgs(int iArgsRequired, std:

// parse the parameters, splitting on :
std::wstring sArg = oArgList.front(); oArgList.pop();
std::wregex oRegex(sDelimiter);
std::wsregex_token_iterator oFirst{ sArg.begin(), sArg.end(), oRegex, -1 }, oLast;
std::vector<std::wstring> oSubArgs = { oFirst, oLast };
std::vector<std::wstring> oSubArgs = SplitArgs(sArg, sDelimiter);

// verify we have enough parameters
if (oSubArgs.size() < (size_t) iArgsRequired)
Expand Down
1 change: 1 addition & 0 deletions Operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Operation
{
protected:

static std::vector<std::wstring> Operation::SplitArgs(std::wstring sInput, std::wstring sDelimiter);
static std::vector<std::wstring> ProcessAndCheckArgs(int iArgsRequired, std::queue<std::wstring> & oArgList, std::wstring sDelimiter = L":");
void ProcessGranularTargetting(std::wstring sScope);

Expand Down
3 changes: 2 additions & 1 deletion OperationDomainPaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ OperationDomainPaths::OperationDomainPaths(std::queue<std::wstring> & oArgList)
}

// create the search filter
WCHAR sSearchFilter[] = L"(&(objectCategory=computer)(|(operatingSystem=*server*)(operatingSystem=*ontap*)(operatingSystem=*netapp*))(!(userAccountControl:1.2.840.113556.1.4.803:=8192))(!(userAccountControl:1.2.840.113556.1.4.803:=2)))";
WCHAR sSearchFilter[] = L"(&(objectCategory=computer)(|(operatingSystem=*server*)(operatingSystem=*ontap*)(operatingSystem=*netapp*))" \
"(!(userAccountControl:1.2.840.113556.1.4.803:=8192))(!(userAccountControl:1.2.840.113556.1.4.803:=2)))";

// execute the search.
LPWSTR sAttributes[] = { L"cn" };
Expand Down
48 changes: 41 additions & 7 deletions OperationSharePaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,61 @@ OperationSharePaths::OperationSharePaths(std::queue<std::wstring> & oArgList) :
bool bStopOnErrors = false;
bool bAdminOnly = false;
bool bHiddenIncluded = false;
std::wregex oMatchRegex = std::wregex(L".*");
std::wregex oNoMatchRegex = std::wregex(L"\0");
if (sSubArgs.size() == 2)
{
// further split the second arg into a command delimited list
std::wstring sArg = oArgList.front(); oArgList.pop();
std::wregex oRegex(L",");
std::wsregex_token_iterator oFirst{ sSubArgs[1].begin(), sSubArgs[1].end(), oRegex, -1 }, oLast;
std::vector<std::wstring> oShareArgs = { oFirst, oLast };
std::vector<std::wstring> oShareArgs = SplitArgs(sSubArgs[1], L",");

// enumerate list
for (std::vector<std::wstring>::iterator sShareArg = oShareArgs.begin();
sShareArg != oShareArgs.end(); sShareArg++)
{
if (_wcsicmp((*sShareArg).c_str(), L"INCLUDEHIDDEN") == 0)
// check to see if a match parameter was passed
WCHAR sMatchArg[] = L"MATCH=";
WCHAR sNoMatchArg[] = L"NOMATCH=";
if (_wcsnicmp((*sShareArg).c_str(), sMatchArg, _countof(sMatchArg) - 1) == 0 ||
_wcsnicmp((*sShareArg).c_str(), sNoMatchArg, _countof(sNoMatchArg) - 1) == 0)
{
// split the NOMATCH/MATCH= sub parameter to get the regular expression part
std::vector<std::wstring> oMatchArgs = SplitArgs(*sShareArg, L"=");

// verify a regular expression was actually specified
if (oMatchArgs.size() != 2)
{
wprintf(L"ERROR: No regular expression specified for parameter '%s'\n", sSubArgs[0].c_str());
exit(-1);
}

try
{
// parse the regular expression
(_wcsnicmp((*sShareArg).c_str(), sMatchArg, _countof(sMatchArg) - 1) == 0) ? oMatchRegex : oNoMatchRegex =
std::wregex(oMatchArgs[1], std::regex_constants::icase);
}
catch (std::exception &)
{
// regular expression could no be parsed
wprintf(L"ERROR: Invalid regular expression '%s'\n", oMatchArgs[1].c_str());
exit(-1);
}
}
else if (_wcsicmp((*sShareArg).c_str(), L"INCLUDEHIDDEN") == 0)
{
bHiddenIncluded = true;
}
else if (_wcsicmp((*sShareArg).c_str(), L"ADMINONLY") == 0)
{
bAdminOnly = true;
}
if (_wcsicmp((*sShareArg).c_str(), L"STOPONERROR") == 0)
else if (_wcsicmp((*sShareArg).c_str(), L"STOPONERROR") == 0)
{
bStopOnErrors = true;
}
else
{
wprintf(L"ERROR: Unrecognized parameter '%s' for command '%s'\n", sSubArgs[1].c_str(), sSubArgs[0].c_str());
wprintf(L"ERROR: Unrecognized share lookup option '%s'\n", (*sShareArg).c_str());
exit(-1);
}
}
Expand Down Expand Up @@ -94,6 +122,12 @@ OperationSharePaths::OperationSharePaths(std::queue<std::wstring> & oArgList) :
// convert to uppercase
std::transform(sLocalPath.begin(), sLocalPath.end(), sLocalPath.begin(), ::toupper);

// see if the share name matches the regular expression
if (!std::regex_match(tInfo[iEntry].shi2_netname, oMatchRegex)) continue;

// see if the share name does not match the regular expression
if (std::regex_match(tInfo[iEntry].shi2_netname, oNoMatchRegex)) continue;

// add path to the share list
mPaths[tInfo[iEntry].shi2_netname] = sLocalPath;
}
Expand Down
2 changes: 1 addition & 1 deletion Version.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#pragma once

#define VERSION_STRING "1.6.0.0"
#define VERSION_STRING "1.6.2.0"

0 comments on commit dc2f770

Please sign in to comment.