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>
pull/1694/head
Brad Fitzpatrick 4 years ago
parent e619296ece
commit c0befee188

@ -16,11 +16,21 @@ import (
const pollInterval = 5 * time.Second const pollInterval = 5 * time.Second
func listPorts() (List, error) { 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") return listPortsNetstat("-na")
} }
func addProcesses(pl []Port) ([]Port, error) { 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("-na")
} }
return listPortsNetstat("-nab") return listPortsNetstat("-nab")

Loading…
Cancel
Save