Skip to content

Commit

Permalink
Merge 10.2 into 10.3
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-m committed Sep 7, 2018
2 parents c3a8017 + 59950df commit 4901f31
Show file tree
Hide file tree
Showing 9 changed files with 672 additions and 50 deletions.
50 changes: 47 additions & 3 deletions extra/mariabackup/encryption_plugin.cc
Expand Up @@ -51,6 +51,36 @@ static void add_to_plugin_load_list(const char *plugin_def)

static char XTRABACKUP_EXE[] = "xtrabackup";

/*
Read "plugin-load" value (encryption plugin) from backup-my.cnf during
prepare phase.
The value is stored during backup phase.
*/
static std::string get_encryption_plugin_from_cnf()
{
FILE *f = fopen("backup-my.cnf", "r");
if (!f)
{
msg("cannot open backup-my.cnf for reading\n");
exit(EXIT_FAILURE);
}
char line[512];
std::string plugin_load;
while (fgets(line, sizeof(line), f))
{
if (strncmp(line, "plugin_load=", 12) == 0)
{
plugin_load = line + 12;
// remote \n at the end of string
plugin_load.resize(plugin_load.size() - 1);
break;
}
}
fclose(f);
return plugin_load;
}


void encryption_plugin_backup_init(MYSQL *mysql)
{
MYSQL_RES *result;
Expand Down Expand Up @@ -78,7 +108,17 @@ void encryption_plugin_backup_init(MYSQL *mysql)

std::string plugin_load(name);
if (library)
{
/* Remove shared library suffixes, in case we'll prepare on different OS.*/
const char *extensions[] = { ".dll", ".so", 0 };
for (size_t i = 0; extensions[i]; i++)
{
const char *ext = extensions[i];
if (ends_with(library, ext))
library[strlen(library) - strlen(ext)] = 0;
}
plugin_load += std::string("=") + library;
}

oss << "plugin_load=" << plugin_load << std::endl;

Expand Down Expand Up @@ -140,14 +180,18 @@ extern int finalize_encryption_plugin(st_plugin_int *plugin);

void encryption_plugin_prepare_init(int argc, char **argv)
{

if (!xb_plugin_load)
std::string plugin_load= get_encryption_plugin_from_cnf();
if (plugin_load.size())
{
msg("Loading encryption plugin from %s\n", plugin_load.c_str());
}
else
{
finalize_encryption_plugin(0);
return;
}

add_to_plugin_load_list(xb_plugin_load);
add_to_plugin_load_list(plugin_load.c_str());

if (xb_plugin_dir)
strncpy(opt_plugin_dir, xb_plugin_dir, FN_REFLEN);
Expand Down
7 changes: 1 addition & 6 deletions extra/mariabackup/xtrabackup.cc
Expand Up @@ -709,7 +709,6 @@ enum options_xtrabackup
OPT_INNODB_LOG_CHECKSUMS,
OPT_XTRA_INCREMENTAL_FORCE_SCAN,
OPT_DEFAULTS_GROUP,
OPT_PLUGIN_LOAD,
OPT_INNODB_ENCRYPT_LOG,
OPT_CLOSE_FILES,
OPT_CORE_FILE,
Expand Down Expand Up @@ -1268,11 +1267,7 @@ struct my_option xb_server_options[] =
&xb_plugin_dir, &xb_plugin_dir,
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },

{ "plugin-load", OPT_PLUGIN_LOAD, "encrypton plugin to load during 'prepare' phase.",
&xb_plugin_load, &xb_plugin_load,
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },

{ "innodb-encrypt-log", OPT_INNODB_ENCRYPT_LOG, "encrypton plugin to load",
{ "innodb-encrypt-log", OPT_INNODB_ENCRYPT_LOG, "Whether to encrypt innodb log",
&srv_encrypt_log, &srv_encrypt_log,
0, GET_BOOL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },

Expand Down

0 comments on commit 4901f31

Please sign in to comment.