1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-14974: --port ignored for --host=localhost

Problem:
=======
MariaDB's command line utilities (e.g., mysql,
mysqldump, etc) silently ignore connection
property options (e.g., --port and --socket)
when protocol is not explicitly set via the
command-line for localhost connections.

Fix:
===
If connection properties are specified without a
protocol, override the protocol to be consistent.
For example, if --port is specified, automatically
set protocol=tcp.

Caveats:
=======
 * When multiple connection properties are
specified, nothing is overridden
 * If protocol is is set via the command-line,
its value is used

Reviewers:
========
Sergei Golubchik <serg@mariadb.com>
Vladislav Vaintroub <wlad@mariadb.com>
This commit is contained in:
Brandon Nesterenko
2021-05-10 11:10:53 -06:00
parent 02380cd384
commit b6cfb2961e
27 changed files with 766 additions and 61 deletions

View File

@@ -98,6 +98,8 @@ static const char *output_prefix= "";
static char **defaults_argv= 0;
static MEM_ROOT glob_root;
static uint protocol_to_force= MYSQL_PROTOCOL_DEFAULT;
#ifndef DBUG_OFF
static const char *default_dbug_option = "d:t:o,/tmp/mariadb-binlog.trace";
const char *current_dbug_option= default_dbug_option;
@@ -1959,9 +1961,13 @@ static my_time_t convert_str_to_timestamp(const char* str)
extern "C" my_bool
get_one_option(const struct my_option *opt, const char *argument, const char *)
get_one_option(const struct my_option *opt, const char *argument, const char *filename)
{
bool tty_password=0;
/* Track when protocol is set via CLI to not force overrides */
static my_bool ignore_protocol_override = FALSE;
switch (opt->id) {
#ifndef DBUG_OFF
case '#':
@@ -2011,6 +2017,14 @@ get_one_option(const struct my_option *opt, const char *argument, const char *)
sf_leaking_memory= 1; /* no memory leak reports here */
die();
}
/* Specification of protocol via CLI trumps implicit overrides */
if (filename[0] == '\0')
{
ignore_protocol_override = TRUE;
protocol_to_force = MYSQL_PROTOCOL_DEFAULT;
}
break;
#ifdef WHEN_FLASHBACK_REVIEW_READY
case opt_flashback_review:
@@ -2092,6 +2106,38 @@ get_one_option(const struct my_option *opt, const char *argument, const char *)
case OPT_PRINT_ROW_EVENT_POSITIONS:
print_row_event_positions_used= 1;
break;
case 'P':
/* If port and socket are set, fall back to default behavior */
if (protocol_to_force == SOCKET_PROTOCOL_TO_FORCE)
{
ignore_protocol_override = TRUE;
protocol_to_force = MYSQL_PROTOCOL_DEFAULT;
}
/* If port is set via CLI, try to force protocol to TCP */
if (filename[0] == '\0' &&
!ignore_protocol_override &&
protocol_to_force == MYSQL_PROTOCOL_DEFAULT)
{
protocol_to_force = MYSQL_PROTOCOL_TCP;
}
break;
case 'S':
/* If port and socket are set, fall back to default behavior */
if (protocol_to_force == MYSQL_PROTOCOL_TCP)
{
ignore_protocol_override = TRUE;
protocol_to_force = MYSQL_PROTOCOL_DEFAULT;
}
/* Prioritize socket if set via command line */
if (filename[0] == '\0' &&
!ignore_protocol_override &&
protocol_to_force == MYSQL_PROTOCOL_DEFAULT)
{
protocol_to_force = SOCKET_PROTOCOL_TO_FORCE;
}
break;
case 'v':
if (argument == disabled_my_option)
verbose= 0;
@@ -3049,6 +3095,9 @@ int main(int argc, char** argv)
my_init_time(); // for time functions
tzset(); // set tzname
/* We need to know if protocol-related options originate from CLI args */
my_defaults_mark_files = TRUE;
load_defaults_or_exit("my", load_groups, &argc, &argv);
defaults_argv= argv;
@@ -3062,6 +3111,13 @@ int main(int argc, char** argv)
parse_args(&argc, (char***)&argv);
/* Command line options override configured protocol */
if (protocol_to_force > MYSQL_PROTOCOL_DEFAULT
&& protocol_to_force != opt_protocol)
{
warn_protocol_override(host, &opt_protocol, protocol_to_force);
}
if (!argc || opt_version)
{
if (!opt_version)