Skip to content

Commit db39107

Browse files
vaintroubvuvova
authored andcommitted
MDEV-11663 Create services for functionality used by plugins
Added service for - encryption (AES) - error reporting, e.g my_printf_error()
1 parent 175dd3a commit db39107

33 files changed

+537
-144
lines changed

include/my_crypt.h

Lines changed: 2 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -18,74 +18,7 @@
1818
#ifndef MY_CRYPT_INCLUDED
1919
#define MY_CRYPT_INCLUDED
2020

21-
#include <my_global.h>
22-
23-
#ifdef __cplusplus
24-
extern "C" {
25-
#endif
26-
27-
/* return values from my_aes_encrypt/my_aes_decrypt functions */
28-
#define MY_AES_OK 0
29-
#define MY_AES_BAD_DATA -100
30-
#define MY_AES_OPENSSL_ERROR -101
31-
#define MY_AES_BAD_KEYSIZE -102
32-
33-
/* The block size for all supported algorithms */
34-
#define MY_AES_BLOCK_SIZE 16
35-
36-
/* The max key length of all supported algorithms */
37-
#define MY_AES_MAX_KEY_LENGTH 32
38-
39-
#define MY_AES_CTX_SIZE 512
40-
41-
enum my_aes_mode {
42-
MY_AES_ECB, MY_AES_CBC
43-
#ifdef HAVE_EncryptAes128Ctr
44-
, MY_AES_CTR
45-
#endif
46-
#ifdef HAVE_EncryptAes128Gcm
47-
, MY_AES_GCM
48-
#endif
49-
};
50-
51-
int my_aes_crypt_init(void *ctx, enum my_aes_mode mode, int flags,
52-
const unsigned char* key, unsigned int klen,
53-
const unsigned char* iv, unsigned int ivlen);
54-
int my_aes_crypt_update(void *ctx, const uchar *src, uint slen,
55-
uchar *dst, uint *dlen);
56-
int my_aes_crypt_finish(void *ctx, uchar *dst, uint *dlen);
57-
int my_aes_crypt(enum my_aes_mode mode, int flags,
58-
const uchar *src, uint slen, uchar *dst, uint *dlen,
59-
const uchar *key, uint klen, const uchar *iv, uint ivlen);
60-
61-
/*
62-
calculate the length of the cyphertext from the length of the plaintext
63-
for different AES encryption modes with padding enabled.
64-
Without padding (ENCRYPTION_FLAG_NOPAD) cyphertext has the same length
65-
as the plaintext
66-
*/
67-
static inline uint my_aes_get_size(enum my_aes_mode mode __attribute__((unused)), uint source_length)
68-
{
69-
#ifdef HAVE_EncryptAes128Ctr
70-
if (mode == MY_AES_CTR)
71-
return source_length;
72-
#ifdef HAVE_EncryptAes128Gcm
73-
if (mode == MY_AES_GCM)
74-
return source_length + MY_AES_BLOCK_SIZE;
75-
#endif
76-
#endif
77-
return (source_length / MY_AES_BLOCK_SIZE + 1) * MY_AES_BLOCK_SIZE;
78-
}
79-
80-
static inline uint my_aes_ctx_size(enum my_aes_mode mode __attribute__((unused)))
81-
{
82-
return MY_AES_CTX_SIZE;
83-
}
84-
85-
int my_random_bytes(uchar* buf, int num);
86-
87-
#ifdef __cplusplus
88-
}
89-
#endif
21+
#include <my_config.h> /* HAVE_EncryptAes128{Ctr,Gcm} */
22+
#include <mysql/service_my_crypt.h>
9023

9124
#endif /* MY_CRYPT_INCLUDED */

include/my_sys.h

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ typedef struct my_aio_result {
4242
#include <malloc.h> /*for alloca*/
4343
#endif
4444
#include <mysql/plugin.h>
45+
#include <mysql/service_my_print_error.h>
4546

4647
#define MY_INIT(name) { my_progname= name; my_init(); }
4748

@@ -104,18 +105,10 @@ typedef struct my_aio_result {
104105
#define MY_GIVE_INFO 2 /* Give time info about process*/
105106
#define MY_DONT_FREE_DBUG 4 /* Do not call DBUG_END() in my_end() */
106107

107-
#define ME_HIGHBYTE 8 /* Shift for colours */
108-
#define ME_NOCUR 1 /* Don't use curses message */
109-
#define ME_OLDWIN 2 /* Use old window */
110-
#define ME_BELL 4 /* Ring bell then printing message */
111-
#define ME_HOLDTANG 8 /* Don't delete last keys */
112-
#define ME_WAITTOT 16 /* Wait for errtime secs of for a action */
113-
#define ME_WAITTANG 32 /* Wait for a user action */
114-
#define ME_NOREFRESH 64 /* Write the error message to error log */
115-
#define ME_NOINPUT 128 /* Dont use the input libary */
116-
#define ME_COLOUR1 ((1 << ME_HIGHBYTE)) /* Possibly error-colours */
117-
#define ME_COLOUR2 ((2 << ME_HIGHBYTE))
118-
#define ME_COLOUR3 ((3 << ME_HIGHBYTE))
108+
#define ME_BELL 4 /* Ring bell then printing message */
109+
#define ME_WAITTANG 0 /* Wait for a user action */
110+
#define ME_NOREFRESH 64 /* Write the error message to error log */
111+
#define ME_NOINPUT 0 /* Dont use the input libary */
119112
#define ME_JUST_INFO 1024 /**< not error but just info */
120113
#define ME_JUST_WARNING 2048 /**< not error but just warning */
121114
#define ME_FATALERROR 4096 /* Fatal statement error */
@@ -715,12 +708,6 @@ extern int my_sync(File fd, myf my_flags);
715708
extern int my_sync_dir(const char *dir_name, myf my_flags);
716709
extern int my_sync_dir_by_file(const char *file_name, myf my_flags);
717710
extern const char *my_get_err_msg(uint nr);
718-
extern void my_error(uint nr,myf MyFlags, ...);
719-
extern void my_printf_error(uint my_err, const char *format,
720-
myf MyFlags, ...)
721-
ATTRIBUTE_FORMAT(printf, 2, 4);
722-
extern void my_printv_error(uint error, const char *format, myf MyFlags,
723-
va_list ap);
724711
extern int my_error_register(const char** (*get_errmsgs) (void),
725712
uint first, uint last);
726713
extern const char **my_error_unregister(uint first, uint last);

include/mysql/plugin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ typedef struct st_mysql_xid MYSQL_XID;
7575
#define MYSQL_PLUGIN_INTERFACE_VERSION 0x0104
7676

7777
/* MariaDB plugin interface version */
78-
#define MARIA_PLUGIN_INTERFACE_VERSION 0x010c
78+
#define MARIA_PLUGIN_INTERFACE_VERSION 0x010d
7979

8080
/*
8181
The allowable types of plugins

include/mysql/plugin_audit.h.pp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,43 @@
137137
void my_md5_init(void *context);
138138
void my_md5_input(void *context, const unsigned char *buf, size_t len);
139139
void my_md5_result(void *context, unsigned char *digest);
140+
enum my_aes_mode {
141+
MY_AES_ECB, MY_AES_CBC
142+
};
143+
extern struct my_crypt_service_st {
144+
int (*my_aes_crypt_init)(void *ctx, enum my_aes_mode mode, int flags,
145+
const unsigned char* key, unsigned int klen,
146+
const unsigned char* iv, unsigned int ivlen);
147+
int (*my_aes_crypt_update)(void *ctx, const unsigned char *src, unsigned int slen,
148+
unsigned char *dst, unsigned int *dlen);
149+
int (*my_aes_crypt_finish)(void *ctx, unsigned char *dst, unsigned int *dlen);
150+
int (*my_aes_crypt)(enum my_aes_mode mode, int flags,
151+
const unsigned char *src, unsigned int slen, unsigned char *dst, unsigned int *dlen,
152+
const unsigned char *key, unsigned int klen, const unsigned char *iv, unsigned int ivlen);
153+
unsigned int (*my_aes_get_size)(enum my_aes_mode mode, unsigned int source_length);
154+
unsigned int (*my_aes_ctx_size)(enum my_aes_mode mode);
155+
int (*my_random_bytes)(unsigned char* buf, int num);
156+
} *my_crypt_service;
157+
int my_aes_crypt_init(void *ctx, enum my_aes_mode mode, int flags,
158+
const unsigned char* key, unsigned int klen,
159+
const unsigned char* iv, unsigned int ivlen);
160+
int my_aes_crypt_update(void *ctx, const unsigned char *src, unsigned int slen,
161+
unsigned char *dst, unsigned int *dlen);
162+
int my_aes_crypt_finish(void *ctx, unsigned char *dst, unsigned int *dlen);
163+
int my_aes_crypt(enum my_aes_mode mode, int flags,
164+
const unsigned char *src, unsigned int slen, unsigned char *dst, unsigned int *dlen,
165+
const unsigned char *key, unsigned int klen, const unsigned char *iv, unsigned int ivlen);
166+
int my_random_bytes(unsigned char* buf, int num);
167+
unsigned int my_aes_get_size(enum my_aes_mode mode, unsigned int source_length);
168+
unsigned int my_aes_ctx_size(enum my_aes_mode mode);
169+
extern struct my_print_error_service_st {
170+
void(*my_error_func)(unsigned int nr, unsigned long MyFlags, ...);
171+
void(*my_printf_error_func)(unsigned int nr, const char *fmt, unsigned long MyFlags,...);
172+
void(*my_printv_error_func)(unsigned int error, const char *format, unsigned long MyFlags, va_list ap);
173+
} *my_print_error_service;
174+
extern void my_error(unsigned int nr, unsigned long MyFlags, ...);
175+
extern void my_printf_error(unsigned int my_err, const char *format, unsigned long MyFlags, ...);
176+
extern void my_printv_error(unsigned int error, const char *format, unsigned long MyFlags,va_list ap);
140177
extern struct my_snprintf_service_st {
141178
size_t (*my_snprintf_type)(char*, size_t, const char*, ...);
142179
size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list);

include/mysql/plugin_auth.h.pp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,43 @@
137137
void my_md5_init(void *context);
138138
void my_md5_input(void *context, const unsigned char *buf, size_t len);
139139
void my_md5_result(void *context, unsigned char *digest);
140+
enum my_aes_mode {
141+
MY_AES_ECB, MY_AES_CBC
142+
};
143+
extern struct my_crypt_service_st {
144+
int (*my_aes_crypt_init)(void *ctx, enum my_aes_mode mode, int flags,
145+
const unsigned char* key, unsigned int klen,
146+
const unsigned char* iv, unsigned int ivlen);
147+
int (*my_aes_crypt_update)(void *ctx, const unsigned char *src, unsigned int slen,
148+
unsigned char *dst, unsigned int *dlen);
149+
int (*my_aes_crypt_finish)(void *ctx, unsigned char *dst, unsigned int *dlen);
150+
int (*my_aes_crypt)(enum my_aes_mode mode, int flags,
151+
const unsigned char *src, unsigned int slen, unsigned char *dst, unsigned int *dlen,
152+
const unsigned char *key, unsigned int klen, const unsigned char *iv, unsigned int ivlen);
153+
unsigned int (*my_aes_get_size)(enum my_aes_mode mode, unsigned int source_length);
154+
unsigned int (*my_aes_ctx_size)(enum my_aes_mode mode);
155+
int (*my_random_bytes)(unsigned char* buf, int num);
156+
} *my_crypt_service;
157+
int my_aes_crypt_init(void *ctx, enum my_aes_mode mode, int flags,
158+
const unsigned char* key, unsigned int klen,
159+
const unsigned char* iv, unsigned int ivlen);
160+
int my_aes_crypt_update(void *ctx, const unsigned char *src, unsigned int slen,
161+
unsigned char *dst, unsigned int *dlen);
162+
int my_aes_crypt_finish(void *ctx, unsigned char *dst, unsigned int *dlen);
163+
int my_aes_crypt(enum my_aes_mode mode, int flags,
164+
const unsigned char *src, unsigned int slen, unsigned char *dst, unsigned int *dlen,
165+
const unsigned char *key, unsigned int klen, const unsigned char *iv, unsigned int ivlen);
166+
int my_random_bytes(unsigned char* buf, int num);
167+
unsigned int my_aes_get_size(enum my_aes_mode mode, unsigned int source_length);
168+
unsigned int my_aes_ctx_size(enum my_aes_mode mode);
169+
extern struct my_print_error_service_st {
170+
void(*my_error_func)(unsigned int nr, unsigned long MyFlags, ...);
171+
void(*my_printf_error_func)(unsigned int nr, const char *fmt, unsigned long MyFlags,...);
172+
void(*my_printv_error_func)(unsigned int error, const char *format, unsigned long MyFlags, va_list ap);
173+
} *my_print_error_service;
174+
extern void my_error(unsigned int nr, unsigned long MyFlags, ...);
175+
extern void my_printf_error(unsigned int my_err, const char *format, unsigned long MyFlags, ...);
176+
extern void my_printv_error(unsigned int error, const char *format, unsigned long MyFlags,va_list ap);
140177
extern struct my_snprintf_service_st {
141178
size_t (*my_snprintf_type)(char*, size_t, const char*, ...);
142179
size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list);

include/mysql/plugin_encryption.h.pp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,43 @@
137137
void my_md5_init(void *context);
138138
void my_md5_input(void *context, const unsigned char *buf, size_t len);
139139
void my_md5_result(void *context, unsigned char *digest);
140+
enum my_aes_mode {
141+
MY_AES_ECB, MY_AES_CBC
142+
};
143+
extern struct my_crypt_service_st {
144+
int (*my_aes_crypt_init)(void *ctx, enum my_aes_mode mode, int flags,
145+
const unsigned char* key, unsigned int klen,
146+
const unsigned char* iv, unsigned int ivlen);
147+
int (*my_aes_crypt_update)(void *ctx, const unsigned char *src, unsigned int slen,
148+
unsigned char *dst, unsigned int *dlen);
149+
int (*my_aes_crypt_finish)(void *ctx, unsigned char *dst, unsigned int *dlen);
150+
int (*my_aes_crypt)(enum my_aes_mode mode, int flags,
151+
const unsigned char *src, unsigned int slen, unsigned char *dst, unsigned int *dlen,
152+
const unsigned char *key, unsigned int klen, const unsigned char *iv, unsigned int ivlen);
153+
unsigned int (*my_aes_get_size)(enum my_aes_mode mode, unsigned int source_length);
154+
unsigned int (*my_aes_ctx_size)(enum my_aes_mode mode);
155+
int (*my_random_bytes)(unsigned char* buf, int num);
156+
} *my_crypt_service;
157+
int my_aes_crypt_init(void *ctx, enum my_aes_mode mode, int flags,
158+
const unsigned char* key, unsigned int klen,
159+
const unsigned char* iv, unsigned int ivlen);
160+
int my_aes_crypt_update(void *ctx, const unsigned char *src, unsigned int slen,
161+
unsigned char *dst, unsigned int *dlen);
162+
int my_aes_crypt_finish(void *ctx, unsigned char *dst, unsigned int *dlen);
163+
int my_aes_crypt(enum my_aes_mode mode, int flags,
164+
const unsigned char *src, unsigned int slen, unsigned char *dst, unsigned int *dlen,
165+
const unsigned char *key, unsigned int klen, const unsigned char *iv, unsigned int ivlen);
166+
int my_random_bytes(unsigned char* buf, int num);
167+
unsigned int my_aes_get_size(enum my_aes_mode mode, unsigned int source_length);
168+
unsigned int my_aes_ctx_size(enum my_aes_mode mode);
169+
extern struct my_print_error_service_st {
170+
void(*my_error_func)(unsigned int nr, unsigned long MyFlags, ...);
171+
void(*my_printf_error_func)(unsigned int nr, const char *fmt, unsigned long MyFlags,...);
172+
void(*my_printv_error_func)(unsigned int error, const char *format, unsigned long MyFlags, va_list ap);
173+
} *my_print_error_service;
174+
extern void my_error(unsigned int nr, unsigned long MyFlags, ...);
175+
extern void my_printf_error(unsigned int my_err, const char *format, unsigned long MyFlags, ...);
176+
extern void my_printv_error(unsigned int error, const char *format, unsigned long MyFlags,va_list ap);
140177
extern struct my_snprintf_service_st {
141178
size_t (*my_snprintf_type)(char*, size_t, const char*, ...);
142179
size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list);

include/mysql/plugin_ftparser.h.pp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,43 @@
137137
void my_md5_init(void *context);
138138
void my_md5_input(void *context, const unsigned char *buf, size_t len);
139139
void my_md5_result(void *context, unsigned char *digest);
140+
enum my_aes_mode {
141+
MY_AES_ECB, MY_AES_CBC
142+
};
143+
extern struct my_crypt_service_st {
144+
int (*my_aes_crypt_init)(void *ctx, enum my_aes_mode mode, int flags,
145+
const unsigned char* key, unsigned int klen,
146+
const unsigned char* iv, unsigned int ivlen);
147+
int (*my_aes_crypt_update)(void *ctx, const unsigned char *src, unsigned int slen,
148+
unsigned char *dst, unsigned int *dlen);
149+
int (*my_aes_crypt_finish)(void *ctx, unsigned char *dst, unsigned int *dlen);
150+
int (*my_aes_crypt)(enum my_aes_mode mode, int flags,
151+
const unsigned char *src, unsigned int slen, unsigned char *dst, unsigned int *dlen,
152+
const unsigned char *key, unsigned int klen, const unsigned char *iv, unsigned int ivlen);
153+
unsigned int (*my_aes_get_size)(enum my_aes_mode mode, unsigned int source_length);
154+
unsigned int (*my_aes_ctx_size)(enum my_aes_mode mode);
155+
int (*my_random_bytes)(unsigned char* buf, int num);
156+
} *my_crypt_service;
157+
int my_aes_crypt_init(void *ctx, enum my_aes_mode mode, int flags,
158+
const unsigned char* key, unsigned int klen,
159+
const unsigned char* iv, unsigned int ivlen);
160+
int my_aes_crypt_update(void *ctx, const unsigned char *src, unsigned int slen,
161+
unsigned char *dst, unsigned int *dlen);
162+
int my_aes_crypt_finish(void *ctx, unsigned char *dst, unsigned int *dlen);
163+
int my_aes_crypt(enum my_aes_mode mode, int flags,
164+
const unsigned char *src, unsigned int slen, unsigned char *dst, unsigned int *dlen,
165+
const unsigned char *key, unsigned int klen, const unsigned char *iv, unsigned int ivlen);
166+
int my_random_bytes(unsigned char* buf, int num);
167+
unsigned int my_aes_get_size(enum my_aes_mode mode, unsigned int source_length);
168+
unsigned int my_aes_ctx_size(enum my_aes_mode mode);
169+
extern struct my_print_error_service_st {
170+
void(*my_error_func)(unsigned int nr, unsigned long MyFlags, ...);
171+
void(*my_printf_error_func)(unsigned int nr, const char *fmt, unsigned long MyFlags,...);
172+
void(*my_printv_error_func)(unsigned int error, const char *format, unsigned long MyFlags, va_list ap);
173+
} *my_print_error_service;
174+
extern void my_error(unsigned int nr, unsigned long MyFlags, ...);
175+
extern void my_printf_error(unsigned int my_err, const char *format, unsigned long MyFlags, ...);
176+
extern void my_printv_error(unsigned int error, const char *format, unsigned long MyFlags,va_list ap);
140177
extern struct my_snprintf_service_st {
141178
size_t (*my_snprintf_type)(char*, size_t, const char*, ...);
142179
size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list);

include/mysql/plugin_password_validation.h.pp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,43 @@
137137
void my_md5_init(void *context);
138138
void my_md5_input(void *context, const unsigned char *buf, size_t len);
139139
void my_md5_result(void *context, unsigned char *digest);
140+
enum my_aes_mode {
141+
MY_AES_ECB, MY_AES_CBC
142+
};
143+
extern struct my_crypt_service_st {
144+
int (*my_aes_crypt_init)(void *ctx, enum my_aes_mode mode, int flags,
145+
const unsigned char* key, unsigned int klen,
146+
const unsigned char* iv, unsigned int ivlen);
147+
int (*my_aes_crypt_update)(void *ctx, const unsigned char *src, unsigned int slen,
148+
unsigned char *dst, unsigned int *dlen);
149+
int (*my_aes_crypt_finish)(void *ctx, unsigned char *dst, unsigned int *dlen);
150+
int (*my_aes_crypt)(enum my_aes_mode mode, int flags,
151+
const unsigned char *src, unsigned int slen, unsigned char *dst, unsigned int *dlen,
152+
const unsigned char *key, unsigned int klen, const unsigned char *iv, unsigned int ivlen);
153+
unsigned int (*my_aes_get_size)(enum my_aes_mode mode, unsigned int source_length);
154+
unsigned int (*my_aes_ctx_size)(enum my_aes_mode mode);
155+
int (*my_random_bytes)(unsigned char* buf, int num);
156+
} *my_crypt_service;
157+
int my_aes_crypt_init(void *ctx, enum my_aes_mode mode, int flags,
158+
const unsigned char* key, unsigned int klen,
159+
const unsigned char* iv, unsigned int ivlen);
160+
int my_aes_crypt_update(void *ctx, const unsigned char *src, unsigned int slen,
161+
unsigned char *dst, unsigned int *dlen);
162+
int my_aes_crypt_finish(void *ctx, unsigned char *dst, unsigned int *dlen);
163+
int my_aes_crypt(enum my_aes_mode mode, int flags,
164+
const unsigned char *src, unsigned int slen, unsigned char *dst, unsigned int *dlen,
165+
const unsigned char *key, unsigned int klen, const unsigned char *iv, unsigned int ivlen);
166+
int my_random_bytes(unsigned char* buf, int num);
167+
unsigned int my_aes_get_size(enum my_aes_mode mode, unsigned int source_length);
168+
unsigned int my_aes_ctx_size(enum my_aes_mode mode);
169+
extern struct my_print_error_service_st {
170+
void(*my_error_func)(unsigned int nr, unsigned long MyFlags, ...);
171+
void(*my_printf_error_func)(unsigned int nr, const char *fmt, unsigned long MyFlags,...);
172+
void(*my_printv_error_func)(unsigned int error, const char *format, unsigned long MyFlags, va_list ap);
173+
} *my_print_error_service;
174+
extern void my_error(unsigned int nr, unsigned long MyFlags, ...);
175+
extern void my_printf_error(unsigned int my_err, const char *format, unsigned long MyFlags, ...);
176+
extern void my_printv_error(unsigned int error, const char *format, unsigned long MyFlags,va_list ap);
140177
extern struct my_snprintf_service_st {
141178
size_t (*my_snprintf_type)(char*, size_t, const char*, ...);
142179
size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list);

0 commit comments

Comments
 (0)