File: chmod.go

package info (click to toggle)
golang-github-hectane-go-acl 0.0~git20190604.da78bae-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 140 kB
  • sloc: makefile: 2
file content (38 lines) | stat: -rw-r--r-- 978 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//+build windows

package acl

import (
	"os"

	"golang.org/x/sys/windows"
)

// 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 Chmod(name string, fileMode os.FileMode) error {
	// https://support.microsoft.com/en-us/help/243330/well-known-security-identifiers-in-windows-operating-systems
	creatorOwnerSID, err := windows.StringToSid("S-1-3-0")
	if err != nil {
		return err
	}
	creatorGroupSID, err := windows.StringToSid("S-1-3-1")
	if err != nil {
		return err
	}
	everyoneSID, err := windows.StringToSid("S-1-1-0")
	if err != nil {
		return err
	}

	mode := uint32(fileMode)
	return Apply(
		name,
		true,
		false,
		GrantSid(((mode&0700)<<23)|((mode&0200)<<9), creatorOwnerSID),
		GrantSid(((mode&0070)<<26)|((mode&0020)<<12), creatorGroupSID),
		GrantSid(((mode&0007)<<29)|((mode&0002)<<15), everyoneSID),
	)
}