def StoreResults(self, responses): """Stores the responses.""" client_id = responses.request.client_id # TODO(user): Should we record client usage stats? processed_responses = [] wmi_interface_parser = wmi_parser.WMIInterfacesParser() for response in responses: if isinstance(response, rdf_client.Interface): processed_responses.extend( filter(None, [self.ProcessInterface(response)])) elif isinstance(response, rdf_protodict.Dict): # This is a result from the WMIQuery call processed_responses.extend( list(wmi_interface_parser.Parse(None, response, None))) new_responses = flow.FakeResponses(processed_responses, responses.request_data) new_responses.success = responses.success new_responses.status = responses.status self.AddResultsToCollection(new_responses, client_id) # Respect both the expiry and pause controls, since this will otherwise run # forever. Pausing will effectively stop this hunt, and a new one will need # to be created. if self.runner.IsHuntStarted(): # Re-issue the request to the client for the next collection. client_call_list = self._GetCallClientList([client_id]) if client_call_list: self._CallClients(client_call_list) else: self.MarkClientDone(client_id)
def testInterfaceParsing(self): parser = wmi_parser.WMIInterfacesParser() rdf_dict = rdf_protodict.Dict() wmi_properties = ( client_fixture.WMIWin32NetworkAdapterConfigurationMock.__dict__. iteritems()) for key, value in wmi_properties: if not key.startswith("__"): try: rdf_dict[key] = value except TypeError: rdf_dict[key] = "Failed to encode: %s" % value result_list = list(parser.Parse(None, rdf_dict, None)) self.assertEqual(len(result_list), 2) for result in result_list: if isinstance(result, rdf_client.Interface): self.assertEqual(len(result.addresses), 4) self.assertItemsEqual( [x.human_readable_address for x in result.addresses], [ "192.168.1.20", "ffff::ffff:aaaa:1111:aaaa", "dddd:0:8888:6666:bbbb:aaaa:eeee:bbbb", "dddd:0:8888:6666:bbbb:aaaa:ffff:bbbb" ]) self.assertItemsEqual([ x.human_readable_address for x in result.dhcp_server_list ], ["192.168.1.1"]) self.assertEqual( result.dhcp_lease_expires.AsMicroSecondsFromEpoch(), 1409008979123456) self.assertEqual( result.dhcp_lease_obtained.AsMicroSecondsFromEpoch(), 1408994579123456) elif isinstance(result, rdf_client.DNSClientConfiguration): self.assertItemsEqual( result.dns_server, ["192.168.1.1", "192.168.255.81", "192.168.128.88"]) self.assertItemsEqual(result.dns_suffix, [ "blah.example.com", "ad.example.com", "internal.example.com", "example.com" ])