From 5497595090365767eda4050192b6aa8f855c3061 Mon Sep 17 00:00:00 2001 From: Vladimir Stoilov Date: Tue, 26 Nov 2024 11:43:15 +0200 Subject: [PATCH] [service] Fix minor windows permission bugs --- base/utils/atomic.go | 4 ++-- cmds/portmaster-start/run.go | 9 ++------- service/updates/helper/electron.go | 7 +------ 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/base/utils/atomic.go b/base/utils/atomic.go index 6bd2d6b1d..7a6e39078 100644 --- a/base/utils/atomic.go +++ b/base/utils/atomic.go @@ -6,7 +6,7 @@ import ( "io" "io/fs" "os" - "path" + "path/filepath" "runtime" "github.com/hectane/go-acl" @@ -44,7 +44,7 @@ func CreateAtomic(dest string, r io.Reader, opts *AtomicFileOptions) error { if opts.Mode != 0 { if runtime.GOOS == "windows" { - err = acl.Chmod(path.Join(opts.TempDir, dest), opts.Mode) + err = acl.Chmod(filepath.Join(opts.TempDir, dest), opts.Mode) } else { err = tmpFile.Chmod(opts.Mode) } diff --git a/cmds/portmaster-start/run.go b/cmds/portmaster-start/run.go index 8b25e8485..98e86927b 100644 --- a/cmds/portmaster-start/run.go +++ b/cmds/portmaster-start/run.go @@ -261,7 +261,7 @@ func runAndRestart(opts *Options, args []string) error { func fixExecPerm(path string) error { if onWindows { - return nil + return acl.Chmod(path, 0o0755) } info, err := os.Stat(path) @@ -273,12 +273,7 @@ func fixExecPerm(path string) error { return nil } - if runtime.GOOS == "windows" { - err = acl.Chmod(path, 0o0755) - } else { - err = os.Chmod(path, 0o0755) - } - if err != nil { //nolint:gosec + if err := os.Chmod(path, 0o0755); err != nil { //nolint:gosec return fmt.Errorf("failed to chmod %s: %w", path, err) } diff --git a/service/updates/helper/electron.go b/service/updates/helper/electron.go index e23f839b6..844f584df 100644 --- a/service/updates/helper/electron.go +++ b/service/updates/helper/electron.go @@ -47,12 +47,7 @@ func EnsureChromeSandboxPermissions(reg *updater.ResourceRegistry) error { filepath.Ext(pmElectronUpdate.Path()), ) sandboxFile := filepath.Join(unpackedPath, "chrome-sandbox") - if runtime.GOOS == "windows" { - err = acl.Chmod(sandboxFile, 0o0755|os.ModeSetuid) - } else { - err = os.Chmod(sandboxFile, 0o0755|os.ModeSetuid) - } - if err != nil { + if err := os.Chmod(sandboxFile, 0o0755|os.ModeSetuid); err != nil { log.Errorf(suidBitWarning, 0o0755|os.ModeSetuid, sandboxFile) return fmt.Errorf("failed to chmod: %w", err) }