diff options
Diffstat (limited to 'src/ext/Util/be')
-rw-r--r-- | src/ext/Util/be/UtilBundleExtension.cpp | 87 | ||||
-rw-r--r-- | src/ext/Util/be/UtilBundleExtension.h | 16 | ||||
-rw-r--r-- | src/ext/Util/be/beDecor.h | 13 | ||||
-rw-r--r-- | src/ext/Util/be/detectsha2support.cpp | 58 | ||||
-rw-r--r-- | src/ext/Util/be/detectsha2support.h | 8 | ||||
-rw-r--r-- | src/ext/Util/be/precomp.cpp | 3 | ||||
-rw-r--r-- | src/ext/Util/be/precomp.h | 37 | ||||
-rw-r--r-- | src/ext/Util/be/utilbe.cpp | 41 | ||||
-rw-r--r-- | src/ext/Util/be/utilbe.def | 8 | ||||
-rw-r--r-- | src/ext/Util/be/utilbe.vcxproj | 80 | ||||
-rw-r--r-- | src/ext/Util/be/utilsearch.cpp | 160 | ||||
-rw-r--r-- | src/ext/Util/be/utilsearch.h | 65 |
12 files changed, 576 insertions, 0 deletions
diff --git a/src/ext/Util/be/UtilBundleExtension.cpp b/src/ext/Util/be/UtilBundleExtension.cpp new file mode 100644 index 00000000..2ac842a5 --- /dev/null +++ b/src/ext/Util/be/UtilBundleExtension.cpp | |||
@@ -0,0 +1,87 @@ | |||
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 | #include "BextBaseBundleExtension.h" | ||
5 | |||
6 | class CWixUtilBundleExtension : public CBextBaseBundleExtension | ||
7 | { | ||
8 | public: // IBundleExtension | ||
9 | virtual STDMETHODIMP Search( | ||
10 | __in LPCWSTR wzId, | ||
11 | __in LPCWSTR wzVariable | ||
12 | ) | ||
13 | { | ||
14 | HRESULT hr = S_OK; | ||
15 | |||
16 | hr = UtilSearchExecute(&m_searches, wzId, wzVariable, m_pEngine); | ||
17 | |||
18 | return hr; | ||
19 | } | ||
20 | |||
21 | public: //CBextBaseBundleExtension | ||
22 | virtual STDMETHODIMP Initialize( | ||
23 | __in const BUNDLE_EXTENSION_CREATE_ARGS* pCreateArgs | ||
24 | ) | ||
25 | { | ||
26 | HRESULT hr = S_OK; | ||
27 | IXMLDOMDocument* pixdManifest = NULL; | ||
28 | IXMLDOMNode* pixnBundleExtension = NULL; | ||
29 | |||
30 | hr = CBextBaseBundleExtension::Initialize(pCreateArgs); | ||
31 | ExitOnFailure(hr, "CBextBaseBundleExtension initialization failed."); | ||
32 | |||
33 | hr = XmlLoadDocumentFromFile(m_sczBundleExtensionDataPath, &pixdManifest); | ||
34 | ExitOnFailure(hr, "Failed to load bundle extension manifest from path: %ls", m_sczBundleExtensionDataPath); | ||
35 | |||
36 | hr = BextGetBundleExtensionDataNode(pixdManifest, UTIL_BUNDLE_EXTENSION_ID, &pixnBundleExtension); | ||
37 | ExitOnFailure(hr, "Failed to get BundleExtension '%ls'", UTIL_BUNDLE_EXTENSION_ID); | ||
38 | |||
39 | hr = UtilSearchParseFromXml(&m_searches, pixnBundleExtension); | ||
40 | ExitOnFailure(hr, "Failed to parse searches from bundle extension manifest."); | ||
41 | |||
42 | LExit: | ||
43 | ReleaseObject(pixnBundleExtension); | ||
44 | ReleaseObject(pixdManifest); | ||
45 | |||
46 | return hr; | ||
47 | } | ||
48 | |||
49 | public: | ||
50 | CWixUtilBundleExtension( | ||
51 | __in IBundleExtensionEngine* pEngine | ||
52 | ) : CBextBaseBundleExtension(pEngine) | ||
53 | { | ||
54 | m_searches = { }; | ||
55 | } | ||
56 | |||
57 | ~CWixUtilBundleExtension() | ||
58 | { | ||
59 | UtilSearchUninitialize(&m_searches); | ||
60 | } | ||
61 | |||
62 | private: | ||
63 | UTIL_SEARCHES m_searches; | ||
64 | }; | ||
65 | |||
66 | HRESULT UtilBundleExtensionCreate( | ||
67 | __in IBundleExtensionEngine* pEngine, | ||
68 | __in const BUNDLE_EXTENSION_CREATE_ARGS* pArgs, | ||
69 | __out IBundleExtension** ppBundleExtension | ||
70 | ) | ||
71 | { | ||
72 | HRESULT hr = S_OK; | ||
73 | CWixUtilBundleExtension* pExtension = NULL; | ||
74 | |||
75 | pExtension = new CWixUtilBundleExtension(pEngine); | ||
76 | ExitOnNull(pExtension, hr, E_OUTOFMEMORY, "Failed to create new CWixUtilBundleExtension."); | ||
77 | |||
78 | hr = pExtension->Initialize(pArgs); | ||
79 | ExitOnFailure(hr, "CWixUtilBundleExtension initialization failed"); | ||
80 | |||
81 | *ppBundleExtension = pExtension; | ||
82 | pExtension = NULL; | ||
83 | |||
84 | LExit: | ||
85 | ReleaseObject(pExtension); | ||
86 | return hr; | ||
87 | } | ||
diff --git a/src/ext/Util/be/UtilBundleExtension.h b/src/ext/Util/be/UtilBundleExtension.h new file mode 100644 index 00000000..c55d6b85 --- /dev/null +++ b/src/ext/Util/be/UtilBundleExtension.h | |||
@@ -0,0 +1,16 @@ | |||
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 | |||
5 | // constants | ||
6 | |||
7 | #define UTIL_BUNDLE_EXTENSION_ID BUNDLE_EXTENSION_DECORATION(L"UtilBundleExtension") | ||
8 | |||
9 | |||
10 | // function declarations | ||
11 | |||
12 | HRESULT UtilBundleExtensionCreate( | ||
13 | __in IBundleExtensionEngine* pEngine, | ||
14 | __in const BUNDLE_EXTENSION_CREATE_ARGS* pArgs, | ||
15 | __out IBundleExtension** ppBundleExtension | ||
16 | ); | ||
diff --git a/src/ext/Util/be/beDecor.h b/src/ext/Util/be/beDecor.h new file mode 100644 index 00000000..2c6a8818 --- /dev/null +++ b/src/ext/Util/be/beDecor.h | |||
@@ -0,0 +1,13 @@ | |||
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 | |||
5 | #if defined(_M_ARM64) | ||
6 | #define BUNDLE_EXTENSION_DECORATION(f) L"Wix4" f L"_A64" | ||
7 | #elif defined(_M_AMD64) | ||
8 | #define BUNDLE_EXTENSION_DECORATION(f) L"Wix4" f L"_X64" | ||
9 | #elif defined(_M_ARM) | ||
10 | #define BUNDLE_EXTENSION_DECORATION(f) L"Wix4" f L"_ARM" | ||
11 | #else | ||
12 | #define BUNDLE_EXTENSION_DECORATION(f) L"Wix4" f L"_X86" | ||
13 | #endif | ||
diff --git a/src/ext/Util/be/detectsha2support.cpp b/src/ext/Util/be/detectsha2support.cpp new file mode 100644 index 00000000..90e349cd --- /dev/null +++ b/src/ext/Util/be/detectsha2support.cpp | |||
@@ -0,0 +1,58 @@ | |||
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 | // https://gist.github.com/navossoc/7572c7d82243e9f818989e2765e7793a | ||
6 | HRESULT DetectSHA2CodeSigning( | ||
7 | __out BOOL* pfSupported | ||
8 | ) | ||
9 | { | ||
10 | HRESULT hr = S_OK; | ||
11 | HMODULE hModule = NULL; | ||
12 | FARPROC pfn = NULL; | ||
13 | DWORD er = ERROR_SUCCESS; | ||
14 | |||
15 | hr = LoadSystemLibrary(L"wintrust.dll", &hModule); | ||
16 | ExitOnFailure(hr, "Failed to load wintrust.dll"); | ||
17 | |||
18 | pfn = ::GetProcAddress(hModule, "CryptCATAdminAcquireContext2"); | ||
19 | if (pfn) | ||
20 | { | ||
21 | *pfSupported = TRUE; | ||
22 | ExitFunction1(hr = S_OK); | ||
23 | } | ||
24 | |||
25 | er = ::GetLastError(); | ||
26 | if (er == ERROR_PROC_NOT_FOUND) | ||
27 | { | ||
28 | *pfSupported = FALSE; | ||
29 | ExitFunction1(hr = S_OK); | ||
30 | } | ||
31 | |||
32 | hr = HRESULT_FROM_WIN32(er); | ||
33 | ExitOnFailure(hr, "Failed to probe for CryptCATAdminAcquireContext2 in wintrust.dll"); | ||
34 | |||
35 | LExit: | ||
36 | ::FreeLibrary(hModule); | ||
37 | |||
38 | return hr; | ||
39 | } | ||
40 | |||
41 | HRESULT UtilPerformDetectSHA2CodeSigning( | ||
42 | __in LPCWSTR wzVariable, | ||
43 | __in UTIL_SEARCH* /*pSearch*/, | ||
44 | __in IBundleExtensionEngine* pEngine | ||
45 | ) | ||
46 | { | ||
47 | HRESULT hr = S_OK; | ||
48 | BOOL fSupported = FALSE; | ||
49 | |||
50 | hr = DetectSHA2CodeSigning(&fSupported); | ||
51 | ExitOnFailure(hr, "DetectSHA2CodeSigning failed."); | ||
52 | |||
53 | hr = pEngine->SetVariableNumeric(wzVariable, fSupported ? 1 : 0); | ||
54 | ExitOnFailure(hr, "Failed to set variable '%ls'", wzVariable); | ||
55 | |||
56 | LExit: | ||
57 | return hr; | ||
58 | } | ||
diff --git a/src/ext/Util/be/detectsha2support.h b/src/ext/Util/be/detectsha2support.h new file mode 100644 index 00000000..c38a3d59 --- /dev/null +++ b/src/ext/Util/be/detectsha2support.h | |||
@@ -0,0 +1,8 @@ | |||
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 | HRESULT UtilPerformDetectSHA2CodeSigning( | ||
5 | __in LPCWSTR wzVariable, | ||
6 | __in UTIL_SEARCH* pSearch, | ||
7 | __in IBundleExtensionEngine* pEngine | ||
8 | ); \ No newline at end of file | ||
diff --git a/src/ext/Util/be/precomp.cpp b/src/ext/Util/be/precomp.cpp new file mode 100644 index 00000000..37664a1c --- /dev/null +++ b/src/ext/Util/be/precomp.cpp | |||
@@ -0,0 +1,3 @@ | |||
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" | ||
diff --git a/src/ext/Util/be/precomp.h b/src/ext/Util/be/precomp.h new file mode 100644 index 00000000..76d24c7b --- /dev/null +++ b/src/ext/Util/be/precomp.h | |||
@@ -0,0 +1,37 @@ | |||
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 | |||
5 | #if _WIN32_MSI < 150 | ||
6 | #define _WIN32_MSI 150 | ||
7 | #endif | ||
8 | |||
9 | #include <windows.h> | ||
10 | #include <msiquery.h> | ||
11 | #include <msidefs.h> | ||
12 | #include <stierr.h> | ||
13 | |||
14 | #include <strsafe.h> | ||
15 | |||
16 | #include <msxml2.h> | ||
17 | |||
18 | #define MAXUINT USHRT_MAX | ||
19 | |||
20 | #include <dutil.h> | ||
21 | #include <memutil.h> | ||
22 | #include <strutil.h> | ||
23 | #include <pathutil.h> | ||
24 | #include <xmlutil.h> | ||
25 | |||
26 | #include <BundleExtensionEngine.h> | ||
27 | #include <BundleExtension.h> | ||
28 | |||
29 | #include <IBundleExtensionEngine.h> | ||
30 | #include <IBundleExtension.h> | ||
31 | #include <bextutil.h> | ||
32 | #include <BextBundleExtensionEngine.h> | ||
33 | |||
34 | #include "beDecor.h" | ||
35 | #include "utilsearch.h" | ||
36 | #include "detectsha2support.h" | ||
37 | #include "UtilBundleExtension.h" | ||
diff --git a/src/ext/Util/be/utilbe.cpp b/src/ext/Util/be/utilbe.cpp new file mode 100644 index 00000000..d9816dc7 --- /dev/null +++ b/src/ext/Util/be/utilbe.cpp | |||
@@ -0,0 +1,41 @@ | |||
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 | #include "BextBaseBundleExtensionProc.h" | ||
5 | |||
6 | static IBundleExtension* vpBundleExtension = NULL; | ||
7 | |||
8 | // function definitions | ||
9 | |||
10 | extern "C" HRESULT WINAPI BundleExtensionCreate( | ||
11 | __in const BUNDLE_EXTENSION_CREATE_ARGS* pArgs, | ||
12 | __inout BUNDLE_EXTENSION_CREATE_RESULTS* pResults | ||
13 | ) | ||
14 | { | ||
15 | HRESULT hr = S_OK; | ||
16 | IBundleExtensionEngine* pEngine = NULL; | ||
17 | |||
18 | hr = XmlInitialize(); | ||
19 | ExitOnFailure(hr, "Failed to initialize XML."); | ||
20 | |||
21 | hr = BextInitializeFromCreateArgs(pArgs, &pEngine); | ||
22 | ExitOnFailure(hr, "Failed to initialize bext"); | ||
23 | |||
24 | hr = UtilBundleExtensionCreate(pEngine, pArgs, &vpBundleExtension); | ||
25 | BextExitOnFailure(hr, "Failed to create WixUtilBundleExtension"); | ||
26 | |||
27 | pResults->pfnBundleExtensionProc = BextBaseBundleExtensionProc; | ||
28 | pResults->pvBundleExtensionProcContext = vpBundleExtension; | ||
29 | |||
30 | LExit: | ||
31 | ReleaseObject(pEngine); | ||
32 | |||
33 | return hr; | ||
34 | } | ||
35 | |||
36 | extern "C" void WINAPI BundleExtensionDestroy() | ||
37 | { | ||
38 | BextUninitialize(); | ||
39 | ReleaseNullObject(vpBundleExtension); | ||
40 | XmlUninitialize(); | ||
41 | } \ No newline at end of file | ||
diff --git a/src/ext/Util/be/utilbe.def b/src/ext/Util/be/utilbe.def new file mode 100644 index 00000000..711b1a5c --- /dev/null +++ b/src/ext/Util/be/utilbe.def | |||
@@ -0,0 +1,8 @@ | |||
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 | |||
4 | LIBRARY "utilbe" | ||
5 | |||
6 | EXPORTS | ||
7 | BundleExtensionCreate | ||
8 | BundleExtensionDestroy | ||
diff --git a/src/ext/Util/be/utilbe.vcxproj b/src/ext/Util/be/utilbe.vcxproj new file mode 100644 index 00000000..683b376a --- /dev/null +++ b/src/ext/Util/be/utilbe.vcxproj | |||
@@ -0,0 +1,80 @@ | |||
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="16.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
5 | <ItemGroup Label="ProjectConfigurations"> | ||
6 | <ProjectConfiguration Include="Debug|ARM64"> | ||
7 | <Configuration>Debug</Configuration> | ||
8 | <Platform>ARM64</Platform> | ||
9 | </ProjectConfiguration> | ||
10 | <ProjectConfiguration Include="Release|ARM64"> | ||
11 | <Configuration>Release</Configuration> | ||
12 | <Platform>ARM64</Platform> | ||
13 | </ProjectConfiguration> | ||
14 | <ProjectConfiguration Include="Debug|X64"> | ||
15 | <Configuration>Debug</Configuration> | ||
16 | <Platform>X64</Platform> | ||
17 | </ProjectConfiguration> | ||
18 | <ProjectConfiguration Include="Release|X64"> | ||
19 | <Configuration>Release</Configuration> | ||
20 | <Platform>X64</Platform> | ||
21 | </ProjectConfiguration> | ||
22 | <ProjectConfiguration Include="Debug|Win32"> | ||
23 | <Configuration>Debug</Configuration> | ||
24 | <Platform>Win32</Platform> | ||
25 | </ProjectConfiguration> | ||
26 | <ProjectConfiguration Include="Release|Win32"> | ||
27 | <Configuration>Release</Configuration> | ||
28 | <Platform>Win32</Platform> | ||
29 | </ProjectConfiguration> | ||
30 | </ItemGroup> | ||
31 | |||
32 | <PropertyGroup Label="Globals"> | ||
33 | <ProjectGuid>{630C1EE7-2517-4A8C-83E3-DA1150308B58}</ProjectGuid> | ||
34 | <ConfigurationType>DynamicLibrary</ConfigurationType> | ||
35 | <TargetName>utilbe</TargetName> | ||
36 | <PlatformToolset>v142</PlatformToolset> | ||
37 | <CharacterSet>Unicode</CharacterSet> | ||
38 | <ProjectModuleDefinitionFile>utilbe.def</ProjectModuleDefinitionFile> | ||
39 | <Description>WiX Toolset Util BundleExtension</Description> | ||
40 | </PropertyGroup> | ||
41 | |||
42 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||
43 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | ||
44 | |||
45 | <PropertyGroup> | ||
46 | <ProjectAdditionalLinkLibraries>msi.lib</ProjectAdditionalLinkLibraries> | ||
47 | </PropertyGroup> | ||
48 | |||
49 | <ItemGroup> | ||
50 | <ClCompile Include="detectsha2support.cpp" /> | ||
51 | <ClCompile Include="precomp.cpp"> | ||
52 | <PrecompiledHeader>Create</PrecompiledHeader> | ||
53 | </ClCompile> | ||
54 | <ClCompile Include="utilbe.cpp" /> | ||
55 | <ClCompile Include="UtilBundleExtension.cpp" /> | ||
56 | <ClCompile Include="utilsearch.cpp" /> | ||
57 | </ItemGroup> | ||
58 | |||
59 | <ItemGroup> | ||
60 | <ClInclude Include="beDecor.h" /> | ||
61 | <ClInclude Include="detectsha2support.h" /> | ||
62 | <ClInclude Include="precomp.h" /> | ||
63 | <ClInclude Include="UtilBundleExtension.h" /> | ||
64 | <ClInclude Include="utilsearch.h" /> | ||
65 | </ItemGroup> | ||
66 | |||
67 | <ItemGroup> | ||
68 | <None Include="utilbe.def" /> | ||
69 | </ItemGroup> | ||
70 | |||
71 | <ItemGroup> | ||
72 | <PackageReference Include="WixToolset.BextUtil" Version="4.0.58" /> | ||
73 | <PackageReference Include="WixToolset.BootstrapperCore.Native" Version="4.0.141" /> | ||
74 | <PackageReference Include="WixToolset.DUtil" Version="4.0.72" /> | ||
75 | <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" /> | ||
76 | <PackageReference Include="Nerdbank.GitVersioning" Version="3.3.37" /> | ||
77 | </ItemGroup> | ||
78 | |||
79 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
80 | </Project> | ||
diff --git a/src/ext/Util/be/utilsearch.cpp b/src/ext/Util/be/utilsearch.cpp new file mode 100644 index 00000000..7cd2ea09 --- /dev/null +++ b/src/ext/Util/be/utilsearch.cpp | |||
@@ -0,0 +1,160 @@ | |||
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 | |||
6 | STDMETHODIMP UtilSearchParseFromXml( | ||
7 | __in UTIL_SEARCHES* pSearches, | ||
8 | __in IXMLDOMNode* pixnBundleExtension | ||
9 | ) | ||
10 | { | ||
11 | HRESULT hr = S_OK; | ||
12 | IXMLDOMNodeList* pixnNodes = NULL; | ||
13 | IXMLDOMNode* pixnNode = NULL; | ||
14 | DWORD cNodes = 0; | ||
15 | BSTR bstrNodeName = NULL; | ||
16 | LPWSTR scz = NULL; | ||
17 | |||
18 | // Select Util search nodes. | ||
19 | hr = XmlSelectNodes(pixnBundleExtension, L"WixWindowsFeatureSearch", &pixnNodes); | ||
20 | ExitOnFailure(hr, "Failed to select Util search nodes."); | ||
21 | |||
22 | // Get Util search node count. | ||
23 | hr = pixnNodes->get_length((long*)&cNodes); | ||
24 | ExitOnFailure(hr, "Failed to get Util search node count."); | ||
25 | |||
26 | if (!cNodes) | ||
27 | { | ||
28 | ExitFunction(); | ||
29 | } | ||
30 | |||
31 | // Allocate memory for searches. | ||
32 | pSearches->rgSearches = (UTIL_SEARCH*)MemAlloc(sizeof(UTIL_SEARCH) * cNodes, TRUE); | ||
33 | ExitOnNull(pSearches->rgSearches, hr, E_OUTOFMEMORY, "Failed to allocate memory for search structs."); | ||
34 | |||
35 | pSearches->cSearches = cNodes; | ||
36 | |||
37 | // Parse search elements. | ||
38 | for (DWORD i = 0; i < cNodes; ++i) | ||
39 | { | ||
40 | UTIL_SEARCH* pSearch = &pSearches->rgSearches[i]; | ||
41 | |||
42 | hr = XmlNextElement(pixnNodes, &pixnNode, &bstrNodeName); | ||
43 | ExitOnFailure(hr, "Failed to get next node."); | ||
44 | |||
45 | // @Id | ||
46 | hr = XmlGetAttributeEx(pixnNode, L"Id", &pSearch->sczId); | ||
47 | ExitOnFailure(hr, "Failed to get @Id."); | ||
48 | |||
49 | // Read type specific attributes. | ||
50 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"WixWindowsFeatureSearch", -1)) | ||
51 | { | ||
52 | pSearch->Type = UTIL_SEARCH_TYPE_WINDOWS_FEATURE_SEARCH; | ||
53 | |||
54 | // @Type | ||
55 | hr = XmlGetAttributeEx(pixnNode, L"Type", &scz); | ||
56 | ExitOnFailure(hr, "Failed to get @Type."); | ||
57 | |||
58 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"sha2CodeSigning", -1)) | ||
59 | { | ||
60 | pSearch->WindowsFeatureSearch.type = UTIL_WINDOWS_FEATURE_SEARCH_TYPE_SHA2_CODE_SIGNING; | ||
61 | } | ||
62 | else | ||
63 | { | ||
64 | hr = E_INVALIDARG; | ||
65 | ExitOnFailure(hr, "Invalid value for @Type: %ls", scz); | ||
66 | } | ||
67 | } | ||
68 | else | ||
69 | { | ||
70 | hr = E_UNEXPECTED; | ||
71 | ExitOnFailure(hr, "Unexpected element name: %ls", bstrNodeName); | ||
72 | } | ||
73 | |||
74 | // prepare next iteration | ||
75 | ReleaseNullObject(pixnNode); | ||
76 | ReleaseNullBSTR(bstrNodeName); | ||
77 | } | ||
78 | |||
79 | LExit: | ||
80 | ReleaseStr(scz); | ||
81 | ReleaseBSTR(bstrNodeName); | ||
82 | ReleaseObject(pixnNode); | ||
83 | ReleaseObject(pixnNodes); | ||
84 | |||
85 | return hr; | ||
86 | } | ||
87 | |||
88 | void UtilSearchUninitialize( | ||
89 | __in UTIL_SEARCHES* pSearches | ||
90 | ) | ||
91 | { | ||
92 | if (pSearches->rgSearches) | ||
93 | { | ||
94 | for (DWORD i = 0; i < pSearches->cSearches; ++i) | ||
95 | { | ||
96 | UTIL_SEARCH* pSearch = &pSearches->rgSearches[i]; | ||
97 | |||
98 | ReleaseStr(pSearch->sczId); | ||
99 | } | ||
100 | MemFree(pSearches->rgSearches); | ||
101 | } | ||
102 | } | ||
103 | |||
104 | STDMETHODIMP UtilSearchExecute( | ||
105 | __in UTIL_SEARCHES* pSearches, | ||
106 | __in LPCWSTR wzSearchId, | ||
107 | __in LPCWSTR wzVariable, | ||
108 | __in IBundleExtensionEngine* pEngine | ||
109 | ) | ||
110 | { | ||
111 | HRESULT hr = S_OK; | ||
112 | UTIL_SEARCH* pSearch = NULL; | ||
113 | |||
114 | hr = UtilSearchFindById(pSearches, wzSearchId, &pSearch); | ||
115 | ExitOnFailure(hr, "Search id '%ls' is unknown to the util extension."); | ||
116 | |||
117 | switch (pSearch->Type) | ||
118 | { | ||
119 | case UTIL_SEARCH_TYPE_WINDOWS_FEATURE_SEARCH: | ||
120 | switch (pSearch->WindowsFeatureSearch.type) | ||
121 | { | ||
122 | case UTIL_WINDOWS_FEATURE_SEARCH_TYPE_SHA2_CODE_SIGNING: | ||
123 | hr = UtilPerformDetectSHA2CodeSigning(wzVariable, pSearch, pEngine); | ||
124 | break; | ||
125 | default: | ||
126 | hr = E_UNEXPECTED; | ||
127 | } | ||
128 | break; | ||
129 | default: | ||
130 | hr = E_UNEXPECTED; | ||
131 | } | ||
132 | |||
133 | LExit: | ||
134 | return hr; | ||
135 | } | ||
136 | |||
137 | STDMETHODIMP UtilSearchFindById( | ||
138 | __in UTIL_SEARCHES* pSearches, | ||
139 | __in LPCWSTR wzId, | ||
140 | __out UTIL_SEARCH** ppSearch | ||
141 | ) | ||
142 | { | ||
143 | HRESULT hr = S_OK; | ||
144 | |||
145 | for (DWORD i = 0; i < pSearches->cSearches; ++i) | ||
146 | { | ||
147 | UTIL_SEARCH* pSearch = &pSearches->rgSearches[i]; | ||
148 | |||
149 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pSearch->sczId, -1, wzId, -1)) | ||
150 | { | ||
151 | *ppSearch = pSearch; | ||
152 | ExitFunction1(hr = S_OK); | ||
153 | } | ||
154 | } | ||
155 | |||
156 | hr = E_NOTFOUND; | ||
157 | |||
158 | LExit: | ||
159 | return hr; | ||
160 | } | ||
diff --git a/src/ext/Util/be/utilsearch.h b/src/ext/Util/be/utilsearch.h new file mode 100644 index 00000000..deeab1f7 --- /dev/null +++ b/src/ext/Util/be/utilsearch.h | |||
@@ -0,0 +1,65 @@ | |||
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 | |||
5 | // constants | ||
6 | |||
7 | enum UTIL_SEARCH_TYPE | ||
8 | { | ||
9 | UTIL_SEARCH_TYPE_NONE, | ||
10 | UTIL_SEARCH_TYPE_WINDOWS_FEATURE_SEARCH, | ||
11 | }; | ||
12 | |||
13 | enum UTIL_WINDOWS_FEATURE_SEARCH_TYPE | ||
14 | { | ||
15 | UTIL_WINDOWS_FEATURE_SEARCH_TYPE_NONE, | ||
16 | UTIL_WINDOWS_FEATURE_SEARCH_TYPE_SHA2_CODE_SIGNING, | ||
17 | }; | ||
18 | |||
19 | |||
20 | // structs | ||
21 | |||
22 | typedef struct _UTIL_SEARCH | ||
23 | { | ||
24 | LPWSTR sczId; | ||
25 | |||
26 | UTIL_SEARCH_TYPE Type; | ||
27 | union | ||
28 | { | ||
29 | struct | ||
30 | { | ||
31 | UTIL_WINDOWS_FEATURE_SEARCH_TYPE type; | ||
32 | } WindowsFeatureSearch; | ||
33 | }; | ||
34 | } UTIL_SEARCH; | ||
35 | |||
36 | typedef struct _UTIL_SEARCHES | ||
37 | { | ||
38 | UTIL_SEARCH* rgSearches; | ||
39 | DWORD cSearches; | ||
40 | } UTIL_SEARCHES; | ||
41 | |||
42 | |||
43 | // function declarations | ||
44 | |||
45 | STDMETHODIMP UtilSearchParseFromXml( | ||
46 | __in UTIL_SEARCHES* pSearches, | ||
47 | __in IXMLDOMNode* pixnBundleExtension | ||
48 | ); | ||
49 | |||
50 | void UtilSearchUninitialize( | ||
51 | __in UTIL_SEARCHES* pSearches | ||
52 | ); | ||
53 | |||
54 | STDMETHODIMP UtilSearchExecute( | ||
55 | __in UTIL_SEARCHES* pSearches, | ||
56 | __in LPCWSTR wzSearchId, | ||
57 | __in LPCWSTR wzVariable, | ||
58 | __in IBundleExtensionEngine* pEngine | ||
59 | ); | ||
60 | |||
61 | STDMETHODIMP UtilSearchFindById( | ||
62 | __in UTIL_SEARCHES* pSearches, | ||
63 | __in LPCWSTR wzId, | ||
64 | __out UTIL_SEARCH** ppSearch | ||
65 | ); | ||