Ejemplo n.º 1
0
def do_auth(user, password, server_sock):
    """Doing roomahost authentication."""
    auth_req = packet.AuthReq()
    auth_req.build(user, password)
    
    written, err = mysock.send(server_sock, auth_req.payload)
    
    #sending packet failed
    if err != None or written < len(auth_req.payload):
        print "can't send auth req to server.err = ", err
        return False
    
    #receiving reply failed
    ba_rsp, err = mysock.recv(server_sock, 1024)
    if err != None:
        print "failed to get auth reply"
        return False
    
    #bad username/password
    rsp = packet.AuthRsp(ba_rsp)
    if rsp.get_val() != packet.AUTH_RSP_OK:
        print "Authentication failed"
        if rsp.get_val() == packet.AUTH_RSP_BAD_USERPASS:
            print "Bad user/password"
            print "Please check your user/password"
        return False
    return True
Ejemplo n.º 2
0
 def _do_forward_data_pkt(self, rsp):
     """Forward DataRsp packet."""
     data = rsp.get_data()
     
     written, err = mysock.send(self.sock, data)
     if err != None:
         LOG.warning("_do_forward_data_pkt:can't forward data to peer. end this peer")
         self.ended = True
         return False, -1
     
     if written != len(data):
         LOG.warning("peer.forward_rsp_pkt partial %s:%s" % self.addr)
         self.enq_rsp(data[written])
     
     if rsp.is_eof() == True:
         self.ended = True
     
     return True, written