Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 4990

Show
Ignore:
Timestamp:
09/04/06 17:55:28 (3 years ago)
Author:
david
Message:

Fixed the Ruby/MySQL adapter we ship with Active Record to work with the new authentication handshake that was introduced in MySQL 4.1, along with the other protocol changes made at that time (closes #5723) [jimw@mysql.com]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r4981 r4990  
    11*SVN* 
     2 
     3* Fixed the Ruby/MySQL adapter we ship with Active Record to work with the new authentication handshake that was introduced in MySQL 4.1, along with the other protocol changes made at that time #5723 [jimw@mysql.com] 
    24 
    35* Deprecation: use :dependent => :delete_all rather than :exclusively_dependent => true.  #6024 [Josh Susser] 
  • trunk/activerecord/lib/active_record/vendor/mysql.rb

    r3274 r4990  
    77class Mysql 
    88 
    9   VERSION = "4.0-ruby-0.2.5
     9  VERSION = "4.0-ruby-0.2.6-plus-changes
    1010 
    1111  require "socket" 
     
    1818  MYSQL_PORT = 3306 
    1919  PROTOCOL_VERSION = 10 
     20 
     21  SCRAMBLE_LENGTH = 20 
     22  SCRAMBLE_LENGTH_323 = 8 
    2023 
    2124  # Command 
     
    148151    end 
    149152    write data 
    150     read 
     153    pkt = read 
     154    handle_auth_fallback(pkt, passwd) 
    151155    ObjectSpace.define_finalizer(self, Mysql.finalizer(@net)) 
    152156    self 
    153157  end 
    154158  alias :connect :real_connect 
     159 
     160  def handle_auth_fallback(pkt, passwd) 
     161    # A packet like this means that we need to send an old-format password 
     162    if pkt.size == 1 and pkt[0] == 254 and 
     163       @server_capabilities & CLIENT_SECURE_CONNECTION != 0 then 
     164      data = scramble(passwd, @scramble_buff, @protocol_version == 9) 
     165      write data + "\0" 
     166      read 
     167    end 
     168  end 
    155169 
    156170  def escape_string(str) 
     
    209223      data = user+"\0"+scramble41(passwd, @scramble_buff)+db 
    210224    end 
    211     command COM_CHANGE_USER, data 
     225    pkt = command COM_CHANGE_USER, data 
     226    handle_auth_fallback(pkt, passwd) 
    212227    @user = user 
    213228    @passwd = passwd 
     
    535550    raise "old version password is not implemented" if old_ver 
    536551    hash_pass = hash_password password 
    537     hash_message = hash_password message 
     552    hash_message = hash_password message.slice(0,SCRAMBLE_LENGTH_323) 
    538553    rnd = Random::new hash_pass[0] ^ hash_message[0], hash_pass[1] ^ hash_message[1] 
    539554    to = [] 
    540     1.upto(message.length) do 
     555    1.upto(SCRAMBLE_LENGTH_323) do 
    541556      to << ((rnd.rnd*31)+64).floor 
    542557    end