diff options
Diffstat (limited to 'include')
73 files changed, 4219 insertions, 1012 deletions
diff --git a/include/atomic/nolock.h b/include/atomic/nolock.h index 56f37644f96..2137445a075 100644 --- a/include/atomic/nolock.h +++ b/include/atomic/nolock.h @@ -51,19 +51,4 @@ # endif #endif -#if defined(make_atomic_cas_body) -/* - Type not used so minimal size (emptry struct has different size between C - and C++, zero-length array is gcc-specific). -*/ -typedef char my_atomic_rwlock_t __attribute__ ((unused)); -#define my_atomic_rwlock_destroy(name) -#define my_atomic_rwlock_init(name) -#define my_atomic_rwlock_rdlock(name) -#define my_atomic_rwlock_wrlock(name) -#define my_atomic_rwlock_rdunlock(name) -#define my_atomic_rwlock_wrunlock(name) - -#endif - #endif /* ATOMIC_NOLOCK_INCLUDED */ diff --git a/include/atomic/rwlock.h b/include/atomic/rwlock.h deleted file mode 100644 index 2ffdd384cc5..00000000000 --- a/include/atomic/rwlock.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef ATOMIC_RWLOCK_INCLUDED -#define ATOMIC_RWLOCK_INCLUDED - -/* Copyright (c) 2006 MySQL AB, 2009 Sun Microsystems, Inc. - Use is subject to license terms. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; version 2 of the License. - - 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 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 */ - -#define MY_ATOMIC_MODE_RWLOCKS 1 - -#ifdef MY_ATOMIC_MODE_DUMMY -/* - the following can never be enabled by ./configure, one need to put #define in - a source to trigger the following warning. The resulting code will be broken, - it only makes sense to do it to see now test_atomic detects broken - implementations (another way is to run a UP build on an SMP box). -*/ -#warning MY_ATOMIC_MODE_DUMMY and MY_ATOMIC_MODE_RWLOCKS are incompatible - -typedef char my_atomic_rwlock_t; - -#define my_atomic_rwlock_destroy(name) -#define my_atomic_rwlock_init(name) -#define my_atomic_rwlock_rdlock(name) -#define my_atomic_rwlock_wrlock(name) -#define my_atomic_rwlock_rdunlock(name) -#define my_atomic_rwlock_wrunlock(name) -#define MY_ATOMIC_MODE "dummy (non-atomic)" -#else /* not MY_ATOMIC_MODE_DUMMY */ - -typedef struct {pthread_mutex_t rw;} my_atomic_rwlock_t; - -#define my_atomic_rwlock_destroy(name) pthread_mutex_destroy(& (name)->rw) -#define my_atomic_rwlock_init(name) pthread_mutex_init(& (name)->rw, 0) -#define my_atomic_rwlock_rdlock(name) pthread_mutex_lock(& (name)->rw) -#define my_atomic_rwlock_wrlock(name) pthread_mutex_lock(& (name)->rw) -#define my_atomic_rwlock_rdunlock(name) pthread_mutex_unlock(& (name)->rw) -#define my_atomic_rwlock_wrunlock(name) pthread_mutex_unlock(& (name)->rw) - -#define MY_ATOMIC_MODE "mutex" -#ifndef MY_ATOMIC_MODE_RWLOCKS -#define MY_ATOMIC_MODE_RWLOCKS 1 -#endif -#endif - -#define make_atomic_add_body(S) int ## S sav; sav= *a; *a+= v; v=sav; -#define make_atomic_fas_body(S) int ## S sav; sav= *a; *a= v; v=sav; -#define make_atomic_cas_body(S) if ((ret= (*a == *cmp))) *a= set; else *cmp=*a; -#define make_atomic_load_body(S) ret= *a; -#define make_atomic_store_body(S) *a= v; - -#endif /* ATOMIC_RWLOCK_INCLUDED */ diff --git a/include/base64.h b/include/base64.h deleted file mode 100644 index 9a843b5088e..00000000000 --- a/include/base64.h +++ /dev/null @@ -1,62 +0,0 @@ -/* Copyright (c) 2003-2006 MySQL AB - Use is subject to license terms - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; version 2 of the License. - - 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 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 Street, Fifth Floor, Boston, MA 02110-1301, USA */ - -#ifndef __BASE64_H_INCLUDED__ -#define __BASE64_H_INCLUDED__ - -#ifdef __cplusplus -extern "C" { -#endif - -/* - Calculate how much memory needed for dst of base64_encode() -*/ -int base64_needed_encoded_length(int length_of_data); - -/* - Maximum length base64_encode_needed_length() can accept with no overflow. -*/ -int base64_encode_max_arg_length(void); - -/* - Calculate how much memory needed for dst of base64_decode() -*/ -int base64_needed_decoded_length(int length_of_encoded_data); - -/* - Maximum length base64_decode_needed_length() can accept with no overflow. -*/ -int base64_decode_max_arg_length(); - -/* - Encode data as a base64 string -*/ -int base64_encode(const void *src, size_t src_len, char *dst); - -/* - Decode a base64 string into data -*/ -int base64_decode(const char *src, size_t src_len, - void *dst, const char **end_ptr, int flags); - -/* Allow multuple chunks 'AAA= AA== AA==', binlog uses this */ -#define MY_BASE64_DECODE_ALLOW_MULTIPLE_CHUNKS 1 - - -#ifdef __cplusplus -} -#endif -#endif /* !__BASE64_H_INCLUDED__ */ diff --git a/include/lf.h b/include/lf.h index 21cf65941ff..19bdafce647 100644 --- a/include/lf.h +++ b/include/lf.h @@ -13,53 +13,14 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef _lf_h -#define _lf_h +#ifndef INCLUDE_LF_INCLUDED +#define INCLUDE_LF_INCLUDED #include <my_atomic.h> C_MODE_START /* - Helpers to define both func() and _func(), where - func() is a _func() protected by my_atomic_rwlock_wrlock() -*/ - -#define lock_wrap(f, t, proto_args, args, lock) \ -t _ ## f proto_args; \ -static inline t f proto_args \ -{ \ - t ret; \ - my_atomic_rwlock_wrlock(lock); \ - ret= _ ## f args; \ - my_atomic_rwlock_wrunlock(lock); \ - return ret; \ -} - -#define lock_wrap_void(f, proto_args, args, lock) \ -void _ ## f proto_args; \ -static inline void f proto_args \ -{ \ - my_atomic_rwlock_wrlock(lock); \ - _ ## f args; \ - my_atomic_rwlock_wrunlock(lock); \ -} - -#define nolock_wrap(f, t, proto_args, args) \ -t _ ## f proto_args; \ -static inline t f proto_args \ -{ \ - return _ ## f args; \ -} - -#define nolock_wrap_void(f, proto_args, args) \ -void _ ## f proto_args; \ -static inline void f proto_args \ -{ \ - _ ## f args; \ -} - -/* wait-free dynamic array, see lf_dynarray.c 4 levels of 256 elements each mean 4311810304 elements in an array - it @@ -71,7 +32,6 @@ static inline void f proto_args \ typedef struct { void * volatile level[LF_DYNARRAY_LEVELS]; uint size_of_element; - my_atomic_rwlock_t lock; } LF_DYNARRAY; typedef int (*lf_dynarray_func)(void *, void *); @@ -79,16 +39,9 @@ typedef int (*lf_dynarray_func)(void *, void *); void lf_dynarray_init(LF_DYNARRAY *array, uint element_size); void lf_dynarray_destroy(LF_DYNARRAY *array); -nolock_wrap(lf_dynarray_value, void *, - (LF_DYNARRAY *array, uint idx), - (array, idx)) -lock_wrap(lf_dynarray_lvalue, void *, - (LF_DYNARRAY *array, uint idx), - (array, idx), - &array->lock) -nolock_wrap(lf_dynarray_iterate, int, - (LF_DYNARRAY *array, lf_dynarray_func func, void *arg), - (array, func, arg)) +void *lf_dynarray_value(LF_DYNARRAY *array, uint idx); +void *lf_dynarray_lvalue(LF_DYNARRAY *array, uint idx); +int lf_dynarray_iterate(LF_DYNARRAY *array, lf_dynarray_func func, void *arg); /* pin manager for memory allocator, lf_alloc-pin.c @@ -122,49 +75,24 @@ typedef struct { -sizeof(void *)*(LF_PINBOX_PINS+1)]; } LF_PINS; -/* - shortcut macros to do an atomic_wrlock on a structure that uses pins - (e.g. lf_hash). -*/ -#define lf_rwlock_by_pins(PINS) \ - my_atomic_rwlock_wrlock(&(PINS)->pinbox->pinarray.lock) -#define lf_rwunlock_by_pins(PINS) \ - my_atomic_rwlock_wrunlock(&(PINS)->pinbox->pinarray.lock) - /* compile-time assert to make sure we have enough pins. */ -#define _lf_pin(PINS, PIN, ADDR) \ +#define lf_pin(PINS, PIN, ADDR) \ do { \ compile_time_assert(PIN < LF_PINBOX_PINS); \ my_atomic_storeptr(&(PINS)->pin[PIN], (ADDR)); \ } while(0) -#define _lf_unpin(PINS, PIN) _lf_pin(PINS, PIN, NULL) -#define lf_pin(PINS, PIN, ADDR) \ - do { \ - lf_rwlock_by_pins(PINS); \ - _lf_pin(PINS, PIN, ADDR); \ - lf_rwunlock_by_pins(PINS); \ - } while (0) -#define lf_unpin(PINS, PIN) lf_pin(PINS, PIN, NULL) -#define _lf_assert_pin(PINS, PIN) assert((PINS)->pin[PIN] != 0) -#define _lf_assert_unpin(PINS, PIN) assert((PINS)->pin[PIN] == 0) +#define lf_unpin(PINS, PIN) lf_pin(PINS, PIN, NULL) +#define lf_assert_pin(PINS, PIN) assert((PINS)->pin[PIN] != 0) +#define lf_assert_unpin(PINS, PIN) assert((PINS)->pin[PIN] == 0) void lf_pinbox_init(LF_PINBOX *pinbox, uint free_ptr_offset, lf_pinbox_free_func *free_func, void * free_func_arg); void lf_pinbox_destroy(LF_PINBOX *pinbox); -lock_wrap(lf_pinbox_get_pins, LF_PINS *, - (LF_PINBOX *pinbox), - (pinbox), - &pinbox->pinarray.lock) -lock_wrap_void(lf_pinbox_put_pins, - (LF_PINS *pins), - (pins), - &pins->pinbox->pinarray.lock) -lock_wrap_void(lf_pinbox_free, - (LF_PINS *pins, void *addr), - (pins, addr), - &pins->pinbox->pinarray.lock) +LF_PINS *lf_pinbox_get_pins(LF_PINBOX *pinbox); +void lf_pinbox_put_pins(LF_PINS *pins); +void lf_pinbox_free(LF_PINS *pins, void *addr); /* memory allocator, lf_alloc-pin.c @@ -184,20 +112,19 @@ void lf_alloc_destroy(LF_ALLOCATOR *allocator); uint lf_alloc_pool_count(LF_ALLOCATOR *allocator); /* shortcut macros to access underlying pinbox functions from an LF_ALLOCATOR - see _lf_pinbox_get_pins() and _lf_pinbox_put_pins() + see lf_pinbox_get_pins() and lf_pinbox_put_pins() */ -#define _lf_alloc_free(PINS, PTR) _lf_pinbox_free((PINS), (PTR)) #define lf_alloc_free(PINS, PTR) lf_pinbox_free((PINS), (PTR)) -#define _lf_alloc_get_pins(A) _lf_pinbox_get_pins(&(A)->pinbox) #define lf_alloc_get_pins(A) lf_pinbox_get_pins(&(A)->pinbox) -#define _lf_alloc_put_pins(PINS) _lf_pinbox_put_pins(PINS) #define lf_alloc_put_pins(PINS) lf_pinbox_put_pins(PINS) -#define lf_alloc_direct_free(ALLOC, ADDR) my_free((ADDR)) +#define lf_alloc_direct_free(ALLOC, ADDR) \ + do { \ + if ((ALLOC)->destructor) \ + (ALLOC)->destructor((uchar*) ADDR); \ + my_free(ADDR); \ + } while(0) -lock_wrap(lf_alloc_new, void *, - (LF_PINS *pins), - (pins), - &pins->pinbox->pinarray.lock) +void *lf_alloc_new(LF_PINS *pins); C_MODE_END @@ -208,22 +135,27 @@ C_MODE_END C_MODE_START +typedef struct st_lf_hash LF_HASH; +typedef void (*lf_hash_initializer)(LF_HASH *hash, void *dst, const void *src); + #define LF_HASH_UNIQUE 1 /* lf_hash overhead per element (that is, sizeof(LF_SLIST) */ extern const int LF_HASH_OVERHEAD; -typedef struct { +struct st_lf_hash { LF_DYNARRAY array; /* hash itself */ LF_ALLOCATOR alloc; /* allocator for elements */ my_hash_get_key get_key; /* see HASH */ + lf_hash_initializer initializer; /* called when an element is inserted */ + my_hash_function hash_function; /* see HASH */ CHARSET_INFO *charset; /* see HASH */ uint key_offset, key_length; /* see HASH */ uint element_size; /* size of memcpy'ed area on insert */ uint flags; /* LF_HASH_UNIQUE, etc */ int32 volatile size; /* size of array */ int32 volatile count; /* number of elements in the hash */ -} LF_HASH; +}; void lf_hash_init(LF_HASH *hash, uint element_size, uint flags, uint key_offset, uint key_length, my_hash_get_key get_key, @@ -231,25 +163,23 @@ void lf_hash_init(LF_HASH *hash, uint element_size, uint flags, void lf_hash_destroy(LF_HASH *hash); int lf_hash_insert(LF_HASH *hash, LF_PINS *pins, const void *data); void *lf_hash_search(LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen); +void *lf_hash_search_using_hash_value(LF_HASH *hash, LF_PINS *pins, + my_hash_value_type hash_value, + const void *key, uint keylen); int lf_hash_delete(LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen); +int lf_hash_iterate(LF_HASH *hash, LF_PINS *pins, + my_hash_walk_action action, void *argument); /* shortcut macros to access underlying pinbox functions from an LF_HASH - see _lf_pinbox_get_pins() and _lf_pinbox_put_pins() + see lf_pinbox_get_pins() and lf_pinbox_put_pins() */ -#define _lf_hash_get_pins(HASH) _lf_alloc_get_pins(&(HASH)->alloc) #define lf_hash_get_pins(HASH) lf_alloc_get_pins(&(HASH)->alloc) -#define _lf_hash_put_pins(PINS) _lf_pinbox_put_pins(PINS) #define lf_hash_put_pins(PINS) lf_pinbox_put_pins(PINS) #define lf_hash_search_unpin(PINS) lf_unpin((PINS), 2) /* cleanup */ -#undef lock_wrap_void -#undef lock_wrap -#undef nolock_wrap_void -#undef nolock_wrap - C_MODE_END #endif diff --git a/include/m_ctype.h b/include/m_ctype.h index eb2d760359b..74dd2a29984 100644 --- a/include/m_ctype.h +++ b/include/m_ctype.h @@ -101,7 +101,7 @@ extern MY_UNICASE_INFO my_unicase_unicode520; */ #define MY_UCA_MAX_WEIGHT_SIZE (8+1) /* Including 0 terminator */ #define MY_UCA_CONTRACTION_MAX_WEIGHT_SIZE (2*8+1) /* Including 0 terminator */ -#define MY_UCA_WEIGHT_LEVELS 1 +#define MY_UCA_WEIGHT_LEVELS 2 typedef struct my_contraction_t { @@ -131,6 +131,7 @@ typedef struct my_uca_level_info_st uchar *lengths; uint16 **weights; MY_CONTRACTIONS contractions; + uint levelno; } MY_UCA_WEIGHT_LEVEL; @@ -204,6 +205,10 @@ extern MY_UNI_CTYPE my_uni_ctype[256]; #define MY_CS_UNICODE_SUPPLEMENT 16384 /* Non-BMP Unicode characters */ #define MY_CS_LOWER_SORT 32768 /* If use lower case as weight */ #define MY_CS_STRNXFRM_BAD_NWEIGHTS 0x10000 /* strnxfrm ignores "nweights" */ +#define MY_CS_NOPAD 0x20000 /* if does not ignore trailing spaces */ +#define MY_CS_NON1TO1 0x40000 /* Has a complex mapping from characters + to weights, e.g. contractions, expansions, + ignorable characters */ #define MY_CHARSET_UNDEFINED 0 /* Character repertoire flags */ @@ -354,7 +359,6 @@ struct my_collation_handler_st my_bool (*propagate)(CHARSET_INFO *cs, const uchar *str, size_t len); }; -extern MY_COLLATION_HANDLER my_collation_mb_bin_handler; extern MY_COLLATION_HANDLER my_collation_8bit_bin_handler; extern MY_COLLATION_HANDLER my_collation_8bit_simple_ci_handler; extern MY_COLLATION_HANDLER my_collation_ucs2_uca_handler; @@ -367,6 +371,33 @@ typedef int (*my_charset_conv_wc_mb)(CHARSET_INFO *, my_wc_t, typedef size_t (*my_charset_conv_case)(CHARSET_INFO *, const char *, size_t, char *, size_t); +/* + A structure to return the statistics of a native string copying, + when no Unicode conversion is involved. + + The stucture is OK to be unitialized before calling a copying routine. + A copying routine must populate the structure as follows: + - m_source_end_pos must be set by to a non-NULL value + in the range of the input string. + - m_well_formed_error_pos must be set to NULL if the string was + well formed, or to the position of the leftmost bad byte sequence. +*/ +typedef struct +{ + const char *m_source_end_pos; /* Position where reading stopped */ + const char *m_well_formed_error_pos; /* Position where a bad byte was found*/ +} MY_STRCOPY_STATUS; + + +/* + A structure to return the statistics of a Unicode string conversion. +*/ +typedef struct +{ + MY_STRCOPY_STATUS m_native_copy_status; + const char *m_cannot_convert_error_pos; +} MY_STRCONV_STATUS; + /* See strings/CHARSET_INFO.txt about information on this structure */ struct my_charset_handler_st @@ -429,10 +460,84 @@ struct my_charset_handler_st char **endptr, int *error); size_t (*scan)(CHARSET_INFO *, const char *b, const char *e, int sq); + + /* String copying routines and helpers for them */ + /* + charlen() - calculate length of the left-most character in bytes. + @param cs Character set + @param str The beginning of the string + @param end The end of the string + + @return MY_CS_ILSEQ if a bad byte sequence was found. + @return MY_CS_TOOSMALLN(x) if the string ended unexpectedly. + @return a positive number in the range 1..mbmaxlen, + if a valid character was found. + */ + int (*charlen)(CHARSET_INFO *cs, const uchar *str, const uchar *end); + /* + well_formed_char_length() - returns character length of a string. + + @param cs Character set + @param str The beginning of the string + @param end The end of the string + @param nchars Not more than "nchars" left-most characters are checked. + @param status[OUT] Additional statistics is returned here. + "status" can be uninitialized before the call, + and it is fully initialized after the call. + + status->m_source_end_pos is set to the position where reading stopped. + + If a bad byte sequence is found, the function returns immediately and + status->m_well_formed_error_pos is set to the position where a bad byte + sequence was found. + + status->m_well_formed_error_pos is set to NULL if no bad bytes were found. + If status->m_well_formed_error_pos is NULL after the call, that means: + - either the function reached the end of the string, + - or all "nchars" characters were read. + The caller can check status->m_source_end_pos to detect which of these two + happened. + */ + size_t (*well_formed_char_length)(CHARSET_INFO *cs, + const char *str, const char *end, + size_t nchars, + MY_STRCOPY_STATUS *status); + + /* + copy_fix() - copy a string, replace bad bytes to '?'. + Not more than "nchars" characters are copied. + + status->m_source_end_pos is set to a position in the range + between "src" and "src + src_length", where reading stopped. + + status->m_well_formed_error_pos is set to NULL if the string + in the range "src" and "status->m_source_end_pos" was well formed, + or is set to a position between "src" and "src + src_length" where + the leftmost bad byte sequence was found. + */ + size_t (*copy_fix)(CHARSET_INFO *, + char *dst, size_t dst_length, + const char *src, size_t src_length, + size_t nchars, MY_STRCOPY_STATUS *status); + /** + Write a character to the target string, using its native code. + For Unicode character sets (utf8, ucs2, utf16, utf16le, utf32, filename) + native codes are equvalent to Unicode code points. + For 8bit character sets the native code is just the byte value. + For Asian characters sets: + - MB1 native code is just the byte value (e.g. on the ASCII range) + - MB2 native code is ((b0 << 8) + b1). + - MB3 native code is ((b0 <<16) + (b1 << 8) + b2) + Note, CHARSET_INFO::min_sort_char and CHARSET_INFO::max_sort_char + are defined in native notation and should be written using + cs->cset->native_to_mb() rather than cs->cset->wc_mb(). + */ + my_charset_conv_wc_mb native_to_mb; }; extern MY_CHARSET_HANDLER my_charset_8bit_handler; extern MY_CHARSET_HANDLER my_charset_ucs2_handler; +extern MY_CHARSET_HANDLER my_charset_utf8_handler; /* @@ -561,6 +666,14 @@ extern uint my_instr_simple(CHARSET_INFO *, const char *s, size_t s_length, my_match_t *match, uint nmatch); +size_t my_copy_8bit(CHARSET_INFO *, + char *dst, size_t dst_length, + const char *src, size_t src_length, + size_t nchars, MY_STRCOPY_STATUS *); +size_t my_copy_fix_mb(CHARSET_INFO *cs, + char *dst, size_t dst_length, + const char *src, size_t src_length, + size_t nchars, MY_STRCOPY_STATUS *); /* Functions for 8bit */ extern size_t my_caseup_str_8bit(CHARSET_INFO *, char *); @@ -576,6 +689,7 @@ extern int my_strcasecmp_8bit(CHARSET_INFO * cs, const char *, const char *); int my_mb_wc_8bit(CHARSET_INFO *cs,my_wc_t *wc, const uchar *s,const uchar *e); int my_wc_mb_8bit(CHARSET_INFO *cs,my_wc_t wc, uchar *s, uchar *e); +int my_wc_mb_bin(CHARSET_INFO *cs,my_wc_t wc, uchar *s, uchar *e); int my_mb_ctype_8bit(CHARSET_INFO *,int *, const uchar *,const uchar *); int my_mb_ctype_mb(CHARSET_INFO *,int *, const uchar *,const uchar *); @@ -654,6 +768,11 @@ size_t my_numcells_8bit(CHARSET_INFO *, const char *b, const char *e); size_t my_charpos_8bit(CHARSET_INFO *, const char *b, const char *e, size_t pos); size_t my_well_formed_len_8bit(CHARSET_INFO *, const char *b, const char *e, size_t pos, int *error); +size_t my_well_formed_char_length_8bit(CHARSET_INFO *cs, + const char *b, const char *e, + size_t nchars, + MY_STRCOPY_STATUS *status); +int my_charlen_8bit(CHARSET_INFO *, const uchar *str, const uchar *end); uint my_mbcharlen_8bit(CHARSET_INFO *, uint c); @@ -768,10 +887,54 @@ const MY_CONTRACTIONS *my_charset_get_contractions(CHARSET_INFO *cs, extern size_t my_vsnprintf_ex(CHARSET_INFO *cs, char *to, size_t n, const char* fmt, va_list ap); +/* + Convert a string between two character sets. + Bad byte sequences as well as characters that cannot be + encoded in the destination character set are replaced to '?'. +*/ uint32 my_convert(char *to, uint32 to_length, CHARSET_INFO *to_cs, const char *from, uint32 from_length, CHARSET_INFO *from_cs, uint *errors); +/** + An extended version of my_convert(), to pass non-default mb_wc() and wc_mb(). + For example, String::copy_printable() which is used in + Protocol::store_warning() uses this to escape control + and non-convertable characters. +*/ +uint32 my_convert_using_func(char *to, uint32 to_length, CHARSET_INFO *to_cs, + my_charset_conv_wc_mb mb_wc, + const char *from, uint32 from_length, + CHARSET_INFO *from_cs, + my_charset_conv_mb_wc wc_mb, + uint *errors); +/* + Convert a string between two character sets. + Bad byte sequences as well as characters that cannot be + encoded in the destination character set are replaced to '?'. + Not more than "nchars" characters are copied. + Conversion statistics is returnd in "status" and is set as follows: + - status->m_native_copy_status.m_source_end_pos - to the position + between (src) and (src+src_length), where the function stopped reading + the source string. + - status->m_native_copy_status.m_well_formed_error_pos - to the position + between (src) and (src+src_length), where the first badly formed byte + sequence was found, or to NULL if the string was well formed in the + given range. + - status->m_cannot_convert_error_pos - to the position + between (src) and (src+src_length), where the first character that + cannot be represented in the destination character set was found, + or to NULL if all characters in the given range were successfully + converted. + + "src" is allowed to be a NULL pointer. In this case "src_length" must + be equal to 0. All "status" members are initialized to NULL, and 0 is + returned. +*/ +size_t my_convert_fix(CHARSET_INFO *dstcs, char *dst, size_t dst_length, + CHARSET_INFO *srccs, const char *src, size_t src_length, + size_t nchars, MY_STRCONV_STATUS *status); + #define _MY_U 01 /* Upper case */ #define _MY_L 02 /* Lower case */ #define _MY_NMR 04 /* Numeral (digit) */ diff --git a/include/m_string.h b/include/m_string.h index 188802bc08b..d088b510de5 100644 --- a/include/m_string.h +++ b/include/m_string.h @@ -64,20 +64,13 @@ extern "C" { #endif -/* - my_str_malloc(), my_str_realloc() and my_str_free() are assigned to - implementations in strings/alloc.c, but can be overridden in - the calling program. - */ -extern void *(*my_str_malloc)(size_t); -extern void *(*my_str_realloc)(void *, size_t); -extern void (*my_str_free)(void *); - +#ifdef DBUG_OFF #if defined(HAVE_STPCPY) && MY_GNUC_PREREQ(3, 4) && !defined(__INTEL_COMPILER) #define strmov(A,B) __builtin_stpcpy((A),(B)) #elif defined(HAVE_STPCPY) #define strmov(A,B) stpcpy((A),(B)) #endif +#endif /* Declared in int2str() */ extern const char _dig_vec_upper[]; @@ -231,4 +224,15 @@ static inline void lex_string_set(LEX_STRING *lex_str, const char *c_str) lex_str->length= strlen(c_str); } +#ifdef __cplusplus +static inline char *safe_str(char *str) +{ return str ? str : const_cast<char*>(""); } +#endif + +static inline const char *safe_str(const char *str) +{ return str ? str : ""; } + +static inline size_t safe_strlen(const char *str) +{ return str ? strlen(str) : 0; } + #endif diff --git a/include/maria.h b/include/maria.h index cdaeadef4de..ab8fc944c8c 100644 --- a/include/maria.h +++ b/include/maria.h @@ -13,21 +13,22 @@ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ /* This file should be included when using maria functions */ #ifndef _maria_h #define _maria_h -#ifdef __cplusplus -extern "C" { -#endif #include <my_base.h> #include <m_ctype.h> #include "my_compare.h" #include "ft_global.h" #include <myisamchk.h> +#ifdef __cplusplus +extern "C" { +#endif + #define MARIA_CANNOT_ROLLBACK /* @@ -148,7 +149,7 @@ typedef struct st_maria_create_info uint null_bytes; uint old_options; enum data_file_type org_data_file_type; - uint8 language; + uint16 language; my_bool with_auto_increment, transactional; } MARIA_CREATE_INFO; @@ -267,6 +268,8 @@ extern my_bool maria_delay_key_write; extern my_off_t maria_max_temp_length; extern ulong maria_bulk_insert_tree_size, maria_data_pointer_size; extern MY_TMPDIR *maria_tmpdir; +extern my_bool maria_encrypt_tables; + /* This is used to check if a symlink points into the mysql data home, which is normally forbidden as it can be used to get access to diff --git a/include/my_aes.h b/include/my_aes.h deleted file mode 100644 index 58a78919023..00000000000 --- a/include/my_aes.h +++ /dev/null @@ -1,71 +0,0 @@ -#ifndef MY_AES_INCLUDED -#define MY_AES_INCLUDED - -/* Copyright (c) 2002, 2006 MySQL AB, 2009 Sun Microsystems, Inc. - Use is subject to license terms. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; version 2 of the License. - - 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 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 */ - - -/* Header file for my_aes.c */ -/* Wrapper to give simple interface for MySQL to AES standard encryption */ - -#include "rijndael.h" - -C_MODE_START - -#define AES_KEY_LENGTH 128 /* Must be 128 192 or 256 */ - -/* - my_aes_encrypt - Crypt buffer with AES encryption algorithm. - source - Pointer to data for encryption - source_length - size of encryption data - dest - buffer to place encrypted data (must be large enough) - key - Key to be used for encryption - kel_length - Length of the key. Will handle keys of any length - - returns - size of encrypted data, or negative in case of error. -*/ - -int my_aes_encrypt(const char *source, int source_length, char *dest, - const char *key, int key_length); - -/* - my_aes_decrypt - DeCrypt buffer with AES encryption algorithm. - source - Pointer to data for decryption - source_length - size of encrypted data - dest - buffer to place decrypted data (must be large enough) - key - Key to be used for decryption - kel_length - Length of the key. Will handle keys of any length - - returns - size of original data, or negative in case of error. -*/ - - -int my_aes_decrypt(const char *source, int source_length, char *dest, - const char *key, int key_length); - -/* - my_aes_get_size - get size of buffer which will be large enough for encrypted - data - source_length - length of data to be encrypted - - returns - size of buffer required to store encrypted data -*/ - -int my_aes_get_size(int source_length); - -C_MODE_END - -#endif /* MY_AES_INCLUDED */ diff --git a/include/my_atomic.h b/include/my_atomic.h index 7c589cd776a..855b781dfe3 100644 --- a/include/my_atomic.h +++ b/include/my_atomic.h @@ -20,41 +20,90 @@ This header defines five atomic operations: my_atomic_add#(&var, what) + my_atomic_add#_explicit(&var, what, memory_order) 'Fetch and Add' add 'what' to *var, and return the old value of *var + All memory orders are valid. my_atomic_fas#(&var, what) + my_atomic_fas#_explicit(&var, what, memory_order) 'Fetch And Store' store 'what' in *var, and return the old value of *var + All memory orders are valid. my_atomic_cas#(&var, &old, new) + my_atomic_cas#_weak_explicit(&var, &old, new, succ, fail) + my_atomic_cas#_strong_explicit(&var, &old, new, succ, fail) 'Compare And Swap' if *var is equal to *old, then store 'new' in *var, and return TRUE otherwise store *var in *old, and return FALSE + succ - the memory synchronization ordering for the read-modify-write + operation if the comparison succeeds. All memory orders are valid. + fail - the memory synchronization ordering for the load operation if the + comparison fails. Cannot be MY_MEMORY_ORDER_RELEASE or + MY_MEMORY_ORDER_ACQ_REL and cannot specify stronger ordering than succ. + + The weak form is allowed to fail spuriously, that is, act as if *var != *old + even if they are equal. When a compare-and-exchange is in a loop, the weak + version will yield better performance on some platforms. When a weak + compare-and-exchange would require a loop and a strong one would not, the + strong one is preferable. my_atomic_load#(&var) + my_atomic_load#_explicit(&var, memory_order) return *var + Order must be one of MY_MEMORY_ORDER_RELAXED, MY_MEMORY_ORDER_CONSUME, + MY_MEMORY_ORDER_ACQUIRE, MY_MEMORY_ORDER_SEQ_CST. my_atomic_store#(&var, what) + my_atomic_store#_explicit(&var, what, memory_order) store 'what' in *var + Order must be one of MY_MEMORY_ORDER_RELAXED, MY_MEMORY_ORDER_RELEASE, + MY_MEMORY_ORDER_SEQ_CST. '#' is substituted by a size suffix - 8, 16, 32, 64, or ptr (e.g. my_atomic_add8, my_atomic_fas32, my_atomic_casptr). - NOTE This operations are not always atomic, so they always must be - enclosed in my_atomic_rwlock_rdlock(lock)/my_atomic_rwlock_rdunlock(lock) - or my_atomic_rwlock_wrlock(lock)/my_atomic_rwlock_wrunlock(lock). - Hint: if a code block makes intensive use of atomic ops, it make sense - to take/release rwlock once for the whole block, not for every statement. + The first version orders memory accesses according to MY_MEMORY_ORDER_SEQ_CST, + the second version (with _explicit suffix) orders memory accesses according to + given memory order. + + memory_order specifies how non-atomic memory accesses are to be ordered around + an atomic operation: + + MY_MEMORY_ORDER_RELAXED - there are no constraints on reordering of memory + accesses around the atomic variable. + MY_MEMORY_ORDER_CONSUME - no reads in the current thread dependent on the + value currently loaded can be reordered before this + load. This ensures that writes to dependent + variables in other threads that release the same + atomic variable are visible in the current thread. + On most platforms, this affects compiler + optimization only. + MY_MEMORY_ORDER_ACQUIRE - no reads in the current thread can be reordered + before this load. This ensures that all writes in + other threads that release the same atomic variable + are visible in the current thread. + MY_MEMORY_ORDER_RELEASE - no writes in the current thread can be reordered + after this store. This ensures that all writes in + the current thread are visible in other threads that + acquire the same atomic variable. + MY_MEMORY_ORDER_ACQ_REL - no reads in the current thread can be reordered + before this load as well as no writes in the current + thread can be reordered after this store. The + operation is read-modify-write operation. It is + ensured that all writes in another threads that + release the same atomic variable are visible before + the modification and the modification is visible in + other threads that acquire the same atomic variable. + MY_MEMORY_ORDER_SEQ_CST - The operation has the same semantics as + acquire-release operation, and additionally has + sequentially-consistent operation ordering. - On architectures where these operations are really atomic, rwlocks will - be optimized away. 8- and 16-bit atomics aren't implemented for windows (see generic-msvc.h), - but can be added, if necessary. + but can be added, if necessary. */ -#ifndef my_atomic_rwlock_init - #define intptr void * /** Currently we don't support 8-bit and 16-bit operations. @@ -62,16 +111,14 @@ */ #undef MY_ATOMIC_HAS_8_16 -#ifndef MY_ATOMIC_MODE_RWLOCKS /* * Attempt to do atomic ops without locks */ #include "atomic/nolock.h" -#endif #ifndef make_atomic_cas_body /* nolock.h was not able to generate even a CAS function, fall back */ -#include "atomic/rwlock.h" +#error atomic ops for this platform are not implemented #endif /* define missing functions by using the already generated ones */ @@ -281,6 +328,79 @@ make_atomic_store(ptr) #define MY_ATOMIC_NOT_1CPU 1 extern int my_atomic_initialize(); +#ifdef HAVE_GCC_C11_ATOMICS +#define MY_MEMORY_ORDER_RELAXED __ATOMIC_RELAXED +#define MY_MEMORY_ORDER_CONSUME __ATOMIC_CONSUME +#define MY_MEMORY_ORDER_ACQUIRE __ATOMIC_ACQUIRE +#define MY_MEMORY_ORDER_RELEASE __ATOMIC_RELEASE +#define MY_MEMORY_ORDER_ACQ_REL __ATOMIC_ACQ_REL +#define MY_MEMORY_ORDER_SEQ_CST __ATOMIC_SEQ_CST + +#define my_atomic_store32_explicit(P, D, O) __atomic_store_n((P), (D), (O)) +#define my_atomic_store64_explicit(P, D, O) __atomic_store_n((P), (D), (O)) +#define my_atomic_storeptr_explicit(P, D, O) __atomic_store_n((P), (D), (O)) + +#define my_atomic_load32_explicit(P, O) __atomic_load_n((P), (O)) +#define my_atomic_load64_explicit(P, O) __atomic_load_n((P), (O)) +#define my_atomic_loadptr_explicit(P, O) __atomic_load_n((P), (O)) + +#define my_atomic_fas32_explicit(P, D, O) __atomic_exchange_n((P), (D), (O)) +#define my_atomic_fas64_explicit(P, D, O) __atomic_exchange_n((P), (D), (O)) +#define my_atomic_fasptr_explicit(P, D, O) __atomic_exchange_n((P), (D), (O)) + +#define my_atomic_add32_explicit(P, A, O) __atomic_fetch_add((P), (A), (O)) +#define my_atomic_add64_explicit(P, A, O) __atomic_fetch_add((P), (A), (O)) + +#define my_atomic_cas32_weak_explicit(P, E, D, S, F) \ + __atomic_compare_exchange_n((P), (E), (D), true, (S), (F)) +#define my_atomic_cas64_weak_explicit(P, E, D, S, F) \ + __atomic_compare_exchange_n((P), (E), (D), true, (S), (F)) +#define my_atomic_casptr_weak_explicit(P, E, D, S, F) \ + __atomic_compare_exchange_n((P), (E), (D), true, (S), (F)) + +#define my_atomic_cas32_strong_explicit(P, E, D, S, F) \ + __atomic_compare_exchange_n((P), (E), (D), false, (S), (F)) +#define my_atomic_cas64_strong_explicit(P, E, D, S, F) \ + __atomic_compare_exchange_n((P), (E), (D), false, (S), (F)) +#define my_atomic_casptr_strong_explicit(P, E, D, S, F) \ + __atomic_compare_exchange_n((P), (E), (D), false, (S), (F)) +#else +#define MY_MEMORY_ORDER_RELAXED +#define MY_MEMORY_ORDER_CONSUME +#define MY_MEMORY_ORDER_ACQUIRE +#define MY_MEMORY_ORDER_RELEASE +#define MY_MEMORY_ORDER_ACQ_REL +#define MY_MEMORY_ORDER_SEQ_CST + +#define my_atomic_store32_explicit(P, D, O) my_atomic_store32((P), (D)) +#define my_atomic_store64_explicit(P, D, O) my_atomic_store64((P), (D)) +#define my_atomic_storeptr_explicit(P, D, O) my_atomic_storeptr((P), (D)) + +#define my_atomic_load32_explicit(P, O) my_atomic_load32((P)) +#define my_atomic_load64_explicit(P, O) my_atomic_load64((P)) +#define my_atomic_loadptr_explicit(P, O) my_atomic_loadptr((P)) + +#define my_atomic_fas32_explicit(P, D, O) my_atomic_fas32((P), (D)) +#define my_atomic_fas64_explicit(P, D, O) my_atomic_fas64((P), (D)) +#define my_atomic_fasptr_explicit(P, D, O) my_atomic_fasptr((P), (D)) + +#define my_atomic_add32_explicit(P, A, O) my_atomic_add32((P), (A)) +#define my_atomic_add64_explicit(P, A, O) my_atomic_add64((P), (A)) +#define my_atomic_addptr_explicit(P, A, O) my_atomic_addptr((P), (A)) + +#define my_atomic_cas32_weak_explicit(P, E, D, S, F) \ + my_atomic_cas32((P), (E), (D)) +#define my_atomic_cas64_weak_explicit(P, E, D, S, F) \ + my_atomic_cas64((P), (E), (D)) +#define my_atomic_casptr_weak_explicit(P, E, D, S, F) \ + my_atomic_casptr((P), (E), (D)) + +#define my_atomic_cas32_strong_explicit(P, E, D, S, F) \ + my_atomic_cas32((P), (E), (D)) +#define my_atomic_cas64_strong_explicit(P, E, D, S, F) \ + my_atomic_cas64((P), (E), (D)) +#define my_atomic_casptr_strong_explicit(P, E, D, S, F) \ + my_atomic_casptr((P), (E), (D)) #endif #endif /* MY_ATOMIC_INCLUDED */ diff --git a/include/my_base.h b/include/my_base.h index 5c3dd8db9d9..8b546edac43 100644 --- a/include/my_base.h +++ b/include/my_base.h @@ -159,8 +159,6 @@ enum ha_extra_function { Ignore if the a tuple is not found, continue processing the transaction and ignore that 'row'. Needed for idempotency handling on the slave - - Currently only used by NDB storage engine. Partition handler ignores flag. */ HA_EXTRA_IGNORE_NO_KEY, HA_EXTRA_NO_IGNORE_NO_KEY, @@ -356,6 +354,7 @@ enum ha_base_keytype { #define HA_CREATE_DELAY_KEY_WRITE 64 #define HA_CREATE_RELIES_ON_SQL_LAYER 128 #define HA_CREATE_INTERNAL_TABLE 256 +#define HA_PRESERVE_INSERT_ORDER 512 /* Flags used by start_bulk_insert */ @@ -502,7 +501,9 @@ enum ha_base_keytype { #define HA_ERR_DISK_FULL 189 #define HA_ERR_INCOMPATIBLE_DEFINITION 190 #define HA_ERR_FTS_TOO_MANY_WORDS_IN_PHRASE 191 /* Too many words in a phrase */ -#define HA_ERR_LAST 191 /* Copy of last error nr */ +#define HA_ERR_DECRYPTION_FAILED 192 /* Table encrypted but + decypt failed */ +#define HA_ERR_LAST 192 /* Copy of last error nr */ /* Number of different errors */ #define HA_ERR_ERRORS (HA_ERR_LAST - HA_ERR_FIRST + 1) diff --git a/include/my_bit.h b/include/my_bit.h index 174e0f70083..a50403c312d 100644 --- a/include/my_bit.h +++ b/include/my_bit.h @@ -121,6 +121,15 @@ static inline uint32 my_reverse_bits(uint32 key) _my_bits_reverse_table[(key>>24) ]; } +/* + a number with the n lowest bits set + an overflow-safe version of (1 << n) - 1 +*/ +static inline uint32 my_set_bits(int n) +{ + return (((1UL << (n - 1)) - 1) << 1) | 1; +} + C_MODE_END #endif /* MY_BIT_INCLUDED */ diff --git a/include/my_compare.h b/include/my_compare.h index 87f0aa8f3ca..1c50ff93791 100644 --- a/include/my_compare.h +++ b/include/my_compare.h @@ -57,7 +57,7 @@ typedef struct st_HA_KEYSEG /* Key-portion */ uint16 language; uint8 type; /* Type of key (for sort) */ uint8 null_bit; /* bitmask to test for NULL */ - uint8 bit_start,bit_end; /* if bit field */ + uint8 bit_start; uint8 bit_length; /* Length of bit part */ } HA_KEYSEG; diff --git a/include/sha1.h b/include/my_crypt.h index d927cd26ad9..719e349bfb9 100644 --- a/include/sha1.h +++ b/include/my_crypt.h @@ -1,7 +1,6 @@ -#ifndef SHA1_INCLUDED -#define SHA1_INCLUDED - -/* Copyright (c) 2013, Monty Program Ab +/* + Copyright (c) 2014 Google Inc. + Copyright (c) 2014, 2015 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -9,17 +8,17 @@ 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 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 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 Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef MY_CRYPT_INCLUDED +#define MY_CRYPT_INCLUDED -#include <mysql/service_sha1.h> -#define SHA1_HASH_SIZE MY_SHA1_HASH_SIZE -#define compute_sha1_hash(A,B,C) my_sha1(A,B,C) -#define compute_sha1_hash_multi(A,B,C,D,E) my_sha1_multi(A,B,C,D,E,NULL) +#include <my_config.h> /* HAVE_EncryptAes128{Ctr,Gcm} */ +#include <mysql/service_my_crypt.h> -#endif /* SHA__INCLUDED */ +#endif /* MY_CRYPT_INCLUDED */ diff --git a/include/my_dbug.h b/include/my_dbug.h index f4c854bc10c..d56033ab025 100644 --- a/include/my_dbug.h +++ b/include/my_dbug.h @@ -30,6 +30,7 @@ struct _db_stack_frame_ { const char *func; /* function name of the previous stack frame */ const char *file; /* filename of the function of previous frame */ uint level; /* this nesting level, highest bit enables tracing */ + int line; /* line of DBUG_RETURN */ struct _db_stack_frame_ *prev; /* pointer to the previous frame */ }; @@ -48,7 +49,7 @@ extern void _db_set_(const char *control); extern void _db_set_init_(const char *control); extern void _db_enter_(const char *_func_, const char *_file_, uint _line_, struct _db_stack_frame_ *_stack_frame_); -extern void _db_return_(uint _line_, struct _db_stack_frame_ *_stack_frame_); +extern void _db_return_(struct _db_stack_frame_ *_stack_frame_); extern void _db_pargs_(uint _line_,const char *keyword); extern void _db_doprnt_(const char *format,...) ATTRIBUTE_FORMAT(printf, 1, 2); @@ -63,12 +64,24 @@ extern void dbug_swap_code_state(void **code_state_store); extern void dbug_free_code_state(void **code_state_store); extern const char* _db_get_func_(void); +#define DBUG_LEAVE do { \ + _db_stack_frame_.line= __LINE__; \ + _db_return_ (&_db_stack_frame_); \ + _db_stack_frame_.line= 0; \ + } while(0) + +#ifdef HAVE_ATTRIBUTE_CLEANUP +#define DBUG_ENTER(a) struct _db_stack_frame_ _db_stack_frame_ __attribute__((cleanup(_db_return_))); \ + _db_enter_ (a,__FILE__,__LINE__,&_db_stack_frame_) +#define DBUG_RETURN(a1) do { _db_stack_frame_.line=__LINE__; return(a1);} while(0) +#define DBUG_VOID_RETURN do { _db_stack_frame_.line=__LINE__; return;} while(0) +#else #define DBUG_ENTER(a) struct _db_stack_frame_ _db_stack_frame_; \ _db_enter_ (a,__FILE__,__LINE__,&_db_stack_frame_) -#define DBUG_LEAVE _db_return_ (__LINE__, &_db_stack_frame_) - #define DBUG_RETURN(a1) do {DBUG_LEAVE; return(a1);} while(0) #define DBUG_VOID_RETURN do {DBUG_LEAVE; return;} while(0) +#endif + #define DBUG_EXECUTE(keyword,a1) \ do {if (_db_keyword_(0, (keyword), 0)) { a1 }} while(0) #define DBUG_EXECUTE_IF(keyword,a1) \ diff --git a/include/my_decimal_limits.h b/include/my_decimal_limits.h index 50d70357c42..0aa247ff035 100644 --- a/include/my_decimal_limits.h +++ b/include/my_decimal_limits.h @@ -13,7 +13,7 @@ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ #define DECIMAL_LONGLONG_DIGITS 22 #define DECIMAL_LONG_DIGITS 10 diff --git a/include/my_default.h b/include/my_default.h index 1d556de69ee..bd3a21f03a8 100644 --- a/include/my_default.h +++ b/include/my_default.h @@ -11,7 +11,7 @@ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ /* Definitions for mysys/my_default.c */ @@ -45,6 +45,13 @@ extern void free_defaults(char **argv); extern void my_print_default_files(const char *conf_file); extern void print_defaults(const char *conf_file, const char **groups); + +/** Simplify load_defaults() common use */ +#define load_defaults_or_exit(A, B, C, D) switch (load_defaults(A, B, C, D)) { \ + case 0: break; \ + case 4: my_end(0); exit(0); \ + default: my_end(0); exit(1); } + C_MODE_END #endif /* MY_DEFAULT_INCLUDED */ diff --git a/include/my_getopt.h b/include/my_getopt.h index 18b4bf10698..584c009464d 100644 --- a/include/my_getopt.h +++ b/include/my_getopt.h @@ -39,8 +39,9 @@ C_MODE_START #define GET_DOUBLE 14 #define GET_FLAGSET 15 -#define GET_ASK_ADDR 128 -#define GET_TYPE_MASK 127 +#define GET_ASK_ADDR 128 +#define GET_AUTO 64 +#define GET_TYPE_MASK 63 /** Enumeration of the my_option::arg_type attributes. @@ -100,8 +101,10 @@ typedef void *(*my_getopt_value)(const char *, uint, const struct my_option *, extern char *disabled_my_option; +extern char *autoset_my_option; extern my_bool my_getopt_print_errors; extern my_bool my_getopt_skip_unknown; +extern my_bool my_getopt_prefix_matching; extern my_error_reporter my_getopt_error_reporter; extern int handle_options (int *argc, char ***argv, diff --git a/include/my_global.h b/include/my_global.h index 057c613d64c..dcfd607b455 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -442,19 +442,6 @@ extern "C" int madvise(void *addr, size_t len, int behav); /* don't assume that STDERR_FILENO is 2, mysqld can freopen */ #undef STDERR_FILENO -/* - Deprecated workaround for false-positive uninitialized variables - warnings. Those should be silenced using tool-specific heuristics. - - Enabled by default for g++ due to the bug referenced below. -*/ -#if defined(_lint) || defined(FORCE_INIT_OF_VARS) || \ - (defined(__GNUC__) && defined(__cplusplus)) -#define LINT_INIT(var) var= 0 -#else -#define LINT_INIT(var) -#endif - #ifndef SO_EXT #ifdef _WIN32 #define SO_EXT ".dll" @@ -465,16 +452,21 @@ extern "C" int madvise(void *addr, size_t len, int behav); /* Suppress uninitialized variable warning without generating code. - - The _cplusplus is a temporary workaround for C++ code pending a fix - for a g++ bug (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34772). */ -#if defined(_lint) || defined(FORCE_INIT_OF_VARS) || \ - defined(__cplusplus) || !defined(__GNUC__) -#define UNINIT_VAR(x) x= 0 -#else +#if defined(__GNUC__) /* GCC specific self-initialization which inhibits the warning. */ #define UNINIT_VAR(x) x= x +#elif defined(_lint) || defined(FORCE_INIT_OF_VARS) +#define UNINIT_VAR(x) x= 0 +#else +#define UNINIT_VAR(x) x +#endif + +/* This is only to be used when reseting variables in a class constructor */ +#if defined(_lint) || defined(FORCE_INIT_OF_VARS) +#define LINT_INIT(x) x= 0 +#else +#define LINT_INIT(x) #endif #if !defined(HAVE_UINT) @@ -1244,9 +1236,6 @@ static inline double rint(double x) #undef HAVE_SMEM /* No shared memory */ #else -#ifdef WITH_NDB_BINLOG -#define HAVE_NDB_BINLOG 1 -#endif #define HAVE_REPLICATION #define HAVE_EXTERNAL_CLIENT #endif /* EMBEDDED_LIBRARY */ diff --git a/include/my_handler_errors.h b/include/my_handler_errors.h index a7afcfe93a3..5af6a359348 100644 --- a/include/my_handler_errors.h +++ b/include/my_handler_errors.h @@ -94,7 +94,8 @@ static const char *handler_error_messages[]= "Operation was interrupted by end user (probably kill command?)", "Disk full", "Incompatible key or row definition between the MariaDB .frm file and the information in the storage engine. You have to dump and restore the table to fix this", - "Too many words in a FTS phrase or proximity search" + "Too many words in a FTS phrase or proximity search", + "Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match." }; #endif /* MYSYS_MY_HANDLER_ERRORS_INCLUDED */ diff --git a/include/my_md5.h b/include/my_md5.h index 77557fb9346..141ea309cae 100644 --- a/include/my_md5.h +++ b/include/my_md5.h @@ -28,7 +28,7 @@ extern "C" { #endif -void compute_md5_hash(char *digest, const char *buf, int len); +#define compute_md5_hash(A,B,C) my_md5(A,B,C) /* Convert an array of bytes to a hexadecimal representation. diff --git a/include/my_net.h b/include/my_net.h index 1ebb71ead23..91d780a276d 100644 --- a/include/my_net.h +++ b/include/my_net.h @@ -36,9 +36,11 @@ C_MODE_START #ifdef HAVE_ARPA_INET_H #include <arpa/inet.h> #endif -#ifdef HAVE_POLL +#if defined(HAVE_POLL_H) +#include <poll.h> +#elif defined(HAVE_SYS_POLL_H) #include <sys/poll.h> -#endif +#endif /* defined(HAVE_POLL_H) */ #ifdef HAVE_SYS_IOCTL_H #include <sys/ioctl.h> #endif diff --git a/include/my_pthread.h b/include/my_pthread.h index cff6416904a..6b830ca36d2 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -184,7 +184,7 @@ int pthread_cancel(pthread_t thread); #define pthread_key(T,V) pthread_key_t V #define my_pthread_getspecific_ptr(T,V) my_pthread_getspecific(T,(V)) #define my_pthread_setspecific_ptr(T,V) pthread_setspecific(T,(void*) (V)) -#define pthread_detach_this_thread() +#define pthread_detach_this_thread() { pthread_t tmp=pthread_self() ; pthread_detach(tmp); } #define pthread_handler_t EXTERNC void * typedef void *(* pthread_handler)(void *); @@ -367,6 +367,26 @@ int my_pthread_mutex_trylock(pthread_mutex_t *mutex); } while(0) #endif /* !set_timespec_time_nsec */ +#ifdef MYSQL_CLIENT +#define _current_thd() NULL +#elif defined(_WIN32) +#ifdef __cplusplus +extern "C" +#endif +MYSQL_THD _current_thd_noinline(); +#define _current_thd() _current_thd_noinline() +#else +/* + THR_THD is a key which will be used to set/get THD* for a thread, + using my_pthread_setspecific_ptr()/my_thread_getspecific_ptr(). +*/ +extern pthread_key(MYSQL_THD, THR_THD); +static inline MYSQL_THD _current_thd(void) +{ + return my_pthread_getspecific_ptr(MYSQL_THD,THR_THD); +} +#endif + /* safe_mutex adds checking to mutex for easier debugging */ struct st_hash; typedef struct st_safe_mutex_t @@ -714,7 +734,7 @@ extern void my_mutex_end(void); We need to have at least 256K stack to handle calls to myisamchk_init() with the current number of keys and key parts. */ -#define DEFAULT_THREAD_STACK (288*1024L) +#define DEFAULT_THREAD_STACK (289*1024L) #endif #define MY_PTHREAD_LOCK_READ 0 diff --git a/include/my_rdtsc.h b/include/my_rdtsc.h index 38ab0de8040..d24e2116733 100644 --- a/include/my_rdtsc.h +++ b/include/my_rdtsc.h @@ -125,6 +125,7 @@ C_MODE_END #define MY_TIMER_ROUTINE_MACH_ABSOLUTE_TIME 25 #define MY_TIMER_ROUTINE_GETSYSTEMTIMEASFILETIME 26 #define MY_TIMER_ROUTINE_ASM_SUNPRO_X86_64 27 +#define MY_TIMER_ROUTINE_ASM_S390 28 #endif diff --git a/include/my_rnd.h b/include/my_rnd.h index b4a5d735811..ab8b3e10d23 100644 --- a/include/my_rnd.h +++ b/include/my_rnd.h @@ -11,7 +11,7 @@ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ #ifndef _my_rnd_h #define _my_rnd_h diff --git a/include/my_service_manager.h b/include/my_service_manager.h new file mode 100644 index 00000000000..4d88e992b5e --- /dev/null +++ b/include/my_service_manager.h @@ -0,0 +1,39 @@ +/* + Copyright (c) 2015 Daniel Black. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + 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 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 Street, Fifth Floor, Boston, MA 02110-1301, USA +*/ + + +#ifndef MY_SERVICE_MANAGER_INCLUDED +#define MY_SERVICE_MANAGER_INCLUDED + +#if defined(HAVE_SYSTEMD) && !defined(EMBEDDED_LIBRARY) +/* + sd-daemon.h may include inttypes.h. Explicitly request format macros before + the first inclusion of inttypes.h. +*/ +#define __STDC_FORMAT_MACROS +#include <systemd/sd-daemon.h> +/** INTERVAL in seconds followed by printf style status */ +#define service_manager_extend_timeout(INTERVAL, FMTSTR, ...) \ + sd_notifyf(0, "STATUS=" FMTSTR "\nEXTEND_TIMEOUT_USEC=%u\n", ##__VA_ARGS__, INTERVAL * 1000000) + +#else +#define sd_notify(X, Y) +#define sd_notifyf(E, F, ...) +#define service_manager_extend_timeout(I, FMTSTR, ...) +#endif + +#endif /* MY_SERVICE_MANAGER_INCLUDED */ diff --git a/include/my_sys.h b/include/my_sys.h index 69daf09311e..110a2ee9af3 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -19,6 +19,8 @@ #include "my_global.h" /* C_MODE_START, C_MODE_END */ +#include <m_string.h> + C_MODE_START #ifdef HAVE_AIOWAIT @@ -40,6 +42,7 @@ typedef struct my_aio_result { #include <malloc.h> /*for alloca*/ #endif #include <mysql/plugin.h> +#include <mysql/service_my_print_error.h> #define MY_INIT(name) { my_progname= name; my_init(); } @@ -65,6 +68,7 @@ typedef struct my_aio_result { #define MY_WME 16 /* Write message on error */ #define MY_WAIT_IF_FULL 32 /* Wait and try again if disk full error */ #define MY_IGNORE_BADFD 32 /* my_sync(): ignore 'bad descriptor' errors */ +#define MY_ENCRYPT 64 /* Encrypt IO_CACHE temporary files */ #define MY_NOSYMLINKS 512 /* my_open(): don't follow symlinks */ #define MY_FULL_IO 512 /* my_read(): loop intil I/O is complete */ #define MY_DONT_CHECK_FILESIZE 128 /* Option to init_io_cache() */ @@ -78,6 +82,11 @@ typedef struct my_aio_result { #define MY_SHORT_WAIT 64 /* my_lock() don't wait if can't lock */ #define MY_FORCE_LOCK 128 /* use my_lock() even if disable_locking */ #define MY_NO_WAIT 256 /* my_lock() don't wait at all */ +/* + init_dynamic_array() has init buffer; Internal flag, not to be used by + caller. +*/ +#define MY_INIT_BUFFER_USED 256 #define MY_ZEROFILL 32 /* my_malloc(), fill array with zero */ #define MY_ALLOW_ZERO_PTR 64 /* my_realloc() ; zero ptr -> malloc */ #define MY_FREE_ON_ERROR 128 /* my_realloc() ; Free old ptr on error */ @@ -96,18 +105,10 @@ typedef struct my_aio_result { #define MY_GIVE_INFO 2 /* Give time info about process*/ #define MY_DONT_FREE_DBUG 4 /* Do not call DBUG_END() in my_end() */ -#define ME_HIGHBYTE 8 /* Shift for colours */ -#define ME_NOCUR 1 /* Don't use curses message */ -#define ME_OLDWIN 2 /* Use old window */ -#define ME_BELL 4 /* Ring bell then printing message */ -#define ME_HOLDTANG 8 /* Don't delete last keys */ -#define ME_WAITTOT 16 /* Wait for errtime secs of for a action */ -#define ME_WAITTANG 32 /* Wait for a user action */ -#define ME_NOREFRESH 64 /* Write the error message to error log */ -#define ME_NOINPUT 128 /* Dont use the input libary */ -#define ME_COLOUR1 ((1 << ME_HIGHBYTE)) /* Possibly error-colours */ -#define ME_COLOUR2 ((2 << ME_HIGHBYTE)) -#define ME_COLOUR3 ((3 << ME_HIGHBYTE)) +#define ME_BELL 4 /* Ring bell then printing message */ +#define ME_WAITTANG 0 /* Wait for a user action */ +#define ME_NOREFRESH 64 /* Write the error message to error log */ +#define ME_NOINPUT 0 /* Dont use the input libary */ #define ME_JUST_INFO 1024 /**< not error but just info */ #define ME_JUST_WARNING 2048 /**< not error but just warning */ #define ME_FATALERROR 4096 /* Fatal statement error */ @@ -198,16 +199,17 @@ extern void my_large_free(uchar *ptr); #endif /* GNUC */ #define my_alloca(SZ) alloca((size_t) (SZ)) #define my_afree(PTR) ((void)0) -#define my_safe_alloca(size, max_alloca_sz) ((size <= max_alloca_sz) ? \ - my_alloca(size) : \ - my_malloc(size, MYF(0))) -#define my_safe_afree(ptr, size, max_alloca_sz) if (size > max_alloca_sz) \ - my_free(ptr) +#define MAX_ALLOCA_SZ 4096 +#define my_safe_alloca(size) (((size) <= MAX_ALLOCA_SZ) ? \ + my_alloca(size) : \ + my_malloc((size), MYF(MY_THREAD_SPECIFIC|MY_WME))) +#define my_safe_afree(ptr, size) \ + do { if ((size) > MAX_ALLOCA_SZ) my_free(ptr); } while(0) #else #define my_alloca(SZ) my_malloc(SZ,MYF(MY_FAE)) #define my_afree(PTR) my_free(PTR) -#define my_safe_alloca(size, max_alloca_sz) my_alloca(size) -#define my_safe_afree(ptr, size, max_alloca_sz) my_afree(ptr) +#define my_safe_alloca(size) my_alloca(size) +#define my_safe_afree(ptr, size) my_afree(ptr) #endif /* HAVE_ALLOCA */ #ifndef errno /* did we already get it? */ @@ -280,7 +282,7 @@ enum cache_type { TYPE_NOT_SET= 0, READ_CACHE, WRITE_CACHE, SEQ_READ_APPEND /* sequential read or append */, - READ_FIFO, READ_NET,WRITE_NET}; + READ_FIFO, READ_NET}; enum flush_type { @@ -359,7 +361,6 @@ typedef struct st_dynamic_string } DYNAMIC_STRING; struct st_io_cache; -typedef int (*IO_CACHE_CALLBACK)(struct st_io_cache*); typedef struct st_io_cache_share { @@ -456,24 +457,14 @@ typedef struct st_io_cache /* Used when cacheing files */ */ enum cache_type type; /* - Callbacks when the actual read I/O happens. These were added and - are currently used for binary logging of LOAD DATA INFILE - when a - block is read from the file, we create a block create/append event, and - when IO_CACHE is closed, we create an end event. These functions could, - of course be used for other things - */ - IO_CACHE_CALLBACK pre_read; - IO_CACHE_CALLBACK post_read; - IO_CACHE_CALLBACK pre_close; - /* Counts the number of times, when we were forced to use disk. We use it to increase the binlog_cache_disk_use and binlog_stmt_cache_disk_use status variables. */ ulong disk_writes; - void* arg; /* for use by pre/post_read */ char *file_name; /* if used with 'open_cached_file' */ - char *dir,*prefix; + const char *dir; + char prefix[3]; File file; /* file descriptor */ /* seek_not_done is set by my_b_seek() to inform the upcoming read/write @@ -513,59 +504,110 @@ typedef void (*my_error_reporter)(enum loglevel level, const char *format, ...) extern my_error_reporter my_charset_error_reporter; - /* defines for mf_iocache */ +/* inline functions for mf_iocache */ - /* Test if buffer is inited */ -#define my_b_clear(info) (info)->buffer=0 -#define my_b_inited(info) (info)->buffer +extern int my_b_flush_io_cache(IO_CACHE *info, int need_append_buffer_lock); +extern int _my_b_get(IO_CACHE *info); +extern int _my_b_read(IO_CACHE *info,uchar *Buffer,size_t Count); +extern int _my_b_write(IO_CACHE *info,const uchar *Buffer,size_t Count); + +/* Test if buffer is inited */ +static inline void my_b_clear(IO_CACHE *info) { info->buffer= 0; } +static inline int my_b_inited(IO_CACHE *info) { return MY_TEST(info->buffer); } #define my_b_EOF INT_MIN -#define my_b_read(info,Buffer,Count) \ - ((info)->read_pos + (Count) <= (info)->read_end ?\ - (memcpy(Buffer,(info)->read_pos,(size_t) (Count)), \ - ((info)->read_pos+=(Count)),0) :\ - (*(info)->read_function)((info),Buffer,Count)) - -#define my_b_write(info,Buffer,Count) \ - ((info)->write_pos + (Count) <=(info)->write_end ?\ - (memcpy((info)->write_pos, (Buffer), (size_t)(Count)),\ - ((info)->write_pos+=(Count)),0) : \ - (*(info)->write_function)((info),(uchar *)(Buffer),(Count))) - -#define my_b_get(info) \ - ((info)->read_pos != (info)->read_end ?\ - ((info)->read_pos++, (int) (uchar) (info)->read_pos[-1]) :\ - _my_b_get(info)) - - /* my_b_write_byte dosn't have any err-check */ -#define my_b_write_byte(info,chr) \ - (((info)->write_pos < (info)->write_end) ?\ - ((*(info)->write_pos++)=(chr)) :\ - (_my_b_write(info,0,0) , ((*(info)->write_pos++)=(chr)))) - -#define my_b_fill_cache(info) \ - (((info)->read_end=(info)->read_pos),(*(info)->read_function)(info,0,0)) - -#define my_b_tell(info) ((info)->pos_in_file + \ - (size_t) (*(info)->current_pos - (info)->request_pos)) -#define my_b_write_tell(info) ((info)->pos_in_file + \ - ((info)->write_pos - (info)->write_buffer)) - -#define my_b_get_buffer_start(info) (info)->request_pos -#define my_b_get_bytes_in_buffer(info) (char*) (info)->read_end - \ - (char*) my_b_get_buffer_start(info) -#define my_b_get_pos_in_file(info) (info)->pos_in_file - -/* tell write offset in the SEQ_APPEND cache */ +static inline int my_b_read(IO_CACHE *info, uchar *Buffer, size_t Count) +{ + if (info->read_pos + Count <= info->read_end) + { + memcpy(Buffer, info->read_pos, Count); + info->read_pos+= Count; + return 0; + } + return _my_b_read(info, Buffer, Count); +} + +static inline int my_b_write(IO_CACHE *info, const uchar *Buffer, size_t Count) +{ + if (info->write_pos + Count <= info->write_end) + { + memcpy(info->write_pos, Buffer, Count); + info->write_pos+= Count; + return 0; + } + return _my_b_write(info, Buffer, Count); +} + +static inline int my_b_get(IO_CACHE *info) +{ + if (info->read_pos != info->read_end) + { + info->read_pos++; + return info->read_pos[-1]; + } + return _my_b_get(info); +} + +/* my_b_write_byte dosn't have any err-check */ +static inline void my_b_write_byte(IO_CACHE *info, uchar chr) +{ + if (info->write_pos >= info->write_end) + my_b_flush_io_cache(info, 1); + *info->write_pos++= chr; +} + +/** + Fill buffer of the cache. + + @note It assumes that you have already used all characters in the CACHE, + independent of the read_pos value! + + @returns + 0 On error or EOF (info->error = -1 on error) + # Number of characters +*/ +static inline size_t my_b_fill(IO_CACHE *info) +{ + info->read_pos= info->read_end; + return _my_b_read(info,0,0) ? 0 : info->read_end - info->read_pos; +} + +static inline my_off_t my_b_tell(const IO_CACHE *info) +{ + return info->pos_in_file + (*info->current_pos - info->request_pos); +} + +static inline my_off_t my_b_write_tell(const IO_CACHE *info) +{ + return info->pos_in_file + (info->write_pos - info->write_buffer); +} + +static inline uchar* my_b_get_buffer_start(const IO_CACHE *info) +{ + return info->request_pos; +} + +static inline size_t my_b_get_bytes_in_buffer(const IO_CACHE *info) +{ + return info->read_end - info->request_pos; +} + +static inline my_off_t my_b_get_pos_in_file(const IO_CACHE *info) +{ + return info->pos_in_file; +} + +static inline size_t my_b_bytes_in_cache(const IO_CACHE *info) +{ + return *info->current_end - *info->current_pos; +} + int my_b_copy_to_file(IO_CACHE *cache, FILE *file); my_off_t my_b_append_tell(IO_CACHE* info); my_off_t my_b_safe_tell(IO_CACHE* info); /* picks the correct tell() */ - -#define my_b_bytes_in_cache(info) (size_t) (*(info)->current_end - \ - *(info)->current_pos) +int my_b_pread(IO_CACHE *info, uchar *Buffer, size_t Count, my_off_t pos); typedef uint32 ha_checksum; -extern ulong my_crc_dbug_check; extern int (*mysys_test_invalid_symlink)(const char *filename); #include <my_alloc.h> @@ -666,10 +708,6 @@ extern int my_sync(File fd, myf my_flags); extern int my_sync_dir(const char *dir_name, myf my_flags); extern int my_sync_dir_by_file(const char *file_name, myf my_flags); extern const char *my_get_err_msg(uint nr); -extern void my_error(uint nr,myf MyFlags, ...); -extern void my_printf_error(uint my_err, const char *format, myf MyFlags, ...); -extern void my_printv_error(uint error, const char *format, myf MyFlags, - va_list ap); extern int my_error_register(const char** (*get_errmsgs) (void), uint first, uint last); extern const char **my_error_unregister(uint first, uint last); @@ -751,32 +789,24 @@ void my_store_ptr(uchar *buff, size_t pack_length, my_off_t pos); my_off_t my_get_ptr(uchar *ptr, size_t pack_length); extern int init_io_cache(IO_CACHE *info,File file,size_t cachesize, enum cache_type type,my_off_t seek_offset, - pbool use_async_io, myf cache_myflags); + my_bool use_async_io, myf cache_myflags); extern my_bool reinit_io_cache(IO_CACHE *info,enum cache_type type, - my_off_t seek_offset,pbool use_async_io, - pbool clear_cache); + my_off_t seek_offset, my_bool use_async_io, + my_bool clear_cache); extern void setup_io_cache(IO_CACHE* info); -extern int _my_b_read(IO_CACHE *info,uchar *Buffer,size_t Count); -extern int _my_b_read_r(IO_CACHE *info,uchar *Buffer,size_t Count); extern void init_io_cache_share(IO_CACHE *read_cache, IO_CACHE_SHARE *cshare, IO_CACHE *write_cache, uint num_threads); extern void remove_io_thread(IO_CACHE *info); -extern int _my_b_seq_read(IO_CACHE *info,uchar *Buffer,size_t Count); -extern int _my_b_net_read(IO_CACHE *info,uchar *Buffer,size_t Count); -extern int _my_b_get(IO_CACHE *info); extern int _my_b_async_read(IO_CACHE *info,uchar *Buffer,size_t Count); -extern int _my_b_write(IO_CACHE *info,const uchar *Buffer,size_t Count); extern int my_b_append(IO_CACHE *info,const uchar *Buffer,size_t Count); extern int my_b_safe_write(IO_CACHE *info,const uchar *Buffer,size_t Count); extern int my_block_write(IO_CACHE *info, const uchar *Buffer, size_t Count, my_off_t pos); -extern int my_b_flush_io_cache(IO_CACHE *info, int need_append_buffer_lock); #define flush_io_cache(info) my_b_flush_io_cache((info),1) extern int end_io_cache(IO_CACHE *info); -extern size_t my_b_fill(IO_CACHE *info); extern void my_b_seek(IO_CACHE *info,my_off_t pos); extern size_t my_b_gets(IO_CACHE *info, char *to, size_t max_length); extern my_off_t my_b_filelength(IO_CACHE *info); @@ -960,6 +990,8 @@ void my_uuid(uchar *guid); void my_uuid2str(const uchar *guid, char *s); void my_uuid_end(void); +const char *my_dlerror(const char *dlpath); + /* character sets */ extern void my_charset_loader_init_mysys(MY_CHARSET_LOADER *loader); extern uint get_charset_number(const char *cs_name, uint cs_flags); @@ -998,9 +1030,9 @@ extern size_t escape_quotes_for_mysql(CHARSET_INFO *charset_info, char *to, size_t to_length, const char *from, size_t length); -extern void thd_increment_bytes_sent(ulong length); -extern void thd_increment_bytes_received(ulong length); -extern void thd_increment_net_big_packet_count(ulong length); +extern void thd_increment_bytes_sent(void *thd, ulong length); +extern void thd_increment_bytes_received(void *thd, ulong length); +extern void thd_increment_net_big_packet_count(void *thd, ulong length); #ifdef __WIN__ extern my_bool have_tcpip; /* Is set if tcpip is used */ diff --git a/include/my_valgrind.h b/include/my_valgrind.h index 5d08a271d4a..c488aaf1052 100644 --- a/include/my_valgrind.h +++ b/include/my_valgrind.h @@ -11,7 +11,7 @@ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ /* clang -> gcc */ #ifndef __has_feature diff --git a/include/myisamchk.h b/include/myisamchk.h index 64724de1789..3520cff7d80 100644 --- a/include/myisamchk.h +++ b/include/myisamchk.h @@ -12,7 +12,7 @@ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ /* Definitions needed for myisamchk/mariachk.c */ diff --git a/include/mysql.h b/include/mysql.h index f088ad668a1..53c86aee889 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -48,7 +48,11 @@ extern "C" { #ifndef MYSQL_ABI_CHECK #include <sys/types.h> #endif + +#ifndef MYSQL_PLUGIN_INCLUDED typedef char my_bool; +#endif + #if (defined(_WIN32) || defined(_WIN64)) && !defined(__WIN__) #define __WIN__ #endif diff --git a/include/mysql.h.pp b/include/mysql.h.pp index a593f526c6e..8936a716b90 100644 --- a/include/mysql.h.pp +++ b/include/mysql.h.pp @@ -29,7 +29,7 @@ typedef struct st_net { my_bool thread_specific_malloc; unsigned char compress; my_bool unused3; - unsigned char *unused; + void *thd; unsigned int last_errno; unsigned char error; my_bool unused4; @@ -81,7 +81,7 @@ enum enum_mysql_set_option MYSQL_OPTION_MULTI_STATEMENTS_ON, MYSQL_OPTION_MULTI_STATEMENTS_OFF }; -my_bool my_net_init(NET *net, Vio* vio, unsigned int my_flags); +my_bool my_net_init(NET *net, Vio* vio, void *thd, unsigned int my_flags); void my_net_local_init(NET *net); void net_end(NET *net); void net_clear(NET *net, my_bool clear_buffer); @@ -100,7 +100,7 @@ struct my_rnd_struct; enum Item_result { STRING_RESULT=0, REAL_RESULT, INT_RESULT, ROW_RESULT, DECIMAL_RESULT, - TIME_RESULT,IMPOSSIBLE_RESULT + TIME_RESULT }; typedef struct st_udf_args { @@ -130,13 +130,11 @@ void scramble_323(char *to, const char *message, const char *password); my_bool check_scramble_323(const unsigned char *reply, const char *message, unsigned long *salt); void get_salt_from_password_323(unsigned long *res, const char *password); -void make_password_from_salt_323(char *to, const unsigned long *salt); void make_scrambled_password(char *to, const char *password); void scramble(char *to, const char *message, const char *password); my_bool check_scramble(const unsigned char *reply, const char *message, const unsigned char *hash_stage2); void get_salt_from_password(unsigned char *res, const char *password); -void make_password_from_salt(char *to, const unsigned char *hash_stage2); char *octet2hex(char *to, const char *str, unsigned int len); char *get_tty_password(const char *opt_message); void get_tty_password_buff(const char *opt_message, char *to, size_t length); @@ -223,8 +221,6 @@ typedef struct st_typelib { extern my_ulonglong find_typeset(char *x, TYPELIB *typelib,int *error_position); extern int find_type_with_warning(const char *x, TYPELIB *typelib, const char *option); -extern int find_type_or_exit(const char *x, TYPELIB *typelib, - const char *option); extern int find_type(const char *x, const TYPELIB *typelib, unsigned int flags); extern void make_type(char *to,unsigned int nr,TYPELIB *typelib); extern const char *get_type(TYPELIB *typelib,unsigned int nr); diff --git a/include/mysql/auth_dialog_client.h b/include/mysql/auth_dialog_client.h index 2c58aac9444..5cbafcc22cc 100644 --- a/include/mysql/auth_dialog_client.h +++ b/include/mysql/auth_dialog_client.h @@ -12,7 +12,7 @@ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ /** @file diff --git a/include/mysql/plugin.h b/include/mysql/plugin.h index ceb6ac93ff5..61be12057e8 100644 --- a/include/mysql/plugin.h +++ b/include/mysql/plugin.h @@ -1,5 +1,5 @@ /* Copyright (c) 2005, 2013, Oracle and/or its affiliates - Copyright (C) 2009, 2013, Monty Program Ab + Copyright (C) 2009, 2017, MariaDB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -14,8 +14,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef _my_plugin_h -#define _my_plugin_h +#ifndef MYSQL_PLUGIN_INCLUDED +#define MYSQL_PLUGIN_INCLUDED /* On Windows, exports from DLL need to be declared @@ -75,21 +75,24 @@ typedef struct st_mysql_xid MYSQL_XID; #define MYSQL_PLUGIN_INTERFACE_VERSION 0x0104 /* MariaDB plugin interface version */ -#define MARIA_PLUGIN_INTERFACE_VERSION 0x0108 +#define MARIA_PLUGIN_INTERFACE_VERSION 0x010d /* The allowable types of plugins */ -#define MYSQL_UDF_PLUGIN 0 /* User-defined function */ -#define MYSQL_STORAGE_ENGINE_PLUGIN 1 /* Storage Engine */ +#define MYSQL_UDF_PLUGIN 0 /* not implemented */ +#define MYSQL_STORAGE_ENGINE_PLUGIN 1 #define MYSQL_FTPARSER_PLUGIN 2 /* Full-text parser plugin */ -#define MYSQL_DAEMON_PLUGIN 3 /* The daemon/raw plugin type */ -#define MYSQL_INFORMATION_SCHEMA_PLUGIN 4 /* The I_S plugin type */ -#define MYSQL_AUDIT_PLUGIN 5 /* The Audit plugin type */ -#define MYSQL_REPLICATION_PLUGIN 6 /* The replication plugin type */ -#define MYSQL_AUTHENTICATION_PLUGIN 7 /* The authentication plugin type */ -#define MYSQL_VALIDATE_PASSWORD_PLUGIN 8 /* validate password plugin type */ -#define MYSQL_MAX_PLUGIN_TYPE_NUM 9 /* The number of plugin types */ +#define MYSQL_DAEMON_PLUGIN 3 +#define MYSQL_INFORMATION_SCHEMA_PLUGIN 4 +#define MYSQL_AUDIT_PLUGIN 5 +#define MYSQL_REPLICATION_PLUGIN 6 +#define MYSQL_AUTHENTICATION_PLUGIN 7 +#define MYSQL_MAX_PLUGIN_TYPE_NUM 10 /* The number of plugin types */ + +/* MariaDB plugin types */ +#define MariaDB_PASSWORD_VALIDATION_PLUGIN 8 +#define MariaDB_ENCRYPTION_PLUGIN 9 /* We use the following strings to define licenses for plugins */ #define PLUGIN_LICENSE_PROPRIETARY 0 @@ -180,14 +183,21 @@ enum enum_mysql_show_type #define SHOW_LONG SHOW_ULONG #define SHOW_LONGLONG SHOW_ULONGLONG +enum enum_var_type +{ + SHOW_OPT_DEFAULT= 0, SHOW_OPT_SESSION, SHOW_OPT_GLOBAL +}; + struct st_mysql_show_var { const char *name; - char *value; + void *value; enum enum_mysql_show_type type; }; -#define SHOW_VAR_FUNC_BUFF_SIZE 1024 -typedef int (*mysql_show_var_func)(MYSQL_THD, struct st_mysql_show_var*, char *); +struct system_status_var; + +#define SHOW_VAR_FUNC_BUFF_SIZE (256 * sizeof(void*)) +typedef int (*mysql_show_var_func)(MYSQL_THD, struct st_mysql_show_var*, void *, struct system_status_var *status_var, enum enum_var_type); /* diff --git a/include/mysql/plugin_audit.h b/include/mysql/plugin_audit.h index 31589f071f0..cbdd6591b70 100644 --- a/include/mysql/plugin_audit.h +++ b/include/mysql/plugin_audit.h @@ -23,6 +23,10 @@ #include "plugin.h" +#ifdef __cplusplus +extern "C" { +#endif + #define MYSQL_AUDIT_CLASS_MASK_SIZE 1 #define MYSQL_AUDIT_INTERFACE_VERSION 0x0302 @@ -175,4 +179,8 @@ struct st_mysql_audit }; +#ifdef __cplusplus +} +#endif + #endif diff --git a/include/mysql/plugin_audit.h.pp b/include/mysql/plugin_audit.h.pp index 2f8edfe192f..d014edfedb9 100644 --- a/include/mysql/plugin_audit.h.pp +++ b/include/mysql/plugin_audit.h.pp @@ -1,75 +1,98 @@ typedef char my_bool; typedef void * MYSQL_PLUGIN; -extern struct my_snprintf_service_st { - size_t (*my_snprintf_type)(char*, size_t, const char*, ...); - size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list); -} *my_snprintf_service; -size_t my_snprintf(char* to, size_t n, const char* fmt, ...); -size_t my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap); -struct st_mysql_lex_string +extern struct base64_service_st { + int (*base64_needed_encoded_length_ptr)(int length_of_data); + int (*base64_encode_max_arg_length_ptr)(void); + int (*base64_needed_decoded_length_ptr)(int length_of_encoded_data); + int (*base64_decode_max_arg_length_ptr)(); + int (*base64_encode_ptr)(const void *src, size_t src_len, char *dst); + int (*base64_decode_ptr)(const char *src, size_t src_len, + void *dst, const char **end_ptr, int flags); +} *base64_service; +int base64_needed_encoded_length(int length_of_data); +int base64_encode_max_arg_length(void); +int base64_needed_decoded_length(int length_of_encoded_data); +int base64_decode_max_arg_length(); +int base64_encode(const void *src, size_t src_len, char *dst); +int base64_decode(const char *src, size_t src_len, + void *dst, const char **end_ptr, int flags); +extern void (*debug_sync_C_callback_ptr)(void*, const char *, size_t); +struct encryption_service_st { + unsigned int (*encryption_key_get_latest_version_func)(unsigned int key_id); + unsigned int (*encryption_key_get_func)(unsigned int key_id, unsigned int key_version, + unsigned char* buffer, unsigned int* length); + unsigned int (*encryption_ctx_size_func)(unsigned int key_id, unsigned int key_version); + int (*encryption_ctx_init_func)(void *ctx, const unsigned char* key, unsigned int klen, + const unsigned char* iv, unsigned int ivlen, + int flags, unsigned int key_id, + unsigned int key_version); + int (*encryption_ctx_update_func)(void *ctx, const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen); + int (*encryption_ctx_finish_func)(void *ctx, unsigned char* dst, unsigned int* dlen); + unsigned int (*encryption_encrypted_length_func)(unsigned int slen, unsigned int key_id, unsigned int key_version); +}; +extern struct encryption_service_st encryption_handler; +static inline unsigned int encryption_key_id_exists(unsigned int id) { - char *str; - size_t length; + return encryption_handler.encryption_key_get_latest_version_func(id) != (~(unsigned int)0); +} +static inline unsigned int encryption_key_version_exists(unsigned int id, unsigned int version) +{ + unsigned int unused; + return encryption_handler.encryption_key_get_func((id),(version),(NULL),(&unused)) != (~(unsigned int)0); +} +static inline int encryption_crypt(const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + const unsigned char* key, unsigned int klen, + const unsigned char* iv, unsigned int ivlen, + int flags, unsigned int key_id, unsigned int key_version) +{ + void *ctx= alloca(encryption_handler.encryption_ctx_size_func((key_id),(key_version))); + int res1, res2; + unsigned int d1, d2; + if ((res1= encryption_handler.encryption_ctx_init_func((ctx),(key),(klen),(iv),(ivlen),(flags),(key_id),(key_version)))) + return res1; + res1= encryption_handler.encryption_ctx_update_func((ctx),(src),(slen),(dst),(&d1)); + res2= encryption_handler.encryption_ctx_finish_func((ctx),(dst + d1),(&d2)); + *dlen= d1 + d2; + return res1 ? res1 : res2; +} +struct st_encryption_scheme_key { + unsigned int version; + unsigned char key[16]; }; -typedef struct st_mysql_lex_string MYSQL_LEX_STRING; -extern struct thd_alloc_service_st { - void *(*thd_alloc_func)(void*, unsigned int); - void *(*thd_calloc_func)(void*, unsigned int); - char *(*thd_strdup_func)(void*, const char *); - char *(*thd_strmake_func)(void*, const char *, unsigned int); - void *(*thd_memdup_func)(void*, const void*, unsigned int); - MYSQL_LEX_STRING *(*thd_make_lex_string_func)(void*, MYSQL_LEX_STRING *, - const char *, unsigned int, int); -} *thd_alloc_service; -void *thd_alloc(void* thd, unsigned int size); -void *thd_calloc(void* thd, unsigned int size); -char *thd_strdup(void* thd, const char *str); -char *thd_strmake(void* thd, const char *str, unsigned int size); -void *thd_memdup(void* thd, const void* str, unsigned int size); -MYSQL_LEX_STRING *thd_make_lex_string(void* thd, MYSQL_LEX_STRING *lex_str, - const char *str, unsigned int size, - int allocate_lex_string); -typedef enum _thd_wait_type_e { - THD_WAIT_SLEEP= 1, - THD_WAIT_DISKIO= 2, - THD_WAIT_ROW_LOCK= 3, - THD_WAIT_GLOBAL_LOCK= 4, - THD_WAIT_META_DATA_LOCK= 5, - THD_WAIT_TABLE_LOCK= 6, - THD_WAIT_USER_LOCK= 7, - THD_WAIT_BINLOG= 8, - THD_WAIT_GROUP_COMMIT= 9, - THD_WAIT_SYNC= 10, - THD_WAIT_NET= 11, - THD_WAIT_LAST= 12 -} thd_wait_type; -extern struct thd_wait_service_st { - void (*thd_wait_begin_func)(void*, int); - void (*thd_wait_end_func)(void*); -} *thd_wait_service; -void thd_wait_begin(void* thd, int wait_type); -void thd_wait_end(void* thd); -extern struct progress_report_service_st { - void (*thd_progress_init_func)(void* thd, unsigned int max_stage); - void (*thd_progress_report_func)(void* thd, - unsigned long long progress, - unsigned long long max_progress); - void (*thd_progress_next_stage_func)(void* thd); - void (*thd_progress_end_func)(void* thd); - const char *(*set_thd_proc_info_func)(void*, const char *info, - const char *func, - const char *file, - unsigned int line); -} *progress_report_service; -void thd_progress_init(void* thd, unsigned int max_stage); -void thd_progress_report(void* thd, - unsigned long long progress, - unsigned long long max_progress); -void thd_progress_next_stage(void* thd); -void thd_progress_end(void* thd); -const char *set_thd_proc_info(void*, const char * info, const char *func, - const char *file, unsigned int line); -extern void (*debug_sync_C_callback_ptr)(void*, const char *, size_t); +struct st_encryption_scheme { + unsigned char iv[16]; + struct st_encryption_scheme_key key[3]; + unsigned int keyserver_requests; + unsigned int key_id; + unsigned int type; + void (*locker)(struct st_encryption_scheme *self, int release); +}; +extern struct encryption_scheme_service_st { + int (*encryption_scheme_encrypt_func) + (const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + struct st_encryption_scheme *scheme, + unsigned int key_version, unsigned int i32_1, + unsigned int i32_2, unsigned long long i64); + int (*encryption_scheme_decrypt_func) + (const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + struct st_encryption_scheme *scheme, + unsigned int key_version, unsigned int i32_1, + unsigned int i32_2, unsigned long long i64); +} *encryption_scheme_service; +int encryption_scheme_encrypt(const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + struct st_encryption_scheme *scheme, + unsigned int key_version, unsigned int i32_1, + unsigned int i32_2, unsigned long long i64); +int encryption_scheme_decrypt(const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + struct st_encryption_scheme *scheme, + unsigned int key_version, unsigned int i32_1, + unsigned int i32_2, unsigned long long i64); enum thd_kill_levels { THD_IS_NOT_KILLED=0, THD_ABORT_SOFTLY=50, @@ -79,31 +102,6 @@ extern struct kill_statement_service_st { enum thd_kill_levels (*thd_kill_level_func)(const void*); } *thd_kill_statement_service; enum thd_kill_levels thd_kill_level(const void*); -typedef long my_time_t; -enum enum_mysql_timestamp_type -{ - MYSQL_TIMESTAMP_NONE= -2, MYSQL_TIMESTAMP_ERROR= -1, - MYSQL_TIMESTAMP_DATE= 0, MYSQL_TIMESTAMP_DATETIME= 1, MYSQL_TIMESTAMP_TIME= 2 -}; -typedef struct st_mysql_time -{ - unsigned int year, month, day, hour, minute, second; - unsigned long second_part; - my_bool neg; - enum enum_mysql_timestamp_type time_type; -} MYSQL_TIME; -extern struct thd_timezone_service_st { - my_time_t (*thd_TIME_to_gmt_sec)(void* thd, const MYSQL_TIME *ltime, unsigned int *errcode); - void (*thd_gmt_sec_to_TIME)(void* thd, MYSQL_TIME *ltime, my_time_t t); -} *thd_timezone_service; -my_time_t thd_TIME_to_gmt_sec(void* thd, const MYSQL_TIME *ltime, unsigned int *errcode); -void thd_gmt_sec_to_TIME(void* thd, MYSQL_TIME *ltime, my_time_t t); -extern struct my_sha1_service_st { - void (*my_sha1_type)(unsigned char*, const char*, size_t); - void (*my_sha1_multi_type)(unsigned char*, ...); -} *my_sha1_service; -void my_sha1(unsigned char*, const char*, size_t); -void my_sha1_multi(unsigned char*, ...); typedef struct logger_handle_st LOGGER_HANDLE; extern struct logger_service_st { void (*logger_init_mutexes)(); @@ -125,6 +123,170 @@ extern struct logger_service_st { int logger_printf(LOGGER_HANDLE *log, const char *fmt, ...); int logger_write(LOGGER_HANDLE *log, const char *buffer, size_t size); int logger_rotate(LOGGER_HANDLE *log); +extern struct my_md5_service_st { + void (*my_md5_type)(unsigned char*, const char*, size_t); + void (*my_md5_multi_type)(unsigned char*, ...); + size_t (*my_md5_context_size_type)(); + void (*my_md5_init_type)(void *); + void (*my_md5_input_type)(void *, const unsigned char *, size_t); + void (*my_md5_result_type)(void *, unsigned char *); +} *my_md5_service; +void my_md5(unsigned char*, const char*, size_t); +void my_md5_multi(unsigned char*, ...); +size_t my_md5_context_size(); +void my_md5_init(void *context); +void my_md5_input(void *context, const unsigned char *buf, size_t len); +void my_md5_result(void *context, unsigned char *digest); +enum my_aes_mode { + MY_AES_ECB, MY_AES_CBC +}; +extern struct my_crypt_service_st { + int (*my_aes_crypt_init)(void *ctx, enum my_aes_mode mode, int flags, + const unsigned char* key, unsigned int klen, + const unsigned char* iv, unsigned int ivlen); + int (*my_aes_crypt_update)(void *ctx, const unsigned char *src, unsigned int slen, + unsigned char *dst, unsigned int *dlen); + int (*my_aes_crypt_finish)(void *ctx, unsigned char *dst, unsigned int *dlen); + int (*my_aes_crypt)(enum my_aes_mode mode, int flags, + const unsigned char *src, unsigned int slen, unsigned char *dst, unsigned int *dlen, + const unsigned char *key, unsigned int klen, const unsigned char *iv, unsigned int ivlen); + unsigned int (*my_aes_get_size)(enum my_aes_mode mode, unsigned int source_length); + unsigned int (*my_aes_ctx_size)(enum my_aes_mode mode); + int (*my_random_bytes)(unsigned char* buf, int num); +} *my_crypt_service; +int my_aes_crypt_init(void *ctx, enum my_aes_mode mode, int flags, + const unsigned char* key, unsigned int klen, + const unsigned char* iv, unsigned int ivlen); +int my_aes_crypt_update(void *ctx, const unsigned char *src, unsigned int slen, + unsigned char *dst, unsigned int *dlen); +int my_aes_crypt_finish(void *ctx, unsigned char *dst, unsigned int *dlen); +int my_aes_crypt(enum my_aes_mode mode, int flags, + const unsigned char *src, unsigned int slen, unsigned char *dst, unsigned int *dlen, + const unsigned char *key, unsigned int klen, const unsigned char *iv, unsigned int ivlen); +int my_random_bytes(unsigned char* buf, int num); +unsigned int my_aes_get_size(enum my_aes_mode mode, unsigned int source_length); +unsigned int my_aes_ctx_size(enum my_aes_mode mode); +extern struct my_print_error_service_st { + void(*my_error_func)(unsigned int nr, unsigned long MyFlags, ...); + void(*my_printf_error_func)(unsigned int nr, const char *fmt, unsigned long MyFlags,...); + void(*my_printv_error_func)(unsigned int error, const char *format, unsigned long MyFlags, va_list ap); +} *my_print_error_service; +extern void my_error(unsigned int nr, unsigned long MyFlags, ...); +extern void my_printf_error(unsigned int my_err, const char *format, unsigned long MyFlags, ...); +extern void my_printv_error(unsigned int error, const char *format, unsigned long MyFlags,va_list ap); +extern struct my_snprintf_service_st { + size_t (*my_snprintf_type)(char*, size_t, const char*, ...); + size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list); +} *my_snprintf_service; +size_t my_snprintf(char* to, size_t n, const char* fmt, ...); +size_t my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap); +extern struct progress_report_service_st { + void (*thd_progress_init_func)(void* thd, unsigned int max_stage); + void (*thd_progress_report_func)(void* thd, + unsigned long long progress, + unsigned long long max_progress); + void (*thd_progress_next_stage_func)(void* thd); + void (*thd_progress_end_func)(void* thd); + const char *(*set_thd_proc_info_func)(void*, const char *info, + const char *func, + const char *file, + unsigned int line); +} *progress_report_service; +void thd_progress_init(void* thd, unsigned int max_stage); +void thd_progress_report(void* thd, + unsigned long long progress, + unsigned long long max_progress); +void thd_progress_next_stage(void* thd); +void thd_progress_end(void* thd); +const char *set_thd_proc_info(void*, const char * info, const char *func, + const char *file, unsigned int line); +extern struct my_sha1_service_st { + void (*my_sha1_type)(unsigned char*, const char*, size_t); + void (*my_sha1_multi_type)(unsigned char*, ...); + size_t (*my_sha1_context_size_type)(); + void (*my_sha1_init_type)(void *); + void (*my_sha1_input_type)(void *, const unsigned char *, size_t); + void (*my_sha1_result_type)(void *, unsigned char *); +} *my_sha1_service; +void my_sha1(unsigned char*, const char*, size_t); +void my_sha1_multi(unsigned char*, ...); +size_t my_sha1_context_size(); +void my_sha1_init(void *context); +void my_sha1_input(void *context, const unsigned char *buf, size_t len); +void my_sha1_result(void *context, unsigned char *digest); +extern struct my_sha2_service_st { + void (*my_sha224_type)(unsigned char*, const char*, size_t); + void (*my_sha224_multi_type)(unsigned char*, ...); + size_t (*my_sha224_context_size_type)(); + void (*my_sha224_init_type)(void *); + void (*my_sha224_input_type)(void *, const unsigned char *, size_t); + void (*my_sha224_result_type)(void *, unsigned char *); + void (*my_sha256_type)(unsigned char*, const char*, size_t); + void (*my_sha256_multi_type)(unsigned char*, ...); + size_t (*my_sha256_context_size_type)(); + void (*my_sha256_init_type)(void *); + void (*my_sha256_input_type)(void *, const unsigned char *, size_t); + void (*my_sha256_result_type)(void *, unsigned char *); + void (*my_sha384_type)(unsigned char*, const char*, size_t); + void (*my_sha384_multi_type)(unsigned char*, ...); + size_t (*my_sha384_context_size_type)(); + void (*my_sha384_init_type)(void *); + void (*my_sha384_input_type)(void *, const unsigned char *, size_t); + void (*my_sha384_result_type)(void *, unsigned char *); + void (*my_sha512_type)(unsigned char*, const char*, size_t); + void (*my_sha512_multi_type)(unsigned char*, ...); + size_t (*my_sha512_context_size_type)(); + void (*my_sha512_init_type)(void *); + void (*my_sha512_input_type)(void *, const unsigned char *, size_t); + void (*my_sha512_result_type)(void *, unsigned char *); +} *my_sha2_service; +void my_sha224(unsigned char*, const char*, size_t); +void my_sha224_multi(unsigned char*, ...); +size_t my_sha224_context_size(); +void my_sha224_init(void *context); +void my_sha224_input(void *context, const unsigned char *buf, size_t len); +void my_sha224_result(void *context, unsigned char *digest); +void my_sha256(unsigned char*, const char*, size_t); +void my_sha256_multi(unsigned char*, ...); +size_t my_sha256_context_size(); +void my_sha256_init(void *context); +void my_sha256_input(void *context, const unsigned char *buf, size_t len); +void my_sha256_result(void *context, unsigned char *digest); +void my_sha384(unsigned char*, const char*, size_t); +void my_sha384_multi(unsigned char*, ...); +size_t my_sha384_context_size(); +void my_sha384_init(void *context); +void my_sha384_input(void *context, const unsigned char *buf, size_t len); +void my_sha384_result(void *context, unsigned char *digest); +void my_sha512(unsigned char*, const char*, size_t); +void my_sha512_multi(unsigned char*, ...); +size_t my_sha512_context_size(); +void my_sha512_init(void *context); +void my_sha512_input(void *context, const unsigned char *buf, size_t len); +void my_sha512_result(void *context, unsigned char *digest); +struct st_mysql_lex_string +{ + char *str; + size_t length; +}; +typedef struct st_mysql_lex_string MYSQL_LEX_STRING; +extern struct thd_alloc_service_st { + void *(*thd_alloc_func)(void*, unsigned int); + void *(*thd_calloc_func)(void*, unsigned int); + char *(*thd_strdup_func)(void*, const char *); + char *(*thd_strmake_func)(void*, const char *, unsigned int); + void *(*thd_memdup_func)(void*, const void*, unsigned int); + MYSQL_LEX_STRING *(*thd_make_lex_string_func)(void*, MYSQL_LEX_STRING *, + const char *, unsigned int, int); +} *thd_alloc_service; +void *thd_alloc(void* thd, unsigned int size); +void *thd_calloc(void* thd, unsigned int size); +char *thd_strdup(void* thd, const char *str); +char *thd_strmake(void* thd, const char *str, unsigned int size); +void *thd_memdup(void* thd, const void* str, unsigned int size); +MYSQL_LEX_STRING *thd_make_lex_string(void* thd, MYSQL_LEX_STRING *lex_str, + const char *str, unsigned int size, + int allocate_lex_string); extern struct thd_autoinc_service_st { void (*thd_get_autoinc_func)(const void* thd, unsigned long* off, unsigned long* inc); @@ -148,6 +310,62 @@ void thd_inc_error_row(void* thd); char *thd_get_error_context_description(void* thd, char *buffer, unsigned int length, unsigned int max_query_length); +extern struct thd_rnd_service_st { + double (*thd_rnd_ptr)(void* thd); + void (*thd_c_r_p_ptr)(void* thd, char *to, size_t length); +} *thd_rnd_service; +double thd_rnd(void* thd); +void thd_create_random_password(void* thd, char *to, size_t length); +typedef int MYSQL_THD_KEY_T; +extern struct thd_specifics_service_st { + int (*thd_key_create_func)(MYSQL_THD_KEY_T *key); + void (*thd_key_delete_func)(MYSQL_THD_KEY_T *key); + void *(*thd_getspecific_func)(void* thd, MYSQL_THD_KEY_T key); + int (*thd_setspecific_func)(void* thd, MYSQL_THD_KEY_T key, void *value); +} *thd_specifics_service; +int thd_key_create(MYSQL_THD_KEY_T *key); +void thd_key_delete(MYSQL_THD_KEY_T *key); +void* thd_getspecific(void* thd, MYSQL_THD_KEY_T key); +int thd_setspecific(void* thd, MYSQL_THD_KEY_T key, void *value); +typedef long my_time_t; +enum enum_mysql_timestamp_type +{ + MYSQL_TIMESTAMP_NONE= -2, MYSQL_TIMESTAMP_ERROR= -1, + MYSQL_TIMESTAMP_DATE= 0, MYSQL_TIMESTAMP_DATETIME= 1, MYSQL_TIMESTAMP_TIME= 2 +}; +typedef struct st_mysql_time +{ + unsigned int year, month, day, hour, minute, second; + unsigned long second_part; + my_bool neg; + enum enum_mysql_timestamp_type time_type; +} MYSQL_TIME; +extern struct thd_timezone_service_st { + my_time_t (*thd_TIME_to_gmt_sec)(void* thd, const MYSQL_TIME *ltime, unsigned int *errcode); + void (*thd_gmt_sec_to_TIME)(void* thd, MYSQL_TIME *ltime, my_time_t t); +} *thd_timezone_service; +my_time_t thd_TIME_to_gmt_sec(void* thd, const MYSQL_TIME *ltime, unsigned int *errcode); +void thd_gmt_sec_to_TIME(void* thd, MYSQL_TIME *ltime, my_time_t t); +typedef enum _thd_wait_type_e { + THD_WAIT_SLEEP= 1, + THD_WAIT_DISKIO= 2, + THD_WAIT_ROW_LOCK= 3, + THD_WAIT_GLOBAL_LOCK= 4, + THD_WAIT_META_DATA_LOCK= 5, + THD_WAIT_TABLE_LOCK= 6, + THD_WAIT_USER_LOCK= 7, + THD_WAIT_BINLOG= 8, + THD_WAIT_GROUP_COMMIT= 9, + THD_WAIT_SYNC= 10, + THD_WAIT_NET= 11, + THD_WAIT_LAST= 12 +} thd_wait_type; +extern struct thd_wait_service_st { + void (*thd_wait_begin_func)(void*, int); + void (*thd_wait_end_func)(void*); +} *thd_wait_service; +void thd_wait_begin(void* thd, int wait_type); +void thd_wait_end(void* thd); struct st_mysql_xid { long formatID; long gtrid_length; @@ -163,12 +381,17 @@ enum enum_mysql_show_type SHOW_SINT, SHOW_SLONG, SHOW_SLONGLONG, SHOW_SIMPLE_FUNC, SHOW_always_last }; +enum enum_var_type +{ + SHOW_OPT_DEFAULT= 0, SHOW_OPT_SESSION, SHOW_OPT_GLOBAL +}; struct st_mysql_show_var { const char *name; - char *value; + void *value; enum enum_mysql_show_type type; }; -typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *); +struct system_status_var; +typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, void *, struct system_status_var *status_var, enum enum_var_type); struct st_mysql_sys_var; struct st_mysql_value; typedef int (*mysql_var_check_func)(void* thd, diff --git a/include/mysql/plugin_auth.h b/include/mysql/plugin_auth.h index 156fb386aae..807bfd4e652 100644 --- a/include/mysql/plugin_auth.h +++ b/include/mysql/plugin_auth.h @@ -27,10 +27,14 @@ #include <mysql/plugin.h> -#define MYSQL_AUTHENTICATION_INTERFACE_VERSION 0x0200 +#define MYSQL_AUTHENTICATION_INTERFACE_VERSION 0x0201 #include <mysql/plugin_auth_common.h> +#ifdef __cplusplus +extern "C" { +#endif + /* defines for MYSQL_SERVER_AUTH_INFO.password_used */ #define PASSWORD_USED_NO 0 @@ -101,6 +105,11 @@ typedef struct st_mysql_server_auth_info */ unsigned int host_or_ip_length; + /** + Current THD pointer (to use with various services) + */ + MYSQL_THD thd; + } MYSQL_SERVER_AUTH_INFO; /** @@ -122,5 +131,10 @@ struct st_mysql_auth */ int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info); }; + +#ifdef __cplusplus +} +#endif + #endif diff --git a/include/mysql/plugin_auth.h.pp b/include/mysql/plugin_auth.h.pp index d052c550896..9dd3deba8de 100644 --- a/include/mysql/plugin_auth.h.pp +++ b/include/mysql/plugin_auth.h.pp @@ -1,75 +1,98 @@ typedef char my_bool; typedef void * MYSQL_PLUGIN; -extern struct my_snprintf_service_st { - size_t (*my_snprintf_type)(char*, size_t, const char*, ...); - size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list); -} *my_snprintf_service; -size_t my_snprintf(char* to, size_t n, const char* fmt, ...); -size_t my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap); -struct st_mysql_lex_string +extern struct base64_service_st { + int (*base64_needed_encoded_length_ptr)(int length_of_data); + int (*base64_encode_max_arg_length_ptr)(void); + int (*base64_needed_decoded_length_ptr)(int length_of_encoded_data); + int (*base64_decode_max_arg_length_ptr)(); + int (*base64_encode_ptr)(const void *src, size_t src_len, char *dst); + int (*base64_decode_ptr)(const char *src, size_t src_len, + void *dst, const char **end_ptr, int flags); +} *base64_service; +int base64_needed_encoded_length(int length_of_data); +int base64_encode_max_arg_length(void); +int base64_needed_decoded_length(int length_of_encoded_data); +int base64_decode_max_arg_length(); +int base64_encode(const void *src, size_t src_len, char *dst); +int base64_decode(const char *src, size_t src_len, + void *dst, const char **end_ptr, int flags); +extern void (*debug_sync_C_callback_ptr)(void*, const char *, size_t); +struct encryption_service_st { + unsigned int (*encryption_key_get_latest_version_func)(unsigned int key_id); + unsigned int (*encryption_key_get_func)(unsigned int key_id, unsigned int key_version, + unsigned char* buffer, unsigned int* length); + unsigned int (*encryption_ctx_size_func)(unsigned int key_id, unsigned int key_version); + int (*encryption_ctx_init_func)(void *ctx, const unsigned char* key, unsigned int klen, + const unsigned char* iv, unsigned int ivlen, + int flags, unsigned int key_id, + unsigned int key_version); + int (*encryption_ctx_update_func)(void *ctx, const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen); + int (*encryption_ctx_finish_func)(void *ctx, unsigned char* dst, unsigned int* dlen); + unsigned int (*encryption_encrypted_length_func)(unsigned int slen, unsigned int key_id, unsigned int key_version); +}; +extern struct encryption_service_st encryption_handler; +static inline unsigned int encryption_key_id_exists(unsigned int id) { - char *str; - size_t length; + return encryption_handler.encryption_key_get_latest_version_func(id) != (~(unsigned int)0); +} +static inline unsigned int encryption_key_version_exists(unsigned int id, unsigned int version) +{ + unsigned int unused; + return encryption_handler.encryption_key_get_func((id),(version),(NULL),(&unused)) != (~(unsigned int)0); +} +static inline int encryption_crypt(const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + const unsigned char* key, unsigned int klen, + const unsigned char* iv, unsigned int ivlen, + int flags, unsigned int key_id, unsigned int key_version) +{ + void *ctx= alloca(encryption_handler.encryption_ctx_size_func((key_id),(key_version))); + int res1, res2; + unsigned int d1, d2; + if ((res1= encryption_handler.encryption_ctx_init_func((ctx),(key),(klen),(iv),(ivlen),(flags),(key_id),(key_version)))) + return res1; + res1= encryption_handler.encryption_ctx_update_func((ctx),(src),(slen),(dst),(&d1)); + res2= encryption_handler.encryption_ctx_finish_func((ctx),(dst + d1),(&d2)); + *dlen= d1 + d2; + return res1 ? res1 : res2; +} +struct st_encryption_scheme_key { + unsigned int version; + unsigned char key[16]; }; -typedef struct st_mysql_lex_string MYSQL_LEX_STRING; -extern struct thd_alloc_service_st { - void *(*thd_alloc_func)(void*, unsigned int); - void *(*thd_calloc_func)(void*, unsigned int); - char *(*thd_strdup_func)(void*, const char *); - char *(*thd_strmake_func)(void*, const char *, unsigned int); - void *(*thd_memdup_func)(void*, const void*, unsigned int); - MYSQL_LEX_STRING *(*thd_make_lex_string_func)(void*, MYSQL_LEX_STRING *, - const char *, unsigned int, int); -} *thd_alloc_service; -void *thd_alloc(void* thd, unsigned int size); -void *thd_calloc(void* thd, unsigned int size); -char *thd_strdup(void* thd, const char *str); -char *thd_strmake(void* thd, const char *str, unsigned int size); -void *thd_memdup(void* thd, const void* str, unsigned int size); -MYSQL_LEX_STRING *thd_make_lex_string(void* thd, MYSQL_LEX_STRING *lex_str, - const char *str, unsigned int size, - int allocate_lex_string); -typedef enum _thd_wait_type_e { - THD_WAIT_SLEEP= 1, - THD_WAIT_DISKIO= 2, - THD_WAIT_ROW_LOCK= 3, - THD_WAIT_GLOBAL_LOCK= 4, - THD_WAIT_META_DATA_LOCK= 5, - THD_WAIT_TABLE_LOCK= 6, - THD_WAIT_USER_LOCK= 7, - THD_WAIT_BINLOG= 8, - THD_WAIT_GROUP_COMMIT= 9, - THD_WAIT_SYNC= 10, - THD_WAIT_NET= 11, - THD_WAIT_LAST= 12 -} thd_wait_type; -extern struct thd_wait_service_st { - void (*thd_wait_begin_func)(void*, int); - void (*thd_wait_end_func)(void*); -} *thd_wait_service; -void thd_wait_begin(void* thd, int wait_type); -void thd_wait_end(void* thd); -extern struct progress_report_service_st { - void (*thd_progress_init_func)(void* thd, unsigned int max_stage); - void (*thd_progress_report_func)(void* thd, - unsigned long long progress, - unsigned long long max_progress); - void (*thd_progress_next_stage_func)(void* thd); - void (*thd_progress_end_func)(void* thd); - const char *(*set_thd_proc_info_func)(void*, const char *info, - const char *func, - const char *file, - unsigned int line); -} *progress_report_service; -void thd_progress_init(void* thd, unsigned int max_stage); -void thd_progress_report(void* thd, - unsigned long long progress, - unsigned long long max_progress); -void thd_progress_next_stage(void* thd); -void thd_progress_end(void* thd); -const char *set_thd_proc_info(void*, const char * info, const char *func, - const char *file, unsigned int line); -extern void (*debug_sync_C_callback_ptr)(void*, const char *, size_t); +struct st_encryption_scheme { + unsigned char iv[16]; + struct st_encryption_scheme_key key[3]; + unsigned int keyserver_requests; + unsigned int key_id; + unsigned int type; + void (*locker)(struct st_encryption_scheme *self, int release); +}; +extern struct encryption_scheme_service_st { + int (*encryption_scheme_encrypt_func) + (const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + struct st_encryption_scheme *scheme, + unsigned int key_version, unsigned int i32_1, + unsigned int i32_2, unsigned long long i64); + int (*encryption_scheme_decrypt_func) + (const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + struct st_encryption_scheme *scheme, + unsigned int key_version, unsigned int i32_1, + unsigned int i32_2, unsigned long long i64); +} *encryption_scheme_service; +int encryption_scheme_encrypt(const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + struct st_encryption_scheme *scheme, + unsigned int key_version, unsigned int i32_1, + unsigned int i32_2, unsigned long long i64); +int encryption_scheme_decrypt(const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + struct st_encryption_scheme *scheme, + unsigned int key_version, unsigned int i32_1, + unsigned int i32_2, unsigned long long i64); enum thd_kill_levels { THD_IS_NOT_KILLED=0, THD_ABORT_SOFTLY=50, @@ -79,31 +102,6 @@ extern struct kill_statement_service_st { enum thd_kill_levels (*thd_kill_level_func)(const void*); } *thd_kill_statement_service; enum thd_kill_levels thd_kill_level(const void*); -typedef long my_time_t; -enum enum_mysql_timestamp_type -{ - MYSQL_TIMESTAMP_NONE= -2, MYSQL_TIMESTAMP_ERROR= -1, - MYSQL_TIMESTAMP_DATE= 0, MYSQL_TIMESTAMP_DATETIME= 1, MYSQL_TIMESTAMP_TIME= 2 -}; -typedef struct st_mysql_time -{ - unsigned int year, month, day, hour, minute, second; - unsigned long second_part; - my_bool neg; - enum enum_mysql_timestamp_type time_type; -} MYSQL_TIME; -extern struct thd_timezone_service_st { - my_time_t (*thd_TIME_to_gmt_sec)(void* thd, const MYSQL_TIME *ltime, unsigned int *errcode); - void (*thd_gmt_sec_to_TIME)(void* thd, MYSQL_TIME *ltime, my_time_t t); -} *thd_timezone_service; -my_time_t thd_TIME_to_gmt_sec(void* thd, const MYSQL_TIME *ltime, unsigned int *errcode); -void thd_gmt_sec_to_TIME(void* thd, MYSQL_TIME *ltime, my_time_t t); -extern struct my_sha1_service_st { - void (*my_sha1_type)(unsigned char*, const char*, size_t); - void (*my_sha1_multi_type)(unsigned char*, ...); -} *my_sha1_service; -void my_sha1(unsigned char*, const char*, size_t); -void my_sha1_multi(unsigned char*, ...); typedef struct logger_handle_st LOGGER_HANDLE; extern struct logger_service_st { void (*logger_init_mutexes)(); @@ -125,6 +123,170 @@ extern struct logger_service_st { int logger_printf(LOGGER_HANDLE *log, const char *fmt, ...); int logger_write(LOGGER_HANDLE *log, const char *buffer, size_t size); int logger_rotate(LOGGER_HANDLE *log); +extern struct my_md5_service_st { + void (*my_md5_type)(unsigned char*, const char*, size_t); + void (*my_md5_multi_type)(unsigned char*, ...); + size_t (*my_md5_context_size_type)(); + void (*my_md5_init_type)(void *); + void (*my_md5_input_type)(void *, const unsigned char *, size_t); + void (*my_md5_result_type)(void *, unsigned char *); +} *my_md5_service; +void my_md5(unsigned char*, const char*, size_t); +void my_md5_multi(unsigned char*, ...); +size_t my_md5_context_size(); +void my_md5_init(void *context); +void my_md5_input(void *context, const unsigned char *buf, size_t len); +void my_md5_result(void *context, unsigned char *digest); +enum my_aes_mode { + MY_AES_ECB, MY_AES_CBC +}; +extern struct my_crypt_service_st { + int (*my_aes_crypt_init)(void *ctx, enum my_aes_mode mode, int flags, + const unsigned char* key, unsigned int klen, + const unsigned char* iv, unsigned int ivlen); + int (*my_aes_crypt_update)(void *ctx, const unsigned char *src, unsigned int slen, + unsigned char *dst, unsigned int *dlen); + int (*my_aes_crypt_finish)(void *ctx, unsigned char *dst, unsigned int *dlen); + int (*my_aes_crypt)(enum my_aes_mode mode, int flags, + const unsigned char *src, unsigned int slen, unsigned char *dst, unsigned int *dlen, + const unsigned char *key, unsigned int klen, const unsigned char *iv, unsigned int ivlen); + unsigned int (*my_aes_get_size)(enum my_aes_mode mode, unsigned int source_length); + unsigned int (*my_aes_ctx_size)(enum my_aes_mode mode); + int (*my_random_bytes)(unsigned char* buf, int num); +} *my_crypt_service; +int my_aes_crypt_init(void *ctx, enum my_aes_mode mode, int flags, + const unsigned char* key, unsigned int klen, + const unsigned char* iv, unsigned int ivlen); +int my_aes_crypt_update(void *ctx, const unsigned char *src, unsigned int slen, + unsigned char *dst, unsigned int *dlen); +int my_aes_crypt_finish(void *ctx, unsigned char *dst, unsigned int *dlen); +int my_aes_crypt(enum my_aes_mode mode, int flags, + const unsigned char *src, unsigned int slen, unsigned char *dst, unsigned int *dlen, + const unsigned char *key, unsigned int klen, const unsigned char *iv, unsigned int ivlen); +int my_random_bytes(unsigned char* buf, int num); +unsigned int my_aes_get_size(enum my_aes_mode mode, unsigned int source_length); +unsigned int my_aes_ctx_size(enum my_aes_mode mode); +extern struct my_print_error_service_st { + void(*my_error_func)(unsigned int nr, unsigned long MyFlags, ...); + void(*my_printf_error_func)(unsigned int nr, const char *fmt, unsigned long MyFlags,...); + void(*my_printv_error_func)(unsigned int error, const char *format, unsigned long MyFlags, va_list ap); +} *my_print_error_service; +extern void my_error(unsigned int nr, unsigned long MyFlags, ...); +extern void my_printf_error(unsigned int my_err, const char *format, unsigned long MyFlags, ...); +extern void my_printv_error(unsigned int error, const char *format, unsigned long MyFlags,va_list ap); +extern struct my_snprintf_service_st { + size_t (*my_snprintf_type)(char*, size_t, const char*, ...); + size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list); +} *my_snprintf_service; +size_t my_snprintf(char* to, size_t n, const char* fmt, ...); +size_t my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap); +extern struct progress_report_service_st { + void (*thd_progress_init_func)(void* thd, unsigned int max_stage); + void (*thd_progress_report_func)(void* thd, + unsigned long long progress, + unsigned long long max_progress); + void (*thd_progress_next_stage_func)(void* thd); + void (*thd_progress_end_func)(void* thd); + const char *(*set_thd_proc_info_func)(void*, const char *info, + const char *func, + const char *file, + unsigned int line); +} *progress_report_service; +void thd_progress_init(void* thd, unsigned int max_stage); +void thd_progress_report(void* thd, + unsigned long long progress, + unsigned long long max_progress); +void thd_progress_next_stage(void* thd); +void thd_progress_end(void* thd); +const char *set_thd_proc_info(void*, const char * info, const char *func, + const char *file, unsigned int line); +extern struct my_sha1_service_st { + void (*my_sha1_type)(unsigned char*, const char*, size_t); + void (*my_sha1_multi_type)(unsigned char*, ...); + size_t (*my_sha1_context_size_type)(); + void (*my_sha1_init_type)(void *); + void (*my_sha1_input_type)(void *, const unsigned char *, size_t); + void (*my_sha1_result_type)(void *, unsigned char *); +} *my_sha1_service; +void my_sha1(unsigned char*, const char*, size_t); +void my_sha1_multi(unsigned char*, ...); +size_t my_sha1_context_size(); +void my_sha1_init(void *context); +void my_sha1_input(void *context, const unsigned char *buf, size_t len); +void my_sha1_result(void *context, unsigned char *digest); +extern struct my_sha2_service_st { + void (*my_sha224_type)(unsigned char*, const char*, size_t); + void (*my_sha224_multi_type)(unsigned char*, ...); + size_t (*my_sha224_context_size_type)(); + void (*my_sha224_init_type)(void *); + void (*my_sha224_input_type)(void *, const unsigned char *, size_t); + void (*my_sha224_result_type)(void *, unsigned char *); + void (*my_sha256_type)(unsigned char*, const char*, size_t); + void (*my_sha256_multi_type)(unsigned char*, ...); + size_t (*my_sha256_context_size_type)(); + void (*my_sha256_init_type)(void *); + void (*my_sha256_input_type)(void *, const unsigned char *, size_t); + void (*my_sha256_result_type)(void *, unsigned char *); + void (*my_sha384_type)(unsigned char*, const char*, size_t); + void (*my_sha384_multi_type)(unsigned char*, ...); + size_t (*my_sha384_context_size_type)(); + void (*my_sha384_init_type)(void *); + void (*my_sha384_input_type)(void *, const unsigned char *, size_t); + void (*my_sha384_result_type)(void *, unsigned char *); + void (*my_sha512_type)(unsigned char*, const char*, size_t); + void (*my_sha512_multi_type)(unsigned char*, ...); + size_t (*my_sha512_context_size_type)(); + void (*my_sha512_init_type)(void *); + void (*my_sha512_input_type)(void *, const unsigned char *, size_t); + void (*my_sha512_result_type)(void *, unsigned char *); +} *my_sha2_service; +void my_sha224(unsigned char*, const char*, size_t); +void my_sha224_multi(unsigned char*, ...); +size_t my_sha224_context_size(); +void my_sha224_init(void *context); +void my_sha224_input(void *context, const unsigned char *buf, size_t len); +void my_sha224_result(void *context, unsigned char *digest); +void my_sha256(unsigned char*, const char*, size_t); +void my_sha256_multi(unsigned char*, ...); +size_t my_sha256_context_size(); +void my_sha256_init(void *context); +void my_sha256_input(void *context, const unsigned char *buf, size_t len); +void my_sha256_result(void *context, unsigned char *digest); +void my_sha384(unsigned char*, const char*, size_t); +void my_sha384_multi(unsigned char*, ...); +size_t my_sha384_context_size(); +void my_sha384_init(void *context); +void my_sha384_input(void *context, const unsigned char *buf, size_t len); +void my_sha384_result(void *context, unsigned char *digest); +void my_sha512(unsigned char*, const char*, size_t); +void my_sha512_multi(unsigned char*, ...); +size_t my_sha512_context_size(); +void my_sha512_init(void *context); +void my_sha512_input(void *context, const unsigned char *buf, size_t len); +void my_sha512_result(void *context, unsigned char *digest); +struct st_mysql_lex_string +{ + char *str; + size_t length; +}; +typedef struct st_mysql_lex_string MYSQL_LEX_STRING; +extern struct thd_alloc_service_st { + void *(*thd_alloc_func)(void*, unsigned int); + void *(*thd_calloc_func)(void*, unsigned int); + char *(*thd_strdup_func)(void*, const char *); + char *(*thd_strmake_func)(void*, const char *, unsigned int); + void *(*thd_memdup_func)(void*, const void*, unsigned int); + MYSQL_LEX_STRING *(*thd_make_lex_string_func)(void*, MYSQL_LEX_STRING *, + const char *, unsigned int, int); +} *thd_alloc_service; +void *thd_alloc(void* thd, unsigned int size); +void *thd_calloc(void* thd, unsigned int size); +char *thd_strdup(void* thd, const char *str); +char *thd_strmake(void* thd, const char *str, unsigned int size); +void *thd_memdup(void* thd, const void* str, unsigned int size); +MYSQL_LEX_STRING *thd_make_lex_string(void* thd, MYSQL_LEX_STRING *lex_str, + const char *str, unsigned int size, + int allocate_lex_string); extern struct thd_autoinc_service_st { void (*thd_get_autoinc_func)(const void* thd, unsigned long* off, unsigned long* inc); @@ -148,6 +310,62 @@ void thd_inc_error_row(void* thd); char *thd_get_error_context_description(void* thd, char *buffer, unsigned int length, unsigned int max_query_length); +extern struct thd_rnd_service_st { + double (*thd_rnd_ptr)(void* thd); + void (*thd_c_r_p_ptr)(void* thd, char *to, size_t length); +} *thd_rnd_service; +double thd_rnd(void* thd); +void thd_create_random_password(void* thd, char *to, size_t length); +typedef int MYSQL_THD_KEY_T; +extern struct thd_specifics_service_st { + int (*thd_key_create_func)(MYSQL_THD_KEY_T *key); + void (*thd_key_delete_func)(MYSQL_THD_KEY_T *key); + void *(*thd_getspecific_func)(void* thd, MYSQL_THD_KEY_T key); + int (*thd_setspecific_func)(void* thd, MYSQL_THD_KEY_T key, void *value); +} *thd_specifics_service; +int thd_key_create(MYSQL_THD_KEY_T *key); +void thd_key_delete(MYSQL_THD_KEY_T *key); +void* thd_getspecific(void* thd, MYSQL_THD_KEY_T key); +int thd_setspecific(void* thd, MYSQL_THD_KEY_T key, void *value); +typedef long my_time_t; +enum enum_mysql_timestamp_type +{ + MYSQL_TIMESTAMP_NONE= -2, MYSQL_TIMESTAMP_ERROR= -1, + MYSQL_TIMESTAMP_DATE= 0, MYSQL_TIMESTAMP_DATETIME= 1, MYSQL_TIMESTAMP_TIME= 2 +}; +typedef struct st_mysql_time +{ + unsigned int year, month, day, hour, minute, second; + unsigned long second_part; + my_bool neg; + enum enum_mysql_timestamp_type time_type; +} MYSQL_TIME; +extern struct thd_timezone_service_st { + my_time_t (*thd_TIME_to_gmt_sec)(void* thd, const MYSQL_TIME *ltime, unsigned int *errcode); + void (*thd_gmt_sec_to_TIME)(void* thd, MYSQL_TIME *ltime, my_time_t t); +} *thd_timezone_service; +my_time_t thd_TIME_to_gmt_sec(void* thd, const MYSQL_TIME *ltime, unsigned int *errcode); +void thd_gmt_sec_to_TIME(void* thd, MYSQL_TIME *ltime, my_time_t t); +typedef enum _thd_wait_type_e { + THD_WAIT_SLEEP= 1, + THD_WAIT_DISKIO= 2, + THD_WAIT_ROW_LOCK= 3, + THD_WAIT_GLOBAL_LOCK= 4, + THD_WAIT_META_DATA_LOCK= 5, + THD_WAIT_TABLE_LOCK= 6, + THD_WAIT_USER_LOCK= 7, + THD_WAIT_BINLOG= 8, + THD_WAIT_GROUP_COMMIT= 9, + THD_WAIT_SYNC= 10, + THD_WAIT_NET= 11, + THD_WAIT_LAST= 12 +} thd_wait_type; +extern struct thd_wait_service_st { + void (*thd_wait_begin_func)(void*, int); + void (*thd_wait_end_func)(void*); +} *thd_wait_service; +void thd_wait_begin(void* thd, int wait_type); +void thd_wait_end(void* thd); struct st_mysql_xid { long formatID; long gtrid_length; @@ -163,12 +381,17 @@ enum enum_mysql_show_type SHOW_SINT, SHOW_SLONG, SHOW_SLONGLONG, SHOW_SIMPLE_FUNC, SHOW_always_last }; +enum enum_var_type +{ + SHOW_OPT_DEFAULT= 0, SHOW_OPT_SESSION, SHOW_OPT_GLOBAL +}; struct st_mysql_show_var { const char *name; - char *value; + void *value; enum enum_mysql_show_type type; }; -typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *); +struct system_status_var; +typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, void *, struct system_status_var *status_var, enum enum_var_type); struct st_mysql_sys_var; struct st_mysql_value; typedef int (*mysql_var_check_func)(void* thd, @@ -324,6 +547,7 @@ typedef struct st_mysql_server_auth_info int password_used; const char *host_or_ip; unsigned int host_or_ip_length; + void* thd; } MYSQL_SERVER_AUTH_INFO; struct st_mysql_auth { diff --git a/include/mysql/plugin_encryption.h b/include/mysql/plugin_encryption.h new file mode 100644 index 00000000000..5d08f6d3067 --- /dev/null +++ b/include/mysql/plugin_encryption.h @@ -0,0 +1,126 @@ +#ifndef MYSQL_PLUGIN_ENCRYPTION_INCLUDED +/* Copyright (C) 2014, 2015 Sergei Golubchik and MariaDB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + 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 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 */ + +/** + @file + + Encryption Plugin API. + + This file defines the API for server plugins that manage encryption + keys for MariaDB on-disk data encryption. +*/ + +#define MYSQL_PLUGIN_ENCRYPTION_INCLUDED + +#include <mysql/plugin.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#define MariaDB_ENCRYPTION_INTERFACE_VERSION 0x0300 + +/** + Encryption plugin descriptor +*/ +struct st_mariadb_encryption +{ + int interface_version; /**< version plugin uses */ + + /*********** KEY MANAGEMENT ********************************************/ + + /** + function returning latest key version for a given key id + + @return a version or ENCRYPTION_KEY_VERSION_INVALID to indicate an error. + */ + unsigned int (*get_latest_key_version)(unsigned int key_id); + + /** + function returning a key for a key version + + @param version the requested key version + @param key the key will be stored there. Can be NULL - + in which case no key will be returned + @param key_length in: key buffer size + out: the actual length of the key + + This method can be used to query the key length - the required + buffer size - by passing key==NULL. + + If the buffer size is less than the key length the content of the + key buffer is undefined (the plugin is free to partially fill it with + the key data or leave it untouched). + + @return 0 on success, or + ENCRYPTION_KEY_VERSION_INVALID, ENCRYPTION_KEY_BUFFER_TOO_SMALL + or any other non-zero number for errors + */ + unsigned int (*get_key)(unsigned int key_id, unsigned int version, + unsigned char *key, unsigned int *key_length); + + /*********** ENCRYPTION ************************************************/ + /* + the caller uses encryption as follows: + 1. create the encryption context object of the crypt_ctx_size() bytes. + 2. initialize it with crypt_ctx_init(). + 3. repeat crypt_ctx_update() until there are no more data to encrypt. + 4. write the remaining output bytes and destroy the context object + with crypt_ctx_finish(). + */ + + /** + returns the size of the encryption context object in bytes + */ + unsigned int (*crypt_ctx_size)(unsigned int key_id, unsigned int key_version); + /** + initializes the encryption context object. + */ + int (*crypt_ctx_init)(void *ctx, const unsigned char* key, unsigned int klen, + const unsigned char* iv, unsigned int ivlen, + int flags, unsigned int key_id, + unsigned int key_version); + /** + processes (encrypts or decrypts) a chunk of data + + writes the output to th dst buffer. note that it might write + more bytes that were in the input. or less. or none at all. + */ + int (*crypt_ctx_update)(void *ctx, const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen); + /** + writes the remaining output bytes and destroys the encryption context + + crypt_ctx_update might've cached part of the output in the context, + this method will flush these data out. + */ + int (*crypt_ctx_finish)(void *ctx, unsigned char* dst, unsigned int* dlen); + /** + returns the length of the encrypted data + + it returns the exact length, given only the source length. + which means, this API only supports encryption algorithms where + the length of the encrypted data only depends on the length of the + input (a.k.a. compression is not supported). + */ + unsigned int (*encrypted_length)(unsigned int slen, unsigned int key_id, unsigned int key_version); +}; + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/include/mysql/plugin_encryption.h.pp b/include/mysql/plugin_encryption.h.pp new file mode 100644 index 00000000000..7bb81614971 --- /dev/null +++ b/include/mysql/plugin_encryption.h.pp @@ -0,0 +1,539 @@ +typedef char my_bool; +typedef void * MYSQL_PLUGIN; +extern struct base64_service_st { + int (*base64_needed_encoded_length_ptr)(int length_of_data); + int (*base64_encode_max_arg_length_ptr)(void); + int (*base64_needed_decoded_length_ptr)(int length_of_encoded_data); + int (*base64_decode_max_arg_length_ptr)(); + int (*base64_encode_ptr)(const void *src, size_t src_len, char *dst); + int (*base64_decode_ptr)(const char *src, size_t src_len, + void *dst, const char **end_ptr, int flags); +} *base64_service; +int base64_needed_encoded_length(int length_of_data); +int base64_encode_max_arg_length(void); +int base64_needed_decoded_length(int length_of_encoded_data); +int base64_decode_max_arg_length(); +int base64_encode(const void *src, size_t src_len, char *dst); +int base64_decode(const char *src, size_t src_len, + void *dst, const char **end_ptr, int flags); +extern void (*debug_sync_C_callback_ptr)(void*, const char *, size_t); +struct encryption_service_st { + unsigned int (*encryption_key_get_latest_version_func)(unsigned int key_id); + unsigned int (*encryption_key_get_func)(unsigned int key_id, unsigned int key_version, + unsigned char* buffer, unsigned int* length); + unsigned int (*encryption_ctx_size_func)(unsigned int key_id, unsigned int key_version); + int (*encryption_ctx_init_func)(void *ctx, const unsigned char* key, unsigned int klen, + const unsigned char* iv, unsigned int ivlen, + int flags, unsigned int key_id, + unsigned int key_version); + int (*encryption_ctx_update_func)(void *ctx, const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen); + int (*encryption_ctx_finish_func)(void *ctx, unsigned char* dst, unsigned int* dlen); + unsigned int (*encryption_encrypted_length_func)(unsigned int slen, unsigned int key_id, unsigned int key_version); +}; +extern struct encryption_service_st encryption_handler; +static inline unsigned int encryption_key_id_exists(unsigned int id) +{ + return encryption_handler.encryption_key_get_latest_version_func(id) != (~(unsigned int)0); +} +static inline unsigned int encryption_key_version_exists(unsigned int id, unsigned int version) +{ + unsigned int unused; + return encryption_handler.encryption_key_get_func((id),(version),(NULL),(&unused)) != (~(unsigned int)0); +} +static inline int encryption_crypt(const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + const unsigned char* key, unsigned int klen, + const unsigned char* iv, unsigned int ivlen, + int flags, unsigned int key_id, unsigned int key_version) +{ + void *ctx= alloca(encryption_handler.encryption_ctx_size_func((key_id),(key_version))); + int res1, res2; + unsigned int d1, d2; + if ((res1= encryption_handler.encryption_ctx_init_func((ctx),(key),(klen),(iv),(ivlen),(flags),(key_id),(key_version)))) + return res1; + res1= encryption_handler.encryption_ctx_update_func((ctx),(src),(slen),(dst),(&d1)); + res2= encryption_handler.encryption_ctx_finish_func((ctx),(dst + d1),(&d2)); + *dlen= d1 + d2; + return res1 ? res1 : res2; +} +struct st_encryption_scheme_key { + unsigned int version; + unsigned char key[16]; +}; +struct st_encryption_scheme { + unsigned char iv[16]; + struct st_encryption_scheme_key key[3]; + unsigned int keyserver_requests; + unsigned int key_id; + unsigned int type; + void (*locker)(struct st_encryption_scheme *self, int release); +}; +extern struct encryption_scheme_service_st { + int (*encryption_scheme_encrypt_func) + (const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + struct st_encryption_scheme *scheme, + unsigned int key_version, unsigned int i32_1, + unsigned int i32_2, unsigned long long i64); + int (*encryption_scheme_decrypt_func) + (const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + struct st_encryption_scheme *scheme, + unsigned int key_version, unsigned int i32_1, + unsigned int i32_2, unsigned long long i64); +} *encryption_scheme_service; +int encryption_scheme_encrypt(const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + struct st_encryption_scheme *scheme, + unsigned int key_version, unsigned int i32_1, + unsigned int i32_2, unsigned long long i64); +int encryption_scheme_decrypt(const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + struct st_encryption_scheme *scheme, + unsigned int key_version, unsigned int i32_1, + unsigned int i32_2, unsigned long long i64); +enum thd_kill_levels { + THD_IS_NOT_KILLED=0, + THD_ABORT_SOFTLY=50, + THD_ABORT_ASAP=100, +}; +extern struct kill_statement_service_st { + enum thd_kill_levels (*thd_kill_level_func)(const void*); +} *thd_kill_statement_service; +enum thd_kill_levels thd_kill_level(const void*); +typedef struct logger_handle_st LOGGER_HANDLE; +extern struct logger_service_st { + void (*logger_init_mutexes)(); + LOGGER_HANDLE* (*open)(const char *path, + unsigned long long size_limit, + unsigned int rotations); + int (*close)(LOGGER_HANDLE *log); + int (*vprintf)(LOGGER_HANDLE *log, const char *fmt, va_list argptr); + int (*printf)(LOGGER_HANDLE *log, const char *fmt, ...); + int (*write)(LOGGER_HANDLE *log, const char *buffer, size_t size); + int (*rotate)(LOGGER_HANDLE *log); +} *logger_service; + void logger_init_mutexes(); + LOGGER_HANDLE *logger_open(const char *path, + unsigned long long size_limit, + unsigned int rotations); + int logger_close(LOGGER_HANDLE *log); + int logger_vprintf(LOGGER_HANDLE *log, const char *fmt, va_list argptr); + int logger_printf(LOGGER_HANDLE *log, const char *fmt, ...); + int logger_write(LOGGER_HANDLE *log, const char *buffer, size_t size); + int logger_rotate(LOGGER_HANDLE *log); +extern struct my_md5_service_st { + void (*my_md5_type)(unsigned char*, const char*, size_t); + void (*my_md5_multi_type)(unsigned char*, ...); + size_t (*my_md5_context_size_type)(); + void (*my_md5_init_type)(void *); + void (*my_md5_input_type)(void *, const unsigned char *, size_t); + void (*my_md5_result_type)(void *, unsigned char *); +} *my_md5_service; +void my_md5(unsigned char*, const char*, size_t); +void my_md5_multi(unsigned char*, ...); +size_t my_md5_context_size(); +void my_md5_init(void *context); +void my_md5_input(void *context, const unsigned char *buf, size_t len); +void my_md5_result(void *context, unsigned char *digest); +enum my_aes_mode { + MY_AES_ECB, MY_AES_CBC +}; +extern struct my_crypt_service_st { + int (*my_aes_crypt_init)(void *ctx, enum my_aes_mode mode, int flags, + const unsigned char* key, unsigned int klen, + const unsigned char* iv, unsigned int ivlen); + int (*my_aes_crypt_update)(void *ctx, const unsigned char *src, unsigned int slen, + unsigned char *dst, unsigned int *dlen); + int (*my_aes_crypt_finish)(void *ctx, unsigned char *dst, unsigned int *dlen); + int (*my_aes_crypt)(enum my_aes_mode mode, int flags, + const unsigned char *src, unsigned int slen, unsigned char *dst, unsigned int *dlen, + const unsigned char *key, unsigned int klen, const unsigned char *iv, unsigned int ivlen); + unsigned int (*my_aes_get_size)(enum my_aes_mode mode, unsigned int source_length); + unsigned int (*my_aes_ctx_size)(enum my_aes_mode mode); + int (*my_random_bytes)(unsigned char* buf, int num); +} *my_crypt_service; +int my_aes_crypt_init(void *ctx, enum my_aes_mode mode, int flags, + const unsigned char* key, unsigned int klen, + const unsigned char* iv, unsigned int ivlen); +int my_aes_crypt_update(void *ctx, const unsigned char *src, unsigned int slen, + unsigned char *dst, unsigned int *dlen); +int my_aes_crypt_finish(void *ctx, unsigned char *dst, unsigned int *dlen); +int my_aes_crypt(enum my_aes_mode mode, int flags, + const unsigned char *src, unsigned int slen, unsigned char *dst, unsigned int *dlen, + const unsigned char *key, unsigned int klen, const unsigned char *iv, unsigned int ivlen); +int my_random_bytes(unsigned char* buf, int num); +unsigned int my_aes_get_size(enum my_aes_mode mode, unsigned int source_length); +unsigned int my_aes_ctx_size(enum my_aes_mode mode); +extern struct my_print_error_service_st { + void(*my_error_func)(unsigned int nr, unsigned long MyFlags, ...); + void(*my_printf_error_func)(unsigned int nr, const char *fmt, unsigned long MyFlags,...); + void(*my_printv_error_func)(unsigned int error, const char *format, unsigned long MyFlags, va_list ap); +} *my_print_error_service; +extern void my_error(unsigned int nr, unsigned long MyFlags, ...); +extern void my_printf_error(unsigned int my_err, const char *format, unsigned long MyFlags, ...); +extern void my_printv_error(unsigned int error, const char *format, unsigned long MyFlags,va_list ap); +extern struct my_snprintf_service_st { + size_t (*my_snprintf_type)(char*, size_t, const char*, ...); + size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list); +} *my_snprintf_service; +size_t my_snprintf(char* to, size_t n, const char* fmt, ...); +size_t my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap); +extern struct progress_report_service_st { + void (*thd_progress_init_func)(void* thd, unsigned int max_stage); + void (*thd_progress_report_func)(void* thd, + unsigned long long progress, + unsigned long long max_progress); + void (*thd_progress_next_stage_func)(void* thd); + void (*thd_progress_end_func)(void* thd); + const char *(*set_thd_proc_info_func)(void*, const char *info, + const char *func, + const char *file, + unsigned int line); +} *progress_report_service; +void thd_progress_init(void* thd, unsigned int max_stage); +void thd_progress_report(void* thd, + unsigned long long progress, + unsigned long long max_progress); +void thd_progress_next_stage(void* thd); +void thd_progress_end(void* thd); +const char *set_thd_proc_info(void*, const char * info, const char *func, + const char *file, unsigned int line); +extern struct my_sha1_service_st { + void (*my_sha1_type)(unsigned char*, const char*, size_t); + void (*my_sha1_multi_type)(unsigned char*, ...); + size_t (*my_sha1_context_size_type)(); + void (*my_sha1_init_type)(void *); + void (*my_sha1_input_type)(void *, const unsigned char *, size_t); + void (*my_sha1_result_type)(void *, unsigned char *); +} *my_sha1_service; +void my_sha1(unsigned char*, const char*, size_t); +void my_sha1_multi(unsigned char*, ...); +size_t my_sha1_context_size(); +void my_sha1_init(void *context); +void my_sha1_input(void *context, const unsigned char *buf, size_t len); +void my_sha1_result(void *context, unsigned char *digest); +extern struct my_sha2_service_st { + void (*my_sha224_type)(unsigned char*, const char*, size_t); + void (*my_sha224_multi_type)(unsigned char*, ...); + size_t (*my_sha224_context_size_type)(); + void (*my_sha224_init_type)(void *); + void (*my_sha224_input_type)(void *, const unsigned char *, size_t); + void (*my_sha224_result_type)(void *, unsigned char *); + void (*my_sha256_type)(unsigned char*, const char*, size_t); + void (*my_sha256_multi_type)(unsigned char*, ...); + size_t (*my_sha256_context_size_type)(); + void (*my_sha256_init_type)(void *); + void (*my_sha256_input_type)(void *, const unsigned char *, size_t); + void (*my_sha256_result_type)(void *, unsigned char *); + void (*my_sha384_type)(unsigned char*, const char*, size_t); + void (*my_sha384_multi_type)(unsigned char*, ...); + size_t (*my_sha384_context_size_type)(); + void (*my_sha384_init_type)(void *); + void (*my_sha384_input_type)(void *, const unsigned char *, size_t); + void (*my_sha384_result_type)(void *, unsigned char *); + void (*my_sha512_type)(unsigned char*, const char*, size_t); + void (*my_sha512_multi_type)(unsigned char*, ...); + size_t (*my_sha512_context_size_type)(); + void (*my_sha512_init_type)(void *); + void (*my_sha512_input_type)(void *, const unsigned char *, size_t); + void (*my_sha512_result_type)(void *, unsigned char *); +} *my_sha2_service; +void my_sha224(unsigned char*, const char*, size_t); +void my_sha224_multi(unsigned char*, ...); +size_t my_sha224_context_size(); +void my_sha224_init(void *context); +void my_sha224_input(void *context, const unsigned char *buf, size_t len); +void my_sha224_result(void *context, unsigned char *digest); +void my_sha256(unsigned char*, const char*, size_t); +void my_sha256_multi(unsigned char*, ...); +size_t my_sha256_context_size(); +void my_sha256_init(void *context); +void my_sha256_input(void *context, const unsigned char *buf, size_t len); +void my_sha256_result(void *context, unsigned char *digest); +void my_sha384(unsigned char*, const char*, size_t); +void my_sha384_multi(unsigned char*, ...); +size_t my_sha384_context_size(); +void my_sha384_init(void *context); +void my_sha384_input(void *context, const unsigned char *buf, size_t len); +void my_sha384_result(void *context, unsigned char *digest); +void my_sha512(unsigned char*, const char*, size_t); +void my_sha512_multi(unsigned char*, ...); +size_t my_sha512_context_size(); +void my_sha512_init(void *context); +void my_sha512_input(void *context, const unsigned char *buf, size_t len); +void my_sha512_result(void *context, unsigned char *digest); +struct st_mysql_lex_string +{ + char *str; + size_t length; +}; +typedef struct st_mysql_lex_string MYSQL_LEX_STRING; +extern struct thd_alloc_service_st { + void *(*thd_alloc_func)(void*, unsigned int); + void *(*thd_calloc_func)(void*, unsigned int); + char *(*thd_strdup_func)(void*, const char *); + char *(*thd_strmake_func)(void*, const char *, unsigned int); + void *(*thd_memdup_func)(void*, const void*, unsigned int); + MYSQL_LEX_STRING *(*thd_make_lex_string_func)(void*, MYSQL_LEX_STRING *, + const char *, unsigned int, int); +} *thd_alloc_service; +void *thd_alloc(void* thd, unsigned int size); +void *thd_calloc(void* thd, unsigned int size); +char *thd_strdup(void* thd, const char *str); +char *thd_strmake(void* thd, const char *str, unsigned int size); +void *thd_memdup(void* thd, const void* str, unsigned int size); +MYSQL_LEX_STRING *thd_make_lex_string(void* thd, MYSQL_LEX_STRING *lex_str, + const char *str, unsigned int size, + int allocate_lex_string); +extern struct thd_autoinc_service_st { + void (*thd_get_autoinc_func)(const void* thd, + unsigned long* off, unsigned long* inc); +} *thd_autoinc_service; +void thd_get_autoinc(const void* thd, + unsigned long* off, unsigned long* inc); +extern struct thd_error_context_service_st { + const char *(*thd_get_error_message_func)(const void* thd); + unsigned int (*thd_get_error_number_func)(const void* thd); + unsigned long (*thd_get_error_row_func)(const void* thd); + void (*thd_inc_error_row_func)(void* thd); + char *(*thd_get_error_context_description_func)(void* thd, + char *buffer, + unsigned int length, + unsigned int max_query_length); +} *thd_error_context_service; +const char *thd_get_error_message(const void* thd); +unsigned int thd_get_error_number(const void* thd); +unsigned long thd_get_error_row(const void* thd); +void thd_inc_error_row(void* thd); +char *thd_get_error_context_description(void* thd, + char *buffer, unsigned int length, + unsigned int max_query_length); +extern struct thd_rnd_service_st { + double (*thd_rnd_ptr)(void* thd); + void (*thd_c_r_p_ptr)(void* thd, char *to, size_t length); +} *thd_rnd_service; +double thd_rnd(void* thd); +void thd_create_random_password(void* thd, char *to, size_t length); +typedef int MYSQL_THD_KEY_T; +extern struct thd_specifics_service_st { + int (*thd_key_create_func)(MYSQL_THD_KEY_T *key); + void (*thd_key_delete_func)(MYSQL_THD_KEY_T *key); + void *(*thd_getspecific_func)(void* thd, MYSQL_THD_KEY_T key); + int (*thd_setspecific_func)(void* thd, MYSQL_THD_KEY_T key, void *value); +} *thd_specifics_service; +int thd_key_create(MYSQL_THD_KEY_T *key); +void thd_key_delete(MYSQL_THD_KEY_T *key); +void* thd_getspecific(void* thd, MYSQL_THD_KEY_T key); +int thd_setspecific(void* thd, MYSQL_THD_KEY_T key, void *value); +typedef long my_time_t; +enum enum_mysql_timestamp_type +{ + MYSQL_TIMESTAMP_NONE= -2, MYSQL_TIMESTAMP_ERROR= -1, + MYSQL_TIMESTAMP_DATE= 0, MYSQL_TIMESTAMP_DATETIME= 1, MYSQL_TIMESTAMP_TIME= 2 +}; +typedef struct st_mysql_time +{ + unsigned int year, month, day, hour, minute, second; + unsigned long second_part; + my_bool neg; + enum enum_mysql_timestamp_type time_type; +} MYSQL_TIME; +extern struct thd_timezone_service_st { + my_time_t (*thd_TIME_to_gmt_sec)(void* thd, const MYSQL_TIME *ltime, unsigned int *errcode); + void (*thd_gmt_sec_to_TIME)(void* thd, MYSQL_TIME *ltime, my_time_t t); +} *thd_timezone_service; +my_time_t thd_TIME_to_gmt_sec(void* thd, const MYSQL_TIME *ltime, unsigned int *errcode); +void thd_gmt_sec_to_TIME(void* thd, MYSQL_TIME *ltime, my_time_t t); +typedef enum _thd_wait_type_e { + THD_WAIT_SLEEP= 1, + THD_WAIT_DISKIO= 2, + THD_WAIT_ROW_LOCK= 3, + THD_WAIT_GLOBAL_LOCK= 4, + THD_WAIT_META_DATA_LOCK= 5, + THD_WAIT_TABLE_LOCK= 6, + THD_WAIT_USER_LOCK= 7, + THD_WAIT_BINLOG= 8, + THD_WAIT_GROUP_COMMIT= 9, + THD_WAIT_SYNC= 10, + THD_WAIT_NET= 11, + THD_WAIT_LAST= 12 +} thd_wait_type; +extern struct thd_wait_service_st { + void (*thd_wait_begin_func)(void*, int); + void (*thd_wait_end_func)(void*); +} *thd_wait_service; +void thd_wait_begin(void* thd, int wait_type); +void thd_wait_end(void* thd); +struct st_mysql_xid { + long formatID; + long gtrid_length; + long bqual_length; + char data[128]; +}; +typedef struct st_mysql_xid MYSQL_XID; +enum enum_mysql_show_type +{ + SHOW_UNDEF, SHOW_BOOL, SHOW_UINT, SHOW_ULONG, + SHOW_ULONGLONG, SHOW_CHAR, SHOW_CHAR_PTR, + SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE, + SHOW_SINT, SHOW_SLONG, SHOW_SLONGLONG, SHOW_SIMPLE_FUNC, + SHOW_always_last +}; +enum enum_var_type +{ + SHOW_OPT_DEFAULT= 0, SHOW_OPT_SESSION, SHOW_OPT_GLOBAL +}; +struct st_mysql_show_var { + const char *name; + void *value; + enum enum_mysql_show_type type; +}; +struct system_status_var; +typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, void *, struct system_status_var *status_var, enum enum_var_type); +struct st_mysql_sys_var; +struct st_mysql_value; +typedef int (*mysql_var_check_func)(void* thd, + struct st_mysql_sys_var *var, + void *save, struct st_mysql_value *value); +typedef void (*mysql_var_update_func)(void* thd, + struct st_mysql_sys_var *var, + void *var_ptr, const void *save); +struct st_mysql_plugin +{ + int type; + void *info; + const char *name; + const char *author; + const char *descr; + int license; + int (*init)(void *); + int (*deinit)(void *); + unsigned int version; + struct st_mysql_show_var *status_vars; + struct st_mysql_sys_var **system_vars; + void * __reserved1; + unsigned long flags; +}; +struct st_maria_plugin +{ + int type; + void *info; + const char *name; + const char *author; + const char *descr; + int license; + int (*init)(void *); + int (*deinit)(void *); + unsigned int version; + struct st_mysql_show_var *status_vars; + struct st_mysql_sys_var **system_vars; + const char *version_info; + unsigned int maturity; +}; +enum enum_ftparser_mode +{ + MYSQL_FTPARSER_SIMPLE_MODE= 0, + MYSQL_FTPARSER_WITH_STOPWORDS= 1, + MYSQL_FTPARSER_FULL_BOOLEAN_INFO= 2 +}; +enum enum_ft_token_type +{ + FT_TOKEN_EOF= 0, + FT_TOKEN_WORD= 1, + FT_TOKEN_LEFT_PAREN= 2, + FT_TOKEN_RIGHT_PAREN= 3, + FT_TOKEN_STOPWORD= 4 +}; +typedef struct st_mysql_ftparser_boolean_info +{ + enum enum_ft_token_type type; + int yesno; + int weight_adjust; + char wasign; + char trunc; + char prev; + char *quot; +} MYSQL_FTPARSER_BOOLEAN_INFO; +typedef struct st_mysql_ftparser_param +{ + int (*mysql_parse)(struct st_mysql_ftparser_param *, + const char *doc, int doc_len); + int (*mysql_add_word)(struct st_mysql_ftparser_param *, + const char *word, int word_len, + MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info); + void *ftparser_state; + void *mysql_ftparam; + const struct charset_info_st *cs; + const char *doc; + int length; + unsigned int flags; + enum enum_ftparser_mode mode; +} MYSQL_FTPARSER_PARAM; +struct st_mysql_ftparser +{ + int interface_version; + int (*parse)(MYSQL_FTPARSER_PARAM *param); + int (*init)(MYSQL_FTPARSER_PARAM *param); + int (*deinit)(MYSQL_FTPARSER_PARAM *param); +}; +struct st_mysql_daemon +{ + int interface_version; +}; +struct st_mysql_information_schema +{ + int interface_version; +}; +struct st_mysql_storage_engine +{ + int interface_version; +}; +struct handlerton; + struct Mysql_replication { + int interface_version; + }; +struct st_mysql_value +{ + int (*value_type)(struct st_mysql_value *); + const char *(*val_str)(struct st_mysql_value *, char *buffer, int *length); + int (*val_real)(struct st_mysql_value *, double *realbuf); + int (*val_int)(struct st_mysql_value *, long long *intbuf); + int (*is_unsigned)(struct st_mysql_value *); +}; +int thd_in_lock_tables(const void* thd); +int thd_tablespace_op(const void* thd); +long long thd_test_options(const void* thd, long long test_options); +int thd_sql_command(const void* thd); +void **thd_ha_data(const void* thd, const struct handlerton *hton); +void thd_storage_lock_wait(void* thd, long long value); +int thd_tx_isolation(const void* thd); +int thd_tx_is_read_only(const void* thd); +int thd_rpl_is_parallel(const void* thd); +int mysql_tmpfile(const char *prefix); +unsigned long thd_get_thread_id(const void* thd); +void thd_get_xid(const void* thd, MYSQL_XID *xid); +void mysql_query_cache_invalidate4(void* thd, + const char *key, unsigned int key_length, + int using_trx); +void *thd_get_ha_data(const void* thd, const struct handlerton *hton); +void thd_set_ha_data(void* thd, const struct handlerton *hton, + const void *ha_data); +void thd_wakeup_subsequent_commits(void* thd, int wakeup_error); +struct st_mariadb_encryption +{ + int interface_version; + unsigned int (*get_latest_key_version)(unsigned int key_id); + unsigned int (*get_key)(unsigned int key_id, unsigned int version, + unsigned char *key, unsigned int *key_length); + unsigned int (*crypt_ctx_size)(unsigned int key_id, unsigned int key_version); + int (*crypt_ctx_init)(void *ctx, const unsigned char* key, unsigned int klen, + const unsigned char* iv, unsigned int ivlen, + int flags, unsigned int key_id, + unsigned int key_version); + int (*crypt_ctx_update)(void *ctx, const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen); + int (*crypt_ctx_finish)(void *ctx, unsigned char* dst, unsigned int* dlen); + unsigned int (*encrypted_length)(unsigned int slen, unsigned int key_id, unsigned int key_version); +}; diff --git a/include/mysql/plugin_ftparser.h b/include/mysql/plugin_ftparser.h index 324fce7ae86..4dace4ef3a6 100644 --- a/include/mysql/plugin_ftparser.h +++ b/include/mysql/plugin_ftparser.h @@ -18,6 +18,10 @@ #define _my_plugin_ftparser_h #include "plugin.h" +#ifdef __cplusplus +extern "C" { +#endif + /************************************************************************* API for Full-text parser plugin. (MYSQL_FTPARSER_PLUGIN) */ @@ -208,5 +212,9 @@ struct st_mysql_ftparser }; +#ifdef __cplusplus +} +#endif + #endif diff --git a/include/mysql/plugin_ftparser.h.pp b/include/mysql/plugin_ftparser.h.pp index 45eb06974f4..43c02059874 100644 --- a/include/mysql/plugin_ftparser.h.pp +++ b/include/mysql/plugin_ftparser.h.pp @@ -1,75 +1,98 @@ typedef char my_bool; typedef void * MYSQL_PLUGIN; -extern struct my_snprintf_service_st { - size_t (*my_snprintf_type)(char*, size_t, const char*, ...); - size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list); -} *my_snprintf_service; -size_t my_snprintf(char* to, size_t n, const char* fmt, ...); -size_t my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap); -struct st_mysql_lex_string +extern struct base64_service_st { + int (*base64_needed_encoded_length_ptr)(int length_of_data); + int (*base64_encode_max_arg_length_ptr)(void); + int (*base64_needed_decoded_length_ptr)(int length_of_encoded_data); + int (*base64_decode_max_arg_length_ptr)(); + int (*base64_encode_ptr)(const void *src, size_t src_len, char *dst); + int (*base64_decode_ptr)(const char *src, size_t src_len, + void *dst, const char **end_ptr, int flags); +} *base64_service; +int base64_needed_encoded_length(int length_of_data); +int base64_encode_max_arg_length(void); +int base64_needed_decoded_length(int length_of_encoded_data); +int base64_decode_max_arg_length(); +int base64_encode(const void *src, size_t src_len, char *dst); +int base64_decode(const char *src, size_t src_len, + void *dst, const char **end_ptr, int flags); +extern void (*debug_sync_C_callback_ptr)(void*, const char *, size_t); +struct encryption_service_st { + unsigned int (*encryption_key_get_latest_version_func)(unsigned int key_id); + unsigned int (*encryption_key_get_func)(unsigned int key_id, unsigned int key_version, + unsigned char* buffer, unsigned int* length); + unsigned int (*encryption_ctx_size_func)(unsigned int key_id, unsigned int key_version); + int (*encryption_ctx_init_func)(void *ctx, const unsigned char* key, unsigned int klen, + const unsigned char* iv, unsigned int ivlen, + int flags, unsigned int key_id, + unsigned int key_version); + int (*encryption_ctx_update_func)(void *ctx, const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen); + int (*encryption_ctx_finish_func)(void *ctx, unsigned char* dst, unsigned int* dlen); + unsigned int (*encryption_encrypted_length_func)(unsigned int slen, unsigned int key_id, unsigned int key_version); +}; +extern struct encryption_service_st encryption_handler; +static inline unsigned int encryption_key_id_exists(unsigned int id) { - char *str; - size_t length; + return encryption_handler.encryption_key_get_latest_version_func(id) != (~(unsigned int)0); +} +static inline unsigned int encryption_key_version_exists(unsigned int id, unsigned int version) +{ + unsigned int unused; + return encryption_handler.encryption_key_get_func((id),(version),(NULL),(&unused)) != (~(unsigned int)0); +} +static inline int encryption_crypt(const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + const unsigned char* key, unsigned int klen, + const unsigned char* iv, unsigned int ivlen, + int flags, unsigned int key_id, unsigned int key_version) +{ + void *ctx= alloca(encryption_handler.encryption_ctx_size_func((key_id),(key_version))); + int res1, res2; + unsigned int d1, d2; + if ((res1= encryption_handler.encryption_ctx_init_func((ctx),(key),(klen),(iv),(ivlen),(flags),(key_id),(key_version)))) + return res1; + res1= encryption_handler.encryption_ctx_update_func((ctx),(src),(slen),(dst),(&d1)); + res2= encryption_handler.encryption_ctx_finish_func((ctx),(dst + d1),(&d2)); + *dlen= d1 + d2; + return res1 ? res1 : res2; +} +struct st_encryption_scheme_key { + unsigned int version; + unsigned char key[16]; }; -typedef struct st_mysql_lex_string MYSQL_LEX_STRING; -extern struct thd_alloc_service_st { - void *(*thd_alloc_func)(void*, unsigned int); - void *(*thd_calloc_func)(void*, unsigned int); - char *(*thd_strdup_func)(void*, const char *); - char *(*thd_strmake_func)(void*, const char *, unsigned int); - void *(*thd_memdup_func)(void*, const void*, unsigned int); - MYSQL_LEX_STRING *(*thd_make_lex_string_func)(void*, MYSQL_LEX_STRING *, - const char *, unsigned int, int); -} *thd_alloc_service; -void *thd_alloc(void* thd, unsigned int size); -void *thd_calloc(void* thd, unsigned int size); -char *thd_strdup(void* thd, const char *str); -char *thd_strmake(void* thd, const char *str, unsigned int size); -void *thd_memdup(void* thd, const void* str, unsigned int size); -MYSQL_LEX_STRING *thd_make_lex_string(void* thd, MYSQL_LEX_STRING *lex_str, - const char *str, unsigned int size, - int allocate_lex_string); -typedef enum _thd_wait_type_e { - THD_WAIT_SLEEP= 1, - THD_WAIT_DISKIO= 2, - THD_WAIT_ROW_LOCK= 3, - THD_WAIT_GLOBAL_LOCK= 4, - THD_WAIT_META_DATA_LOCK= 5, - THD_WAIT_TABLE_LOCK= 6, - THD_WAIT_USER_LOCK= 7, - THD_WAIT_BINLOG= 8, - THD_WAIT_GROUP_COMMIT= 9, - THD_WAIT_SYNC= 10, - THD_WAIT_NET= 11, - THD_WAIT_LAST= 12 -} thd_wait_type; -extern struct thd_wait_service_st { - void (*thd_wait_begin_func)(void*, int); - void (*thd_wait_end_func)(void*); -} *thd_wait_service; -void thd_wait_begin(void* thd, int wait_type); -void thd_wait_end(void* thd); -extern struct progress_report_service_st { - void (*thd_progress_init_func)(void* thd, unsigned int max_stage); - void (*thd_progress_report_func)(void* thd, - unsigned long long progress, - unsigned long long max_progress); - void (*thd_progress_next_stage_func)(void* thd); - void (*thd_progress_end_func)(void* thd); - const char *(*set_thd_proc_info_func)(void*, const char *info, - const char *func, - const char *file, - unsigned int line); -} *progress_report_service; -void thd_progress_init(void* thd, unsigned int max_stage); -void thd_progress_report(void* thd, - unsigned long long progress, - unsigned long long max_progress); -void thd_progress_next_stage(void* thd); -void thd_progress_end(void* thd); -const char *set_thd_proc_info(void*, const char * info, const char *func, - const char *file, unsigned int line); -extern void (*debug_sync_C_callback_ptr)(void*, const char *, size_t); +struct st_encryption_scheme { + unsigned char iv[16]; + struct st_encryption_scheme_key key[3]; + unsigned int keyserver_requests; + unsigned int key_id; + unsigned int type; + void (*locker)(struct st_encryption_scheme *self, int release); +}; +extern struct encryption_scheme_service_st { + int (*encryption_scheme_encrypt_func) + (const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + struct st_encryption_scheme *scheme, + unsigned int key_version, unsigned int i32_1, + unsigned int i32_2, unsigned long long i64); + int (*encryption_scheme_decrypt_func) + (const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + struct st_encryption_scheme *scheme, + unsigned int key_version, unsigned int i32_1, + unsigned int i32_2, unsigned long long i64); +} *encryption_scheme_service; +int encryption_scheme_encrypt(const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + struct st_encryption_scheme *scheme, + unsigned int key_version, unsigned int i32_1, + unsigned int i32_2, unsigned long long i64); +int encryption_scheme_decrypt(const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + struct st_encryption_scheme *scheme, + unsigned int key_version, unsigned int i32_1, + unsigned int i32_2, unsigned long long i64); enum thd_kill_levels { THD_IS_NOT_KILLED=0, THD_ABORT_SOFTLY=50, @@ -79,31 +102,6 @@ extern struct kill_statement_service_st { enum thd_kill_levels (*thd_kill_level_func)(const void*); } *thd_kill_statement_service; enum thd_kill_levels thd_kill_level(const void*); -typedef long my_time_t; -enum enum_mysql_timestamp_type -{ - MYSQL_TIMESTAMP_NONE= -2, MYSQL_TIMESTAMP_ERROR= -1, - MYSQL_TIMESTAMP_DATE= 0, MYSQL_TIMESTAMP_DATETIME= 1, MYSQL_TIMESTAMP_TIME= 2 -}; -typedef struct st_mysql_time -{ - unsigned int year, month, day, hour, minute, second; - unsigned long second_part; - my_bool neg; - enum enum_mysql_timestamp_type time_type; -} MYSQL_TIME; -extern struct thd_timezone_service_st { - my_time_t (*thd_TIME_to_gmt_sec)(void* thd, const MYSQL_TIME *ltime, unsigned int *errcode); - void (*thd_gmt_sec_to_TIME)(void* thd, MYSQL_TIME *ltime, my_time_t t); -} *thd_timezone_service; -my_time_t thd_TIME_to_gmt_sec(void* thd, const MYSQL_TIME *ltime, unsigned int *errcode); -void thd_gmt_sec_to_TIME(void* thd, MYSQL_TIME *ltime, my_time_t t); -extern struct my_sha1_service_st { - void (*my_sha1_type)(unsigned char*, const char*, size_t); - void (*my_sha1_multi_type)(unsigned char*, ...); -} *my_sha1_service; -void my_sha1(unsigned char*, const char*, size_t); -void my_sha1_multi(unsigned char*, ...); typedef struct logger_handle_st LOGGER_HANDLE; extern struct logger_service_st { void (*logger_init_mutexes)(); @@ -125,6 +123,170 @@ extern struct logger_service_st { int logger_printf(LOGGER_HANDLE *log, const char *fmt, ...); int logger_write(LOGGER_HANDLE *log, const char *buffer, size_t size); int logger_rotate(LOGGER_HANDLE *log); +extern struct my_md5_service_st { + void (*my_md5_type)(unsigned char*, const char*, size_t); + void (*my_md5_multi_type)(unsigned char*, ...); + size_t (*my_md5_context_size_type)(); + void (*my_md5_init_type)(void *); + void (*my_md5_input_type)(void *, const unsigned char *, size_t); + void (*my_md5_result_type)(void *, unsigned char *); +} *my_md5_service; +void my_md5(unsigned char*, const char*, size_t); +void my_md5_multi(unsigned char*, ...); +size_t my_md5_context_size(); +void my_md5_init(void *context); +void my_md5_input(void *context, const unsigned char *buf, size_t len); +void my_md5_result(void *context, unsigned char *digest); +enum my_aes_mode { + MY_AES_ECB, MY_AES_CBC +}; +extern struct my_crypt_service_st { + int (*my_aes_crypt_init)(void *ctx, enum my_aes_mode mode, int flags, + const unsigned char* key, unsigned int klen, + const unsigned char* iv, unsigned int ivlen); + int (*my_aes_crypt_update)(void *ctx, const unsigned char *src, unsigned int slen, + unsigned char *dst, unsigned int *dlen); + int (*my_aes_crypt_finish)(void *ctx, unsigned char *dst, unsigned int *dlen); + int (*my_aes_crypt)(enum my_aes_mode mode, int flags, + const unsigned char *src, unsigned int slen, unsigned char *dst, unsigned int *dlen, + const unsigned char *key, unsigned int klen, const unsigned char *iv, unsigned int ivlen); + unsigned int (*my_aes_get_size)(enum my_aes_mode mode, unsigned int source_length); + unsigned int (*my_aes_ctx_size)(enum my_aes_mode mode); + int (*my_random_bytes)(unsigned char* buf, int num); +} *my_crypt_service; +int my_aes_crypt_init(void *ctx, enum my_aes_mode mode, int flags, + const unsigned char* key, unsigned int klen, + const unsigned char* iv, unsigned int ivlen); +int my_aes_crypt_update(void *ctx, const unsigned char *src, unsigned int slen, + unsigned char *dst, unsigned int *dlen); +int my_aes_crypt_finish(void *ctx, unsigned char *dst, unsigned int *dlen); +int my_aes_crypt(enum my_aes_mode mode, int flags, + const unsigned char *src, unsigned int slen, unsigned char *dst, unsigned int *dlen, + const unsigned char *key, unsigned int klen, const unsigned char *iv, unsigned int ivlen); +int my_random_bytes(unsigned char* buf, int num); +unsigned int my_aes_get_size(enum my_aes_mode mode, unsigned int source_length); +unsigned int my_aes_ctx_size(enum my_aes_mode mode); +extern struct my_print_error_service_st { + void(*my_error_func)(unsigned int nr, unsigned long MyFlags, ...); + void(*my_printf_error_func)(unsigned int nr, const char *fmt, unsigned long MyFlags,...); + void(*my_printv_error_func)(unsigned int error, const char *format, unsigned long MyFlags, va_list ap); +} *my_print_error_service; +extern void my_error(unsigned int nr, unsigned long MyFlags, ...); +extern void my_printf_error(unsigned int my_err, const char *format, unsigned long MyFlags, ...); +extern void my_printv_error(unsigned int error, const char *format, unsigned long MyFlags,va_list ap); +extern struct my_snprintf_service_st { + size_t (*my_snprintf_type)(char*, size_t, const char*, ...); + size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list); +} *my_snprintf_service; +size_t my_snprintf(char* to, size_t n, const char* fmt, ...); +size_t my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap); +extern struct progress_report_service_st { + void (*thd_progress_init_func)(void* thd, unsigned int max_stage); + void (*thd_progress_report_func)(void* thd, + unsigned long long progress, + unsigned long long max_progress); + void (*thd_progress_next_stage_func)(void* thd); + void (*thd_progress_end_func)(void* thd); + const char *(*set_thd_proc_info_func)(void*, const char *info, + const char *func, + const char *file, + unsigned int line); +} *progress_report_service; +void thd_progress_init(void* thd, unsigned int max_stage); +void thd_progress_report(void* thd, + unsigned long long progress, + unsigned long long max_progress); +void thd_progress_next_stage(void* thd); +void thd_progress_end(void* thd); +const char *set_thd_proc_info(void*, const char * info, const char *func, + const char *file, unsigned int line); +extern struct my_sha1_service_st { + void (*my_sha1_type)(unsigned char*, const char*, size_t); + void (*my_sha1_multi_type)(unsigned char*, ...); + size_t (*my_sha1_context_size_type)(); + void (*my_sha1_init_type)(void *); + void (*my_sha1_input_type)(void *, const unsigned char *, size_t); + void (*my_sha1_result_type)(void *, unsigned char *); +} *my_sha1_service; +void my_sha1(unsigned char*, const char*, size_t); +void my_sha1_multi(unsigned char*, ...); +size_t my_sha1_context_size(); +void my_sha1_init(void *context); +void my_sha1_input(void *context, const unsigned char *buf, size_t len); +void my_sha1_result(void *context, unsigned char *digest); +extern struct my_sha2_service_st { + void (*my_sha224_type)(unsigned char*, const char*, size_t); + void (*my_sha224_multi_type)(unsigned char*, ...); + size_t (*my_sha224_context_size_type)(); + void (*my_sha224_init_type)(void *); + void (*my_sha224_input_type)(void *, const unsigned char *, size_t); + void (*my_sha224_result_type)(void *, unsigned char *); + void (*my_sha256_type)(unsigned char*, const char*, size_t); + void (*my_sha256_multi_type)(unsigned char*, ...); + size_t (*my_sha256_context_size_type)(); + void (*my_sha256_init_type)(void *); + void (*my_sha256_input_type)(void *, const unsigned char *, size_t); + void (*my_sha256_result_type)(void *, unsigned char *); + void (*my_sha384_type)(unsigned char*, const char*, size_t); + void (*my_sha384_multi_type)(unsigned char*, ...); + size_t (*my_sha384_context_size_type)(); + void (*my_sha384_init_type)(void *); + void (*my_sha384_input_type)(void *, const unsigned char *, size_t); + void (*my_sha384_result_type)(void *, unsigned char *); + void (*my_sha512_type)(unsigned char*, const char*, size_t); + void (*my_sha512_multi_type)(unsigned char*, ...); + size_t (*my_sha512_context_size_type)(); + void (*my_sha512_init_type)(void *); + void (*my_sha512_input_type)(void *, const unsigned char *, size_t); + void (*my_sha512_result_type)(void *, unsigned char *); +} *my_sha2_service; +void my_sha224(unsigned char*, const char*, size_t); +void my_sha224_multi(unsigned char*, ...); +size_t my_sha224_context_size(); +void my_sha224_init(void *context); +void my_sha224_input(void *context, const unsigned char *buf, size_t len); +void my_sha224_result(void *context, unsigned char *digest); +void my_sha256(unsigned char*, const char*, size_t); +void my_sha256_multi(unsigned char*, ...); +size_t my_sha256_context_size(); +void my_sha256_init(void *context); +void my_sha256_input(void *context, const unsigned char *buf, size_t len); +void my_sha256_result(void *context, unsigned char *digest); +void my_sha384(unsigned char*, const char*, size_t); +void my_sha384_multi(unsigned char*, ...); +size_t my_sha384_context_size(); +void my_sha384_init(void *context); +void my_sha384_input(void *context, const unsigned char *buf, size_t len); +void my_sha384_result(void *context, unsigned char *digest); +void my_sha512(unsigned char*, const char*, size_t); +void my_sha512_multi(unsigned char*, ...); +size_t my_sha512_context_size(); +void my_sha512_init(void *context); +void my_sha512_input(void *context, const unsigned char *buf, size_t len); +void my_sha512_result(void *context, unsigned char *digest); +struct st_mysql_lex_string +{ + char *str; + size_t length; +}; +typedef struct st_mysql_lex_string MYSQL_LEX_STRING; +extern struct thd_alloc_service_st { + void *(*thd_alloc_func)(void*, unsigned int); + void *(*thd_calloc_func)(void*, unsigned int); + char *(*thd_strdup_func)(void*, const char *); + char *(*thd_strmake_func)(void*, const char *, unsigned int); + void *(*thd_memdup_func)(void*, const void*, unsigned int); + MYSQL_LEX_STRING *(*thd_make_lex_string_func)(void*, MYSQL_LEX_STRING *, + const char *, unsigned int, int); +} *thd_alloc_service; +void *thd_alloc(void* thd, unsigned int size); +void *thd_calloc(void* thd, unsigned int size); +char *thd_strdup(void* thd, const char *str); +char *thd_strmake(void* thd, const char *str, unsigned int size); +void *thd_memdup(void* thd, const void* str, unsigned int size); +MYSQL_LEX_STRING *thd_make_lex_string(void* thd, MYSQL_LEX_STRING *lex_str, + const char *str, unsigned int size, + int allocate_lex_string); extern struct thd_autoinc_service_st { void (*thd_get_autoinc_func)(const void* thd, unsigned long* off, unsigned long* inc); @@ -148,6 +310,62 @@ void thd_inc_error_row(void* thd); char *thd_get_error_context_description(void* thd, char *buffer, unsigned int length, unsigned int max_query_length); +extern struct thd_rnd_service_st { + double (*thd_rnd_ptr)(void* thd); + void (*thd_c_r_p_ptr)(void* thd, char *to, size_t length); +} *thd_rnd_service; +double thd_rnd(void* thd); +void thd_create_random_password(void* thd, char *to, size_t length); +typedef int MYSQL_THD_KEY_T; +extern struct thd_specifics_service_st { + int (*thd_key_create_func)(MYSQL_THD_KEY_T *key); + void (*thd_key_delete_func)(MYSQL_THD_KEY_T *key); + void *(*thd_getspecific_func)(void* thd, MYSQL_THD_KEY_T key); + int (*thd_setspecific_func)(void* thd, MYSQL_THD_KEY_T key, void *value); +} *thd_specifics_service; +int thd_key_create(MYSQL_THD_KEY_T *key); +void thd_key_delete(MYSQL_THD_KEY_T *key); +void* thd_getspecific(void* thd, MYSQL_THD_KEY_T key); +int thd_setspecific(void* thd, MYSQL_THD_KEY_T key, void *value); +typedef long my_time_t; +enum enum_mysql_timestamp_type +{ + MYSQL_TIMESTAMP_NONE= -2, MYSQL_TIMESTAMP_ERROR= -1, + MYSQL_TIMESTAMP_DATE= 0, MYSQL_TIMESTAMP_DATETIME= 1, MYSQL_TIMESTAMP_TIME= 2 +}; +typedef struct st_mysql_time +{ + unsigned int year, month, day, hour, minute, second; + unsigned long second_part; + my_bool neg; + enum enum_mysql_timestamp_type time_type; +} MYSQL_TIME; +extern struct thd_timezone_service_st { + my_time_t (*thd_TIME_to_gmt_sec)(void* thd, const MYSQL_TIME *ltime, unsigned int *errcode); + void (*thd_gmt_sec_to_TIME)(void* thd, MYSQL_TIME *ltime, my_time_t t); +} *thd_timezone_service; +my_time_t thd_TIME_to_gmt_sec(void* thd, const MYSQL_TIME *ltime, unsigned int *errcode); +void thd_gmt_sec_to_TIME(void* thd, MYSQL_TIME *ltime, my_time_t t); +typedef enum _thd_wait_type_e { + THD_WAIT_SLEEP= 1, + THD_WAIT_DISKIO= 2, + THD_WAIT_ROW_LOCK= 3, + THD_WAIT_GLOBAL_LOCK= 4, + THD_WAIT_META_DATA_LOCK= 5, + THD_WAIT_TABLE_LOCK= 6, + THD_WAIT_USER_LOCK= 7, + THD_WAIT_BINLOG= 8, + THD_WAIT_GROUP_COMMIT= 9, + THD_WAIT_SYNC= 10, + THD_WAIT_NET= 11, + THD_WAIT_LAST= 12 +} thd_wait_type; +extern struct thd_wait_service_st { + void (*thd_wait_begin_func)(void*, int); + void (*thd_wait_end_func)(void*); +} *thd_wait_service; +void thd_wait_begin(void* thd, int wait_type); +void thd_wait_end(void* thd); struct st_mysql_xid { long formatID; long gtrid_length; @@ -163,12 +381,17 @@ enum enum_mysql_show_type SHOW_SINT, SHOW_SLONG, SHOW_SLONGLONG, SHOW_SIMPLE_FUNC, SHOW_always_last }; +enum enum_var_type +{ + SHOW_OPT_DEFAULT= 0, SHOW_OPT_SESSION, SHOW_OPT_GLOBAL +}; struct st_mysql_show_var { const char *name; - char *value; + void *value; enum enum_mysql_show_type type; }; -typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *); +struct system_status_var; +typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, void *, struct system_status_var *status_var, enum enum_var_type); struct st_mysql_sys_var; struct st_mysql_value; typedef int (*mysql_var_check_func)(void* thd, diff --git a/include/mysql/plugin_password_validation.h b/include/mysql/plugin_password_validation.h new file mode 100644 index 00000000000..18c643e877b --- /dev/null +++ b/include/mysql/plugin_password_validation.h @@ -0,0 +1,54 @@ +#ifndef MYSQL_PLUGIN_PASSWORD_VALIDATION_INCLUDED +/* Copyright (C) 2014 Sergei Golubchik and MariaDB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + 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 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 */ + +/** + @file + + Password Validation Plugin API. + + This file defines the API for server password validation plugins. +*/ + +#define MYSQL_PLUGIN_PASSWORD_VALIDATION_INCLUDED + +#include <mysql/plugin.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#define MariaDB_PASSWORD_VALIDATION_INTERFACE_VERSION 0x0100 + +/** + Password validation plugin descriptor +*/ +struct st_mariadb_password_validation +{ + int interface_version; /**< version plugin uses */ + /** + Function provided by the plugin which should perform password validation + and return 0 if the password has passed the validation. + */ + int (*validate_password)(MYSQL_LEX_STRING *username, + MYSQL_LEX_STRING *password); +}; + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/include/mysql/plugin_password_validation.h.pp b/include/mysql/plugin_password_validation.h.pp new file mode 100644 index 00000000000..d2fe8fa8e23 --- /dev/null +++ b/include/mysql/plugin_password_validation.h.pp @@ -0,0 +1,529 @@ +typedef char my_bool; +typedef void * MYSQL_PLUGIN; +extern struct base64_service_st { + int (*base64_needed_encoded_length_ptr)(int length_of_data); + int (*base64_encode_max_arg_length_ptr)(void); + int (*base64_needed_decoded_length_ptr)(int length_of_encoded_data); + int (*base64_decode_max_arg_length_ptr)(); + int (*base64_encode_ptr)(const void *src, size_t src_len, char *dst); + int (*base64_decode_ptr)(const char *src, size_t src_len, + void *dst, const char **end_ptr, int flags); +} *base64_service; +int base64_needed_encoded_length(int length_of_data); +int base64_encode_max_arg_length(void); +int base64_needed_decoded_length(int length_of_encoded_data); +int base64_decode_max_arg_length(); +int base64_encode(const void *src, size_t src_len, char *dst); +int base64_decode(const char *src, size_t src_len, + void *dst, const char **end_ptr, int flags); +extern void (*debug_sync_C_callback_ptr)(void*, const char *, size_t); +struct encryption_service_st { + unsigned int (*encryption_key_get_latest_version_func)(unsigned int key_id); + unsigned int (*encryption_key_get_func)(unsigned int key_id, unsigned int key_version, + unsigned char* buffer, unsigned int* length); + unsigned int (*encryption_ctx_size_func)(unsigned int key_id, unsigned int key_version); + int (*encryption_ctx_init_func)(void *ctx, const unsigned char* key, unsigned int klen, + const unsigned char* iv, unsigned int ivlen, + int flags, unsigned int key_id, + unsigned int key_version); + int (*encryption_ctx_update_func)(void *ctx, const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen); + int (*encryption_ctx_finish_func)(void *ctx, unsigned char* dst, unsigned int* dlen); + unsigned int (*encryption_encrypted_length_func)(unsigned int slen, unsigned int key_id, unsigned int key_version); +}; +extern struct encryption_service_st encryption_handler; +static inline unsigned int encryption_key_id_exists(unsigned int id) +{ + return encryption_handler.encryption_key_get_latest_version_func(id) != (~(unsigned int)0); +} +static inline unsigned int encryption_key_version_exists(unsigned int id, unsigned int version) +{ + unsigned int unused; + return encryption_handler.encryption_key_get_func((id),(version),(NULL),(&unused)) != (~(unsigned int)0); +} +static inline int encryption_crypt(const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + const unsigned char* key, unsigned int klen, + const unsigned char* iv, unsigned int ivlen, + int flags, unsigned int key_id, unsigned int key_version) +{ + void *ctx= alloca(encryption_handler.encryption_ctx_size_func((key_id),(key_version))); + int res1, res2; + unsigned int d1, d2; + if ((res1= encryption_handler.encryption_ctx_init_func((ctx),(key),(klen),(iv),(ivlen),(flags),(key_id),(key_version)))) + return res1; + res1= encryption_handler.encryption_ctx_update_func((ctx),(src),(slen),(dst),(&d1)); + res2= encryption_handler.encryption_ctx_finish_func((ctx),(dst + d1),(&d2)); + *dlen= d1 + d2; + return res1 ? res1 : res2; +} +struct st_encryption_scheme_key { + unsigned int version; + unsigned char key[16]; +}; +struct st_encryption_scheme { + unsigned char iv[16]; + struct st_encryption_scheme_key key[3]; + unsigned int keyserver_requests; + unsigned int key_id; + unsigned int type; + void (*locker)(struct st_encryption_scheme *self, int release); +}; +extern struct encryption_scheme_service_st { + int (*encryption_scheme_encrypt_func) + (const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + struct st_encryption_scheme *scheme, + unsigned int key_version, unsigned int i32_1, + unsigned int i32_2, unsigned long long i64); + int (*encryption_scheme_decrypt_func) + (const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + struct st_encryption_scheme *scheme, + unsigned int key_version, unsigned int i32_1, + unsigned int i32_2, unsigned long long i64); +} *encryption_scheme_service; +int encryption_scheme_encrypt(const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + struct st_encryption_scheme *scheme, + unsigned int key_version, unsigned int i32_1, + unsigned int i32_2, unsigned long long i64); +int encryption_scheme_decrypt(const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + struct st_encryption_scheme *scheme, + unsigned int key_version, unsigned int i32_1, + unsigned int i32_2, unsigned long long i64); +enum thd_kill_levels { + THD_IS_NOT_KILLED=0, + THD_ABORT_SOFTLY=50, + THD_ABORT_ASAP=100, +}; +extern struct kill_statement_service_st { + enum thd_kill_levels (*thd_kill_level_func)(const void*); +} *thd_kill_statement_service; +enum thd_kill_levels thd_kill_level(const void*); +typedef struct logger_handle_st LOGGER_HANDLE; +extern struct logger_service_st { + void (*logger_init_mutexes)(); + LOGGER_HANDLE* (*open)(const char *path, + unsigned long long size_limit, + unsigned int rotations); + int (*close)(LOGGER_HANDLE *log); + int (*vprintf)(LOGGER_HANDLE *log, const char *fmt, va_list argptr); + int (*printf)(LOGGER_HANDLE *log, const char *fmt, ...); + int (*write)(LOGGER_HANDLE *log, const char *buffer, size_t size); + int (*rotate)(LOGGER_HANDLE *log); +} *logger_service; + void logger_init_mutexes(); + LOGGER_HANDLE *logger_open(const char *path, + unsigned long long size_limit, + unsigned int rotations); + int logger_close(LOGGER_HANDLE *log); + int logger_vprintf(LOGGER_HANDLE *log, const char *fmt, va_list argptr); + int logger_printf(LOGGER_HANDLE *log, const char *fmt, ...); + int logger_write(LOGGER_HANDLE *log, const char *buffer, size_t size); + int logger_rotate(LOGGER_HANDLE *log); +extern struct my_md5_service_st { + void (*my_md5_type)(unsigned char*, const char*, size_t); + void (*my_md5_multi_type)(unsigned char*, ...); + size_t (*my_md5_context_size_type)(); + void (*my_md5_init_type)(void *); + void (*my_md5_input_type)(void *, const unsigned char *, size_t); + void (*my_md5_result_type)(void *, unsigned char *); +} *my_md5_service; +void my_md5(unsigned char*, const char*, size_t); +void my_md5_multi(unsigned char*, ...); +size_t my_md5_context_size(); +void my_md5_init(void *context); +void my_md5_input(void *context, const unsigned char *buf, size_t len); +void my_md5_result(void *context, unsigned char *digest); +enum my_aes_mode { + MY_AES_ECB, MY_AES_CBC +}; +extern struct my_crypt_service_st { + int (*my_aes_crypt_init)(void *ctx, enum my_aes_mode mode, int flags, + const unsigned char* key, unsigned int klen, + const unsigned char* iv, unsigned int ivlen); + int (*my_aes_crypt_update)(void *ctx, const unsigned char *src, unsigned int slen, + unsigned char *dst, unsigned int *dlen); + int (*my_aes_crypt_finish)(void *ctx, unsigned char *dst, unsigned int *dlen); + int (*my_aes_crypt)(enum my_aes_mode mode, int flags, + const unsigned char *src, unsigned int slen, unsigned char *dst, unsigned int *dlen, + const unsigned char *key, unsigned int klen, const unsigned char *iv, unsigned int ivlen); + unsigned int (*my_aes_get_size)(enum my_aes_mode mode, unsigned int source_length); + unsigned int (*my_aes_ctx_size)(enum my_aes_mode mode); + int (*my_random_bytes)(unsigned char* buf, int num); +} *my_crypt_service; +int my_aes_crypt_init(void *ctx, enum my_aes_mode mode, int flags, + const unsigned char* key, unsigned int klen, + const unsigned char* iv, unsigned int ivlen); +int my_aes_crypt_update(void *ctx, const unsigned char *src, unsigned int slen, + unsigned char *dst, unsigned int *dlen); +int my_aes_crypt_finish(void *ctx, unsigned char *dst, unsigned int *dlen); +int my_aes_crypt(enum my_aes_mode mode, int flags, + const unsigned char *src, unsigned int slen, unsigned char *dst, unsigned int *dlen, + const unsigned char *key, unsigned int klen, const unsigned char *iv, unsigned int ivlen); +int my_random_bytes(unsigned char* buf, int num); +unsigned int my_aes_get_size(enum my_aes_mode mode, unsigned int source_length); +unsigned int my_aes_ctx_size(enum my_aes_mode mode); +extern struct my_print_error_service_st { + void(*my_error_func)(unsigned int nr, unsigned long MyFlags, ...); + void(*my_printf_error_func)(unsigned int nr, const char *fmt, unsigned long MyFlags,...); + void(*my_printv_error_func)(unsigned int error, const char *format, unsigned long MyFlags, va_list ap); +} *my_print_error_service; +extern void my_error(unsigned int nr, unsigned long MyFlags, ...); +extern void my_printf_error(unsigned int my_err, const char *format, unsigned long MyFlags, ...); +extern void my_printv_error(unsigned int error, const char *format, unsigned long MyFlags,va_list ap); +extern struct my_snprintf_service_st { + size_t (*my_snprintf_type)(char*, size_t, const char*, ...); + size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list); +} *my_snprintf_service; +size_t my_snprintf(char* to, size_t n, const char* fmt, ...); +size_t my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap); +extern struct progress_report_service_st { + void (*thd_progress_init_func)(void* thd, unsigned int max_stage); + void (*thd_progress_report_func)(void* thd, + unsigned long long progress, + unsigned long long max_progress); + void (*thd_progress_next_stage_func)(void* thd); + void (*thd_progress_end_func)(void* thd); + const char *(*set_thd_proc_info_func)(void*, const char *info, + const char *func, + const char *file, + unsigned int line); +} *progress_report_service; +void thd_progress_init(void* thd, unsigned int max_stage); +void thd_progress_report(void* thd, + unsigned long long progress, + unsigned long long max_progress); +void thd_progress_next_stage(void* thd); +void thd_progress_end(void* thd); +const char *set_thd_proc_info(void*, const char * info, const char *func, + const char *file, unsigned int line); +extern struct my_sha1_service_st { + void (*my_sha1_type)(unsigned char*, const char*, size_t); + void (*my_sha1_multi_type)(unsigned char*, ...); + size_t (*my_sha1_context_size_type)(); + void (*my_sha1_init_type)(void *); + void (*my_sha1_input_type)(void *, const unsigned char *, size_t); + void (*my_sha1_result_type)(void *, unsigned char *); +} *my_sha1_service; +void my_sha1(unsigned char*, const char*, size_t); +void my_sha1_multi(unsigned char*, ...); +size_t my_sha1_context_size(); +void my_sha1_init(void *context); +void my_sha1_input(void *context, const unsigned char *buf, size_t len); +void my_sha1_result(void *context, unsigned char *digest); +extern struct my_sha2_service_st { + void (*my_sha224_type)(unsigned char*, const char*, size_t); + void (*my_sha224_multi_type)(unsigned char*, ...); + size_t (*my_sha224_context_size_type)(); + void (*my_sha224_init_type)(void *); + void (*my_sha224_input_type)(void *, const unsigned char *, size_t); + void (*my_sha224_result_type)(void *, unsigned char *); + void (*my_sha256_type)(unsigned char*, const char*, size_t); + void (*my_sha256_multi_type)(unsigned char*, ...); + size_t (*my_sha256_context_size_type)(); + void (*my_sha256_init_type)(void *); + void (*my_sha256_input_type)(void *, const unsigned char *, size_t); + void (*my_sha256_result_type)(void *, unsigned char *); + void (*my_sha384_type)(unsigned char*, const char*, size_t); + void (*my_sha384_multi_type)(unsigned char*, ...); + size_t (*my_sha384_context_size_type)(); + void (*my_sha384_init_type)(void *); + void (*my_sha384_input_type)(void *, const unsigned char *, size_t); + void (*my_sha384_result_type)(void *, unsigned char *); + void (*my_sha512_type)(unsigned char*, const char*, size_t); + void (*my_sha512_multi_type)(unsigned char*, ...); + size_t (*my_sha512_context_size_type)(); + void (*my_sha512_init_type)(void *); + void (*my_sha512_input_type)(void *, const unsigned char *, size_t); + void (*my_sha512_result_type)(void *, unsigned char *); +} *my_sha2_service; +void my_sha224(unsigned char*, const char*, size_t); +void my_sha224_multi(unsigned char*, ...); +size_t my_sha224_context_size(); +void my_sha224_init(void *context); +void my_sha224_input(void *context, const unsigned char *buf, size_t len); +void my_sha224_result(void *context, unsigned char *digest); +void my_sha256(unsigned char*, const char*, size_t); +void my_sha256_multi(unsigned char*, ...); +size_t my_sha256_context_size(); +void my_sha256_init(void *context); +void my_sha256_input(void *context, const unsigned char *buf, size_t len); +void my_sha256_result(void *context, unsigned char *digest); +void my_sha384(unsigned char*, const char*, size_t); +void my_sha384_multi(unsigned char*, ...); +size_t my_sha384_context_size(); +void my_sha384_init(void *context); +void my_sha384_input(void *context, const unsigned char *buf, size_t len); +void my_sha384_result(void *context, unsigned char *digest); +void my_sha512(unsigned char*, const char*, size_t); +void my_sha512_multi(unsigned char*, ...); +size_t my_sha512_context_size(); +void my_sha512_init(void *context); +void my_sha512_input(void *context, const unsigned char *buf, size_t len); +void my_sha512_result(void *context, unsigned char *digest); +struct st_mysql_lex_string +{ + char *str; + size_t length; +}; +typedef struct st_mysql_lex_string MYSQL_LEX_STRING; +extern struct thd_alloc_service_st { + void *(*thd_alloc_func)(void*, unsigned int); + void *(*thd_calloc_func)(void*, unsigned int); + char *(*thd_strdup_func)(void*, const char *); + char *(*thd_strmake_func)(void*, const char *, unsigned int); + void *(*thd_memdup_func)(void*, const void*, unsigned int); + MYSQL_LEX_STRING *(*thd_make_lex_string_func)(void*, MYSQL_LEX_STRING *, + const char *, unsigned int, int); +} *thd_alloc_service; +void *thd_alloc(void* thd, unsigned int size); +void *thd_calloc(void* thd, unsigned int size); +char *thd_strdup(void* thd, const char *str); +char *thd_strmake(void* thd, const char *str, unsigned int size); +void *thd_memdup(void* thd, const void* str, unsigned int size); +MYSQL_LEX_STRING *thd_make_lex_string(void* thd, MYSQL_LEX_STRING *lex_str, + const char *str, unsigned int size, + int allocate_lex_string); +extern struct thd_autoinc_service_st { + void (*thd_get_autoinc_func)(const void* thd, + unsigned long* off, unsigned long* inc); +} *thd_autoinc_service; +void thd_get_autoinc(const void* thd, + unsigned long* off, unsigned long* inc); +extern struct thd_error_context_service_st { + const char *(*thd_get_error_message_func)(const void* thd); + unsigned int (*thd_get_error_number_func)(const void* thd); + unsigned long (*thd_get_error_row_func)(const void* thd); + void (*thd_inc_error_row_func)(void* thd); + char *(*thd_get_error_context_description_func)(void* thd, + char *buffer, + unsigned int length, + unsigned int max_query_length); +} *thd_error_context_service; +const char *thd_get_error_message(const void* thd); +unsigned int thd_get_error_number(const void* thd); +unsigned long thd_get_error_row(const void* thd); +void thd_inc_error_row(void* thd); +char *thd_get_error_context_description(void* thd, + char *buffer, unsigned int length, + unsigned int max_query_length); +extern struct thd_rnd_service_st { + double (*thd_rnd_ptr)(void* thd); + void (*thd_c_r_p_ptr)(void* thd, char *to, size_t length); +} *thd_rnd_service; +double thd_rnd(void* thd); +void thd_create_random_password(void* thd, char *to, size_t length); +typedef int MYSQL_THD_KEY_T; +extern struct thd_specifics_service_st { + int (*thd_key_create_func)(MYSQL_THD_KEY_T *key); + void (*thd_key_delete_func)(MYSQL_THD_KEY_T *key); + void *(*thd_getspecific_func)(void* thd, MYSQL_THD_KEY_T key); + int (*thd_setspecific_func)(void* thd, MYSQL_THD_KEY_T key, void *value); +} *thd_specifics_service; +int thd_key_create(MYSQL_THD_KEY_T *key); +void thd_key_delete(MYSQL_THD_KEY_T *key); +void* thd_getspecific(void* thd, MYSQL_THD_KEY_T key); +int thd_setspecific(void* thd, MYSQL_THD_KEY_T key, void *value); +typedef long my_time_t; +enum enum_mysql_timestamp_type +{ + MYSQL_TIMESTAMP_NONE= -2, MYSQL_TIMESTAMP_ERROR= -1, + MYSQL_TIMESTAMP_DATE= 0, MYSQL_TIMESTAMP_DATETIME= 1, MYSQL_TIMESTAMP_TIME= 2 +}; +typedef struct st_mysql_time +{ + unsigned int year, month, day, hour, minute, second; + unsigned long second_part; + my_bool neg; + enum enum_mysql_timestamp_type time_type; +} MYSQL_TIME; +extern struct thd_timezone_service_st { + my_time_t (*thd_TIME_to_gmt_sec)(void* thd, const MYSQL_TIME *ltime, unsigned int *errcode); + void (*thd_gmt_sec_to_TIME)(void* thd, MYSQL_TIME *ltime, my_time_t t); +} *thd_timezone_service; +my_time_t thd_TIME_to_gmt_sec(void* thd, const MYSQL_TIME *ltime, unsigned int *errcode); +void thd_gmt_sec_to_TIME(void* thd, MYSQL_TIME *ltime, my_time_t t); +typedef enum _thd_wait_type_e { + THD_WAIT_SLEEP= 1, + THD_WAIT_DISKIO= 2, + THD_WAIT_ROW_LOCK= 3, + THD_WAIT_GLOBAL_LOCK= 4, + THD_WAIT_META_DATA_LOCK= 5, + THD_WAIT_TABLE_LOCK= 6, + THD_WAIT_USER_LOCK= 7, + THD_WAIT_BINLOG= 8, + THD_WAIT_GROUP_COMMIT= 9, + THD_WAIT_SYNC= 10, + THD_WAIT_NET= 11, + THD_WAIT_LAST= 12 +} thd_wait_type; +extern struct thd_wait_service_st { + void (*thd_wait_begin_func)(void*, int); + void (*thd_wait_end_func)(void*); +} *thd_wait_service; +void thd_wait_begin(void* thd, int wait_type); +void thd_wait_end(void* thd); +struct st_mysql_xid { + long formatID; + long gtrid_length; + long bqual_length; + char data[128]; +}; +typedef struct st_mysql_xid MYSQL_XID; +enum enum_mysql_show_type +{ + SHOW_UNDEF, SHOW_BOOL, SHOW_UINT, SHOW_ULONG, + SHOW_ULONGLONG, SHOW_CHAR, SHOW_CHAR_PTR, + SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE, + SHOW_SINT, SHOW_SLONG, SHOW_SLONGLONG, SHOW_SIMPLE_FUNC, + SHOW_always_last +}; +enum enum_var_type +{ + SHOW_OPT_DEFAULT= 0, SHOW_OPT_SESSION, SHOW_OPT_GLOBAL +}; +struct st_mysql_show_var { + const char *name; + void *value; + enum enum_mysql_show_type type; +}; +struct system_status_var; +typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, void *, struct system_status_var *status_var, enum enum_var_type); +struct st_mysql_sys_var; +struct st_mysql_value; +typedef int (*mysql_var_check_func)(void* thd, + struct st_mysql_sys_var *var, + void *save, struct st_mysql_value *value); +typedef void (*mysql_var_update_func)(void* thd, + struct st_mysql_sys_var *var, + void *var_ptr, const void *save); +struct st_mysql_plugin +{ + int type; + void *info; + const char *name; + const char *author; + const char *descr; + int license; + int (*init)(void *); + int (*deinit)(void *); + unsigned int version; + struct st_mysql_show_var *status_vars; + struct st_mysql_sys_var **system_vars; + void * __reserved1; + unsigned long flags; +}; +struct st_maria_plugin +{ + int type; + void *info; + const char *name; + const char *author; + const char *descr; + int license; + int (*init)(void *); + int (*deinit)(void *); + unsigned int version; + struct st_mysql_show_var *status_vars; + struct st_mysql_sys_var **system_vars; + const char *version_info; + unsigned int maturity; +}; +enum enum_ftparser_mode +{ + MYSQL_FTPARSER_SIMPLE_MODE= 0, + MYSQL_FTPARSER_WITH_STOPWORDS= 1, + MYSQL_FTPARSER_FULL_BOOLEAN_INFO= 2 +}; +enum enum_ft_token_type +{ + FT_TOKEN_EOF= 0, + FT_TOKEN_WORD= 1, + FT_TOKEN_LEFT_PAREN= 2, + FT_TOKEN_RIGHT_PAREN= 3, + FT_TOKEN_STOPWORD= 4 +}; +typedef struct st_mysql_ftparser_boolean_info +{ + enum enum_ft_token_type type; + int yesno; + int weight_adjust; + char wasign; + char trunc; + char prev; + char *quot; +} MYSQL_FTPARSER_BOOLEAN_INFO; +typedef struct st_mysql_ftparser_param +{ + int (*mysql_parse)(struct st_mysql_ftparser_param *, + const char *doc, int doc_len); + int (*mysql_add_word)(struct st_mysql_ftparser_param *, + const char *word, int word_len, + MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info); + void *ftparser_state; + void *mysql_ftparam; + const struct charset_info_st *cs; + const char *doc; + int length; + unsigned int flags; + enum enum_ftparser_mode mode; +} MYSQL_FTPARSER_PARAM; +struct st_mysql_ftparser +{ + int interface_version; + int (*parse)(MYSQL_FTPARSER_PARAM *param); + int (*init)(MYSQL_FTPARSER_PARAM *param); + int (*deinit)(MYSQL_FTPARSER_PARAM *param); +}; +struct st_mysql_daemon +{ + int interface_version; +}; +struct st_mysql_information_schema +{ + int interface_version; +}; +struct st_mysql_storage_engine +{ + int interface_version; +}; +struct handlerton; + struct Mysql_replication { + int interface_version; + }; +struct st_mysql_value +{ + int (*value_type)(struct st_mysql_value *); + const char *(*val_str)(struct st_mysql_value *, char *buffer, int *length); + int (*val_real)(struct st_mysql_value *, double *realbuf); + int (*val_int)(struct st_mysql_value *, long long *intbuf); + int (*is_unsigned)(struct st_mysql_value *); +}; +int thd_in_lock_tables(const void* thd); +int thd_tablespace_op(const void* thd); +long long thd_test_options(const void* thd, long long test_options); +int thd_sql_command(const void* thd); +void **thd_ha_data(const void* thd, const struct handlerton *hton); +void thd_storage_lock_wait(void* thd, long long value); +int thd_tx_isolation(const void* thd); +int thd_tx_is_read_only(const void* thd); +int thd_rpl_is_parallel(const void* thd); +int mysql_tmpfile(const char *prefix); +unsigned long thd_get_thread_id(const void* thd); +void thd_get_xid(const void* thd, MYSQL_XID *xid); +void mysql_query_cache_invalidate4(void* thd, + const char *key, unsigned int key_length, + int using_trx); +void *thd_get_ha_data(const void* thd, const struct handlerton *hton); +void thd_set_ha_data(void* thd, const struct handlerton *hton, + const void *ha_data); +void thd_wakeup_subsequent_commits(void* thd, int wakeup_error); +struct st_mariadb_password_validation +{ + int interface_version; + int (*validate_password)(MYSQL_LEX_STRING *username, + MYSQL_LEX_STRING *password); +}; diff --git a/include/mysql/psi/mysql_socket.h b/include/mysql/psi/mysql_socket.h index 70700a733d8..fc0a3ce2eb0 100644 --- a/include/mysql/psi/mysql_socket.h +++ b/include/mysql/psi/mysql_socket.h @@ -1019,7 +1019,9 @@ inline_mysql_socket_accept #endif MYSQL_SOCKET socket_listen, struct sockaddr *addr, socklen_t *addr_len) { +#ifdef FD_CLOEXEC int flags; +#endif MYSQL_SOCKET socket_accept= MYSQL_INVALID_SOCKET; socklen_t addr_length= (addr_len != NULL) ? *addr_len : 0; @@ -1039,12 +1041,14 @@ inline_mysql_socket_accept SOCK_CLOEXEC); #else socket_accept.fd= accept(socket_listen.fd, addr, &addr_length); +#ifdef FD_CLOEXEC flags= fcntl(socket_accept.fd, F_GETFD); if (flags != -1) { flags |= FD_CLOEXEC; fcntl(socket_accept.fd, F_SETFD, flags); } #endif +#endif /* Instrumentation end */ if (locker != NULL) @@ -1059,12 +1063,14 @@ inline_mysql_socket_accept SOCK_CLOEXEC); #else socket_accept.fd= accept(socket_listen.fd, addr, &addr_length); +#ifdef FD_CLOEXEC flags= fcntl(socket_accept.fd, F_GETFD); if (flags != -1) { flags |= FD_CLOEXEC; fcntl(socket_accept.fd, F_SETFD, flags); } #endif +#endif } #ifdef HAVE_PSI_SOCKET_INTERFACE diff --git a/include/mysql/psi/mysql_table.h b/include/mysql/psi/mysql_table.h index bd703d75e1f..74217a32b13 100644 --- a/include/mysql/psi/mysql_table.h +++ b/include/mysql/psi/mysql_table.h @@ -30,6 +30,9 @@ */ #ifdef HAVE_PSI_TABLE_INTERFACE +#define MYSQL_UNBIND_TABLE(handler) (handler)->unbind_psi() +#define MYSQL_REBIND_TABLE(handler) (handler)->rebind_psi() + #define PSI_CALL_unbind_table PSI_TABLE_CALL(unbind_table) #define PSI_CALL_rebind_table PSI_TABLE_CALL(rebind_table) #define PSI_CALL_open_table PSI_TABLE_CALL(open_table) @@ -38,13 +41,16 @@ #define PSI_CALL_release_table_share PSI_TABLE_CALL(release_table_share) #define PSI_CALL_drop_table_share PSI_TABLE_CALL(drop_table_share) #else -#define PSI_CALL_unbind_table(A1) /* no-op */ +#define MYSQL_UNBIND_TABLE(handler) do { } while(0) +#define MYSQL_REBIND_TABLE(handler) do { } while(0) + +#define PSI_CALL_unbind_table(A1) do { } while(0) #define PSI_CALL_rebind_table(A1,A2,A3) NULL -#define PSI_CALL_close_table(A1) /* no-op */ +#define PSI_CALL_close_table(A1) do { } while(0) #define PSI_CALL_open_table(A1,A2) NULL #define PSI_CALL_get_table_share(A1,A2) NULL -#define PSI_CALL_release_table_share(A1) /* no-op */ -#define PSI_CALL_drop_table_share(A1,A2,A3,A4,A5) /* no-op */ +#define PSI_CALL_release_table_share(A1) do { } while(0) +#define PSI_CALL_drop_table_share(A1,A2,A3,A4,A5) do { } while(0) #endif /** diff --git a/include/mysql/service_base64.h b/include/mysql/service_base64.h new file mode 100644 index 00000000000..6020daed6cb --- /dev/null +++ b/include/mysql/service_base64.h @@ -0,0 +1,82 @@ +#ifndef MYSQL_SERVICE_BASE64_INCLUDED +/* Copyright (c) 2017, MariaDB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + 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 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 */ + +/** + @file + my base64 service + + Functions for base64 en- and decoding +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef MYSQL_ABI_CHECK +#include <stdlib.h> +#endif + +/* Allow multuple chunks 'AAA= AA== AA==', binlog uses this */ +#define MY_BASE64_DECODE_ALLOW_MULTIPLE_CHUNKS 1 + +extern struct base64_service_st { + int (*base64_needed_encoded_length_ptr)(int length_of_data); + int (*base64_encode_max_arg_length_ptr)(void); + int (*base64_needed_decoded_length_ptr)(int length_of_encoded_data); + int (*base64_decode_max_arg_length_ptr)(); + int (*base64_encode_ptr)(const void *src, size_t src_len, char *dst); + int (*base64_decode_ptr)(const char *src, size_t src_len, + void *dst, const char **end_ptr, int flags); +} *base64_service; + +#ifdef MYSQL_DYNAMIC_PLUGIN + +#define base64_needed_encoded_length(A) base64_service->base64_needed_encoded_length_ptr(A) +#define base64_encode_max_arg_length() base64_service->base64_encode_max_arg_length_ptr() +#define base64_needed_decoded_length(A) base64_service->base64_needed_decoded_length_ptr(A) +#define base64_decode_max_arg_length() base64_service->base64_decode_max_arg_length_ptr() +#define base64_encode(A,B,C) base64_service->base64_encode_ptr(A,B,C) +#define base64_decode(A,B,C,D,E) base64_service->base64_decode_ptr(A,B,C,D,E) + +#else + +/* Calculate how much memory needed for dst of base64_encode() */ +int base64_needed_encoded_length(int length_of_data); + +/* Maximum length base64_encode_needed_length() can accept with no overflow. */ +int base64_encode_max_arg_length(void); + +/* Calculate how much memory needed for dst of base64_decode() */ +int base64_needed_decoded_length(int length_of_encoded_data); + +/* Maximum length base64_decode_needed_length() can accept with no overflow. */ +int base64_decode_max_arg_length(); + +/* Encode data as a base64 string */ +int base64_encode(const void *src, size_t src_len, char *dst); + +/* Decode a base64 string into data */ +int base64_decode(const char *src, size_t src_len, + void *dst, const char **end_ptr, int flags); + +#endif + +#ifdef __cplusplus +} +#endif + +#define MYSQL_SERVICE_BASE64_INCLUDED +#endif diff --git a/include/mysql/service_encryption.h b/include/mysql/service_encryption.h new file mode 100644 index 00000000000..77afc047372 --- /dev/null +++ b/include/mysql/service_encryption.h @@ -0,0 +1,131 @@ +#ifndef MYSQL_SERVICE_ENCRYPTION_INCLUDED +/* Copyright (c) 2015, MariaDB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + 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 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 */ + +/** + @file + encryption service + + Functions to support data encryption and encryption key management. + They are normally implemented in an encryption plugin, so this service + connects encryption *consumers* (e.g. storage engines) to the encryption + *provider* (encryption plugin). +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef MYSQL_ABI_CHECK +#ifdef _WIN32 +#include <malloc.h> +#ifndef __cplusplus +#define inline __inline +#endif +#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) +#include <stdlib.h> +#else +#include <alloca.h> +#endif +#endif + +/* returned from encryption_key_get_latest_version() */ +#define ENCRYPTION_KEY_VERSION_INVALID (~(unsigned int)0) +#define ENCRYPTION_KEY_NOT_ENCRYPTED (0) + +#define ENCRYPTION_KEY_SYSTEM_DATA 1 +#define ENCRYPTION_KEY_TEMPORARY_DATA 2 + +/* returned from encryption_key_get() */ +#define ENCRYPTION_KEY_BUFFER_TOO_SMALL (100) + +#define ENCRYPTION_FLAG_DECRYPT 0 +#define ENCRYPTION_FLAG_ENCRYPT 1 +#define ENCRYPTION_FLAG_NOPAD 2 + +struct encryption_service_st { + unsigned int (*encryption_key_get_latest_version_func)(unsigned int key_id); + unsigned int (*encryption_key_get_func)(unsigned int key_id, unsigned int key_version, + unsigned char* buffer, unsigned int* length); + unsigned int (*encryption_ctx_size_func)(unsigned int key_id, unsigned int key_version); + int (*encryption_ctx_init_func)(void *ctx, const unsigned char* key, unsigned int klen, + const unsigned char* iv, unsigned int ivlen, + int flags, unsigned int key_id, + unsigned int key_version); + int (*encryption_ctx_update_func)(void *ctx, const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen); + int (*encryption_ctx_finish_func)(void *ctx, unsigned char* dst, unsigned int* dlen); + unsigned int (*encryption_encrypted_length_func)(unsigned int slen, unsigned int key_id, unsigned int key_version); +}; + +#ifdef MYSQL_DYNAMIC_PLUGIN + +extern struct encryption_service_st *encryption_service; + +#define encryption_key_get_latest_version(KI) encryption_service->encryption_key_get_latest_version_func(KI) +#define encryption_key_get(KI,KV,K,S) encryption_service->encryption_key_get_func((KI),(KV),(K),(S)) +#define encryption_ctx_size(KI,KV) encryption_service->encryption_ctx_size_func((KI),(KV)) +#define encryption_ctx_init(CTX,K,KL,IV,IVL,F,KI,KV) encryption_service->encryption_ctx_init_func((CTX),(K),(KL),(IV),(IVL),(F),(KI),(KV)) +#define encryption_ctx_update(CTX,S,SL,D,DL) encryption_service->encryption_ctx_update_func((CTX),(S),(SL),(D),(DL)) +#define encryption_ctx_finish(CTX,D,DL) encryption_service->encryption_ctx_finish_func((CTX),(D),(DL)) +#define encryption_encrypted_length(SL,KI,KV) encryption_service->encryption_encrypted_length_func((SL),(KI),(KV)) +#else + +extern struct encryption_service_st encryption_handler; + +#define encryption_key_get_latest_version(KI) encryption_handler.encryption_key_get_latest_version_func(KI) +#define encryption_key_get(KI,KV,K,S) encryption_handler.encryption_key_get_func((KI),(KV),(K),(S)) +#define encryption_ctx_size(KI,KV) encryption_handler.encryption_ctx_size_func((KI),(KV)) +#define encryption_ctx_init(CTX,K,KL,IV,IVL,F,KI,KV) encryption_handler.encryption_ctx_init_func((CTX),(K),(KL),(IV),(IVL),(F),(KI),(KV)) +#define encryption_ctx_update(CTX,S,SL,D,DL) encryption_handler.encryption_ctx_update_func((CTX),(S),(SL),(D),(DL)) +#define encryption_ctx_finish(CTX,D,DL) encryption_handler.encryption_ctx_finish_func((CTX),(D),(DL)) +#define encryption_encrypted_length(SL,KI,KV) encryption_handler.encryption_encrypted_length_func((SL),(KI),(KV)) +#endif + +static inline unsigned int encryption_key_id_exists(unsigned int id) +{ + return encryption_key_get_latest_version(id) != ENCRYPTION_KEY_VERSION_INVALID; +} + +static inline unsigned int encryption_key_version_exists(unsigned int id, unsigned int version) +{ + unsigned int unused; + return encryption_key_get(id, version, NULL, &unused) != ENCRYPTION_KEY_VERSION_INVALID; +} + +static inline int encryption_crypt(const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + const unsigned char* key, unsigned int klen, + const unsigned char* iv, unsigned int ivlen, + int flags, unsigned int key_id, unsigned int key_version) +{ + void *ctx= alloca(encryption_ctx_size(key_id, key_version)); + int res1, res2; + unsigned int d1, d2; + if ((res1= encryption_ctx_init(ctx, key, klen, iv, ivlen, flags, key_id, key_version))) + return res1; + res1= encryption_ctx_update(ctx, src, slen, dst, &d1); + res2= encryption_ctx_finish(ctx, dst + d1, &d2); + *dlen= d1 + d2; + return res1 ? res1 : res2; +} + +#ifdef __cplusplus +} +#endif + +#define MYSQL_SERVICE_ENCRYPTION_INCLUDED +#endif + diff --git a/include/mysql/service_encryption_scheme.h b/include/mysql/service_encryption_scheme.h new file mode 100644 index 00000000000..195c7aa4a5c --- /dev/null +++ b/include/mysql/service_encryption_scheme.h @@ -0,0 +1,133 @@ +#ifndef MYSQL_SERVICE_ENCRYPTION_SCHEME_INCLUDED +/* Copyright (c) 2015, MariaDB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + 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 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 */ + +/** + @file + encryption scheme service + + A higher-level access to encryption service. + + This is a helper service that storage engines use to encrypt tables on disk. + It requests keys from the plugin, generates temporary or local keys + from the global (as returned by the plugin) keys, etc. + + To use the service: + + * st_encryption_scheme object is created per space. A "space" can be + a table space in XtraDB/InnoDB, a file in Aria, etc. The whole + space is encrypted with the one key id. + + * The service does not take the key and the IV as parameters for + encryption or decryption. Instead it takes two 32-bit integers and + one 64-bit integer (and requests the key from an encryption + plugin, if needed). + + * The service requests the global key from the encryption plugin + automatically as needed. Three last keys are cached in the + st_encryption_scheme. Number of key requests (number of cache + misses) are counted in st_encryption_scheme::keyserver_requests + + * If an st_encryption_scheme can be used concurrently by different + threads, it needs to be able to lock itself when accessing the key + cache. Set the st_encryption_scheme::locker appropriately. If + non-zero, it will be invoked by encrypt/decrypt functions to lock + and unlock the scheme when needed. + + * Implementation details (in particular, key derivation) are defined + by the scheme type. Currently only schema type 1 is supported. + + In the schema type 1, every "space" (table space in XtraDB/InnoDB, + file in Aria) is encrypted with a different space-local key: + + * Every space has a 16-byte unique identifier (typically it's + generated randomly and stored in the space). The caller should + put it into st_encryption_scheme::iv. + + * Space-local key is generated by encrypting this identifier with + the global encryption key (of the given id and version) using AES_ECB. + + * Encryption/decryption parameters for a page are typically the + 4-byte space id, 4-byte page position (offset, page number, etc), + and the 8-byte LSN. This guarantees that they'll be different for + any two pages (of the same or different tablespaces) and also that + they'll change for the same page when it's modified. They don't need + to be secret (they create the IV, not the encryption key). +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#define ENCRYPTION_SCHEME_KEY_INVALID -1 +#define ENCRYPTION_SCHEME_BLOCK_LENGTH 16 + +struct st_encryption_scheme_key { + unsigned int version; + unsigned char key[ENCRYPTION_SCHEME_BLOCK_LENGTH]; +}; + +struct st_encryption_scheme { + unsigned char iv[ENCRYPTION_SCHEME_BLOCK_LENGTH]; + struct st_encryption_scheme_key key[3]; + unsigned int keyserver_requests; + unsigned int key_id; + unsigned int type; + + void (*locker)(struct st_encryption_scheme *self, int release); +}; + +extern struct encryption_scheme_service_st { + int (*encryption_scheme_encrypt_func) + (const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + struct st_encryption_scheme *scheme, + unsigned int key_version, unsigned int i32_1, + unsigned int i32_2, unsigned long long i64); + int (*encryption_scheme_decrypt_func) + (const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + struct st_encryption_scheme *scheme, + unsigned int key_version, unsigned int i32_1, + unsigned int i32_2, unsigned long long i64); +} *encryption_scheme_service; + +#ifdef MYSQL_DYNAMIC_PLUGIN + +#define encryption_scheme_encrypt(S,SL,D,DL,SCH,KV,I32,J32,I64) encryption_scheme_service->encryption_scheme_encrypt_func(S,SL,D,DL,SCH,KV,I32,J32,I64) +#define encryption_scheme_decrypt(S,SL,D,DL,SCH,KV,I32,J32,I64) encryption_scheme_service->encryption_scheme_decrypt_func(S,SL,D,DL,SCH,KV,I32,J32,I64) + +#else + +int encryption_scheme_encrypt(const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + struct st_encryption_scheme *scheme, + unsigned int key_version, unsigned int i32_1, + unsigned int i32_2, unsigned long long i64); +int encryption_scheme_decrypt(const unsigned char* src, unsigned int slen, + unsigned char* dst, unsigned int* dlen, + struct st_encryption_scheme *scheme, + unsigned int key_version, unsigned int i32_1, + unsigned int i32_2, unsigned long long i64); + +#endif + + +#ifdef __cplusplus +} +#endif + +#define MYSQL_SERVICE_ENCRYPTION_SCHEME_INCLUDED +#endif diff --git a/include/mysql/service_logger.h b/include/mysql/service_logger.h index 962ab2fbc0b..aa2c1b335e3 100644 --- a/include/mysql/service_logger.h +++ b/include/mysql/service_logger.h @@ -11,7 +11,7 @@ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ #ifndef MYSQL_SERVICE_LOGGER_INCLUDED #define MYSQL_SERVICE_LOGGER_INCLUDED @@ -71,7 +71,7 @@ extern struct logger_service_st { int (*rotate)(LOGGER_HANDLE *log); } *logger_service; -#if MYSQL_DYNAMIC_PLUGIN +#ifdef MYSQL_DYNAMIC_PLUGIN #define logger_init_mutexes logger_service->logger_init_mutexes #define logger_open(path, size_limit, rotations) \ diff --git a/include/mysql/service_md5.h b/include/mysql/service_md5.h new file mode 100644 index 00000000000..5e589e57415 --- /dev/null +++ b/include/mysql/service_md5.h @@ -0,0 +1,69 @@ +#ifndef MYSQL_SERVICE_MD5_INCLUDED +/* Copyright (c) 2014, Monty Program Ab + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + 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 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 */ + +/** + @file + my md5 service + + Functions to calculate MD5 hash from a memory buffer +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef MYSQL_ABI_CHECK +#include <stdlib.h> +#endif + +#define MY_MD5_HASH_SIZE 16 /* Hash size in bytes */ + +extern struct my_md5_service_st { + void (*my_md5_type)(unsigned char*, const char*, size_t); + void (*my_md5_multi_type)(unsigned char*, ...); + size_t (*my_md5_context_size_type)(); + void (*my_md5_init_type)(void *); + void (*my_md5_input_type)(void *, const unsigned char *, size_t); + void (*my_md5_result_type)(void *, unsigned char *); +} *my_md5_service; + +#ifdef MYSQL_DYNAMIC_PLUGIN + +#define my_md5(A,B,C) my_md5_service->my_md5_type(A,B,C) +#define my_md5_multi my_md5_service->my_md5_multi_type +#define my_md5_context_size() my_md5_service->my_md5_context_size_type() +#define my_md5_init(A) my_md5_service->my_md5_init_type(A) +#define my_md5_input(A,B,C) my_md5_service->my_md5_input_type(A,B,C) +#define my_md5_result(A,B) my_md5_service->my_md5_result_type(A,B) + +#else + +void my_md5(unsigned char*, const char*, size_t); +void my_md5_multi(unsigned char*, ...); +size_t my_md5_context_size(); +void my_md5_init(void *context); +void my_md5_input(void *context, const unsigned char *buf, size_t len); +void my_md5_result(void *context, unsigned char *digest); + +#endif + +#ifdef __cplusplus +} +#endif + +#define MYSQL_SERVICE_MD5_INCLUDED +#endif + diff --git a/include/mysql/service_my_crypt.h b/include/mysql/service_my_crypt.h new file mode 100644 index 00000000000..83de0378e4a --- /dev/null +++ b/include/mysql/service_my_crypt.h @@ -0,0 +1,120 @@ +#ifndef MYSQL_SERVICE_MY_CRYPT_INCLUDED +#define MYSQL_SERVICE_MY_CRYPT_INCLUDED + +/* + Copyright (c) 2014 Google Inc. + Copyright (c) 2014, 2015 MariaDB Corporation + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + 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 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 */ + +/** + @file + my crypt service + + AES encryption functions, and a function to generate random bytes. + + Include my_config.h before this file to use CTR and GCM modes + (they only work if server was compiled with openssl). +*/ + + +#ifdef __cplusplus +extern "C" { +#endif + +/* return values from my_aes_encrypt/my_aes_decrypt functions */ +#define MY_AES_OK 0 +#define MY_AES_BAD_DATA -100 +#define MY_AES_OPENSSL_ERROR -101 +#define MY_AES_BAD_KEYSIZE -102 + +/* The block size for all supported algorithms */ +#define MY_AES_BLOCK_SIZE 16 + +/* The max key length of all supported algorithms */ +#define MY_AES_MAX_KEY_LENGTH 32 + +#define MY_AES_CTX_SIZE 512 + +enum my_aes_mode { + MY_AES_ECB, MY_AES_CBC +#ifdef HAVE_EncryptAes128Ctr + , MY_AES_CTR +#endif +#ifdef HAVE_EncryptAes128Gcm + , MY_AES_GCM +#endif +}; + +extern struct my_crypt_service_st { + int (*my_aes_crypt_init)(void *ctx, enum my_aes_mode mode, int flags, + const unsigned char* key, unsigned int klen, + const unsigned char* iv, unsigned int ivlen); + int (*my_aes_crypt_update)(void *ctx, const unsigned char *src, unsigned int slen, + unsigned char *dst, unsigned int *dlen); + int (*my_aes_crypt_finish)(void *ctx, unsigned char *dst, unsigned int *dlen); + int (*my_aes_crypt)(enum my_aes_mode mode, int flags, + const unsigned char *src, unsigned int slen, unsigned char *dst, unsigned int *dlen, + const unsigned char *key, unsigned int klen, const unsigned char *iv, unsigned int ivlen); + unsigned int (*my_aes_get_size)(enum my_aes_mode mode, unsigned int source_length); + unsigned int (*my_aes_ctx_size)(enum my_aes_mode mode); + int (*my_random_bytes)(unsigned char* buf, int num); +} *my_crypt_service; + +#ifdef MYSQL_DYNAMIC_PLUGIN + +#define my_aes_crypt_init(A,B,C,D,E,F,G) \ + my_crypt_service->my_aes_crypt_init(A,B,C,D,E,F,G) + +#define my_aes_crypt_update(A,B,C,D,E) \ + my_crypt_service->my_aes_crypt_update(A,B,C,D,E) + +#define my_aes_crypt_finish(A,B,C) \ + my_crypt_service->my_aes_crypt_finish(A,B,C) + +#define my_aes_crypt(A,B,C,D,E,F,G,H,I,J) \ + my_crypt_service->my_aes_crypt(A,B,C,D,E,F,G,H,I,J) + +#define my_aes_get_size(A,B)\ + my_crypt_service->my_aes_get_size(A,B) + +#define my_aes_ctx_size(A)\ + my_crypt_service->my_aes_ctx_size(A) + +#define my_random_bytes(A,B)\ + my_crypt_service->my_random_bytes(A,B) + +#else + +int my_aes_crypt_init(void *ctx, enum my_aes_mode mode, int flags, + const unsigned char* key, unsigned int klen, + const unsigned char* iv, unsigned int ivlen); +int my_aes_crypt_update(void *ctx, const unsigned char *src, unsigned int slen, + unsigned char *dst, unsigned int *dlen); +int my_aes_crypt_finish(void *ctx, unsigned char *dst, unsigned int *dlen); +int my_aes_crypt(enum my_aes_mode mode, int flags, + const unsigned char *src, unsigned int slen, unsigned char *dst, unsigned int *dlen, + const unsigned char *key, unsigned int klen, const unsigned char *iv, unsigned int ivlen); + +int my_random_bytes(unsigned char* buf, int num); +unsigned int my_aes_get_size(enum my_aes_mode mode, unsigned int source_length); +unsigned int my_aes_ctx_size(enum my_aes_mode mode); +#endif + + +#ifdef __cplusplus +} +#endif + +#endif /* MYSQL_SERVICE_MY_CRYPT_INCLUDED */ diff --git a/include/mysql/service_my_plugin_log.h b/include/mysql/service_my_plugin_log.h deleted file mode 100644 index 0cf7817573c..00000000000 --- a/include/mysql/service_my_plugin_log.h +++ /dev/null @@ -1,64 +0,0 @@ -/* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; version 2 of the - License. - - 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 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 */ - -/** - @file - This service provides functions to report error conditions and log to - mysql error log. -*/ - -#ifndef MYSQL_SERVICE_MY_PLUGIN_LOG_INCLUDED -#define MYSQL_SERVICE_MY_PLUGIN_LOG_INCLUDED - -#ifndef MYSQL_ABI_CHECK -#include <stdarg.h> -#endif - -/* keep in sync with the loglevel enum in my_sys.h */ -enum plugin_log_level -{ - MY_ERROR_LEVEL, - MY_WARNING_LEVEL, - MY_INFORMATION_LEVEL -}; - - -#ifdef __cplusplus -extern "C" { -#endif - -extern struct my_plugin_log_service -{ - /** write a message to the log */ - int (*my_plugin_log_message)(MYSQL_PLUGIN *, enum plugin_log_level, const char *, ...); -} *my_plugin_log_service; - -#ifdef MYSQL_DYNAMIC_PLUGIN - -#define my_plugin_log_message my_plugin_log_service->my_plugin_log_message - -#else - -int my_plugin_log_message(MYSQL_PLUGIN *plugin, enum plugin_log_level level, - const char *format, ...); - -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/mysql/service_my_print_error.h b/include/mysql/service_my_print_error.h new file mode 100644 index 00000000000..636151655e5 --- /dev/null +++ b/include/mysql/service_my_print_error.h @@ -0,0 +1,64 @@ +/* Copyright (c) 2016, MariaDB + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +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 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 MYSQL_SERVICE_MY_PRINT_ERROR_INCLUDED +#define MYSQL_SERVICE_MY_PRINT_ERROR_INCLUDED + +/** + @file include/mysql/service_my_print_error.h + + This service provides functions for plugins to report + errors to client (without client, the errors are written to the error log). + +*/ +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef MYSQL_ABI_CHECK +#include <stdarg.h> +#include <stdlib.h> +#endif + +#define ME_ERROR_LOG 64 /* Write the message to the error log */ +#define ME_NOTE 1024 /* Not an error, just a note */ +#define ME_WARNING 2048 /* Not an error, just a warning */ +#define ME_FATAL 4096 /* Fatal statement error */ + +extern struct my_print_error_service_st { + void (*my_error_func)(unsigned int nr, unsigned long MyFlags, ...); + void (*my_printf_error_func)(unsigned int nr, const char *fmt, unsigned long MyFlags,...); + void (*my_printv_error_func)(unsigned int error, const char *format, unsigned long MyFlags, va_list ap); +} *my_print_error_service; + +#ifdef MYSQL_DYNAMIC_PLUGIN + +#define my_error my_print_error_service->my_error_func +#define my_printf_error my_print_error_service->my_printf_error_func +#define my_printv_error(A,B,C,D) my_print_error_service->my_printv_error_func(A,B,C,D) + +#else + +extern void my_error(unsigned int nr, unsigned long MyFlags, ...); +extern void my_printf_error(unsigned int my_err, const char *format, unsigned long MyFlags, ...); +extern void my_printv_error(unsigned int error, const char *format, unsigned long MyFlags,va_list ap); +#endif + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/include/mysql/service_my_snprintf.h b/include/mysql/service_my_snprintf.h index d4ce97076e6..4a99561dd00 100644 --- a/include/mysql/service_my_snprintf.h +++ b/include/mysql/service_my_snprintf.h @@ -55,7 +55,7 @@ Supported formats are 's' (null pointer is accepted, printed as "(null)"), 'b' (extension, see below), 'c', 'd', 'i', 'u', 'x', 'o', - 'X', 'p' (works as 0x%x), 'f', 'g'. + 'X', 'p' (works as 0x%x), 'f', 'g', 'M' (extension, see below). Standard syntax for positional arguments $n is supported. @@ -65,6 +65,10 @@ Format 'b': binary buffer, prints exactly <precision> bytes from the argument, without stopping at '\0'. + + Format 'M': takes one integer, prints this integer, space, double quote + error message, double quote. In other words + printf("%M", n) === printf("%d \"%s\"", n, strerror(n)) */ #ifdef __cplusplus diff --git a/include/mysql/service_progress_report.h b/include/mysql/service_progress_report.h index 7ec3aa4c946..fc935b6bd0c 100644 --- a/include/mysql/service_progress_report.h +++ b/include/mysql/service_progress_report.h @@ -12,7 +12,7 @@ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ /** @file diff --git a/include/mysql/service_sha1.h b/include/mysql/service_sha1.h index 01f5ba81566..e000c898dd7 100644 --- a/include/mysql/service_sha1.h +++ b/include/mysql/service_sha1.h @@ -1,5 +1,5 @@ #ifndef MYSQL_SERVICE_SHA1_INCLUDED -/* Copyright (c) 2013, Monty Program Ab +/* Copyright (c) 2013, 2014, Monty Program Ab This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -34,17 +34,29 @@ extern "C" { extern struct my_sha1_service_st { void (*my_sha1_type)(unsigned char*, const char*, size_t); void (*my_sha1_multi_type)(unsigned char*, ...); + size_t (*my_sha1_context_size_type)(); + void (*my_sha1_init_type)(void *); + void (*my_sha1_input_type)(void *, const unsigned char *, size_t); + void (*my_sha1_result_type)(void *, unsigned char *); } *my_sha1_service; #ifdef MYSQL_DYNAMIC_PLUGIN #define my_sha1(A,B,C) my_sha1_service->my_sha1_type(A,B,C) #define my_sha1_multi my_sha1_service->my_sha1_multi_type +#define my_sha1_context_size() my_sha1_service->my_sha1_context_size_type() +#define my_sha1_init(A) my_sha1_service->my_sha1_init_type(A) +#define my_sha1_input(A,B,C) my_sha1_service->my_sha1_input_type(A,B,C) +#define my_sha1_result(A,B) my_sha1_service->my_sha1_result_type(A,B) #else void my_sha1(unsigned char*, const char*, size_t); void my_sha1_multi(unsigned char*, ...); +size_t my_sha1_context_size(); +void my_sha1_init(void *context); +void my_sha1_input(void *context, const unsigned char *buf, size_t len); +void my_sha1_result(void *context, unsigned char *digest); #endif diff --git a/include/mysql/service_sha2.h b/include/mysql/service_sha2.h new file mode 100644 index 00000000000..ee4975f7f24 --- /dev/null +++ b/include/mysql/service_sha2.h @@ -0,0 +1,130 @@ +#ifndef MYSQL_SERVICE_SHA2_INCLUDED +/* Copyright (c) 2017, MariaDB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + 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 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 */ + +/** + @file + my sha2 service + + Functions to calculate SHA2 hash from a memory buffer +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef MYSQL_ABI_CHECK +#include <stdlib.h> +#endif + +extern struct my_sha2_service_st { + void (*my_sha224_type)(unsigned char*, const char*, size_t); + void (*my_sha224_multi_type)(unsigned char*, ...); + size_t (*my_sha224_context_size_type)(); + void (*my_sha224_init_type)(void *); + void (*my_sha224_input_type)(void *, const unsigned char *, size_t); + void (*my_sha224_result_type)(void *, unsigned char *); + + void (*my_sha256_type)(unsigned char*, const char*, size_t); + void (*my_sha256_multi_type)(unsigned char*, ...); + size_t (*my_sha256_context_size_type)(); + void (*my_sha256_init_type)(void *); + void (*my_sha256_input_type)(void *, const unsigned char *, size_t); + void (*my_sha256_result_type)(void *, unsigned char *); + + void (*my_sha384_type)(unsigned char*, const char*, size_t); + void (*my_sha384_multi_type)(unsigned char*, ...); + size_t (*my_sha384_context_size_type)(); + void (*my_sha384_init_type)(void *); + void (*my_sha384_input_type)(void *, const unsigned char *, size_t); + void (*my_sha384_result_type)(void *, unsigned char *); + + void (*my_sha512_type)(unsigned char*, const char*, size_t); + void (*my_sha512_multi_type)(unsigned char*, ...); + size_t (*my_sha512_context_size_type)(); + void (*my_sha512_init_type)(void *); + void (*my_sha512_input_type)(void *, const unsigned char *, size_t); + void (*my_sha512_result_type)(void *, unsigned char *); +} *my_sha2_service; + +#ifdef MYSQL_DYNAMIC_PLUGIN + +#define my_sha224(A,B,C) my_sha2_service->my_sha224_type(A,B,C) +#define my_sha224_multi my_sha2_service->my_sha224_multi_type +#define my_sha224_context_size() my_sha2_service->my_sha224_context_size_type() +#define my_sha224_init(A) my_sha2_service->my_sha224_init_type(A) +#define my_sha224_input(A,B,C) my_sha2_service->my_sha224_input_type(A,B,C) +#define my_sha224_result(A,B) my_sha2_service->my_sha224_result_type(A,B) + +#define my_sha256(A,B,C) my_sha2_service->my_sha256_type(A,B,C) +#define my_sha256_multi my_sha2_service->my_sha256_multi_type +#define my_sha256_context_size() my_sha2_service->my_sha256_context_size_type() +#define my_sha256_init(A) my_sha2_service->my_sha256_init_type(A) +#define my_sha256_input(A,B,C) my_sha2_service->my_sha256_input_type(A,B,C) +#define my_sha256_result(A,B) my_sha2_service->my_sha256_result_type(A,B) + +#define my_sha384(A,B,C) my_sha2_service->my_sha384_type(A,B,C) +#define my_sha384_multi my_sha2_service->my_sha384_multi_type +#define my_sha384_context_size() my_sha2_service->my_sha384_context_size_type() +#define my_sha384_init(A) my_sha2_service->my_sha384_init_type(A) +#define my_sha384_input(A,B,C) my_sha2_service->my_sha384_input_type(A,B,C) +#define my_sha384_result(A,B) my_sha2_service->my_sha384_result_type(A,B) + +#define my_sha512(A,B,C) my_sha2_service->my_sha512_type(A,B,C) +#define my_sha512_multi my_sha2_service->my_sha512_multi_type +#define my_sha512_context_size() my_sha2_service->my_sha512_context_size_type() +#define my_sha512_init(A) my_sha2_service->my_sha512_init_type(A) +#define my_sha512_input(A,B,C) my_sha2_service->my_sha512_input_type(A,B,C) +#define my_sha512_result(A,B) my_sha2_service->my_sha512_result_type(A,B) + +#else + +void my_sha224(unsigned char*, const char*, size_t); +void my_sha224_multi(unsigned char*, ...); +size_t my_sha224_context_size(); +void my_sha224_init(void *context); +void my_sha224_input(void *context, const unsigned char *buf, size_t len); +void my_sha224_result(void *context, unsigned char *digest); + +void my_sha256(unsigned char*, const char*, size_t); +void my_sha256_multi(unsigned char*, ...); +size_t my_sha256_context_size(); +void my_sha256_init(void *context); +void my_sha256_input(void *context, const unsigned char *buf, size_t len); +void my_sha256_result(void *context, unsigned char *digest); + +void my_sha384(unsigned char*, const char*, size_t); +void my_sha384_multi(unsigned char*, ...); +size_t my_sha384_context_size(); +void my_sha384_init(void *context); +void my_sha384_input(void *context, const unsigned char *buf, size_t len); +void my_sha384_result(void *context, unsigned char *digest); + +void my_sha512(unsigned char*, const char*, size_t); +void my_sha512_multi(unsigned char*, ...); +size_t my_sha512_context_size(); +void my_sha512_init(void *context); +void my_sha512_input(void *context, const unsigned char *buf, size_t len); +void my_sha512_result(void *context, unsigned char *digest); + +#endif + +#ifdef __cplusplus +} +#endif + +#define MYSQL_SERVICE_SHA2_INCLUDED +#endif + diff --git a/include/mysql/service_thd_alloc.h b/include/mysql/service_thd_alloc.h index 645fb310cbc..e92f81b52c3 100644 --- a/include/mysql/service_thd_alloc.h +++ b/include/mysql/service_thd_alloc.h @@ -16,7 +16,7 @@ /** @file - This service provdes functions to allocate memory in a connection local + This service provides functions to allocate memory in a connection local memory pool. The memory allocated there will be automatically freed at the end of the statement, don't use it for allocations that should live longer than that. For short living allocations this is more efficient than diff --git a/include/mysql/service_thd_rnd.h b/include/mysql/service_thd_rnd.h new file mode 100644 index 00000000000..21133c7889f --- /dev/null +++ b/include/mysql/service_thd_rnd.h @@ -0,0 +1,62 @@ +#ifndef MYSQL_SERVICE_THD_RND_INCLUDED +/* Copyright (C) 2017 MariaDB Corporation + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + 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 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 */ + +/** + @file + This service provides access to the thd-local random number generator. + + It's preferrable over the global one, because concurrent threads + can generate random numbers without fighting each other over the access + to the shared rnd state. +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef MYSQL_ABI_CHECK +#include <stdlib.h> +#endif + +extern struct thd_rnd_service_st { + double (*thd_rnd_ptr)(MYSQL_THD thd); + void (*thd_c_r_p_ptr)(MYSQL_THD thd, char *to, size_t length); +} *thd_rnd_service; + +#ifdef MYSQL_DYNAMIC_PLUGIN +#define thd_rnd(A) thd_rnd_service->thd_rnd_ptr(A) +#define thd_create_random_password(A,B,C) thd_rnd_service->thd_c_r_p_ptr(A,B,C) +#else + +double thd_rnd(MYSQL_THD thd); + +/** + Generate string of printable random characters of requested length. + + @param to[out] Buffer for generation; must be at least length+1 bytes + long; result string is always null-terminated + @param length[in] How many random characters to put in buffer +*/ +void thd_create_random_password(MYSQL_THD thd, char *to, size_t length); + +#endif + +#ifdef __cplusplus +} +#endif + +#define MYSQL_SERVICE_THD_RND_INCLUDED +#endif diff --git a/include/mysql/service_thd_specifics.h b/include/mysql/service_thd_specifics.h new file mode 100644 index 00000000000..161385c387e --- /dev/null +++ b/include/mysql/service_thd_specifics.h @@ -0,0 +1,110 @@ +#ifndef MYSQL_SERVICE_THD_SPECIFICS_INCLUDED +/* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + 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 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 */ + +/** + @file + + THD specific for plugin(s) + + This API provides pthread_getspecific like functionality to plugin authors. + This is a functional alternative to the declarative MYSQL_THDVAR + + A plugin should at init call thd_key_create that create a key that + will have storage in each THD. The key should be used by all threads + and can be used concurrently from all threads. + + A plugin should at deinit call thd_key_delete. + + Alternatively, a plugin can use thd_key_create_from_var(K,V) to create + a key that corresponds to a named MYSQL_THDVAR variable. + + This API is also safe when using pool-of-threads in which case + pthread_getspecific is not, because the actual OS thread may change. + + @note + + Normally one should prefer MYSQL_THDVAR declarative API. + + The benefits are: + + - It supports typed variables (int, char*, enum, etc), not only void*. + - The memory allocated for MYSQL_THDVAR is free'd automatically + (if PLUGIN_VAR_MEMALLOC is specified). + - Continuous loading and unloading of the same plugin does not allocate + memory for same variables over and over again. + + An example of using MYSQL_THDVAR for a thd local storage: + + MYSQL_THDVAR_STR(my_tls, + PLUGIN_VAR_MEMALLOC | PLUGIN_VAR_NOSYSVAR | PLUGIN_VAR_NOCMDOPT, + "thd local storage example", 0, 0, 0); +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef int MYSQL_THD_KEY_T; + +extern struct thd_specifics_service_st { + int (*thd_key_create_func)(MYSQL_THD_KEY_T *key); + void (*thd_key_delete_func)(MYSQL_THD_KEY_T *key); + void *(*thd_getspecific_func)(MYSQL_THD thd, MYSQL_THD_KEY_T key); + int (*thd_setspecific_func)(MYSQL_THD thd, MYSQL_THD_KEY_T key, void *value); +} *thd_specifics_service; + +#define thd_key_create_from_var(K, V) do { *(K)= MYSQL_SYSVAR_NAME(V).offset; } while(0) + +#ifdef MYSQL_DYNAMIC_PLUGIN + +#define thd_key_create(K) (thd_specifics_service->thd_key_create_func(K)) +#define thd_key_delete(K) (thd_specifics_service->thd_key_delete_func(K)) +#define thd_getspecific(T, K) (thd_specifics_service->thd_getspecific_func(T, K)) +#define thd_setspecific(T, K, V) (thd_specifics_service->thd_setspecific_func(T, K, V)) + +#else + +/** + * create THD specific storage + * @return 0 on success + * else errno is returned + */ +int thd_key_create(MYSQL_THD_KEY_T *key); + +/** + * delete THD specific storage + */ +void thd_key_delete(MYSQL_THD_KEY_T *key); + +/** + * get/set thd specific storage + * - first time this is called from a thread it will return 0 + * - this call is thread-safe in that different threads may call this + * simultaneously if operating on different THDs. + * - this call acquires no mutexes and is implemented as an array lookup + */ +void* thd_getspecific(MYSQL_THD thd, MYSQL_THD_KEY_T key); +int thd_setspecific(MYSQL_THD thd, MYSQL_THD_KEY_T key, void *value); + +#endif + +#ifdef __cplusplus +} +#endif + +#define MYSQL_SERVICE_THD_SPECIFICS_INCLUDED +#endif + diff --git a/include/mysql/service_wsrep.h b/include/mysql/service_wsrep.h new file mode 100644 index 00000000000..b51f154422f --- /dev/null +++ b/include/mysql/service_wsrep.h @@ -0,0 +1,223 @@ +#ifndef MYSQL_SERVICE_WSREP_INCLUDED +/* Copyright (c) 2015 MariaDB Corporation Ab + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + 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 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 */ + +/** + @file + wsrep service + + Interface to WSREP functionality in the server. + For engines that want to support galera. +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +enum wsrep_conflict_state { + NO_CONFLICT, + MUST_ABORT, + ABORTING, + ABORTED, + MUST_REPLAY, + REPLAYING, + RETRY_AUTOCOMMIT, + CERT_FAILURE, +}; + +enum wsrep_exec_mode { + /* Transaction processing before replication. */ + LOCAL_STATE, + /* Slave thread applying write sets from other nodes or replaying thread. */ + REPL_RECV, + /* Total-order-isolation mode. */ + TOTAL_ORDER, + /* + Transaction procession after it has been replicated in prepare stage and + has passed certification. + */ + LOCAL_COMMIT +}; + +enum wsrep_query_state { + QUERY_IDLE, + QUERY_EXEC, + QUERY_COMMITTING, + QUERY_EXITING, + QUERY_ROLLINGBACK, +}; + +enum wsrep_trx_status { + WSREP_TRX_OK, + WSREP_TRX_CERT_FAIL, /* certification failure, must abort */ + WSREP_TRX_SIZE_EXCEEDED, /* trx size exceeded */ + WSREP_TRX_ERROR, /* native mysql error */ +}; + +struct xid_t; +struct wsrep; +struct wsrep_ws_handle; +struct wsrep_buf; + +extern struct wsrep_service_st { + struct wsrep * (*get_wsrep_func)(); + my_bool (*get_wsrep_certify_nonPK_func)(); + my_bool (*get_wsrep_debug_func)(); + my_bool (*get_wsrep_drupal_282555_workaround_func)(); + my_bool (*get_wsrep_recovery_func)(); + my_bool (*get_wsrep_load_data_splitting_func)(); + my_bool (*get_wsrep_log_conflicts_func)(); + long (*get_wsrep_protocol_version_func)(); + my_bool (*wsrep_aborting_thd_contains_func)(THD *thd); + void (*wsrep_aborting_thd_enqueue_func)(THD *thd); + bool (*wsrep_consistency_check_func)(THD *thd); + int (*wsrep_is_wsrep_xid_func)(const struct xid_t *xid); + void (*wsrep_lock_rollback_func)(); + int (*wsrep_on_func)(MYSQL_THD); + void (*wsrep_post_commit_func)(THD* thd, bool all); + bool (*wsrep_prepare_key_func)(const unsigned char*, size_t, const unsigned char*, size_t, struct wsrep_buf*, size_t*); + enum wsrep_trx_status (*wsrep_run_wsrep_commit_func)(THD *thd, bool all); + void (*wsrep_thd_LOCK_func)(THD *thd); + void (*wsrep_thd_UNLOCK_func)(THD *thd); + void (*wsrep_thd_awake_func)(THD *thd, my_bool signal); + enum wsrep_conflict_state (*wsrep_thd_conflict_state_func)(MYSQL_THD, my_bool); + const char * (*wsrep_thd_conflict_state_str_func)(THD *thd); + enum wsrep_exec_mode (*wsrep_thd_exec_mode_func)(THD *thd); + const char * (*wsrep_thd_exec_mode_str_func)(THD *thd); + enum wsrep_conflict_state (*wsrep_thd_get_conflict_state_func)(MYSQL_THD); + my_bool (*wsrep_thd_is_BF_func)(MYSQL_THD , my_bool); + my_bool (*wsrep_thd_is_wsrep_func)(MYSQL_THD thd); + char * (*wsrep_thd_query_func)(THD *thd); + enum wsrep_query_state (*wsrep_thd_query_state_func)(THD *thd); + const char * (*wsrep_thd_query_state_str_func)(THD *thd); + int (*wsrep_thd_retry_counter_func)(THD *thd); + void (*wsrep_thd_set_conflict_state_func)(THD *thd, enum wsrep_conflict_state state); + bool (*wsrep_thd_ignore_table_func)(THD *thd); + long long (*wsrep_thd_trx_seqno_func)(THD *thd); + struct wsrep_ws_handle * (*wsrep_thd_ws_handle_func)(THD *thd); + int (*wsrep_trx_is_aborting_func)(MYSQL_THD thd); + int (*wsrep_trx_order_before_func)(MYSQL_THD, MYSQL_THD); + void (*wsrep_unlock_rollback_func)(); + void (*wsrep_set_data_home_dir_func)(const char *data_dir); +} *wsrep_service; + +#ifdef MYSQL_DYNAMIC_PLUGIN +#define get_wsrep() wsrep_service->get_wsrep_func() +#define get_wsrep_certify_nonPK() wsrep_service->get_wsrep_certify_nonPK_func() +#define get_wsrep_debug() wsrep_service->get_wsrep_debug_func() +#define get_wsrep_drupal_282555_workaround() wsrep_service->get_wsrep_drupal_282555_workaround_func() +#define get_wsrep_recovery() wsrep_service->get_wsrep_recovery_func() +#define get_wsrep_load_data_splitting() wsrep_service->get_wsrep_load_data_splitting_func() +#define get_wsrep_log_conflicts() wsrep_service->get_wsrep_log_conflicts_func() +#define get_wsrep_protocol_version() wsrep_service->get_wsrep_protocol_version_func() +#define wsrep_aborting_thd_contains(T) wsrep_service->wsrep_aborting_thd_contains_func(T) +#define wsrep_aborting_thd_enqueue(T) wsrep_service->wsrep_aborting_thd_enqueue_func(T) +#define wsrep_consistency_check(T) wsrep_service->wsrep_consistency_check_func(T) +#define wsrep_is_wsrep_xid(X) wsrep_service->wsrep_is_wsrep_xid_func(X) +#define wsrep_lock_rollback() wsrep_service->wsrep_lock_rollback_func() +#define wsrep_on(X) wsrep_service->wsrep_on_func(X) +#define wsrep_post_commit(T,A) wsrep_service->wsrep_post_commit_func(T,A) +#define wsrep_prepare_key(A,B,C,D,E,F) wsrep_service->wsrep_prepare_key_func(A,B,C,D,E,F) +#define wsrep_run_wsrep_commit(T,A) wsrep_service->wsrep_run_wsrep_commit_func(T,A) +#define wsrep_thd_LOCK(T) wsrep_service->wsrep_thd_LOCK_func(T) +#define wsrep_thd_UNLOCK(T) wsrep_service->wsrep_thd_UNLOCK_func(T) +#define wsrep_thd_awake(T,S) wsrep_service->wsrep_thd_awake_func(T,S) +#define wsrep_thd_conflict_state(T,S) wsrep_service->wsrep_thd_conflict_state_func(T,S) +#define wsrep_thd_conflict_state_str(T) wsrep_service->wsrep_thd_conflict_state_str_func(T) +#define wsrep_thd_exec_mode(T) wsrep_service->wsrep_thd_exec_mode_func(T) +#define wsrep_thd_exec_mode_str(T) wsrep_service->wsrep_thd_exec_mode_str_func(T) +#define wsrep_thd_get_conflict_state(T) wsrep_service->wsrep_thd_get_conflict_state_func(T) +#define wsrep_thd_is_BF(T,S) wsrep_service->wsrep_thd_is_BF_func(T,S) +#define wsrep_thd_is_wsrep(T) wsrep_service->wsrep_thd_is_wsrep_func(T) +#define wsrep_thd_query(T) wsrep_service->wsrep_thd_query_func(T) +#define wsrep_thd_query_state(T) wsrep_service->wsrep_thd_query_state_func(T) +#define wsrep_thd_query_state_str(T) wsrep_service->wsrep_thd_query_state_str_func(T) +#define wsrep_thd_retry_counter(T) wsrep_service->wsrep_thd_retry_counter_func(T) +#define wsrep_thd_set_conflict_state(T,S) wsrep_service->wsrep_thd_set_conflict_state_func(T,S) +#define wsrep_thd_ignore_table(T) wsrep_service->wsrep_thd_ignore_table_func(T) +#define wsrep_thd_trx_seqno(T) wsrep_service->wsrep_thd_trx_seqno_func(T) +#define wsrep_thd_ws_handle(T) wsrep_service->wsrep_thd_ws_handle_func(T) +#define wsrep_trx_is_aborting(T) wsrep_service->wsrep_trx_is_aborting_func(T) +#define wsrep_trx_order_before(T1,T2) wsrep_service->wsrep_trx_order_before_func(T1,T2) +#define wsrep_unlock_rollback() wsrep_service->wsrep_unlock_rollback_func() +#define wsrep_set_data_home_dir(A) wsrep_service->wsrep_set_data_home_dir_func(A) + +#define wsrep_debug get_wsrep_debug() +#define wsrep_log_conflicts get_wsrep_log_conflicts() +#define wsrep_certify_nonPK get_wsrep_certify_nonPK() +#define wsrep_load_data_splitting get_wsrep_load_data_splitting() +#define wsrep_drupal_282555_workaround get_wsrep_drupal_282555_workaround() +#define wsrep_recovery get_wsrep_recovery() +#define wsrep_protocol_version get_wsrep_protocol_version() + +#else + +extern my_bool wsrep_debug; +extern my_bool wsrep_log_conflicts; +extern my_bool wsrep_certify_nonPK; +extern my_bool wsrep_load_data_splitting; +extern my_bool wsrep_drupal_282555_workaround; +extern my_bool wsrep_recovery; +extern long wsrep_protocol_version; + +bool wsrep_consistency_check(THD *thd); +bool wsrep_prepare_key(const unsigned char* cache_key, size_t cache_key_len, const unsigned char* row_id, size_t row_id_len, struct wsrep_buf* key, size_t* key_len); +char *wsrep_thd_query(THD *thd); +const char *wsrep_thd_conflict_state_str(THD *thd); +const char *wsrep_thd_exec_mode_str(THD *thd); +const char *wsrep_thd_query_state_str(THD *thd); +enum wsrep_conflict_state wsrep_thd_conflict_state(MYSQL_THD thd, my_bool sync); +enum wsrep_conflict_state wsrep_thd_get_conflict_state(MYSQL_THD thd); +enum wsrep_exec_mode wsrep_thd_exec_mode(THD *thd); +enum wsrep_query_state wsrep_thd_query_state(THD *thd); +enum wsrep_trx_status wsrep_run_wsrep_commit(THD *thd, bool all); +int wsrep_is_wsrep_xid(const struct xid_t* xid); +int wsrep_on(MYSQL_THD thd); +int wsrep_thd_retry_counter(THD *thd); +int wsrep_trx_is_aborting(MYSQL_THD thd); +int wsrep_trx_order_before(MYSQL_THD thd1, MYSQL_THD thd2); +long get_wsrep_protocol_version(); +long long wsrep_thd_trx_seqno(THD *thd); +my_bool get_wsrep_certify_nonPK(); +my_bool get_wsrep_debug(); +my_bool get_wsrep_drupal_282555_workaround(); +my_bool get_wsrep_recovery(); +my_bool get_wsrep_load_data_splitting(); +my_bool get_wsrep_log_conflicts(); +my_bool wsrep_aborting_thd_contains(THD *thd); +my_bool wsrep_thd_is_BF(MYSQL_THD thd, my_bool sync); +my_bool wsrep_thd_is_wsrep(MYSQL_THD thd); +struct wsrep *get_wsrep(); +struct wsrep_ws_handle *wsrep_thd_ws_handle(THD *thd); +void wsrep_aborting_thd_enqueue(THD *thd); +void wsrep_lock_rollback(); +void wsrep_post_commit(THD* thd, bool all); +void wsrep_thd_LOCK(THD *thd); +void wsrep_thd_UNLOCK(THD *thd); +void wsrep_thd_awake(THD *thd, my_bool signal); +void wsrep_thd_set_conflict_state(THD *thd, enum wsrep_conflict_state state); +bool wsrep_thd_ignore_table(THD *thd); +void wsrep_unlock_rollback(); +void wsrep_set_data_home_dir(const char *data_dir); + +#endif + +#ifdef __cplusplus +} +#endif + +#define MYSQL_SERVICE_WSREP_INCLUDED +#endif + diff --git a/include/mysql/services.h b/include/mysql/services.h index 62cac338703..6168c5ed8dc 100644 --- a/include/mysql/services.h +++ b/include/mysql/services.h @@ -1,6 +1,6 @@ #ifndef MYSQL_SERVICES_INCLUDED /* Copyright (c) 2009, 2010, Oracle and/or its affiliates. - Copyright (c) 2012, 2013, Monty Program Ab + Copyright (c) 2012, 2017, MariaDB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,17 +19,27 @@ extern "C" { #endif -#include <mysql/service_my_snprintf.h> -#include <mysql/service_thd_alloc.h> -#include <mysql/service_thd_wait.h> -#include <mysql/service_progress_report.h> +#include <mysql/service_base64.h> #include <mysql/service_debug_sync.h> +#include <mysql/service_encryption.h> +#include <mysql/service_encryption_scheme.h> #include <mysql/service_kill_statement.h> -#include <mysql/service_thd_timezone.h> -#include <mysql/service_sha1.h> #include <mysql/service_logger.h> +#include <mysql/service_md5.h> +#include <mysql/service_my_crypt.h> +#include <mysql/service_my_print_error.h> +#include <mysql/service_my_snprintf.h> +#include <mysql/service_progress_report.h> +#include <mysql/service_sha1.h> +#include <mysql/service_sha2.h> +#include <mysql/service_thd_alloc.h> #include <mysql/service_thd_autoinc.h> #include <mysql/service_thd_error_context.h> +#include <mysql/service_thd_rnd.h> +#include <mysql/service_thd_specifics.h> +#include <mysql/service_thd_timezone.h> +#include <mysql/service_thd_wait.h> +/*#include <mysql/service_wsrep.h>*/ #ifdef __cplusplus } diff --git a/include/mysql_async.h b/include/mysql_async.h index 2728b9c1dc7..04b975211db 100644 --- a/include/mysql_async.h +++ b/include/mysql_async.h @@ -11,7 +11,7 @@ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ /* Common definitions for MariaDB non-blocking client library. */ diff --git a/include/mysql_com.h b/include/mysql_com.h index 3c8301eddbf..dd55daf77aa 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -186,11 +186,7 @@ enum enum_server_command #define REFRESH_USER_RESOURCES (1ULL << 19) #define REFRESH_FOR_EXPORT (1ULL << 20) /* FLUSH TABLES ... FOR EXPORT */ -#define REFRESH_TABLE_STATS (1ULL << 27) /* Refresh table stats hash table */ -#define REFRESH_INDEX_STATS (1ULL << 28) /* Refresh index stats hash table */ -#define REFRESH_USER_STATS (1ULL << 29) /* Refresh user stats hash table */ -#define REFRESH_CLIENT_STATS (1ULL << 30) /* Refresh client stats hash table */ - +#define REFRESH_GENERIC (1ULL << 30) #define REFRESH_FAST (1ULL << 31) /* Intern flag */ #define CLIENT_LONG_PASSWORD 1 /* new more secure passwords */ @@ -214,8 +210,6 @@ enum enum_server_command #define CLIENT_PS_MULTI_RESULTS (1UL << 18) /* Multi-results in PS-protocol */ #define CLIENT_PLUGIN_AUTH (1UL << 19) /* Client supports plugin authentication */ - -#define CLIENT_PLUGIN_AUTH (1UL << 19) /* Client supports plugin authentication */ #define CLIENT_CONNECT_ATTRS (1UL << 20) /* Client supports connection attributes */ /* Enable authentication response packet to be larger than 255 bytes. */ #define CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA (1UL << 21) @@ -354,9 +348,6 @@ enum enum_server_command #define NET_WRITE_TIMEOUT 60 /* Timeout on write */ #define NET_WAIT_TIMEOUT 8*60*60 /* Wait for new query */ -#define ONLY_KILL_QUERY 1 - - struct st_vio; /* Only C */ typedef struct st_vio Vio; @@ -395,10 +386,7 @@ typedef struct st_net { queries in cache that have not stored its results yet */ #endif - /* - Unused, please remove with the next incompatible ABI change. - */ - unsigned char *unused; + void *thd; /* Used by MariaDB server to avoid calling current_thd */ unsigned int last_errno; unsigned char error; my_bool unused4; /* Please remove with the next incompatible ABI change. */ @@ -504,12 +492,6 @@ enum mysql_enum_shutdown_level { SHUTDOWN_WAIT_CRITICAL_BUFFERS= (MYSQL_SHUTDOWN_KILLABLE_UPDATE << 1) + 1 }; -/* Compatibility */ -#if !defined(MYSQL_SERVER) && defined(USE_OLD_FUNCTIONS) -#define KILL_QUERY SHUTDOWN_KILL_QUERY -#define KILL_CONNECTION SHUTDOWN_KILL_CONNECTION -#endif - enum enum_cursor_type { CURSOR_TYPE_NO_CURSOR= 0, @@ -532,7 +514,7 @@ enum enum_mysql_set_option extern "C" { #endif -my_bool my_net_init(NET *net, Vio* vio, unsigned int my_flags); +my_bool my_net_init(NET *net, Vio* vio, void *thd, unsigned int my_flags); void my_net_local_init(NET *net); void net_end(NET *net); void net_clear(NET *net, my_bool clear_buffer); @@ -565,7 +547,7 @@ struct my_rnd_struct; enum Item_result { STRING_RESULT=0, REAL_RESULT, INT_RESULT, ROW_RESULT, DECIMAL_RESULT, - TIME_RESULT,IMPOSSIBLE_RESULT + TIME_RESULT }; typedef struct st_udf_args @@ -620,17 +602,11 @@ void scramble_323(char *to, const char *message, const char *password); my_bool check_scramble_323(const unsigned char *reply, const char *message, unsigned long *salt); void get_salt_from_password_323(unsigned long *res, const char *password); -#if MYSQL_VERSION_ID < 100100 -void make_password_from_salt_323(char *to, const unsigned long *salt); -#endif void make_scrambled_password(char *to, const char *password); void scramble(char *to, const char *message, const char *password); my_bool check_scramble(const unsigned char *reply, const char *message, const unsigned char *hash_stage2); void get_salt_from_password(unsigned char *res, const char *password); -#if MYSQL_VERSION_ID < 100100 -void make_password_from_salt(char *to, const unsigned char *hash_stage2); -#endif char *octet2hex(char *to, const char *str, unsigned int len); /* end of password.c */ diff --git a/include/mysql_version.h.in b/include/mysql_version.h.in index cceb4e984c7..f22e00dabb9 100644 --- a/include/mysql_version.h.in +++ b/include/mysql_version.h.in @@ -23,6 +23,10 @@ #define MYSQL_CONFIG_NAME "my" #define MYSQL_COMPILATION_COMMENT "@COMPILATION_COMMENT@" +#ifdef WITH_WSREP +#define WSREP_PATCH_VERSION "@WSREP_PATCH_VERSION@" +#endif + /* mysqld compile time options */ #endif /* _CUSTOMCONFIG_ */ diff --git a/include/mysqld_default_groups.h b/include/mysqld_default_groups.h index 30dfdae1338..3bc82359787 100644 --- a/include/mysqld_default_groups.h +++ b/include/mysqld_default_groups.h @@ -1,7 +1,4 @@ const char *load_default_groups[]= { -#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE -"mysql_cluster", -#endif "mysqld", "server", MYSQL_BASE_VERSION, "mariadb", MARIADB_BASE_VERSION, "client-server", diff --git a/include/service_versions.h b/include/service_versions.h index ce4a0c931f7..3bbf2a9a625 100644 --- a/include/service_versions.h +++ b/include/service_versions.h @@ -1,5 +1,5 @@ /* Copyright (c) 2009, 2010, Oracle and/or its affiliates. - Copyright (c) 2012, 2013, Monty Program Ab + Copyright (c) 2012, 2017, MariaDB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -23,12 +23,22 @@ #define VERSION_debug_sync 0x1000 #define VERSION_kill_statement 0x1000 +#define VERSION_base64 0x0100 +#define VERSION_encryption 0x0300 +#define VERSION_encryption_scheme 0x0100 +#define VERSION_logger 0x0100 +#define VERSION_my_crypt 0x0100 +#define VERSION_my_md5 0x0100 +#define VERSION_my_print_error 0x0100 +#define VERSION_my_sha1 0x0101 +#define VERSION_my_sha2 0x0100 #define VERSION_my_snprintf 0x0100 -#define VERSION_thd_alloc 0x0100 -#define VERSION_thd_wait 0x0100 #define VERSION_progress_report 0x0100 -#define VERSION_thd_timezone 0x0100 -#define VERSION_my_sha1 0x0100 -#define VERSION_logger 0x0100 +#define VERSION_thd_alloc 0x0100 #define VERSION_thd_autoinc 0x0100 #define VERSION_thd_error_context 0x0200 +#define VERSION_thd_rnd 0x0100 +#define VERSION_thd_specifics 0x0100 +#define VERSION_thd_timezone 0x0100 +#define VERSION_thd_wait 0x0100 +#define VERSION_wsrep 0x0202 diff --git a/include/sha2.h b/include/sha2.h deleted file mode 100644 index 737658e9ced..00000000000 --- a/include/sha2.h +++ /dev/null @@ -1,72 +0,0 @@ -/* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; version 2 of the License. - - 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 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 included_sha2_h -#define included_sha2_h - -#include <my_config.h> - -#if defined(HAVE_YASSL) || defined(HAVE_OPENSSL) - -# ifdef HAVE_STDDEF_H -# include <stddef.h> -# endif - -# ifndef HAVE_YASSL -# include <openssl/sha.h> - -# else - -#include "../extra/yassl/taocrypt/include/sha.hpp" - -# ifdef __cplusplus -extern "C" { -# endif - -#ifndef SHA512_DIGEST_LENGTH -#define SHA512_DIGEST_LENGTH TaoCrypt::SHA512::DIGEST_SIZE -#endif - -#ifndef SHA384_DIGEST_LENGTH -#define SHA384_DIGEST_LENGTH TaoCrypt::SHA384::DIGEST_SIZE -#endif - -#ifndef SHA256_DIGEST_LENGTH -#define SHA256_DIGEST_LENGTH TaoCrypt::SHA256::DIGEST_SIZE -#endif - -#ifndef SHA224_DIGEST_LENGTH -#define SHA224_DIGEST_LENGTH TaoCrypt::SHA224::DIGEST_SIZE -#endif - -#define GEN_YASSL_SHA2_BRIDGE(size) \ -unsigned char* SHA##size(const unsigned char *input_ptr, size_t input_length, \ - char unsigned *output_ptr); - -GEN_YASSL_SHA2_BRIDGE(512); -GEN_YASSL_SHA2_BRIDGE(384); -GEN_YASSL_SHA2_BRIDGE(256); -GEN_YASSL_SHA2_BRIDGE(224); - -#undef GEN_YASSL_SHA2_BRIDGE - -# ifdef __cplusplus -} -# endif - -# endif /* HAVE_YASSL */ - -#endif /* HAVE_OPENSSL || HAVE_YASSL */ -#endif /* included_sha2_h */ diff --git a/include/thr_lock.h b/include/thr_lock.h index f05db666da9..bc916b8ec9c 100644 --- a/include/thr_lock.h +++ b/include/thr_lock.h @@ -20,16 +20,6 @@ #ifdef __cplusplus extern "C" { #endif -#ifdef WITH_WSREP -#include <my_sys.h> - typedef my_bool (* wsrep_thd_is_brute_force_fun)(void *, my_bool); - typedef int (* wsrep_abort_thd_fun)(void *, void *, my_bool); - typedef int (* wsrep_on_fun)(void *); - void wsrep_thr_lock_init( - wsrep_thd_is_brute_force_fun bf_fun, wsrep_abort_thd_fun abort_fun, - my_bool debug, my_bool convert_LOCK_to_trx, wsrep_on_fun on_fun); -#endif - #include <my_pthread.h> #include <my_list.h> @@ -104,10 +94,7 @@ typedef struct st_thr_lock_info { pthread_t thread; my_thread_id thread_id; -#ifdef WITH_WSREP void *mysql_thd; // THD pointer - my_bool in_lock_tables; // true, if inside locking session -#endif } THR_LOCK_INFO; @@ -177,6 +164,16 @@ my_bool thr_reschedule_write_lock(THR_LOCK_DATA *data, ulong lock_wait_timeout); void thr_set_lock_wait_callback(void (*before_wait)(void), void (*after_wait)(void)); + +#ifdef WITH_WSREP + typedef my_bool (* wsrep_thd_is_brute_force_fun)(void *, my_bool); + typedef int (* wsrep_abort_thd_fun)(void *, void *, my_bool); + typedef int (* wsrep_on_fun)(void *); + void wsrep_thr_lock_init( + wsrep_thd_is_brute_force_fun bf_fun, wsrep_abort_thd_fun abort_fun, + my_bool debug, my_bool convert_LOCK_to_trx, wsrep_on_fun on_fun); +#endif + #ifdef __cplusplus } #endif diff --git a/include/thr_timer.h b/include/thr_timer.h new file mode 100644 index 00000000000..724fdac41c8 --- /dev/null +++ b/include/thr_timer.h @@ -0,0 +1,45 @@ +/* Copyright (c) 2014 Monty Program Ab + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 or later of the License. + + 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 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 */ + +/* Prototypes when using thr_timer functions */ + +#ifndef THR_TIMER_INCLUDED +#define THR_TIMER_INCLUDED +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct st_timer { + struct timespec expire_time; + my_bool expired; + uint index_in_queue; + void (*func)(void*); + void *func_arg; +} thr_timer_t; + +/* Main functions for library */ +my_bool init_thr_timer(uint init_size_for_timer_queue); +void end_thr_timer(); + +/* Functions for handling one timer */ +void thr_timer_init(thr_timer_t *timer_data, void(*function)(void*), + void *arg); +my_bool thr_timer_settime(thr_timer_t *timer_data, ulonglong microseconds); +void thr_timer_end(thr_timer_t *timer_data); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* THR_TIMER_INCLUDED */ diff --git a/include/typelib.h b/include/typelib.h index 4504bea4ff7..ab5a0f0d258 100644 --- a/include/typelib.h +++ b/include/typelib.h @@ -29,8 +29,6 @@ typedef struct st_typelib { /* Different types saved here */ extern my_ulonglong find_typeset(char *x, TYPELIB *typelib,int *error_position); extern int find_type_with_warning(const char *x, TYPELIB *typelib, const char *option); -extern int find_type_or_exit(const char *x, TYPELIB *typelib, - const char *option); #define FIND_TYPE_BASIC 0 /** makes @c find_type() require the whole name, no prefix */ #define FIND_TYPE_NO_PREFIX (1 << 0) diff --git a/include/waiting_threads.h b/include/waiting_threads.h index e17874b9611..cd4db35701c 100644 --- a/include/waiting_threads.h +++ b/include/waiting_threads.h @@ -11,7 +11,7 @@ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ #ifndef _waiting_threads_h #define _waiting_threads_h diff --git a/include/wqueue.h b/include/wqueue.h index e568ab8e91e..69cb715a97d 100644 --- a/include/wqueue.h +++ b/include/wqueue.h @@ -13,7 +13,7 @@ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ #ifndef WQUEUE_INCLUDED #define WQUEUE_INCLUDED diff --git a/include/wsrep.h b/include/wsrep.h new file mode 100644 index 00000000000..0d32547d69c --- /dev/null +++ b/include/wsrep.h @@ -0,0 +1,71 @@ +/* Copyright 2014 Codership Oy <http://www.codership.com> & SkySQL Ab + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + 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 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 Street, Fifth Floor, Boston, MA 02111-1301 USA */ + +#include <my_config.h> + +#ifndef WSREP_INCLUDED +#define WSREP_INCLUDED + +#ifdef WITH_WSREP +#define IF_WSREP(A,B) A +#define DBUG_ASSERT_IF_WSREP(A) DBUG_ASSERT(A) + +#define WSREP_MYSQL_DB (char *)"mysql" +#define WSREP_TO_ISOLATION_BEGIN(db_, table_, table_list_) \ + if (WSREP_ON && WSREP(thd) && wsrep_to_isolation_begin(thd, db_, table_, table_list_)) \ + goto error; + +#define WSREP_TO_ISOLATION_BEGIN_ALTER(db_, table_, table_list_, alter_info_) \ + if (WSREP_ON && WSREP(thd) && wsrep_to_isolation_begin(thd, db_, table_, \ + table_list_, alter_info_)) \ + goto error; + +#define WSREP_TO_ISOLATION_END \ + if (WSREP_ON && (WSREP(thd) || (thd && thd->wsrep_exec_mode==TOTAL_ORDER))) \ + wsrep_to_isolation_end(thd); + +/* + Checks if lex->no_write_to_binlog is set for statements that use LOCAL or + NO_WRITE_TO_BINLOG. +*/ +#define WSREP_TO_ISOLATION_BEGIN_WRTCHK(db_, table_, table_list_) \ + if (WSREP(thd) && !thd->lex->no_write_to_binlog \ + && wsrep_to_isolation_begin(thd, db_, table_, table_list_)) goto error; + +#define WSREP_DEBUG(...) \ + if (wsrep_debug) WSREP_LOG(sql_print_information, ##__VA_ARGS__) +#define WSREP_INFO(...) WSREP_LOG(sql_print_information, ##__VA_ARGS__) +#define WSREP_WARN(...) WSREP_LOG(sql_print_warning, ##__VA_ARGS__) +#define WSREP_ERROR(...) WSREP_LOG(sql_print_error, ##__VA_ARGS__) + +#define WSREP_SYNC_WAIT(thd_, before_) \ + { if (WSREP_CLIENT(thd_) && \ + wsrep_sync_wait(thd_, before_)) goto error; } + +#else +#define IF_WSREP(A,B) B +#define DBUG_ASSERT_IF_WSREP(A) +#define WSREP_DEBUG(...) +#define WSREP_INFO(...) +#define WSREP_WARN(...) +#define WSREP_ERROR(...) +#define WSREP_TO_ISOLATION_BEGIN(db_, table_, table_list_) +#define WSREP_TO_ISOLATION_END +#define WSREP_TO_ISOLATION_BEGIN_WRTCHK(db_, table_, table_list_) +#define WSREP_SYNC_WAIT(thd_, before_) + +#endif /* WITH_WSREP */ + +#endif /* WSREP_INCLUDED */ |