From 4d30ab70573f9734d7fd3cd4d54c02173fa281db Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Sun, 20 Jan 2019 09:19:12 -0600 Subject: Import code from old v4 repo --- src/wixext/HttpCompiler.cs | 280 +++++++++++++++++++++++++++++++++++++ src/wixext/HttpConstants.cs | 19 +++ src/wixext/HttpDecompiler.cs | 135 ++++++++++++++++++ src/wixext/HttpExtensionData.cs | 64 +++++++++ src/wixext/WixHttpExtension.csproj | 48 +++++++ src/wixext/http.xsd | 148 ++++++++++++++++++++ src/wixext/messages.xml | 13 ++ src/wixext/tables.xml | 28 ++++ 8 files changed, 735 insertions(+) create mode 100644 src/wixext/HttpCompiler.cs create mode 100644 src/wixext/HttpConstants.cs create mode 100644 src/wixext/HttpDecompiler.cs create mode 100644 src/wixext/HttpExtensionData.cs create mode 100644 src/wixext/WixHttpExtension.csproj create mode 100644 src/wixext/http.xsd create mode 100644 src/wixext/messages.xml create mode 100644 src/wixext/tables.xml (limited to 'src/wixext') diff --git a/src/wixext/HttpCompiler.cs b/src/wixext/HttpCompiler.cs new file mode 100644 index 00000000..c694ccde --- /dev/null +++ b/src/wixext/HttpCompiler.cs @@ -0,0 +1,280 @@ +// 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.Extensions +{ + using System; + using System.Collections.Generic; + using System.Globalization; + using System.Xml.Linq; + using WixToolset.Data; + using WixToolset.Extensibility; + + /// + /// The compiler for the WiX Toolset Http Extension. + /// + public sealed class HttpCompiler : CompilerExtension + { + /// + /// Instantiate a new HttpCompiler. + /// + public HttpCompiler() + { + this.Namespace = "http://wixtoolset.org/schemas/v4/wxs/http"; + } + + /// + /// Processes an element for the Compiler. + /// + /// Source line number for the parent element. + /// Parent element of element to process. + /// Element to process. + /// Extra information about the context in which this element is being parsed. + public override void ParseElement(XElement parentElement, XElement element, IDictionary context) + { + switch (parentElement.Name.LocalName) + { + case "ServiceInstall": + string serviceInstallName = context["ServiceInstallName"]; + string serviceUser = String.IsNullOrEmpty(serviceInstallName) ? null : String.Concat("NT SERVICE\\", serviceInstallName); + string serviceComponentId = context["ServiceInstallComponentId"]; + + switch (element.Name.LocalName) + { + case "UrlReservation": + this.ParseUrlReservationElement(element, serviceComponentId, serviceUser); + break; + default: + this.Core.UnexpectedElement(parentElement, element); + break; + } + break; + case "Component": + string componentId = context["ComponentId"]; + + switch (element.Name.LocalName) + { + case "UrlReservation": + this.ParseUrlReservationElement(element, componentId, null); + break; + default: + this.Core.UnexpectedElement(parentElement, element); + break; + } + break; + default: + this.Core.UnexpectedElement(parentElement, element); + break; + } + } + + /// + /// Parses a UrlReservation element. + /// + /// The element to parse. + /// Identifier of the component that owns this URL reservation. + /// The security principal of the parent element (null if nested under Component). + private void ParseUrlReservationElement(XElement node, string componentId, string securityPrincipal) + { + SourceLineNumber sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node); + Identifier id = null; + int handleExisting = HttpConstants.heReplace; + string handleExistingValue = null; + string sddl = null; + string url = null; + bool foundACE = false; + + foreach (XAttribute attrib in node.Attributes()) + { + if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) + { + switch (attrib.Name.LocalName) + { + case "Id": + id = this.Core.GetAttributeIdentifier(sourceLineNumbers, attrib); + break; + case "HandleExisting": + handleExistingValue = this.Core.GetAttributeValue(sourceLineNumbers, attrib); + switch (handleExistingValue) + { + case "replace": + handleExisting = HttpConstants.heReplace; + break; + case "ignore": + handleExisting = HttpConstants.heIgnore; + break; + case "fail": + handleExisting = HttpConstants.heFail; + break; + default: + this.Core.OnMessage(WixErrors.IllegalAttributeValue(sourceLineNumbers, node.Name.LocalName, "HandleExisting", handleExistingValue, "replace", "ignore", "fail")); + break; + } + break; + case "Sddl": + sddl = this.Core.GetAttributeValue(sourceLineNumbers, attrib); + break; + case "Url": + url = this.Core.GetAttributeValue(sourceLineNumbers, attrib); + break; + default: + this.Core.UnexpectedAttribute(node, attrib); + break; + } + } + else + { + this.Core.ParseExtensionAttribute(node, attrib); + } + } + + // Need the element ID for child element processing, so generate now if not authored. + if (null == id) + { + id = this.Core.CreateIdentifier("url", componentId, securityPrincipal, url); + } + + // Parse UrlAce children. + foreach (XElement child in node.Elements()) + { + if (this.Namespace == child.Name.Namespace) + { + switch (child.Name.LocalName) + { + case "UrlAce": + if (null != sddl) + { + this.Core.OnMessage(WixErrors.IllegalParentAttributeWhenNested(sourceLineNumbers, "UrlReservation", "Sddl", "UrlAce")); + } + else + { + foundACE = true; + this.ParseUrlAceElement(child, id.Id, securityPrincipal); + } + break; + default: + this.Core.UnexpectedElement(node, child); + break; + } + } + else + { + this.Core.ParseExtensionElement(node, child); + } + } + + // Url is required. + if (null == url) + { + this.Core.OnMessage(WixErrors.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Url")); + } + + // Security is required. + if (null == sddl && !foundACE) + { + this.Core.OnMessage(HttpErrors.NoSecuritySpecified(sourceLineNumbers)); + } + + if (!this.Core.EncounteredError) + { + Row row = this.Core.CreateRow(sourceLineNumbers, "WixHttpUrlReservation"); + row[0] = id.Id; + row[1] = handleExisting; + row[2] = sddl; + row[3] = url; + row[4] = componentId; + + if (this.Core.CurrentPlatform == Platform.ARM) + { + // Ensure ARM version of the CA is referenced. + this.Core.CreateSimpleReference(sourceLineNumbers, "CustomAction", "WixSchedHttpUrlReservationsInstall_ARM"); + this.Core.CreateSimpleReference(sourceLineNumbers, "CustomAction", "WixSchedHttpUrlReservationsUninstall_ARM"); + } + else + { + // All other supported platforms use x86. + this.Core.CreateSimpleReference(sourceLineNumbers, "CustomAction", "WixSchedHttpUrlReservationsInstall"); + this.Core.CreateSimpleReference(sourceLineNumbers, "CustomAction", "WixSchedHttpUrlReservationsUninstall"); + } + } + } + + /// + /// Parses a UrlAce element. + /// + /// The element to parse. + /// The URL reservation ID. + /// The default security principal. + private void ParseUrlAceElement(XElement node, string urlReservationId, string defaultSecurityPrincipal) + { + SourceLineNumber sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node); + Identifier id = null; + string securityPrincipal = defaultSecurityPrincipal; + int rights = HttpConstants.GENERIC_ALL; + string rightsValue = null; + + foreach (XAttribute attrib in node.Attributes()) + { + if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) + { + switch (attrib.Name.LocalName) + { + case "Id": + id = this.Core.GetAttributeIdentifier(sourceLineNumbers, attrib); + break; + case "SecurityPrincipal": + securityPrincipal = this.Core.GetAttributeValue(sourceLineNumbers, attrib); + break; + case "Rights": + rightsValue = this.Core.GetAttributeValue(sourceLineNumbers, attrib); + switch (rightsValue) + { + case "all": + rights = HttpConstants.GENERIC_ALL; + break; + case "delegate": + rights = HttpConstants.GENERIC_WRITE; + break; + case "register": + rights = HttpConstants.GENERIC_EXECUTE; + break; + default: + this.Core.OnMessage(WixErrors.IllegalAttributeValue(sourceLineNumbers, node.Name.LocalName, "Rights", rightsValue, "all", "delegate", "register")); + break; + } + break; + default: + this.Core.UnexpectedAttribute(node, attrib); + break; + } + } + else + { + this.Core.ParseExtensionAttribute(node, attrib); + } + } + + // Generate Id now if not authored. + if (null == id) + { + id = this.Core.CreateIdentifier("ace", urlReservationId, securityPrincipal, rightsValue); + } + + this.Core.ParseForExtensionElements(node); + + // SecurityPrincipal is required. + if (null == securityPrincipal) + { + this.Core.OnMessage(WixErrors.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "SecurityPrincipal")); + } + + if (!this.Core.EncounteredError) + { + Row row = this.Core.CreateRow(sourceLineNumbers, "WixHttpUrlAce"); + row[0] = id.Id; + row[1] = urlReservationId; + row[2] = securityPrincipal; + row[3] = rights; + } + } + } +} diff --git a/src/wixext/HttpConstants.cs b/src/wixext/HttpConstants.cs new file mode 100644 index 00000000..7760d03f --- /dev/null +++ b/src/wixext/HttpConstants.cs @@ -0,0 +1,19 @@ +// 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.Extensions +{ + using System; + + internal static class HttpConstants + { + // from winnt.h + public const int GENERIC_ALL = 0x10000000; + public const int GENERIC_EXECUTE = 0x20000000; + public const int GENERIC_WRITE = 0x40000000; + + // from wixhttpca.cpp + public const int heReplace = 0; + public const int heIgnore = 1; + public const int heFail = 2; + } +} diff --git a/src/wixext/HttpDecompiler.cs b/src/wixext/HttpDecompiler.cs new file mode 100644 index 00000000..043ee1e1 --- /dev/null +++ b/src/wixext/HttpDecompiler.cs @@ -0,0 +1,135 @@ +// 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.Extensions +{ + using System; + using System.Collections; + using System.Diagnostics; + using System.Globalization; + using WixToolset.Data; + using WixToolset.Extensibility; + using Http = WixToolset.Extensions.Serialize.Http; + using Wix = WixToolset.Data.Serialize; + + /// + /// The decompiler for the WiX Toolset Http Extension. + /// + public sealed class HttpDecompiler : DecompilerExtension + { + /// + /// Creates a decompiler for Http Extension. + /// + public HttpDecompiler() + { + this.TableDefinitions = HttpExtensionData.GetExtensionTableDefinitions(); + } + + /// + /// Get the extensions library to be removed. + /// + /// Table definitions for library. + /// Library to remove from decompiled output. + public override Library GetLibraryToRemove(TableDefinitionCollection tableDefinitions) + { + return HttpExtensionData.GetExtensionLibrary(tableDefinitions); + } + + /// + /// Decompiles an extension table. + /// + /// The table to decompile. + public override void DecompileTable(Table table) + { + switch (table.Name) + { + case "WixHttpUrlReservation": + this.DecompileWixHttpUrlReservationTable(table); + break; + case "WixHttpUrlAce": + this.DecompileWixHttpUrlAceTable(table); + break; + default: + base.DecompileTable(table); + break; + } + } + + /// + /// Decompile the WixHttpUrlReservation table. + /// + /// The table to decompile. + private void DecompileWixHttpUrlReservationTable(Table table) + { + foreach (Row row in table.Rows) + { + Http.UrlReservation urlReservation = new Http.UrlReservation(); + urlReservation.Id = (string)row[0]; + switch((int)row[1]) + { + case HttpConstants.heReplace: + default: + urlReservation.HandleExisting = Http.UrlReservation.HandleExistingType.replace; + break; + case HttpConstants.heIgnore: + urlReservation.HandleExisting = Http.UrlReservation.HandleExistingType.ignore; + break; + case HttpConstants.heFail: + urlReservation.HandleExisting = Http.UrlReservation.HandleExistingType.fail; + break; + } + urlReservation.Sddl = (string)row[2]; + urlReservation.Url = (string)row[3]; + + Wix.Component component = (Wix.Component)this.Core.GetIndexedElement("Component", (string)row[4]); + if (null != component) + { + component.AddChild(urlReservation); + } + else + { + this.Core.OnMessage(WixWarnings.ExpectedForeignRow(row.SourceLineNumbers, table.Name, row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter), "Component_", (string)row[2], "Component")); + } + this.Core.IndexElement(row, urlReservation); + } + } + + + /// + /// Decompile the WixHttpUrlAce table. + /// + /// The table to decompile. + private void DecompileWixHttpUrlAceTable(Table table) + { + foreach (Row row in table.Rows) + { + Http.UrlAce urlace = new Http.UrlAce(); + urlace.Id = (string)row[0]; + urlace.SecurityPrincipal = (string)row[2]; + switch (Convert.ToInt32(row[3])) + { + case HttpConstants.GENERIC_ALL: + default: + urlace.Rights = Http.UrlAce.RightsType.all; + break; + case HttpConstants.GENERIC_EXECUTE: + urlace.Rights = Http.UrlAce.RightsType.register; + break; + case HttpConstants.GENERIC_WRITE: + urlace.Rights = Http.UrlAce.RightsType.@delegate; + break; + } + + string reservationId = (string)row[1]; + Http.UrlReservation urlReservation = (Http.UrlReservation)this.Core.GetIndexedElement("WixHttpUrlReservation", reservationId); + if (null != urlReservation) + { + urlReservation.AddChild(urlace); + } + else + { + this.Core.OnMessage(WixWarnings.ExpectedForeignRow(row.SourceLineNumbers, table.Name, urlace.Id, "WixHttpUrlReservation_", reservationId, "WixHttpUrlReservation")); + } + } + } + } +} diff --git a/src/wixext/HttpExtensionData.cs b/src/wixext/HttpExtensionData.cs new file mode 100644 index 00000000..db79a6c1 --- /dev/null +++ b/src/wixext/HttpExtensionData.cs @@ -0,0 +1,64 @@ +// 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.Extensions +{ + using System; + using System.Reflection; + using WixToolset.Data; + using WixToolset.Extensibility; + + /// + /// The WiX Toolset Http Extension. + /// + public sealed class HttpExtensionData : ExtensionData + { + /// + /// Gets the default culture. + /// + /// The default culture. + public override string DefaultCulture + { + get { return "en-us"; } + } + + /// + /// Gets the optional table definitions for this extension. + /// + /// The optional table definitions for this extension. + public override TableDefinitionCollection TableDefinitions + { + get + { + return HttpExtensionData.GetExtensionTableDefinitions(); + } + } + + /// + /// Gets the library associated with this extension. + /// + /// The table definitions to use while loading the library. + /// The loaded library. + public override Library GetLibrary(TableDefinitionCollection tableDefinitions) + { + return HttpExtensionData.GetExtensionLibrary(tableDefinitions); + } + + /// + /// Internal mechanism to access the extension's table definitions. + /// + /// Extension's table definitions. + internal static TableDefinitionCollection GetExtensionTableDefinitions() + { + return ExtensionData.LoadTableDefinitionHelper(Assembly.GetExecutingAssembly(), "WixToolset.Extensions.Data.tables.xml"); + } + + /// + /// Internal mechanism to access the extension's library. + /// + /// Extension's library. + internal static Library GetExtensionLibrary(TableDefinitionCollection tableDefinitions) + { + return ExtensionData.LoadLibraryHelper(Assembly.GetExecutingAssembly(), "WixToolset.Extensions.Data.http.wixlib", tableDefinitions); + } + } +} diff --git a/src/wixext/WixHttpExtension.csproj b/src/wixext/WixHttpExtension.csproj new file mode 100644 index 00000000..74af503f --- /dev/null +++ b/src/wixext/WixHttpExtension.csproj @@ -0,0 +1,48 @@ + + + + + + + {AAFC3C7F-D818-4B1D-AF3F-A331EA917F3F} + WixHttpExtension + Library + WixToolset.Extensions + + + + + + + + + $(RootNamespace).Data.Messages.resources + + + $(RootNamespace).Data.tables.xml + + + $(RootNamespace).Xsd.http.xsd + PreserveNewest + + + WixToolset.Data.Serialize + WixToolset.Extensions.Serialize.Http + + + Data\http.wixlib + + + + + + + + + + + false + + + + diff --git a/src/wixext/http.xsd b/src/wixext/http.xsd new file mode 100644 index 00000000..b96a6ded --- /dev/null +++ b/src/wixext/http.xsd @@ -0,0 +1,148 @@ + + + + + + + + The source code schema for the Windows Installer XML Toolset Http Extension. + + + + + + + + + Makes a reservation record for the HTTP Server API configuration store on Windows XP SP2, + Windows Server 2003, and later. For more information about the HTTP Server API, see + + HTTP Server API + . + + + + + + + + + + + + The access control entries for the access control list. + + + + + + + + + Specifies the behavior when trying to install a URL reservation and it already exists. + + + + + + + + Replaces the existing URL reservation (the default). + + + + + + + Keeps the existing URL reservation. + + + + + + + The installation fails. + + + + + + + + + + + Unique ID of this URL reservation. + If this attribute is not specified, an identifier will be generated automatically. + + + + + + + + Security descriptor to apply to the URL reservation. + Can't be specified when using children UrlAce elements. + + + + + + + + The UrlPrefix + string that defines the portion of the URL namespace to which this reservation pertains. + + + + + + + + + + The security principal and which rights to assign to them for the URL reservation. + + + + + + + Unique ID of this URL ACE. + If this attribute is not specified, an identifier will be generated automatically. + + + + + + + + The security principal for this ACE. When the UrlReservation is under a ServiceInstall element, this defaults to + "NT SERVICE\ServiceInstallName". This may be either a SID or an account name in a format that + LookupAccountName + supports. When using a SID, an asterisk must be prepended. For example, "*S-1-5-18". + + + + + + + + Rights for this ACE. Default is "all". + + + + + + + + + + + + + diff --git a/src/wixext/messages.xml b/src/wixext/messages.xml new file mode 100644 index 00000000..6dcdc366 --- /dev/null +++ b/src/wixext/messages.xml @@ -0,0 +1,13 @@ + + + + + + + + + The UrlReservation element doesn't identify the security for the reservation. You must either specify the Sddl attribute, or provide child UrlAce elements. + + + + diff --git a/src/wixext/tables.xml b/src/wixext/tables.xml new file mode 100644 index 00000000..576fc2a7 --- /dev/null +++ b/src/wixext/tables.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3-55-g6feb