diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-01-28 20:44:12 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-01-28 20:48:25 +0100 |
commit | 2bc596c21f562c144b0b9b23c06c18d08f210fa4 (patch) | |
tree | f6dd38176d256f5a53e98df1aed91708dcf173be | |
parent | tunnel: deduplicate addresses from config (diff) | |
download | wireguard-windows-2bc596c21f562c144b0b9b23c06c18d08f210fa4.tar.xz wireguard-windows-2bc596c21f562c144b0b9b23c06c18d08f210fa4.zip |
manager: add ability to update silentlyjd/adminnobs
-rw-r--r-- | ADMIN_REGISTRY.md | 13 | ||||
-rw-r--r-- | conf/admin.go | 36 | ||||
-rw-r--r-- | manager/updatestate.go | 24 |
3 files changed, 67 insertions, 6 deletions
diff --git a/ADMIN_REGISTRY.md b/ADMIN_REGISTRY.md new file mode 100644 index 00000000..ba96b6ff --- /dev/null +++ b/ADMIN_REGISTRY.md @@ -0,0 +1,13 @@ +## Registry Keys for Admins + +These are advanced configuration nobs that admins can set to do unusual things +that are not recommended. There is no UI to enable these, and no such thing is +planned. Use at your own risk, and please make sure you know what you're doing. + + +#### `HKLM\Software\WireGuard\SilentUpdate` + +When this key is set to `DWORD(1)`, WireGuard will silently update itself when +an update is available. Note that this is not recommended, as all tunnels will +be disrupted during the update, during which time Windows will revert to its +ordinary routing rules. diff --git a/conf/admin.go b/conf/admin.go new file mode 100644 index 00000000..5740907a --- /dev/null +++ b/conf/admin.go @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (C) 2019 WireGuard LLC. All Rights Reserved. + */ + +package conf + +import "golang.org/x/sys/windows/registry" + +const adminRegKey = `Software\WireGuard` + +var adminKey registry.Key + +func openAdminKey() (registry.Key, error) { + if adminKey != 0 { + return adminKey, nil + } + var err error + adminKey, err = registry.OpenKey(registry.LOCAL_MACHINE, adminRegKey, registry.QUERY_VALUE | registry.SET_VALUE) + if err != nil { + return 0, err + } + return adminKey, nil +} + +func AdminBool(name string) bool { + key, err := openAdminKey() + if err != nil { + return false + } + val, _, err := key.GetIntegerValue(name) + if err != nil { + return false + } + return val != 0 +} diff --git a/manager/updatestate.go b/manager/updatestate.go index b54cc367..4cc9a8f8 100644 --- a/manager/updatestate.go +++ b/manager/updatestate.go @@ -9,6 +9,7 @@ import ( "log" "time" + "golang.zx2c4.com/wireguard/windows/conf" "golang.zx2c4.com/wireguard/windows/updater" "golang.zx2c4.com/wireguard/windows/version" ) @@ -35,12 +36,23 @@ func checkForUpdates() { first := true for { - update, err := updater.CheckForUpdate() - if err == nil && update != nil { - log.Println("An update is available") - updateState = UpdateStateFoundUpdate - IPCServerNotifyUpdateFound(updateState) - return + var err error + if conf.AdminBool("SilentUpdate") { + progress := updater.DownloadVerifyAndExecute(0) + for { + dp := <-progress + if dp.Complete || dp.Error != nil { + break + } + } + } else { + update, err := updater.CheckForUpdate() + if err == nil && update != nil { + log.Println("An update is available") + updateState = UpdateStateFoundUpdate + IPCServerNotifyUpdateFound(updateState) + return + } } if err != nil { log.Printf("Update checker: %v", err) |