1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Brian Aker
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
#include <drizzled/server_includes.h>
23
21
#include <drizzled/gettext.h>
24
22
#include <drizzled/error.h>
25
23
#include <drizzled/query_id.h>
26
24
#include <drizzled/sql_state.h>
27
25
#include <drizzled/session.h>
28
#include "drizzled/internal/my_sys.h"
29
#include "drizzled/internal/m_string.h"
28
#include "oldlibdrizzle.h"
29
#include "libdrizzle.h"
30
31
#include <algorithm>
32
#include <boost/program_options.hpp>
33
#include <drizzled/module/option_map.h>
34
#include "drizzled/util/tokenize.h"
35
#include "drizzle_protocol.h"
36
#include "plugin/drizzle_protocol/status_table.h"
38
namespace po= boost::program_options;
39
34
using namespace drizzled;
42
namespace drizzle_plugin
44
namespace drizzle_protocol
47
std::vector<std::string> ClientDrizzleProtocol::drizzle_admin_ip_addresses;
48
static port_constraint port;
49
static timeout_constraint connect_timeout;
50
static timeout_constraint read_timeout;
51
static timeout_constraint write_timeout;
52
static retry_constraint retry_count;
53
static buffer_constraint buffer_length;
55
static const uint32_t DRIZZLE_TCP_PORT= 4427;
57
ProtocolCounters *ListenDrizzleProtocol::drizzle_counters= new ProtocolCounters();
59
ListenDrizzleProtocol::~ListenDrizzleProtocol()
63
in_port_t ListenDrizzleProtocol::getPort(void) const
68
void ClientDrizzleProtocol::drizzle_compose_ip_addresses(vector<string> options)
70
for (vector<string>::iterator it= options.begin();
74
tokenize(*it, drizzle_admin_ip_addresses, ",", true);
78
bool ClientDrizzleProtocol::isAdminAllowed(void)
80
if (std::find(drizzle_admin_ip_addresses.begin(), drizzle_admin_ip_addresses.end(), session->user()->address()) != drizzle_admin_ip_addresses.end())
86
plugin::Client *ListenDrizzleProtocol::getClient(int fd)
36
#define PROTOCOL_VERSION 10
38
extern uint32_t drizzled_tcp_port;
40
static const unsigned int PACKET_BUFFER_EXTRA_ALLOC= 1024;
41
static uint32_t connect_timeout;
42
static uint32_t read_timeout;
43
static uint32_t write_timeout;
44
static uint32_t retry_count;
46
in_port_t ListenOldLibdrizzle::getPort(void) const
48
return (in_port_t) drizzled_tcp_port;
51
plugin::Client *ListenOldLibdrizzle::getClient(int fd)
54
return new (nothrow) ClientOldLibdrizzle(-1);
89
57
new_fd= acceptTcp(fd);
93
return new ClientDrizzleProtocol(new_fd, getCounters());
96
static int init(drizzled::module::Context &context)
98
const module::option_map &vm= context.getOptions();
100
context.add(new StatusTable);
101
context.add(new ListenDrizzleProtocol("drizzle_protocol", vm["bind-address"].as<std::string>(), true));
102
context.registerVariable(new sys_var_constrained_value_readonly<in_port_t>("port", port));
103
context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("connect_timeout", connect_timeout));
104
context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("read_timeout", read_timeout));
105
context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("write_timeout", write_timeout));
106
context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("retry_count", retry_count));
107
context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("buffer_length", buffer_length));
108
context.registerVariable(new sys_var_const_string_val("bind_address",
109
vm["bind-address"].as<std::string>()));
111
context.registerVariable(new sys_var_uint32_t_ptr("max-connections", &ListenDrizzleProtocol::drizzle_counters->max_connections));
117
static void init_options(drizzled::module::option_context &context)
120
po::value<port_constraint>(&port)->default_value(DRIZZLE_TCP_PORT),
121
N_("Port number to use for connection or 0 for default to with Drizzle/MySQL protocol."));
122
context("connect-timeout",
123
po::value<timeout_constraint>(&connect_timeout)->default_value(10),
124
N_("Connect Timeout."));
125
context("read-timeout",
126
po::value<timeout_constraint>(&read_timeout)->default_value(30),
127
N_("Read Timeout."));
128
context("write-timeout",
129
po::value<timeout_constraint>(&write_timeout)->default_value(60),
130
N_("Write Timeout."));
131
context("retry-count",
132
po::value<retry_constraint>(&retry_count)->default_value(10),
134
context("buffer-length",
135
po::value<buffer_constraint>(&buffer_length)->default_value(16384),
136
N_("Buffer length."));
137
context("bind-address",
138
po::value<std::string>()->default_value(""),
139
N_("Address to bind to."));
140
context("max-connections",
141
po::value<uint32_t>(&ListenDrizzleProtocol::drizzle_counters->max_connections)->default_value(1000),
142
N_("Maximum simultaneous connections."));
143
context("admin-ip-addresses",
144
po::value<vector<string> >()->composing()->notifier(&ClientDrizzleProtocol::drizzle_compose_ip_addresses),
145
N_("A restrictive IP address list for incoming admin connections."));
148
} /* namespace drizzle_protocol */
149
} /* namespace drizzle_plugin */
151
DRIZZLE_PLUGIN(drizzle_plugin::drizzle_protocol::init, NULL, drizzle_plugin::drizzle_protocol::init_options);
61
return new (nothrow) ClientOldLibdrizzle(new_fd);
64
static void write_eof_packet(Session *session, NET *net,
65
uint32_t server_status, uint32_t total_warn_count);
67
bool ClientOldLibdrizzle::isConnected()
72
void ClientOldLibdrizzle::setError(char error)
77
bool ClientOldLibdrizzle::haveError(void)
79
return net.error || net.vio == 0;
82
bool ClientOldLibdrizzle::wasAborted(void)
84
return net.error && net.vio != 0;
87
bool ClientOldLibdrizzle::haveMoreData(void)
89
return drizzleclient_net_more_data(&net);
92
bool ClientOldLibdrizzle::isReading(void)
94
return net.reading_or_writing == 1;
97
bool ClientOldLibdrizzle::isWriting(void)
99
return net.reading_or_writing == 2;
102
bool ClientOldLibdrizzle::netStoreData(const unsigned char *from, size_t length)
104
size_t packet_length= packet->length();
106
The +9 comes from that strings of length longer than 16M require
107
9 bytes to be stored (see drizzleclient_net_store_length).
109
if (packet_length+9+length > packet->alloced_length() &&
110
packet->realloc(packet_length+9+length))
112
unsigned char *to= drizzleclient_net_store_length((unsigned char*) packet->ptr()+packet_length, length);
113
memcpy(to,from,length);
114
packet->length((size_t) (to+length-(unsigned char*) packet->ptr()));
120
Return ok to the client.
122
The ok packet has the following structure:
124
- 0 : Marker (1 byte)
125
- affected_rows : Stored in 1-9 bytes
126
- id : Stored in 1-9 bytes
127
- server_status : Copy of session->server_status; Can be used by client
128
to check if we are inside an transaction.
130
- warning_count : Stored in 2 bytes; New in 4.1 client
131
- message : Stored as packed length (1-9 bytes) + message.
132
Is not stored if no message.
134
@param session Thread handler
135
@param affected_rows Number of rows changed by statement
136
@param id Auto_increment id for first row (if used)
137
@param message Message to send to the client (Used by mysql_status)
140
void ClientOldLibdrizzle::sendOK()
142
unsigned char buff[DRIZZLE_ERRMSG_SIZE+10],*pos;
143
const char *message= NULL;
146
if (!net.vio) // hack for re-parsing queries
151
buff[0]=0; // No fields
152
if (session->main_da.status() == Diagnostics_area::DA_OK)
154
if (client_capabilities & CLIENT_FOUND_ROWS && session->main_da.found_rows())
155
pos=drizzleclient_net_store_length(buff+1,session->main_da.found_rows());
157
pos=drizzleclient_net_store_length(buff+1,session->main_da.affected_rows());
158
pos=drizzleclient_net_store_length(pos, session->main_da.last_insert_id());
159
int2store(pos, session->main_da.server_status());
161
tmp= min(session->main_da.total_warn_count(), (uint32_t)65535);
162
message= session->main_da.message();
166
pos=drizzleclient_net_store_length(buff+1,0);
167
pos=drizzleclient_net_store_length(pos, 0);
168
int2store(pos, session->server_status);
170
tmp= min(session->total_warn_count, (uint32_t)65535);
173
/* We can only return up to 65535 warnings in two bytes */
177
session->main_da.can_overwrite_status= true;
179
if (message && message[0])
181
size_t length= strlen(message);
182
pos=drizzleclient_net_store_length(pos,length);
183
memcpy(pos,(unsigned char*) message,length);
186
drizzleclient_net_write(&net, buff, (size_t) (pos-buff));
187
drizzleclient_net_flush(&net);
189
session->main_da.can_overwrite_status= false;
193
Send eof (= end of result set) to the client.
195
The eof packet has the following structure:
197
- 254 (DRIZZLE_PROTOCOL_NO_MORE_DATA) : Marker (1 byte)
198
- warning_count : Stored in 2 bytes; New in 4.1 client
199
- status_flag : Stored in 2 bytes;
200
For flags like SERVER_MORE_RESULTS_EXISTS.
202
Note that the warning count will not be sent if 'no_flush' is set as
203
we don't want to report the warning count until all data is sent to the
207
void ClientOldLibdrizzle::sendEOF()
209
/* Set to true if no active vio, to work well in case of --init-file */
212
session->main_da.can_overwrite_status= true;
213
write_eof_packet(session, &net, session->main_da.server_status(),
214
session->main_da.total_warn_count());
215
drizzleclient_net_flush(&net);
216
session->main_da.can_overwrite_status= false;
222
Format EOF packet according to the current client and
223
write it to the network output buffer.
226
static void write_eof_packet(Session *session, NET *net,
227
uint32_t server_status,
228
uint32_t total_warn_count)
230
unsigned char buff[5];
232
Don't send warn count during SP execution, as the warn_list
233
is cleared between substatements, and mysqltest gets confused
235
uint32_t tmp= min(total_warn_count, (uint32_t)65535);
236
buff[0]= DRIZZLE_PROTOCOL_NO_MORE_DATA;
237
int2store(buff+1, tmp);
239
The following test should never be true, but it's better to do it
240
because if 'is_fatal_error' is set the server is not going to execute
241
other queries (see the if test in dispatch_command / COM_QUERY)
243
if (session->is_fatal_error)
244
server_status&= ~SERVER_MORE_RESULTS_EXISTS;
245
int2store(buff + 3, server_status);
246
drizzleclient_net_write(net, buff, 5);
249
void ClientOldLibdrizzle::sendError(uint32_t sql_errno, const char *err)
253
buff[]: sql_errno:2 + ('#':1 + SQLSTATE_LENGTH:5) + DRIZZLE_ERRMSG_SIZE:512
255
unsigned char buff[2+1+SQLSTATE_LENGTH+DRIZZLE_ERRMSG_SIZE], *pos;
258
assert(err && err[0]);
261
It's one case when we can push an error even though there
262
is an OK or EOF already.
264
session->main_da.can_overwrite_status= true;
266
/* Abort multi-result sets */
267
session->server_status&= ~SERVER_MORE_RESULTS_EXISTS;
270
Send a error string to client.
272
For SIGNAL/RESIGNAL and GET DIAGNOSTICS functionality it's
273
critical that every error that can be intercepted is issued in one
274
place only, my_message_sql.
282
int2store(buff,sql_errno);
285
/* The first # is to make the client backward compatible */
287
pos= (unsigned char*) strcpy((char*) buff+3, drizzle_errno_to_sqlstate(sql_errno));
288
pos+= strlen(drizzle_errno_to_sqlstate(sql_errno));
290
char *tmp= strncpy((char*)pos, err, DRIZZLE_ERRMSG_SIZE-1);
291
tmp+= strlen((char*)pos);
293
length= (uint32_t)(tmp-(char*)buff);
296
drizzleclient_net_write_command(&net,(unsigned char) 255, (unsigned char*) "", 0, (unsigned char*) err, length);
298
session->main_da.can_overwrite_status= false;
302
ClientOldLibdrizzle::ClientOldLibdrizzle(int fd)
310
if (drizzleclient_net_init_sock(&net, fd, 0))
313
drizzleclient_net_set_read_timeout(&net, read_timeout);
314
drizzleclient_net_set_write_timeout(&net, write_timeout);
315
net.retry_count=retry_count;
318
ClientOldLibdrizzle::~ClientOldLibdrizzle()
321
drizzleclient_vio_close(net.vio);
324
void ClientOldLibdrizzle::setSession(Session *session_arg)
326
session= session_arg;
327
packet= &session->packet;
328
convert= &session->convert_buffer;
334
Send name and type of result to client.
336
Sum fields has table name empty and field_name.
338
@param Session Thread data object
339
@param list List of items to send to client
340
@param flag Bit mask with the following functions:
341
- 1 send number of rows
342
- 2 send default values
343
- 4 don't write eof packet
348
1 Error (Note that in this case the error is not sent to the
351
bool ClientOldLibdrizzle::sendFields(List<Item> *list)
353
List_iterator_fast<Item> it(*list);
355
unsigned char buff[80];
356
String tmp((char*) buff,sizeof(buff),&my_charset_bin);
358
unsigned char *row_pos= drizzleclient_net_store_length(buff, list->elements);
359
(void) drizzleclient_net_write(&net, buff, (size_t) (row_pos-buff));
365
item->make_field(&field);
369
if (store(STRING_WITH_LEN("def")) ||
370
store(field.db_name) ||
371
store(field.table_name) ||
372
store(field.org_table_name) ||
373
store(field.col_name) ||
374
store(field.org_col_name) ||
375
packet->realloc(packet->length()+12))
378
/* Store fixed length fields */
379
pos= (char*) packet->ptr()+packet->length();
380
*pos++= 12; // Length of packed fields
382
int2store(pos, field.charsetnr);
383
int4store(pos+2, field.length);
385
int2store(pos+7,field.flags);
386
pos[9]= (char) field.decimals;
387
pos[10]= 0; // For the future
388
pos[11]= 0; // For the future
391
packet->length((uint32_t) (pos - packet->ptr()));
397
Mark the end of meta-data result set, and store session->server_status,
398
to show that there is no cursor.
399
Send no warning information, as it will be sent at statement end.
401
write_eof_packet(session, &net, session->server_status,
402
session->total_warn_count);
404
field_count= list->elements;
408
my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES),
414
bool ClientOldLibdrizzle::flush()
418
bool ret= drizzleclient_net_write(&net, (unsigned char*) packet->ptr(),
424
void ClientOldLibdrizzle::free()
429
int ClientOldLibdrizzle::getFileDescriptor(void)
431
return drizzleclient_net_get_sd(&net);
434
bool ClientOldLibdrizzle::authenticate()
436
bool connection_is_valid;
438
/* Use "connect_timeout" value during connection phase */
439
drizzleclient_net_set_read_timeout(&net, connect_timeout);
440
drizzleclient_net_set_write_timeout(&net, connect_timeout);
442
connection_is_valid= checkConnection();
444
if (connection_is_valid)
448
sendError(session->main_da.sql_errno(), session->main_da.message());
452
/* Connect completed, set read/write timeouts back to default */
453
drizzleclient_net_set_read_timeout(&net, read_timeout);
454
drizzleclient_net_set_write_timeout(&net, write_timeout);
458
bool ClientOldLibdrizzle::readCommand(char **l_packet, uint32_t *packet_length)
461
This thread will do a blocking read from the client which
462
will be interrupted when the next command is received from
463
the client, the connection is closed or "net_wait_timeout"
464
number of seconds has passed
467
/* We can do this much more efficiently with poll timeouts or watcher thread,
468
disabling for now, which means net_wait_timeout == read_timeout. */
469
drizzleclient_net_set_read_timeout(&net,
470
session->variables.net_wait_timeout);
475
*packet_length= drizzleclient_net_read(&net);
476
if (*packet_length == packet_error)
478
/* Check if we can continue without closing the connection */
480
if(net.last_errno== CR_NET_PACKET_TOO_LARGE)
481
my_error(ER_NET_PACKET_TOO_LARGE, MYF(0));
482
if (session->main_da.status() == Diagnostics_area::DA_ERROR)
483
sendError(session->main_da.sql_errno(), session->main_da.message());
488
return false; // We have to close it.
495
*l_packet= (char*) net.read_pos;
498
'packet_length' contains length of data, as it was stored in packet
499
header. In case of malformed header, drizzleclient_net_read returns zero.
500
If packet_length is not zero, drizzleclient_net_read ensures that the returned
501
number of bytes was actually read from network.
502
There is also an extra safety measure in drizzleclient_net_read:
503
it sets packet[packet_length]= 0, but only for non-zero packets.
506
if (*packet_length == 0) /* safety */
508
/* Initialize with COM_SLEEP packet */
509
(*l_packet)[0]= (unsigned char) COM_SLEEP;
512
/* Do not rely on drizzleclient_net_read, extra safety against programming errors. */
513
(*l_packet)[*packet_length]= '\0'; /* safety */
516
/* See comment above. */
517
/* Restore read timeout value */
518
drizzleclient_net_set_read_timeout(&net,
519
session->variables.net_read_timeout);
525
void ClientOldLibdrizzle::close(void)
529
drizzleclient_net_close(&net);
530
drizzleclient_net_end(&net);
534
void ClientOldLibdrizzle::forceClose(void)
537
drizzleclient_vio_close(net.vio);
540
void ClientOldLibdrizzle::prepareForResend()
545
bool ClientOldLibdrizzle::store(void)
549
return packet->append(buff, sizeof(buff), PACKET_BUFFER_EXTRA_ALLOC);
553
bool ClientOldLibdrizzle::store(const char *from, size_t length)
555
return netStoreData((const unsigned char *)from, length);
559
bool ClientOldLibdrizzle::store(int32_t from)
562
return netStoreData((unsigned char*) buff,
563
(size_t) (int10_to_str(from, buff, -10) - buff));
566
bool ClientOldLibdrizzle::store(uint32_t from)
569
return netStoreData((unsigned char*) buff,
570
(size_t) (int10_to_str(from, buff, 10) - buff));
573
bool ClientOldLibdrizzle::store(int64_t from)
576
return netStoreData((unsigned char*) buff,
577
(size_t) (int64_t10_to_str(from, buff, -10) - buff));
580
bool ClientOldLibdrizzle::store(uint64_t from)
583
return netStoreData((unsigned char*) buff,
584
(size_t) (int64_t10_to_str(from, buff, 10) - buff));
588
bool ClientOldLibdrizzle::store(double from, uint32_t decimals, String *buffer)
590
buffer->set_real(from, decimals, session->charset());
591
return netStoreData((unsigned char*) buffer->ptr(), buffer->length());
595
bool ClientOldLibdrizzle::store(Field *from)
599
char buff[MAX_FIELD_WIDTH];
600
String str(buff,sizeof(buff), &my_charset_bin);
604
return netStoreData((const unsigned char *)str.ptr(), str.length());
610
Second_part format ("%06") needs to change when
611
we support 0-6 decimals for time.
614
bool ClientOldLibdrizzle::store(const DRIZZLE_TIME *tm)
620
switch (tm->time_type)
622
case DRIZZLE_TIMESTAMP_DATETIME:
623
length= sprintf(buff, "%04d-%02d-%02d %02d:%02d:%02d",
631
length+= sprintf(buff+length, ".%06d", (int)tm->second_part);
634
case DRIZZLE_TIMESTAMP_DATE:
635
length= sprintf(buff, "%04d-%02d-%02d",
641
case DRIZZLE_TIMESTAMP_TIME:
642
day= (tm->year || tm->month) ? 0 : tm->day;
643
length= sprintf(buff, "%s%02ld:%02d:%02d", tm->neg ? "-" : "",
644
(long) day*24L+(long) tm->hour, (int) tm->minute,
647
length+= sprintf(buff+length, ".%06d", (int)tm->second_part);
650
case DRIZZLE_TIMESTAMP_NONE:
651
case DRIZZLE_TIMESTAMP_ERROR:
657
return netStoreData((unsigned char*) buff, length);
660
bool ClientOldLibdrizzle::checkConnection(void)
665
const Query_id& local_query_id= Query_id::get_query_id();
666
struct rand_struct rand;
673
if (drizzleclient_net_peer_addr(&net, ip, &port, NI_MAXHOST))
675
my_error(ER_BAD_HOST_ERROR, MYF(0), session->security_ctx.ip.c_str());
679
session->security_ctx.ip.assign(ip);
681
drizzleclient_net_keepalive(&net, true);
683
uint32_t server_capabilites;
685
/* buff[] needs to big enough to hold the server_version variable */
686
char buff[SERVER_VERSION_LENGTH + SCRAMBLE_LENGTH + 64];
688
server_capabilites= CLIENT_BASIC_FLAGS;
691
server_capabilites|= CLIENT_COMPRESS;
692
#endif /* HAVE_COMPRESS */
694
end= buff + strlen(VERSION);
695
if ((end - buff) >= SERVER_VERSION_LENGTH)
696
end= buff + (SERVER_VERSION_LENGTH - 1);
697
memcpy(buff, VERSION, end - buff);
701
int4store((unsigned char*) end, global_thread_id);
704
So as _checkConnection is the only entry point to authorization
705
procedure, scramble is set here. This gives us new scramble for
709
drizzleclient_randominit(&rand, rnd_tmp + (uint64_t) &session,
710
rnd_tmp + (uint64_t)local_query_id.value());
711
drizzleclient_create_random_string(scramble, SCRAMBLE_LENGTH, &rand);
713
Old clients does not understand long scrambles, but can ignore packet
714
tail: that's why first part of the scramble is placed here, and second
715
part at the end of packet.
717
end= strncpy(end, scramble, SCRAMBLE_LENGTH_323);
718
end+= SCRAMBLE_LENGTH_323;
720
*end++= 0; /* an empty byte for some reason */
722
int2store(end, server_capabilites);
723
/* write server characteristics: up to 16 bytes allowed */
724
end[2]=(char) default_charset_info->number;
725
int2store(end+3, session->server_status);
726
memset(end+5, 0, 13);
728
/* write scramble tail */
729
size_t scramble_len= SCRAMBLE_LENGTH - SCRAMBLE_LENGTH_323;
730
end= strncpy(end, scramble + SCRAMBLE_LENGTH_323, scramble_len);
733
*end++= 0; /* an empty byte for some reason */
735
/* At this point we write connection message and read reply */
736
if (drizzleclient_net_write_command(&net
737
, (unsigned char) PROTOCOL_VERSION
738
, (unsigned char*) ""
740
, (unsigned char*) buff
741
, (size_t) (end-buff))
742
|| (pkt_len= drizzleclient_net_read(&net)) == packet_error
743
|| pkt_len < MIN_HANDSHAKE_SIZE)
745
my_error(ER_HANDSHAKE_ERROR, MYF(0), session->security_ctx.ip.c_str());
749
if (session->packet.alloc(session->variables.net_buffer_length))
750
return false; /* The error is set by alloc(). */
752
client_capabilities= uint2korr(net.read_pos);
755
client_capabilities|= ((uint32_t) uint2korr(net.read_pos + 2)) << 16;
756
session->max_client_packet_length= uint4korr(net.read_pos + 4);
757
end= (char*) net.read_pos + 32;
760
Disable those bits which are not supported by the server.
761
This is a precautionary measure, if the client lies. See Bug#27944.
763
client_capabilities&= server_capabilites;
765
if (end >= (char*) net.read_pos + pkt_len + 2)
767
my_error(ER_HANDSHAKE_ERROR, MYF(0), session->security_ctx.ip.c_str());
771
net.return_status= &session->server_status;
774
char *passwd= strchr(user, '\0')+1;
775
uint32_t user_len= passwd - user - 1;
779
Old clients send null-terminated string as password; new clients send
780
the size (1 byte) + string (not null-terminated). Hence in case of empty
781
password both send '\0'.
783
This strlen() can't be easily deleted without changing client.
785
Cast *passwd to an unsigned char, so that it doesn't extend the sign for
786
*passwd > 127 and become 2**32-127+ after casting to uint.
788
uint32_t passwd_len= client_capabilities & CLIENT_SECURE_CONNECTION ?
789
(unsigned char)(*passwd++) : strlen(passwd);
790
l_db= client_capabilities & CLIENT_CONNECT_WITH_DB ? l_db + passwd_len + 1 : 0;
792
/* strlen() can't be easily deleted without changing client */
793
uint32_t db_len= l_db ? strlen(l_db) : 0;
795
if (passwd + passwd_len + db_len > (char *) net.read_pos + pkt_len)
797
my_error(ER_HANDSHAKE_ERROR, MYF(0), session->security_ctx.ip.c_str());
801
/* If username starts and ends in "'", chop them off */
802
if (user_len > 1 && user[0] == '\'' && user[user_len - 1] == '\'')
809
session->security_ctx.user.assign(user);
811
return session->checkUser(passwd, passwd_len, l_db);
814
static ListenOldLibdrizzle *listen_obj= NULL;
816
static int init(drizzled::plugin::Registry ®istry)
818
listen_obj= new ListenOldLibdrizzle;
819
registry.add(listen_obj);
823
static int deinit(drizzled::plugin::Registry ®istry)
825
registry.remove(listen_obj);
830
static DRIZZLE_SYSVAR_UINT(connect_timeout, connect_timeout,
831
PLUGIN_VAR_RQCMDARG, N_("Connect Timeout."),
832
NULL, NULL, 10, 1, 300, 0);
833
static DRIZZLE_SYSVAR_UINT(read_timeout, read_timeout, PLUGIN_VAR_RQCMDARG,
834
N_("Read Timeout."), NULL, NULL, 30, 1, 300, 0);
835
static DRIZZLE_SYSVAR_UINT(write_timeout, write_timeout, PLUGIN_VAR_RQCMDARG,
836
N_("Write Timeout."), NULL, NULL, 60, 1, 300, 0);
837
static DRIZZLE_SYSVAR_UINT(retry_count, retry_count, PLUGIN_VAR_RQCMDARG,
838
N_("Retry Count."), NULL, NULL, 10, 1, 100, 0);
840
static struct st_mysql_sys_var* system_variables[]= {
841
DRIZZLE_SYSVAR(connect_timeout),
842
DRIZZLE_SYSVAR(read_timeout),
843
DRIZZLE_SYSVAR(write_timeout),
844
DRIZZLE_SYSVAR(retry_count),
848
drizzle_declare_plugin(oldlibdrizzle)
853
"Old libdrizzle Client",
855
init, /* Plugin Init */
856
deinit, /* Plugin Deinit */
857
NULL, /* status variables */
858
system_variables, /* system variables */
859
NULL /* config options */
861
drizzle_declare_plugin_end;