Skip to content

Commit cc49207

Browse files
author
Robert Golebiowski
committed
Merge branch 'mysql-5.7-keyring-okv' into mysql-5.7
Conflicts: sql/mysqld.cc storage/innobase/os/os0file.cc
2 parents 545e3ae + d11b480 commit cc49207

File tree

22 files changed

+287
-241
lines changed

22 files changed

+287
-241
lines changed

include/mysql/plugin_keyring.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
st_mysql_plugin.
2929
*/
3030

31-
struct st_mysql_keyring_file
31+
struct st_mysql_keyring
3232
{
3333
int interface_version;
3434
/*!

include/mysql/plugin_keyring.h.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
void *thd_get_ha_data(const void* thd, const struct handlerton *hton);
112112
void thd_set_ha_data(void* thd, const struct handlerton *hton,
113113
const void *ha_data);
114-
struct st_mysql_keyring_file
114+
struct st_mysql_keyring
115115
{
116116
int interface_version;
117117
my_bool (*mysql_key_store)(const char *key_id, const char *key_type,

libmysqld/lib_sql.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ int init_embedded_server(int argc, char **argv, char **groups)
610610
Each server should have one UUID. We will create it automatically, if it
611611
does not exist.
612612
*/
613-
if (!opt_bootstrap && init_server_auto_options())
613+
if (!opt_bootstrap && init_server_auto_options(false))
614614
{
615615
mysql_server_end();
616616
return 1;

packaging/rpm-oel/mysql.spec.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,12 +828,14 @@ fi
828828
%if 0%{?commercial}
829829
%attr(755, root, root) %{_libdir}/mysql/plugin/audit_log.so
830830
%attr(755, root, root) %{_libdir}/mysql/plugin/authentication_pam.so
831+
%attr(755, root, root) %{_libdir}/mysql/plugin/keyring_okv.so
831832
%attr(755, root, root) %{_libdir}/mysql/plugin/thread_pool.so
832833
%attr(755, root, root) %{_libdir}/mysql/plugin/openssl_udf.so
833834
%attr(755, root, root) %{_libdir}/mysql/plugin/firewall.so
834835
%attr(644, root, root) %{_datadir}/mysql/linux_install_firewall.sql
835836
%attr(755, root, root) %{_libdir}/mysql/plugin/debug/audit_log.so
836837
%attr(755, root, root) %{_libdir}/mysql/plugin/debug/authentication_pam.so
838+
%attr(755, root, root) %{_libdir}/mysql/plugin/debug/keyring_okv.so
837839
%attr(755, root, root) %{_libdir}/mysql/plugin/debug/thread_pool.so
838840
%attr(755, root, root) %{_libdir}/mysql/plugin/debug/openssl_udf.so
839841
%attr(755, root, root) %{_libdir}/mysql/plugin/debug/firewall.so
@@ -1060,6 +1062,9 @@ fi
10601062
%endif
10611063

10621064
%changelog
1065+
* Fri Feb 5 2016 Balasubramanian Kandasamy <[email protected]> - 5.7.12-1
1066+
- Add keyring_okv.so plugin to commercial server subpackage
1067+
10631068
* Mon Jan 4 2016 Balasubramanian Kandasamy <[email protected]> - 5.7.11-1
10641069
- Include mysql-keyring directory
10651070
- Provide keyring_file.so plugin

packaging/rpm-sles/mysql.spec.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,12 +652,14 @@ fi
652652
%if 0%{?commercial}
653653
%attr(755, root, root) %{_libdir}/mysql/plugin/audit_log.so
654654
%attr(755, root, root) %{_libdir}/mysql/plugin/authentication_pam.so
655+
%attr(755, root, root) %{_libdir}/mysql/plugin/keyring_okv.so
655656
%attr(755, root, root) %{_libdir}/mysql/plugin/thread_pool.so
656657
%attr(755, root, root) %{_libdir}/mysql/plugin/openssl_udf.so
657658
%attr(755, root, root) %{_libdir}/mysql/plugin/firewall.so
658659
%attr(644, root, root) %{_datadir}/mysql/linux_install_firewall.sql
659660
%attr(755, root, root) %{_libdir}/mysql/plugin/debug/audit_log.so
660661
%attr(755, root, root) %{_libdir}/mysql/plugin/debug/authentication_pam.so
662+
%attr(755, root, root) %{_libdir}/mysql/plugin/debug/keyring_okv.so
661663
%attr(755, root, root) %{_libdir}/mysql/plugin/debug/thread_pool.so
662664
%attr(755, root, root) %{_libdir}/mysql/plugin/debug/openssl_udf.so
663665
%attr(755, root, root) %{_libdir}/mysql/plugin/debug/firewall.so
@@ -868,6 +870,9 @@ fi
868870
%attr(755, root, root) %{_libdir}/mysql/libmysqld.so
869871

870872
%changelog
873+
* Fri Feb 5 2016 Balasubramanian Kandasamy <[email protected]> - 5.7.12-1
874+
- Add keyring_okv.so plugin to commercial server subpackage
875+
871876
* Mon Jan 4 2016 Balasubramanian Kandasamy <[email protected]> - 5.7.11-1
872877
- Include mysql-keyring directory
873878
- Provide keyring_file.so plugin

plugin/keyring/buffered_file_io.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ my_bool Buffered_file_io::remove_backup()
208208
return remove(get_backup_filename()->c_str()) == 0 ? FALSE : TRUE;
209209
}
210210

211-
my_bool Buffered_file_io::flush_to_keyring()
211+
212+
my_bool Buffered_file_io::flush_to_keyring(IKey *key /*=NULL*/__attribute__((unused)),
213+
Flush_operation operation /*= STORE_KEY*/__attribute__((unused)))
212214
{
213215
return flush_to_file(&keyring_file_data_key, &keyring_filename);
214216
}

plugin/keyring/buffered_file_io.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ class Buffered_file_io : public IKeyring_io
4242
void reserve_buffer(size_t memory_size);
4343
my_bool close();
4444
my_bool flush_to_backup();
45-
my_bool flush_to_keyring();
45+
/* Both attributes are unused */
46+
my_bool flush_to_keyring(IKey *key = NULL, Flush_operation operation = STORE_KEY);
4647
/**
4748
* Writes key into the buffer
4849
* @param key the key to be written to the buffer

plugin/keyring/i_keyring_io.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121

2222
namespace keyring {
2323

24+
enum Flush_operation
25+
{
26+
STORE_KEY,
27+
REMOVE_KEY,
28+
FULL
29+
};
30+
2431
class IKeyring_io : public Keyring_alloc
2532
{
2633
public:
@@ -29,7 +36,7 @@ class IKeyring_io : public Keyring_alloc
2936
virtual void reserve_buffer(size_t memory_size)= 0;
3037
virtual my_bool close()= 0;
3138
virtual my_bool flush_to_backup()= 0;
32-
virtual my_bool flush_to_keyring()= 0;
39+
virtual my_bool flush_to_keyring(IKey *key = NULL, Flush_operation operation= STORE_KEY)= 0;
3340
virtual my_bool operator<< (const IKey* key)= 0;
3441
virtual my_bool operator>> (IKey* key)= 0;
3542

plugin/keyring/keyring.cc

Lines changed: 98 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,69 @@
2323
#define MYSQL_DEFAULT_KEYRINGFILE MYSQL_KEYRINGDIR"/keyring"
2424
#endif
2525

26-
static int check_keyring_file_data(MYSQL_THD thd __attribute__((unused)),
27-
struct st_mysql_sys_var *var __attribute__((unused)),
28-
void *save, st_mysql_value *value)
26+
my_bool create_keyring_dir_if_does_not_exist(const char *keyring_file_path)
2927
{
30-
Buffered_file_io keyring_io(logger.get());
28+
if (!keyring_file_path || strlen(keyring_file_path) == 0)
29+
return TRUE;
30+
char keyring_dir[FN_REFLEN];
31+
size_t keyring_dir_length;
32+
dirname_part(keyring_dir, keyring_file_path, &keyring_dir_length);
33+
if (keyring_dir_length > 1 && (keyring_dir[keyring_dir_length-1] == FN_LIBCHAR ||
34+
keyring_dir[keyring_dir_length-1] == FN_LIBCHAR2) )
35+
{
36+
keyring_dir[keyring_dir_length-1]= '\0';
37+
--keyring_dir_length;
38+
}
39+
int flags=
40+
#ifdef _WIN32
41+
0
42+
#else
43+
S_IRWXU | S_IRGRP | S_IXGRP
44+
#endif
45+
;
46+
if (strlen(keyring_dir) == 0)
47+
return TRUE;
48+
my_mkdir(keyring_dir, flags, MYF(0));
49+
return FALSE;
50+
}
3151

52+
int check_keyring_file_data(MYSQL_THD thd __attribute__((unused)),
53+
struct st_mysql_sys_var *var __attribute__((unused)),
54+
void *save, st_mysql_value *value)
55+
{
56+
char buff[FN_REFLEN+1];
57+
const char *keyring_filename;
58+
int len = sizeof(buff);
59+
Buffered_file_io keyring_io(logger.get());
3260
boost::movelib::unique_ptr<IKeys_container> new_keys(new Keys_container(logger.get()));
33-
return check_keyring_file_data(&keyring_io, ::boost::move(new_keys), thd, var, save, value);
61+
62+
(*(const char **) save)= NULL;
63+
keyring_filename= value->val_str(value, buff, &len);
64+
mysql_rwlock_wrlock(&LOCK_keyring);
65+
if (create_keyring_dir_if_does_not_exist(keyring_filename))
66+
{
67+
mysql_rwlock_unlock(&LOCK_keyring);
68+
logger->log(MY_ERROR_LEVEL, "keyring_file_data cannot be set to new value"
69+
" as the keyring file cannot be created/accessed in the provided path");
70+
return 1;
71+
}
72+
try
73+
{
74+
if (new_keys->init(&keyring_io, keyring_filename))
75+
{
76+
mysql_rwlock_unlock(&LOCK_keyring);
77+
return 1;
78+
}
79+
*reinterpret_cast<IKeys_container **>(save)= new_keys.get();
80+
new_keys.release();
81+
mysql_rwlock_unlock(&LOCK_keyring);
82+
}
83+
catch (...)
84+
{
85+
mysql_rwlock_unlock(&LOCK_keyring);
86+
return 1;
87+
}
88+
return(0);
3489
}
3590

3691
static char *keyring_file_data_value= NULL;
@@ -44,7 +99,7 @@ static MYSQL_SYSVAR_STR(
4499
MYSQL_DEFAULT_KEYRINGFILE /* default */
45100
);
46101

47-
static struct st_mysql_sys_var *keyring_system_variables[]= {
102+
static struct st_mysql_sys_var *keyring_file_system_variables[]= {
48103
MYSQL_SYSVAR(data),
49104
NULL
50105
};
@@ -85,55 +140,69 @@ static int keyring_init(MYSQL_PLUGIN plugin_info)
85140
}
86141
catch (...)
87142
{
143+
if (logger != NULL)
144+
logger->log(MY_ERROR_LEVEL, "keyring_file initialization failure due to internal"
145+
" exception inside the plugin");
88146
return TRUE;
89147
}
90148
}
91149

150+
int keyring_deinit(void *arg __attribute__((unused)))
151+
{
152+
//not taking a lock here as the calls to keyring_deinit are serialized by
153+
//the plugin framework
154+
keys.reset();
155+
logger.reset();
156+
keyring_file_data.reset();
157+
mysql_rwlock_destroy(&LOCK_keyring);
158+
return 0;
159+
}
160+
161+
my_bool mysql_key_fetch(const char *key_id, char **key_type, const char *user_id,
162+
void **key, size_t *key_len)
163+
{
164+
return mysql_key_fetch<Buffered_file_io, Key>(key_id, key_type, user_id, key,
165+
key_len);
166+
}
167+
92168
my_bool mysql_key_store(const char *key_id, const char *key_type,
93169
const char *user_id, const void *key, size_t key_len)
94170
{
95-
try
96-
{
97-
Buffered_file_io keyring_io(logger.get());
98-
return mysql_key_store(&keyring_io, key_id, key_type, user_id, key,
99-
key_len);
100-
}
101-
catch (...)
102-
{
103-
return TRUE;
104-
}
171+
return mysql_key_store<Buffered_file_io, Key>(key_id, key_type, user_id, key,
172+
key_len);
105173
}
106174

107175
my_bool mysql_key_remove(const char *key_id, const char *user_id)
108176
{
109-
try
110-
{
111-
Buffered_file_io keyring_io(logger.get());
112-
return mysql_key_remove(&keyring_io, key_id, user_id);
113-
}
114-
catch (...)
115-
{
116-
return TRUE;
117-
}
177+
return mysql_key_remove<Buffered_file_io, Key>(key_id, user_id);
118178
}
119179

180+
120181
my_bool mysql_key_generate(const char *key_id, const char *key_type,
121182
const char *user_id, size_t key_len)
122183
{
123184
try
124185
{
125186
Buffered_file_io keyring_io(logger.get());
126-
return mysql_key_generate(&keyring_io, key_id, key_type, user_id, key_len);
187+
boost::movelib::unique_ptr<IKey> key_candidate(new Key(key_id, key_type, user_id, NULL, 0));
188+
189+
boost::movelib::unique_ptr<uchar[]> key(new uchar[key_len]);
190+
if (is_keys_container_initialized == FALSE || check_key_for_writting(key_candidate.get(), "generating") ||
191+
my_rand_buffer(key.get(), key_len))
192+
return TRUE;
193+
194+
return mysql_key_store(key_id, key_type, user_id, key.get(), key_len) == TRUE;
127195
}
128196
catch (...)
129197
{
198+
if (logger != NULL)
199+
logger->log(MY_ERROR_LEVEL, "Failed to generate a key due to internal exception inside keyring_file plugin");
130200
return TRUE;
131201
}
132-
133202
}
134203

135204
/* Plugin type-specific descriptor */
136-
static struct st_mysql_keyring_file keyring_descriptor=
205+
static struct st_mysql_keyring keyring_descriptor=
137206
{
138207
MYSQL_KEYRING_INTERFACE_VERSION,
139208
mysql_key_store,
@@ -154,7 +223,7 @@ mysql_declare_plugin(keyring_file)
154223
keyring_deinit, /* deinit function (when unloaded) */
155224
0x0100, /* version */
156225
NULL, /* status variables */
157-
keyring_system_variables, /* system variables */
226+
keyring_file_system_variables, /* system variables */
158227
NULL,
159228
0,
160229
}

plugin/keyring/keyring.h

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,33 +44,72 @@ void keyring_init_psi_keys(void);
4444

4545
my_bool init_keyring_locks();
4646

47-
my_bool create_keyring_dir_if_does_not_exist(const char *keyring_file_path);
48-
49-
int check_keyring_file_data(IKeyring_io* keyring_io, boost::movelib::unique_ptr<IKeys_container> new_keys,
50-
MYSQL_THD thd __attribute__((unused)),
51-
struct st_mysql_sys_var *var __attribute__((unused)),
52-
void *save, st_mysql_value *value);
53-
5447
void update_keyring_file_data(MYSQL_THD thd __attribute__((unused)),
5548
struct st_mysql_sys_var *var __attribute__((unused)),
5649
void *var_ptr __attribute__((unused)),
5750
const void *save_ptr);
5851

59-
my_bool mysql_key_store(IKeyring_io *keyring_io, const char *key_id,
60-
const char *key_type, const char *user_id,
61-
const void *key, size_t key_len);
52+
my_bool mysql_key_fetch(boost::movelib::unique_ptr<IKey> key_to_fetch, char **key_type,
53+
void **key, size_t *key_len);
54+
55+
my_bool mysql_key_store(IKeyring_io *keyring_io,
56+
boost::movelib::unique_ptr<IKey> key_to_store);
6257

58+
my_bool mysql_key_remove(IKeyring_io *keyring_io,
59+
boost::movelib::unique_ptr<IKey> key_to_remove);
6360

64-
my_bool mysql_key_remove(IKeyring_io *keyring_io, const char *key_id,
65-
const char *user_id);
61+
my_bool check_key_for_writting(IKey* key, std::string error_for);
6662

63+
template <typename T, typename U>
6764
my_bool mysql_key_fetch(const char *key_id, char **key_type, const char *user_id,
68-
void **key, size_t *key_len);
65+
void **key, size_t *key_len)
66+
{
67+
try
68+
{
69+
boost::movelib::unique_ptr<IKey> key_to_fetch(new U(key_id, NULL, user_id, NULL, 0));
70+
return mysql_key_fetch(::boost::move(key_to_fetch), key_type, key, key_len);
71+
}
72+
catch (...)
73+
{
74+
if (logger != NULL)
75+
logger->log(MY_ERROR_LEVEL, "Failed to fetch a key due to internal exception inside keyring_okv plugin");
76+
return TRUE;
77+
}
78+
}
6979

70-
my_bool mysql_key_generate(IKeyring_io* keyring_io, const char *key_id,
71-
const char *key_type, const char *user_id,
72-
size_t key_len);
80+
template <typename T, typename U>
81+
my_bool mysql_key_store(const char *key_id, const char *key_type,
82+
const char *user_id, const void *key, size_t key_len)
83+
{
84+
try
85+
{
86+
T keyring_io(logger.get());
87+
boost::movelib::unique_ptr<IKey> key_to_store(new U(key_id, key_type, user_id, key, key_len));
88+
return mysql_key_store(&keyring_io, ::boost::move(key_to_store));
89+
}
90+
catch (...)
91+
{
92+
if (logger != NULL)
93+
logger->log(MY_ERROR_LEVEL, "Failed to store a key due to internal exception inside keyring_okv plugin");
94+
return TRUE;
95+
}
96+
}
7397

74-
int keyring_deinit(void *arg __attribute__((unused)));
98+
template <typename T, typename U>
99+
my_bool mysql_key_remove(const char *key_id, const char *user_id)
100+
{
101+
try
102+
{
103+
T keyring_io(logger.get());
104+
boost::movelib::unique_ptr<IKey> key_to_remove(new U(key_id, NULL, user_id, NULL, 0));
105+
return mysql_key_remove(&keyring_io, ::boost::move(key_to_remove));
106+
}
107+
catch (...)
108+
{
109+
if (logger != NULL)
110+
logger->log(MY_ERROR_LEVEL, "Failed to remove a key due to internal exception inside keyring_okv plugin");
111+
return TRUE;
112+
}
113+
}
75114

76115
#endif //MYSQL_KEYRING_H

0 commit comments

Comments
 (0)