From f866ab77f8fd0790f4d6628f54dcdf0bd66fccb6 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Fri, 10 Jul 2020 21:25:44 +1000 Subject: Change the DetectSHA2Support element to WindowsFeatureSearch. This will make it easier to add support for other Windows features in the future. --- src/be/detectsha2support.cpp | 8 +-- src/be/detectsha2support.h | 2 +- src/be/utilsearch.cpp | 33 ++++++++++-- src/be/utilsearch.h | 15 +++++- .../TestData/BundleWithSearches/Bundle.wxs | 6 +-- .../WixToolsetTest.Util/UtilExtensionFixture.cs | 2 +- src/wixext/Symbols/UtilSymbolDefinitions.cs | 10 ++-- src/wixext/Symbols/WixDetectSHA2SupportSymbol.cs | 33 ------------ .../Symbols/WixWindowsFeatureSearchSymbol.cs | 47 ++++++++++++++++ src/wixext/UtilCompiler.cs | 50 +++++++++++------ src/wixext/util.xsd | 62 +++++++++++++--------- 11 files changed, 176 insertions(+), 92 deletions(-) delete mode 100644 src/wixext/Symbols/WixDetectSHA2SupportSymbol.cs create mode 100644 src/wixext/Symbols/WixWindowsFeatureSearchSymbol.cs diff --git a/src/be/detectsha2support.cpp b/src/be/detectsha2support.cpp index f1f3637e..90e349cd 100644 --- a/src/be/detectsha2support.cpp +++ b/src/be/detectsha2support.cpp @@ -3,7 +3,7 @@ #include "precomp.h" // https://gist.github.com/navossoc/7572c7d82243e9f818989e2765e7793a -HRESULT DetectSHA2Support( +HRESULT DetectSHA2CodeSigning( __out BOOL* pfSupported ) { @@ -38,7 +38,7 @@ LExit: return hr; } -HRESULT UtilPerformDetectSHA2Support( +HRESULT UtilPerformDetectSHA2CodeSigning( __in LPCWSTR wzVariable, __in UTIL_SEARCH* /*pSearch*/, __in IBundleExtensionEngine* pEngine @@ -47,8 +47,8 @@ HRESULT UtilPerformDetectSHA2Support( HRESULT hr = S_OK; BOOL fSupported = FALSE; - hr = DetectSHA2Support(&fSupported); - ExitOnFailure(hr, "DetectSHA2Support failed."); + hr = DetectSHA2CodeSigning(&fSupported); + ExitOnFailure(hr, "DetectSHA2CodeSigning failed."); hr = pEngine->SetVariableNumeric(wzVariable, fSupported ? 1 : 0); ExitOnFailure(hr, "Failed to set variable '%ls'", wzVariable); diff --git a/src/be/detectsha2support.h b/src/be/detectsha2support.h index 7f1f6031..c38a3d59 100644 --- a/src/be/detectsha2support.h +++ b/src/be/detectsha2support.h @@ -1,7 +1,7 @@ #pragma once // 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. -HRESULT UtilPerformDetectSHA2Support( +HRESULT UtilPerformDetectSHA2CodeSigning( __in LPCWSTR wzVariable, __in UTIL_SEARCH* pSearch, __in IBundleExtensionEngine* pEngine diff --git a/src/be/utilsearch.cpp b/src/be/utilsearch.cpp index 4e9d86a1..7cd2ea09 100644 --- a/src/be/utilsearch.cpp +++ b/src/be/utilsearch.cpp @@ -13,9 +13,10 @@ STDMETHODIMP UtilSearchParseFromXml( IXMLDOMNode* pixnNode = NULL; DWORD cNodes = 0; BSTR bstrNodeName = NULL; + LPWSTR scz = NULL; // Select Util search nodes. - hr = XmlSelectNodes(pixnBundleExtension, L"WixDetectSHA2Support", &pixnNodes); + hr = XmlSelectNodes(pixnBundleExtension, L"WixWindowsFeatureSearch", &pixnNodes); ExitOnFailure(hr, "Failed to select Util search nodes."); // Get Util search node count. @@ -46,9 +47,23 @@ STDMETHODIMP UtilSearchParseFromXml( ExitOnFailure(hr, "Failed to get @Id."); // Read type specific attributes. - if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"WixDetectSHA2Support", -1)) + if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"WixWindowsFeatureSearch", -1)) { - pSearch->Type = UTIL_SEARCH_TYPE_DETECT_SHA2_SUPPORT; + pSearch->Type = UTIL_SEARCH_TYPE_WINDOWS_FEATURE_SEARCH; + + // @Type + hr = XmlGetAttributeEx(pixnNode, L"Type", &scz); + ExitOnFailure(hr, "Failed to get @Type."); + + if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"sha2CodeSigning", -1)) + { + pSearch->WindowsFeatureSearch.type = UTIL_WINDOWS_FEATURE_SEARCH_TYPE_SHA2_CODE_SIGNING; + } + else + { + hr = E_INVALIDARG; + ExitOnFailure(hr, "Invalid value for @Type: %ls", scz); + } } else { @@ -62,6 +77,7 @@ STDMETHODIMP UtilSearchParseFromXml( } LExit: + ReleaseStr(scz); ReleaseBSTR(bstrNodeName); ReleaseObject(pixnNode); ReleaseObject(pixnNodes); @@ -100,8 +116,15 @@ STDMETHODIMP UtilSearchExecute( switch (pSearch->Type) { - case UTIL_SEARCH_TYPE_DETECT_SHA2_SUPPORT: - hr = UtilPerformDetectSHA2Support(wzVariable, pSearch, pEngine); + case UTIL_SEARCH_TYPE_WINDOWS_FEATURE_SEARCH: + switch (pSearch->WindowsFeatureSearch.type) + { + case UTIL_WINDOWS_FEATURE_SEARCH_TYPE_SHA2_CODE_SIGNING: + hr = UtilPerformDetectSHA2CodeSigning(wzVariable, pSearch, pEngine); + break; + default: + hr = E_UNEXPECTED; + } break; default: hr = E_UNEXPECTED; diff --git a/src/be/utilsearch.h b/src/be/utilsearch.h index 1e0ca96d..deeab1f7 100644 --- a/src/be/utilsearch.h +++ b/src/be/utilsearch.h @@ -7,7 +7,13 @@ enum UTIL_SEARCH_TYPE { UTIL_SEARCH_TYPE_NONE, - UTIL_SEARCH_TYPE_DETECT_SHA2_SUPPORT, + UTIL_SEARCH_TYPE_WINDOWS_FEATURE_SEARCH, +}; + +enum UTIL_WINDOWS_FEATURE_SEARCH_TYPE +{ + UTIL_WINDOWS_FEATURE_SEARCH_TYPE_NONE, + UTIL_WINDOWS_FEATURE_SEARCH_TYPE_SHA2_CODE_SIGNING, }; @@ -18,6 +24,13 @@ typedef struct _UTIL_SEARCH LPWSTR sczId; UTIL_SEARCH_TYPE Type; + union + { + struct + { + UTIL_WINDOWS_FEATURE_SEARCH_TYPE type; + } WindowsFeatureSearch; + }; } UTIL_SEARCH; typedef struct _UTIL_SEARCHES diff --git a/src/test/WixToolsetTest.Util/TestData/BundleWithSearches/Bundle.wxs b/src/test/WixToolsetTest.Util/TestData/BundleWithSearches/Bundle.wxs index 56eba137..c8f7205f 100644 --- a/src/test/WixToolsetTest.Util/TestData/BundleWithSearches/Bundle.wxs +++ b/src/test/WixToolsetTest.Util/TestData/BundleWithSearches/Bundle.wxs @@ -1,11 +1,11 @@ - + - + @@ -33,6 +33,6 @@ - + diff --git a/src/test/WixToolsetTest.Util/UtilExtensionFixture.cs b/src/test/WixToolsetTest.Util/UtilExtensionFixture.cs index aa03d068..78a9f967 100644 --- a/src/test/WixToolsetTest.Util/UtilExtensionFixture.cs +++ b/src/test/WixToolsetTest.Util/UtilExtensionFixture.cs @@ -172,7 +172,7 @@ namespace WixToolsetTest.Util var bundleExtensionDatas = extractResult.SelectBundleExtensionDataNodes("/be:BundleExtensionData/be:BundleExtension[@Id='Wix4UtilBundleExtension_X86']"); Assert.Equal(1, bundleExtensionDatas.Count); Assert.Equal("" + - "" + + "" + "", bundleExtensionDatas[0].GetTestXml()); var utilSearches = extractResult.SelectManifestNodes("/burn:BurnManifest/*[self::burn:ExtensionSearch or self::burn:FileSearch or self::burn:MsiProductSearch or self::burn:RegistrySearch]"); diff --git a/src/wixext/Symbols/UtilSymbolDefinitions.cs b/src/wixext/Symbols/UtilSymbolDefinitions.cs index ae9c4c81..5f062676 100644 --- a/src/wixext/Symbols/UtilSymbolDefinitions.cs +++ b/src/wixext/Symbols/UtilSymbolDefinitions.cs @@ -20,12 +20,12 @@ namespace WixToolset.Util User, UserGroup, WixCloseApplication, - WixDetectSHA2Support, WixFormatFiles, WixInternetShortcut, WixRemoveFolderEx, WixRestartResource, WixTouchFile, + WixWindowsFeatureSearch, XmlConfig, XmlFile, } @@ -84,9 +84,6 @@ namespace WixToolset.Util case UtilSymbolDefinitionType.WixCloseApplication: return UtilSymbolDefinitions.WixCloseApplication; - case UtilSymbolDefinitionType.WixDetectSHA2Support: - return UtilSymbolDefinitions.WixDetectSHA2Support; - case UtilSymbolDefinitionType.WixFormatFiles: return UtilSymbolDefinitions.WixFormatFiles; @@ -102,6 +99,9 @@ namespace WixToolset.Util case UtilSymbolDefinitionType.WixTouchFile: return UtilSymbolDefinitions.WixTouchFile; + case UtilSymbolDefinitionType.WixWindowsFeatureSearch: + return UtilSymbolDefinitions.WixWindowsFeatureSearch; + case UtilSymbolDefinitionType.XmlConfig: return UtilSymbolDefinitions.XmlConfig; @@ -115,7 +115,7 @@ namespace WixToolset.Util static UtilSymbolDefinitions() { - WixDetectSHA2Support.AddTag(BurnConstants.BundleExtensionSearchSymbolDefinitionTag); + WixWindowsFeatureSearch.AddTag(BurnConstants.BundleExtensionSearchSymbolDefinitionTag); } } } diff --git a/src/wixext/Symbols/WixDetectSHA2SupportSymbol.cs b/src/wixext/Symbols/WixDetectSHA2SupportSymbol.cs deleted file mode 100644 index b518ba3b..00000000 --- a/src/wixext/Symbols/WixDetectSHA2SupportSymbol.cs +++ /dev/null @@ -1,33 +0,0 @@ -// 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. - -namespace WixToolset.Util -{ - using WixToolset.Data; - using WixToolset.Util.Symbols; - - public static partial class UtilSymbolDefinitions - { - public static readonly IntermediateSymbolDefinition WixDetectSHA2Support = new IntermediateSymbolDefinition( - UtilSymbolDefinitionType.WixDetectSHA2Support.ToString(), - new IntermediateFieldDefinition[0], - typeof(WixDetectSHA2SupportSymbol)); - } -} - -namespace WixToolset.Util.Symbols -{ - using WixToolset.Data; - - public class WixDetectSHA2SupportSymbol : IntermediateSymbol - { - public WixDetectSHA2SupportSymbol() : base(UtilSymbolDefinitions.WixDetectSHA2Support, null, null) - { - } - - public WixDetectSHA2SupportSymbol(SourceLineNumber sourceLineNumber, Identifier id = null) : base(UtilSymbolDefinitions.WixDetectSHA2Support, sourceLineNumber, id) - { - } - - public IntermediateField this[GroupSymbolFields index] => this.Fields[(int)index]; - } -} diff --git a/src/wixext/Symbols/WixWindowsFeatureSearchSymbol.cs b/src/wixext/Symbols/WixWindowsFeatureSearchSymbol.cs new file mode 100644 index 00000000..9a43692c --- /dev/null +++ b/src/wixext/Symbols/WixWindowsFeatureSearchSymbol.cs @@ -0,0 +1,47 @@ +// 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. + +namespace WixToolset.Util +{ + using WixToolset.Data; + using WixToolset.Util.Symbols; + + public static partial class UtilSymbolDefinitions + { + public static readonly IntermediateSymbolDefinition WixWindowsFeatureSearch = new IntermediateSymbolDefinition( + UtilSymbolDefinitionType.WixWindowsFeatureSearch.ToString(), + new[] + { + new IntermediateFieldDefinition(nameof(WixWindowsFeatureSearchSymbolFields.Type), IntermediateFieldType.String), + }, + typeof(WixWindowsFeatureSearchSymbol)); + } +} + +namespace WixToolset.Util.Symbols +{ + using WixToolset.Data; + + public enum WixWindowsFeatureSearchSymbolFields + { + Type, + } + + public class WixWindowsFeatureSearchSymbol : IntermediateSymbol + { + public WixWindowsFeatureSearchSymbol() : base(UtilSymbolDefinitions.WixWindowsFeatureSearch, null, null) + { + } + + public WixWindowsFeatureSearchSymbol(SourceLineNumber sourceLineNumber, Identifier id = null) : base(UtilSymbolDefinitions.WixWindowsFeatureSearch, sourceLineNumber, id) + { + } + + public IntermediateField this[WixWindowsFeatureSearchSymbolFields index] => this.Fields[(int)index]; + + public string Type + { + get => this.Fields[(int)WixWindowsFeatureSearchSymbolFields.Type].AsString(); + set => this.Set((int)WixWindowsFeatureSearchSymbolFields.Type, value); + } + } +} diff --git a/src/wixext/UtilCompiler.cs b/src/wixext/UtilCompiler.cs index a5745b6c..79dbbc6d 100644 --- a/src/wixext/UtilCompiler.cs +++ b/src/wixext/UtilCompiler.cs @@ -235,8 +235,6 @@ namespace WixToolset.Util break; case "ComponentSearch": case "ComponentSearchRef": - case "DetectSHA2Support": - case "DetectSHA2SupportRef": case "DirectorySearch": case "DirectorySearchRef": case "FileSearch": @@ -245,6 +243,8 @@ namespace WixToolset.Util case "ProductSearchRef": case "RegistrySearch": case "RegistrySearchRef": + case "WindowsFeatureSearch": + case "WindowsFeatureSearchRef": // These will eventually be supported under Module/Product, but are not yet. if (parentElement.Name.LocalName == "Bundle" || parentElement.Name.LocalName == "Fragment") { @@ -258,12 +258,6 @@ namespace WixToolset.Util case "ComponentSearchRef": this.ParseComponentSearchRefElement(intermediate, section, element); break; - case "DetectSHA2Support": - this.ParseDetectSHA2SupportElement(intermediate, section, element); - break; - case "DetectSHA2SupportRef": - this.ParseDetectSHA2SupportRefElement(intermediate, section, element); - break; case "DirectorySearch": this.ParseDirectorySearchElement(intermediate, section, element); break; @@ -288,6 +282,12 @@ namespace WixToolset.Util case "RegistrySearchRef": this.ParseWixSearchRefElement(intermediate, section, element); break; + case "WindowsFeatureSearch": + this.ParseWindowsFeatureSearchElement(intermediate, section, element); + break; + case "WindowsFeatureSearchRef": + this.ParseWindowsFeatureSearchRefElement(intermediate, section, element); + break; } } else @@ -508,16 +508,17 @@ namespace WixToolset.Util } /// - /// Parses a DetectSHA2Support element. + /// Parses a WindowsFeatureSearch element. /// /// Element to parse. - private void ParseDetectSHA2SupportElement(Intermediate intermediate, IntermediateSection section, XElement element) + private void ParseWindowsFeatureSearchElement(Intermediate intermediate, IntermediateSection section, XElement element) { var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); Identifier id = null; string variable = null; string condition = null; string after = null; + string feature = null; foreach (var attrib in element.Attributes()) { @@ -531,6 +532,17 @@ namespace WixToolset.Util case "After": this.ParseCommonSearchAttributes(sourceLineNumbers, attrib, ref id, ref variable, ref condition, ref after); break; + case "Feature": + feature = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); + switch (feature) + { + case "sha2CodeSigning": + break; + default: + this.Messaging.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, element.Name.LocalName, "Feature", feature, "sha2CodeSigning")); + break; + } + break; default: this.ParseHelper.UnexpectedAttribute(element, attrib); break; @@ -544,7 +556,12 @@ namespace WixToolset.Util if (id == null) { - id = this.ParseHelper.CreateIdentifier("wds2s", variable, condition, after); + id = this.ParseHelper.CreateIdentifier("wwfs", variable, condition, after); + } + + if (feature == null) + { + this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Feature")); } this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, element); @@ -559,15 +576,18 @@ namespace WixToolset.Util if (!this.Messaging.EncounteredError) { - section.AddSymbol(new WixDetectSHA2SupportSymbol(sourceLineNumbers, id)); + section.AddSymbol(new WixWindowsFeatureSearchSymbol(sourceLineNumbers, id) + { + Type = feature, + }); } } /// - /// Parses a DetectSHA2SupportRef element + /// Parses a WindowsFeatureSearchRef element /// /// Element to parse. - private void ParseDetectSHA2SupportRefElement(Intermediate intermediate, IntermediateSection section, XElement element) + private void ParseWindowsFeatureSearchRefElement(Intermediate intermediate, IntermediateSection section, XElement element) { var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); @@ -579,7 +599,7 @@ namespace WixToolset.Util { case "Id": var refId = this.ParseHelper.GetAttributeIdentifierValue(sourceLineNumbers, attrib); - this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, UtilSymbolDefinitions.WixDetectSHA2Support, refId); + this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, UtilSymbolDefinitions.WixWindowsFeatureSearch, refId); break; default: this.ParseHelper.UnexpectedAttribute(element, attrib); diff --git a/src/wixext/util.xsd b/src/wixext/util.xsd index bb7a1e39..b6f0365b 100644 --- a/src/wixext/util.xsd +++ b/src/wixext/util.xsd @@ -174,30 +174,6 @@ - - - Detects support for SHA2. - - - - - - - - - - - - References a DetectSHA2Support. - - - - - - - - - Describes a directory search. @@ -1389,6 +1365,44 @@ + + + Detects the existence of a Windows feature. + + + + + + + + + + The feature to detect. + + + + + + The oldest OS with this feature is Win7 SP1 with KB3033929. + + + + + + + + + + References a WindowsFeatureSearch. + + + + + + + + + -- cgit v1.2.3-55-g6feb