aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/conf
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-11-26 13:13:44 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2020-11-27 12:50:53 +0100
commit10678f4ba3fc5165a0215029aa4ceeed3a297dca (patch)
tree9ea8fb434b086b0ab4ce226a667fd8b133163ccb /conf
parentconf: rework migration flows around a single Save() (diff)
downloadwireguard-windows-10678f4ba3fc5165a0215029aa4ceeed3a297dca.tar.xz
wireguard-windows-10678f4ba3fc5165a0215029aa4ceeed3a297dca.zip
manager: move legacy store from conf
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'conf')
-rw-r--r--conf/legacy_windows.go130
-rw-r--r--conf/path_windows.go3
-rw-r--r--conf/store.go4
3 files changed, 0 insertions, 137 deletions
diff --git a/conf/legacy_windows.go b/conf/legacy_windows.go
deleted file mode 100644
index ea8513cb..00000000
--- a/conf/legacy_windows.go
+++ /dev/null
@@ -1,130 +0,0 @@
-/* SPDX-License-Identifier: MIT
- *
- * Copyright (C) 2019-2020 WireGuard LLC. All Rights Reserved.
- */
-
-package conf
-
-import (
- "fmt"
- "io/ioutil"
- "log"
- "path/filepath"
- "regexp"
- "strings"
-
- "golang.org/x/sys/windows"
- "golang.org/x/sys/windows/registry"
- "golang.org/x/sys/windows/svc/mgr"
-)
-
-func moveConfigsFromLegacyStore() {
- if disableAutoMigration {
- return
- }
- oldRoot, err := windows.KnownFolderPath(windows.FOLDERID_LocalAppData, windows.KF_FLAG_DEFAULT)
- if err != nil {
- return
- }
- oldC := filepath.Join(oldRoot, "WireGuard", "Configurations")
- files, err := ioutil.ReadDir(oldC)
- if err != nil {
- return
- }
- pendingDeletion := make(map[string]bool)
- if key, err := registry.OpenKey(registry.LOCAL_MACHINE, `SYSTEM\CurrentControlSet\Control\Session Manager`, registry.READ); err == nil {
- if ntPaths, _, err := key.GetStringsValue("PendingFileRenameOperations"); err == nil {
- for _, ntPath := range ntPaths {
- pendingDeletion[strings.ToLower(strings.TrimPrefix(ntPath, `\??\`))] = true
- }
- }
- key.Close()
- }
- migratedConfigs := make(map[string]string)
- for i := range files {
- if files[i].IsDir() {
- continue
- }
- fileName := files[i].Name()
- oldPath := filepath.Join(oldC, fileName)
- if pendingDeletion[strings.ToLower(oldPath)] {
- continue
- }
- config, err := LoadFromPath(oldPath)
- if err != nil {
- continue
- }
- newPath, err := config.Path()
- if err != nil {
- continue
- }
- err = config.Save(false)
- if err != nil {
- continue
- }
- oldPath16, err := windows.UTF16PtrFromString(oldPath)
- if err == nil {
- windows.MoveFileEx(oldPath16, nil, windows.MOVEFILE_DELAY_UNTIL_REBOOT)
- }
- migratedConfigs[strings.ToLower(oldPath)] = newPath
- log.Printf("Migrated configuration from ‘%s’ to ‘%s’", oldPath, newPath)
- }
- oldC16, err := windows.UTF16PtrFromString(oldC)
- if err == nil {
- windows.MoveFileEx(oldC16, nil, windows.MOVEFILE_DELAY_UNTIL_REBOOT)
- }
- oldLog16, err := windows.UTF16PtrFromString(filepath.Join(oldRoot, "WireGuard", "log.bin"))
- if err == nil {
- windows.MoveFileEx(oldLog16, nil, windows.MOVEFILE_DELAY_UNTIL_REBOOT)
- }
- oldRoot16, err := windows.UTF16PtrFromString(filepath.Join(oldRoot, "WireGuard"))
- if err == nil {
- windows.MoveFileEx(oldRoot16, nil, windows.MOVEFILE_DELAY_UNTIL_REBOOT)
- }
- if len(migratedConfigs) == 0 {
- return
- }
- m, err := mgr.Connect()
- if err != nil {
- return
- }
- defer m.Disconnect()
- services, err := m.ListServices()
- if err != nil {
- return
- }
- matcher, err := regexp.Compile(" /tunnelservice \"?([^\"]+)\"?$")
- if err != nil {
- return
- }
- for _, svcName := range services {
- if !strings.HasPrefix(svcName, "WireGuardTunnel$") {
- continue
- }
- svc, err := m.OpenService(svcName)
- if err != nil {
- continue
- }
- config, err := svc.Config()
- if err != nil {
- continue
- }
- matches := matcher.FindStringSubmatchIndex(config.BinaryPathName)
- if len(matches) != 4 {
- svc.Close()
- continue
- }
- newName, found := migratedConfigs[strings.ToLower(config.BinaryPathName[matches[2]:])]
- if !found {
- svc.Close()
- continue
- }
- config.BinaryPathName = config.BinaryPathName[:matches[0]] + fmt.Sprintf(" /tunnelservice \"%s\"", newName)
- err = svc.UpdateConfig(config)
- svc.Close()
- if err != nil {
- continue
- }
- log.Printf("Migrated service command line arguments for ‘%s’", svcName)
- }
-}
diff --git a/conf/path_windows.go b/conf/path_windows.go
index d1ce07cc..9bda7918 100644
--- a/conf/path_windows.go
+++ b/conf/path_windows.go
@@ -19,7 +19,6 @@ import (
var cachedConfigFileDir string
var cachedRootDir string
-var disableAutoMigration bool
func tunnelConfigurationsDirectory() (string, error) {
if cachedConfigFileDir != "" {
@@ -35,7 +34,6 @@ func tunnelConfigurationsDirectory() (string, error) {
return "", err
}
cachedConfigFileDir = c
- moveConfigsFromLegacyStore()
return cachedConfigFileDir, nil
}
@@ -44,7 +42,6 @@ func tunnelConfigurationsDirectory() (string, error) {
// consumers of our libraries who might want to do strange things.
func PresetRootDirectory(root string) {
cachedRootDir = root
- disableAutoMigration = true
}
func RootDirectory(create bool) (string, error) {
diff --git a/conf/store.go b/conf/store.go
index 9a0f8c7d..5cc2ce46 100644
--- a/conf/store.go
+++ b/conf/store.go
@@ -132,10 +132,6 @@ func LoadFromName(name string) (*Config, error) {
}
func LoadFromPath(path string) (*Config, error) {
- if !disableAutoMigration {
- tunnelConfigurationsDirectory() // Provoke migrations, if needed.
- }
-
name, err := NameFromPath(path)
if err != nil {
return nil, err