1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-07 02:42:49 +03:00

10.2 integration fixes

- changed plugin API to avoid crashes: Oracle/MariaDB changed
    structure several times without updating interface version.
  - ABI fixes: moved additional net items to net->extension (connection
    handler and com_multi buffer)
This commit is contained in:
Georg Richter
2016-02-22 10:43:11 +01:00
parent dc1a8715c2
commit d68b48f954
22 changed files with 168 additions and 84 deletions

View File

@@ -62,6 +62,19 @@ struct st_mysql_options_extension {
HASH userdata; HASH userdata;
}; };
typedef struct st_connection_handler
{
struct st_ma_connection_plugin *plugin;
void *data;
my_bool active;
my_bool free_data;
} MA_CONNECTION_HANDLER;
struct st_mariadb_net_extension {
unsigned char *mbuff, *mbuff_end, *mbuff_pos;
MA_CONNECTION_HANDLER *conn_hdlr;
};
#define OPT_HAS_EXT_VAL(a,key) \ #define OPT_HAS_EXT_VAL(a,key) \
((a)->options.extension && (a)->options.extension->key) ((a)->options.extension && (a)->options.extension->key)

View File

@@ -179,6 +179,8 @@ extern MARIADB_CHARSET_INFO *get_charset(uint cs_number, myf flags);
extern MARIADB_CHARSET_INFO *get_charset_by_name(const char *cs_name); extern MARIADB_CHARSET_INFO *get_charset_by_name(const char *cs_name);
extern MARIADB_CHARSET_INFO *get_charset_by_nr(uint cs_number); extern MARIADB_CHARSET_INFO *get_charset_by_nr(uint cs_number);
/* string functions */
char *ma_strmake(register char *dst, register const char *src, size_t length);
/* statistics */ /* statistics */
#ifdef TBR #ifdef TBR

View File

@@ -246,19 +246,11 @@ typedef struct st_ma_pvio MARIADB_PVIO;
struct st_ma_connection_plugin; struct st_ma_connection_plugin;
typedef struct st_connection_handler
{
struct st_ma_connection_plugin *plugin;
void *data;
my_bool active;
my_bool free_data;
} MA_CONNECTION_HANDLER;
typedef struct st_net { typedef struct st_net {
MARIADB_PVIO *pvio; MARIADB_PVIO *pvio;
unsigned char *buff; unsigned char *buff;
unsigned char *buff_end,*write_pos,*read_pos; unsigned char *buff_end,*write_pos,*read_pos;
unsigned char *mbuff, *mbuff_end, *mbuff_pos;
my_socket fd; /* For Perl DBI/dbd */ my_socket fd; /* For Perl DBI/dbd */
unsigned long remain_in_buf,length; unsigned long remain_in_buf,length;
unsigned long buf_length, where_b; unsigned long buf_length, where_b;
@@ -269,18 +261,18 @@ typedef struct st_net {
unsigned int *return_status; unsigned int *return_status;
unsigned char reading_or_writing; unsigned char reading_or_writing;
char save_char; char save_char;
my_bool unused_1, unused_2; char unused_1;
my_bool unused_2;
my_bool compress; my_bool compress;
my_bool unused_3; my_bool unused_3;
MA_CONNECTION_HANDLER *conn_hdlr; void *unused_4;
unsigned int last_errno; unsigned int last_errno;
unsigned char error; unsigned char error;
my_bool unused_4;
my_bool unused_5; my_bool unused_5;
my_bool unused_6;
char last_error[MYSQL_ERRMSG_SIZE]; char last_error[MYSQL_ERRMSG_SIZE];
char sqlstate[SQLSTATE_LENGTH+1]; char sqlstate[SQLSTATE_LENGTH+1];
void *extension; struct st_mariadb_net_extension *extension;
} NET; } NET;
#define packet_error ((unsigned int) -1) #define packet_error ((unsigned int) -1)

View File

@@ -424,8 +424,10 @@ typedef struct character_set
const char *desc; \ const char *desc; \
unsigned int version[3]; \ unsigned int version[3]; \
const char *license; \ const char *license; \
void *mariadb_api; \
int (*init)(char *, size_t, int, va_list); \ int (*init)(char *, size_t, int, va_list); \
int (*deinit)(); int (*deinit)(); \
int (*options)(const char *option, const void *);
struct st_mysql_client_plugin struct st_mysql_client_plugin
{ {
MYSQL_CLIENT_PLUGIN_HEADER MYSQL_CLIENT_PLUGIN_HEADER

View File

@@ -76,8 +76,10 @@
const char *desc; \ const char *desc; \
unsigned int version[3]; \ unsigned int version[3]; \
const char *license; \ const char *license; \
void *mysql_api; \
int (*init)(char *, size_t, int, va_list); \ int (*init)(char *, size_t, int, va_list); \
int (*deinit)(); int (*deinit)(); \
int (*options)(const char *option, const void *);
struct st_mysql_client_plugin struct st_mysql_client_plugin
{ {
MYSQL_CLIENT_PLUGIN_HEADER MYSQL_CLIENT_PLUGIN_HEADER
@@ -94,7 +96,7 @@ typedef struct st_ma_connection_plugin
MYSQL *(*connect)(MYSQL *mysql, const char *host, const char *user, const char *passwd, MYSQL *(*connect)(MYSQL *mysql, const char *host, const char *user, const char *passwd,
const char *db, unsigned int port, const char *unix_socket, unsigned long clientflag); const char *db, unsigned int port, const char *unix_socket, unsigned long clientflag);
void (*close)(MYSQL *mysql); void (*close)(MYSQL *mysql);
int (*options)(MYSQL *mysql, enum mysql_option, void *arg); int (*set_options)(MYSQL *mysql, enum mysql_option, void *arg);
int (*set_connection)(MYSQL *mysql,enum enum_server_command command, const char *arg, int (*set_connection)(MYSQL *mysql,enum enum_server_command command, const char *arg,
size_t length, my_bool skipp_check, void *opt_arg); size_t length, my_bool skipp_check, void *opt_arg);
my_bool (*reconnect)(MYSQL *mysql); my_bool (*reconnect)(MYSQL *mysql);

View File

@@ -258,12 +258,12 @@ ma_alloc.c
ma_compress.c ma_compress.c
ma_init.c ma_init.c
ma_password.c ma_password.c
ma_string.c
ma_ll2str.c ma_ll2str.c
ma_sha1.c ma_sha1.c
mariadb_stmt.c mariadb_stmt.c
ma_loaddata.c ma_loaddata.c
ma_stmt_codec.c ma_stmt_codec.c
ma_string.c
${CMAKE_BINARY_DIR}/libmariadb/ma_client_plugin.c ${CMAKE_BINARY_DIR}/libmariadb/ma_client_plugin.c
ma_io.c ma_io.c
${SSL_SOURCES} ${SSL_SOURCES}

View File

@@ -84,7 +84,7 @@ int mysql_local_infile_init(void **ptr, const char *filename, void *userdata)
if (mysql_errno(mysql) && !info->error_no) if (mysql_errno(mysql) && !info->error_no)
{ {
info->error_no= mysql_errno(mysql); info->error_no= mysql_errno(mysql);
strncpy(info->error_msg, mysql_error(mysql), MYSQL_ERRMSG_SIZE); ma_strmake(info->error_msg, mysql_error(mysql), MYSQL_ERRMSG_SIZE);
} }
else else
{ {
@@ -127,11 +127,11 @@ int mysql_local_infile_error(void *ptr, char *error_buf, unsigned int error_buf_
MYSQL_INFILE_INFO *info = (MYSQL_INFILE_INFO *)ptr; MYSQL_INFILE_INFO *info = (MYSQL_INFILE_INFO *)ptr;
if (info) { if (info) {
strncpy(error_buf, info->error_msg, error_buf_len); ma_strmake(error_buf, info->error_msg, error_buf_len);
return(info->error_no); return(info->error_no);
} }
strncpy(error_buf, "Unknown error", error_buf_len); ma_strmake(error_buf, "Unknown error", error_buf_len);
return(CR_UNKNOWN_ERROR); return(CR_UNKNOWN_ERROR);
} }
/* }}} */ /* }}} */

View File

@@ -34,6 +34,7 @@
#include <errno.h> #include <errno.h>
#include <sys/types.h> #include <sys/types.h>
#include <ma_pvio.h> #include <ma_pvio.h>
#include <ma_common.h>
#ifndef _WIN32 #ifndef _WIN32
#include <poll.h> #include <poll.h>
#endif #endif
@@ -103,6 +104,11 @@ int ma_net_init(NET *net, MARIADB_PVIO* pvio)
if (!(net->buff=(uchar*) calloc(1, net_buffer_length))) if (!(net->buff=(uchar*) calloc(1, net_buffer_length)))
return 1; return 1;
if (!net->extension)
{
printf("Fatal\n");
exit(-1);
}
/* We don't allocate memory for multi buffer, since we don't know in advance if the server /* We don't allocate memory for multi buffer, since we don't know in advance if the server
* supports COM_MULTI comand. It will be allocated on demand in net_add_multi_command */ * supports COM_MULTI comand. It will be allocated on demand in net_add_multi_command */
max_allowed_packet= net->max_packet_size= MAX(net_buffer_length, max_allowed_packet); max_allowed_packet= net->max_packet_size= MAX(net_buffer_length, max_allowed_packet);
@@ -130,9 +136,9 @@ int ma_net_init(NET *net, MARIADB_PVIO* pvio)
void ma_net_end(NET *net) void ma_net_end(NET *net)
{ {
free(net->buff); free(net->buff);
free(net->mbuff); free(net->extension->mbuff);
net->buff=0; net->buff=0;
net->mbuff= 0; net->extension->mbuff= 0;
} }
/* Realloc the packet buffer */ /* Realloc the packet buffer */
@@ -151,7 +157,7 @@ static my_bool net_realloc(NET *net, my_bool is_multi, size_t length)
pkt_length = (length+IO_SIZE-1) & ~(IO_SIZE-1); pkt_length = (length+IO_SIZE-1) & ~(IO_SIZE-1);
/* reallocate buffer: /* reallocate buffer:
size= pkt_length + NET_HEADER_SIZE + COMP_HEADER_SIZE */ size= pkt_length + NET_HEADER_SIZE + COMP_HEADER_SIZE */
if (!(buff=(uchar*) realloc(is_multi ? net->mbuff : net->buff, if (!(buff=(uchar*) realloc(is_multi ? net->extension->mbuff : net->buff,
pkt_length + NET_HEADER_SIZE + COMP_HEADER_SIZE))) pkt_length + NET_HEADER_SIZE + COMP_HEADER_SIZE)))
{ {
net->error=1; net->error=1;
@@ -164,8 +170,8 @@ static my_bool net_realloc(NET *net, my_bool is_multi, size_t length)
} }
else else
{ {
net->mbuff=net->mbuff_pos=buff; net->extension->mbuff=net->extension->mbuff_pos=buff;
net->mbuff_end=buff+(net->max_packet=(unsigned long)pkt_length); net->extension->mbuff_end=buff+(net->max_packet=(unsigned long)pkt_length);
} }
return(0); return(0);
} }
@@ -178,8 +184,8 @@ void ma_net_clear(NET *net)
ma_pvio_has_data(net->pvio, &len); */ ma_pvio_has_data(net->pvio, &len); */
net->compress_pkt_nr= net->pkt_nr=0; /* Ready for new command */ net->compress_pkt_nr= net->pkt_nr=0; /* Ready for new command */
net->write_pos=net->buff; net->write_pos=net->buff;
if (net->mbuff) if (net->extension->mbuff)
net->mbuff_pos= net->mbuff; net->extension->mbuff_pos= net->extension->mbuff;
return; return;
} }
@@ -326,42 +332,42 @@ int net_add_multi_command(NET *net, uchar command, const uchar *packet,
/* We didn't allocate memory in ma_net_init since it was to early to /* We didn't allocate memory in ma_net_init since it was to early to
* detect if the server supports COM_MULTI command */ * detect if the server supports COM_MULTI command */
if (!net->mbuff) if (!net->extension->mbuff)
{ {
size_t alloc_size= (required_length + IO_SIZE - 1) & ~(IO_SIZE - 1); size_t alloc_size= (required_length + IO_SIZE - 1) & ~(IO_SIZE - 1);
if (!(net->mbuff= (char *)malloc(alloc_size))) if (!(net->extension->mbuff= (char *)malloc(alloc_size)))
{ {
net->last_errno=ER_OUT_OF_RESOURCES; net->last_errno=ER_OUT_OF_RESOURCES;
net->error=2; net->error=2;
net->reading_or_writing=0; net->reading_or_writing=0;
return(1); return(1);
} }
net->mbuff_pos= net->mbuff; net->extension->mbuff_pos= net->extension->mbuff;
net->mbuff_end= net->mbuff + alloc_size; net->extension->mbuff_end= net->extension->mbuff + alloc_size;
} }
left_length= net->mbuff_end - net->mbuff_pos; left_length= net->extension->mbuff_end - net->extension->mbuff_pos;
/* check if our buffer is large enough */ /* check if our buffer is large enough */
if (left_length < required_length) if (left_length < required_length)
{ {
current_length= net->mbuff_pos - net->mbuff; current_length= net->extension->mbuff_pos - net->extension->mbuff;
if (net_realloc(net, 1, current_length + required_length)) if (net_realloc(net, 1, current_length + required_length))
goto error; goto error;
} }
int3store(net->mbuff_pos, length + 1); int3store(net->extension->mbuff_pos, length + 1);
net->mbuff_pos+= 3; net->extension->mbuff_pos+= 3;
*net->mbuff_pos= command; *net->extension->mbuff_pos= command;
net->mbuff_pos++; net->extension->mbuff_pos++;
memcpy(net->mbuff_pos, packet, length); memcpy(net->extension->mbuff_pos, packet, length);
net->mbuff_pos+= length; net->extension->mbuff_pos+= length;
return 0; return 0;
error: error:
if (net->mbuff) if (net->extension->mbuff)
{ {
free(net->mbuff); free(net->extension->mbuff);
net->mbuff= net->mbuff_pos= net->mbuff_end= 0; net->extension->mbuff= net->extension->mbuff_pos= net->extension->mbuff_end= 0;
} }
return 1; return 1;
} }

View File

@@ -124,4 +124,11 @@ void ma_dynstr_free(DYNAMIC_STRING *str)
} }
} }
char *ma_strmake(register char *dst, register const char *src, size_t length)
{
while (length--)
if (! (*dst++ = *src++))
return dst-1;
*dst=0;
return dst;
}

View File

@@ -136,7 +136,7 @@ struct st_mariadb_methods MARIADB_DEFAULT_METHODS;
#define native_password_plugin_name "mysql_native_password" #define native_password_plugin_name "mysql_native_password"
#define IS_CONNHDLR_ACTIVE(mysql)\ #define IS_CONNHDLR_ACTIVE(mysql)\
(((mysql)->net.conn_hdlr)) (((mysql)->net.extension->conn_hdlr))
static void end_server(MYSQL *mysql); static void end_server(MYSQL *mysql);
static void mysql_close_memory(MYSQL *mysql); static void mysql_close_memory(MYSQL *mysql);
@@ -226,14 +226,14 @@ restart:
net->last_errno= last_errno; net->last_errno= last_errno;
if (pos[0]== '#') if (pos[0]== '#')
{ {
strncpy(net->sqlstate, pos+1, SQLSTATE_LENGTH); ma_strmake(net->sqlstate, pos+1, SQLSTATE_LENGTH);
pos+= SQLSTATE_LENGTH + 1; pos+= SQLSTATE_LENGTH + 1;
} }
else else
{ {
strcpy(net->sqlstate, SQLSTATE_UNKNOWN); strcpy(net->sqlstate, SQLSTATE_UNKNOWN);
} }
strncpy(net->last_error,(char*) pos, ma_strmake(net->last_error,(char*) pos,
min(len,sizeof(net->last_error)-1)); min(len,sizeof(net->last_error)-1));
} }
else else
@@ -387,7 +387,7 @@ mthd_my_send_cmd(MYSQL *mysql,enum enum_server_command command, const char *arg,
if (IS_CONNHDLR_ACTIVE(mysql)) if (IS_CONNHDLR_ACTIVE(mysql))
{ {
result= mysql->net.conn_hdlr->plugin->set_connection(mysql, command, arg, length, skipp_check, opt_arg); result= mysql->net.extension->conn_hdlr->plugin->set_connection(mysql, command, arg, length, skipp_check, opt_arg);
if (result== -1) if (result== -1)
return(result); return(result);
} }
@@ -467,11 +467,11 @@ void read_user_name(char *name)
!(str=getenv("LOGIN"))) !(str=getenv("LOGIN")))
str="UNKNOWN_USER"; str="UNKNOWN_USER";
} }
strncpy(name,str,USERNAME_LENGTH); ma_strmake(name,str,USERNAME_LENGTH);
#elif HAVE_CUSERID #elif HAVE_CUSERID
(void) cuserid(name); (void) cuserid(name);
#else #else
strncpy(name,"UNKNOWN_USER", USERNAME_LENGTH); ma_strmake(name,"UNKNOWN_USER", USERNAME_LENGTH);
#endif #endif
} }
return; return;
@@ -482,7 +482,7 @@ void read_user_name(char *name)
void read_user_name(char *name) void read_user_name(char *name)
{ {
char *str=getenv("USERNAME"); /* ODBC will send user variable */ char *str=getenv("USERNAME"); /* ODBC will send user variable */
strncpy(name,str ? str : "ODBC", USERNAME_LENGTH); ma_strmake(name,str ? str : "ODBC", USERNAME_LENGTH);
} }
#endif #endif
@@ -582,6 +582,7 @@ struct st_default_options mariadb_defaults[] =
{MYSQL_OPT_SSL_CERT, MARIADB_OPTION_STR,"ssl-cert"}, {MYSQL_OPT_SSL_CERT, MARIADB_OPTION_STR,"ssl-cert"},
{MYSQL_OPT_SSL_CA, MARIADB_OPTION_STR,"ssl-ca"}, {MYSQL_OPT_SSL_CA, MARIADB_OPTION_STR,"ssl-ca"},
{MYSQL_OPT_SSL_CAPATH, MARIADB_OPTION_STR,"ssl-capath"}, {MYSQL_OPT_SSL_CAPATH, MARIADB_OPTION_STR,"ssl-capath"},
{MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MARIADB_OPTION_BOOL,"ssl-verify-server-cert"},
{MYSQL_SET_CHARSET_DIR, MARIADB_OPTION_STR, "character-sets-dir"}, {MYSQL_SET_CHARSET_DIR, MARIADB_OPTION_STR, "character-sets-dir"},
{MYSQL_SET_CHARSET_NAME, MARIADB_OPTION_STR, "default-character-set"}, {MYSQL_SET_CHARSET_NAME, MARIADB_OPTION_STR, "default-character-set"},
{MARIADB_OPT_INTERACTIVE, MARIADB_OPTION_NONE, "interactive-timeout"}, {MARIADB_OPT_INTERACTIVE, MARIADB_OPTION_NONE, "interactive-timeout"},
@@ -936,9 +937,38 @@ mysql_init(MYSQL *mysql)
return 0; return 0;
mysql->free_me=1; mysql->free_me=1;
mysql->net.pvio= 0; mysql->net.pvio= 0;
mysql->net.extension= 0;
} }
else else
{
memset((char*) (mysql), 0, sizeof(*(mysql))); memset((char*) (mysql), 0, sizeof(*(mysql)));
mysql->net.pvio= 0;
mysql->net.extension= 0;
}
if (!(mysql->net.extension= (struct st_mariadb_net_extension *)
calloc(1, sizeof(struct st_mariadb_net_extension))))
{
if (mysql->free_me)
free(mysql);
return 0;
}
mysql->options.report_data_truncation= 1;
mysql->options.connect_timeout=CONNECT_TIMEOUT;
mysql->charset= ma_default_charset_info;
mysql->methods= &MARIADB_DEFAULT_METHODS;
strcpy(mysql->net.sqlstate, "00000");
mysql->net.last_error[0]= mysql->net.last_errno= 0;
/*
}
if (!(mysql->net.extension= (struct st_mariadb_net_extension *)
calloc(1, sizeof(struct st_mariadb_net_extension))))
{
if (mysql->free_me)
free(mysql);
return 0;
}
mysql->options.report_data_truncation= 1; mysql->options.report_data_truncation= 1;
mysql->options.connect_timeout=CONNECT_TIMEOUT; mysql->options.connect_timeout=CONNECT_TIMEOUT;
mysql->charset= ma_default_charset_info; mysql->charset= ma_default_charset_info;
@@ -1081,16 +1111,16 @@ mysql_real_connect(MYSQL *mysql, const char *host, const char *user,
if (!connection_handler || !connection_handler[0]) if (!connection_handler || !connection_handler[0])
{ {
memset(plugin_name, 0, 64); memset(plugin_name, 0, 64);
strncpy(plugin_name, host, MIN(end - host, 63)); ma_strmake(plugin_name, host, MIN(end - host, 63));
end+= 3; end+= 3;
} }
else else
strncpy(plugin_name, connection_handler, MIN(63, strlen(connection_handler))); ma_strmake(plugin_name, connection_handler, MIN(63, strlen(connection_handler)));
if (!(plugin= (MARIADB_CONNECTION_PLUGIN *)mysql_client_find_plugin(mysql, plugin_name, MARIADB_CLIENT_CONNECTION_PLUGIN))) if (!(plugin= (MARIADB_CONNECTION_PLUGIN *)mysql_client_find_plugin(mysql, plugin_name, MARIADB_CLIENT_CONNECTION_PLUGIN)))
return NULL; return NULL;
if (!(mysql->net.conn_hdlr= (MA_CONNECTION_HANDLER *)calloc(1, sizeof(MA_CONNECTION_HANDLER)))) if (!(mysql->net.extension->conn_hdlr= (MA_CONNECTION_HANDLER *)calloc(1, sizeof(MA_CONNECTION_HANDLER))))
{ {
SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0);
return NULL; return NULL;
@@ -1099,15 +1129,15 @@ mysql_real_connect(MYSQL *mysql, const char *host, const char *user,
/* save URL for reconnect */ /* save URL for reconnect */
OPT_SET_EXTENDED_VALUE_STR(&mysql->options, url, host); OPT_SET_EXTENDED_VALUE_STR(&mysql->options, url, host);
mysql->net.conn_hdlr->plugin= plugin; mysql->net.extension->conn_hdlr->plugin= plugin;
if (plugin && plugin->connect) if (plugin && plugin->connect)
{ {
MYSQL *my= plugin->connect(mysql, end, user, passwd, db, port, unix_socket, client_flag); MYSQL *my= plugin->connect(mysql, end, user, passwd, db, port, unix_socket, client_flag);
if (!my) if (!my)
{ {
free(mysql->net.conn_hdlr); free(mysql->net.extension->conn_hdlr);
mysql->net.conn_hdlr= NULL; mysql->net.extension->conn_hdlr= NULL;
} }
return my; return my;
} }
@@ -1166,6 +1196,8 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user,
#ifndef DONT_USE_MYSQL_PWD #ifndef DONT_USE_MYSQL_PWD
if (!passwd) if (!passwd)
passwd=getenv("MYSQL_PWD"); /* get it from environment (haneke) */ passwd=getenv("MYSQL_PWD"); /* get it from environment (haneke) */
if (!passwd)
passwd= "";
#endif #endif
} }
if (!db || !db[0]) if (!db || !db[0])
@@ -1514,8 +1546,8 @@ my_bool STDCALL mysql_reconnect(MYSQL *mysql)
/* check if connection handler is active */ /* check if connection handler is active */
if (IS_CONNHDLR_ACTIVE(mysql)) if (IS_CONNHDLR_ACTIVE(mysql))
{ {
if (mysql->net.conn_hdlr->plugin && mysql->net.conn_hdlr->plugin->reconnect) if (mysql->net.extension->conn_hdlr->plugin && mysql->net.extension->conn_hdlr->plugin->reconnect)
return(mysql->net.conn_hdlr->plugin->reconnect(mysql)); return(mysql->net.extension->conn_hdlr->plugin->reconnect(mysql));
} }
if (!mysql->options.reconnect || if (!mysql->options.reconnect ||
@@ -1529,10 +1561,10 @@ my_bool STDCALL mysql_reconnect(MYSQL *mysql)
mysql_init(&tmp_mysql); mysql_init(&tmp_mysql);
tmp_mysql.options=mysql->options; tmp_mysql.options=mysql->options;
if (mysql->net.conn_hdlr) if (mysql->net.extension->conn_hdlr)
{ {
tmp_mysql.net.conn_hdlr= mysql->net.conn_hdlr; tmp_mysql.net.extension->conn_hdlr= mysql->net.extension->conn_hdlr;
mysql->net.conn_hdlr= 0; mysql->net.extension->conn_hdlr= 0;
} }
@@ -1803,7 +1835,7 @@ void my_set_error(MYSQL *mysql,
va_list ap; va_list ap;
mysql->net.last_errno= error_nr; mysql->net.last_errno= error_nr;
strncpy(mysql->net.sqlstate, sqlstate, SQLSTATE_LENGTH); ma_strmake(mysql->net.sqlstate, sqlstate, SQLSTATE_LENGTH);
va_start(ap, format); va_start(ap, format);
vsnprintf(mysql->net.last_error, MYSQL_ERRMSG_SIZE, vsnprintf(mysql->net.last_error, MYSQL_ERRMSG_SIZE,
format ? format : ER(error_nr), ap); format ? format : ER(error_nr), ap);
@@ -1829,9 +1861,9 @@ mysql_close(MYSQL *mysql)
{ {
if (mysql) /* Some simple safety */ if (mysql) /* Some simple safety */
{ {
if (mysql->net.conn_hdlr) if (mysql->net.extension->conn_hdlr)
{ {
MA_CONNECTION_HANDLER *p= mysql->net.conn_hdlr; MA_CONNECTION_HANDLER *p= mysql->net.extension->conn_hdlr;
p->plugin->close(mysql); p->plugin->close(mysql);
free(p); free(p);
} }
@@ -1851,6 +1883,8 @@ mysql_close(MYSQL *mysql)
if (mysql->extension) if (mysql->extension)
free(mysql->extension); free(mysql->extension);
if (mysql->net.extension)
free(mysql->net.extension);
mysql->net.pvio= 0; mysql->net.pvio= 0;
if (mysql->free_me) if (mysql->free_me)
@@ -2405,16 +2439,16 @@ void ma_hash_free(void *p)
int mariadb_flush_multi_command(MYSQL *mysql) int mariadb_flush_multi_command(MYSQL *mysql)
{ {
int rc; int rc;
size_t length= mysql->net.mbuff_pos - mysql->net.mbuff; size_t length= mysql->net.extension->mbuff_pos - mysql->net.extension->mbuff;
rc= ma_simple_command(mysql, COM_MULTI, mysql->net.mbuff, rc= ma_simple_command(mysql, COM_MULTI, mysql->net.extension->mbuff,
length, 1, 0); length, 1, 0);
/* reset multi_buff */ /* reset multi_buff */
mysql->net.mbuff_pos= mysql->net.mbuff; mysql->net.extension->mbuff_pos= mysql->net.extension->mbuff;
if (!rc) if (!rc)
if (mysql->net.mbuff && length > 3 && if (mysql->net.extension->mbuff && length > 3 &&
(mysql->net.mbuff[3] == COM_STMT_PREPARE || mysql->net.mbuff[3] == COM_STMT_EXECUTE)) (mysql->net.extension->mbuff[3] == COM_STMT_PREPARE || mysql->net.extension->mbuff[3] == COM_STMT_EXECUTE))
return rc; return rc;
else else
return mysql->methods->db_read_query_result(mysql); return mysql->methods->db_read_query_result(mysql);
@@ -2774,7 +2808,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...)
mysql->options.extension->multi_command != MARIADB_COM_MULTI_BEGIN) mysql->options.extension->multi_command != MARIADB_COM_MULTI_BEGIN)
return(-1); return(-1);
/* reset multi_buff */ /* reset multi_buff */
mysql->net.mbuff_pos= mysql->net.mbuff; mysql->net.extension->mbuff_pos= mysql->net.extension->mbuff;
OPT_SET_EXTENDED_VALUE_INT(&mysql->options, multi_command, MARIADB_COM_MULTI_END); OPT_SET_EXTENDED_VALUE_INT(&mysql->options, multi_command, MARIADB_COM_MULTI_END);
break; break;
case MARIADB_COM_MULTI_END: case MARIADB_COM_MULTI_END:

View File

@@ -115,5 +115,7 @@ struct st_mysql_client_plugin_AUTHENTICATION _mysql_client_plugin_declaration_ =
"BSD", "BSD",
NULL, NULL,
NULL, NULL,
NULL,
NULL,
gssapi_auth_client gssapi_auth_client
}; };

View File

@@ -54,8 +54,10 @@ struct st_mysql_client_plugin_AUTHENTICATION _mysql_client_plugin_declaration_ =
"Dialog Client Authentication Plugin", "Dialog Client Authentication Plugin",
{0,1,0}, {0,1,0},
"LGPL", "LGPL",
NULL,
auth_dialog_init, auth_dialog_init,
NULL, NULL,
NULL,
auth_dialog_open auth_dialog_open
}; };

View File

@@ -68,6 +68,8 @@ struct st_mysql_client_plugin_AUTHENTICATION _mysql_client_plugin_declaration_ =
"LGPL", "LGPL",
NULL, NULL,
NULL, NULL,
NULL,
NULL,
clear_password_auth_client clear_password_auth_client
}; };

View File

@@ -45,6 +45,8 @@ auth_plugin_t native_password_client_plugin=
"LGPL", "LGPL",
NULL, NULL,
NULL, NULL,
NULL,
NULL,
native_password_auth_client native_password_auth_client
}; };
@@ -104,7 +106,7 @@ static int send_change_user_packet(MCPVIO_EXT *mpvio,
buff= malloc(USERNAME_LENGTH+1 + data_len+1 + NAME_LEN+1 + 2 + NAME_LEN+1 + 9 + conn_attr_len); buff= malloc(USERNAME_LENGTH+1 + data_len+1 + NAME_LEN+1 + 2 + NAME_LEN+1 + 9 + conn_attr_len);
end= strncpy(buff, mysql->user, USERNAME_LENGTH) + strlen(buff) + 1; end= ma_strmake(buff, mysql->user, USERNAME_LENGTH) + 1;
if (!data_len) if (!data_len)
*end++= 0; *end++= 0;
@@ -162,6 +164,7 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio,
/* see end= buff+32 below, fixed size of the packet is 32 bytes */ /* see end= buff+32 below, fixed size of the packet is 32 bytes */
buff= malloc(33 + USERNAME_LENGTH + data_len + NAME_LEN + NAME_LEN + conn_attr_len + 9); buff= malloc(33 + USERNAME_LENGTH + data_len + NAME_LEN + NAME_LEN + conn_attr_len + 9);
end= buff;
mysql->client_flag|= mysql->options.client_flag; mysql->client_flag|= mysql->options.client_flag;
mysql->client_flag|= CLIENT_CAPABILITIES; mysql->client_flag|= CLIENT_CAPABILITIES;
@@ -172,7 +175,8 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio,
#if defined(HAVE_SSL) && !defined(EMBEDDED_LIBRARY) #if defined(HAVE_SSL) && !defined(EMBEDDED_LIBRARY)
if (mysql->options.ssl_key || mysql->options.ssl_cert || if (mysql->options.ssl_key || mysql->options.ssl_cert ||
mysql->options.ssl_ca || mysql->options.ssl_capath || mysql->options.ssl_ca || mysql->options.ssl_capath ||
mysql->options.ssl_cipher) mysql->options.ssl_cipher ||
(mysql->options.client_flag & CLIENT_SSL_VERIFY_SERVER_CERT))
mysql->options.use_ssl= 1; mysql->options.use_ssl= 1;
if (mysql->options.use_ssl) if (mysql->options.use_ssl)
mysql->client_flag|= CLIENT_SSL; mysql->client_flag|= CLIENT_SSL;
@@ -190,7 +194,7 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio,
{ {
my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN,
ER(CR_SSL_CONNECTION_ERROR), ER(CR_SSL_CONNECTION_ERROR),
"Server doesn't support SSL"); "SSL is required, but the server does not support it");
goto error; goto error;
} }
} }
@@ -259,13 +263,13 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio,
#endif /* HAVE_SSL */ #endif /* HAVE_SSL */
/* This needs to be changed as it's not useful with big packets */ /* This needs to be changed as it's not useful with big packets */
if (mysql->user[0]) if (mysql->user && mysql->user[0])
strncpy(end, mysql->user, USERNAME_LENGTH); ma_strmake(end, mysql->user, USERNAME_LENGTH);
else else
read_user_name(end); read_user_name(end);
/* We have to handle different version of handshake here */ /* We have to handle different version of handshake here */
end= strchr(end, '\0') + 1; end+= strlen(end) + 1;
if (data_len) if (data_len)
{ {
if (mysql->server_capabilities & CLIENT_SECURE_CONNECTION) if (mysql->server_capabilities & CLIENT_SECURE_CONNECTION)
@@ -287,12 +291,12 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio,
/* Add database if needed */ /* Add database if needed */
if (mpvio->db && (mysql->server_capabilities & CLIENT_CONNECT_WITH_DB)) if (mpvio->db && (mysql->server_capabilities & CLIENT_CONNECT_WITH_DB))
{ {
end= strncpy(end, mpvio->db, NAME_LEN) + strlen(end) + 1; end= ma_strmake(end, mpvio->db, NAME_LEN) + 1;
mysql->db= strdup(mpvio->db); mysql->db= strdup(mpvio->db);
} }
if (mysql->server_capabilities & CLIENT_PLUGIN_AUTH) if (mysql->server_capabilities & CLIENT_PLUGIN_AUTH)
end= strncpy(end, mpvio->plugin->name, NAME_LEN) + strlen(end) + 1; end= ma_strmake(end, mpvio->plugin->name, NAME_LEN) + 1;
end= ma_send_connect_attr(mysql, end); end= ma_send_connect_attr(mysql, end);
@@ -547,8 +551,9 @@ int run_plugin_auth(MYSQL *mysql, char *data, uint data_len,
if (res > CR_ERROR) if (res > CR_ERROR)
my_set_error(mysql, res, SQLSTATE_UNKNOWN, 0); my_set_error(mysql, res, SQLSTATE_UNKNOWN, 0);
else else
if (!mysql->net.last_errno) if (!mysql->net.last_errno) {
my_set_error(mysql, CR_UNKNOWN_ERROR, SQLSTATE_UNKNOWN, 0); my_set_error(mysql, CR_UNKNOWN_ERROR, SQLSTATE_UNKNOWN, 0);
}
return 1; return 1;
} }
@@ -587,7 +592,6 @@ int run_plugin_auth(MYSQL *mysql, char *data, uint data_len,
mpvio.cached_server_reply.pkt_len= pkt_length - len - 2; mpvio.cached_server_reply.pkt_len= pkt_length - len - 2;
mpvio.cached_server_reply.pkt= mysql->net.read_pos + len + 2; mpvio.cached_server_reply.pkt= mysql->net.read_pos + len + 2;
} }
if (!(auth_plugin= (auth_plugin_t *) mysql_client_find_plugin(mysql, if (!(auth_plugin= (auth_plugin_t *) mysql_client_find_plugin(mysql,
auth_plugin_name, MYSQL_CLIENT_AUTHENTICATION_PLUGIN))) auth_plugin_name, MYSQL_CLIENT_AUTHENTICATION_PLUGIN)))
return 1; return 1;

View File

@@ -54,13 +54,15 @@ struct st_mysql_client_plugin_AUTHENTICATION _mysql_client_plugin_declaration_ =
{ {
MYSQL_CLIENT_AUTHENTICATION_PLUGIN, MYSQL_CLIENT_AUTHENTICATION_PLUGIN,
MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION, MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION,
"old_password", "mysql_old_password",
"Sergei Golubchik, R.J. Silk, Georg Richter", "Sergei Golubchik, R.J. Silk, Georg Richter",
"Old (pre 4.1) authentication plugin", "Old (pre 4.1) authentication plugin",
{1,0,0}, {1,0,0},
"LGPL", "LGPL",
NULL, NULL,
NULL, NULL,
NULL,
NULL,
auth_old_password auth_old_password
}; };
@@ -94,11 +96,11 @@ static int auth_old_password(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql)
return CR_SERVER_HANDSHAKE_ERR; return CR_SERVER_HANDSHAKE_ERR;
/* save it in MYSQL */ /* save it in MYSQL */
memcpy(mysql->scramble_buff, pkt, pkt_len); memmove(mysql->scramble_buff, pkt, pkt_len);
mysql->scramble_buff[pkt_len] = 0; mysql->scramble_buff[pkt_len] = 0;
} }
if (mysql->passwd[0]) if (mysql && mysql->passwd[0])
{ {
char scrambled[SCRAMBLE_LENGTH_323 + 1]; char scrambled[SCRAMBLE_LENGTH_323 + 1];
ma_scramble_323(scrambled, (char*)pkt, mysql->passwd); ma_scramble_323(scrambled, (char*)pkt, mysql->passwd);

View File

@@ -67,8 +67,10 @@ MARIADB_CONNECTION_PLUGIN _mysql_client_plugin_declaration_ =
"MariaDB connection plugin for Aurora failover", "MariaDB connection plugin for Aurora failover",
{1, 0, 0}, {1, 0, 0},
"LGPL", "LGPL",
NULL,
aurora_init, aurora_init,
NULL, NULL,
NULL,
aurora_connect, aurora_connect,
aurora_close, aurora_close,
NULL, NULL,

View File

@@ -62,6 +62,8 @@ MARIADB_CONNECTION_PLUGIN _mysql_client_plugin_declaration_ =
"LGPL", "LGPL",
NULL, NULL,
NULL, NULL,
NULL,
NULL,
repl_connect, repl_connect,
repl_close, repl_close,
repl_set_options, repl_set_options,

View File

@@ -104,8 +104,10 @@ MARIADB_REMOTEIO_PLUGIN _mysql_client_plugin_declaration_ =
"Remote IO plugin", "Remote IO plugin",
{0,1,0}, {0,1,0},
"LGPL", "LGPL",
NULL,
ma_rio_init, ma_rio_init,
ma_rio_deinit, ma_rio_deinit,
NULL,
&ma_rio_methods &ma_rio_methods
mysql_end_client_plugin; mysql_end_client_plugin;

View File

@@ -78,6 +78,8 @@ MARIADB_PVIO_PLUGIN _mysql_client_plugin_declaration_ =
"LGPL", "LGPL",
NULL, NULL,
NULL, NULL,
NULL,
NULL,
&pvio_npipe_methods &pvio_npipe_methods
}; };

View File

@@ -75,6 +75,8 @@ MARIADB_PVIO_PLUGIN _mysql_client_plugin_declaration_=
"LGPPL", "LGPPL",
NULL, NULL,
NULL, NULL,
NULL,
NULL,
&pvio_shm_methods, &pvio_shm_methods,
}; };

View File

@@ -127,8 +127,10 @@ MARIADB_PVIO_PLUGIN _mysql_client_plugin_declaration_
"MariaDB virtual IO plugin for socket communication", "MariaDB virtual IO plugin for socket communication",
{1, 0, 0}, {1, 0, 0},
"LGPL", "LGPL",
NULL,
&pvio_socket_init, &pvio_socket_init,
&pvio_socket_end, &pvio_socket_end,
NULL,
&pvio_socket_methods &pvio_socket_methods
}; };

View File

@@ -57,8 +57,10 @@ struct st_mysql_client_plugin _mysql_client_plugin_declaration_ =
"Trace example plugin", "Trace example plugin",
{1,0,0}, {1,0,0},
"LGPL", "LGPL",
NULL,
&trace_init, &trace_init,
&trace_deinit &trace_deinit,
NULL
}; };
static char *commands[]= { static char *commands[]= {