portlist: use windows OpenCurrentProcessToken, not GetCurrentProcessToken

The latter only works on Windows 8+.

Also add a TODO to get do this all more efficiently.

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2021-04-12 09:23:49 -07:00
parent e619296ece
commit c0befee188
1 changed files with 11 additions and 1 deletions

View File

@ -16,11 +16,21 @@ import (
const pollInterval = 5 * time.Second
func listPorts() (List, error) {
// TODO(bradfitz): stop shelling out to netstat and use the
// net/netstat package instead. When doing so, be sure to filter
// out all of 127.0.0.0/8 and not just 127.0.0.1.
return listPortsNetstat("-na")
}
func addProcesses(pl []Port) ([]Port, error) {
if t := windows.GetCurrentProcessToken(); !t.IsElevated() {
// OpenCurrentProcessToken instead of GetCurrentProcessToken,
// as GetCurrentProcessToken only works on Windows 8+.
tok, err := windows.OpenCurrentProcessToken()
if err != nil {
return nil, err
}
defer tok.Close()
if !tok.IsElevated() {
return listPortsNetstat("-na")
}
return listPortsNetstat("-nab")