Exemplo n.º 1
0
    def testStatFS(self):
        import posix  # pylint: disable=g-import-not-at-top

        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."""
            # All code should ideally deal only with unicode paths. Unfortunately,
            # this is not always the case. While fixing path handling should be dealt
            # with at some point, for the time being this works and is more in line
            # with the original function (`os.path.ismount` works with bytestrings as
            # well).
            return path == "/" or path == b"/"

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

            # This test assumes "/" is the mount point for /usr/bin
            results = self.RunAction(
                standard.StatFS,
                rdf_client_action.StatFSRequest(path_list=["/usr/bin", "/"]))
            self.assertLen(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(
                standard.StatFS,
                rdf_client_action.StatFSRequest(
                    path_list=["/does/not/exist", "/"]))
            self.assertLen(results, 1)
            self.assertEqual(result.Name(), "/")
Exemplo n.º 2
0
    def testStatFS(self):
        import posix  # pylint: disable=g-import-not-at-top

        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(
                standard.StatFS,
                rdf_client_action.StatFSRequest(path_list=["/usr/bin", "/"]))
            self.assertLen(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(
                standard.StatFS,
                rdf_client_action.StatFSRequest(
                    path_list=["/does/not/exist", "/"]))
            self.assertLen(results, 1)
            self.assertEqual(result.Name(), "/")
Exemplo n.º 3
0
 def CollectVolumeInfo(self, responses):
     del responses
     if self.state.system == "Windows":
         # No dependencies for WMI
         deps = rdf_artifacts.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_action.StatFSRequest(
                             path_list=self.args.path_list,
                             pathtype=self.args.pathtype),
                         next_state="ProcessVolumes")
Exemplo n.º 4
0
  def _ProcessClientActionSource(self, source):
    # TODO(user): Add support for remaining client actions
    # EnumerateFilesystems and OSXEnumerateRunningServices

    request = {}
    action_name = source.base_source.attributes["client_action"]

    if action_name == "GetHostname":
      action = admin.GetHostnameFromClient

    elif action_name == "ListProcesses":
      action = standard.ListProcessesFromClient

    elif action_name == "ListNetworkConnections":
      action = network.ListNetworkConnectionsFromClient
      request = rdf_client_action.ListNetworkConnectionsArgs()

    elif action_name == "EnumerateInterfaces":
      action = operating_system.EnumerateInterfacesFromClient

    elif action_name == "EnumerateUsers":
      action = operating_system.EnumerateUsersFromClient

    # elif action_name == "EnumerateFilesystems":
    #   action = operating_system.EnumerateFilesystemsFromClient

    elif action_name == "StatFS":
      action = standard.StatFSFromClient
      paths = []
      if "action_args" in source.base_source.attributes:
        if "path_list" in source.base_source.attributes["action_args"]:
          paths = source.base_source.attributes["action_args"]["path_list"]
      request = rdf_client_action.StatFSRequest(
          path_list=paths, pathtype=source.path_type)

    # elif action_name == "OSXEnumerateRunningServices":
    #   action = operating_system.OSXEnumerateRunningServicesFromClient

    else:
      raise ValueError("Incorrect action type: %s" % action_name)

    yield action, request