aboutsummaryrefslogtreecommitdiffstats
path: root/conf
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-06-13 14:58:23 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-06-13 14:58:23 +0200
commit84bba1fd7c522d359fa663250cec9f796d4cb38b (patch)
tree0ea7b4d52207cd8e26ac2286b2f7471ef88c583f /conf
parentconf: grammar (diff)
downloadwireguard-windows-84bba1fd7c522d359fa663250cec9f796d4cb38b.tar.xz
wireguard-windows-84bba1fd7c522d359fa663250cec9f796d4cb38b.zip
conf: known folder path is upstream
Diffstat (limited to 'conf')
-rw-r--r--conf/path_windows.go16
-rw-r--r--conf/zsyscall_windows.go17
2 files changed, 1 insertions, 32 deletions
diff --git a/conf/path_windows.go b/conf/path_windows.go
index ec2a715b..8da97708 100644
--- a/conf/path_windows.go
+++ b/conf/path_windows.go
@@ -6,24 +6,16 @@
package conf
import (
- "errors"
"log"
"os"
"path/filepath"
"strings"
- "unsafe"
"golang.org/x/sys/windows"
)
-//sys coTaskMemFree(pointer uintptr) = ole32.CoTaskMemFree
-//sys shGetKnownFolderPath(id *windows.GUID, flags uint32, token windows.Handle, path **uint16) (ret error) = shell32.SHGetKnownFolderPath
//sys getFileSecurity(fileName *uint16, securityInformation uint32, securityDescriptor *byte, descriptorLen uint32, requestedLen *uint32) (err error) = advapi32.GetFileSecurityW
//sys getSecurityDescriptorOwner(securityDescriptor *byte, sid **windows.SID, ownerDefaulted *bool) (err error) = advapi32.GetSecurityDescriptorOwner
-
-var folderIDLocalAppData = windows.GUID{0xf1b32785, 0x6fba, 0x4fcf, [8]byte{0x9d, 0x55, 0x7b, 0x8e, 0x7f, 0x15, 0x70, 0x91}}
-
-const kfFlagCreate = 0x00008000
const ownerSecurityInformation = 0x00000001
var cachedConfigFileDir string
@@ -97,16 +89,10 @@ func RootDirectory() (string, error) {
if cachedRootDir != "" {
return cachedRootDir, nil
}
- var path *uint16
- err := shGetKnownFolderPath(&folderIDLocalAppData, kfFlagCreate, 0, &path)
+ root, err := windows.KnownFolderPath(windows.FOLDERID_LocalAppData, windows.KF_FLAG_CREATE)
if err != nil {
return "", err
}
- defer coTaskMemFree(uintptr(unsafe.Pointer(path)))
- root := windows.UTF16ToString((*[windows.MAX_LONG_PATH + 1]uint16)(unsafe.Pointer(path))[:])
- if len(root) == 0 {
- return "", errors.New("Unable to determine configuration directory")
- }
c := filepath.Join(root, "WireGuard")
err = os.MkdirAll(c, os.ModeDir|0700)
if err != nil {
diff --git a/conf/zsyscall_windows.go b/conf/zsyscall_windows.go
index 4cf6d0bd..ec63bc3d 100644
--- a/conf/zsyscall_windows.go
+++ b/conf/zsyscall_windows.go
@@ -38,14 +38,10 @@ func errnoErr(e syscall.Errno) error {
var (
modwininet = windows.NewLazySystemDLL("wininet.dll")
- modole32 = windows.NewLazySystemDLL("ole32.dll")
- modshell32 = windows.NewLazySystemDLL("shell32.dll")
modadvapi32 = windows.NewLazySystemDLL("advapi32.dll")
modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
procInternetGetConnectedState = modwininet.NewProc("InternetGetConnectedState")
- procCoTaskMemFree = modole32.NewProc("CoTaskMemFree")
- procSHGetKnownFolderPath = modshell32.NewProc("SHGetKnownFolderPath")
procGetFileSecurityW = modadvapi32.NewProc("GetFileSecurityW")
procGetSecurityDescriptorOwner = modadvapi32.NewProc("GetSecurityDescriptorOwner")
procFindFirstChangeNotificationW = modkernel32.NewProc("FindFirstChangeNotificationW")
@@ -58,19 +54,6 @@ func internetGetConnectedState(flags *uint32, reserved uint32) (connected bool)
return
}
-func coTaskMemFree(pointer uintptr) {
- syscall.Syscall(procCoTaskMemFree.Addr(), 1, uintptr(pointer), 0, 0)
- return
-}
-
-func shGetKnownFolderPath(id *windows.GUID, flags uint32, token windows.Handle, path **uint16) (ret error) {
- r0, _, _ := syscall.Syscall6(procSHGetKnownFolderPath.Addr(), 4, uintptr(unsafe.Pointer(id)), uintptr(flags), uintptr(token), uintptr(unsafe.Pointer(path)), 0, 0)
- if r0 != 0 {
- ret = syscall.Errno(r0)
- }
- return
-}
-
func getFileSecurity(fileName *uint16, securityInformation uint32, securityDescriptor *byte, descriptorLen uint32, requestedLen *uint32) (err error) {
r1, _, e1 := syscall.Syscall6(procGetFileSecurityW.Addr(), 5, uintptr(unsafe.Pointer(fileName)), uintptr(securityInformation), uintptr(unsafe.Pointer(securityDescriptor)), uintptr(descriptorLen), uintptr(unsafe.Pointer(requestedLen)), 0)
if r1 == 0 {