Example #1
0
    def do_PUT(self):
        chunked = False
        if 'Transfer-encoding' in self.headers:
            contentLength = 0
            chunked = True
        elif 'Content-Length' in self.headers:
            chunked = False
            contentLength = int(self.headers['Content-Length'])
        else:
            # send 411: Length Required
            self.send_error(411)

        authToken = self.getAuth()

        if self.cfg.proxyContentsDir:
            status, reason = netclient.httpPutFile(self.path, self.rfile,
                                                   contentLength)
            self.send_response(status)
            return

        path = self.path.split("?")[-1]

        if '/' in path:
            self.send_error(403)

        path = self.tmpDir + '/' + path + "-in"

        size = os.stat(path).st_size
        if size != 0:
            self.send_error(410)
            return

        out = open(path, "w")
        try:
            if chunked:
                while 1:
                    chunk = self.rfile.readline()
                    chunkSize = int(chunk, 16)
                    # chunksize of 0 means we're done
                    if chunkSize == 0:
                        break
                    util.copyfileobj(self.rfile, out, sizeLimit=chunkSize)
                    # read the \r\n after the chunk we just copied
                    self.rfile.readline()
            else:
                util.copyfileobj(self.rfile, out, sizeLimit=contentLength)
        finally:
            out.close()
        self.send_response(200)
        self.end_headers()
Example #2
0
    def do_PUT(self):
        chunked = False
        if 'Transfer-encoding' in self.headers:
            contentLength = 0
            chunked = True
        elif 'Content-Length' in self.headers:
            chunked = False
            contentLength = int(self.headers['Content-Length'])
        else:
            # send 411: Length Required
            self.send_error(411)

        authToken = self.getAuth()

        if self.cfg.proxyContentsDir:
            status, reason = netclient.httpPutFile(self.path, self.rfile, contentLength)
            self.send_response(status)
            return

        path = self.path.split("?")[-1]

        if '/' in path:
            self.send_error(403)

        path = self.tmpDir + '/' + path + "-in"

        size = os.stat(path).st_size
        if size != 0:
            self.send_error(410)
            return

        out = open(path, "w")
        try:
            if chunked:
                while 1:
                    chunk = self.rfile.readline()
                    chunkSize = int(chunk, 16)
                    # chunksize of 0 means we're done
                    if chunkSize == 0:
                        break
                    util.copyfileobj(self.rfile, out, sizeLimit=chunkSize)
                    # read the \r\n after the chunk we just copied
                    self.rfile.readline()
            else:
                util.copyfileobj(self.rfile, out, sizeLimit=contentLength)
        finally:
            out.close()
        self.send_response(200)
        self.end_headers()
Example #3
0
def putFile(port, isSecure, repos, req):
    if isinstance(repos, proxy.ProxyRepositoryServer):
        contentLength = int(req.headers_in['Content-length'])
        headers = [
            x for x in req.headers_in.iteritems() if x[0].lower() in (
                'x-conary-servername',
                'x-conary-entitlement',
            )
        ]
        status, reason = netclient.httpPutFile(req.unparsed_uri,
                                               req,
                                               contentLength,
                                               headers=headers)
        return status

    if not isSecure and repos.cfg.forceSSL or '/' in req.args:
        return apache.HTTP_FORBIDDEN

    path = repos.tmpPath + "/" + req.args + "-in"
    size = os.stat(path).st_size
    if size != 0:
        return apache.HTTP_UNAUTHORIZED

    retcode = apache.OK
    f = open(path, "w+")
    try:
        try:
            s = req.read(BUFFER)
            while s:
                f.write(s)
                s = req.read(BUFFER)
        except IOError:
            # Client timed out, etc. Even if they're not around to get
            # a response, apache can make a useful log entry.
            retcode = apache.HTTP_BAD_REQUEST
        except Exception, e:
            # for some reason, this is a different instance of the
            # apache.SERVER_RETURN class than we have available from
            # mod_python, so we can't catch only the SERVER_RETURN
            # exception
            if 'SERVER_RETURN' in str(e.__class__):
                retcode = e.args[0]
            else:
                raise
    finally:
        f.close()

    return retcode
Example #4
0
def putFile(port, isSecure, repos, req):
    if isinstance(repos, proxy.ProxyRepositoryServer):
        contentLength = int(req.headers_in['Content-length'])
        headers = [x for x in req.headers_in.iteritems() if x[0].lower() in (
            'x-conary-servername',
            'x-conary-entitlement',
            )]
        status, reason = netclient.httpPutFile(req.unparsed_uri, req,
                contentLength, headers=headers)
        return status

    if not isSecure and repos.cfg.forceSSL or '/' in req.args:
        return apache.HTTP_FORBIDDEN

    path = repos.tmpPath + "/" + req.args + "-in"
    size = os.stat(path).st_size
    if size != 0:
        return apache.HTTP_UNAUTHORIZED

    retcode = apache.OK
    f = open(path, "w+")
    try:
        try:
            s = req.read(BUFFER)
            while s:
                f.write(s)
                s = req.read(BUFFER)
        except IOError:
            # Client timed out, etc. Even if they're not around to get
            # a response, apache can make a useful log entry.
            retcode = apache.HTTP_BAD_REQUEST
        except Exception, e:
            # for some reason, this is a different instance of the
            # apache.SERVER_RETURN class than we have available from
            # mod_python, so we can't catch only the SERVER_RETURN
            # exception
            if 'SERVER_RETURN' in str(e.__class__):
                retcode = e.args[0]
            else:
                raise
    finally:
        f.close()

    return retcode
Example #5
0
    def putChangeset(self):
        """PUT method -- handle changeset uploads."""
        if not self.repositoryServer:
            # FIXME: this mechanism is unauthenticated and can probably be used
            # to PUT content to random things on the internet
            if 'content-length' in self.request.headers:
                size = int(self.request.headers['content-length'])
            else:
                size = None
            headers = [
                x for x in self.request.headers.items() if x[0].lower() in (
                    'x-conary-servername',
                    'x-conary-entitlement',
                )
            ]
            result = netclient.httpPutFile(
                self.request.url,
                self.request.body_file,
                size,
                headers=headers,
                chunked=(size is None),
                withResponse=True,
            )
            return self.responseFactory(
                status='%s %s' % (result.status, result.reason),
                app_iter=self._produceProxy(result),
                #headerlist=result.getheaders(),
            )

        # Copy request body to the designated temporary file.
        stream = self.request.body_file
        out = self._openForPut()
        if out is None:
            # File already exists or is in an illegal location.
            return self._makeError('403 Forbidden', "Illegal changeset upload")

        util.copyfileobj(stream, out)
        out.close()

        return self.responseFactory(status='200 OK')
Example #6
0
    def putChangeset(self):
        """PUT method -- handle changeset uploads."""
        if not self.repositoryServer:
            # FIXME: this mechanism is unauthenticated and can probably be used
            # to PUT content to random things on the internet
            if 'content-length' in self.request.headers:
                size = int(self.request.headers['content-length'])
            else:
                size = None
            headers = [x for x in self.request.headers.items()
                    if x[0].lower() in (
                        'x-conary-servername',
                        'x-conary-entitlement',
                        )]
            result = netclient.httpPutFile(self.request.url,
                    self.request.body_file,
                    size,
                    headers=headers,
                    chunked=(size is None),
                    withResponse=True,
                    )
            return self.responseFactory(
                    status='%s %s' % (result.status, result.reason),
                    app_iter=self._produceProxy(result),
                    #headerlist=result.getheaders(),
                    )

        # Copy request body to the designated temporary file.
        stream = self.request.body_file
        out = self._openForPut()
        if out is None:
            # File already exists or is in an illegal location.
            return self._makeError('403 Forbidden', "Illegal changeset upload")

        util.copyfileobj(stream, out)
        out.close()

        return self.responseFactory(status='200 OK')