From e71f6840420175069ee23ae43a8db4d7ee540f8b Mon Sep 17 00:00:00 2001 From: Mark Yen Date: Fri, 17 Jan 2025 13:51:56 -0800 Subject: [PATCH] wsl-helper: Remove unused wix custom action code Since we no longer attempt to install WSL as part of our installer, we can remove the code that was used to do so. Signed-off-by: Mark Yen --- .github/actions/spelling/expect.txt | 2 +- .../wsl-helper/pkg/wsl-utils/dism_windows.go | 123 ------------------ .../pkg/wsl-utils/install_windows.go | 22 ---- src/go/wsl-helper/wix/install_windows.go | 44 ------- src/go/wsl-helper/wix/main_windows.go | 20 --- 5 files changed, 1 insertion(+), 210 deletions(-) delete mode 100644 src/go/wsl-helper/pkg/wsl-utils/dism_windows.go diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt index 2ea444b1ca4..888be6c0d38 100644 --- a/.github/actions/spelling/expect.txt +++ b/.github/actions/spelling/expect.txt @@ -337,7 +337,7 @@ HOSTPORT hoverable howett hpa -hresult +HRESULT htpasswd httpconfig Huawei diff --git a/src/go/wsl-helper/pkg/wsl-utils/dism_windows.go b/src/go/wsl-helper/pkg/wsl-utils/dism_windows.go deleted file mode 100644 index 44663d8ba99..00000000000 --- a/src/go/wsl-helper/pkg/wsl-utils/dism_windows.go +++ /dev/null @@ -1,123 +0,0 @@ -/* -Copyright © 2023 SUSE LLC - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package wslutils - -// This file is a helper for interacting with the Windows Deployment Image -// Servicing and Management (DISM) APIs. It lets us install Windows optional -// features with logging. - -import ( - "context" - "fmt" - "math" - "unsafe" - - "github.com/sirupsen/logrus" - "golang.org/x/sys/windows" -) - -type dismSession uint - -const ( - // kWindowsFeature is the name of the Windows feature that needs to be - // installed. - kWindowsFeature = "VirtualMachinePlatform" - // DISM_ONLINE_IMAGE is the DISM "image path" that signifies we're trying - // to modify the running Windows installation. - //nolint:stylecheck // Win32 constant - DISM_ONLINE_IMAGE = "DISM_{53BFAE52-B167-4E2F-A258-0A37B57FF845}" - DismLogErrorsWarningsInfo = 2 -) - -var ( - dllDismAPI = windows.NewLazySystemDLL("dismapi.dll") - dismInitialize = dllDismAPI.NewProc("DismInitialize") - dismOpenSession = dllDismAPI.NewProc("DismOpenSession") - dismCloseSession = dllDismAPI.NewProc("DismCloseSession") - dismEnableFeature = dllDismAPI.NewProc("DismEnableFeature") -) - -func errorFromHResult(hr int32, err error) error { - var result error - if hr < 0 { - result = windows.Errno(hr) - if err != nil { - result = fmt.Errorf("%w: %w", result, err) - } - return result - } - return nil -} - -// DismDoInstall installs the Virtual Machine Platform Windows feature. -func DismDoInstall(ctx context.Context, log *logrus.Entry) error { - var session dismSession - - hr, _, err := dismInitialize.Call( - uintptr(DismLogErrorsWarningsInfo), - uintptr(unsafe.Pointer(nil)), - uintptr(unsafe.Pointer(nil)), - ) - err = errorFromHResult(int32(hr), err) - if err != nil { - return fmt.Errorf("error initializing DISM: %w", err) - } - - buf, err := windows.UTF16PtrFromString(DISM_ONLINE_IMAGE) - if err != nil { - log.WithError(err).Error("Failed to convert DISM_ONLINE_IMAGE") - return err - } - hr, _, err = dismOpenSession.Call( - uintptr(unsafe.Pointer(buf)), - uintptr(unsafe.Pointer(nil)), - uintptr(unsafe.Pointer(nil)), - uintptr(unsafe.Pointer(&session)), - ) - if hr != uintptr(windows.S_OK) { - return errorFromWin32("failed to open DISM session", hr&math.MaxUint16, err) - } - defer func() { _, _, _ = dismCloseSession.Call(uintptr(session)) }() - - if buf, err = windows.UTF16PtrFromString(kWindowsFeature); err != nil { - log.WithError(err).Error("Failed to convert kWindowsFeature") - return err - } - - hr, _, err = dismEnableFeature.Call( - uintptr(session), - uintptr(unsafe.Pointer(buf)), - uintptr(unsafe.Pointer(nil)), // Identifier - uintptr(unsafe.Pointer(nil)), // PackageIdentifier - uintptr(0), // LimitAccess - uintptr(unsafe.Pointer(nil)), // SourcePaths - uintptr(0), // SourcePathCount - uintptr(1), // EnableAll - uintptr(unsafe.Pointer(nil)), // CancelEvent - uintptr(unsafe.Pointer(nil)), // Progress - uintptr(unsafe.Pointer(nil)), // UserData - ) - if hr != uintptr(windows.ERROR_SUCCESS_REBOOT_REQUIRED) { - log.WithError(err).WithField("hr", fmt.Sprintf("%08x", hr)).Trace("DismEnableFeature") - } - err = errorFromHResult(int32(hr), err) - if err != nil { - return fmt.Errorf("error enabling feature %q: %w", kWindowsFeature, err) - } - log.Tracef("Windows feature %q enabled", kWindowsFeature) - return nil -} diff --git a/src/go/wsl-helper/pkg/wsl-utils/install_windows.go b/src/go/wsl-helper/pkg/wsl-utils/install_windows.go index b5a9f6aa5f3..ac155cdda83 100644 --- a/src/go/wsl-helper/pkg/wsl-utils/install_windows.go +++ b/src/go/wsl-helper/pkg/wsl-utils/install_windows.go @@ -9,28 +9,6 @@ import ( "golang.org/x/sys/windows" ) -// InstallWSL runs wsl.exe to install WSL. -func InstallWSL(ctx context.Context, log *logrus.Entry) error { - // wsl.exe calls wslapi.dll, which eventually uses the WinRT API - // Windows.ApplicationModel.Store.Preview.InstallControl — but that is - // (according to docs) private and only usable by Microsoft-signed apps. - // Just spawn wsl.exe and hope it does the job. Trying to reverse-engineer - // the WslInstaller COM component seems error-prone, and it will likely - // change in the future. Unfortunately, this means more UAC prompts. - newRunnerFunc := NewWSLRunner - if f := ctx.Value(&kWSLExeOverride); f != nil { - newRunnerFunc = f.(func() WSLRunner) - } - // WSL install hangs if we set stdout; don't set that here. - err := newRunnerFunc(). - WithStderr(log.WriterLevel(logrus.InfoLevel)). - Run(ctx, "--install", "--no-distribution") - if err != nil { - return err - } - return nil -} - // UpdateWSL runs wsl.exe to update the WSL kernel. This assumes that WSL had // already been installed. This may request elevation. func UpdateWSL(ctx context.Context, log *logrus.Entry) error { diff --git a/src/go/wsl-helper/wix/install_windows.go b/src/go/wsl-helper/wix/install_windows.go index 0eef14440d7..f388433b868 100644 --- a/src/go/wsl-helper/wix/install_windows.go +++ b/src/go/wsl-helper/wix/install_windows.go @@ -32,50 +32,6 @@ func setupLogger(hInstall MSIHANDLE) *logrus.Entry { }) } -// InstallWindowsFeatureImpl installs the Windows features necessary for WSL to -// be installed. This needs to be run elevated. -func InstallWindowsFeatureImpl(hInstall MSIHANDLE) uint32 { - ctx := context.Background() - log := setupLogger(hInstall) - - log.Infof("Installing Windows feature...") - err := submitMessage(hInstall, INSTALLMESSAGE_ACTIONSTART, []string{ - "", "InstalWindowsFeature", "Installing required Windows features...", "", - }) - if err != nil { - log.WithError(err).Info("Failed to update progress") - } - if err := wslutils.DismDoInstall(ctx, log); err != nil { - log.WithError(err).Error("Failed to install feature") - return 1 - } - - return 0 -} - -// InstallWSLImpl installs WSL. -// This assumes WSL was not previously installed. -// This needs to be run as the user. -func InstallWSLImpl(hInstall MSIHANDLE) uint32 { - ctx := context.Background() - log := setupLogger(hInstall) - - log.Info("Installing WSL...") - err := submitMessage(hInstall, INSTALLMESSAGE_ACTIONSTART, []string{ - "", "InstallWSL", "Installing Windows Subsystem for Linux...", "", - }) - if err != nil { - log.WithError(err).Info("Failed to update progress") - } - if err := wslutils.InstallWSL(ctx, log); err != nil { - log.WithError(err).Error("Installing WSL failed") - return 1 - } - - log.Info("WSL successfully installed.") - return 0 -} - // UpdateWSLImpl updates the previously installed WSL. // This needs to be run as the user, and may request elevation. func UpdateWSLImpl(hInstall MSIHANDLE) uint32 { diff --git a/src/go/wsl-helper/wix/main_windows.go b/src/go/wsl-helper/wix/main_windows.go index f4651e59379..22bd72bae9d 100644 --- a/src/go/wsl-helper/wix/main_windows.go +++ b/src/go/wsl-helper/wix/main_windows.go @@ -32,26 +32,6 @@ func DetectWSL(hInstall C.ulong) C.ulong { return C.ulong(DetectWSLImpl(MSIHANDLE(hInstall))) } -// InstallWindowsFeature is a wrapper around InstallWindowsFeature; this is the -// stub to be exported in the DLL. This only exists to limit cgo to this file -// so that editing on a machine that requires cross compilation can avoid -// needing a cross cgo toolchain. -// -//export InstallWindowsFeature -func InstallWindowsFeature(hInstall C.ulong) C.ulong { - return C.ulong(InstallWindowsFeatureImpl(MSIHANDLE(hInstall))) -} - -// InstallWSL is a wrapper around InstallWSLImpl; this is the stub to be -// exported in the DLL. This only exists to limit cgo to this file so that -// editing on a machine that requires cross compilation can avoid needing a -// cross cgo toolchain. -// -//export InstallWSL -func InstallWSL(hInstall C.ulong) C.ulong { - return C.ulong(InstallWSLImpl(MSIHANDLE(hInstall))) -} - // UpdateWSL is a wrapper around UpdateWSLImpl; this is the stub to be exported // in the DLL. This only exists to limit cgo to this file so that editing on a // machine that requires cross compilation can avoid needing a cross cgo