2016-09-27 22:01:08 +03:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2014-08-09 16:50:49 +04:00
|
|
|
#include "cmWIXAccessControlList.h"
|
|
|
|
|
|
|
|
#include <CPack/cmCPackGenerator.h>
|
|
|
|
|
|
|
|
#include <cmSystemTools.h>
|
|
|
|
|
|
|
|
cmWIXAccessControlList::cmWIXAccessControlList(
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCPackLog* logger, cmInstalledFile const& installedFile,
|
|
|
|
cmWIXSourceWriter& sourceWriter)
|
|
|
|
: Logger(logger)
|
|
|
|
, InstalledFile(installedFile)
|
|
|
|
, SourceWriter(sourceWriter)
|
2014-08-09 16:50:49 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmWIXAccessControlList::Apply()
|
|
|
|
{
|
|
|
|
std::vector<std::string> entries;
|
|
|
|
this->InstalledFile.GetPropertyAsList("CPACK_WIX_ACL", entries);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (size_t i = 0; i < entries.size(); ++i) {
|
2014-08-09 16:50:49 +04:00
|
|
|
this->CreatePermissionElement(entries[i]);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-08-09 16:50:49 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmWIXAccessControlList::CreatePermissionElement(std::string const& entry)
|
2014-08-09 16:50:49 +04:00
|
|
|
{
|
|
|
|
std::string::size_type pos = entry.find('=');
|
2016-05-16 17:34:04 +03:00
|
|
|
if (pos == std::string::npos) {
|
2014-08-09 16:50:49 +04:00
|
|
|
this->ReportError(entry, "Did not find mandatory '='");
|
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-08-09 16:50:49 +04:00
|
|
|
|
|
|
|
std::string user_and_domain = entry.substr(0, pos);
|
|
|
|
std::string permission_string = entry.substr(pos + 1);
|
|
|
|
|
|
|
|
pos = user_and_domain.find('@');
|
|
|
|
std::string user;
|
|
|
|
std::string domain;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (pos != std::string::npos) {
|
2014-08-09 16:50:49 +04:00
|
|
|
user = user_and_domain.substr(0, pos);
|
|
|
|
domain = user_and_domain.substr(pos + 1);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2014-08-09 16:50:49 +04:00
|
|
|
user = user_and_domain;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-08-09 16:50:49 +04:00
|
|
|
|
|
|
|
std::vector<std::string> permissions =
|
|
|
|
cmSystemTools::tokenize(permission_string, ",");
|
|
|
|
|
|
|
|
this->SourceWriter.BeginElement("Permission");
|
|
|
|
this->SourceWriter.AddAttribute("User", user);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!domain.empty()) {
|
2014-08-09 16:50:49 +04:00
|
|
|
this->SourceWriter.AddAttribute("Domain", domain);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
for (size_t i = 0; i < permissions.size(); ++i) {
|
2014-08-09 16:50:49 +04:00
|
|
|
this->EmitBooleanAttribute(entry,
|
2016-05-16 17:34:04 +03:00
|
|
|
cmSystemTools::TrimWhitespace(permissions[i]));
|
|
|
|
}
|
2014-08-09 16:50:49 +04:00
|
|
|
this->SourceWriter.EndElement("Permission");
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmWIXAccessControlList::ReportError(std::string const& entry,
|
|
|
|
std::string const& message)
|
2014-08-09 16:50:49 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR, "Failed processing ACL entry '"
|
|
|
|
<< entry << "': " << message << std::endl);
|
2014-08-09 16:50:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cmWIXAccessControlList::IsBooleanAttribute(std::string const& name)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
static const char* validAttributes[] = {
|
2016-05-06 22:21:30 +03:00
|
|
|
/* clang-format needs this comment to break after the opening brace */
|
2014-08-09 16:50:49 +04:00
|
|
|
"Append",
|
|
|
|
"ChangePermission",
|
|
|
|
"CreateChild",
|
|
|
|
"CreateFile",
|
|
|
|
"CreateLink",
|
|
|
|
"CreateSubkeys",
|
|
|
|
"Delete",
|
|
|
|
"DeleteChild",
|
|
|
|
"EnumerateSubkeys",
|
|
|
|
"Execute",
|
|
|
|
"FileAllRights",
|
|
|
|
"GenericAll",
|
|
|
|
"GenericExecute",
|
|
|
|
"GenericRead",
|
|
|
|
"GenericWrite",
|
|
|
|
"Notify",
|
|
|
|
"Read",
|
|
|
|
"ReadAttributes",
|
|
|
|
"ReadExtendedAttributes",
|
|
|
|
"ReadPermission",
|
|
|
|
"SpecificRightsAll",
|
|
|
|
"Synchronize",
|
|
|
|
"TakeOwnership",
|
|
|
|
"Traverse",
|
|
|
|
"Write",
|
|
|
|
"WriteAttributes",
|
|
|
|
"WriteExtendedAttributes",
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t i = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (validAttributes[i]) {
|
|
|
|
if (name == validAttributes[i++])
|
|
|
|
return true;
|
|
|
|
}
|
2014-08-09 16:50:49 +04:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmWIXAccessControlList::EmitBooleanAttribute(std::string const& entry,
|
|
|
|
std::string const& name)
|
2014-08-09 16:50:49 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->IsBooleanAttribute(name)) {
|
2016-06-14 23:37:36 +03:00
|
|
|
std::ostringstream message;
|
2014-08-09 16:50:49 +04:00
|
|
|
message << "Unknown boolean attribute '" << name << "'";
|
|
|
|
this->ReportError(entry, message.str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-08-09 16:50:49 +04:00
|
|
|
|
|
|
|
this->SourceWriter.AddAttribute(name, "yes");
|
|
|
|
}
|