Skip to content

Commit 49bfff7

Browse files
Bharathy SatishHery Ramilison
authored andcommitted
Bug #27175716: KEYRING MIGRATION TOOL GENERATING THE KEYS WHICH CAN'T
BE READ BY SERVER Problem: Keyring migration tool creates backed file for destination plugin if the file is not present. This file is created with OS user as owner for this file. After migration when server is started with destination keyring plugin, plugin will reject this file from reading. Fix: Moved the migration specific code after calls to setgid and setuid so that backend files for destination plugin is created with correct user. (cherry picked from commit 46e91ea8a292f0fcbb9f193514f29375c5335205)
1 parent 944a330 commit 49bfff7

File tree

3 files changed

+71
-74
lines changed

3 files changed

+71
-74
lines changed

sql/migrate_keyring.cc

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ Migrate_keyring::Migrate_keyring()
3333

3434
/**
3535
This function does the following:
36-
1. Read command line arguments specific to migration operation
37-
2. Get plugin_dir value.
38-
3. Get a connection handle by connecting to server.
36+
1. Validate all keyring migration specific options.
37+
2. Get a connection handle by connecting to server if connection
38+
specific options are set.
3939
4040
@param [in] argc Pointer to argc of original program
4141
@param [in] argv Pointer to argv of original program
@@ -61,14 +61,6 @@ bool Migrate_keyring::init(int argc,
6161
{
6262
DBUG_ENTER("Migrate_keyring::init");
6363

64-
my_option migration_options[]= {
65-
{"basedir", 0, "", &mysql_home_ptr, 0,
66-
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
67-
{"plugin_dir", 0, "", &opt_plugin_dir_ptr, 0,
68-
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
69-
70-
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
71-
};
7264
std::size_t found= std::string::npos;
7365
string equal("=");
7466
string so(".so");
@@ -120,17 +112,10 @@ bool Migrate_keyring::init(int argc,
120112
DBUG_RETURN(true);
121113
}
122114

123-
if (my_handle_options(&m_argc, &m_argv, migration_options,
124-
NULL, NULL, TRUE))
125-
DBUG_RETURN(true);
126115
/* Restore program name */
127116
m_argc++;
128117
m_argv--;
129118

130-
convert_dirname(opt_plugin_dir, opt_plugin_dir_ptr ? opt_plugin_dir_ptr :
131-
PLUGINDIR, NullS);
132-
opt_plugin_dir_ptr= opt_plugin_dir;
133-
134119
/* if connect options are provided then initiate connection */
135120
if (migrate_connect_options)
136121
{

sql/migrate_keyring.h

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,34 @@ enum enum_plugin_type
3535
class Key_info
3636
{
3737
public:
38+
Key_info()
39+
: m_key_id_len(0),
40+
m_user_id_len(0)
41+
{}
3842
Key_info(char *key_id,
3943
char *user_id)
4044
{
41-
memcpy(m_key_id, key_id, strlen(key_id));
42-
memcpy(m_user_id, user_id, strlen(user_id));
45+
m_key_id_len= strlen(key_id);
46+
memcpy(m_key_id, key_id, m_key_id_len);
47+
m_key_id[m_key_id_len]= '\0';
48+
m_user_id_len= strlen(user_id);
49+
memcpy(m_user_id, user_id, m_user_id_len);
50+
m_user_id[m_user_id_len]= '\0';
4351
}
4452
Key_info(const Key_info &ki)
4553
{
46-
memcpy(this->m_key_id, ki.m_key_id, strlen(ki.m_key_id));
47-
memcpy(this->m_user_id, ki.m_user_id, strlen(ki.m_user_id));
54+
this->m_key_id_len= ki.m_key_id_len;
55+
memcpy(this->m_key_id, ki.m_key_id, this->m_key_id_len);
56+
this->m_key_id[this->m_key_id_len]= '\0';
57+
this->m_user_id_len= ki.m_user_id_len;
58+
memcpy(this->m_user_id, ki.m_user_id, this->m_user_id_len);
59+
this->m_user_id[this->m_user_id_len]= '\0';
4860
}
4961
public:
5062
char m_key_id[MAX_KEY_LEN];
63+
int m_key_id_len;
5164
char m_user_id[USERNAME_LENGTH];
65+
int m_user_id_len;
5266
};
5367

5468
class Migrate_keyring

sql/mysqld.cc

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2955,49 +2955,6 @@ int init_common_variables()
29552955
return 1;
29562956
init_client_errs();
29572957

2958-
/*
2959-
initiate key migration if any one of the migration specific
2960-
options are provided.
2961-
*/
2962-
if (opt_keyring_migration_source ||
2963-
opt_keyring_migration_destination ||
2964-
migrate_connect_options)
2965-
{
2966-
Migrate_keyring mk;
2967-
my_getopt_skip_unknown= TRUE;
2968-
if (mk.init(remaining_argc, remaining_argv,
2969-
opt_keyring_migration_source,
2970-
opt_keyring_migration_destination,
2971-
opt_keyring_migration_user,
2972-
opt_keyring_migration_host,
2973-
opt_keyring_migration_password,
2974-
opt_keyring_migration_socket,
2975-
opt_keyring_migration_port))
2976-
{
2977-
sql_print_error(ER_DEFAULT(ER_KEYRING_MIGRATION_STATUS),
2978-
"failed");
2979-
log_error_dest= "stderr";
2980-
flush_error_log_messages();
2981-
return 1;
2982-
}
2983-
2984-
if (mk.execute())
2985-
{
2986-
sql_print_error(ER_DEFAULT(ER_KEYRING_MIGRATION_STATUS),
2987-
"failed");
2988-
log_error_dest= "stderr";
2989-
flush_error_log_messages();
2990-
return 1;
2991-
}
2992-
2993-
my_getopt_skip_unknown= 0;
2994-
sql_print_information(ER_DEFAULT(ER_KEYRING_MIGRATION_STATUS),
2995-
"sucessfull");
2996-
log_error_dest= "stderr";
2997-
flush_error_log_messages();
2998-
exit(MYSQLD_SUCCESS_EXIT);
2999-
}
3000-
30012958
mysql_client_plugin_init();
30022959
if (item_create_init())
30032960
return 1;
@@ -4680,15 +4637,6 @@ int mysqld_main(int argc, char **argv)
46804637
srand(static_cast<uint>(time(NULL)));
46814638
#endif
46824639

4683-
/*
4684-
We have enough space for fiddling with the argv, continue
4685-
*/
4686-
if (my_setwd(mysql_real_data_home,MYF(MY_WME)) && !opt_help)
4687-
{
4688-
sql_print_error("failed to set datadir to %s", mysql_real_data_home);
4689-
unireg_abort(MYSQLD_ABORT_EXIT); /* purecov: inspected */
4690-
}
4691-
46924640
#ifndef _WIN32
46934641
if ((user_info= check_user(mysqld_user)))
46944642
{
@@ -4733,6 +4681,56 @@ int mysqld_main(int argc, char **argv)
47334681
}
47344682
#endif // !_WIN32
47354683

4684+
/*
4685+
initiate key migration if any one of the migration specific
4686+
options are provided.
4687+
*/
4688+
if (opt_keyring_migration_source ||
4689+
opt_keyring_migration_destination ||
4690+
migrate_connect_options)
4691+
{
4692+
Migrate_keyring mk;
4693+
if (mk.init(remaining_argc, remaining_argv,
4694+
opt_keyring_migration_source,
4695+
opt_keyring_migration_destination,
4696+
opt_keyring_migration_user,
4697+
opt_keyring_migration_host,
4698+
opt_keyring_migration_password,
4699+
opt_keyring_migration_socket,
4700+
opt_keyring_migration_port))
4701+
{
4702+
sql_print_error(ER_DEFAULT(ER_KEYRING_MIGRATION_STATUS),
4703+
"failed");
4704+
log_error_dest= "stderr";
4705+
flush_error_log_messages();
4706+
unireg_abort(MYSQLD_ABORT_EXIT);
4707+
}
4708+
4709+
if (mk.execute())
4710+
{
4711+
sql_print_error(ER_DEFAULT(ER_KEYRING_MIGRATION_STATUS),
4712+
"failed");
4713+
log_error_dest= "stderr";
4714+
flush_error_log_messages();
4715+
unireg_abort(MYSQLD_ABORT_EXIT);
4716+
}
4717+
4718+
sql_print_information(ER_DEFAULT(ER_KEYRING_MIGRATION_STATUS),
4719+
"successfull");
4720+
log_error_dest= "stderr";
4721+
flush_error_log_messages();
4722+
unireg_abort(MYSQLD_SUCCESS_EXIT);
4723+
}
4724+
4725+
/*
4726+
We have enough space for fiddling with the argv, continue
4727+
*/
4728+
if (my_setwd(mysql_real_data_home,MYF(MY_WME)) && !opt_help)
4729+
{
4730+
sql_print_error("failed to set datadir to %s", mysql_real_data_home);
4731+
unireg_abort(MYSQLD_ABORT_EXIT); /* purecov: inspected */
4732+
}
4733+
47364734
//If the binlog is enabled, one needs to provide a server-id
47374735
if (opt_bin_log && !(server_id_supplied) )
47384736
{

0 commit comments

Comments
 (0)