Skip to content

Instantly share code, notes, and snippets.

@pudquick
Created June 10, 2014 22:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pudquick/b1188a35a47c314e42b6 to your computer and use it in GitHub Desktop.
Save pudquick/b1188a35a47c314e42b6 to your computer and use it in GitHub Desktop.
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