aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-08-28 08:22:03 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2019-08-30 08:47:21 -0600
commit558e9d335a287a0ef985544cd583c0722d943c35 (patch)
tree2d57da00c22f339369ccf6eeb8dd4c3dd406116c
parentmanager: clean stale adapters on startup (diff)
downloadwireguard-windows-558e9d335a287a0ef985544cd583c0722d943c35.tar.xz
wireguard-windows-558e9d335a287a0ef985544cd583c0722d943c35.zip
manager: fix nits in adapter cleanup logic and also handle ‘%s’ uniformly
-rw-r--r--conf/migration_windows.go10
-rw-r--r--manager/adaptercleanup.go (renamed from manager/adapters.go)28
-rw-r--r--manager/ipc_server.go3
-rw-r--r--manager/service.go4
-rw-r--r--tunnel/addressconfig.go2
-rw-r--r--ui/filesave.go2
6 files changed, 23 insertions, 26 deletions
diff --git a/conf/migration_windows.go b/conf/migration_windows.go
index 9c070a08..4b7ffe30 100644
--- a/conf/migration_windows.go
+++ b/conf/migration_windows.go
@@ -38,27 +38,27 @@ func maybeMigrate(c string) {
return
}
if err != nil {
- log.Printf("Not migrating configuration from '%s' due to GetFileSecurity error: %v", oldRoot, err)
+ log.Printf("Not migrating configuration from ‘%s’ due to GetFileSecurity error: %v", oldRoot, err)
return
}
var defaulted bool
var sid *windows.SID
err = getSecurityDescriptorOwner(&sd[0], &sid, &defaulted)
if err != nil {
- log.Printf("Not migrating configuration from '%s' due to GetSecurityDescriptorOwner error: %v", oldRoot, err)
+ log.Printf("Not migrating configuration from ‘%s’ due to GetSecurityDescriptorOwner error: %v", oldRoot, err)
return
}
if defaulted || !sid.IsWellKnown(windows.WinLocalSystemSid) {
sidStr, _ := sid.String()
- log.Printf("Not migrating configuration from '%s', as it is not explicitly owned by SYSTEM, but rather '%s'", oldRoot, sidStr)
+ log.Printf("Not migrating configuration from ‘%s’, as it is not explicitly owned by SYSTEM, but rather ‘%s’", oldRoot, sidStr)
return
}
err = windows.MoveFileEx(windows.StringToUTF16Ptr(oldC), windows.StringToUTF16Ptr(c), windows.MOVEFILE_COPY_ALLOWED)
if err != nil {
if err != windows.ERROR_FILE_NOT_FOUND && err != windows.ERROR_ALREADY_EXISTS {
- log.Printf("Not migrating configuration from '%s' due to error when moving files: %v", oldRoot, err)
+ log.Printf("Not migrating configuration from ‘%s’ due to error when moving files: %v", oldRoot, err)
}
return
}
- log.Printf("Migrated configuration from '%s'", oldRoot)
+ log.Printf("Migrated configuration from ‘%s’", oldRoot)
}
diff --git a/manager/adapters.go b/manager/adaptercleanup.go
index 5ac16465..779e4b80 100644
--- a/manager/adapters.go
+++ b/manager/adaptercleanup.go
@@ -7,6 +7,7 @@ package manager
import (
"log"
+ "strings"
"golang.org/x/sys/windows"
"golang.org/x/sys/windows/svc"
@@ -16,12 +17,13 @@ import (
"golang.zx2c4.com/wireguard/windows/services"
)
-func cleanStaleAdapters() {
+const unnamedWintunInterface = "Local Area Connection"
+
+func cleanupStaleAdapters() {
defer printPanic()
m, err := mgr.Connect()
if err != nil {
- log.Printf("Error connecting to Service Control Manager: %v", err)
return
}
defer m.Disconnect()
@@ -32,36 +34,28 @@ func cleanStaleAdapters() {
log.Printf("Removing Wintun interface %s because determining interface name failed: %v", wintun.GUID().String(), err)
return true
}
+ if strings.HasPrefix(interfaceName, unnamedWintunInterface) {
+ return false
+ }
serviceName, err := services.ServiceNameOfTunnel(interfaceName)
if err != nil {
- log.Printf("Removing Wintun interface %s because determining tunnel service name failed: %v", interfaceName, err)
+ log.Printf("Removing Wintun interface ‘%s’ because determining tunnel service name failed: %v", interfaceName, err)
return true
}
service, err := m.OpenService(serviceName)
if err == windows.ERROR_SERVICE_DOES_NOT_EXIST {
- log.Printf("Removing orphaned Wintun interface %s", interfaceName)
+ log.Printf("Removing Wintun interface ‘%s’ because no service for it exists", interfaceName)
return true
- }
- if err != nil {
- log.Printf("Error opening service %s: %v", serviceName, err)
+ } else if err != nil {
return false
}
defer service.Close()
- config, err := service.Config()
- if err != nil {
- log.Printf("Error getting service %s configuration: %v", serviceName, err)
- return false
- }
- if config.StartType == mgr.StartAutomatic {
- return false
- }
status, err := service.Query()
if err != nil {
- log.Printf("Error getting service %s status: %v", serviceName, err)
return false
}
if status.State == svc.Stopped {
- log.Printf("Removing unused Wintun interface %s", interfaceName)
+ log.Printf("Removing Wintun interface ‘%s’ because its service is stopped", interfaceName)
return true
}
return false
diff --git a/manager/ipc_server.go b/manager/ipc_server.go
index 7691adb8..ed60d6b6 100644
--- a/manager/ipc_server.go
+++ b/manager/ipc_server.go
@@ -107,6 +107,7 @@ func (s *ManagerService) Start(tunnelName string, unused *uintptr) error {
}
}
}()
+ go cleanupStaleAdapters()
// After that process is started -- it's somewhat asynchronous -- we install the new one.
c, err := conf.LoadFromName(tunnelName)
@@ -121,6 +122,8 @@ func (s *ManagerService) Start(tunnelName string, unused *uintptr) error {
}
func (s *ManagerService) Stop(tunnelName string, _ *uintptr) error {
+ go cleanupStaleAdapters()
+
err := UninstallTunnel(tunnelName)
if err == windows.ERROR_SERVICE_DOES_NOT_EXIST {
_, notExistsError := conf.LoadFromName(tunnelName)
diff --git a/manager/service.go b/manager/service.go
index 7ab3db16..8a525b12 100644
--- a/manager/service.go
+++ b/manager/service.go
@@ -182,7 +182,7 @@ func (service *managerService) Execute(args []string, r <-chan svc.ChangeRequest
return
}
- log.Printf("Starting UI process for user '%s@%s' for session %d", username, domain, session)
+ log.Printf("Starting UI process for user ‘%s@%s’ for session %d", username, domain, session)
attr := &os.ProcAttr{
Sys: &syscall.SysProcAttr{
Token: syscall.Token(elevatedToken),
@@ -247,7 +247,7 @@ func (service *managerService) Execute(args []string, r <-chan svc.ChangeRequest
}()
}
- go cleanStaleAdapters()
+ go cleanupStaleAdapters()
go checkForUpdates()
var sessionsPointer *windows.WTS_SESSION_INFO
diff --git a/tunnel/addressconfig.go b/tunnel/addressconfig.go
index a1e5dc59..643e178e 100644
--- a/tunnel/addressconfig.go
+++ b/tunnel/addressconfig.go
@@ -50,7 +50,7 @@ func cleanupAddressesOnDisconnectedInterfaces(family winipcfg.AddressFamily, add
ip := address.Address.IP()
ipnet := net.IPNet{IP: ip, Mask: net.CIDRMask(int(address.OnLinkPrefixLength), 8*len(ip))}
if includedInAddresses(ipnet) {
- log.Printf("Cleaning up stale address %s from interface '%s'", ipnet.String(), iface.FriendlyName())
+ log.Printf("Cleaning up stale address %s from interface ‘%s’", ipnet.String(), iface.FriendlyName())
iface.LUID.DeleteIPAddress(ipnet)
}
}
diff --git a/ui/filesave.go b/ui/filesave.go
index 5f78cfee..4b5c2947 100644
--- a/ui/filesave.go
+++ b/ui/filesave.go
@@ -26,7 +26,7 @@ func writeFileWithOverwriteHandling(owner walk.Form, filePath string, write func
file, err := os.OpenFile(filePath, os.O_CREATE|os.O_WRONLY|os.O_EXCL, 0600)
if err != nil {
if os.IsExist(err) {
- if walk.DlgCmdNo == walk.MsgBox(owner, "Writing file failed", fmt.Sprintf(`File "%s" already exists.
+ if walk.DlgCmdNo == walk.MsgBox(owner, "Writing file failed", fmt.Sprintf(`File ‘%s’ already exists.
Do you want to overwrite it?`, filePath), walk.MsgBoxYesNo|walk.MsgBoxDefButton2|walk.MsgBoxIconWarning) {
return false