예제 #1
0
    def Open(cls, fd, component, pathspec):
        """Try to correct the casing of component.

    This method is called when we failed to open the component directly. We try
    to transform the component into something which is likely to work.

    In this implementation, we correct the case of the component until we can
    not open the path any more.

    Args:
      fd: The base fd we will use.
      component: The component we should open.
      pathspec: The rest of the pathspec object.

    Returns:
      A file object.

    Raises:
      IOError: If nothing could be opened still.
    """
        # The handler for this component
        try:
            handler = VFS_HANDLERS[component.pathtype]
        except KeyError:
            raise IOError("VFS handler %d not supported." % component.pathtype)

        # We will not do any case folding unless requested.
        if component.path_options == rdfvalue.PathSpec.Options.CASE_LITERAL:
            return handler(base_fd=fd, pathspec=component)

        path_components = client_utils.LocalPathToCanonicalPath(component.path)
        path_components = ["/"] + filter(None, path_components.split("/"))
        for i, path_component in enumerate(path_components):
            try:
                if fd:
                    new_pathspec = fd.MatchBestComponentName(path_component)
                else:
                    new_pathspec = component
                    new_pathspec.path = path_component

                # The handler for this component
                try:
                    handler = VFS_HANDLERS[new_pathspec.pathtype]
                except KeyError:
                    raise IOError("VFS handler %d not supported." %
                                  new_pathspec.pathtype)

                fd = handler(base_fd=fd, pathspec=new_pathspec)
            except IOError:
                # Can not open the first component, we must raise here.
                if i <= 1:
                    raise IOError("File not found")

                # Insert the remaining path at the front of the pathspec.
                pathspec.Insert(0,
                                path=utils.JoinPath(*path_components[i:]),
                                pathtype=rdfvalue.PathSpec.PathType.TSK)
                break

        return fd
예제 #2
0
    def Open(cls, fd, component, pathspec):
        # A Pathspec which starts with TSK means we need to resolve the mount point
        # at runtime.
        if fd is None and component.pathtype == rdfvalue.PathSpec.PathType.TSK:
            # We are the top level handler. This means we need to check the system
            # mounts to work out the exact mount point and device we need to
            # open. We then modify the pathspec so we get nested in the raw
            # pathspec.
            raw_pathspec, corrected_path = client_utils.GetRawDevice(
                component.path)

            # Insert the raw device before the component in the pathspec and correct
            # the path
            component.path = corrected_path
            pathspec.Insert(0, component)
            pathspec.Insert(0, raw_pathspec)

            # Allow incoming pathspec to be given in the local system path
            # conventions.
            for component in pathspec:
                if component.path:
                    component.path = client_utils.LocalPathToCanonicalPath(
                        component.path)

            # We have not actually opened anything in this iteration, but modified the
            # pathspec. Next time we should be able to open it properly.
            return fd

        # If an inode is specified, just use it directly.
        elif component.HasField("inode"):
            return TSKFile(fd, component)

        # Otherwise do the usual case folding.
        else:
            return vfs.VFSHandler.Open(fd, component, pathspec)
예제 #3
0
 def Stat(self, fname, opts):
     stat = self._GetStat(fname, follow_symlink=opts.resolve_links)
     pathspec = rdf_paths.PathSpec(
         pathtype=rdf_paths.PathSpec.PathType.OS,
         path=client_utils.LocalPathToCanonicalPath(fname),
         path_options=rdf_paths.PathSpec.Options.CASE_LITERAL)
     return files.MakeStatResponse(stat,
                                   pathspec=pathspec,
                                   ext_attrs=opts.collect_ext_attrs)
예제 #4
0
파일: file_finder.py 프로젝트: rdsece/grr
    def Stat(self, fname, stat_object, resolve_links):
        if resolve_links and stat.S_ISLNK(stat_object.st_mode):
            try:
                stat_object = os.stat(fname)
            except OSError:
                return None

        pathspec = rdf_paths.PathSpec(
            pathtype=rdf_paths.PathSpec.PathType.OS,
            path=client_utils.LocalPathToCanonicalPath(fname),
            path_options=rdf_paths.PathSpec.Options.CASE_LITERAL)
        return files.MakeStatResponse(stat_object, pathspec=pathspec)
예제 #5
0
    def Stat(self, fname, stat, opts):
        if opts.resolve_links and stat.IsSymlink():
            try:
                stat = utils.Stat(fname, follow_symlink=True)
            except OSError:
                return None

        pathspec = rdf_paths.PathSpec(
            pathtype=rdf_paths.PathSpec.PathType.OS,
            path=client_utils.LocalPathToCanonicalPath(fname),
            path_options=rdf_paths.PathSpec.Options.CASE_LITERAL)
        return files.MakeStatResponse(stat,
                                      pathspec=pathspec,
                                      ext_attrs=opts.ext_attrs)
예제 #6
0
파일: file_finder.py 프로젝트: dc865/grr
def _StatEntry(stat, ext_attrs):
    pathspec = rdf_paths.PathSpec(
        pathtype=rdf_paths.PathSpec.PathType.OS,
        path=client_utils.LocalPathToCanonicalPath(stat.GetPath()),
        path_options=rdf_paths.PathSpec.Options.CASE_LITERAL)
    return files.MakeStatResponse(stat, pathspec=pathspec, ext_attrs=ext_attrs)