Skip to content

Commit

Permalink
MSM: Add support for MSM building
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Rozman <simon@rozman.si>
  • Loading branch information
rozmansi authored and mattock committed Jul 3, 2020
1 parent 6056bc8 commit 7f0433a
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,6 +4,7 @@ dist/**
*.pyc
*.tar.gz
tap-windows-*.exe
tap-windows-*.msm

# builttap.py-generated files
src/config.h
Expand Down
2 changes: 2 additions & 0 deletions README.rst
Expand Up @@ -20,6 +20,7 @@ The prerequisites for building are:
- Git (not strictly required, but useful for running commands using bundled bash shell)
- MakeNSIS (optional)
- Prebuilt tapinstall.exe binaries (optional)
- WiX Toolset (optional)

Make sure you add Python's install directory (usually c:\\python27) to the PATH
environment variable.
Expand All @@ -44,6 +45,7 @@ View build script options::
--sdk=SDK SDK to use for building: ewdk or wdk, default=ewdk
--sign sign the driver files
-p, --package generate an NSIS installer from the compiled files
-m, --package-msm generate a MSM installer from the compiled files
--cert=CERT Common name of code signing certificate,
default=openvpn
--certfile=CERTFILE Path to the code signing certificate
Expand Down
18 changes: 17 additions & 1 deletion buildtap.py
Expand Up @@ -198,7 +198,7 @@ def config_tap(self):
self.preprocess(kv, os.path.join(self.src, "OemVista.inf"))
self.preprocess(kv, os.path.join(self.src, "tap-windows6.vcxproj"))
self.preprocess(kv, os.path.join(self.src, "config.h"))
self.preprocess(kv, os.path.join(self.msm, "resource.rc"))
self.preprocess(kv, os.path.join(self.msm, "config.props"))

# build a "msbuild" file using (E)WDK
def build_ewdk(self, project_file, arch):
Expand Down Expand Up @@ -334,6 +334,18 @@ def package(self):
if self.codesign:
self.sign(installer_file)

# build MSM installer
def package_msm(self):
self.config_tap()
project_file = os.path.join(self.msm, "installer.vcxproj")
for arch in ("i386", "amd64"): #self.architectures_supported
print("***** BUILD MSM arch=%s" % (arch,))
self.run_ewdk('msbuild.exe %s /t:MSM /p:Configuration=%s /p:Platform=%s' % (
project_file,
self.configuration,
self.architecture_platform_map[arch]
))

# like find . | sort
def enum_tree(self, dir):
data = []
Expand Down Expand Up @@ -484,6 +496,8 @@ def sign_verify_ti(self, arch):
default=False, help="sign the driver files")
op.add_option("-p", "--package", action="store_true", dest="package",
help="generate an NSIS installer from the compiled files")
op.add_option("-m", "--package-msm", action="store_true", dest="package_msm",
help="generate a MSM installer from the compiled files")
op.add_option("--cert", dest="cert", metavar="CERT",
default=cert,
help="Common name of code signing certificate, default=%s" % (cert,))
Expand Down Expand Up @@ -513,3 +527,5 @@ def sign_verify_ti(self, arch):
btw.build()
if opt.package:
btw.package()
if opt.package_msm:
btw.package_msm()
2 changes: 1 addition & 1 deletion msm/.gitignore
Expand Up @@ -2,4 +2,4 @@
/Debug
/Release
/x64
/resource.rc
/config.props
28 changes: 28 additions & 0 deletions msm/config.props.in
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
SPDX-License-Identifier: GPL-2.0
Copyright (C) 2020 Simon Rozman. All Rights Reserved.
-->
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProductName>@PRODUCT_NAME@</ProductName>
<ProductPublisher>@PRODUCT_PUBLISHER@</ProductPublisher>
<ProductVersion>@PRODUCT_VERSION@</ProductVersion>
<ProductVersionResource>@PRODUCT_VERSION_RESOURCE@</ProductVersionResource>
<ProductTapWinComponentId>@PRODUCT_TAP_WIN_COMPONENT_ID@</ProductTapWinComponentId>
<ProductTapWinMajor>@PRODUCT_TAP_WIN_MAJOR@</ProductTapWinMajor>
<ProductTapWinMinor>@PRODUCT_TAP_WIN_MINOR@</ProductTapWinMinor>
<ProductTapWinRevision>@PRODUCT_TAP_WIN_REVISION@</ProductTapWinRevision>
<ProductTapWinBuild>@PRODUCT_TAP_WIN_BUILD@</ProductTapWinBuild>
<ProductTapWinProvider>@PRODUCT_TAP_WIN_PROVIDER@</ProductTapWinProvider>
<ProductTapWinCharacteristics>@PRODUCT_TAP_WIN_CHARACTERISTICS@</ProductTapWinCharacteristics>
<ProductTapWinDeviceDescription>@PRODUCT_TAP_WIN_DEVICE_DESCRIPTION@</ProductTapWinDeviceDescription>
<ProductTapWinReldate>@PRODUCT_TAP_WIN_RELDATE@</ProductTapWinReldate>

<WixCandleFlags>$(WixCandleFlags) -dPRODUCT_NAME="@PRODUCT_NAME@"</WixCandleFlags>
<WixCandleFlags>$(WixCandleFlags) -dPRODUCT_PUBLISHER="@PRODUCT_PUBLISHER@"</WixCandleFlags>
<WixCandleFlags>$(WixCandleFlags) -dPRODUCT_VERSION="@PRODUCT_VERSION@"</WixCandleFlags>
<WixCandleFlags>$(WixCandleFlags) -dPRODUCT_TAP_WIN_COMPONENT_ID="@PRODUCT_TAP_WIN_COMPONENT_ID@"</WixCandleFlags>
</PropertyGroup>
</Project>
53 changes: 52 additions & 1 deletion msm/installer.vcxproj
Expand Up @@ -34,6 +34,18 @@
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Platform)'=='Win32'">
<WixArch>x86</WixArch>
<OpenVPNPlatform>i386</OpenVPNPlatform>
</PropertyGroup>
<PropertyGroup Condition="'$(Platform)'=='x64'">
<WixArch>x64</WixArch>
<OpenVPNPlatform>amd64</OpenVPNPlatform>
</PropertyGroup>
<PropertyGroup Condition="'$(Platform)'=='ARM64'">
<WixArch>arm64</WixArch>
<OpenVPNPlatform>arm64</OpenVPNPlatform>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
Expand Down Expand Up @@ -80,28 +92,43 @@
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="config.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="config.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="config.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="config.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="config.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="config.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<WixCandleFlags>$(WixCandleFlags) -nologo -arch $(WixArch) -dPLATFORM=$(Platform) -sw1086</WixCandleFlags>
<WixLightFlags>$(WixLightFlags) -nologo -b output_dir="$(OutDir.TrimEnd('\'))" -spdb -sw1076 -sw1079</WixLightFlags>
<WixOutputPath>$(OutDir)</WixOutputPath>
<WixOutputName>tap-windows</WixOutputName>
<WixOutputExt>.msm</WixOutputExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<LinkIncremental>false</LinkIncremental>
<WixOutputPath>..\</WixOutputPath>
<WixOutputName>tap-windows-$(ProductVersion)-I$(ProductTapWinBuild)-$(OpenVPNPlatform)</WixOutputName>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
Expand All @@ -112,6 +139,9 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>DRIVER_INF=OemVista.inf;DRIVER_CAT=$(ProductTapWinComponentId).cat;DRIVER_SYS=$(ProductTapWinComponentId).sys;DRIVER_INF_WHQL=win10\\OemVista.inf;DRIVER_CAT_WHQL=win10\\$(ProductTapWinComponentId).cat;DRIVER_SYS_WHQL=win10\\$(ProductTapWinComponentId).sys;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
<Link>
<SubSystem>Windows</SubSystem>
<AdditionalDependencies>Cfgmgr32.lib;Crypt32.lib;Msi.lib;Newdev.lib;ntdll.lib;Setupapi.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
Expand Down Expand Up @@ -189,9 +219,30 @@
</ItemGroup>
<ItemGroup>
<None Include="exports.def" />
<None Include="resource.rc.in" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
<PropertyGroup>
<MSMDependsOn>$(MSMDependsOn);WixCompile;WixLink</MSMDependsOn>
<CleanDependsOn>WixClean;$(CleanDependsOn)</CleanDependsOn>
</PropertyGroup>
<Target Name="HashInstallerLibrary" DependsOnTargets="Build">
<GetFileHash Files="$(OutDir)$(TargetName)$(TargetExt)" Algorithm="SHA256" HashEncoding="hex">
<Output TaskParameter="Items" ItemName="InstallerLibraryHash" />
</GetFileHash>
<PropertyGroup>
<WixCandleFlags>$(WixCandleFlags) -dINSTALLER_LIBRARY_HASH=@(InstallerLibraryHash-&gt;Metadata('FileHash')) -dINSTALLER_LIBRARY_TIME=$([System.IO.File]::GetLastWriteTime('$(OutDir)$(TargetName)$(TargetExt)').Ticks)</WixCandleFlags>
</PropertyGroup>
</Target>
<Target Name="WixCompile" DependsOnTargets="HashInstallerLibrary" Inputs="installer.wxs" Outputs="$(IntDir)installer.wixobj">
<Exec Command="&quot;$(WIX)bin\candle.exe&quot; $(WixCandleFlags) -out &quot;$(IntDir)installer.wixobj&quot; installer.wxs" />
</Target>
<Target Name="WixLink" DependsOnTargets="Build;WixCompile" Inputs="$(IntDir)installer.wixobj;$(OutDir)$(TargetName)$(TargetExt)" Outputs="$(WixOutputPath)$(WixOutputName)$(WixOutputExt)">
<Exec Command="&quot;$(WIX)bin\light.exe&quot; $(WixLightFlags) -out &quot;$(WixOutputPath)$(WixOutputName)$(WixOutputExt)&quot; &quot;$(IntDir)installer.wixobj&quot;" />
</Target>
<Target Name="WixClean">
<Delete Files="$(IntDir)installer.wixobj;$(WixOutputPath)$(WixOutputName)$(WixOutputExt)" />
</Target>
<Target Name="MSM" DependsOnTargets="$(MSMDependsOn)" />
</Project>
3 changes: 0 additions & 3 deletions msm/installer.vcxproj.filters
Expand Up @@ -48,8 +48,5 @@
<None Include="exports.def">
<Filter>Source Files</Filter>
</None>
<None Include="resource.rc.in">
<Filter>Resource Files</Filter>
</None>
</ItemGroup>
</Project>
51 changes: 51 additions & 0 deletions msm/installer.wxs
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
SPDX-License-Identifier: GPL-2.0
Copyright (C) 2018-2019 WireGuard LLC. All Rights Reserved.
-->
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Module Id="$(var.PRODUCT_TAP_WIN_COMPONENT_ID)" Language="0" Version="$(var.PRODUCT_VERSION)">
<Package
Id="8d9a59ba-33c1-4ca0-96af-e7f728dec8d7"
Description="$(var.PRODUCT_NAME)"
Manufacturer="$(var.PRODUCT_PUBLISHER)"
InstallerVersion="200"
InstallPrivileges="elevated"
InstallScope="perMachine"
ReadOnly="yes" />

<Directory Id="TARGETDIR" Name="SourceDir">
<Component Guid="b937efa3-ce00-4e5b-86c8-8cb67a32d448">
<RegistryValue
Root="HKLM"
Key="SOFTWARE\$(var.PRODUCT_TAP_WIN_COMPONENT_ID)"
Type="integer"
Value="1"
KeyPath="yes" />
</Component>
</Directory>

<Property Id="$(var.PRODUCT_TAP_WIN_COMPONENT_ID)_InstallerHash" Value="$(var.INSTALLER_LIBRARY_HASH)" SuppressModularization="yes" />
<Property Id="$(var.PRODUCT_TAP_WIN_COMPONENT_ID)_InstallerBuildtime" Value="$(var.INSTALLER_LIBRARY_TIME)" SuppressModularization="yes" />
<Property Id="$(var.PRODUCT_TAP_WIN_COMPONENT_ID)_Version" Value="$(var.PRODUCT_VERSION)" SuppressModularization="yes" />

<Binary Id="installer.dll" SourceFile="!(bindpath.output_dir)installer.dll" />
<CustomAction Id="$(var.PRODUCT_TAP_WIN_COMPONENT_ID)_Evaluate" SuppressModularization="yes" BinaryKey="installer.dll" DllEntry="MsiEvaluate" Execute="immediate" />
<CustomAction Id="$(var.PRODUCT_TAP_WIN_COMPONENT_ID)_Process" SuppressModularization="yes" BinaryKey="installer.dll" DllEntry="MsiProcess" Execute="deferred" Impersonate="no" />
<InstallExecuteSequence>
<Custom Action="$(var.PRODUCT_TAP_WIN_COMPONENT_ID)_Evaluate" Before="$(var.PRODUCT_TAP_WIN_COMPONENT_ID)_Process" />
<Custom Action="$(var.PRODUCT_TAP_WIN_COMPONENT_ID)_Process" After="InstallFiles" />
</InstallExecuteSequence>

<?if $(var.PLATFORM) = "Win32"?>
<CustomAction Id="WoW64Unsupported" Error="You are attempting to install the 32-bit variant of [ProductName] on a 64-bit operating system, which is not supported. Please install the 64-bit variant instead." />
<InstallExecuteSequence>
<Custom Action="WoW64Unsupported" After="LaunchConditions"><![CDATA[VersionNT64]]></Custom>
</InstallExecuteSequence>
<InstallUISequence>
<Custom Action="WoW64Unsupported" After="LaunchConditions"><![CDATA[VersionNT64]]></Custom>
</InstallUISequence>
<?endif?>
</Module>
</Wix>
10 changes: 5 additions & 5 deletions msm/msi.c
Expand Up @@ -9,15 +9,15 @@

static MSIHANDLE MsiHandle;

#define ANCHOR_COMPONENT TEXT("{B668D4C7-ABB3-485A-B8DF-D34200489A43}")
#define PROCESS_ACTION TEXT("Process") TEXT(PRODUCT_TAP_WIN_COMPONENT_ID)
#define ANCHOR_COMPONENT TEXT("{B937EFA3-CE00-4E5B-86C8-8CB67A32D448}")
#define PROCESS_ACTION TEXT(PRODUCT_TAP_WIN_COMPONENT_ID) TEXT("_Process")
#define ACTION_INSTALL TEXT("/Action=Install")
#define ACTION_INSTALL_SEPERATOR TEXT('-')
#define ACTION_INSTALL_SEPERATORS TEXT("-%s-%s-%s")
#define ACTION_UNINSTALL TEXT("/Action=Uninstall")
#define PROPERTY_INSTALLER_HASH TEXT(PRODUCT_TAP_WIN_COMPONENT_ID) TEXT("InstallerHash")
#define PROPERTY_INSTALLER_BUILDTIME TEXT(PRODUCT_TAP_WIN_COMPONENT_ID) TEXT("InstallerBuildtime")
#define PROPERTY_VERSION TEXT(PRODUCT_TAP_WIN_COMPONENT_ID) TEXT("Version")
#define PROPERTY_INSTALLER_HASH TEXT(PRODUCT_TAP_WIN_COMPONENT_ID) TEXT("_InstallerHash")
#define PROPERTY_INSTALLER_BUILDTIME TEXT(PRODUCT_TAP_WIN_COMPONENT_ID) TEXT("_InstallerBuildtime")
#define PROPERTY_VERSION TEXT(PRODUCT_TAP_WIN_COMPONENT_ID) TEXT("_Version")
#define REGKEY_DRIVER TEXT("Software\\") TEXT(PRODUCT_TAP_WIN_COMPONENT_ID)
#define REGKEY_INSTALLER_HASH TEXT("InstallerHash")
#define REGKEY_INSTALLER_BUILDTIME TEXT("InstallerBuildtime")
Expand Down
14 changes: 14 additions & 0 deletions msm/resource.rc
@@ -0,0 +1,14 @@
/* SPDX-License-Identifier: GPL-2.0
*
* Copyright (C) 2018-2019 WireGuard LLC. All Rights Reserved.
*/

#ifndef _M_ARM64
driver.inf RCDATA DRIVER_INF
driver.cat RCDATA DRIVER_CAT
driver.sys RCDATA DRIVER_SYS
#endif

driver-whql.inf RCDATA DRIVER_INF_WHQL
driver-whql.cat RCDATA DRIVER_CAT_WHQL
driver-whql.sys RCDATA DRIVER_SYS_WHQL
16 changes: 0 additions & 16 deletions msm/resource.rc.in

This file was deleted.

0 comments on commit 7f0433a

Please sign in to comment.