예제 #1
0
    def testInequality(self):
        foo = objects.PathID(["quux", "foo"])
        bar = objects.PathID(["quux", "bar"])

        self.assertIsNot(foo, bar)
        self.assertNotEqual(foo, bar)
예제 #2
0
    def testEquality(self):
        foo = objects.PathID(["quux", "norf"])
        bar = objects.PathID(["quux", "norf"])

        self.assertIsNot(foo, bar)
        self.assertEqual(foo, bar)
예제 #3
0
 def testRepr(self):
     string = str(objects.PathID(["foo", "bar", "baz"]))
     self.assertRegexpMatches(string, r"^PathID\(\'[0-9a-f]{64}\'\)$")
예제 #4
0
 def testReprEmpty(self):
     string = str(objects.PathID([]))
     self.assertEqual(string, "PathID('{}')".format("0" * 64))
예제 #5
0
파일: vfs.py 프로젝트: hanul93/grr
    def _HandleRelational(self, args, token=None):
        client_id = args.client_id.ToClientURN()

        if not args.file_path or args.file_path == "/":
            return self._GetRootChildren(args, token=token)

        if args.file_path == "fs":
            return self._GetFilesystemChildren(args)

        path_type, components = rdf_objects.ParseCategorizedPath(
            args.file_path)
        path_id = rdf_objects.PathID(components)

        child_path_ids = data_store.REL_DB.FindDescendentPathIDs(
            client_id=client_id.Basename(),
            path_type=path_type,
            path_id=path_id,
            max_depth=1)

        child_path_infos = data_store.REL_DB.FindPathInfosByPathIDs(
            client_id=client_id.Basename(),
            path_type=path_type,
            path_ids=child_path_ids).values()

        items = []

        for child_path_info in child_path_infos:
            if args.directories_only and not child_path_info.directory:
                continue

            child_item = ApiFile()
            child_item.name = child_path_info.basename

            if path_type == rdf_objects.PathInfo.PathType.OS:
                prefix = "fs/os/"
            elif path_type == rdf_objects.PathInfo.PathType.TSK:
                prefix = "fs/tsk/"
            elif path_type == rdf_objects.PathInfo.PathType.REGISTRY:
                prefix = "registry/"
            elif path_type == rdf_objects.PathInfo.PathType.TEMP:
                prefix = "temp/"

            child_item.path = prefix + "/".join(child_path_info.components)

            # TODO(hanuszczak): `PathInfo#directory` tells us whether given path has
            # ever been observed as a directory. Is this what we want here or should
            # we use `st_mode` information instead?
            child_item.is_directory = child_path_info.directory
            child_item.stat = child_path_info.stat_entry

            # The `age` field collides with RDF `age` pseudo-property so `Set` lets us
            # set the right thing.
            child_item.Set("age", child_path_info.timestamp)

            items.append(child_item)

        # TODO(hanuszczak): Instead of getting the whole list from the database and
        # then filtering the results we should do the filtering directly in the
        # database query.
        if args.filter:
            pattern = re.compile(args.filter, re.IGNORECASE)
            is_matching = lambda item: pattern.search(item.name)
            items = filter(is_matching, items)

        items.sort(key=lambda item: item.path)

        if args.count:
            items = items[args.offset:args.offset + args.count]
        else:
            items = items[args.offset:]

        return ApiListFilesResult(items=items)