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.
forest afceea9825 update module for fork 3 years ago
api Merge remote-tracking branch 'jazzy-crane/master' 3 years ago
LICENSE.txt Added MIT license. 9 years ago
README.md update module for fork 3 years ago
apply.go update module for fork 3 years ago
apply_test.go Fix issue #16 - Error code propagation from api incorrect 3 years ago
chmod.go Merge remote-tracking branch 'zb140/get-access-mode' 3 years ago
chmod_test.go Enabled build on non-Windows systems 6 years ago
constants.go Support a couple of different methods for checking which permissions are set for a given file 6 years ago
getaccessmode.go update module for fork 3 years ago
go.mod update module for fork 3 years ago
go.sum Added Go modules support 6 years ago
posix.go Added Chmod as alias for os.Chmod on non-Windows 6 years ago
util.go update module for fork 3 years ago

README.md

go-acl

Build status GoDoc MIT License

Manipulating ACLs (Access Control Lists) on Windows is difficult. go-acl wraps the Windows API functions that control access to objects, simplifying the process.

Using the Package

To use the package add the following imports:

import (
    "git.sequentialread.com/forest/go-acl"
    "golang.org/x/sys/windows"
)

Examples

Probably the most commonly used function in this package is Chmod:

if err := acl.Chmod("C:\\path\\to\\file.txt", 0755); err != nil {
    panic(err)
}

To grant read access to user "Alice" and deny write access to user "Bob":

if err := acl.Apply(
    "C:\\path\\to\\file.txt",
    false,
    false,
    acl.GrantName(windows.GENERIC_READ, "Alice"),
    acl.DenyName(windows.GENERIC_WRITE, "Bob"),
); err != nil {
    panic(err)
}

Using the API Directly

go-acl's api package exposes the individual Windows API functions that are used to manipulate ACLs. For example, to retrieve the current owner of a file:

import (
    "git.sequentialread.com/forest/go-acl/api"
    "golang.org/x/sys/windows"
)

var (
    owner   *windows.SID
    secDesc windows.Handle
)
err := api.GetNamedSecurityInfo(
    "C:\\path\\to\\file.txt",
    api.SE_FILE_OBJECT,
    api.OWNER_SECURITY_INFORMATION,
    &owner,
    nil,
    nil,
    nil,
    &secDesc,
)
if err != nil {
    panic(err)
}
defer windows.LocalFree(secDesc)

owner will then point to the SID for the owner of the file.