1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
/* Copyright (c) 2017, 2025, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is designed to work with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have either included with
the program or referenced in the documentation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#ifndef MIGRATE_KEYRING_H_INCLUDED
#define MIGRATE_KEYRING_H_INCLUDED
#include <string>
#include "mysql.h"
#include "mysql/plugin_keyring.h"
#include "sql_common.h" // NET_SERVER
#include <mysql/components/services/keyring_load.h>
#include <mysql/components/services/keyring_writer.h>
class THD;
#define MAX_KEY_LEN 16384
enum class enum_plugin_type { SOURCE_PLUGIN = 0, DESTINATION_PLUGIN };
class Key_info {
public:
Key_info() = default;
Key_info(char *key_id, char *user_id) {
m_key_id = key_id;
m_user_id = user_id;
}
Key_info(const Key_info &ki) {
this->m_key_id = ki.m_key_id;
this->m_user_id = ki.m_user_id;
}
public:
std::string m_key_id;
std::string m_user_id;
};
using const_keyring_writer_t = SERVICE_TYPE(keyring_writer);
using const_keyring_load_t = SERVICE_TYPE(keyring_load);
class Destination_keyring_component final {
public:
Destination_keyring_component(const std::string component_path,
const std::string implementation_name);
~Destination_keyring_component();
const_keyring_writer_t *writer() { return keyring_writer_service_; }
const_keyring_load_t *initializer() { return keyring_load_service_; }
bool ok() { return ok_; }
private:
const std::string component_path_;
const_keyring_load_t *keyring_load_service_;
const_keyring_writer_t *keyring_writer_service_;
bool component_loaded_;
bool ok_;
};
class Migrate_keyring {
public:
/**
Standard constructor.
*/
Migrate_keyring();
/**
Initialize all needed parameters to proceed with migration process.
*/
bool init(int argc, char **argv, char *source_plugin,
char *destination_plugin, char *user, char *host, char *password,
char *socket, ulong port, bool migrate_to_component);
/**
Migrate keys from source keyring to destination keyring.
*/
bool execute();
/**
Standard destructor
*/
~Migrate_keyring();
private:
/**
Load source or destination plugin.
*/
bool load_plugin(enum_plugin_type plugin_type);
/**
Load component
*/
bool load_component();
/**
Fetch keys from source plugin and store in destination plugin.
*/
bool fetch_and_store_keys();
/**
Disable @@keyring_operations variable.
*/
bool disable_keyring_operations();
/**
Enable @@keyring_operations variable.
*/
bool enable_keyring_operations();
private:
int m_argc;
char **m_argv;
std::string m_source_plugin_option;
std::string m_destination_plugin_option;
std::string m_source_plugin_name;
std::string m_destination_plugin_name;
std::string m_internal_option[2];
st_mysql_keyring *m_source_plugin_handle;
st_mysql_keyring *m_destination_plugin_handle;
std::vector<Key_info> m_source_keys;
MYSQL *mysql;
NET_SERVER server_extn;
bool m_migrate_to_component;
Destination_keyring_component *m_destination_component;
};
#endif /* MIGRATE_KEYRING_H_INCLUDED */
|