blob: baa4d71b293f494865d86f7dfa0b350c004c17e1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
/* SPDX-License-Identifier: MIT
*
* Copyright (C) 2019 WireGuard LLC. All Rights Reserved.
*/
package elevate
import (
"runtime"
"golang.org/x/sys/windows"
)
func TokenIsMemberOfBuiltInAdministrator(token windows.Token) bool {
gs, err := token.GetTokenGroups()
if err != nil {
return false
}
isAdmin := false
for _, g := range gs.AllGroups() {
if (g.Attributes&windows.SE_GROUP_USE_FOR_DENY_ONLY != 0 || g.Attributes&windows.SE_GROUP_ENABLED != 0) && g.Sid.IsWellKnown(windows.WinBuiltinAdministratorsSid) {
isAdmin = true
break
}
}
runtime.KeepAlive(gs)
return isAdmin
}
|