Exemplo n.º 1
0
def connect(link):
    # Send the announce message - we only support protocol version 2.
    """

    :type link: SvnRequestHandler
    """
    link.send_msg(gen.success(2, 2, gen.list(),
                              gen.list(*server_capabilities)))
    msg = parse.msg(link.read_msg())

    proto_ver = int(msg[0])
    client_caps = msg[1]
    url = parse.string(msg[2])

    print "ver: %d" % proto_ver
    print "caps: %s" % client_caps
    print "url: %s" % url

    if proto_ver != 2:
        raise BadProtoVersion()

    repo, path, base_url = link.server.find_repo(url)

    if repo is None:
        link.send_msg(
            gen.failure(
                gen.list(210005,
                         gen.string("No repository found in '%s'" % url),
                         gen.string('message.py'), 0)))

    return path, client_caps, repo, base_url
Exemplo n.º 2
0
def connect(link):
    # Send the announce message - we only support protocol version 2.
    """

    :type link: SvnRequestHandler
    """
    link.send_msg(gen.success(2, 2, gen.list(), gen.list(*server_capabilities)))
    msg = parse.msg(link.read_msg())

    proto_ver = int(msg[0])
    client_caps = msg[1]
    url = parse.string(msg[2])

    print "ver: %d" % proto_ver
    print "caps: %s" % client_caps
    print "url: %s" % url

    if proto_ver != 2:
        raise BadProtoVersion()

    repo, path, base_url = link.server.find_repo(url)

    if repo is None:
        link.send_msg(gen.failure(gen.list(210005,
                                           gen.string("No repository found in '%s'" % url),
                                           gen.string('message.py'), 0)))

    return path, client_caps, repo, base_url
Exemplo n.º 3
0
    def perform_auth(self):
        """

        :rtype : User
        """
        msg_id = make_msgid()
        self.link.send_msg(gen.tuple('step', gen.string(msg_id)))

        resp = self.get_response()
        username, pass_hash = resp.rsplit(' ', 1)

        user = self.auth_db.get(username, None)
        if user is None:
            raise AuthFailure(gen.string('unknown user'))

        if pass_hash != hmac.new(user.password, msg_id).hexdigest():
            raise AuthFailure(gen.string('incorrect password'))

        self.link.send_msg(gen.success())
        return user
Exemplo n.º 4
0
    def perform_auth(self):
        """

        :rtype : User
        """
        msg_id = make_msgid()
        self.link.send_msg(gen.tuple('step', gen.string(msg_id)))

        resp = self.get_response()
        username, pass_hash = resp.rsplit(' ', 1)

        user = self.auth_db.get(username, None)
        if user is None:
            raise AuthFailure(gen.string('unknown user'))

        if pass_hash != hmac.new(user.password, msg_id).hexdigest():
            raise AuthFailure(gen.string('incorrect password'))

        self.link.send_msg(gen.success())
        return user
Exemplo n.º 5
0
def perform_auth(link, auth_db):
    """


    :type link: SvnRequestHandler
    :rtype : User
    """
    link.send_msg(gen.success(gen.list(*auths.keys()), gen.string(link.base_url)))

    while True:
        auth_type = parse.msg(link.read_msg())[0]

        if auth_type not in auths:
            link.send_msg(gen.failure(gen.string('unknown auth type: %s' % auth_type)))
            continue

        auth = auths[auth_type](link, auth_db)

        user = auth.do_auth()
        if user:
            return user
Exemplo n.º 6
0
def perform_auth(link, auth_db):
    """


    :type link: SvnRequestHandler
    :rtype : User
    """
    link.send_msg(
        gen.success(gen.list(*auths.keys()), gen.string(link.base_url)))

    while True:
        auth_type = parse.msg(link.read_msg())[0]

        if auth_type not in auths:
            link.send_msg(
                gen.failure(gen.string('unknown auth type: %s' % auth_type)))
            continue

        auth = auths[auth_type](link, auth_db)

        user = auth.do_auth()
        if user:
            return user
Exemplo n.º 7
0
    def handle(self):
        sys.stderr.write('%d: -- NEW CONNECTION --\n' % os.getpid())
        msg = None
        try:
            while True:
                try:
                    if self.mode == 'connect':
                        self.url, self.client_caps, self.repos, self.base_url = client.connect(self)

                        if self.client_caps is None or self.repos is None:
                            return

                        self.mode = 'auth'

                    elif self.mode == 'auth':
                        if self.user is None:
                            self.user = auth.perform_auth(self, self.server.users)
                            self.mode = 'announce'
                        else:
                            self.send_msg(gen.success(gen.list(), gen.string('')))
                            self.mode = self.data
                            self.data = None

                        if self.user is None:
                            return

                    elif self.mode == 'announce':
                        self.send_server_id()
                        self.mode = 'command'

                    elif self.mode == 'command':
                        if self.command is None:
                            self.command = command.process(self)
                        else:
                            self.command = self.command.process()

                    elif self.mode == 'editor':
                        editor.process(self)

                    elif self.mode == 'report':
                        report.process(self)

                    else:
                        raise ModeError("unknown mode '%s'" % self.mode)

                except ChangeMode as cm:
                    self.mode = cm.args[0]
                    if len(cm.args) > 1:
                        self.data = cm.args[1]
        except EOF:
            msg = 'EOF'
        except socket.error as e:
            errno, msg = e
        except Exception:
            try:
                self.send_msg(gen.error(235000, traceback.format_exc()))
            except Exception as e1:
                print e1
            raise

        sys.stderr.write('%d: -- CLOSE CONNECTION (%s) --\n' %
                         (os.getpid(), msg))
Exemplo n.º 8
0
 def send_server_id(self):
     self.send_msg(gen.success(gen.string(self.repos.uuid),
                               gen.string(self.base_url)))
Exemplo n.º 9
0
    def handle(self):
        sys.stderr.write('%d: -- NEW CONNECTION --\n' % os.getpid())
        msg = None
        try:
            while True:
                try:
                    if self.mode == 'connect':
                        self.url, self.client_caps, self.repos, self.base_url = client.connect(
                            self)

                        if self.client_caps is None or self.repos is None:
                            return

                        self.mode = 'auth'

                    elif self.mode == 'auth':
                        if self.user is None:
                            self.user = auth.perform_auth(
                                self, self.server.users)
                            self.mode = 'announce'
                        else:
                            self.send_msg(
                                gen.success(gen.list(), gen.string('')))
                            self.mode = self.data
                            self.data = None

                        if self.user is None:
                            return

                    elif self.mode == 'announce':
                        self.send_server_id()
                        self.mode = 'command'

                    elif self.mode == 'command':
                        if self.command is None:
                            self.command = command.process(self)
                        else:
                            self.command = self.command.process()

                    elif self.mode == 'editor':
                        editor.process(self)

                    elif self.mode == 'report':
                        report.process(self)

                    else:
                        raise ModeError("unknown mode '%s'" % self.mode)

                except ChangeMode as cm:
                    self.mode = cm.args[0]
                    if len(cm.args) > 1:
                        self.data = cm.args[1]
        except EOF:
            msg = 'EOF'
        except socket.error as e:
            errno, msg = e
        except Exception:
            try:
                self.send_msg(gen.error(235000, traceback.format_exc()))
            except Exception as e1:
                print e1
            raise

        sys.stderr.write('%d: -- CLOSE CONNECTION (%s) --\n' %
                         (os.getpid(), msg))
Exemplo n.º 10
0
 def send_server_id(self):
     self.send_msg(
         gen.success(gen.string(self.repos.uuid),
                     gen.string(self.base_url)))