1
0
mirror of https://github.com/DNSCrypt/dnscrypt-proxy.git synced 2024-12-12 22:36:32 +01:00
dnscrypt-proxy/vendor/github.com/hectane/go-acl/api/secinfo.go
William Elwood 4324a09fc9 Fix failing tests on Windows
To simulate failures opening a cache file, fixtures are written without the read permission bits.
Since Unix permission bits have no meaning on Windows, a slightly more complicated solution is required to achieve the same permissions.
Thankfully, there's a library to abstract that already.
2019-11-08 10:17:12 +01:00

85 lines
2.4 KiB
Go

//+build windows
package api
import (
"golang.org/x/sys/windows"
"unsafe"
)
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa379593.aspx
const (
SE_UNKNOWN_OBJECT_TYPE = iota
SE_FILE_OBJECT
SE_SERVICE
SE_PRINTER
SE_REGISTRY_KEY
SE_LMSHARE
SE_KERNEL_OBJECT
SE_WINDOW_OBJECT
SE_DS_OBJECT
SE_DS_OBJECT_ALL
SE_PROVIDER_DEFINED_OBJECT
SE_WMIGUID_OBJECT
SE_REGISTRY_WOW64_32KEY
)
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa379573.aspx
const (
OWNER_SECURITY_INFORMATION = 0x00001
GROUP_SECURITY_INFORMATION = 0x00002
DACL_SECURITY_INFORMATION = 0x00004
SACL_SECURITY_INFORMATION = 0x00008
LABEL_SECURITY_INFORMATION = 0x00010
ATTRIBUTE_SECURITY_INFORMATION = 0x00020
SCOPE_SECURITY_INFORMATION = 0x00040
PROCESS_TRUST_LABEL_SECURITY_INFORMATION = 0x00080
BACKUP_SECURITY_INFORMATION = 0x10000
PROTECTED_DACL_SECURITY_INFORMATION = 0x80000000
PROTECTED_SACL_SECURITY_INFORMATION = 0x40000000
UNPROTECTED_DACL_SECURITY_INFORMATION = 0x20000000
UNPROTECTED_SACL_SECURITY_INFORMATION = 0x10000000
)
var (
procGetNamedSecurityInfoW = advapi32.MustFindProc("GetNamedSecurityInfoW")
procSetNamedSecurityInfoW = advapi32.MustFindProc("SetNamedSecurityInfoW")
)
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa446645.aspx
func GetNamedSecurityInfo(objectName string, objectType int32, secInfo uint32, owner, group **windows.SID, dacl, sacl, secDesc *windows.Handle) error {
ret, _, err := procGetNamedSecurityInfoW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(objectName))),
uintptr(objectType),
uintptr(secInfo),
uintptr(unsafe.Pointer(owner)),
uintptr(unsafe.Pointer(group)),
uintptr(unsafe.Pointer(dacl)),
uintptr(unsafe.Pointer(sacl)),
uintptr(unsafe.Pointer(secDesc)),
)
if ret != 0 {
return err
}
return nil
}
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa379579.aspx
func SetNamedSecurityInfo(objectName string, objectType int32, secInfo uint32, owner, group *windows.SID, dacl, sacl windows.Handle) error {
ret, _, err := procSetNamedSecurityInfoW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(objectName))),
uintptr(objectType),
uintptr(secInfo),
uintptr(unsafe.Pointer(owner)),
uintptr(unsafe.Pointer(group)),
uintptr(dacl),
uintptr(sacl),
)
if ret != 0 {
return err
}
return nil
}