Giter VIP home page Giter VIP logo

acls's Introduction

codecov

Overview

This library provides the means to, without any cgo dependencies, adjust the regular linux filesystem ACLs (system.posix_acl_access) as well as the default ACLs (system.posix_acl_default). It therefore is a golang native implementation of the getfacl / setfacl commands.

Sample

The following code will try to load the actual ACL entries from the filePath referenced file.

If the filePath referenced object does not have an ACL attached, the regular file permissions are loadded as ACL Entries.

Subsequentyl a new entry for the linux group with GID 5558 and a permission of 7 (rwx) is added.

Then the ACL is applied as an Access ACL to the filePath provided filesystem object.

package main

import (
  log "github.com/sirupsen/logrus"
  "github.com/steiler/acls"
)

func main() {
    // Define the path to the file for which you want to get ACLs.
    filePath := "/tmp/foo"

    // init the ACL struct
    a := &acls.ACL{}
    // load (access) ACL entries from a given path object
    err := a.Load(filePath, acls.PosixACLAccess)
    if err != nil {
        log.Fatal(err)
    }
    // add a new entry referencing a group with GID 5558 granting permission rwx (7)
    err = a.AddEntry(acls.NewEntry(acls.TAG_ACL_GROUP, 5558, 7))
    if err != nil {
        log.Fatal(err)
    }
    // print a visual representation of the ACL
    fmt.Println(a.String())

    // Apply the ACL as an access ACL to the given filesystem path object.
    err = a.Apply(filePath, acls.PosixACLAccess)
    if err != nil {
        log.Fatal(err)
    }
}

The output of the fmt.Println(a.String()) looks like the following:

Version: 2
Entries:
Tag:   USER_OBJ ( 1), ID:       1000, Perm: rwx (7)
Tag:  GROUP_OBJ ( 4), ID:       1000, Perm: rwx (7)
Tag:      GROUP ( 8), ID:       5558, Perm: rwx (7)
Tag:       MASK (16), ID: 4294967295, Perm: rwx (7)
Tag:      OTHER (32), ID: 4294967295, Perm: r-x (5)

Features

- Add ACL Entry
- Delete ACL Entry
- Modify ACL Entry
- Print ACL Entry
- Read ACL entries from one file object, apply to another
- Adjust default and access ACL

acls's People

Contributors

steiler avatar

Watchers

 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.