diff options
author | 2019-03-20 01:01:48 -0600 | |
---|---|---|
committer | 2019-03-20 01:01:48 -0600 | |
commit | 282a4564b71d041f4c65e4152da6cf7ca42c339a (patch) | |
tree | d186074fd90c25e5b7c1e906d40ea7365db526b5 | |
parent | confview: dns -> dns servers (diff) | |
download | wireguard-windows-282a4564b71d041f4c65e4152da6cf7ca42c339a.tar.xz wireguard-windows-282a4564b71d041f4c65e4152da6cf7ca42c339a.zip |
conf: expose configuration root directory
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | conf/path_windows.go | 28 | ||||
-rw-r--r-- | conf/store.go | 12 | ||||
-rw-r--r-- | conf/storewatcher_windows.go | 2 |
3 files changed, 30 insertions, 12 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 diff --git a/conf/store.go b/conf/store.go index da144a17..43f524cd 100644 --- a/conf/store.go +++ b/conf/store.go @@ -18,7 +18,7 @@ const configFileSuffix = ".conf.dpapi" const configFileUnencryptedSuffix = ".conf" func ListConfigNames() ([]string, error) { - configFileDir, err := resolveConfigFileDir() + configFileDir, err := tunnelConfigurationsDirectory() if err != nil { return nil, err } @@ -47,7 +47,7 @@ func ListConfigNames() ([]string, error) { } func MigrateUnencryptedConfigs() (int, []error) { - configFileDir, err := resolveConfigFileDir() + configFileDir, err := tunnelConfigurationsDirectory() if err != nil { return 0, []error{err} } @@ -120,7 +120,7 @@ func MigrateUnencryptedConfigs() (int, []error) { } func LoadFromName(name string) (*Config, error) { - configFileDir, err := resolveConfigFileDir() + configFileDir, err := tunnelConfigurationsDirectory() if err != nil { return nil, err } @@ -166,7 +166,7 @@ func (config *Config) Save() error { if !TunnelNameIsValid(config.Name) { return errors.New("Tunnel name is not valid") } - configFileDir, err := resolveConfigFileDir() + configFileDir, err := tunnelConfigurationsDirectory() if err != nil { return err } @@ -192,7 +192,7 @@ func (config *Config) Path() (string, error) { if !TunnelNameIsValid(config.Name) { return "", errors.New("Tunnel name is not valid") } - configFileDir, err := resolveConfigFileDir() + configFileDir, err := tunnelConfigurationsDirectory() if err != nil { return "", err } @@ -203,7 +203,7 @@ func DeleteName(name string) error { if !TunnelNameIsValid(name) { return errors.New("Tunnel name is not valid") } - configFileDir, err := resolveConfigFileDir() + configFileDir, err := tunnelConfigurationsDirectory() if err != nil { return err } diff --git a/conf/storewatcher_windows.go b/conf/storewatcher_windows.go index ddfc8b92..5c5ffac7 100644 --- a/conf/storewatcher_windows.go +++ b/conf/storewatcher_windows.go @@ -32,7 +32,7 @@ func startWatchingConfigDir() { } haveStartedWatchingConfigDir = true go func() { - configFileDir, err := resolveConfigFileDir() + configFileDir, err := tunnelConfigurationsDirectory() if err != nil { return } |