tsucchi/p5-Net-MySQL — Issue #1: Please patch MySQL.pm with support for extended authentication
Author: mnikhil-git
Created: 2011-12-31 13:20:13+00:00
State: open

Hi,

Can you please patch Net::MySQL with the bug and patch described in https://rt.cpan.org/Public/Bug/Display.html?id=21462 , to support the extended authentication with MySQL later versions of 5.0 and above?

Having MySQL.pm fixed with what is the protocol described in http://www.bernzilla.com/item.php?id=862 has got me plugged to use Net::MySQL in a working mode. I see the bug has been opened and patch has been supplied on RT/CPAN but somehow seems to have been missed.

On CPAN's doc, this github link is pointing to the new source. Please patch the following into the upstream.

This is krisodb's readily available patch (and NOT mine) and happy that its working. Please note that this patch is for 0.11 stream.

----------------------------------------------------------------

--- backup/MySQL.pm 2011-12-31 18:26:54.000000000 +0530
+++ /usr/lib/perl5/site_perl/5.8.8/Net/MySQL.pm 2011-12-31 18:27:08.000000000 +0530
@@ -224,6 +224,8 @@
$i += 4;
$self->{salt} = substr $message, $i, 8;
#
+ $self->{saltold} = $self->{salt};
+ #
$i += 8+1;
if (length $message >= $i + 1) {
$i += 1;
@@ -256,7 +258,19 @@
croak "Timeout of authentication";
}
croak substr $auth_result, 7;
- }
+ } elsif (ord(substr $auth_result, 4) == 254 ) {
+ $self->_send_password();
+ $mysql->recv($auth_result, BUFFER_LENGTH, 0);
+ $self->_dump_packet($auth_result) if Net::MySQL->debug;
+ if ($self->_is_error($auth_result)) {
+ $mysql->close;
+ if (length $auth_result < 7) {
+ croak "Timeout of authentication";
+ }
+ croak substr $auth_result, 7;
+ }
+
+ }
print "connect database\n" if Net::MySQL->debug;
}

@@ -281,6 +295,21 @@
}

+sub _send_password
+{
+ my $self = shift;
+ my $mysql = $self->{socket};
+ my $body = "\0\0\x03".
+ Net::MySQL::Password32->scramble(
+ $self->{password}, $self->{saltold}, $self->{client_capabilities}
+ );
+ $body .= "\0";
+ my $pw_message = chr(length($body)-3). $body;
+ $mysql->send($pw_message, 0);
+ $self->_dump_packet($pw_message) if Net::MySQL->debug;
+}
+
+

sub _execute_command
{
@@ -457,7 +486,7 @@
my $self = shift;
#substr($_[0], -1) ne "\xfe";
#$self->_dump_packet(substr($_[0], -5));
- return substr($_[0], -5, 1) ne "\xfe";
+ return substr($_[0], -5) ne "\xfe\0\0\x22\x00";
}

-------------------------------------------------------------------------------------