fleet/orbit/pkg/platform/platform_windows.go
Tomas Touceda 8457e55b53
Bump go to 1.19.1 (#7690)
* Bump go to 1.19.1

* Bump remaining go-version to the 1.19.1

* Add extra paths for test-go

* Oops, putting the right path in the right place

* gofmt file

* gofmt ALL THE THINGS

* Moar changes

* Actually, go.mod doesn't like minor versions
2022-09-12 20:32:43 -03:00

52 lines
1.1 KiB
Go

//go:build windows
// +build windows
package platform
import (
"fmt"
"github.com/fleetdm/fleet/v4/orbit/pkg/constant"
"github.com/hectane/go-acl"
)
const (
fullControl = uint32(2032127)
readAndExecute = uint32(131241)
)
// ChmodExecutableDirectory sets the appropriate permissions on the parent
// directory of an executable file. On Windows this involves setting the
// appropriate ACLs.
func ChmodExecutableDirectory(path string) error {
if err := acl.Apply(
path,
true,
false,
acl.GrantSid(fullControl, constant.SystemSID),
acl.GrantSid(fullControl, constant.AdminSID),
acl.GrantSid(readAndExecute, constant.UserSID),
); err != nil {
return fmt.Errorf("apply ACLs: %w", err)
}
return nil
}
// ChmodExecutable sets the appropriate permissions on an executable file. On
// Windows this involves setting the appropriate ACLs.
func ChmodExecutable(path string) error {
if err := acl.Apply(
path,
true,
false,
acl.GrantSid(fullControl, constant.SystemSID),
acl.GrantSid(fullControl, constant.AdminSID),
acl.GrantSid(readAndExecute, constant.UserSID),
); err != nil {
return fmt.Errorf("apply ACLs: %w", err)
}
return nil
}