go - How to control file access in Windows? -


go provides os.chmod() setting file , directory permissions. example, if want ensure file accessible current user, can following:

os.chmod("somefile.txt", 0600) 

this works great on linux absolutely nothing on windows. after digging go source code, came across its implementation. seems s_iwrite attribute supported.

how control access file or directory on windows using go?

explanation

windows not use traditional unix permissions. instead, windows controls access files , directories through access control. each object has acl (access control list)* controls access object.

each acl list of aces (access control entries) determine access specific trustee (user, group, etc.) granted. example, file may contain ace granting specific user read access (generic_read) file.

manipulating acls , aces done through authorization functions in windows api.

* technically each object has 2 acls - dacl , sacl

solution

thankfully, learning of these functions isn't necessary. i've put a small go package named "go-acl" of heavy-lifting , exposes function named (what else?) chmod. basic usage follows:

import "github.com/hectane/go-acl"  err := acl.chmod("c:\\path\\to\\file.txt", 0755) if err != nil {     panic(err) } 

results

the chmod() function creates 3 aces in file's acl:

enter image description here

  • one owner (wincreatorownersid)
  • one group (wincreatorgroupsid)
  • one else (winworldsid)

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -