aboutsummaryrefslogtreecommitdiff
path: root/src/winterop
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2017-09-03 16:51:39 -0700
committerRob Mensching <rob@firegiant.com>2017-09-07 23:21:11 -0700
commit088dc648a3478e2cacdbdab1cb1782556642ee69 (patch)
tree70535a2e14113ebe639040fa908599322511dfc6 /src/winterop
parent2a72f06449431b326c671cf59811b9cefb73a2c8 (diff)
downloadwix-088dc648a3478e2cacdbdab1cb1782556642ee69.tar.gz
wix-088dc648a3478e2cacdbdab1cb1782556642ee69.tar.bz2
wix-088dc648a3478e2cacdbdab1cb1782556642ee69.zip
Initial commit
Diffstat (limited to 'src/winterop')
-rw-r--r--src/winterop/packages.config5
-rw-r--r--src/winterop/precomp.h12
-rw-r--r--src/winterop/runtime.win-xxx.WixToolset.Core.Native.nuspec19
-rw-r--r--src/winterop/winterop.cpp216
-rw-r--r--src/winterop/winterop.def18
-rw-r--r--src/winterop/winterop.vcxproj79
6 files changed, 349 insertions, 0 deletions
diff --git a/src/winterop/packages.config b/src/winterop/packages.config
new file mode 100644
index 00000000..b11fe210
--- /dev/null
+++ b/src/winterop/packages.config
@@ -0,0 +1,5 @@
1<?xml version="1.0" encoding="utf-8"?>
2<packages>
3 <package id="Nerdbank.GitVersioning" version="2.0.37-beta" targetFramework="native" developmentDependency="true" />
4 <package id="WixToolset.DUtil" version="4.0.3" targetFramework="native" />
5</packages> \ No newline at end of file
diff --git a/src/winterop/precomp.h b/src/winterop/precomp.h
new file mode 100644
index 00000000..eba996c7
--- /dev/null
+++ b/src/winterop/precomp.h
@@ -0,0 +1,12 @@
1#pragma once
2// 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.
3
4#include <windows.h>
5#include <aclapi.h>
6
7#include "dutil.h"
8#include "fileutil.h"
9#include "memutil.h"
10#include "strutil.h"
11#include "cabcutil.h"
12#include "cabutil.h"
diff --git a/src/winterop/runtime.win-xxx.WixToolset.Core.Native.nuspec b/src/winterop/runtime.win-xxx.WixToolset.Core.Native.nuspec
new file mode 100644
index 00000000..87cf0919
--- /dev/null
+++ b/src/winterop/runtime.win-xxx.WixToolset.Core.Native.nuspec
@@ -0,0 +1,19 @@
1<?xml version="1.0"?>
2<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
3 <metadata minClientVersion="4.0">
4 <id>$id$</id>
5 <version>$version$</version>
6 <authors>$authors$</authors>
7 <owners>$authors$</owners>
8 <licenseUrl>https://github.com/wixtoolset/Core.Native/blob/master/LICENSE.TXT</licenseUrl>
9 <projectUrl>https://github.com/wixtoolset/Core.Native</projectUrl>
10 <requireLicenseAcceptance>false</requireLicenseAcceptance>
11 <description>$description$</description>
12 <copyright>$copyright$</copyright>
13 </metadata>
14
15 <files>
16 <file src="winterop.dll" target="runtimes\win-$platform$\native" />
17 <file src="winterop.pdb" target="runtimes\win-$platform$\native" />
18 </files>
19</package>
diff --git a/src/winterop/winterop.cpp b/src/winterop/winterop.cpp
new file mode 100644
index 00000000..12d8ca3f
--- /dev/null
+++ b/src/winterop/winterop.cpp
@@ -0,0 +1,216 @@
1// 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.
2
3#include "precomp.h"
4
5
6HRESULT HashPublicKeyInfo(
7 __in PCERT_CONTEXT pCertContext,
8 __in_ecount(*pcbSubjectKeyIndentifier) BYTE* rgbSubjectKeyIdentifier,
9 __inout DWORD* pcbSubjectKeyIndentifier
10 )
11{
12 HRESULT hr = S_OK;
13
14 if (!::CryptHashPublicKeyInfo(NULL, CALG_SHA1, 0, X509_ASN_ENCODING, &pCertContext->pCertInfo->SubjectPublicKeyInfo, rgbSubjectKeyIdentifier, pcbSubjectKeyIndentifier))
15 {
16 ExitWithLastError(hr, "Failed to hash public key information.");
17 }
18
19LExit:
20 return hr;
21}
22
23HRESULT ResetAcls(
24 __in LPCWSTR pwzFiles[],
25 __in DWORD cFiles
26 )
27{
28 HRESULT hr = S_OK;
29 ACL* pacl = NULL;
30 DWORD cbAcl = sizeof(ACL);
31
32 OSVERSIONINFO osvi;
33
34 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
35 if (!::GetVersionExA(&osvi))
36 {
37 ExitOnLastError(hr, "failed to get OS version");
38 }
39
40 // If we're running on NT 4 or earlier, or ME or earlier, don't reset ACLs.
41 if (4 >= osvi.dwMajorVersion)
42 {
43 ExitFunction1(hr = S_FALSE);
44 }
45
46 // create an empty (not NULL!) ACL to use on all the files
47 pacl = static_cast<ACL*>(MemAlloc(cbAcl, FALSE));
48 ExitOnNull(pacl, hr, E_OUTOFMEMORY, "failed to allocate ACL");
49
50#pragma prefast(push)
51#pragma prefast(disable:25029)
52 if (!::InitializeAcl(pacl, cbAcl, ACL_REVISION))
53#pragma prefast(op)
54 {
55 ExitOnLastError(hr, "failed to initialize ACL");
56 }
57
58 // reset the existing security permissions on each file
59 for (DWORD i = 0; i < cFiles; ++i)
60 {
61 hr = ::SetNamedSecurityInfoW(const_cast<LPWSTR>(pwzFiles[i]), SE_FILE_OBJECT, DACL_SECURITY_INFORMATION | UNPROTECTED_DACL_SECURITY_INFORMATION, NULL, NULL, pacl, NULL);
62 if (ERROR_FILE_NOT_FOUND != hr && ERROR_PATH_NOT_FOUND != hr)
63 {
64 ExitOnFailure(hr = HRESULT_FROM_WIN32(hr), "failed to set security descriptor for file: %S", pwzFiles[i]);
65 }
66 }
67
68 // Setting to S_OK because we could end with ERROR_FILE_NOT_FOUND or ERROR_PATH_NOT_FOUND as valid return values.
69 hr = S_OK;
70
71 AssertSz(::IsValidAcl(pacl), "ResetAcls() - created invalid ACL");
72
73LExit:
74 if (pacl)
75 {
76 MemFree(pacl);
77 }
78
79 return hr;
80}
81
82
83HRESULT CreateCabBegin(
84 __in LPCWSTR wzCab,
85 __in LPCWSTR wzCabDir,
86 __in DWORD dwMaxFiles,
87 __in DWORD dwMaxSize,
88 __in DWORD dwMaxThresh,
89 __in COMPRESSION_TYPE ct,
90 __out HANDLE *phContext
91 )
92{
93 return CabCBegin(wzCab, wzCabDir, dwMaxFiles, dwMaxSize, dwMaxThresh, ct, phContext);
94}
95
96
97HRESULT CreateCabAddFile(
98 __in LPCWSTR wzFile,
99 __in_opt LPCWSTR wzToken,
100 __in_opt PMSIFILEHASHINFO pmfHash,
101 __in HANDLE hContext
102 )
103{
104 return CabCAddFile(wzFile, wzToken, pmfHash, hContext);
105}
106
107
108HRESULT CreateCabAddFiles(
109 __in LPCWSTR pwzFiles[],
110 __in LPCWSTR pwzTokens[],
111 __in PMSIFILEHASHINFO pmfHash[],
112 __in DWORD cFiles,
113 __in HANDLE hContext
114 )
115{
116 HRESULT hr = S_OK;
117 DWORD i;
118
119 Assert(pwzFiles);
120 Assert(hContext);
121
122 for (i = 0; i < cFiles; i++)
123 {
124 hr = CreateCabAddFile(
125 pwzFiles[i],
126 pwzTokens ? pwzTokens[i] : NULL,
127 pmfHash[i],
128 hContext
129 );
130 ExitOnFailure(hr, "Failed to add file %S to cab", pwzFiles[i]);
131 }
132
133LExit:
134 return hr;
135}
136
137
138HRESULT CreateCabFinish(
139 __in HANDLE hContext,
140 __in_opt FileSplitCabNamesCallback newCabNamesCallBackAddress
141 )
142{
143 // Convert address into Binder callback function
144 return CabCFinish(hContext, newCabNamesCallBackAddress);
145}
146
147
148void CreateCabCancel(
149 __in HANDLE hContext
150 )
151{
152 CabCCancel(hContext);
153}
154
155
156HRESULT ExtractCabBegin()
157{
158 return CabInitialize(FALSE);
159}
160
161
162HRESULT ExtractCab(
163 __in LPCWSTR wzCabinet,
164 __in LPCWSTR wzExtractDir
165 )
166{
167 return CabExtract(wzCabinet, L"*", wzExtractDir, NULL, NULL, 0);
168}
169
170
171void ExtractCabFinish()
172{
173 CabUninitialize();
174 return;
175}
176
177
178HRESULT EnumerateCabBegin()
179{
180 return CabInitialize(FALSE);
181}
182
183
184HRESULT EnumerateCab(
185 __in LPCWSTR wzCabinet,
186 __in STDCALL_PFNFDINOTIFY pfnNotify
187 )
188{
189 return CabEnumerate(wzCabinet, L"*", pfnNotify, 0);
190}
191
192
193void EnumerateCabFinish()
194{
195 CabUninitialize();
196 return;
197}
198
199
200BOOL WINAPI DllMain(
201 __in HINSTANCE /*hInstance*/,
202 __in DWORD dwReason,
203 __in LPVOID /*lpvReserved*/
204 )
205{
206 switch(dwReason)
207 {
208 case DLL_PROCESS_ATTACH:
209 case DLL_PROCESS_DETACH:
210 case DLL_THREAD_ATTACH:
211 case DLL_THREAD_DETACH:
212 break;
213 }
214
215 return TRUE;
216}
diff --git a/src/winterop/winterop.def b/src/winterop/winterop.def
new file mode 100644
index 00000000..dffa6268
--- /dev/null
+++ b/src/winterop/winterop.def
@@ -0,0 +1,18 @@
1; 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.
2
3LIBRARY "winterop.dll"
4
5EXPORTS
6 CreateCabBegin
7 CreateCabCancel
8 CreateCabAddFile
9 CreateCabAddFiles
10 CreateCabFinish
11 EnumerateCabBegin
12 EnumerateCab
13 EnumerateCabFinish
14 ExtractCabBegin
15 ExtractCab
16 ExtractCabFinish
17 ResetAcls
18 HashPublicKeyInfo
diff --git a/src/winterop/winterop.vcxproj b/src/winterop/winterop.vcxproj
new file mode 100644
index 00000000..6274a063
--- /dev/null
+++ b/src/winterop/winterop.vcxproj
@@ -0,0 +1,79 @@
1<?xml version="1.0" encoding="utf-8"?>
2<!-- 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. -->
3
4<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
5 <Import Project="..\..\packages\WixToolset.DUtil.4.0.3\build\WixToolset.DUtil.props" Condition="Exists('..\..\packages\WixToolset.DUtil.4.0.3\build\WixToolset.DUtil.props')" />
6
7 <ItemGroup Label="ProjectConfigurations">
8 <ProjectConfiguration Include="Debug|Win32">
9 <Configuration>Debug</Configuration>
10 <Platform>Win32</Platform>
11 </ProjectConfiguration>
12 <ProjectConfiguration Include="Release|Win32">
13 <Configuration>Release</Configuration>
14 <Platform>Win32</Platform>
15 </ProjectConfiguration>
16 <ProjectConfiguration Include="Debug|x64">
17 <Configuration>Debug</Configuration>
18 <Platform>x64</Platform>
19 </ProjectConfiguration>
20 <ProjectConfiguration Include="Release|x64">
21 <Configuration>Release</Configuration>
22 <Platform>x64</Platform>
23 </ProjectConfiguration>
24 </ItemGroup>
25
26 <PropertyGroup Label="Globals">
27 <ProjectGuid>{26D45E58-E703-431D-B67E-493C72C9DA0B}</ProjectGuid>
28 <ConfigurationType>DynamicLibrary</ConfigurationType>
29 <TargetName>winterop</TargetName>
30 <PlatformToolset>v141</PlatformToolset>
31 <CharacterSet>MultiByte</CharacterSet>
32 <ProjectModuleDefinitionFile>winterop.def</ProjectModuleDefinitionFile>
33 <Description>Native component of WixToolset.Core</Description>
34 </PropertyGroup>
35
36 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
37 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
38
39 <ImportGroup Label="ExtensionSettings">
40 </ImportGroup>
41
42 <ImportGroup Label="Shared">
43 </ImportGroup>
44
45 <PropertyGroup>
46 <ProjectAdditionalLinkLibraries>crypt32.lib;cabinet.lib;msi.lib</ProjectAdditionalLinkLibraries>
47 </PropertyGroup>
48
49 <ItemGroup>
50 <ClCompile Include="winterop.cpp">
51 <!-- turn off deprecation warning -->
52 <DisableSpecificWarnings>4996</DisableSpecificWarnings>
53 <PrecompiledHeader>Create</PrecompiledHeader>
54 </ClCompile>
55 </ItemGroup>
56
57 <ItemGroup>
58 <ClInclude Include="precomp.h" />
59 </ItemGroup>
60
61 <ItemGroup>
62 <None Include="packages.config" />
63 <None Include="winterop.def" />
64 </ItemGroup>
65
66 <Target Name="PackNativeNuget" DependsOnTargets="Build">
67 <Exec Command="nuget pack runtime.win-xxx.WixToolset.Core.Native.nuspec -BasePath &quot;$(OutputPath)\&quot; -OutputDirectory &quot;$(BaseOutputPath)\&quot; -NoPackageAnalysis -Properties Configuration=$(Configuration);Id=runtime.win-$(PlatformTarget).WixToolset.Core.Native;Version=&quot;$(BuildVersionSimple)&quot;;Platform=$(PlatformTarget);Authors=&quot;$(Authors)&quot;;Copyright=&quot;$(Copyright)&quot;;Description=&quot;$(Description)&quot;;Title=&quot;$(Title)&quot;" />
68 </Target>
69
70 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
71 <Import Project="..\..\packages\Nerdbank.GitVersioning.2.0.37-beta\build\Nerdbank.GitVersioning.targets" Condition="Exists('..\..\packages\Nerdbank.GitVersioning.2.0.37-beta\build\Nerdbank.GitVersioning.targets')" />
72 <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
73 <PropertyGroup>
74 <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>
75 </PropertyGroup>
76 <Error Condition="!Exists('..\..\packages\WixToolset.DUtil.4.0.3\build\WixToolset.DUtil.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\WixToolset.DUtil.4.0.3\build\WixToolset.DUtil.props'))" />
77 <Error Condition="!Exists('..\..\packages\Nerdbank.GitVersioning.2.0.37-beta\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Nerdbank.GitVersioning.2.0.37-beta\build\Nerdbank.GitVersioning.targets'))" />
78 </Target>
79</Project>