MCPcopy Create free account
hub / github.com/SamNet-dev/snix / IsElevated

Function IsElevated

platform/windows/privilege.go:45–62  ·  view source on GitHub ↗

IsElevated reports whether the current process has the Administrators group in its effective token — i.e. WinDivertOpen will succeed (modulo driver state). We check via CheckTokenMembership against the well-known SECURITY_BUILTIN_DOMAIN_RID \ DOMAIN_ALIAS_RID_ADMINS SID. This is the standard Win32

()

Source from the content-addressed store, hash-verified

43// standard Win32 pattern and works for both Run-as-admin sessions and
44// services running under LocalSystem.
45func IsElevated() (bool, error) {
46 var sid *windows.SID
47 err := windows.AllocateAndInitializeSid(
48 &windows.SECURITY_NT_AUTHORITY,
49 2,
50 windows.SECURITY_BUILTIN_DOMAIN_RID,
51 windows.DOMAIN_ALIAS_RID_ADMINS,
52 0, 0, 0, 0, 0, 0,
53 &sid,
54 )
55 if err != nil {
56 return false, err
57 }
58 defer windows.FreeSid(sid)
59
60 // Passing a zero token uses the impersonation token of the calling thread.
61 return checkTokenMembership(0, sid)
62}

Callers 1

OpenMethod · 0.85

Calls 1

checkTokenMembershipFunction · 0.85

Tested by

no test coverage detected