<s> """<STR_LIT>""" <EOL> import cStringIO <EOL> import os <EOL> import stat <EOL> from binplist import binplist <EOL> from grr . lib import parsers <EOL> from grr . lib . rdfvalues import client as rdf_client <EOL> from grr . lib . rdfvalues import plist as rdf_plist <EOL> class OSXUsersParser ( parsers . ArtifactFilesParser ) : <EOL> """<STR_LIT>""" <EOL> output_types = [ "<STR_LIT>" ] <EOL> supported_artifacts = [ "<STR_LIT>" ] <EOL> blacklist = [ "<STR_LIT>" ] <EOL> def Parse ( self , stat_entries , knowledge_base , path_type ) : <EOL> """<STR_LIT>""" <EOL> _ , _ = knowledge_base , path_type <EOL> for stat_entry in stat_entries : <EOL> if stat . S_ISDIR ( stat_entry . st_mode ) : <EOL> homedir = stat_entry . pathspec . path <EOL> username = os . path . basename ( homedir ) <EOL> if username not in self . blacklist : <EOL> yield rdf_client . User ( username = username , homedir = homedir ) <EOL> class OSXSPHardwareDataTypeParser ( parsers . CommandParser ) : <EOL> """<STR_LIT>""" <EOL> output_types = [ "<STR_LIT>" ] <EOL> supported_artifacts = [ "<STR_LIT>" ] <EOL> def Parse ( self , cmd , args , stdout , stderr , return_val , time_taken , <EOL> knowledge_base ) : <EOL> """<STR_LIT>""" <EOL> _ = stderr , time_taken , args , knowledge_base <EOL> self . CheckReturn ( cmd , return_val ) <EOL> serial_number = [ ] <EOL> hardware_list = [ ] <EOL> plist = binplist . readPlist ( cStringIO . StringIO ( stdout ) ) <EOL> if len ( plist ) > <NUM_LIT:1> : <EOL> raise parsers . ParseError ( "<STR_LIT>" ) <EOL> hardware_list = plist [ <NUM_LIT:0> ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] <EOL> serial_number = hardware_list [ "<STR_LIT>" ] <EOL> yield rdf_client . HardwareInfo ( serial_number = serial_number ) <EOL> class OSXLaunchdPlistParser ( parsers . FileParser ) : <EOL> """<STR_LIT>""" <EOL> output_types = [ "<STR_LIT>" ] <EOL> supported_artifacts = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> def Parse ( self , statentry , file_object , knowledge_base ) : <EOL> """<STR_LIT>""" <EOL> _ = knowledge_base <EOL> kwargs = { } <EOL> kwargs [ "<STR_LIT>" ] = statentry . aff4path <EOL> direct_copy_items = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> string_array_items = [ "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] <EOL> flag_only_items = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> plist = { } <EOL> try : <EOL> plist = binplist . readPlist ( file_object ) <EOL> except ( binplist . FormatError , ValueError , IOError ) as e : <EOL> plist [ "<STR_LIT>" ] = "<STR_LIT>" % e <EOL> for key in direct_copy_items : <EOL> kwargs [ key ] = plist . get ( key ) <EOL> for key in string_array_items : <EOL> elements = plist . get ( key ) <EOL> if isinstance ( elements , basestring ) : <EOL> kwargs [ key ] = [ elements ] <EOL> else : <EOL> kwargs [ key ] = elements <EOL> for key in flag_only_items : <EOL> if plist . get ( key ) : <EOL> kwargs [ key ] = True <EOL> if plist . get ( "<STR_LIT>" ) is not None : <EOL> kwargs [ "<STR_LIT>" ] = plist . get ( <EOL> "<STR_LIT>" ) . get ( "<STR_LIT>" ) <EOL> keepalive = plist . get ( "<STR_LIT>" ) <EOL> if isinstance ( keepalive , bool ) or keepalive is None : <EOL> kwargs [ "<STR_LIT>" ] = keepalive <EOL> else : <EOL> keepalivedict = { } <EOL> keepalivedict [ "<STR_LIT>" ] = keepalive . get ( "<STR_LIT>" ) <EOL> keepalivedict [ "<STR_LIT>" ] = keepalive . get ( "<STR_LIT>" ) <EOL> pathstates = keepalive . get ( "<STR_LIT>" ) <EOL> if pathstates is not None : <EOL> keepalivedict [ "<STR_LIT>" ] = [ ] <EOL> for pathstate in pathstates : <EOL> keepalivedict [ "<STR_LIT>" ] . append ( <EOL> rdf_plist . PlistBoolDictEntry ( name = pathstate , <EOL> value = pathstates [ pathstate ] ) ) <EOL> otherjobs = keepalive . get ( "<STR_LIT>" ) <EOL> if otherjobs is not None : <EOL> keepalivedict [ "<STR_LIT>" ] = [ ] <EOL> for otherjob in otherjobs : <EOL> keepalivedict [ "<STR_LIT>" ] . append ( <EOL> rdf_plist . PlistBoolDictEntry ( name = otherjob , <EOL> value = otherjobs [ otherjob ] ) ) <EOL> kwargs [ "<STR_LIT>" ] = rdf_plist . LaunchdKeepAlive ( ** keepalivedict ) <EOL> envvars = plist . get ( "<STR_LIT>" ) <EOL> if envvars is not None : <EOL> kwargs [ "<STR_LIT>" ] = [ ] <EOL> for envvar in envvars : <EOL> kwargs [ "<STR_LIT>" ] . append ( <EOL> rdf_plist . PlistStringDictEntry ( name = envvar , <EOL> value = envvars [ envvar ] ) ) <EOL> startcalendarinterval = plist . get ( "<STR_LIT>" ) <EOL> if startcalendarinterval is not None : <EOL> if isinstance ( startcalendarinterval , dict ) : <EOL> kwargs [ "<STR_LIT>" ] = [ <EOL> rdf_plist . LaunchdStartCalendarIntervalEntry ( <EOL> Minute = startcalendarinterval . get ( "<STR_LIT>" ) , <EOL> Hour = startcalendarinterval . get ( "<STR_LIT>" ) , <EOL> Day = startcalendarinterval . get ( "<STR_LIT>" ) , <EOL> Weekday = startcalendarinterval . get ( "<STR_LIT>" ) , <EOL> Month = startcalendarinterval . get ( "<STR_LIT>" ) ) ] <EOL> else : <EOL> kwargs [ "<STR_LIT>" ] = [ ] <EOL> for entry in startcalendarinterval : <EOL> kwargs [ "<STR_LIT>" ] . append ( <EOL> rdf_plist . LaunchdStartCalendarIntervalEntry ( <EOL> Minute = entry . get ( "<STR_LIT>" ) , <EOL> Hour = entry . get ( "<STR_LIT>" ) , <EOL> Day = entry . get ( "<STR_LIT>" ) , <EOL> Weekday = entry . get ( "<STR_LIT>" ) , <EOL> Month = entry . get ( "<STR_LIT>" ) ) ) <EOL> yield rdf_plist . LaunchdPlist ( ** kwargs ) </s>
