mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 09:46:54 +02:00
common: refactor common library pt2 (#8588)
- remove common lib - split settings, remove common-md - move ipc interop/kb_layout to interop - rename core -> settings, settings -> old_settings - os-detect header-only; interop -> PowerToysInterop - split notifications, move single-use headers where they're used - winstore lib - rename com utils - rename Updating and Telemetry projects - rename core -> settings-ui and remove examples folder - rename settings-ui folder + consisent common/version include
This commit is contained in:
85
src/common/COMUtils/COMUtils.cpp
Normal file
85
src/common/COMUtils/COMUtils.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
#include "comUtils.h"
|
||||
|
||||
#include <Windows.h>
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4067)
|
||||
#include <Sddl.h>
|
||||
#pragma warning(pop)
|
||||
|
||||
#include <memory>
|
||||
#include <wil/resource.h>
|
||||
|
||||
// Helper class for various COM-related APIs, e.g working with security descriptors
|
||||
template<typename T>
|
||||
struct typed_storage
|
||||
{
|
||||
std::unique_ptr<char[]> _buffer;
|
||||
inline explicit typed_storage(const DWORD size) :
|
||||
_buffer{ std::make_unique<char[]>(size) }
|
||||
{
|
||||
}
|
||||
|
||||
inline operator T*()
|
||||
{
|
||||
return reinterpret_cast<T*>(_buffer.get());
|
||||
}
|
||||
};
|
||||
|
||||
bool initializeCOMSecurity(const wchar_t* securityDescriptor)
|
||||
{
|
||||
PSECURITY_DESCRIPTOR self_relative_sd{};
|
||||
if (!ConvertStringSecurityDescriptorToSecurityDescriptorW(securityDescriptor, SDDL_REVISION_1, &self_relative_sd, nullptr))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
auto free_relative_sd = wil::scope_exit([&] {
|
||||
LocalFree(self_relative_sd);
|
||||
});
|
||||
|
||||
DWORD absolute_sd_size = 0;
|
||||
DWORD dacl_size = 0;
|
||||
DWORD group_size = 0;
|
||||
DWORD owner_size = 0;
|
||||
DWORD sacl_size = 0;
|
||||
|
||||
if (!MakeAbsoluteSD(self_relative_sd, nullptr, &absolute_sd_size, nullptr, &dacl_size, nullptr, &sacl_size, nullptr, &owner_size, nullptr, &group_size))
|
||||
{
|
||||
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
typed_storage<SECURITY_DESCRIPTOR> absolute_sd{ absolute_sd_size };
|
||||
typed_storage<ACL> dacl{ dacl_size };
|
||||
typed_storage<ACL> sacl{ sacl_size };
|
||||
typed_storage<SID> owner{ owner_size };
|
||||
typed_storage<SID> group{ group_size };
|
||||
|
||||
if (!MakeAbsoluteSD(self_relative_sd,
|
||||
absolute_sd,
|
||||
&absolute_sd_size,
|
||||
dacl,
|
||||
&dacl_size,
|
||||
sacl,
|
||||
&sacl_size,
|
||||
owner,
|
||||
&owner_size,
|
||||
group,
|
||||
&group_size))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return !FAILED(CoInitializeSecurity(
|
||||
absolute_sd,
|
||||
-1,
|
||||
nullptr,
|
||||
nullptr,
|
||||
RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
|
||||
RPC_C_IMP_LEVEL_IDENTIFY,
|
||||
nullptr,
|
||||
EOAC_DYNAMIC_CLOAKING | EOAC_DISABLE_AAA,
|
||||
nullptr));
|
||||
}
|
||||
3
src/common/COMUtils/COMUtils.h
Normal file
3
src/common/COMUtils/COMUtils.h
Normal file
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
bool initializeCOMSecurity(const wchar_t* securityDescriptor);
|
||||
47
src/common/COMUtils/COMUtils.vcxproj
Normal file
47
src/common/COMUtils/COMUtils.vcxproj
Normal file
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<ProjectGuid>{7319089E-46D6-4400-BC65-E39BDF1416EE}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>COMUtils</RootNamespace>
|
||||
<ProjectName>COMUtils</ProjectName>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<AdditionalIncludeDirectories>..\..\..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<TreatWarningAsError>true</TreatWarningAsError>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="comUtils.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="comUtils.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.200902.2\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.200902.2\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
|
||||
</ImportGroup>
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.200902.2\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.200902.2\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
||||
4
src/common/COMUtils/packages.config
Normal file
4
src/common/COMUtils/packages.config
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.200902.2" targetFramework="native" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user