Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Check Security context flags
from ctypes import CDLL, byref, c_uint32
Security = CDLL('/System/Library/Frameworks/Security.framework/Versions/Current/Security')
kcallerSecuritySession = c_uint32(-1)
my_session = c_uint32(0)
session_bits = c_uint32(0)
result = Security.SessionGetInfo(kcallerSecuritySession, byref(my_session), byref(session_bits))
flags = session_bits.value
print "sessionIsRoot:", bool(flags & 0x0001)
print "sessionHasGraphicAccess:", bool(flags & 0x0010)
print "sessionHasTTY:", bool(flags & 0x0020)
print "sessionIsRemote:", bool(flags & 0x1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment