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/ca/cost.h | 5 + src/ca/dllmain.cpp | 26 ++ src/ca/precomp.h | 17 ++ src/ca/wixhttpca.cpp | 525 ++++++++++++++++++++++++++++++++++ src/ca/wixhttpca.def | 9 + src/ca/wixhttpca.vcxproj | 58 ++++ src/ca/wixhttpca.vcxproj.filters | 40 +++ 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 ++ src/wixlib/HttpExtension.wixproj | 26 ++ src/wixlib/HttpExtension.wxs | 11 + src/wixlib/HttpExtension_Platform.wxi | 40 +++ src/wixlib/HttpExtension_x86.wxs | 8 + src/wixlib/en-us.wxl | 12 + 20 files changed, 1512 insertions(+) create mode 100644 src/ca/cost.h create mode 100644 src/ca/dllmain.cpp create mode 100644 src/ca/precomp.h create mode 100644 src/ca/wixhttpca.cpp create mode 100644 src/ca/wixhttpca.def create mode 100644 src/ca/wixhttpca.vcxproj create mode 100644 src/ca/wixhttpca.vcxproj.filters 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 create mode 100644 src/wixlib/HttpExtension.wixproj create mode 100644 src/wixlib/HttpExtension.wxs create mode 100644 src/wixlib/HttpExtension_Platform.wxi create mode 100644 src/wixlib/HttpExtension_x86.wxs create mode 100644 src/wixlib/en-us.wxl diff --git a/src/ca/cost.h b/src/ca/cost.h new file mode 100644 index 00000000..283758b0 --- /dev/null +++ b/src/ca/cost.h @@ -0,0 +1,5 @@ +#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. + + +const UINT COST_HTTP_URL_ACL = 2000; diff --git a/src/ca/dllmain.cpp b/src/ca/dllmain.cpp new file mode 100644 index 00000000..b4c8c037 --- /dev/null +++ b/src/ca/dllmain.cpp @@ -0,0 +1,26 @@ +// 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. + +#include "precomp.h" + +/******************************************************************** +DllMain - standard entry point for all WiX CustomActions + +********************************************************************/ +extern "C" BOOL WINAPI DllMain( + IN HINSTANCE hInstance, + IN ULONG ulReason, + IN LPVOID) +{ + switch(ulReason) + { + case DLL_PROCESS_ATTACH: + WcaGlobalInitialize(hInstance); + break; + + case DLL_PROCESS_DETACH: + WcaGlobalFinalize(); + break; + } + + return TRUE; +} diff --git a/src/ca/precomp.h b/src/ca/precomp.h new file mode 100644 index 00000000..ec74006b --- /dev/null +++ b/src/ca/precomp.h @@ -0,0 +1,17 @@ +#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. + + +#include +#include +#include + +#include "wcautil.h" +#include "cryputil.h" +#include "dutil.h" +#include "memutil.h" +#include "strutil.h" +#include "aclutil.h" + +#include "CustomMsiErrors.h" +#include "cost.h" diff --git a/src/ca/wixhttpca.cpp b/src/ca/wixhttpca.cpp new file mode 100644 index 00000000..58b46c0f --- /dev/null +++ b/src/ca/wixhttpca.cpp @@ -0,0 +1,525 @@ +// 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. + +#include "precomp.h" + +static HRESULT AppendUrlAce( + __in LPWSTR wzSecurityPrincipal, + __in int iRights, + __in LPWSTR* psczSDDL + ); +static HRESULT WriteHttpUrlReservation( + __in WCA_TODO action, + __in LPWSTR wzUrl, + __in LPWSTR wzSDDL, + __in int iHandleExisting, + __in LPWSTR* psczCustomActionData + ); +static HRESULT AddUrlReservation( + __in LPWSTR wzUrl, + __in LPWSTR wzSddl + ); +static HRESULT GetUrlReservation( + __in LPWSTR wzUrl, + __deref_out_z LPWSTR* psczSddl + ); +static HRESULT RemoveUrlReservation( + __in LPWSTR wzUrl + ); + +HTTPAPI_VERSION vcHttpVersion = HTTPAPI_VERSION_1; +ULONG vcHttpFlags = HTTP_INITIALIZE_CONFIG; + +LPCWSTR vcsHttpUrlReservationQuery = + L"SELECT `WixHttpUrlReservation`.`WixHttpUrlReservation`, `WixHttpUrlReservation`.`HandleExisting`, `WixHttpUrlReservation`.`Sddl`, `WixHttpUrlReservation`.`Url`, `WixHttpUrlReservation`.`Component_` " + L"FROM `WixHttpUrlReservation`"; +enum eHttpUrlReservationQuery { hurqId = 1, hurqHandleExisting, hurqSDDL, hurqUrl, hurqComponent }; + +LPCWSTR vcsHttpUrlAceQuery = + L"SELECT `WixHttpUrlAce`.`SecurityPrincipal`, `WixHttpUrlAce`.`Rights` " + L"FROM `WixHttpUrlAce` " + L"WHERE `WixHttpUrlAce`.`WixHttpUrlReservation_`=?"; +enum eHttpUrlAceQuery { huaqSecurityPrincipal = 1, huaqRights }; + +enum eHandleExisting { heReplace = 0, heIgnore = 1, heFail = 2 }; + +/****************************************************************** + SchedHttpUrlReservations - immediate custom action worker to + prepare configuring URL reservations. + +********************************************************************/ +static UINT SchedHttpUrlReservations( + __in MSIHANDLE hInstall, + __in WCA_TODO todoSched + ) +{ + HRESULT hr = S_OK; + UINT er = ERROR_SUCCESS; + BOOL fAceTableExists = FALSE; + BOOL fHttpInitialized = FALSE; + DWORD cUrlReservations = 0; + + PMSIHANDLE hView = NULL; + PMSIHANDLE hRec = NULL; + PMSIHANDLE hQueryReq = NULL; + PMSIHANDLE hAceView = NULL; + + LPWSTR sczCustomActionData = NULL; + LPWSTR sczRollbackCustomActionData = NULL; + + LPWSTR sczId = NULL; + LPWSTR sczComponent = NULL; + WCA_TODO todoComponent = WCA_TODO_UNKNOWN; + LPWSTR sczUrl = NULL; + LPWSTR sczSecurityPrincipal = NULL; + int iRights = 0; + int iHandleExisting = 0; + + LPWSTR sczExistingSDDL = NULL; + LPWSTR sczSDDL = NULL; + + // Initialize. + hr = WcaInitialize(hInstall, "SchedHttpUrlReservations"); + ExitOnFailure(hr, "Failed to initialize."); + + // Anything to do? + hr = WcaTableExists(L"WixHttpUrlReservation"); + ExitOnFailure(hr, "Failed to check if the WixHttpUrlReservation table exists."); + if (S_FALSE == hr) + { + WcaLog(LOGMSG_STANDARD, "WixHttpUrlReservation table doesn't exist, so there are no URL reservations to configure."); + ExitFunction(); + } + + hr = WcaTableExists(L"WixHttpUrlAce"); + ExitOnFailure(hr, "Failed to check if the WixHttpUrlAce table exists."); + fAceTableExists = S_OK == hr; + + // Query and loop through all the URL reservations. + hr = WcaOpenExecuteView(vcsHttpUrlReservationQuery, &hView); + ExitOnFailure(hr, "Failed to open view on the WixHttpUrlReservation table."); + + hr = HRESULT_FROM_WIN32(::HttpInitialize(vcHttpVersion, vcHttpFlags, NULL)); + ExitOnFailure(hr, "Failed to initialize HTTP Server configuration."); + + fHttpInitialized = TRUE; + + while (S_OK == (hr = WcaFetchRecord(hView, &hRec))) + { + hr = WcaGetRecordString(hRec, hurqId, &sczId); + ExitOnFailure(hr, "Failed to get WixHttpUrlReservation.WixHttpUrlReservation"); + + hr = WcaGetRecordString(hRec, hurqComponent, &sczComponent); + ExitOnFailure(hr, "Failed to get WixHttpUrlReservation.Component_"); + + // Figure out what we're doing for this reservation, treating reinstall the same as install. + todoComponent = WcaGetComponentToDo(sczComponent); + if ((WCA_TODO_REINSTALL == todoComponent ? WCA_TODO_INSTALL : todoComponent) != todoSched) + { + WcaLog(LOGMSG_STANDARD, "Component '%ls' action state (%d) doesn't match request (%d) for UrlReservation '%ls'.", sczComponent, todoComponent, todoSched, sczId); + continue; + } + + hr = WcaGetRecordFormattedString(hRec, hurqUrl, &sczUrl); + ExitOnFailure(hr, "Failed to get WixHttpUrlReservation.Url"); + + hr = WcaGetRecordInteger(hRec, hurqHandleExisting, &iHandleExisting); + ExitOnFailure(hr, "Failed to get WixHttpUrlReservation.HandleExisting"); + + if (::MsiRecordIsNull(hRec, hurqSDDL)) + { + hr = StrAllocString(&sczSDDL, L"D:", 2); + ExitOnFailure(hr, "Failed to allocate SDDL string."); + + // Skip creating the SDDL on uninstall, since it's never used and the lookup(s) could fail. + if (fAceTableExists && WCA_TODO_UNINSTALL != todoComponent) + { + hQueryReq = ::MsiCreateRecord(1); + hr = WcaSetRecordString(hQueryReq, 1, sczId); + ExitOnFailure(hr, "Failed to create record for querying WixHttpUrlAce table for reservation %ls", sczId); + + hr = WcaOpenView(vcsHttpUrlAceQuery, &hAceView); + ExitOnFailure(hr, "Failed to open view on WixHttpUrlAce table for reservation %ls", sczId); + hr = WcaExecuteView(hAceView, hQueryReq); + ExitOnFailure(hr, "Failed to execute view on WixHttpUrlAce table for reservation %ls", sczId); + + while (S_OK == (hr = WcaFetchRecord(hAceView, &hRec))) + { + hr = WcaGetRecordFormattedString(hRec, huaqSecurityPrincipal, &sczSecurityPrincipal); + ExitOnFailure(hr, "Failed to get WixHttpUrlAce.SecurityPrincipal"); + + hr = WcaGetRecordInteger(hRec, huaqRights, &iRights); + ExitOnFailure(hr, "Failed to get WixHttpUrlAce.Rights"); + + hr = AppendUrlAce(sczSecurityPrincipal, iRights, &sczSDDL); + ExitOnFailure(hr, "Failed to append URL ACE."); + } + + if (E_NOMOREITEMS == hr) + { + hr = S_OK; + } + ExitOnFailure(hr, "Failed to enumerate selected rows from WixHttpUrlAce table."); + } + } + else + { + hr = WcaGetRecordFormattedString(hRec, hurqSDDL, &sczSDDL); + ExitOnFailure(hr, "Failed to get WixHttpUrlReservation.SDDL"); + } + + hr = GetUrlReservation(sczUrl, &sczExistingSDDL); + ExitOnFailure(hr, "Failed to get the existing SDDL for %ls", sczUrl); + + hr = WriteHttpUrlReservation(todoComponent, sczUrl, sczExistingSDDL ? sczExistingSDDL : L"", iHandleExisting, &sczRollbackCustomActionData); + ExitOnFailure(hr, "Failed to write URL Reservation to rollback custom action data."); + + hr = WriteHttpUrlReservation(todoComponent, sczUrl, sczSDDL, iHandleExisting, &sczCustomActionData); + ExitOnFailure(hr, "Failed to write URL reservation to custom action data."); + ++cUrlReservations; + } + + // Reaching the end of the list is not an error. + if (E_NOMOREITEMS == hr) + { + hr = S_OK; + } + ExitOnFailure(hr, "Failure occurred while processing WixHttpUrlReservation table."); + + // Schedule ExecHttpUrlReservations if there's anything to do. + if (cUrlReservations) + { + WcaLog(LOGMSG_STANDARD, "Scheduling URL reservations (%ls)", sczCustomActionData); + WcaLog(LOGMSG_STANDARD, "Scheduling rollback URL reservations (%ls)", sczRollbackCustomActionData); + + if (WCA_TODO_INSTALL == todoSched) + { + hr = WcaDoDeferredAction(L"WixRollbackHttpUrlReservationsInstall", sczRollbackCustomActionData, cUrlReservations * COST_HTTP_URL_ACL); + ExitOnFailure(hr, "Failed to schedule install URL reservations rollback."); + hr = WcaDoDeferredAction(L"WixExecHttpUrlReservationsInstall", sczCustomActionData, cUrlReservations * COST_HTTP_URL_ACL); + ExitOnFailure(hr, "Failed to schedule install URL reservations execution."); + } + else + { + hr = WcaDoDeferredAction(L"WixRollbackHttpUrlReservationsUninstall", sczRollbackCustomActionData, cUrlReservations * COST_HTTP_URL_ACL); + ExitOnFailure(hr, "Failed to schedule uninstall URL reservations rollback."); + hr = WcaDoDeferredAction(L"WixExecHttpUrlReservationsUninstall", sczCustomActionData, cUrlReservations * COST_HTTP_URL_ACL); + ExitOnFailure(hr, "Failed to schedule uninstall URL reservations execution."); + } + } + else + { + WcaLog(LOGMSG_STANDARD, "No URL reservations scheduled."); + } +LExit: + ReleaseStr(sczSDDL); + ReleaseStr(sczExistingSDDL); + ReleaseStr(sczSecurityPrincipal); + ReleaseStr(sczUrl) + ReleaseStr(sczComponent); + ReleaseStr(sczId); + ReleaseStr(sczRollbackCustomActionData); + ReleaseStr(sczCustomActionData); + + if (fHttpInitialized) + { + ::HttpTerminate(vcHttpFlags, NULL); + } + + return WcaFinalize(er = FAILED(hr) ? ERROR_INSTALL_FAILURE : er); +} + +static HRESULT AppendUrlAce( + __in LPWSTR wzSecurityPrincipal, + __in int iRights, + __in LPWSTR* psczSDDL + ) +{ + HRESULT hr = S_OK; + LPCWSTR wzSid = NULL; + LPWSTR sczSid = NULL; + + Assert(wzSecurityPrincipal && *wzSecurityPrincipal); + Assert(psczSDDL && *psczSDDL); + + // As documented in the xsd, if the first char is '*', then the rest of the string is a SID string, e.g. *S-1-5-18. + if (L'*' == wzSecurityPrincipal[0]) + { + wzSid = &wzSecurityPrincipal[1]; + } + else + { + hr = AclGetAccountSidStringEx(NULL, wzSecurityPrincipal, &sczSid); + ExitOnFailure(hr, "Failed to lookup the SID for account %ls", wzSecurityPrincipal); + + wzSid = sczSid; + } + + hr = StrAllocFormatted(psczSDDL, L"%ls(A;;%#x;;;%ls)", *psczSDDL, iRights, wzSid); + +LExit: + ReleaseStr(sczSid); + + return hr; +} + +static HRESULT WriteHttpUrlReservation( + __in WCA_TODO action, + __in LPWSTR wzUrl, + __in LPWSTR wzSDDL, + __in int iHandleExisting, + __in LPWSTR* psczCustomActionData + ) +{ + HRESULT hr = S_OK; + + hr = WcaWriteIntegerToCaData(action, psczCustomActionData); + ExitOnFailure(hr, "Failed to write action to custom action data."); + + hr = WcaWriteStringToCaData(wzUrl, psczCustomActionData); + ExitOnFailure(hr, "Failed to write URL to custom action data."); + + hr = WcaWriteStringToCaData(wzSDDL, psczCustomActionData); + ExitOnFailure(hr, "Failed to write SDDL to custom action data."); + + hr = WcaWriteIntegerToCaData(iHandleExisting, psczCustomActionData); + ExitOnFailure(hr, "Failed to write HandleExisting to custom action data.") + +LExit: + return hr; +} + +/****************************************************************** + SchedHttpUrlReservationsInstall - immediate custom action entry + point to prepare adding URL reservations. + +********************************************************************/ +extern "C" UINT __stdcall SchedHttpUrlReservationsInstall( + __in MSIHANDLE hInstall + ) +{ + return SchedHttpUrlReservations(hInstall, WCA_TODO_INSTALL); +} + +/****************************************************************** + SchedHttpUrlReservationsUninstall - immediate custom action entry + point to prepare removing URL reservations. + +********************************************************************/ +extern "C" UINT __stdcall SchedHttpUrlReservationsUninstall( + __in MSIHANDLE hInstall + ) +{ + return SchedHttpUrlReservations(hInstall, WCA_TODO_UNINSTALL); +} + +/****************************************************************** + ExecHttpUrlReservations - deferred custom action entry point to + register and remove URL reservations. + +********************************************************************/ +extern "C" UINT __stdcall ExecHttpUrlReservations( + __in MSIHANDLE hInstall + ) +{ + HRESULT hr = S_OK; + BOOL fHttpInitialized = FALSE; + LPWSTR sczCustomActionData = NULL; + LPWSTR wz = NULL; + int iTodo = WCA_TODO_UNKNOWN; + LPWSTR sczUrl = NULL; + LPWSTR sczSDDL = NULL; + eHandleExisting handleExisting = heIgnore; + BOOL fRollback = ::MsiGetMode(hInstall, MSIRUNMODE_ROLLBACK); + BOOL fRemove = FALSE; + BOOL fAdd = FALSE; + BOOL fFailOnExisting = FALSE; + + // Initialize. + hr = WcaInitialize(hInstall, "ExecHttpUrlReservations"); + ExitOnFailure(hr, "Failed to initialize."); + + hr = HRESULT_FROM_WIN32(::HttpInitialize(vcHttpVersion, vcHttpFlags, NULL)); + ExitOnFailure(hr, "Failed to initialize HTTP Server configuration."); + + fHttpInitialized = TRUE; + + hr = WcaGetProperty(L"CustomActionData", &sczCustomActionData); + ExitOnFailure(hr, "Failed to get CustomActionData."); + WcaLog(LOGMSG_TRACEONLY, "CustomActionData: %ls", sczCustomActionData); + + wz = sczCustomActionData; + while (wz && *wz) + { + // Extract the custom action data and if rolling back, swap INSTALL and UNINSTALL. + hr = WcaReadIntegerFromCaData(&wz, &iTodo); + ExitOnFailure(hr, "Failed to read todo from custom action data."); + + hr = WcaReadStringFromCaData(&wz, &sczUrl); + ExitOnFailure(hr, "Failed to read Url from custom action data."); + + hr = WcaReadStringFromCaData(&wz, &sczSDDL); + ExitOnFailure(hr, "Failed to read SDDL from custom action data."); + + hr = WcaReadIntegerFromCaData(&wz, reinterpret_cast(&handleExisting)); + ExitOnFailure(hr, "Failed to read HandleExisting from custom action data."); + + switch (iTodo) + { + case WCA_TODO_INSTALL: + case WCA_TODO_REINSTALL: + fRemove = heReplace == handleExisting || fRollback; + fAdd = !fRollback || *sczSDDL; + fFailOnExisting = heFail == handleExisting && !fRollback; + break; + + case WCA_TODO_UNINSTALL: + fRemove = !fRollback; + fAdd = fRollback && *sczSDDL; + fFailOnExisting = FALSE; + break; + } + + if (fRemove) + { + WcaLog(LOGMSG_STANDARD, "Removing reservation for URL '%ls'", sczUrl); + hr = RemoveUrlReservation(sczUrl); + if (FAILED(hr)) + { + if (fRollback) + { + WcaLogError(hr, "Failed to remove reservation for URL '%ls'", sczUrl); + } + else + { + ExitOnFailure(hr, "Failed to remove reservation for URL '%ls'", sczUrl); + } + } + } + if (fAdd) + { + WcaLog(LOGMSG_STANDARD, "Adding reservation for URL '%ls' with SDDL '%ls'", sczUrl, sczSDDL); + hr = AddUrlReservation(sczUrl, sczSDDL); + if (S_FALSE == hr && fFailOnExisting) + { + hr = HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS); + } + if (FAILED(hr)) + { + if (fRollback) + { + WcaLogError(hr, "Failed to add reservation for URL '%ls' with SDDL '%ls'", sczUrl, sczSDDL); + } + else + { + ExitOnFailure(hr, "Failed to add reservation for URL '%ls' with SDDL '%ls'", sczUrl, sczSDDL); + } + } + } + } + +LExit: + ReleaseStr(sczSDDL); + ReleaseStr(sczUrl); + ReleaseStr(sczCustomActionData); + + if (fHttpInitialized) + { + ::HttpTerminate(vcHttpFlags, NULL); + } + + return WcaFinalize(FAILED(hr) ? ERROR_INSTALL_FAILURE : ERROR_SUCCESS); +} + +static HRESULT AddUrlReservation( + __in LPWSTR wzUrl, + __in LPWSTR wzSddl + ) +{ + HRESULT hr = S_OK; + DWORD er = ERROR_SUCCESS; + HTTP_SERVICE_CONFIG_URLACL_SET set = { }; + + set.KeyDesc.pUrlPrefix = wzUrl; + set.ParamDesc.pStringSecurityDescriptor = wzSddl; + + er = ::HttpSetServiceConfiguration(NULL, HttpServiceConfigUrlAclInfo, &set, sizeof(set), NULL); + if (ERROR_ALREADY_EXISTS == er) + { + hr = S_FALSE; + } + else + { + hr = HRESULT_FROM_WIN32(er); + } + ExitOnFailure(hr, "Failed to add URL reservation: %ls, ACL: %ls", wzUrl, wzSddl); + +LExit: + return hr; +} + +static HRESULT GetUrlReservation( + __in LPWSTR wzUrl, + __deref_out_z LPWSTR* psczSddl + ) +{ + HRESULT hr = S_OK; + DWORD er = ERROR_SUCCESS; + HTTP_SERVICE_CONFIG_URLACL_QUERY query = { }; + HTTP_SERVICE_CONFIG_URLACL_SET* pSet = NULL; + ULONG cbSet = 0; + + query.QueryDesc = HttpServiceConfigQueryExact; + query.KeyDesc.pUrlPrefix = wzUrl; + + er = ::HttpQueryServiceConfiguration(NULL, HttpServiceConfigUrlAclInfo, &query, sizeof(query), pSet, cbSet, &cbSet, NULL); + if (ERROR_INSUFFICIENT_BUFFER == er) + { + pSet = reinterpret_cast(MemAlloc(cbSet, TRUE)); + ExitOnNull(pSet, hr, E_OUTOFMEMORY, "Failed to allocate query URLACL buffer."); + + er = ::HttpQueryServiceConfiguration(NULL, HttpServiceConfigUrlAclInfo, &query, sizeof(query), pSet, cbSet, &cbSet, NULL); + } + + if (ERROR_SUCCESS == er) + { + hr = StrAllocString(psczSddl, pSet->ParamDesc.pStringSecurityDescriptor, 0); + } + else if (ERROR_FILE_NOT_FOUND == er) + { + hr = S_FALSE; + } + else + { + hr = HRESULT_FROM_WIN32(er); + } + +LExit: + ReleaseMem(pSet); + + return hr; +} + +static HRESULT RemoveUrlReservation( + __in LPWSTR wzUrl + ) +{ + HRESULT hr = S_OK; + DWORD er = ERROR_SUCCESS; + HTTP_SERVICE_CONFIG_URLACL_SET set = { }; + + set.KeyDesc.pUrlPrefix = wzUrl; + + er = ::HttpDeleteServiceConfiguration(NULL, HttpServiceConfigUrlAclInfo, &set, sizeof(set), NULL); + if (ERROR_FILE_NOT_FOUND == er) + { + hr = S_FALSE; + } + else + { + hr = HRESULT_FROM_WIN32(er); + } + ExitOnFailure(hr, "Failed to remove URL reservation: %ls", wzUrl); + +LExit: + return hr; +} diff --git a/src/ca/wixhttpca.def b/src/ca/wixhttpca.def new file mode 100644 index 00000000..5368c946 --- /dev/null +++ b/src/ca/wixhttpca.def @@ -0,0 +1,9 @@ +; 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. + + +LIBRARY "wixhttpca" + +EXPORTS + SchedHttpUrlReservationsInstall + SchedHttpUrlReservationsUninstall + ExecHttpUrlReservations diff --git a/src/ca/wixhttpca.vcxproj b/src/ca/wixhttpca.vcxproj new file mode 100644 index 00000000..89dbc79a --- /dev/null +++ b/src/ca/wixhttpca.vcxproj @@ -0,0 +1,58 @@ + + + + + + + + Debug + Win32 + + + Release + Win32 + + + + + Debug + ARM + + + Release + ARM + + + + + {90743805-C043-47C7-B5FF-8F5EE5C8A2DE} + DynamicLibrary + Unicode + wixhttpca + wixhttpca.def + + + + + + $(WixRoot)src\libs\dutil\inc;$(WixRoot)src\libs\wcautil + crypt32.lib;httpapi.lib;msi.lib;dutil.lib;wcautil.lib + + + + + + + + + + + + + + + + + + + diff --git a/src/ca/wixhttpca.vcxproj.filters b/src/ca/wixhttpca.vcxproj.filters new file mode 100644 index 00000000..354653c1 --- /dev/null +++ b/src/ca/wixhttpca.vcxproj.filters @@ -0,0 +1,40 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + + + Header Files + + + + + Resource Files + + + + + Source Files + + + \ No newline at end of file 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 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/wixlib/HttpExtension.wixproj b/src/wixlib/HttpExtension.wixproj new file mode 100644 index 00000000..738579db --- /dev/null +++ b/src/wixlib/HttpExtension.wixproj @@ -0,0 +1,26 @@ + + + + + + + {055C1517-4CED-4199-BCDE-A383E5C4EF78} + http + Library + true + true + en-us + + + + + + + + + + + + + + diff --git a/src/wixlib/HttpExtension.wxs b/src/wixlib/HttpExtension.wxs new file mode 100644 index 00000000..e2b3534d --- /dev/null +++ b/src/wixlib/HttpExtension.wxs @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/src/wixlib/HttpExtension_Platform.wxi b/src/wixlib/HttpExtension_Platform.wxi new file mode 100644 index 00000000..11c3aa2b --- /dev/null +++ b/src/wixlib/HttpExtension_Platform.wxi @@ -0,0 +1,40 @@ + + + + + + + + + + !(loc.WixSchedHttpUrlReservationsInstall) + !(loc.WixSchedHttpUrlReservationsUninstall) + !(loc.WixRollbackHttpUrlReservationsInstall) + !(loc.WixExecHttpUrlReservationsInstall) + !(loc.WixRollbackHttpUrlReservationsUninstall) + !(loc.WixExecHttpUrlReservationsUninstall) + + + + + + + + + + + + + = 600 OR (VersionNT >= 501 AND ((MsiNTProductType = 1 AND ServicePackLevel >= 2) OR (MsiNTProductType > 1))) ]]> + + + = 600 OR (VersionNT >= 501 AND ((MsiNTProductType = 1 AND ServicePackLevel >= 2) OR (MsiNTProductType > 1))) ]]> + + + + + + + diff --git a/src/wixlib/HttpExtension_x86.wxs b/src/wixlib/HttpExtension_x86.wxs new file mode 100644 index 00000000..00a3dc18 --- /dev/null +++ b/src/wixlib/HttpExtension_x86.wxs @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/wixlib/en-us.wxl b/src/wixlib/en-us.wxl new file mode 100644 index 00000000..2c43af06 --- /dev/null +++ b/src/wixlib/en-us.wxl @@ -0,0 +1,12 @@ + + + + + + Preparing to configure Windows HTTP Server + Preparing to configure Windows HTTP Server + Rolling back Windows HTTP Server configuration + Configuring Windows HTTP Server + Rolling back Windows HTTP Server configuration + Configuring Windows HTTP Server + -- cgit v1.2.3-55-g6feb