fleet/orbit/pkg/platform/platform_windows.go
Tomas Touceda 989e638cc0
Make creating dirs and files more secure by checking permissions (#1566)
* Add safe mkdirall and open

* Use secure as much as possible and merge gomodules for orbit to fleet

* Improve openfile and mkdirall to check for permissiveness instead of equality

* Don't shift

* Fix links

* Address review comments
2021-08-11 11:02:22 -03:00

50 lines
1.1 KiB
Go

//+build windows
package platform
import (
"github.com/fleetdm/fleet/v4/orbit/pkg/constant"
"github.com/pkg/errors"
"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 errors.Wrap(err, "apply ACLs")
}
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 errors.Wrap(err, "apply ACLs")
}
return nil
}