-
Notifications
You must be signed in to change notification settings - Fork 21
/
ipcpermissions.go
63 lines (54 loc) · 1.35 KB
/
ipcpermissions.go
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* SPDX-License-Identifier: MIT
*
* Copyright (C) 2019-2021 WireGuard LLC. All Rights Reserved.
*/
package main
import (
"golang.org/x/sys/windows"
"github.com/amnezia-vpn/amneziawg-go/ipc"
"github.com/amnezia-vpn/amneziawg-windows/conf"
)
func CopyConfigOwnerToIPCSecurityDescriptor(filename string) error {
if conf.PathIsEncrypted(filename) {
return nil
}
fileSd, err := windows.GetNamedSecurityInfo(filename, windows.SE_FILE_OBJECT, windows.OWNER_SECURITY_INFORMATION)
if err != nil {
return err
}
fileOwner, _, err := fileSd.Owner()
if err != nil {
return err
}
if fileOwner.IsWellKnown(windows.WinLocalSystemSid) {
return nil
}
additionalEntries := []windows.EXPLICIT_ACCESS{{
AccessPermissions: windows.GENERIC_ALL,
AccessMode: windows.GRANT_ACCESS,
Trustee: windows.TRUSTEE{
TrusteeForm: windows.TRUSTEE_IS_SID,
TrusteeType: windows.TRUSTEE_IS_USER,
TrusteeValue: windows.TrusteeValueFromSID(fileOwner),
},
}}
sd, err := ipc.UAPISecurityDescriptor.ToAbsolute()
if err != nil {
return err
}
dacl, defaulted, _ := sd.DACL()
newDacl, err := windows.ACLFromEntries(additionalEntries, dacl)
if err != nil {
return err
}
err = sd.SetDACL(newDacl, true, defaulted)
if err != nil {
return err
}
sd, err = sd.ToSelfRelative()
if err != nil {
return err
}
ipc.UAPISecurityDescriptor = sd
return nil
}