Skip to content

Commit 7bd2f20

Browse files
committed
make encrypt-binlog and encrypt-tmp-files to fail if no encryption
--encrypt-binlog and --encrypt-tmp-files used to mean "encrypt XXX if encryption is available, otherwise don't encrypt", now they mean "encrypt or fail with an error".
1 parent 39b46ae commit 7bd2f20

File tree

5 files changed

+39
-26
lines changed

5 files changed

+39
-26
lines changed

sql/encryption.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#include "sql_plugin.h"
2020
#include <my_crypt.h>
2121

22-
void init_io_cache_encryption();
23-
2422
/* there can be only one encryption plugin enabled */
2523
static plugin_ref encryption_manager= 0;
2624
struct encryption_service_st encryption_handler;
@@ -81,8 +79,6 @@ int initialize_encryption_plugin(st_plugin_int *plugin)
8179
encryption_handler.encryption_key_get_latest_version_func=
8280
handle->get_latest_key_version; // must be the last
8381

84-
init_io_cache_encryption();
85-
8682
return 0;
8783
}
8884

@@ -100,7 +96,6 @@ int finalize_encryption_plugin(st_plugin_int *plugin)
10096
if (encryption_manager)
10197
plugin_unlock(NULL, encryption_manager);
10298
encryption_manager= 0;
103-
init_io_cache_encryption();
10499
return 0;
105100
}
106101

sql/log.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3469,8 +3469,13 @@ bool MYSQL_BIN_LOG::open(const char *log_name,
34693469
if (encrypt_binlog)
34703470
{
34713471
uint key_version= encryption_key_get_latest_version(ENCRYPTION_KEY_SYSTEM_DATA);
3472-
if (key_version != ENCRYPTION_KEY_VERSION_INVALID &&
3473-
key_version != ENCRYPTION_KEY_NOT_ENCRYPTED)
3472+
if (key_version == ENCRYPTION_KEY_VERSION_INVALID)
3473+
{
3474+
sql_print_error("Failed to enable encryption of binary logs");
3475+
goto err;
3476+
}
3477+
3478+
if (key_version != ENCRYPTION_KEY_NOT_ENCRYPTED)
34743479
{
34753480
if (my_random_bytes(crypto.nonce, sizeof(crypto.nonce)))
34763481
goto err;

sql/mf_iocache_encr.cc

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static int my_b_encr_write(IO_CACHE *info, const uchar *Buffer, size_t Count)
230230
231231
Note that encrypt_tmp_files variable is read-only.
232232
*/
233-
void init_io_cache_encryption()
233+
int init_io_cache_encryption()
234234
{
235235
if (encrypt_tmp_files)
236236
{
@@ -241,20 +241,23 @@ void init_io_cache_encryption()
241241
keyid= ENCRYPTION_KEY_SYSTEM_DATA;
242242
keyver= encryption_key_get_latest_version(keyid);
243243
}
244-
}
245-
else
246-
keyver= ENCRYPTION_KEY_VERSION_INVALID;
244+
if (keyver == ENCRYPTION_KEY_VERSION_INVALID)
245+
{
246+
sql_print_error("Failed to enable encryption of temporary files");
247+
return 1;
248+
}
247249

248-
if (keyver != ENCRYPTION_KEY_VERSION_INVALID)
249-
{
250-
sql_print_information("Using encryption key id %d for temporary files", keyid);
251-
_my_b_encr_read= my_b_encr_read;
252-
_my_b_encr_write= my_b_encr_write;
253-
}
254-
else
255-
{
256-
_my_b_encr_read= 0;
257-
_my_b_encr_write= 0;
250+
if (keyver != ENCRYPTION_KEY_NOT_ENCRYPTED)
251+
{
252+
sql_print_information("Using encryption key id %d for temporary files", keyid);
253+
_my_b_encr_read= my_b_encr_read;
254+
_my_b_encr_write= my_b_encr_write;
255+
return 0;
256+
}
258257
}
258+
259+
_my_b_encr_read= 0;
260+
_my_b_encr_write= 0;
261+
return 0;
259262
}
260263

sql/mysqld.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ extern "C" sig_handler handle_fatal_signal(int sig);
278278
#define ENABLE_TEMP_POOL 0
279279
#endif
280280

281+
int init_io_cache_encryption();
282+
281283
/* Constants */
282284

283285
#include <welcome_copyright_notice.h> // ORACLE_WELCOME_COPYRIGHT_NOTICE
@@ -5231,6 +5233,9 @@ static int init_server_components()
52315233
}
52325234
}
52335235

5236+
if (init_io_cache_encryption())
5237+
unireg_abort(1);
5238+
52345239
if (opt_abort)
52355240
unireg_abort(0);
52365241

@@ -5329,10 +5334,11 @@ static int init_server_components()
53295334
* but to be able to have mysql_mutex_assert_owner() in code,
53305335
* we do it anyway */
53315336
mysql_mutex_lock(mysql_bin_log.get_log_lock());
5332-
if (mysql_bin_log.open(opt_bin_logname, LOG_BIN, 0, 0,
5333-
WRITE_CACHE, max_binlog_size, 0, TRUE))
5334-
unireg_abort(1);
5337+
int r= mysql_bin_log.open(opt_bin_logname, LOG_BIN, 0, 0,
5338+
WRITE_CACHE, max_binlog_size, 0, TRUE);
53355339
mysql_mutex_unlock(mysql_bin_log.get_log_lock());
5340+
if (r)
5341+
unireg_abort(1);
53365342
}
53375343

53385344
#ifdef HAVE_REPLICATION

unittest/sql/mf_iocache-t.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#define KEY_SIZE (128/8)
2222

2323
my_bool encrypt_tmp_files;
24-
void init_io_cache_encryption();
24+
int init_io_cache_encryption();
2525

2626
uint encryption_key_get_latest_version_func(uint)
2727
{
@@ -79,7 +79,11 @@ struct encryption_service_st encryption_handler=
7979
encryption_encrypted_length_func
8080
};
8181

82-
void sql_print_information(const char *format, ...)
82+
void sql_print_information(const char *format, ...)
83+
{
84+
}
85+
86+
void sql_print_error(const char *format, ...)
8387
{
8488
}
8589

0 commit comments

Comments
 (0)