Skip to content

Commit 539979e

Browse files
committed
manager: cleanup legacy wintun
It's not good to leave cruft around from the upgrade case when people want to uninstall, so we remove wintun in the uninstaller manually (without the help of wintun.dll, which we no longer ship). But also, so that we can eventually drop that code, we also remove it opportunistically when the manager starts. Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent 203494e commit 539979e

File tree

5 files changed

+63
-9
lines changed

5 files changed

+63
-9
lines changed

driver/wintunremoval_windows.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* SPDX-License-Identifier: MIT
2+
*
3+
* Copyright (C) 2019-2021 WireGuard LLC. All Rights Reserved.
4+
*/
5+
6+
package driver
7+
8+
import (
9+
"path/filepath"
10+
11+
"golang.org/x/sys/windows"
12+
"golang.org/x/sys/windows/setupapi"
13+
)
14+
15+
func UninstallLegacyWintun() error {
16+
var deviceClassNetGUID = &windows.GUID{0x4d36e972, 0xe325, 0x11ce, [8]byte{0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18}}
17+
devInfo, err := setupapi.SetupDiCreateDeviceInfoListEx(deviceClassNetGUID, 0, "")
18+
if err != nil {
19+
return err
20+
}
21+
defer devInfo.Close()
22+
devInfoData, err := devInfo.CreateDeviceInfo("Wintun", deviceClassNetGUID, "", 0, setupapi.DICD_GENERATE_ID)
23+
if err != nil {
24+
return err
25+
}
26+
err = devInfo.SetDeviceRegistryProperty(devInfoData, setupapi.SPDRP_HARDWAREID, []byte("W\x00i\x00n\x00t\x00u\x00n\x00\x00\x00\x00\x00"))
27+
if err != nil {
28+
return err
29+
}
30+
err = devInfo.BuildDriverInfoList(devInfoData, setupapi.SPDIT_COMPATDRIVER)
31+
if err != nil {
32+
return err
33+
}
34+
defer devInfo.DestroyDriverInfoList(devInfoData, setupapi.SPDIT_COMPATDRIVER)
35+
var lastError error
36+
for i := 0; ; i++ {
37+
drvInfoData, err := devInfo.EnumDriverInfo(devInfoData, setupapi.SPDIT_COMPATDRIVER, i)
38+
if err != nil {
39+
if err == windows.ERROR_NO_MORE_ITEMS {
40+
break
41+
}
42+
continue
43+
}
44+
drvInfoDetailData, err := devInfo.DriverInfoDetail(devInfoData, drvInfoData)
45+
if err != nil {
46+
continue
47+
}
48+
lastError = setupapi.SetupUninstallOEMInf(filepath.Base(drvInfoDetailData.InfFileName()), 0)
49+
}
50+
return lastError
51+
}

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ require (
66
github.com/lxn/walk v0.0.0-20210112085537-c389da54e794
77
github.com/lxn/win v0.0.0-20210218163916-a377121e959e
88
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
9-
golang.org/x/net v0.0.0-20211020060615-d418f374d309
10-
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359
11-
golang.org/x/text v0.3.8-0.20211004125949-5bd84dd9b33b
9+
golang.org/x/net v0.0.0-20211029160332-540bb53d3b2e
10+
golang.org/x/sys v0.0.0-20211029165221-6e7872819dc8
11+
golang.org/x/text v0.3.8-0.20211029042148-bb1c79828956
1212
)
1313

1414
require (
@@ -20,5 +20,5 @@ require (
2020
replace (
2121
github.com/lxn/walk => golang.zx2c4.com/wireguard/windows v0.0.0-20210121140954-e7fc19d483bd
2222
github.com/lxn/win => golang.zx2c4.com/wireguard/windows v0.0.0-20210224134948-620c54ef6199
23-
golang.org/x/sys => golang.zx2c4.com/wireguard/windows v0.0.0-20211026085405-4db69cf28188
23+
golang.org/x/sys => golang.zx2c4.com/wireguard/windows v0.0.0-20211029170807-5c05bdce0504
2424
)

go.sum

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
66
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
77
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
88
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
9-
golang.org/x/net v0.0.0-20211020060615-d418f374d309/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
9+
golang.org/x/net v0.0.0-20211029160332-540bb53d3b2e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
1010
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
1111
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
12-
golang.org/x/text v0.3.8-0.20211004125949-5bd84dd9b33b h1:NXqSWXSRUSCaFuvitrWtU169I3876zRTalMRbfd6LL0=
13-
golang.org/x/text v0.3.8-0.20211004125949-5bd84dd9b33b/go.mod h1:EFNZuWvGYxIRUEX+K8UmCFwYmZjqcrnq15ZuVldZkZ0=
12+
golang.org/x/text v0.3.8-0.20211029042148-bb1c79828956 h1:xw/3G76i8BwoCoEZ8RzhVpFrHEz4Qm9D7zPckwa7KVM=
13+
golang.org/x/text v0.3.8-0.20211029042148-bb1c79828956/go.mod h1:EFNZuWvGYxIRUEX+K8UmCFwYmZjqcrnq15ZuVldZkZ0=
1414
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
1515
golang.org/x/tools v0.1.7 h1:6j8CgantCy3yc8JGBqkDLMKWqZ0RDU2g1HVgacojGWQ=
1616
golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
@@ -22,5 +22,5 @@ golang.zx2c4.com/wireguard/windows v0.0.0-20210121140954-e7fc19d483bd h1:kAUzMAI
2222
golang.zx2c4.com/wireguard/windows v0.0.0-20210121140954-e7fc19d483bd/go.mod h1:Y+FYqVFaQO6a+1uigm0N0GiuaZrLEaBxEiJ8tfH9sMQ=
2323
golang.zx2c4.com/wireguard/windows v0.0.0-20210224134948-620c54ef6199 h1:ogXKLng/Myrt2odYTkleySGzQj/GWg9GV1AQ8P9NnU4=
2424
golang.zx2c4.com/wireguard/windows v0.0.0-20210224134948-620c54ef6199/go.mod h1:KxxjdtRkfNoYDCUP5ryK7XJJNTnpC8atvtmTheChOtk=
25-
golang.zx2c4.com/wireguard/windows v0.0.0-20211026085405-4db69cf28188 h1:dn58scjvJtbJHUasC10DOLt+dgcwSOSB3AZU9YpvXS8=
26-
golang.zx2c4.com/wireguard/windows v0.0.0-20211026085405-4db69cf28188/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
25+
golang.zx2c4.com/wireguard/windows v0.0.0-20211029170807-5c05bdce0504 h1:nieMJi73mSTXbdllDz6R7Es9QoYOry/q88v1F45ev4A=
26+
golang.zx2c4.com/wireguard/windows v0.0.0-20211029170807-5c05bdce0504/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ func main() {
318318
if len(os.Args) != 2 {
319319
usage()
320320
}
321+
_ = driver.UninstallLegacyWintun() // Best effort
321322
err := driver.Uninstall()
322323
if err != nil {
323324
fatal(err)

manager/service.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717

1818
"golang.org/x/sys/windows"
1919
"golang.org/x/sys/windows/svc"
20+
"golang.zx2c4.com/wireguard/windows/driver"
2021

2122
"golang.zx2c4.com/wireguard/windows/conf"
2223
"golang.zx2c4.com/wireguard/windows/elevate"
@@ -259,6 +260,7 @@ func (service *managerService) Execute(args []string, r <-chan svc.ChangeRequest
259260
}
260261

261262
go checkForUpdates()
263+
go driver.UninstallLegacyWintun() // We uninstall opportunistically here, so that we don't have to carry around the uninstaller code forever.
262264

263265
var sessionsPointer *windows.WTS_SESSION_INFO
264266
var count uint32

0 commit comments

Comments
 (0)