acl

package module
v0.0.0-...-1ced35d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2017 License: MIT Imports: 5 Imported by: 0

README

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 (
    "github.com/KuoKongQingYun/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 (
    "github.com/KuoKongQingYun/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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(name string, replace, inherit bool, entries ...api.ExplicitAccess) error

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 Chmod

func Chmod(name string, mode os.FileMode) error

Change the permissions of the specified file. Only the nine least-significant bytes are used, allowing access by the file's owner, the file's group, and everyone else to be explicitly controlled.

func DenyName

func DenyName(accessPermissions uint32, name string) api.ExplicitAccess

Create an ExplicitAccess instance denying permissions to the provided name.

func DenySid

func DenySid(accessPermissions uint32, sid *windows.SID) api.ExplicitAccess

Create an ExplicitAccess instance denying permissions to the provided SID.

func GrantName

func GrantName(accessPermissions uint32, name string) api.ExplicitAccess

Create an ExplicitAccess instance granting permissions to the provided name.

func GrantSid

func GrantSid(accessPermissions uint32, sid *windows.SID) api.ExplicitAccess

Create an ExplicitAccess instance granting permissions to the provided SID.

func SetOwner

func SetOwner(name string, inherit bool, owner *windows.SID) error

Types

This section is empty.

Directories

Path Synopsis
Windows API functions for manipulating ACLs.
Windows API functions for manipulating ACLs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL