summaryrefslogtreecommitdiff
path: root/plugin/example_key_management
diff options
context:
space:
mode:
authorVladislav Vaintroub <wlad@mariadb.com>2017-04-25 15:44:18 +0200
committerSergei Golubchik <serg@mariadb.org>2017-04-27 19:12:38 +0200
commit7bf409593e624deb00265e21e0d4579ce9fa7999 (patch)
tree7da6af1ff5a92126af5969a9504a82ddcf4cf263 /plugin/example_key_management
parentdb3910741347e7d741f4a854075c248e9081d722 (diff)
downloadmariadb-git-7bf409593e624deb00265e21e0d4579ce9fa7999.tar.gz
MDEV-11660 Make encryption plugins "pure"
Do not exporting mysqld entry points directly. This is needed for mariabackup, to load encryption plugins on Windows. All plugins are "pure" by default. To mark plugin "impure" it should use RECOMPILE_FOR_EMBEDDED or STORAGE_ENGINE keyword.
Diffstat (limited to 'plugin/example_key_management')
-rw-r--r--plugin/example_key_management/example_key_management_plugin.cc13
1 files changed, 9 insertions, 4 deletions
diff --git a/plugin/example_key_management/example_key_management_plugin.cc b/plugin/example_key_management/example_key_management_plugin.cc
index dc1e2038dd2..2b43729e3f7 100644
--- a/plugin/example_key_management/example_key_management_plugin.cc
+++ b/plugin/example_key_management/example_key_management_plugin.cc
@@ -28,18 +28,24 @@
#include <my_global.h>
#include <my_pthread.h>
#include <mysql/plugin_encryption.h>
-#include <my_rnd.h>
#include <my_crypt.h>
/* rotate key randomly between 45 and 90 seconds */
#define KEY_ROTATION_MIN 45
#define KEY_ROTATION_MAX 90
-static struct my_rnd_struct seed;
static time_t key_version = 0;
static time_t next_key_version = 0;
static pthread_mutex_t mutex;
+
+/* Random double value in 0..1 range */
+static double double_rnd()
+{
+ return ((double)rand()) / RAND_MAX;
+}
+
+
static unsigned int
get_latest_key_version(unsigned int key_id)
{
@@ -50,7 +56,7 @@ get_latest_key_version(unsigned int key_id)
key_version = now;
unsigned int interval = KEY_ROTATION_MAX - KEY_ROTATION_MIN;
next_key_version = (time_t) (now + KEY_ROTATION_MIN +
- my_rnd(&seed) * interval);
+ double_rnd() * interval);
}
pthread_mutex_unlock(&mutex);
@@ -101,7 +107,6 @@ static unsigned int get_length(unsigned int slen, unsigned int key_id,
static int example_key_management_plugin_init(void *p)
{
/* init */
- my_rnd_init(&seed, time(0), 0);
pthread_mutex_init(&mutex, NULL);
get_latest_key_version(1);