예제 #1
0
파일: action_test.py 프로젝트: lismore/grr
    def testStatFS(self):
        f_bsize = 4096
        # Simulate pre-2.6 kernel
        f_frsize = 0
        f_blocks = 9743394
        f_bfree = 5690052
        f_bavail = 5201809
        f_files = 2441216
        f_ffree = 2074221
        f_favail = 2074221
        f_flag = 4096
        f_namemax = 255

        def MockStatFS(unused_path):
            return posix.statvfs_result(
                (f_bsize, f_frsize, f_blocks, f_bfree, f_bavail, f_files,
                 f_ffree, f_favail, f_flag, f_namemax))

        def MockIsMount(path):
            """Only return True for the root path."""
            return path == "/"

        with utils.MultiStubber((os, "statvfs", MockStatFS),
                                (os.path, "ismount", MockIsMount)):

            # This test assumes "/" is the mount point for /usr/bin
            results = self.RunAction(
                "StatFS",
                rdf_client.StatFSRequest(path_list=["/usr/bin", "/"]))
            self.assertEqual(len(results), 2)

            # Both results should have mount_point as "/"
            self.assertEqual(results[0].unixvolume.mount_point,
                             results[1].unixvolume.mount_point)
            result = results[0]
            self.assertEqual(result.bytes_per_sector, f_bsize)
            self.assertEqual(result.sectors_per_allocation_unit, 1)
            self.assertEqual(result.total_allocation_units, f_blocks)
            self.assertEqual(result.actual_available_allocation_units,
                             f_bavail)
            self.assertAlmostEqual(result.FreeSpacePercent(),
                                   53.388,
                                   delta=0.001)
            self.assertEqual(result.unixvolume.mount_point, "/")
            self.assertEqual(result.Name(), "/")

            # Test we get a result even if one path is bad
            results = self.RunAction(
                "StatFS",
                rdf_client.StatFSRequest(path_list=["/does/not/exist", "/"]))
            self.assertEqual(len(results), 1)
            self.assertEqual(result.Name(), "/")
예제 #2
0
파일: filesystem.py 프로젝트: vishvega/grr
 def CollectVolumeInfo(self, unused_responses):
     if self.state.system == "Windows":
         # No dependencies for WMI
         deps = artifact_utils.ArtifactCollectorFlowArgs.Dependency.IGNORE_DEPS
         self.CallFlow("ArtifactCollectorFlow",
                       artifact_list=["WMILogicalDisks"],
                       next_state="ProcessWindowsVolumes",
                       dependencies=deps,
                       store_results_in_aff4=True)
     else:
         self.CallClient(server_stubs.StatFS,
                         rdf_client.StatFSRequest(
                             path_list=self.args.path_list,
                             pathtype=self.args.pathtype),
                         next_state="ProcessVolumes")
예제 #3
0
 def CollectVolumeInfo(self, unused_responses):
     if self.state.system == "Windows":
         # No dependencies for WMI
         deps = artifact_utils.ArtifactCollectorFlowArgs.Dependency.IGNORE_DEPS
         self.CallFlow(
             # TODO(user): dependency loop between collectors.py and
             # filesystem.py.
             # collectors.ArtifactCollectorFlow.__name__,
             "ArtifactCollectorFlow",
             artifact_list=["WMILogicalDisks"],
             next_state="ProcessWindowsVolumes",
             dependencies=deps)
     else:
         self.CallClient(server_stubs.StatFS,
                         rdf_client.StatFSRequest(
                             path_list=self.args.path_list,
                             pathtype=self.args.pathtype),
                         next_state="ProcessVolumes")