From ea3d18595a610ee07b03f07af4f03cf75b5ab420 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 29 Nov 2017 14:08:08 -0800 Subject: Improved cabinet handling --- src/wixnative/resetacls.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/wixnative/resetacls.cpp (limited to 'src/wixnative/resetacls.cpp') diff --git a/src/wixnative/resetacls.cpp b/src/wixnative/resetacls.cpp new file mode 100644 index 00000000..8c5bdc56 --- /dev/null +++ b/src/wixnative/resetacls.cpp @@ -0,0 +1,51 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +#include "precomp.h" + +HRESULT ResetAclsCommand(int argc, LPWSTR argv[]) +{ + Unused(argc); + Unused(argv); + + HRESULT hr = S_OK; + ACL* pacl = NULL; + DWORD cbAcl = sizeof(ACL); + LPWSTR sczFilePath = NULL; + + // create an empty (not NULL!) ACL to use on all the files + pacl = static_cast(MemAlloc(cbAcl, FALSE)); + ConsoleExitOnNull(pacl, hr, E_OUTOFMEMORY, CONSOLE_COLOR_RED, "failed to allocate ACL"); + +#pragma prefast(push) +#pragma prefast(disable:25029) + if (!::InitializeAcl(pacl, cbAcl, ACL_REVISION)) +#pragma prefast(op) + { + ConsoleExitOnLastError(hr, CONSOLE_COLOR_RED, "failed to initialize ACL"); + } + + // Reset the existing security permissions on each provided file. + for (;;) + { + hr = ConsoleReadW(&sczFilePath); + ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "failed to read file path from stdin"); + + if (!*sczFilePath) + { + break; + } + + hr = ::SetNamedSecurityInfoW(sczFilePath, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION | UNPROTECTED_DACL_SECURITY_INFORMATION, NULL, NULL, pacl, NULL); + if (ERROR_FILE_NOT_FOUND != hr && ERROR_PATH_NOT_FOUND != hr) + { + ConsoleExitOnFailure(hr = HRESULT_FROM_WIN32(hr), CONSOLE_COLOR_RED, "failed to set security descriptor for file: %ls", sczFilePath); + } + } + + AssertSz(::IsValidAcl(pacl), "ResetAcls() - created invalid ACL"); + +LExit: + ReleaseStr(sczFilePath); + ReleaseMem(pacl); + return hr; +} -- cgit v1.2.3-55-g6feb