MCPcopy Create free account
hub / github.com/codeyourweb/irma / CheckCurrentUserPermissions

Function CheckCurrentUserPermissions

main.go:207–231  ·  view source on GitHub ↗

CheckCurrentUserPermissions retieves the current user permissions and check if the program run with elevated privileges

()

Source from the content-addressed store, hash-verified

205
206// CheckCurrentUserPermissions retieves the current user permissions and check if the program run with elevated privileges
207func CheckCurrentUserPermissions() (admin bool, elevated bool) {
208 var err error
209 var sid *windows.SID
210 err = windows.AllocateAndInitializeSid(
211 &windows.SECURITY_NT_AUTHORITY,
212 2,
213 windows.SECURITY_BUILTIN_DOMAIN_RID,
214 windows.DOMAIN_ALIAS_RID_ADMINS,
215 0, 0, 0, 0, 0, 0,
216 &sid)
217 if err != nil {
218 log.Fatalf("[ERROR] SID Error: %s", err)
219 return false, false
220 }
221 defer windows.FreeSid(sid)
222 token := windows.Token(0)
223
224 admin, err = token.IsMember(sid)
225 if err != nil {
226 log.Fatalf("[ERROR] Token Membership Error: %s", err)
227 return false, false
228 }
229
230 return admin, token.IsElevated()
231}

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected