Git Product home page Git Product logo

go-acl's Introduction

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/hectane/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/hectane/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.

go-acl's People

Contributors

nathan-osman avatar twpayne avatar zb140 avatar ogarod avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.