Beispiel #1
0
    def _locToFilePath(self, path, environ=None):
        path_parts = path.strip("/").split("/")

        if len(path_parts) < 1:
            raise RuntimeError("Security exception: tried to access root")

        course_id = path_parts[0]
        try:
            course = self.course_factory.get_course(course_id)
        except:
            raise RuntimeError("Unknown course {}".format(course_id))

        path_to_course_fs = course.get_fs()
        if not isinstance(path_to_course_fs, LocalFSProvider):
            raise RuntimeError(
                "WebDav access is only supported if INGInious is using a local filesystem to access tasks"
            )
        path_to_course = os.path.abspath(path_to_course_fs.prefix)

        file_path = os.path.abspath(
            os.path.join(path_to_course, *path_parts[1:]))
        if not file_path.startswith(path_to_course):
            raise RuntimeError(
                "Security exception: tried to access file outside course root: {}"
                .format(file_path))

        # Convert to unicode
        file_path = util.toUnicode(file_path)
        return file_path
		def invalidate(app_id, obj_id, path):
			cache.last_access = datetime.now()
			key = (app_id, obj_id, path.encode("utf8"))
			with lock:
				try:
					
					result = cache.pop(key)
					cache[key] = (result[0], 1)
				except:
					pass
				for key in cache:
					if (key[0], key[1]) == (app_id, obj_id) and util.isChildUri(util.toUnicode(path), util.toUnicode(key[2])):
						cache.pop(key,None)
    def _locToFilePath(self, path, environ=None):
        """Convert resource path to a unicode absolute file path.
        Optional environ argument may be useful e.g. in relation to per-user
        sub-folder chrooting inside rootFolderPath.
        """
        assert self.rootFolderPath is not None
        assert compat.is_native(path)
        pathInfoParts = path.strip("/").split("/")

        r = os.path.abspath(os.path.join(self.rootFolderPath, *pathInfoParts))
        if not r.startswith(self.rootFolderPath):
            raise RuntimeError(
                "Security exception: tried to access file outside root.")
        r = util.toUnicode(r)
        #        print "_locToFilePath(%s, %s): %s" % (path, environ, r)
        return r
Beispiel #4
0
    def getResourceInst(self, path, environ):
        """Return info dictionary for path.

        See DAVProvider.getResourceInst()
        """
        self._count_getResourceInst += 1
        fp = util.toUnicode(path.rstrip("/"))
        r_obj = self.nibbler.get_resource(fp)

        if r_obj is None:
            return None

        if r_obj.is_dir():
            return FolderResource(self.nibbler, path, environ, r_obj)

        return FileResource(self.nibbler, path, environ, r_obj)
Beispiel #5
0
    def _locToFilePath(self, path, environ=None):
        course_id = self._get_course_id(path)
        try:
            course = self.course_factory.get_course(course_id)
        except:
            raise RuntimeError("Unknown course {}".format(course_id))

        path_to_course_fs = course.get_fs()
        path_to_course = os.path.abspath(path_to_course_fs.prefix)

        file_path = os.path.abspath(os.path.join(path_to_course, *self._get_inner_path(path)))
        if not file_path.startswith(path_to_course):
            raise RuntimeError("Security exception: tried to access file outside course root: {}".format(file_path))

        # Convert to unicode
        file_path = util.toUnicode(file_path)
        return file_path
    def _locToFilePath(self, path, environ=None):
        """Convert resource path to a unicode absolute file path.
        Optional environ argument may be useful e.g. in relation to per-user
        sub-folder chrooting inside rootFolderPath.
        """
        root_path = self.rootFolderPath
        assert root_path is not None
        assert compat.is_native(root_path)
        assert compat.is_native(path)

        path_parts = path.strip("/").split("/")
        file_path = os.path.abspath(os.path.join(root_path, *path_parts))
        if not file_path.startswith(root_path):
            raise RuntimeError("Security exception: tried to access file outside root: {}"
                .format(file_path))

        # Convert to unicode
        file_path = util.toUnicode(file_path)
        return file_path
Beispiel #7
0
    def _locToFilePath(self, path, environ=None):
        path_parts = path.strip("/").split("/")

        if len(path_parts) < 1:
            raise RuntimeError("Security exception: tried to access root")

        course_id = path_parts[0]
        try:
            course = self.course_factory.get_course(course_id)
        except:
            raise RuntimeError("Unknown course {}".format(course_id))

        path_to_course_fs = course.get_fs()
        path_to_course = os.path.abspath(path_to_course_fs.prefix)

        file_path = os.path.abspath(os.path.join(path_to_course, *path_parts[1:]))
        if not file_path.startswith(path_to_course):
            raise RuntimeError("Security exception: tried to access file outside course root: {}".format(file_path))

        # Convert to unicode
        file_path = util.toUnicode(file_path)
        return file_path