Merge branch '2.2' into develop

This commit is contained in:
Markus Mäkelä
2018-08-28 16:06:23 +03:00
9 changed files with 137 additions and 64 deletions

View File

@ -20,6 +20,7 @@
#include <limits.h>
#include <netinet/tcp.h>
#include <sys/stat.h>
#include <algorithm>
#include <string>
#include <vector>
@ -1545,21 +1546,30 @@ static bool reauthenticate_client(MXS_SESSION* session, GWBUF* packetbuf)
if (session->client_dcb->authfunc.reauthenticate)
{
uint64_t payloadlen = gwbuf_length(packetbuf) - MYSQL_HEADER_LEN;
MySQLProtocol* proto = (MySQLProtocol*)session->client_dcb->protocol;
uint8_t payload[gwbuf_length(packetbuf) - MYSQL_HEADER_LEN];
gwbuf_copy_data(packetbuf, MYSQL_HEADER_LEN, sizeof(payload), payload);
std::vector<uint8_t> payload;
payload.resize(payloadlen);
gwbuf_copy_data(packetbuf, MYSQL_HEADER_LEN, payloadlen, &payload[0]);
// Will contains extra data but the username is null-terminated
char user[gwbuf_length(proto->stored_query) - MYSQL_HEADER_LEN - 1];
gwbuf_copy_data(proto->stored_query, MYSQL_HEADER_LEN + 1,
sizeof(user), (uint8_t*)user);
char user[MYSQL_USER_MAXLEN + 1];
gwbuf_copy_data(proto->stored_query, MYSQL_HEADER_LEN + 1, sizeof(user), (uint8_t*)user);
char* end = user + sizeof(user);
if (std::find(user, end, '\0') == end)
{
mysql_send_auth_error(session->client_dcb, 3, 0, "Malformed AuthSwitchRequest packet");
return false;
}
// Copy the new username to the session data
MYSQL_session* data = (MYSQL_session*)session->client_dcb->data;
strcpy(data->user, user);
int rc = session->client_dcb->authfunc.reauthenticate(session->client_dcb, data->user,
payload, sizeof(payload),
&payload[0], payload.size(),
proto->scramble, sizeof(proto->scramble),
data->client_sha1, sizeof(data->client_sha1));

View File

@ -343,17 +343,17 @@ void AvroSession::process_command(GWBUF *queue)
}
else
{
dcb_printf(dcb, "ERR NO-FILE File '%s' not found.", avro_binfile.c_str());
dcb_printf(dcb, "ERR NO-FILE File '%s' not found.\n", avro_binfile.c_str());
}
}
else
{
dcb_printf(dcb, "ERR REQUEST-DATA with no data");
dcb_printf(dcb, "ERR REQUEST-DATA with no data\n");
}
}
else
{
const char err[] = "ERR: Unknown command";
const char err[] = "ERR: Unknown command\n";
GWBUF *reply = gwbuf_alloc_and_load(sizeof(err), err);
dcb->func.write(dcb, reply);
}
@ -571,8 +571,7 @@ bool AvroSession::stream_data()
}
else
{
fprintf(stderr, "No file specified\n");
dcb_printf(dcb, "ERR avro file not specified");
dcb_printf(dcb, "ERR avro file not specified\n");
}
return read_more;

View File

@ -444,6 +444,29 @@ static bool pos_is_ok(Avro* router, const REP_HEADER& hdr, uint64_t pos)
return rval;
}
bool read_fde(Avro* router)
{
bool rval = false;
avro_binlog_end_t rc;
REP_HEADER hdr;
if (read_header(router, 4, &hdr, &rc))
{
if (GWBUF *result = read_event_data(router, &hdr, 4))
{
router->handler.handle_event(hdr, GWBUF_DATA(result));
rval = true;
}
}
else if (rc == AVRO_OK)
{
// Empty file
rval = true;
}
return rval;
}
/**
* @brief Read all replication events from a binlog file.
*
@ -457,12 +480,19 @@ static bool pos_is_ok(Avro* router, const REP_HEADER& hdr, uint64_t pos)
*/
avro_binlog_end_t avro_read_all_events(Avro *router)
{
mxb_assert(router->binlog_fd != -1);
if (!read_fde(router))
{
MXS_ERROR("Failed to read the FDE event from the binary log: %d, %s",
errno, mxs_strerror(errno));
return AVRO_BINLOG_ERROR;
}
uint64_t pos = router->current_pos;
std::string next_binlog;
bool rotate_seen = false;
mxb_assert(router->binlog_fd != -1);
while (!service_should_stop)
{
avro_binlog_end_t rc;