go-watchdog/cmd/watchdog/installer/whoami_windows.go

33 lines
656 B
Go
Raw Normal View History

2019-06-27 08:54:51 +00:00
package installer
import "os/user"
2019-06-29 21:05:13 +00:00
// IsAdmin returns true if the user can be determined to be an admin
// and false otherwise (errs on the side of non-admin).
func IsAdmin() bool {
2019-06-27 08:54:51 +00:00
u, err := user.Current()
if nil != err {
return false
}
// https://support.microsoft.com/en-us/help/243330/well-known-security-identifiers-in-windows-operating-systems
// not quite, but close enough for now
// BUILTIN\ADMINISTRATORS
if "S-1-5-32-544" == u.Uid || "S-1-5-32-544" == u.Gid {
return true
}
2019-06-29 21:05:13 +00:00
ids, err := u.GroupIds()
if nil != err {
return false
}
2019-06-27 08:54:51 +00:00
for i := range ids {
if "S-1-5-32-544" == ids[i] {
return true
}
}
return false
}