summaryrefslogtreecommitdiffstats
path: root/Source/CPack
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2014-08-11 13:54:19 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2014-08-11 13:54:19 (GMT)
commit401d82b3db7253d29e51ecc7c7cdbaee70a38166 (patch)
tree42eb35223cc7d810523b8c5882c78b846e6c194f /Source/CPack
parent8b61070748ce7de7c7ad3a21b9fa6b3bc5281e4f (diff)
parent975dc87174294d59f60ffa0e52608f8fbf429737 (diff)
downloadCMake-401d82b3db7253d29e51ecc7c7cdbaee70a38166.zip
CMake-401d82b3db7253d29e51ecc7c7cdbaee70a38166.tar.gz
CMake-401d82b3db7253d29e51ecc7c7cdbaee70a38166.tar.bz2
Merge topic 'wix-acl'
975dc871 Help: Add notes for topic 'wix-acl' 12418f5c CPackWIX: Implement CPACK_WIX_ACL (Access Control List) property
Diffstat (limited to 'Source/CPack')
-rw-r--r--Source/CPack/WiX/cmWIXAccessControlList.cxx149
-rw-r--r--Source/CPack/WiX/cmWIXAccessControlList.h46
-rw-r--r--Source/CPack/WiX/cmWIXFilesSourceWriter.cxx7
-rw-r--r--Source/CPack/WiX/cmWIXSourceWriter.h5
4 files changed, 205 insertions, 2 deletions
diff --git a/Source/CPack/WiX/cmWIXAccessControlList.cxx b/Source/CPack/WiX/cmWIXAccessControlList.cxx
new file mode 100644
index 0000000..aeec968
--- /dev/null
+++ b/Source/CPack/WiX/cmWIXAccessControlList.cxx
@@ -0,0 +1,149 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2014 Kitware, Inc.
+
+ Distributed under the OSI-approved BSD License (the "License");
+ see accompanying file Copyright.txt for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even the
+ implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the License for more information.
+============================================================================*/
+
+#include "cmWIXAccessControlList.h"
+
+#include <CPack/cmCPackGenerator.h>
+
+#include <cmSystemTools.h>
+
+cmWIXAccessControlList::cmWIXAccessControlList(
+ cmCPackLog *logger,
+ cmInstalledFile const& installedFile,
+ cmWIXSourceWriter &sourceWriter):
+ Logger(logger),
+ InstalledFile(installedFile),
+ SourceWriter(sourceWriter)
+{
+
+}
+
+bool cmWIXAccessControlList::Apply()
+{
+ std::vector<std::string> entries;
+ this->InstalledFile.GetPropertyAsList("CPACK_WIX_ACL", entries);
+
+ for(size_t i = 0; i < entries.size(); ++i)
+ {
+ this->CreatePermissionElement(entries[i]);
+ }
+
+ return true;
+}
+
+void cmWIXAccessControlList::CreatePermissionElement(
+ std::string const& entry)
+{
+ std::string::size_type pos = entry.find('=');
+ if(pos == std::string::npos)
+ {
+ this->ReportError(entry, "Did not find mandatory '='");
+ return;
+ }
+
+ 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;
+ if(pos != std::string::npos)
+ {
+ user = user_and_domain.substr(0, pos);
+ domain = user_and_domain.substr(pos + 1);
+ }
+ else
+ {
+ user = user_and_domain;
+ }
+
+ std::vector<std::string> permissions =
+ cmSystemTools::tokenize(permission_string, ",");
+
+ this->SourceWriter.BeginElement("Permission");
+ this->SourceWriter.AddAttribute("User", user);
+ if(domain.size())
+ {
+ this->SourceWriter.AddAttribute("Domain", domain);
+ }
+ for(size_t i = 0; i < permissions.size(); ++i)
+ {
+ this->EmitBooleanAttribute(entry,
+ cmSystemTools::TrimWhitespace(permissions[i]));
+ }
+ this->SourceWriter.EndElement("Permission");
+}
+
+void cmWIXAccessControlList::ReportError(
+ std::string const& entry,
+ std::string const& message)
+{
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Failed processing ACL entry '" << entry <<
+ "': " << message << std::endl);
+}
+
+bool cmWIXAccessControlList::IsBooleanAttribute(std::string const& name)
+{
+ static const char* validAttributes[] =
+ {
+ "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;
+ while(validAttributes[i])
+ {
+ if(name == validAttributes[i++]) return true;
+ }
+
+ return false;
+}
+
+void cmWIXAccessControlList::EmitBooleanAttribute(
+ std::string const& entry, std::string const& name)
+{
+ if(!this->IsBooleanAttribute(name))
+ {
+ std::stringstream message;
+ message << "Unknown boolean attribute '" << name << "'";
+ this->ReportError(entry, message.str());
+ }
+
+ this->SourceWriter.AddAttribute(name, "yes");
+}
diff --git a/Source/CPack/WiX/cmWIXAccessControlList.h b/Source/CPack/WiX/cmWIXAccessControlList.h
new file mode 100644
index 0000000..20902f7
--- /dev/null
+++ b/Source/CPack/WiX/cmWIXAccessControlList.h
@@ -0,0 +1,46 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2014 Kitware, Inc.
+
+ Distributed under the OSI-approved BSD License (the "License");
+ see accompanying file Copyright.txt for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even the
+ implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the License for more information.
+============================================================================*/
+
+#ifndef cmWIXAccessControlList_h
+#define cmWIXAccessControlList_h
+
+#include <cmInstalledFile.h>
+#include <CPack/cmCPackLog.h>
+
+#include "cmWIXSourceWriter.h"
+
+class cmWIXAccessControlList
+{
+public:
+ cmWIXAccessControlList(
+ cmCPackLog *logger,
+ cmInstalledFile const& installedFile,
+ cmWIXSourceWriter &sourceWriter);
+
+ bool Apply();
+
+private:
+ void CreatePermissionElement(std::string const& entry);
+
+ void ReportError(std::string const& entry, std::string const& message);
+
+ bool IsBooleanAttribute(std::string const& name);
+
+ void EmitBooleanAttribute(
+ std::string const& entry, std::string const& name);
+
+ cmCPackLog* Logger;
+ cmInstalledFile const& InstalledFile;
+ cmWIXSourceWriter &SourceWriter;
+};
+
+#endif
diff --git a/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx b/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx
index 451188e..0ad5d0c 100644
--- a/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx
+++ b/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx
@@ -11,6 +11,7 @@
============================================================================*/
#include "cmWIXFilesSourceWriter.h"
+#include "cmWIXAccessControlList.h"
#include <cmInstalledFile.h>
@@ -175,6 +176,12 @@ std::string cmWIXFilesSourceWriter::EmitComponentFile(
AddAttribute("ReadOnly", "yes");
}
+ if(installedFile)
+ {
+ cmWIXAccessControlList acl(Logger, *installedFile, *this);
+ acl.Apply();
+ }
+
patch.ApplyFragment(fileId, *this);
EndElement("File");
diff --git a/Source/CPack/WiX/cmWIXSourceWriter.h b/Source/CPack/WiX/cmWIXSourceWriter.h
index 65b7240..3957d96 100644
--- a/Source/CPack/WiX/cmWIXSourceWriter.h
+++ b/Source/CPack/WiX/cmWIXSourceWriter.h
@@ -45,6 +45,9 @@ public:
static std::string WindowsCodepageToUtf8(std::string const& value);
+protected:
+ cmCPackLog* Logger;
+
private:
enum State
{
@@ -58,8 +61,6 @@ private:
static std::string EscapeAttributeValue(std::string const& value);
- cmCPackLog* Logger;
-
cmsys::ofstream File;
State State;