fork of chmod for windows (from https://github.com/hectane/go-acl)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.1 KiB

//+build windows
package acl
import (
"git.sequentialread.com/forest/go-acl/api"
"golang.org/x/sys/windows"
"unsafe"
)
// Apply the provided access control entries to a file. If the replace
// parameter is true, existing entries will be overwritten. If the inherit
// parameter is true, the file will inherit ACEs from its parent.
func Apply(name string, replace, inherit bool, entries ...api.ExplicitAccess) error {
var oldAcl windows.Handle
if !replace {
var secDesc windows.Handle
api.GetNamedSecurityInfo(
name,
api.SE_FILE_OBJECT,
api.DACL_SECURITY_INFORMATION,
nil,
nil,
&oldAcl,
nil,
&secDesc,
)
defer windows.LocalFree(secDesc)
}
var acl windows.Handle
if err := api.SetEntriesInAcl(
entries,
oldAcl,
&acl,
); err != nil {
return err
}
defer windows.LocalFree((windows.Handle)(unsafe.Pointer(acl)))
var secInfo uint32
if !inherit {
secInfo = api.PROTECTED_DACL_SECURITY_INFORMATION
} else {
secInfo = api.UNPROTECTED_DACL_SECURITY_INFORMATION
}
return api.SetNamedSecurityInfo(
name,
api.SE_FILE_OBJECT,
api.DACL_SECURITY_INFORMATION|secInfo,
nil,
nil,
acl,
0,
)
}