diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-03-20 01:01:48 -0600 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-03-20 01:01:48 -0600 |
commit | 8d7e12d3fbef4230613848a219cf0168d90a9993 (patch) | |
tree | d186074fd90c25e5b7c1e906d40ea7365db526b5 /conf/path_windows.go | |
parent | confview: dns -> dns servers (diff) | |
download | wireguard-windows-8d7e12d3fbef4230613848a219cf0168d90a9993.tar.xz wireguard-windows-8d7e12d3fbef4230613848a219cf0168d90a9993.zip |
conf: expose configuration root directory
Diffstat (limited to 'conf/path_windows.go')
-rw-r--r-- | conf/path_windows.go | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/conf/path_windows.go b/conf/path_windows.go index 0ee3fc73..96c68738 100644 --- a/conf/path_windows.go +++ b/conf/path_windows.go @@ -20,11 +20,29 @@ var folderIDLocalAppData = windows.GUID{0xf1b32785, 0x6fba, 0x4fcf, [8]byte{0x9d const kfFlagCreate = 0x00008000 var cachedConfigFileDir string +var cachedRootDir string -func resolveConfigFileDir() (string, error) { +func tunnelConfigurationsDirectory() (string, error) { if cachedConfigFileDir != "" { return cachedConfigFileDir, nil } + root, err := RootDirectory() + if err != nil { + return "", err + } + c := filepath.Join(root, "Configurations") + err = os.MkdirAll(c, os.ModeDir|0700) + if err != nil { + return "", err + } + cachedConfigFileDir = c + return cachedConfigFileDir, nil +} + +func RootDirectory() (string, error) { + if cachedRootDir != "" { + return cachedRootDir, nil + } processToken, err := windows.OpenCurrentProcessToken() if err != nil { return "", err @@ -40,11 +58,11 @@ func resolveConfigFileDir() (string, error) { if len(root) == 0 { return "", errors.New("Unable to determine configuration directory") } - c := filepath.Join(root, "WireGuard", "Configurations") + c := filepath.Join(root, "WireGuard") err = os.MkdirAll(c, os.ModeDir|0700) if err != nil { return "", err } - cachedConfigFileDir = c - return cachedConfigFileDir, nil -} + cachedRootDir = c + return cachedRootDir, nil +}
\ No newline at end of file |