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

Added missing error messages for wrong protocol

moved connection handler into net->extension (ABI break)
This commit is contained in:
Georg Richter
2016-02-23 13:50:14 +01:00
parent 38b78704e0
commit 8620b754ea
10 changed files with 74 additions and 48 deletions

View File

@@ -72,6 +72,7 @@ extern const char *mariadb_client_errors[]; /* Error messages */
#define CR_SHARED_MEMORY_CONNECTION 2037
#define CR_SHARED_MEMORY_CONNECT_ERROR 2038
#define CR_CONN_UNKNOWN_PROTOCOL 2047
#define CR_SECURE_AUTH 2049
#define CR_NO_DATA 2051
#define CR_NO_STMT_METADATA 2052
@@ -79,9 +80,10 @@ extern const char *mariadb_client_errors[]; /* Error messages */
#define CR_SERVER_LOST_EXTENDED 2055
#define CR_STMT_CLOSED 2056
#define CR_NEW_STMT_METADATA 2057
#define CR_AUTH_PLUGIN_CANNOT_LOAD 2058
#define CR_ALREADY_CONNECTED 2059
#define CR_PLUGIN_FUNCTION_NOT_SUPPORTED 2060
#define CR_ALREADY_CONNECTED 2058
#define CR_AUTH_PLUGIN_CANNOT_LOAD 2059
#define CR_DUPLICATE_CONNECTION_ATTR 2060
#define CR_AUTH_PLUGIN_ERR 2061
/*
* MariaDB Connector/C errors:

View File

@@ -32,7 +32,7 @@
#define NAME_CHAR_LEN 64
#define NAME_LEN 256 /* Field/table name length */
#define HOSTNAME_LENGTH 60
#define SYSTEM_MB_MAX_CHAR_LENGTH 3
#define SYSTEM_MB_MAX_CHAR_LENGTH 4
#define USERNAME_CHAR_LENGTH 128
#define USERNAME_LENGTH USERNAME_CHAR_LENGTH * SYSTEM_MB_MAX_CHAR_LENGTH
#define SERVER_VERSION_LENGTH 60

View File

@@ -25,7 +25,7 @@
#define MYSQL_PLUGIN_AUTH_COMMON_INCLUDED
/** the max allowed length for a user name */
#define MYSQL_USERNAME_LENGTH 48
#define MYSQL_USERNAME_LENGTH 512
/**
return values of the plugin authenticate_user() method.

View File

@@ -25,7 +25,7 @@
#define MYSQL_PLUGIN_AUTH_COMMON_INCLUDED
/** the max allowed length for a user name */
#define MYSQL_USERNAME_LENGTH 48
#define MYSQL_USERNAME_LENGTH 512
/**
return values of the plugin authenticate_user() method.

View File

@@ -127,7 +127,7 @@ const char *client_errors[]=
/* 2044 */ "",
/* 2045 */ "",
/* 2046 */ "",
/* 2047 */ "",
/* 2047 */ "Wrong or unknown protocol",
/* 2048 */ "",
/* 2049 */ "Connection with old authentication protocol refused.",
/* 2050 */ "",
@@ -138,8 +138,9 @@ const char *client_errors[]=
/* 2055 */ "Lost connection to MySQL server at '%s', system error: %d",
/* 2056 */ "Server closed statement due to a prior %s function call",
/* 2057 */ "The number of parameters in bound buffers differs from number of columns in resultset",
/* 2058 */ "Plugin %s could not be loaded: %s",
/* 2059 */ "Can't connect twice. Already connected",
/* 2058 */ "Plugin %s could not be loaded: %s",
/* 2059 */ "An attribute with same name already exists"
/* 2060 */ "Plugin doesn't support this function",
""
};

View File

@@ -115,6 +115,14 @@ my_context_install_suspend_resume_hook(struct mysql_async_context *b,
uint mysql_port=0;
my_string mysql_unix_port=0;
static char *mariadb_protocols[]= {"TCP",
#ifndef WIN32
"SOCKET",
#else
"PIPE", "MEMORY",
#endif
0};
#ifdef _WIN32
#define CONNECT_TIMEOUT 20
#else
@@ -441,6 +449,7 @@ static void free_old_query(MYSQL *mysql)
ma_init_ma_alloc_root(&mysql->field_alloc,8192,0); /* Assume rowlength < 8192 */
mysql->fields=0;
mysql->field_count=0; /* For API */
mysql->info= 0;
return;
}
@@ -1185,6 +1194,14 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user,
mysql->options.my_cnf_file=mysql->options.my_cnf_group=0;
}
#ifndef WIN32
if (mysql->options.protocol > MYSQL_PROTOCOL_SOCKET)
{
SET_CLIENT_ERROR(mysql, CR_CONN_UNKNOWN_PROTOCOL, SQLSTATE_UNKNOWN, 0);
return(NULL);
}
#endif
/* Some empty-string-tests are done because of ODBC */
if (!host || !host[0])
host=mysql->options.host;
@@ -1207,10 +1224,8 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user,
if (!unix_socket)
unix_socket=mysql->options.unix_socket;
mysql->server_status=SERVER_STATUS_AUTOCOMMIT;
/* try to connect via pvio_init */
cinfo.host= host;
cinfo.unix_socket= unix_socket;
@@ -1622,6 +1637,7 @@ my_bool STDCALL mysql_reconnect(MYSQL *mysql)
mysql->net.pvio->mysql= mysql;
ma_net_clear(&mysql->net);
mysql->affected_rows= ~(my_ulonglong) 0;
mysql->info= 0;
return(0);
}
@@ -2502,10 +2518,10 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...)
OPT_SET_VALUE_STR(&mysql->options, charset_name, (char *)arg1);
break;
case MYSQL_OPT_RECONNECT:
mysql->options.reconnect= *(uint *)arg1;
mysql->options.reconnect= *(my_bool *)arg1;
break;
case MYSQL_OPT_PROTOCOL:
mysql->options.protocol= *(uint *)arg1;
mysql->options.protocol= *((uint *)arg1);
break;
case MYSQL_OPT_READ_TIMEOUT:
mysql->options.read_timeout= *(uint *)arg1;
@@ -2579,6 +2595,9 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...)
case MYSQL_OPT_NET_BUFFER_LENGTH:
net_buffer_length= (*(size_t *)arg1);
break;
case MYSQL_OPT_SSL_ENFORCE:
mysql->options.use_ssl= (*(my_bool *)arg1);
break;
case MYSQL_OPT_SSL_VERIFY_SERVER_CERT:
if (*(my_bool *)arg1)
mysql->options.client_flag |= CLIENT_SSL_VERIFY_SERVER_CERT;
@@ -2922,6 +2941,9 @@ mysql_get_optionv(MYSQL *mysql, enum mysql_option option, void *arg, ...)
else
return(-1);
break;
case MYSQL_OPT_SSL_ENFORCE:
*((my_bool *)arg)= mysql->options.use_ssl;
break;
case MYSQL_OPT_SSL_VERIFY_SERVER_CERT:
*((my_bool *)arg)= test(mysql->options.client_flag & CLIENT_SSL_VERIFY_SERVER_CERT);
break;

View File

@@ -64,7 +64,6 @@ static void ma_ssl_set_error(MYSQL *mysql)
}
if ((ssl_error_reason= ERR_reason_error_string(ssl_errno)))
{
printf("reason: %s\n", ssl_error_reason);
pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN,
0, ssl_error_reason);
return;
@@ -424,19 +423,20 @@ my_bool ma_ssl_connect(MARIADB_SSL *cssl)
pvio->methods->blocking(pvio, FALSE, 0);
return 1;
}
rc= SSL_get_verify_result(ssl);
if (rc != X509_V_OK)
if ((mysql->client_flag & CLIENT_SSL_VERIFY_SERVER_CERT))
{
printf("--------------------\n");
my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN,
ER(CR_SSL_CONNECTION_ERROR), X509_verify_cert_error_string(rc));
/* restore blocking mode */
if (!blocking)
pvio->methods->blocking(pvio, FALSE, 0);
rc= SSL_get_verify_result(ssl);
if (rc != X509_V_OK)
{
my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN,
ER(CR_SSL_CONNECTION_ERROR), X509_verify_cert_error_string(rc));
/* restore blocking mode */
if (!blocking)
pvio->methods->blocking(pvio, FALSE, 0);
return 1;
return 1;
}
}
pvio->cssl->ssl= cssl->ssl= (void *)ssl;
return 0;

View File

@@ -175,7 +175,7 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio,
#if defined(HAVE_SSL) && !defined(EMBEDDED_LIBRARY)
if (mysql->options.ssl_key || mysql->options.ssl_cert ||
mysql->options.ssl_ca || mysql->options.ssl_capath ||
mysql->options.ssl_cipher ||
mysql->options.ssl_cipher || mysql->options.use_ssl ||
(mysql->options.client_flag & CLIENT_SSL_VERIFY_SERVER_CERT))
mysql->options.use_ssl= 1;
if (mysql->options.use_ssl)

View File

@@ -245,21 +245,21 @@ my_bool aurora_parse_url(const char *url, AURORA *aurora)
int aurora_get_instance_type(MYSQL *mysql)
{
int rc= -1;
MA_CONNECTION_HANDLER *save_hdlr= mysql->net.conn_hdlr;
MA_CONNECTION_HANDLER *save_hdlr= mysql->net.extension->conn_hdlr;
char *query= "select variable_value from information_schema.global_variables where variable_name='INNODB_READ_ONLY' AND variable_value='OFF'";
if (!mysql)
return -1;
mysql->net.conn_hdlr= 0;
mysql->net.extension->conn_hdlr= 0;
if (!mariadb_api->mysql_query(mysql, query))
{
MYSQL_RES *res= mariadb_api->mysql_store_result(mysql);
rc= mysql_num_rows(res) ? AURORA_PRIMARY : AURORA_REPLICA;
mariadb_api->mysql_free_result(res);
}
mysql->net.conn_hdlr= save_hdlr;
mysql->net.extension->conn_hdlr= save_hdlr;
return rc;
}
/* }}} */
@@ -280,9 +280,9 @@ int aurora_get_instance_type(MYSQL *mysql)
my_bool aurora_get_primary_id(MYSQL *mysql, AURORA *aurora)
{
my_bool rc= 0;
MA_CONNECTION_HANDLER *save_hdlr= mysql->net.conn_hdlr;
MA_CONNECTION_HANDLER *save_hdlr= mysql->net.extension->conn_hdlr;
mysql->net.conn_hdlr= 0;
mysql->net.extension->conn_hdlr= 0;
if (!mariadb_api->mysql_query(mysql, "select server_id from information_schema.replica_host_status "
"where session_id = 'MASTER_SESSION_ID'"))
{
@@ -302,7 +302,7 @@ my_bool aurora_get_primary_id(MYSQL *mysql, AURORA *aurora)
mariadb_api->mysql_free_result(res);
}
}
mysql->net.conn_hdlr= save_hdlr;
mysql->net.extension->conn_hdlr= save_hdlr;
return rc;
}
/* }}} */
@@ -393,7 +393,7 @@ void aurora_close_internal(MYSQL *mysql)
{
if (mysql)
{
mysql->net.conn_hdlr= 0;
mysql->net.extension->conn_hdlr= 0;
memset(&mysql->options, 0, sizeof(struct st_mysql_options));
mariadb_api->mysql_close(mysql);
}
@@ -421,7 +421,7 @@ my_bool aurora_find_replica(AURORA *aurora)
mysql->options= aurora->save_mysql.options;
/* don't execute init_command on slave */
// mysql->net.conn_hdlr= aurora->save_mysql.net.conn_hdlr;
// mysql->net.extension->conn_hdlr= aurora->save_mysql.net.extension->conn_hdlr;
if ((aurora_connect_instance(aurora, instance[random_pick], mysql)))
{
switch (instance[random_pick]->type) {
@@ -522,7 +522,7 @@ MYSQL *aurora_connect(MYSQL *mysql, const char *host, const char *user, const ch
const char *db, unsigned int port, const char *unix_socket, unsigned long client_flag)
{
AURORA *aurora= NULL;
MA_CONNECTION_HANDLER *save_hdlr= mysql->net.conn_hdlr;
MA_CONNECTION_HANDLER *save_hdlr= mysql->net.extension->conn_hdlr;
if (!mariadb_api)
mariadb_api= mysql->methods->api;
@@ -564,7 +564,7 @@ MYSQL *aurora_connect(MYSQL *mysql, const char *host, const char *user, const ch
if (!aurora_find_replica(aurora))
aurora->mysql[AURORA_REPLICA]= NULL;
else
aurora->mysql[AURORA_REPLICA]->net.conn_hdlr= save_hdlr;
aurora->mysql[AURORA_REPLICA]->net.extension->conn_hdlr= save_hdlr;
}
if (!aurora->mysql[AURORA_PRIMARY])
@@ -572,7 +572,7 @@ MYSQL *aurora_connect(MYSQL *mysql, const char *host, const char *user, const ch
if (!aurora_find_primary(aurora))
aurora->mysql[AURORA_PRIMARY]= NULL;
else
aurora->mysql[AURORA_PRIMARY]->net.conn_hdlr= save_hdlr;
aurora->mysql[AURORA_PRIMARY]->net.extension->conn_hdlr= save_hdlr;
}
if (!aurora->mysql[AURORA_PRIMARY] && !aurora->mysql[AURORA_REPLICA])
@@ -582,7 +582,7 @@ MYSQL *aurora_connect(MYSQL *mysql, const char *host, const char *user, const ch
aurora_switch_connection(mysql, aurora, AURORA_PRIMARY);
else
aurora_switch_connection(mysql, aurora, AURORA_REPLICA);
mysql->net.conn_hdlr= save_hdlr;
mysql->net.extension->conn_hdlr= save_hdlr;
return mysql;
error:
aurora_close_memory(aurora);
@@ -594,7 +594,7 @@ error:
my_bool aurora_reconnect(MYSQL *mysql)
{
AURORA *aurora;
MA_CONNECTION_HANDLER *save_hdlr= mysql->net.conn_hdlr;
MA_CONNECTION_HANDLER *save_hdlr= mysql->net.extension->conn_hdlr;
int i;
/* We can't determine if a new primary was promotoed, or if
@@ -647,7 +647,7 @@ my_bool aurora_reconnect(MYSQL *mysql)
/* {{{ void aurora_close */
void aurora_close(MYSQL *mysql)
{
MA_CONNECTION_HANDLER *hdlr= mysql->net.conn_hdlr;
MA_CONNECTION_HANDLER *hdlr= mysql->net.extension->conn_hdlr;
AURORA *aurora;
int i;
@@ -675,7 +675,7 @@ void aurora_close(MYSQL *mysql)
/* free information */
end:
aurora_close_memory(aurora);
mysql->net.conn_hdlr= hdlr;
mysql->net.extension->conn_hdlr= hdlr;
}
/* }}} */
@@ -718,7 +718,7 @@ my_bool is_replica_stmt(MYSQL *mysql, const char *buffer)
int aurora_command(MYSQL *mysql,enum enum_server_command command, const char *arg,
size_t length, my_bool skipp_check, void *opt_arg)
{
MA_CONNECTION_HANDLER *save_hdlr= mysql->net.conn_hdlr;
MA_CONNECTION_HANDLER *save_hdlr= mysql->net.extension->conn_hdlr;
AURORA *aurora= (AURORA *)save_hdlr->data;
/* if we don't have slave or slave became unavailable root traffic to master */
@@ -736,9 +736,9 @@ int aurora_command(MYSQL *mysql,enum enum_server_command command, const char *ar
/* we need to change default database on primary and replica */
if (aurora->mysql[AURORA_REPLICA] && mysql->thread_id == aurora->mysql[AURORA_PRIMARY]->thread_id)
{
aurora->mysql[AURORA_REPLICA]->net.conn_hdlr= 0;
aurora->mysql[AURORA_REPLICA]->net.extension->conn_hdlr= 0;
mariadb_api->mysql_select_db(aurora->mysql[AURORA_REPLICA], arg);
aurora->mysql[AURORA_REPLICA]->net.conn_hdlr= mysql->net.conn_hdlr;
aurora->mysql[AURORA_REPLICA]->net.extension->conn_hdlr= mysql->net.extension->conn_hdlr;
}
break;
case COM_QUERY:
@@ -763,7 +763,7 @@ int aurora_command(MYSQL *mysql,enum enum_server_command command, const char *ar
break;
}
end:
mysql->net.conn_hdlr= save_hdlr;
mysql->net.extension->conn_hdlr= save_hdlr;
return 0;
}
/* }}} */

View File

@@ -29,6 +29,7 @@
#include <mysql/client_plugin.h>
#include <string.h>
#include <ma_string.h>
#include <ma_common.h>
#ifndef WIN32
#include <sys/time.h>
@@ -181,7 +182,7 @@ MYSQL *repl_connect(MYSQL *mysql, const char *host, const char *user, const char
const char *db, unsigned int port, const char *unix_socket, unsigned long clientflag)
{
REPL_DATA *data= NULL;
MA_CONNECTION_HANDLER *hdlr= mysql->net.conn_hdlr;
MA_CONNECTION_HANDLER *hdlr= mysql->net.extension->conn_hdlr;
if (!mariadb_api)
mariadb_api= mysql->methods->api;
@@ -242,7 +243,7 @@ error:
void repl_close(MYSQL *mysql)
{
MA_CONNECTION_HANDLER *hdlr= mysql->net.conn_hdlr;
MA_CONNECTION_HANDLER *hdlr= mysql->net.extension->conn_hdlr;
REPL_DATA *data= (REPL_DATA *)hdlr->data;
/* restore master */
@@ -261,7 +262,7 @@ void repl_close(MYSQL *mysql)
/* free masrwe information and close connection */
free(data->url);
free(data);
mysql->net.conn_hdlr->data= NULL;
mysql->net.extension->conn_hdlr->data= NULL;
}
static my_bool is_slave_command(const char *buffer, size_t buffer_len)
@@ -299,7 +300,7 @@ static my_bool is_slave_stmt(MYSQL *mysql, const char *buffer)
int repl_command(MYSQL *mysql,enum enum_server_command command, const char *arg,
size_t length, my_bool skipp_check, void *opt_arg)
{
REPL_DATA *data= (REPL_DATA *)mysql->net.conn_hdlr->data;
REPL_DATA *data= (REPL_DATA *)mysql->net.extension->conn_hdlr->data;
/* if we don't have slave or slave became unavailable root traffic to master */
if (!data->pvio[MARIADB_SLAVE] || !data->read_only)
@@ -332,7 +333,7 @@ int repl_command(MYSQL *mysql,enum enum_server_command command, const char *arg,
int repl_set_options(MYSQL *mysql, enum mysql_option option, void *arg)
{
REPL_DATA *data= (REPL_DATA *)mysql->net.conn_hdlr->data;
REPL_DATA *data= (REPL_DATA *)mysql->net.extension->conn_hdlr->data;
switch(option) {
case MARIADB_OPT_CONNECTION_READ_ONLY: