#At file:///home/kgeorge/mysql/work/wl1054-next-mr/ based on revid:georgi.kodinov@stripped
2972 Georgi Kodinov 2010-08-02
WL1054 :
- removed an unused variable from MPVIO (priv_user)
- moved the definition of make_lex_string_root () next to
THD::make_lex_string and removed code duplication
- created a properly named function for the special net_write_command call.
- used the proper function pointers instead of the absolute function names
modified:
sql/sql_acl.cc
sql/sql_class.cc
sql/sql_class.h
=== modified file 'sql/sql_acl.cc'
--- a/sql/sql_acl.cc 2010-07-30 15:43:16 +0000
+++ b/sql/sql_acl.cc 2010-08-02 13:42:25 +0000
@@ -7823,27 +7823,12 @@ struct MPVIO_EXT : public MYSQL_PLUGIN_V
uint *server_status;
NET *net;
ulong max_client_packet_length;
- char *priv_user;
char *ip;
char *host;
Thd_charset_adapter *charset_adapter;
LEX_STRING acl_user_plugin;
};
-static LEX_STRING *
-make_lex_string_root(MEM_ROOT *mem_root,
- LEX_STRING *lex_str, const char* str, uint length,
- bool allocate_lex_string)
-{
- if (allocate_lex_string)
- if (!(lex_str= (LEX_STRING *)alloc_root(mem_root, sizeof(LEX_STRING))))
- return 0;
- if (!(lex_str->str= strmake_root(mem_root, str, length)))
- return 0;
- lex_str->length= length;
- return lex_str;
-}
-
/**
a helper function to report an access denied error in all the proper places
*/
@@ -8271,8 +8256,6 @@ static bool parse_com_change_user_packet
return 1;
mpvio->auth_info.user_name_length= user_len;
- strmake(mpvio->priv_user, mpvio->auth_info.user_name, USERNAME_LENGTH);
-
if (make_lex_string_root(mpvio->mem_root,
&mpvio->db, db_buff, db_len, 0) == 0)
DBUG_RETURN (1); /* The error is set by make_lex_string(). */
@@ -8280,6 +8263,9 @@ static bool parse_com_change_user_packet
if (!initialized)
{
// if mysqld's been started with --skip-grant-tables option
+ strmake(mpvio->auth_info.authenticated_as,
+ mpvio->auth_info.user_name, USERNAME_LENGTH);
+
mpvio->status= MPVIO_EXT::SUCCESS;
DBUG_RETURN (0);
}
@@ -8555,6 +8541,30 @@ static ulong parse_client_handshake_pack
#endif
}
+
+/**
+ Make sure that when sending plugin supplued data to the client they
+ are not considered a special out-of-band command, like e.g.
+ \255 (error) or \254 (change user request packet).
+ To avoid this we send plugin data packets starting with one of these
+ 2 bytes "wrapped" in a command \1.
+ For the above reason we have to wrap plugin data packets starting with
+ \1 as well.
+*/
+
+#define IS_OUT_OF_BAND_PACKET(packet,packet_len) \
+ ((packet_len) > 0 && \
+ (*(packet) == 1 || *(packet) == 255 || *(packet) == 254))
+
+static inline int
+wrap_plguin_data_into_proper_command(NET *net,
+ const uchar *packet, int packet_len)
+{
+ DBUG_ASSERT(IS_OUT_OF_BAND_PACKET(packet, packet_len));
+ return net_write_command(net, 1, (uchar*)"", 0, packet, packet_len);
+}
+
+
/**
vio->write_packet() callback method for server authentication plugins
@@ -8579,17 +8589,8 @@ static int server_mpvio_write_packet(MYS
res= send_server_handshake_packet(mpvio, (char*)packet, packet_len);
else if (mpvio->status == MPVIO_EXT::RESTART)
res= send_plugin_request_packet(mpvio, packet, packet_len);
- else if (packet_len > 0 && (*packet == 1 || *packet == 255 || *packet == 254))
- {
- /*
- we cannot allow plugin data packet to start from 255 or 254 -
- as the client will treat it as an error or "change plugin" packet.
- We'll escape these bytes with \1. Consequently, we
- have to escape \1 byte too.
- */
- res= net_write_command(mpvio->net, 1, (uchar*)"", 0,
- packet, packet_len);
- }
+ else if (IS_OUT_OF_BAND_PACKET(packet, packet_len))
+ res= wrap_plguin_data_into_proper_command(mpvio->net, packet, packet_len);
else
{
res= my_net_write(mpvio->net, packet, packet_len) ||
@@ -8621,13 +8622,12 @@ static int server_mpvio_read_packet(MYSQ
plugin wants to read the data without sending anything first.
send an empty packet to force a server handshake packet to be sent
*/
- if (server_mpvio_write_packet(mpvio, 0, 0))
+ if (mpvio->write_packet(mpvio, 0, 0))
pkt_len= packet_error;
else
pkt_len= my_net_read(mpvio->net);
}
- else
- if (mpvio->cached_client_reply.pkt)
+ else if (mpvio->cached_client_reply.pkt)
{
DBUG_ASSERT(mpvio->status == MPVIO_EXT::RESTART);
DBUG_ASSERT(mpvio->packets_read > 0);
@@ -8654,7 +8654,7 @@ static int server_mpvio_read_packet(MYSQ
useless. Furthermore, we have to send a "change plugin" request
to the client.
*/
- if (server_mpvio_write_packet(mpvio, 0, 0))
+ if (mpvio->write_packet(mpvio, 0, 0))
pkt_len= packet_error;
else
pkt_len= my_net_read(mpvio->net);
@@ -8865,7 +8865,7 @@ static void
server_mpvio_initialize(THD *thd, MPVIO_EXT *mpvio, uint connect_errors,
Thd_charset_adapter *charset_adapter)
{
- bzero(mpvio, sizeof(MPVIO_EXT));
+ memset(mpvio, 0, sizeof(MPVIO_EXT));
mpvio->read_packet= server_mpvio_read_packet;
mpvio->write_packet= server_mpvio_write_packet;
mpvio->info= server_mpvio_info;
@@ -8885,7 +8885,6 @@ server_mpvio_initialize(THD *thd, MPVIO_
mpvio->thread_id= thd->thread_id;
mpvio->server_status= &thd->server_status;
mpvio->net= &thd->net;
- mpvio->priv_user= thd->security_ctx->priv_user;
mpvio->ip= thd->security_ctx->ip;
mpvio->host= thd->security_ctx->host;
mpvio->charset_adapter= charset_adapter;
=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc 2010-07-30 15:43:16 +0000
+++ b/sql/sql_class.cc 2010-08-02 13:42:25 +0000
@@ -1358,6 +1358,20 @@ void THD::cleanup_after_query()
}
+LEX_STRING *
+make_lex_string_root(MEM_ROOT *mem_root,
+ LEX_STRING *lex_str, const char* str, uint length,
+ bool allocate_lex_string)
+{
+ if (allocate_lex_string)
+ if (!(lex_str= (LEX_STRING *)alloc_root(mem_root, sizeof(LEX_STRING))))
+ return 0;
+ if (!(lex_str->str= strmake_root(mem_root, str, length)))
+ return 0;
+ lex_str->length= length;
+ return lex_str;
+}
+
/**
Create a LEX_STRING in this connection.
@@ -1372,13 +1386,8 @@ LEX_STRING *THD::make_lex_string(LEX_STR
const char* str, uint length,
bool allocate_lex_string)
{
- if (allocate_lex_string)
- if (!(lex_str= (LEX_STRING *)alloc(sizeof(LEX_STRING))))
- return 0;
- if (!(lex_str->str= strmake_root(mem_root, str, length)))
- return 0;
- lex_str->length= length;
- return lex_str;
+ return make_lex_string_root (mem_root, lex_str, str,
+ length, allocate_lex_string);
}
=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h 2010-07-26 09:08:37 +0000
+++ b/sql/sql_class.h 2010-08-02 13:42:25 +0000
@@ -2936,6 +2936,11 @@ my_eof(THD *thd)
#define reenable_binlog(A) (A)->variables.option_bits= tmp_disable_binlog__save_options;}
+LEX_STRING *
+make_lex_string_root(MEM_ROOT *mem_root,
+ LEX_STRING *lex_str, const char* str, uint length,
+ bool allocate_lex_string);
+
/*
Used to hold information about file and file structure in exchange
via non-DB file (...INTO OUTFILE..., ...LOAD DATA...)
Attachment: [text/bzr-bundle] bzr/georgi.kodinov@oracle.com-20100802134225-8m1o4v7o3kfnmygb.bundle
| Thread |
|---|
| • bzr commit into mysql-next-mr-wl1054 branch (Georgi.Kodinov:2972) | Georgi Kodinov | 2 Aug |