예제 #1
0
  def testExistingFileStat(self):
    bash_stat = {
        "st_ctime":
            rdfvalue.RDFDatetimeSeconds(1299502221),
        "st_rdev":
            0,
        "st_mtime":
            rdfvalue.RDFDatetimeSeconds(1284154642),
        "st_blocks":
            16,
        "st_nlink":
            1,
        "st_gid":
            0,
        "st_blksize":
            4096,
        "pathspec":
            rdf_paths.PathSpec(
                path="/bin/bash", pathtype="OS", path_options="CASE_LITERAL"),
        "st_dev":
            51713,
        "st_size":
            4874,
        "st_ino":
            1026148,
        "st_uid":
            0,
        "st_mode":
            rdf_client.StatMode(33261),
        "st_atime":
            rdfvalue.RDFDatetimeSeconds(1299502220)
    }

    bash_path = os.path.join("/", self.client_name, "fs/os/c/bin/bash")
    self.assertItemsEqual(self.passthrough.getattr(bash_path), bash_stat)
예제 #2
0
  def testPrettyPrintMode(self):

    for mode, result in [
        (0775, "-rwxrwxr-x"),
        (075, "----rwxr-x"),
        (0, "----------"),
        # DIR
        (040775, "drwxrwxr-x"),
        # SUID
        (35232, "-rwSr-----"),
        # GID
        (34208, "-rw-r-S---"),
        # CHR
        (9136, "crw-rw---T"),
        # BLK
        (25008, "brw-rw----"),
        # FIFO
        (4516, "prw-r--r--"),
        # Socket
        (49663, "srwxrwxrwx"),
        # Sticky
        (33791, "-rwxrwxrwt"),
        # Sticky, not x
        (33784, "-rwxrwx--T"),
    ]:
      value = rdf_client.StatMode(mode)
      self.assertEqual(unicode(value), result)
예제 #3
0
파일: searching.py 프로젝트: binsrc/grr
  def QuickListDirectory(self, pathspec, state):
    """Quick recursive generator of files."""
    try:
      fd = vfs.VFSOpen(pathspec, progress_callback=self.Progress)
    except (IOError, OSError) as e:
      # We failed to open the directory the server asked for because dir
      # doesn't exist or some other reason. So we set status and return
      # back to the caller ending the Iterator.
      self.SetStatus(rdf_flows.GrrStatus.ReturnedStatus.IOERROR, e)

      return

    root = None
    for top, dirs, files in fd.RecursiveListNames(self.request.max_depth,
                                                  self.request.cross_devs):
      if root is None:
        root = top

      # pyformat: disable
      for name, is_dir in itertools.chain(((name, True) for name in dirs),
                                          ((name, False) for name in files)):
        # pyformat: enable
        path = os.path.join(top, name)[len(root) + 1:]

        if self.request.path_regex.Match(path):
          # Generate fake minimal stat entries for compatibility.
          yield rdf_client.StatEntry(
              pathspec=fd.pathspec.Copy().Append(
                  rdf_paths.PathSpec(
                      pathtype=pathspec.pathtype,
                      path=path,
                      path_options="CASE_LITERAL")),
              st_mode=rdf_client.StatMode(stat.S_IFDIR if is_dir else 0))