<s> from __future__ import unicode_literals <EOL> import win32security <EOL> from winsys import accounts , constants , core , exc , utils <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> class x_lsa ( exc . x_winsys ) : <EOL> "<STR_LIT>" <EOL> WINERROR_MAP = { <EOL> } <EOL> wrapped = exc . wrapper ( WINERROR_MAP , x_lsa ) <EOL> def principal ( account ) : <EOL> try : <EOL> return accounts . principal ( account ) <EOL> except exc . x_not_found : <EOL> return "<STR_LIT>" <EOL> class LogonSession ( core . _WinSysObject ) : <EOL> _MAP = { <EOL> "<STR_LIT>" : principal , <EOL> "<STR_LIT>" : principal , <EOL> "<STR_LIT>" : utils . from_pytime <EOL> } <EOL> def __init__ ( self , session_id ) : <EOL> core . _WinSysObject . __init__ ( self ) <EOL> self . _session_id = session_id <EOL> self . _session_info = dict ( session_id = self . _session_id ) <EOL> for k , v in wrapped ( win32security . LsaGetLogonSessionData , session_id ) . items ( ) : <EOL> mapper = self . _MAP . get ( k ) <EOL> if mapper : v = mapper ( v ) <EOL> self . _session_info [ k ] = v <EOL> def __getattr__ ( self , attr ) : <EOL> return self . _session_info [ attr ] <EOL> def __dir__ ( self ) : <EOL> return list ( self . _session_info . iterkeys ( ) ) <EOL> def as_string ( self ) : <EOL> return "<STR_LIT>" % self . _session_info <EOL> def dumped ( self , level ) : <EOL> output = [ ] <EOL> output . append ( "<STR_LIT>" % self . _session_id ) <EOL> output . append ( "<STR_LIT>" % self . UserName ) <EOL> output . append ( "<STR_LIT>" % ( self . Sid . sid if self . Sid else None ) ) <EOL> output . append ( "<STR_LIT>" % self . LogonTime ) <EOL> return utils . dumped ( "<STR_LIT:\n>" . join ( output ) , level ) <EOL> class LSA ( core . _WinSysObject ) : <EOL> def __init__ ( self , system_name = None ) : <EOL> core . _WinSysObject . __init__ ( self ) <EOL> self . _lsa = wrapped ( win32security . LsaOpenPolicy , system_name , <NUM_LIT:0> ) <EOL> @ staticmethod <EOL> def logon_sessions ( ) : <EOL> for session_id in wrapped ( win32security . LsaEnumerateLogonSessions ) : <EOL> yield LogonSession ( session_id ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> for logon_session in LSA . logon_sessions ( ) : <EOL> logon_session . dump ( ) </s>
