Exemple #1
0
    def get_writer(self, file_name):
        """
        @see: L{IBackend.get_writer}

        @rtype: L{Deferred}, yielding a L{FilesystemWriter}

        """
        if not self.can_write:
            raise Unsupported("Writing not supported")
        try:
            target_path = self.base.descendant(file_name.split("/"))
        except InsecurePath, e:
            raise AccessViolation("Insecure path: %s" % e)
Exemple #2
0
    def get_reader(self, file_name):
        """
        @see: L{IBackend.get_reader}

        @rtype: L{Deferred}, yielding a L{FilesystemReader}

        """
        if not self.can_read:
            raise Unsupported("Reading not supported")
        try:
            target_path = self.base.descendant(file_name.split(b"/"))
        except InsecurePath as e:
            raise AccessViolation("Insecure path: %s" % e)
        return FilesystemReader(target_path)
    def test_unsupported(self):
        tftp = TFTP(BackendFactory(Unsupported("I don't support you")),
                    _clock=self.clock)
        tftp.transport = self.transport
        wrq_datagram = WRQDatagram(b'foobar', b'netascii', {})
        tftp.datagramReceived(wrq_datagram.to_wire(), ('127.0.0.1', 1111))
        self.clock.advance(1)
        error_datagram = TFTPDatagramFactory(
            *split_opcode(self.transport.value()))
        self.assertEqual(error_datagram.errorcode, ERR_ILLEGAL_OP)

        self.transport.clear()
        rrq_datagram = RRQDatagram(b'foobar', b'octet', {})
        tftp.datagramReceived(rrq_datagram.to_wire(), ('127.0.0.1', 1111))
        self.clock.advance(1)
        error_datagram = TFTPDatagramFactory(
            *split_opcode(self.transport.value()))
        self.assertEqual(error_datagram.errorcode, ERR_ILLEGAL_OP)
Exemple #4
0
    def get_reader(self, file_name):
        """
        @see: L{IBackend.get_reader}

        @rtype: L{Deferred}, yielding a L{FilesystemReader}

        """
        if not self.can_read:
            raise Unsupported("Reading not supported")
        try:
            target_path = self.base.descendant(file_name.split(b"/"))
        except InsecurePath as e:
            raise AccessViolation("Insecure path: %s" % e)
        try:
            # Try using FilesystemReader first
            return FilesystemReader(target_path)
        except FileNotFound:
            # Try using DynamicReader if dyn_handler was supplied
            if self.dyn_handler is not None:
                return DynamicReader(file_name, self.dyn_handler)
            else:
                raise