diff options
Diffstat (limited to 'plugin')
39 files changed, 480 insertions, 179 deletions
diff --git a/plugin/auth_dialog/CMakeLists.txt b/plugin/auth_dialog/CMakeLists.txt index b612dd14fe2..b5e1b2beca0 100644 --- a/plugin/auth_dialog/CMakeLists.txt +++ b/plugin/auth_dialog/CMakeLists.txt @@ -14,9 +14,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA -ADD_DEFINITIONS(-DNO_GET_TTY_PASSWORD) -IF(LIBDL) - SET(LLDL LINK_LIBRARIES dl) -ENDIF() -MYSQL_ADD_PLUGIN(dialog dialog.c ${CMAKE_SOURCE_DIR}/libmysql/get_password.c - MODULE_ONLY CLIENT ${LLDL} COMPONENT ClientPlugins) +# disabled in favor of libmariadb/plugins/auth/dialog.c +# +#MYSQL_ADD_PLUGIN(dialog dialog.c ${CMAKE_SOURCE_DIR}/libmysql/get_password.c +# MODULE_ONLY CLIENT COMPONENT ClientPlugins) diff --git a/plugin/auth_ed25519/CMakeLists.txt b/plugin/auth_ed25519/CMakeLists.txt index 73d8eeb208b..ff6651c528d 100644 --- a/plugin/auth_ed25519/CMakeLists.txt +++ b/plugin/auth_ed25519/CMakeLists.txt @@ -25,8 +25,8 @@ MYSQL_ADD_PLUGIN(auth_ed25519 server_ed25519.c ${REF10_SOURCES} MODULE_ONLY) # client plugin and unit test ed25519-t can use the library MYSQL_ADD_PLUGIN(client_ed25519 client_ed25519.c MODULE_ONLY - CLIENT LINK_LIBRARIES mysys_ssl ref10 COMPONENT ClientPlugins) + CLIENT LINK_LIBRARIES ref10 mysys_ssl COMPONENT ClientPlugins) IF(WITH_UNIT_TESTS) - MY_ADD_TESTS(ed25519 LINK_LIBRARIES mysys ref10) + MY_ADD_TESTS(ed25519 LINK_LIBRARIES ref10 mysys_ssl) ENDIF() diff --git a/plugin/auth_ed25519/server_ed25519.c b/plugin/auth_ed25519/server_ed25519.c index 753d4cb58c3..81fc3e66755 100644 --- a/plugin/auth_ed25519/server_ed25519.c +++ b/plugin/auth_ed25519/server_ed25519.c @@ -33,7 +33,6 @@ static int loaded= 0; static int auth(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info) { - unsigned int i; int pkt_len; unsigned long nonce[CRYPTO_LONGS + NONCE_LONGS]; unsigned char *pkt, *reply= (unsigned char*)nonce; @@ -45,14 +44,14 @@ static int auth(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info) return CR_AUTH_USER_CREDENTIALS; memcpy(pw, info->auth_string, PASSWORD_LEN); pw[PASSWORD_LEN]= '='; - if (base64_decode(pw, PASSWORD_LEN_BUF, pk, NULL, 0) != CRYPTO_PUBLICKEYBYTES) + if (my_base64_decode(pw, PASSWORD_LEN_BUF, pk, NULL, 0) != CRYPTO_PUBLICKEYBYTES) return CR_AUTH_USER_CREDENTIALS; info->password_used= PASSWORD_USED_YES; /* prepare random nonce */ - for (i=CRYPTO_LONGS; i < CRYPTO_LONGS + NONCE_LONGS; i++) - nonce[i]= thd_rnd(info->thd) * ~0UL; + if (my_random_bytes((unsigned char *)nonce, (int)sizeof(nonce))) + return CR_AUTH_USER_CREDENTIALS; /* send it */ if (vio->write_packet(vio, reply + CRYPTO_BYTES, NONCE_BYTES)) @@ -119,7 +118,7 @@ char *ed25519_password(UDF_INIT *initid __attribute__((unused)), *length= PASSWORD_LEN; crypto_sign_keypair(pk, (unsigned char*)args->args[0], args->lengths[0]); - base64_encode(pk, CRYPTO_PUBLICKEYBYTES, result); + my_base64_encode(pk, CRYPTO_PUBLICKEYBYTES, result); return result; } diff --git a/plugin/auth_examples/CMakeLists.txt b/plugin/auth_examples/CMakeLists.txt index 7eed0f722e2..0efd8348ab4 100644 --- a/plugin/auth_examples/CMakeLists.txt +++ b/plugin/auth_examples/CMakeLists.txt @@ -29,5 +29,8 @@ MYSQL_ADD_PLUGIN(qa_auth_client qa_auth_client.c MYSQL_ADD_PLUGIN(auth_0x0100 auth_0x0100.c MODULE_ONLY COMPONENT Test) -MYSQL_ADD_PLUGIN(mysql_clear_password clear_password_client.c - MODULE_ONLY CLIENT COMPONENT ClientPlugins) +# disabled in favor of +# libmariadb/plugins/auth/mariadb_cleartext.c +# +#MYSQL_ADD_PLUGIN(mysql_clear_password clear_password_client.c +# MODULE_ONLY CLIENT COMPONENT ClientPlugins) diff --git a/plugin/auth_examples/qa_auth_client.c b/plugin/auth_examples/qa_auth_client.c index 4421ceed5a0..a915306e60b 100644 --- a/plugin/auth_examples/qa_auth_client.c +++ b/plugin/auth_examples/qa_auth_client.c @@ -90,7 +90,7 @@ static int test_plugin_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql) return CR_ERROR; /* send the reply to the server */ res= vio->write_packet(vio, (const unsigned char *) reply, - strlen(reply) + 1); + (int)strlen(reply) + 1); if (res) return CR_ERROR; diff --git a/plugin/auth_examples/qa_auth_interface.c b/plugin/auth_examples/qa_auth_interface.c index 6b7e9c42adb..6eda10b11fa 100644 --- a/plugin/auth_examples/qa_auth_interface.c +++ b/plugin/auth_examples/qa_auth_interface.c @@ -226,7 +226,7 @@ static int test_plugin_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql) return CR_ERROR; /* send the reply to the server */ res= vio->write_packet(vio, (const unsigned char *) reply, - strlen(reply) + 1); + (int)strlen(reply) + 1); if (res) return CR_ERROR; diff --git a/plugin/auth_examples/test_plugin.c b/plugin/auth_examples/test_plugin.c index ae4e2004bb6..4e3ebf74112 100644 --- a/plugin/auth_examples/test_plugin.c +++ b/plugin/auth_examples/test_plugin.c @@ -205,7 +205,7 @@ static int test_plugin_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql) return CR_ERROR; /* send the reply to the server */ res= vio->write_packet(vio, (const unsigned char *) reply, - strlen(reply) + 1); + (int)strlen(reply) + 1); if (res) return CR_ERROR; diff --git a/plugin/auth_gssapi/CMakeLists.txt b/plugin/auth_gssapi/CMakeLists.txt index 7d9e58e165f..d2f854c2918 100644 --- a/plugin/auth_gssapi/CMakeLists.txt +++ b/plugin/auth_gssapi/CMakeLists.txt @@ -38,8 +38,10 @@ MYSQL_ADD_PLUGIN(auth_gssapi server_plugin.cc ${GSSAPI_SERVER} ${GSSAPI_ERRMSG} COMPONENT gssapi-server MODULE_ONLY) -MYSQL_ADD_PLUGIN(auth_gssapi_client client_plugin.cc ${GSSAPI_CLIENT} ${GSSAPI_ERRMSG} - LINK_LIBRARIES ${GSSAPI_LIBS} - COMPONENT gssapi-client - CLIENT - MODULE_ONLY) +# disabled in favor of libmariadb/plugins/auth/auth_gssapi_client.c +# +#MYSQL_ADD_PLUGIN(auth_gssapi_client client_plugin.cc ${GSSAPI_CLIENT} ${GSSAPI_ERRMSG} +# LINK_LIBRARIES ${GSSAPI_LIBS COMPONENT ClientPlugins} +# COMPONENT gssapi-client +# CLIENT +# MODULE_ONLY) diff --git a/plugin/auth_gssapi/gssapi_server.cc b/plugin/auth_gssapi/gssapi_server.cc index 50c34ecc573..9197b3e06fc 100644 --- a/plugin/auth_gssapi/gssapi_server.cc +++ b/plugin/auth_gssapi/gssapi_server.cc @@ -44,21 +44,21 @@ static char* get_default_principal_name() if(krb5_init_context(&context)) { - my_printf_error(0, "GSSAPI plugin : krb5_init_context failed", + my_printf_error(1, "GSSAPI plugin : krb5_init_context failed", ME_ERROR_LOG | ME_WARNING); goto cleanup; } if (krb5_sname_to_principal(context, NULL, "mariadb", KRB5_NT_SRV_HST, &principal)) { - my_printf_error(0, "GSSAPI plugin : krb5_sname_to_principal failed", + my_printf_error(1, "GSSAPI plugin : krb5_sname_to_principal failed", ME_ERROR_LOG | ME_WARNING); goto cleanup; } if (krb5_unparse_name(context, principal, &unparsed_name)) { - my_printf_error(0, "GSSAPI plugin : krb5_unparse_name failed", + my_printf_error(1, "GSSAPI plugin : krb5_unparse_name failed", ME_ERROR_LOG | ME_WARNING); goto cleanup; } @@ -66,7 +66,7 @@ static char* get_default_principal_name() /* Check for entry in keytab */ if (krb5_kt_read_service_key(context, NULL, principal, 0, (krb5_enctype)0, &key)) { - my_printf_error(0, "GSSAPI plugin : default principal '%s' not found in keytab", + my_printf_error(1, "GSSAPI plugin : default principal '%s' not found in keytab", ME_ERROR_LOG | ME_WARNING, unparsed_name); goto cleanup; } @@ -104,7 +104,7 @@ int plugin_init() /* import service principal from plain text */ if(srv_principal_name && srv_principal_name[0]) { - my_printf_error(0, "GSSAPI plugin : using principal name '%s'", + my_printf_error(1, "GSSAPI plugin : using principal name '%s'", ME_ERROR_LOG | ME_NOTE, srv_principal_name); principal_name_buf.length= strlen(srv_principal_name); principal_name_buf.value= srv_principal_name; diff --git a/plugin/auth_gssapi/mysql-test/auth_gssapi/basic.result b/plugin/auth_gssapi/mysql-test/auth_gssapi/basic.result index 3044f984ffa..b7cf3d8e488 100644 --- a/plugin/auth_gssapi/mysql-test/auth_gssapi/basic.result +++ b/plugin/auth_gssapi/mysql-test/auth_gssapi/basic.result @@ -2,17 +2,23 @@ INSTALL SONAME 'auth_gssapi'; Warnings: Note 1105 SSPI: using principal name 'localhost', mech 'Negotiate' CREATE USER 'GSSAPI_SHORTNAME' IDENTIFIED WITH gssapi; +connect con1,localhost,$GSSAPI_SHORTNAME,,; SELECT USER(),CURRENT_USER(); USER() CURRENT_USER() GSSAPI_SHORTNAME@localhost GSSAPI_SHORTNAME@% +disconnect con1; +connection default; DROP USER 'GSSAPI_SHORTNAME'; CREATE USER nosuchuser IDENTIFIED WITH gssapi; ERROR 28000: GSSAPI name mismatch, requested 'nosuchuser', actual name 'GSSAPI_SHORTNAME' DROP USER nosuchuser; CREATE USER usr1 IDENTIFIED WITH gssapi as 'GSSAPI_FULLNAME'; +connect con1,localhost,usr1,,; SELECT USER(),CURRENT_USER(); USER() CURRENT_USER() usr1@localhost usr1@% +disconnect con1; +connection default; DROP USER usr1; CREATE USER nosuchuser IDENTIFIED WITH gssapi AS 'nosuchuser@EXAMPLE.COM'; ERROR 28000: GSSAPI name mismatch, requested 'nosuchuser@EXAMPLE.COM', actual name 'GSSAPI_FULLNAME' diff --git a/plugin/auth_pipe/auth_pipe.c b/plugin/auth_pipe/auth_pipe.c index ed41b94cfca..902add448f9 100644 --- a/plugin/auth_pipe/auth_pipe.c +++ b/plugin/auth_pipe/auth_pipe.c @@ -36,7 +36,7 @@ static int pipe_auth(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info) unsigned char *pkt; MYSQL_PLUGIN_VIO_INFO vio_info; char username[UNLEN + 1]; - size_t username_length; + DWORD username_length; int ret; /* no user name yet ? read the client handshake packet with the user name */ @@ -54,7 +54,7 @@ static int pipe_auth(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info) if (!ImpersonateNamedPipeClient(vio_info.handle)) return CR_ERROR; - username_length= sizeof(username) - 1; + username_length=UNLEN; ret= CR_ERROR; if (GetUserName(username, &username_length)) { diff --git a/plugin/aws_key_management/CMakeLists.txt b/plugin/aws_key_management/CMakeLists.txt index 49f6b54a24c..e9e1b49d5f2 100644 --- a/plugin/aws_key_management/CMakeLists.txt +++ b/plugin/aws_key_management/CMakeLists.txt @@ -12,12 +12,7 @@ # Give message why the building this plugin is skipped (only if -DVERBOSE is defined) # or if plugin is explicitly requested to build. Then bail out. MACRO(SKIP_AWS_PLUGIN msg) - IF(VERBOSE OR "${PLUGIN_AWS_KEY_MANAGEMENT}" MATCHES "^(STATIC|DYNAMIC)$") - MESSAGE(STATUS "Can't build aws_key_management - ${msg}") - ENDIF() - IF(TARGET aws_key_management) - MESSAGE(FATAL_ERROR "Error configuring aws_key_management - aborting") - ENDIF() + MESSAGE_ONCE(SKIP_AWS_PLUGIN "Skip aws_key_management - ${msg}") RETURN() ENDMACRO() SET(CMAKE_CXX_STANDARD 11) @@ -26,15 +21,6 @@ IF(NOT NOT_FOR_DISTRIBUTION) SKIP_AWS_PLUGIN("AWS SDK has Apache 2.0 License which is not complatible with GPLv2. Set -DNOT_FOR_DISTRIBUTION=ON if you need this plugin") ENDIF() -MYSQL_ADD_PLUGIN(aws_key_management aws_key_management_plugin.cc DISABLED - COMPONENT aws-key-management) - -IF(NOT TARGET aws_key_management) - RETURN() -ELSE() - SET(NON_DISTRIBUTABLE_WARNING "Apache 2.0" PARENT_SCOPE) -ENDIF() - # This plugin needs recent C++ compilers (AWS C++ SDK header files are using C++11 features) SET(CXX11_FLAGS) SET(OLD_COMPILER_MSG "AWS SDK requires c++11 -capable compiler (minimal supported versions are g++ 4.8, clang 3.3, VS2103)") @@ -130,13 +116,10 @@ ELSE() ENDFOREACH() # To be compatible with older cmake, we use older version of the SDK - # We increase the version for macs however, so the newest mac could built it. - IF(APPLE) - SET(GIT_TAG "1.0.100") - ELSEIF(_OPENSSL_VERSION VERSION_EQUAL "1.1") - SET(GIT_TAG "1.0.114") + IF(CMAKE_VERSION LESS "3.0") + SET(GIT_TAG "1.0.8") ELSE() - SET(GIT_TAG "1.0.8") + SET(GIT_TAG "1.2.11") ENDIF() SET(AWS_SDK_PATCH_COMMAND ) @@ -158,6 +141,7 @@ ELSE() "-DCMAKE_CXX_FLAGS_MINSIZEREL=${CMAKE_CXX_FLAGS_MINSIZEREL} ${PIC_FLAG}" ${EXTRA_SDK_CMAKE_FLAGS} -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/aws_sdk_cpp + -DCMAKE_INSTALL_LIBDIR=lib TEST_COMMAND "" ) SET_TARGET_PROPERTIES(aws_sdk_cpp PROPERTIES EXCLUDE_FROM_ALL TRUE) @@ -181,5 +165,10 @@ IF(WIN32) ELSE() SET(AWS_CPP_SDK_DEPENDENCIES ${OPENSSL_LIBRARIES} ${CURL_LIBRARIES} ${UUID_LIBRARIES}) ENDIF() +MYSQL_ADD_PLUGIN(aws_key_management aws_key_management_plugin.cc + LINK_LIBRARIES ${AWS_SDK_LIBS} ${AWS_CPP_SDK_DEPENDENCIES} + COMPONENT aws-key-management) -TARGET_LINK_LIBRARIES(aws_key_management ${AWS_SDK_LIBS} ${AWS_CPP_SDK_DEPENDENCIES}) +IF (TARGET aws_key_management) + SET(NON_DISTRIBUTABLE_WARNING "Apache 2.0" PARENT_SCOPE) +ENDIF() diff --git a/plugin/aws_key_management/aws_key_management_plugin.cc b/plugin/aws_key_management/aws_key_management_plugin.cc index e396be8cbdf..ea407be0e04 100644 --- a/plugin/aws_key_management/aws_key_management_plugin.cc +++ b/plugin/aws_key_management/aws_key_management_plugin.cc @@ -106,6 +106,14 @@ static std::mutex mtx; static Aws::KMS::KMSClient *client; +static void print_kms_error(const char *func, const Aws::Client::AWSError<Aws::KMS::KMSErrors>& err) +{ + my_printf_error(ER_UNKNOWN_ERROR, + "AWS KMS plugin : KMS Client API '%s' failed : %s - %s", + ME_ERROR_LOG, + func, err.GetExceptionName().c_str(), err.GetMessage().c_str()); +} + #if WITH_AWS_MOCK /* Mock routines to test plugin without actual AWS KMS interaction @@ -127,7 +135,7 @@ static int mock_generate_encrypted_key(Aws::Utils::ByteBuffer *result) } -static int mock_decrypt(Aws::Utils::ByteBuffer input, Aws::Utils::ByteBuffer* output, Aws::String *errmsg) +static int mock_decrypt(Aws::Utils::ByteBuffer input, Aws::Utils::ByteBuffer* output) { /* We do not encrypt or decrypt in mock mode.*/ *output = input; @@ -401,14 +409,14 @@ static unsigned int get_latest_key_version_nolock(unsigned int key_id) } /* Decrypt Byte buffer with AWS. */ -static int aws_decrypt(Aws::Utils::ByteBuffer input, Aws::Utils::ByteBuffer* output, Aws::String *errmsg) +static int aws_decrypt(Aws::Utils::ByteBuffer input, Aws::Utils::ByteBuffer* output) { DecryptRequest request; request.SetCiphertextBlob(input); DecryptOutcome outcome = client->Decrypt(request); if (!outcome.IsSuccess()) { - *errmsg = outcome.GetError().GetMessage(); + print_kms_error("Decrypt", outcome.GetError()); return -1; } *output= outcome.GetResult().GetPlaintext(); @@ -416,13 +424,13 @@ static int aws_decrypt(Aws::Utils::ByteBuffer input, Aws::Utils::ByteBuffer* out } -static int decrypt(Aws::Utils::ByteBuffer input, Aws::Utils::ByteBuffer* output, Aws::String *errmsg) +static int decrypt(Aws::Utils::ByteBuffer input, Aws::Utils::ByteBuffer* output) { #if WITH_AWS_MOCK if(mock) - return mock_decrypt(input,output, errmsg); + return mock_decrypt(input,output); #endif - return aws_decrypt(input, output, errmsg); + return aws_decrypt(input, output); } /* @@ -452,12 +460,9 @@ static int read_and_decrypt_key(const char *path, KEY_INFO *info) Aws::Utils::ByteBuffer input((unsigned char *)contents.data(), pos); Aws::Utils::ByteBuffer plaintext; - Aws::String errmsg; - if (decrypt(input, &plaintext, &errmsg)) + if (decrypt(input, &plaintext)) { - my_printf_error(ER_UNKNOWN_ERROR, "AWS KMS plugin: Decrypt failed for %s : %s", ME_ERROR_LOG, path, - errmsg.c_str()); return -1; } @@ -491,9 +496,7 @@ int aws_generate_encrypted_key(Aws::Utils::ByteBuffer *result) outcome= client->GenerateDataKeyWithoutPlaintext(request); if (!outcome.IsSuccess()) { - my_printf_error(ER_UNKNOWN_ERROR, "AWS KMS plugin : GenerateDataKeyWithoutPlaintext failed : %s - %s", ME_ERROR_LOG, - outcome.GetError().GetExceptionName().c_str(), - outcome.GetError().GetMessage().c_str()); + print_kms_error("GenerateDataKeyWithoutPlaintext", outcome.GetError()); return(-1); } *result = outcome.GetResult().GetCiphertextBlob(); diff --git a/plugin/disks/mysql-test/disks/disks.result b/plugin/disks/mysql-test/disks/disks.result index bd6befc5e11..65b1127d479 100644 --- a/plugin/disks/mysql-test/disks/disks.result +++ b/plugin/disks/mysql-test/disks/disks.result @@ -3,9 +3,9 @@ Table Create Table DISKS CREATE TEMPORARY TABLE `DISKS` ( `Disk` varchar(4096) NOT NULL DEFAULT '', `Path` varchar(4096) NOT NULL DEFAULT '', - `Total` int(32) NOT NULL DEFAULT '0', - `Used` int(32) NOT NULL DEFAULT '0', - `Available` int(32) NOT NULL DEFAULT '0' + `Total` int(32) NOT NULL DEFAULT 0, + `Used` int(32) NOT NULL DEFAULT 0, + `Available` int(32) NOT NULL DEFAULT 0 ) ENGINE=MEMORY DEFAULT CHARSET=utf8 select sum(Total) > sum(Available), sum(Total)>sum(Used) from information_schema.disks; sum(Total) > sum(Available) sum(Total)>sum(Used) diff --git a/plugin/feedback/feedback.cc b/plugin/feedback/feedback.cc index 75e6e8ddf17..c76828efa2b 100644 --- a/plugin/feedback/feedback.cc +++ b/plugin/feedback/feedback.cc @@ -112,7 +112,7 @@ static COND* make_cond(THD *thd, TABLE_LIST *tables, LEX_STRING *filter) Item_field *fld= new (thd->mem_root) Item_field(thd, &nrc, db, table, field); Item_string *pattern= new (thd->mem_root) Item_string(thd, filter->str, - filter->length, cs); + (uint) filter->length, cs); Item_string *escape= new (thd->mem_root) Item_string(thd, "\\", 1, cs); if (!fld || !pattern || !escape) diff --git a/plugin/feedback/sender_thread.cc b/plugin/feedback/sender_thread.cc index e22550998a7..3210c1c9e41 100644 --- a/plugin/feedback/sender_thread.cc +++ b/plugin/feedback/sender_thread.cc @@ -89,9 +89,8 @@ static int prepare_for_fill(TABLE_LIST *tables) (every increment of global thread_id counts as a new connection in SHOW STATUS and we want to avoid skewing the statistics) */ - thd->thread_id= thd->variables.pseudo_thread_id= thd_thread_id; + thd->variables.pseudo_thread_id= thd->thread_id; mysql_mutex_lock(&LOCK_thread_count); - thread_count++; threads.append(thd); mysql_mutex_unlock(&LOCK_thread_count); thd->thread_stack= (char*) &tables; @@ -208,7 +207,7 @@ static void send_report(const char *when) SELECT * FROM INFORMATION_SCHEMA.FEEDBACK is doing, read and concatenate table data into a String. */ - if (!(thd= new THD())) + if (!(thd= new THD(thd_thread_id))) return; if (prepare_for_fill(&tables)) @@ -239,7 +238,7 @@ static void send_report(const char *when) Url *url= todo[i]; if (thd) // for nicer SHOW PROCESSLIST - thd->set_query(const_cast<char*>(url->url()), url->url_length()); + thd->set_query(const_cast<char*>(url->url()), (uint) url->url_length()); if (url->send(str.ptr(), str.length())) i++; @@ -263,8 +262,8 @@ ret: */ mysql_mutex_lock(&LOCK_thread_count); thd->set_status_var_init(); - thread_count--; thd->killed= KILL_CONNECTION; + thd->unlink(); mysql_cond_broadcast(&COND_thread_count); mysql_mutex_unlock(&LOCK_thread_count); delete thd; @@ -280,9 +279,7 @@ pthread_handler_t background_thread(void *arg __attribute__((unused))) if (my_thread_init()) return 0; - mysql_mutex_lock(&LOCK_thread_count); - thd_thread_id= thread_id++; - mysql_mutex_unlock(&LOCK_thread_count); + thd_thread_id= next_thread_id(); if (slept_ok(startup_interval)) { diff --git a/plugin/feedback/utils.cc b/plugin/feedback/utils.cc index 684d95a3dbf..650da9b7ac8 100644 --- a/plugin/feedback/utils.cc +++ b/plugin/feedback/utils.cc @@ -151,7 +151,7 @@ namespace feedback { */ #define INSERT2(NAME,LEN,VALUE) \ do { \ - table->field[0]->store(NAME, LEN, system_charset_info); \ + table->field[0]->store(NAME, (uint) LEN, system_charset_info); \ table->field[1]->store VALUE; \ if (schema_table_store_record(thd, table)) \ return 1; \ @@ -159,7 +159,7 @@ namespace feedback { #define INSERT1(NAME,VALUE) \ do { \ - table->field[0]->store(NAME, sizeof(NAME)-1, system_charset_info); \ + table->field[0]->store(NAME, (uint) sizeof(NAME)-1, system_charset_info); \ table->field[1]->store VALUE; \ if (schema_table_store_record(thd, table)) \ return 1; \ @@ -186,7 +186,7 @@ static my_bool show_plugins(THD *thd, plugin_ref plugin, void *arg) (plugin_decl(plugin)->version) & 0xff); INSERT2(name, name_len, - (version, version_len, system_charset_info)); + (version, (uint)version_len, system_charset_info)); name_len= my_snprintf(name, sizeof(name), "%s used", plugin_name(plugin)->str); @@ -358,10 +358,10 @@ int fill_linux_info(THD *thd, TABLE_LIST *tables) #ifdef HAVE_SYS_UTSNAME_H if (have_ubuf) { - INSERT1("Uname_sysname", (ubuf.sysname, strlen(ubuf.sysname), cs)); - INSERT1("Uname_release", (ubuf.release, strlen(ubuf.release), cs)); - INSERT1("Uname_version", (ubuf.version, strlen(ubuf.version), cs)); - INSERT1("Uname_machine", (ubuf.machine, strlen(ubuf.machine), cs)); + INSERT1("Uname_sysname", (ubuf.sysname, (uint) strlen(ubuf.sysname), cs)); + INSERT1("Uname_release", (ubuf.release, (uint) strlen(ubuf.release), cs)); + INSERT1("Uname_version", (ubuf.version, (uint) strlen(ubuf.version), cs)); + INSERT1("Uname_machine", (ubuf.machine, (uint) strlen(ubuf.machine), cs)); } #endif @@ -428,8 +428,8 @@ int calculate_server_uid(char *dest) my_sha1((uint8*) shabuf, (char*) rawbuf, sizeof(rawbuf)); - assert(base64_needed_encoded_length(sizeof(shabuf)) <= SERVER_UID_SIZE); - base64_encode(shabuf, sizeof(shabuf), dest); + assert(my_base64_needed_encoded_length(sizeof(shabuf)) <= SERVER_UID_SIZE); + my_base64_encode(shabuf, sizeof(shabuf), dest); return 0; } diff --git a/plugin/file_key_management/file_key_management_plugin.cc b/plugin/file_key_management/file_key_management_plugin.cc index b5dcbd71f1e..927045ce175 100644 --- a/plugin/file_key_management/file_key_management_plugin.cc +++ b/plugin/file_key_management/file_key_management_plugin.cc @@ -179,6 +179,12 @@ static int file_key_management_plugin_init(void *p) return parser.parse(&keys); } +static int file_key_management_plugin_deinit(void *p) +{ + keys.clear(); + return 0; +} + /* Plugin library descriptor */ @@ -191,7 +197,7 @@ maria_declare_plugin(file_key_management) "File-based key management plugin", PLUGIN_LICENSE_GPL, file_key_management_plugin_init, - NULL, + file_key_management_plugin_deinit, 0x0100 /* 1.0 */, NULL, /* status variables */ settings, diff --git a/plugin/file_key_management/parser.cc b/plugin/file_key_management/parser.cc index 83895fe2808..1ef2e3e8662 100644 --- a/plugin/file_key_management/parser.cc +++ b/plugin/file_key_management/parser.cc @@ -230,9 +230,9 @@ bool Parser::parse_file(std::map<uint,keyentry> *keys, const char *secret) return 0; } -void Parser::report_error(const char *reason, uint position) +void Parser::report_error(const char *reason, size_t position) { - my_printf_error(EE_READ, "%s at %s line %u, column %u", + my_printf_error(EE_READ, "%s at %s line %u, column %zu", ME_ERROR_LOG, reason, filename, line_number, position + 1); } diff --git a/plugin/file_key_management/parser.h b/plugin/file_key_management/parser.h index ca9dedd8acc..e2fda758bf9 100644 --- a/plugin/file_key_management/parser.h +++ b/plugin/file_key_management/parser.h @@ -23,6 +23,7 @@ Created 09/15/2014 #include <my_crypt.h> #include <ctype.h> #include <map> +#include <stdlib.h> /* size_t */ struct keyentry { unsigned int id; @@ -43,7 +44,7 @@ class Parser unsigned char *key, unsigned char *iv); bool read_filekey(const char *filekey, char *secret); bool parse_file(std::map<unsigned int ,keyentry> *keys, const char *secret); - void report_error(const char *reason, unsigned int position); + void report_error(const char *reason, size_t position); int parse_line(char **line_ptr, keyentry *key); char* read_and_decrypt_file(const char *secret); diff --git a/plugin/fulltext/plugin_example.c b/plugin/fulltext/plugin_example.c index f175179e8bb..fb8de478a9f 100644 --- a/plugin/fulltext/plugin_example.c +++ b/plugin/fulltext/plugin_example.c @@ -150,7 +150,7 @@ static void add_word(MYSQL_FTPARSER_PARAM *param, const char *word, size_t len) MYSQL_FTPARSER_BOOLEAN_INFO bool_info= { FT_TOKEN_WORD, 0, 0, 0, 0, ' ', 0 }; - param->mysql_add_word(param, word, len, &bool_info); + param->mysql_add_word(param, word, (int)len, &bool_info); } /* diff --git a/plugin/handler_socket/handlersocket/database.cpp b/plugin/handler_socket/handlersocket/database.cpp index b05b6384565..4292b826753 100644 --- a/plugin/handler_socket/handlersocket/database.cpp +++ b/plugin/handler_socket/handlersocket/database.cpp @@ -278,7 +278,7 @@ dbcontext::init_thread(const void *stack_bottom, volatile int& shutdown_flag) DBG_THR(fprintf(stderr, "HNDSOCK init thread\n")); { my_thread_init(); - thd = new THD; + thd = new THD(0); thd->thread_stack = (char *)stack_bottom; DBG_THR(fprintf(stderr, "thread_stack = %p sizeof(THD)=%zu sizeof(mtx)=%zu " @@ -309,11 +309,8 @@ dbcontext::init_thread(const void *stack_bottom, volatile int& shutdown_flag) DBG_THR(fprintf(stderr, "HNDSOCK x0 %p\n", thd)); } { - pthread_mutex_lock(&LOCK_thread_count); - thd->thread_id = thread_id++; - threads.append(thd); - ++thread_count; - pthread_mutex_unlock(&LOCK_thread_count); + thd->thread_id = next_thread_id(); + add_to_active_threads(thd); } DBG_THR(fprintf(stderr, "HNDSOCK init thread wsts\n")); @@ -350,7 +347,6 @@ dbcontext::term_thread() pthread_mutex_lock(&LOCK_thread_count); delete thd; thd = 0; - --thread_count; pthread_mutex_unlock(&LOCK_thread_count); my_thread_end(); } diff --git a/plugin/handler_socket/libhsclient/allocator.hpp b/plugin/handler_socket/libhsclient/allocator.hpp index 82ff51f00e7..dd3a28ba7bd 100644 --- a/plugin/handler_socket/libhsclient/allocator.hpp +++ b/plugin/handler_socket/libhsclient/allocator.hpp @@ -35,7 +35,7 @@ typedef std::allocator<int> allocator_type; #if 1 #define DENA_ALLOCA_ALLOCATE(typ, len) \ - static_cast<typ *>(alloca((len) * sizeof(typ))) + (typ *) alloca((len) * sizeof(typ)) #define DENA_ALLOCA_FREE(x) #else #define DENA_ALLOCA_ALLOCATE(typ, len) \ diff --git a/plugin/metadata_lock_info/metadata_lock_info.cc b/plugin/metadata_lock_info/metadata_lock_info.cc index 7abae275ff2..f83d9833c9f 100644 --- a/plugin/metadata_lock_info/metadata_lock_info.cc +++ b/plugin/metadata_lock_info/metadata_lock_info.cc @@ -39,6 +39,7 @@ static const LEX_STRING metadata_lock_info_lock_mode[] = { { C_STRING_WITH_LEN("MDL_SHARED_READ") }, { C_STRING_WITH_LEN("MDL_SHARED_WRITE") }, { C_STRING_WITH_LEN("MDL_SHARED_UPGRADABLE") }, + { C_STRING_WITH_LEN("MDL_SHARED_READ_ONLY") }, { C_STRING_WITH_LEN("MDL_SHARED_NO_WRITE") }, { C_STRING_WITH_LEN("MDL_SHARED_NO_READ_WRITE") }, { C_STRING_WITH_LEN("MDL_EXCLUSIVE") }, diff --git a/plugin/qc_info/qc_info.cc b/plugin/qc_info/qc_info.cc index 1dcef004447..e36e490dec3 100644 --- a/plugin/qc_info/qc_info.cc +++ b/plugin/qc_info/qc_info.cc @@ -32,10 +32,11 @@ #define MYSQL_SERVER #endif -#include <sql_cache.h> +#include <my_global.h> #include <sql_parse.h> // check_global_access #include <sql_acl.h> // PROCESS_ACL #include <sql_class.h> // THD +#include <sql_cache.h> #include <table.h> // ST_SCHEMA_TABLE #include <set_var.h> // sql_mode_string_representation #include <tztime.h> diff --git a/plugin/query_response_time/mysql-test/query_response_time/basic.result b/plugin/query_response_time/mysql-test/query_response_time/basic.result index 11cc607df39..d2de1b23e5f 100644 --- a/plugin/query_response_time/mysql-test/query_response_time/basic.result +++ b/plugin/query_response_time/mysql-test/query_response_time/basic.result @@ -7,7 +7,7 @@ SHOW CREATE TABLE INFORMATION_SCHEMA.QUERY_RESPONSE_TIME; Table Create Table QUERY_RESPONSE_TIME CREATE TEMPORARY TABLE `QUERY_RESPONSE_TIME` ( `TIME` varchar(14) NOT NULL DEFAULT '', - `COUNT` int(11) unsigned NOT NULL DEFAULT '0', + `COUNT` int(11) unsigned NOT NULL DEFAULT 0, `TOTAL` varchar(14) NOT NULL DEFAULT '' ) ENGINE=MEMORY DEFAULT CHARSET=utf8 SELECT PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_TYPE, PLUGIN_AUTHOR, PLUGIN_DESCRIPTION, PLUGIN_LICENSE, PLUGIN_MATURITY FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME LIKE 'query_response_time%';; diff --git a/plugin/query_response_time/query_response_time.cc b/plugin/query_response_time/query_response_time.cc index 10b9391d9da..5d6119d20ef 100644 --- a/plugin/query_response_time/query_response_time.cc +++ b/plugin/query_response_time/query_response_time.cc @@ -221,7 +221,7 @@ public: print_time(total, sizeof(total), TOTAL_STRING_FORMAT, this->total(i)); } fields[0]->store(time,strlen(time),system_charset_info); - fields[1]->store(this->count(i)); + fields[1]->store((longlong)this->count(i),true); fields[2]->store(total,strlen(total),system_charset_info); if (schema_table_store_record(thd, table)) { diff --git a/plugin/server_audit/server_audit.c b/plugin/server_audit/server_audit.c index c9e7e3a532a..e143f56b415 100644 --- a/plugin/server_audit/server_audit.c +++ b/plugin/server_audit/server_audit.c @@ -15,7 +15,7 @@ #define PLUGIN_VERSION 0x104 -#define PLUGIN_STR_VERSION "1.4.4" +#define PLUGIN_STR_VERSION "1.4.6" #define _my_thread_var loc_thread_var @@ -24,6 +24,7 @@ #include <time.h> #include <string.h> #include <fcntl.h> +#include <assert.h> #ifndef _WIN32 #include <syslog.h> @@ -97,7 +98,7 @@ static void closelog() {} #define FLOGGER_NO_PSI /* How to access the pthread_mutex in mysql_mutex_t */ -#if defined(SAFE_MUTEX) || defined(MY_PTHREAD_FASTMUTEX) +#ifdef SAFE_MUTEX #define mysql_mutex_real_mutex(A) &(A)->m_mutex.mutex #else #define mysql_mutex_real_mutex(A) &(A)->m_mutex @@ -140,7 +141,7 @@ static size_t loc_write(File Filedes, const uchar *Buffer, size_t Count) { size_t writtenbytes; #ifdef _WIN32 - writtenbytes= my_win_write(Filedes, Buffer, Count); + writtenbytes= (size_t)_write(Filedes, Buffer, (unsigned int)Count); #else writtenbytes= write(Filedes, Buffer, Count); #endif @@ -154,10 +155,29 @@ static File loc_open(const char *FileName, int Flags) /* Special flags */ { File fd; -#if defined(_WIN32) - fd= my_win_open(FileName, Flags); +#ifdef _WIN32 + HANDLE h; + /* + We could just use _open() here. but prefer to open in unix-similar way + just like my_open() does it on Windows. + This gives atomic multiprocess-safe appends, and possibility to rename + or even delete file while it is open, and CRT lacks this features. + */ + assert(Flags == (O_APPEND | O_CREAT | O_WRONLY)); + h= CreateFile(FileName, FILE_APPEND_DATA, + FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, NULL, + OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + if (h == INVALID_HANDLE_VALUE) + { + fd= -1; + my_osmaperr(GetLastError()); + } + else + { + fd= _open_osfhandle((intptr)h, O_WRONLY|O_BINARY); + } #else - fd = open(FileName, Flags, my_umask); + fd= open(FileName, Flags, my_umask); #endif my_errno= errno; return fd; @@ -173,7 +193,7 @@ static int loc_close(File fd) err= close(fd); } while (err == -1 && errno == EINTR); #else - err= my_win_close(fd); + err= close(fd); #endif my_errno=errno; return err; @@ -203,32 +223,9 @@ static int loc_rename(const char *from, const char *to) } -static my_off_t loc_seek(File fd, my_off_t pos, int whence) -{ - os_off_t newpos= -1; -#ifdef _WIN32 - newpos= my_win_lseek(fd, pos, whence); -#else - newpos= lseek(fd, pos, whence); -#endif - if (newpos == (os_off_t) -1) - { - my_errno= errno; - return MY_FILEPOS_ERROR; - } - - return (my_off_t) newpos; -} - - static my_off_t loc_tell(File fd) { - os_off_t pos; -#if defined (HAVE_TELL) && !defined (_WIN32) - pos= tell(fd); -#else - pos= loc_seek(fd, 0L, MY_SEEK_CUR); -#endif + os_off_t pos= IF_WIN(_telli64(fd),lseek(fd, 0, SEEK_CUR)); if (pos == (os_off_t) -1) { my_errno= errno; @@ -303,7 +300,7 @@ static size_t big_buffer_alloced= 0; static unsigned int query_log_limit= 0; static char servhost[256]; -static size_t servhost_len; +static uint servhost_len; static char *syslog_ident; static char syslog_ident_buffer[128]= "mysql-server_auditing"; @@ -338,6 +335,10 @@ static void update_file_rotations(MYSQL_THD thd, struct st_mysql_sys_var *var, void *var_ptr, const void *save); static void update_incl_users(MYSQL_THD thd, struct st_mysql_sys_var *var, void *var_ptr, const void *save); +static int check_incl_users(MYSQL_THD thd, struct st_mysql_sys_var *var, void *save, + struct st_mysql_value *value); +static int check_excl_users(MYSQL_THD thd, struct st_mysql_sys_var *var, void *save, + struct st_mysql_value *value); static void update_excl_users(MYSQL_THD thd, struct st_mysql_sys_var *var, void *var_ptr, const void *save); static void update_output_type(MYSQL_THD thd, struct st_mysql_sys_var *var, @@ -357,10 +358,10 @@ static void rotate_log(MYSQL_THD thd, struct st_mysql_sys_var *var, static MYSQL_SYSVAR_STR(incl_users, incl_users, PLUGIN_VAR_RQCMDARG, "Comma separated list of users to monitor.", - NULL, update_incl_users, NULL); + check_incl_users, update_incl_users, NULL); static MYSQL_SYSVAR_STR(excl_users, excl_users, PLUGIN_VAR_RQCMDARG, "Comma separated list of users to exclude from auditing.", - NULL, update_excl_users, NULL); + check_excl_users, update_excl_users, NULL); /* bits in the event filter. */ #define EVENT_CONNECT 1 #define EVENT_QUERY_ALL 2 @@ -626,7 +627,7 @@ static void remove_blanks(char *user) struct user_name { - int name_len; + size_t name_len; char *name; }; @@ -661,7 +662,7 @@ static int cmp_users(const void *ia, const void *ib) { const struct user_name *a= (const struct user_name *) ia; const struct user_name *b= (const struct user_name *) ib; - int dl= a->name_len - b->name_len; + int dl= (int)(a->name_len - b->name_len); if (dl != 0) return dl; @@ -669,7 +670,7 @@ static int cmp_users(const void *ia, const void *ib) } -static char *coll_search(struct user_coll *c, const char *n, int len) +static char *coll_search(struct user_coll *c, const char *n, size_t len) { struct user_name un; struct user_name *found; @@ -681,7 +682,7 @@ static char *coll_search(struct user_coll *c, const char *n, int len) } -static int coll_insert(struct user_coll *c, char *n, int len) +static int coll_insert(struct user_coll *c, char *n, size_t len) { if (c->n_users >= c->n_alloced) { @@ -936,7 +937,7 @@ static void get_str_n(char *dest, int *dest_len, size_t dest_size, memcpy(dest, src, src_len); dest[src_len]= 0; - *dest_len= src_len; + *dest_len= (int)src_len; } @@ -1008,7 +1009,7 @@ static int start_logging() if (output_type == OUTPUT_FILE) { char alt_path_buffer[FN_REFLEN+1+DEFAULT_FILENAME_LEN]; - MY_STAT *f_stat; + struct stat *f_stat= (struct stat *)alt_path_buffer; const char *alt_fname= file_path; while (*alt_fname == ' ') @@ -1023,7 +1024,7 @@ static int start_logging() { /* See if the directory exists with the name of file_path. */ /* Log file name should be [file_path]/server_audit.log then. */ - if ((f_stat= my_stat(file_path, (MY_STAT *)alt_path_buffer, MYF(0))) && + if (stat(file_path, (struct stat *)alt_path_buffer) == 0 && S_ISDIR(f_stat->st_mode)) { size_t p_len= strlen(file_path); @@ -1252,12 +1253,12 @@ static void change_connection(struct connection_info *cn, event->ip, event->ip_length); } -static int write_log(const char *message, int len) +static int write_log(const char *message, size_t len) { if (output_type == OUTPUT_FILE) { if (logfile && - (is_active= (logger_write(logfile, message, len) == len))) + (is_active= (logger_write(logfile, message, len) == (int)len))) return 0; ++log_write_failures; return 1; @@ -1266,7 +1267,7 @@ static int write_log(const char *message, int len) { syslog(syslog_facility_codes[syslog_facility] | syslog_priority_codes[syslog_priority], - "%s %.*s", syslog_info, len, message); + "%s %.*s", syslog_info, (int)len, message); } return 0; } @@ -1450,7 +1451,7 @@ static size_t escape_string_hide_passwords(const char *str, unsigned int len, } next_s++; } - len-= next_s - str; + len-= (uint)(next_s - str); str= next_s; continue; } @@ -1622,7 +1623,7 @@ static int log_statement_ex(const struct connection_info *cn, } if (query && !(events & EVENT_QUERY_ALL) && - (events & EVENT_QUERY)) + (events & EVENT_QUERY && !cn->log_always)) { const char *orig_query= query; @@ -1764,9 +1765,9 @@ static int log_table(const struct connection_info *cn, (void) time(&ctime); csize= log_header(message, sizeof(message)-1, &ctime, servhost, servhost_len, - event->user, SAFE_STRLEN(event->user), - event->host, SAFE_STRLEN(event->host), - event->ip, SAFE_STRLEN(event->ip), + event->user, (unsigned int)SAFE_STRLEN(event->user), + event->host, (unsigned int)SAFE_STRLEN(event->host), + event->ip, (unsigned int)SAFE_STRLEN(event->ip), event->thread_id, cn->query_id, type); csize+= my_snprintf(message+csize, sizeof(message) - 1 - csize, ",%.*s,%.*s,",event->database_length, event->database, @@ -1786,9 +1787,9 @@ static int log_rename(const struct connection_info *cn, (void) time(&ctime); csize= log_header(message, sizeof(message)-1, &ctime, servhost, servhost_len, - event->user, SAFE_STRLEN(event->user), - event->host, SAFE_STRLEN(event->host), - event->ip, SAFE_STRLEN(event->ip), + event->user, (unsigned int)SAFE_STRLEN(event->user), + event->host, (unsigned int)SAFE_STRLEN(event->host), + event->ip, (unsigned int)SAFE_STRLEN(event->ip), event->thread_id, cn->query_id, "RENAME"); csize+= my_snprintf(message+csize, sizeof(message) - 1 - csize, ",%.*s,%.*s|%.*s.%.*s,",event->database_length, event->database, @@ -2021,10 +2022,14 @@ void auditing(MYSQL_THD thd, unsigned int event_class, const void *ev) update_connection_info(cn, event_class, ev, &after_action); if (!logging) + { + if (cn) + cn->log_always= 0; goto exit_func; + } if (event_class == MYSQL_AUDIT_GENERAL_CLASS && FILTER(EVENT_QUERY) && - cn && do_log_user(cn->user)) + cn && (cn->log_always || do_log_user(cn->user))) { const struct mysql_event_general *event = (const struct mysql_event_general *) ev; @@ -2037,6 +2042,7 @@ void auditing(MYSQL_THD thd, unsigned int event_class, const void *ev) { log_statement(cn, event, "QUERY"); cn->query_length= 0; /* So the log_current_query() won't log this again. */ + cn->log_always= 0; } } else if (event_class == MYSQL_AUDIT_TABLE_CLASS && FILTER(EVENT_TABLE) && cn) @@ -2107,8 +2113,6 @@ exit_func: break; } } - if (cn) - cn->log_always= 0; flogger_mutex_unlock(&lock_operations); } @@ -2369,7 +2373,7 @@ static int server_audit_init(void *p __attribute__((unused))) if (gethostname(servhost, sizeof(servhost))) strcpy(servhost, "unknown"); - servhost_len= strlen(servhost); + servhost_len= (uint)strlen(servhost); logger_init_mutexes(); #if defined(HAVE_PSI_INTERFACE) && !defined(FLOGGER_NO_PSI) @@ -2552,12 +2556,12 @@ static void log_current_query(MYSQL_THD thd) if (!thd) return; cn= get_loc_info(thd); - if (!ci_needs_setup(cn) && cn->query_length && - FILTER(EVENT_QUERY) && do_log_user(cn->user)) + if (!ci_needs_setup(cn) && cn->query_length) { + cn->log_always= 1; log_statement_ex(cn, cn->query_time, thd_get_thread_id(thd), cn->query, cn->query_length, 0, "QUERY"); - cn->log_always= 1; + cn->log_always= 0; } } @@ -2646,16 +2650,56 @@ static void update_file_rotate_size(MYSQL_THD thd __attribute__((unused)), } +static int check_users(void *save, struct st_mysql_value *value, + size_t s, const char *name) +{ + const char *users; + int len= 0; + + users= value->val_str(value, NULL, &len); + if ((size_t) len > s) + { + error_header(); + fprintf(stderr, + "server_audit_%s_users value can't be longer than %zu characters.\n", + name, s); + return 1; + } + *((const char**)save)= users; + return 0; +} + +static int check_incl_users(MYSQL_THD thd __attribute__((unused)), + struct st_mysql_sys_var *var __attribute__((unused)), + void *save, struct st_mysql_value *value) +{ + return check_users(save, value, sizeof(incl_user_buffer), "incl"); +} + +static int check_excl_users(MYSQL_THD thd __attribute__((unused)), + struct st_mysql_sys_var *var __attribute__((unused)), + void *save, struct st_mysql_value *value) +{ + return check_users(save, value, sizeof(excl_user_buffer), "excl"); +} + + static void update_incl_users(MYSQL_THD thd, struct st_mysql_sys_var *var __attribute__((unused)), void *var_ptr __attribute__((unused)), const void *save) { char *new_users= (*(char **) save) ? *(char **) save : empty_str; + size_t new_len= strlen(new_users) + 1; if (!maria_55_started || !debug_server_started) flogger_mutex_lock(&lock_operations); mark_always_logged(thd); - strncpy(incl_user_buffer, new_users, sizeof(incl_user_buffer)-1); - incl_user_buffer[sizeof(incl_user_buffer)-1]= 0; + + if (new_len > sizeof(incl_user_buffer)) + new_len= sizeof(incl_user_buffer); + + memcpy(incl_user_buffer, new_users, new_len - 1); + incl_user_buffer[new_len - 1]= 0; + incl_users= incl_user_buffer; user_coll_fill(&incl_user_coll, incl_users, &excl_user_coll, 1); error_header(); @@ -2670,11 +2714,17 @@ static void update_excl_users(MYSQL_THD thd __attribute__((unused)), void *var_ptr __attribute__((unused)), const void *save) { char *new_users= (*(char **) save) ? *(char **) save : empty_str; + size_t new_len= strlen(new_users) + 1; if (!maria_55_started || !debug_server_started) flogger_mutex_lock(&lock_operations); mark_always_logged(thd); - strncpy(excl_user_buffer, new_users, sizeof(excl_user_buffer)-1); - excl_user_buffer[sizeof(excl_user_buffer)-1]= 0; + + if (new_len > sizeof(excl_user_buffer)) + new_len= sizeof(excl_user_buffer); + + memcpy(excl_user_buffer, new_users, new_len - 1); + excl_user_buffer[new_len - 1]= 0; + excl_users= excl_user_buffer; user_coll_fill(&excl_user_coll, excl_users, &incl_user_coll, 0); error_header(); @@ -2766,6 +2816,7 @@ static void update_logging(MYSQL_THD thd, { CLIENT_ERROR(1, "Logging was disabled.", MYF(ME_JUST_WARNING)); } + mark_always_logged(thd); } else { diff --git a/plugin/server_audit/test_audit_v4.c b/plugin/server_audit/test_audit_v4.c index ae7527f8449..85d45e35808 100644 --- a/plugin/server_audit/test_audit_v4.c +++ b/plugin/server_audit/test_audit_v4.c @@ -56,11 +56,11 @@ static int auditing_v4(MYSQL_THD thd, mysql_event_class_t class, const void *ev) ev_302.general_error_code= event->general_error_code; ev_302.general_thread_id= event->general_thread_id; ev_302.general_user= event->general_user.str; - ev_302.general_user_length= event->general_user.length; + ev_302.general_user_length= (unsigned int)event->general_user.length; ev_302.general_command= event->general_command.str; - ev_302.general_command_length= event->general_command.length; + ev_302.general_command_length= (unsigned int)event->general_command.length; ev_302.general_query= event->general_query.str; - ev_302.general_query_length= event->general_query.length; + ev_302.general_query_length= (unsigned int)event->general_query.length; ev_302.general_charset= event->general_charset; ev_302.general_time= event->general_time; ev_302.general_rows= event->general_rows; diff --git a/plugin/simple_password_check/simple_password_check.c b/plugin/simple_password_check/simple_password_check.c index 32f3ba6c703..4d2d762f47a 100644 --- a/plugin/simple_password_check/simple_password_check.c +++ b/plugin/simple_password_check/simple_password_check.c @@ -25,7 +25,7 @@ static unsigned min_length, min_digits, min_letters, min_others; static int validate(MYSQL_LEX_STRING *username, MYSQL_LEX_STRING *password) { - unsigned digits=0 , uppers=0 , lowers=0, others=0, length= password->length; + unsigned digits=0 , uppers=0 , lowers=0, others=0, length= (unsigned)password->length; const char *ptr= password->str, *end= ptr + length; if (strncmp(password->str, username->str, length) == 0) @@ -68,6 +68,7 @@ static void fix_min_length(MYSQL_THD thd __attribute__((unused)), } } + static MYSQL_SYSVAR_UINT(minimal_length, min_length, PLUGIN_VAR_RQCMDARG, "Minimal required password length", NULL, fix_min_length, 8, 0, 1000, 1); diff --git a/plugin/user_variables/CMakeLists.txt b/plugin/user_variables/CMakeLists.txt new file mode 100644 index 00000000000..6638a5cb622 --- /dev/null +++ b/plugin/user_variables/CMakeLists.txt @@ -0,0 +1,2 @@ +MYSQL_ADD_PLUGIN(user_variables user_variables.cc + DEFAULT RECOMPILE_FOR_EMBEDDED) diff --git a/plugin/user_variables/mysql-test/user_variables/basic.result b/plugin/user_variables/mysql-test/user_variables/basic.result new file mode 100644 index 00000000000..5650fa0dcce --- /dev/null +++ b/plugin/user_variables/mysql-test/user_variables/basic.result @@ -0,0 +1,63 @@ +SELECT PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_STATUS, PLUGIN_TYPE, PLUGIN_AUTHOR, PLUGIN_DESCRIPTION, PLUGIN_LICENSE, LOAD_OPTION, PLUGIN_MATURITY FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME='user_variables'; +PLUGIN_NAME user_variables +PLUGIN_VERSION 1.0 +PLUGIN_STATUS ACTIVE +PLUGIN_TYPE INFORMATION SCHEMA +PLUGIN_AUTHOR Sergey Vojtovich +PLUGIN_DESCRIPTION User-defined variables +PLUGIN_LICENSE GPL +LOAD_OPTION ON +PLUGIN_MATURITY Gamma +SHOW CREATE TABLE INFORMATION_SCHEMA.USER_VARIABLES; +Table Create Table +user_variables CREATE TEMPORARY TABLE `user_variables` ( + `VARIABLE_NAME` varchar(64) NOT NULL DEFAULT '', + `VARIABLE_VALUE` varchar(2048) DEFAULT NULL, + `VARIABLE_TYPE` varchar(64) NOT NULL DEFAULT '', + `CHARACTER_SET_NAME` varchar(32) DEFAULT NULL +) ENGINE=MEMORY DEFAULT CHARSET=utf8 +FLUSH USER_VARIABLES; +SELECT COUNT(*) FROM INFORMATION_SCHEMA.USER_VARIABLES; +COUNT(*) +0 +SET @int_var=1; +SET @uint_var=CAST(2 AS UNSIGNED INTEGER); +SET @str_var='Value of string variable'; +SET @utf8str_var=_utf8 'UTF8 string value'; +SET @double_var=CAST(1 AS DOUBLE); +SET @dec_var=CAST(1 AS DECIMAL(20, 10)); +SET @time_var=CAST('2016-02-25' AS DATE); +SET @' @#^%'='Value of variable with odd name'; +SET @''='Value of variable with empty name'; +SET @null_var=NULL; +SELECT COUNT(*) FROM INFORMATION_SCHEMA.USER_VARIABLES; +COUNT(*) +10 +SELECT * FROM INFORMATION_SCHEMA.USER_VARIABLES ORDER BY VARIABLE_NAME; +VARIABLE_NAME VARIABLE_VALUE VARIABLE_TYPE CHARACTER_SET_NAME + Value of variable with empty name VARCHAR latin1 + @#^% Value of variable with odd name VARCHAR latin1 +dec_var 1.0000000000 DECIMAL latin1 +double_var 1 DOUBLE latin1 +int_var 1 INT latin1 +null_var NULL VARCHAR binary +str_var Value of string variable VARCHAR latin1 +time_var 2016-02-25 VARCHAR latin1 +uint_var 2 INT UNSIGNED latin1 +utf8str_var UTF8 string value VARCHAR utf8 +SHOW USER_VARIABLES; +Variable_name Value + Value of variable with empty name + @#^% Value of variable with odd name +dec_var 1.0000000000 +double_var 1 +int_var 1 +null_var NULL +str_var Value of string variable +time_var 2016-02-25 +uint_var 2 +utf8str_var UTF8 string value +FLUSH USER_VARIABLES; +SELECT COUNT(*) FROM INFORMATION_SCHEMA.USER_VARIABLES; +COUNT(*) +0 diff --git a/plugin/user_variables/mysql-test/user_variables/basic.test b/plugin/user_variables/mysql-test/user_variables/basic.test new file mode 100644 index 00000000000..7e67e4fa5af --- /dev/null +++ b/plugin/user_variables/mysql-test/user_variables/basic.test @@ -0,0 +1,24 @@ +query_vertical SELECT PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_STATUS, PLUGIN_TYPE, PLUGIN_AUTHOR, PLUGIN_DESCRIPTION, PLUGIN_LICENSE, LOAD_OPTION, PLUGIN_MATURITY FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME='user_variables'; +SHOW CREATE TABLE INFORMATION_SCHEMA.USER_VARIABLES; + +FLUSH USER_VARIABLES; +SELECT COUNT(*) FROM INFORMATION_SCHEMA.USER_VARIABLES; + +SET @int_var=1; +SET @uint_var=CAST(2 AS UNSIGNED INTEGER); +SET @str_var='Value of string variable'; +SET @utf8str_var=_utf8 'UTF8 string value'; +SET @double_var=CAST(1 AS DOUBLE); +SET @dec_var=CAST(1 AS DECIMAL(20, 10)); +SET @time_var=CAST('2016-02-25' AS DATE); +SET @' @#^%'='Value of variable with odd name'; +SET @''='Value of variable with empty name'; +SET @null_var=NULL; + +SELECT COUNT(*) FROM INFORMATION_SCHEMA.USER_VARIABLES; +SELECT * FROM INFORMATION_SCHEMA.USER_VARIABLES ORDER BY VARIABLE_NAME; +--sorted_result +SHOW USER_VARIABLES; + +FLUSH USER_VARIABLES; +SELECT COUNT(*) FROM INFORMATION_SCHEMA.USER_VARIABLES; diff --git a/plugin/user_variables/mysql-test/user_variables/suite.opt b/plugin/user_variables/mysql-test/user_variables/suite.opt new file mode 100644 index 00000000000..6140014d569 --- /dev/null +++ b/plugin/user_variables/mysql-test/user_variables/suite.opt @@ -0,0 +1 @@ +--plugin-load-add=$USER_VARIABLES_SO --plugin-user-variables=ON diff --git a/plugin/user_variables/mysql-test/user_variables/suite.pm b/plugin/user_variables/mysql-test/user_variables/suite.pm new file mode 100644 index 00000000000..b927bf40ecc --- /dev/null +++ b/plugin/user_variables/mysql-test/user_variables/suite.pm @@ -0,0 +1,14 @@ +package My::Suite::User_variables; + +@ISA = qw(My::Suite); + +return "No USER_VARIABLES plugin" unless + $ENV{USER_VARIABLES_SO} or + $::mysqld_variables{'user-variables'} eq "ON"; + +return "Not run for embedded server" if $::opt_embedded_server and + $ENV{USER_VARIABLES_SO}; + +sub is_default { 1 } + +bless { }; diff --git a/plugin/user_variables/user_variables.cc b/plugin/user_variables/user_variables.cc new file mode 100644 index 00000000000..0dfd1b4db94 --- /dev/null +++ b/plugin/user_variables/user_variables.cc @@ -0,0 +1,139 @@ +/* Copyright (C) 2016 MariaDB Foundation and Sergey Vojtovich + + 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-1335 USA */ + +#define MYSQL_SERVER +#include <sql_class.h> +#include <table.h> +#include <sql_show.h> + + +static const LEX_CSTRING result_types[]= +{ + { STRING_WITH_LEN("VARCHAR") }, + { STRING_WITH_LEN("DOUBLE") }, + { STRING_WITH_LEN("INT") }, + { STRING_WITH_LEN("<IMPOSSIBLE1>") }, // ROW_RESULT + { STRING_WITH_LEN("DECIMAL") }, + { STRING_WITH_LEN("<IMPOSSIBLE2>")} // TIME_RESULT +}; + + +static const LEX_CSTRING unsigned_result_types[]= +{ + { STRING_WITH_LEN("<IMPOSSIBLE3>") }, // UNSIGNED STRING_RESULT + { STRING_WITH_LEN("DOUBLE UNSIGNED") }, + { STRING_WITH_LEN("INT UNSIGNED") }, + { STRING_WITH_LEN("<IMPOSSIBLE4>") }, // UNSIGNED ROW_RESULT + { STRING_WITH_LEN("DECIMAL UNSIGNED") }, + { STRING_WITH_LEN("<IMPOSSIBLE5>") } // UNSIGNED TIME_RESULT +}; + + +static ST_FIELD_INFO user_variables_fields_info[] = +{ + { "VARIABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Variable_name", 0 }, + { "VARIABLE_VALUE", 2048, MYSQL_TYPE_STRING, 0, MY_I_S_MAYBE_NULL, "Value", 0 }, + { "VARIABLE_TYPE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, 0 }, + { "CHARACTER_SET_NAME", MY_CS_NAME_SIZE, MYSQL_TYPE_STRING, 0, + MY_I_S_MAYBE_NULL, 0, 0 }, + { 0, 0, MYSQL_TYPE_NULL, 0, 0, 0, 0 } +}; + + +static int user_variables_fill(THD *thd, TABLE_LIST *tables, COND *cond) +{ + ulong i; + TABLE *table= tables->table; + Field **field= table->field; + String buff; + bool is_null; + + for (i= 0; i < thd->user_vars.records; i++) + { + user_var_entry *var= (user_var_entry*) my_hash_element(&thd->user_vars, i); + + field[0]->store(var->name.str, var->name.length, system_charset_info); + + if (var->val_str(&is_null, &buff, NOT_FIXED_DEC)) + { + field[1]->store(buff.ptr(), buff.length(), buff.charset()); + field[1]->set_notnull(); + } + else if (is_null) + field[1]->set_null(); + else + return 1; + + const LEX_CSTRING *tmp= var->unsigned_flag ? + &unsigned_result_types[var->type] : + &result_types[var->type]; + field[2]->store(tmp->str, tmp->length, system_charset_info); + + if (var->charset()) + { + field[3]->store(var->charset()->csname, strlen(var->charset()->csname), + system_charset_info); + field[3]->set_notnull(); + } + else + field[3]->set_null(); + + if (schema_table_store_record(thd, table)) + return 1; + } + return 0; +} + + +int user_variables_reset(void) +{ + THD *thd= current_thd; + if (thd) + my_hash_reset(&thd->user_vars); + return 0; +} + + +static int user_variables_init(void *p) +{ + ST_SCHEMA_TABLE *is= (ST_SCHEMA_TABLE *) p; + is->fields_info= user_variables_fields_info; + is->fill_table= user_variables_fill; + is->reset_table= user_variables_reset; + return 0; +} + + +static struct st_mysql_information_schema user_variables_descriptor= +{ MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION }; + + +maria_declare_plugin(user_variables) +{ + MYSQL_INFORMATION_SCHEMA_PLUGIN, + &user_variables_descriptor, + "user_variables", + "Sergey Vojtovich", + "User-defined variables", + PLUGIN_LICENSE_GPL, + user_variables_init, + NULL, + 0x0100, + NULL, + NULL, + "1.0", + MariaDB_PLUGIN_MATURITY_GAMMA +} +maria_declare_plugin_end; diff --git a/plugin/userstat/index_stats.cc b/plugin/userstat/index_stats.cc index 236130d327f..87e6da63e38 100644 --- a/plugin/userstat/index_stats.cc +++ b/plugin/userstat/index_stats.cc @@ -35,11 +35,11 @@ static int index_stats_fill(THD *thd, TABLE_LIST *tables, COND *cond) index_name_length= (index_stats->index_name_length - schema_name_length - table_name_length - 3); - table->field[0]->store(tmp_table.db, schema_name_length, + table->field[0]->store(tmp_table.db, (uint)schema_name_length, system_charset_info); - table->field[1]->store(tmp_table.table_name, table_name_length, + table->field[1]->store(tmp_table.table_name, (uint) table_name_length, system_charset_info); - table->field[2]->store(index_name, index_name_length, system_charset_info); + table->field[2]->store(index_name, (uint) index_name_length, system_charset_info); table->field[3]->store((longlong)index_stats->rows_read, TRUE); if (schema_table_store_record(thd, table)) diff --git a/plugin/wsrep_info/mysql-test/wsrep_info/r/plugin.result b/plugin/wsrep_info/mysql-test/wsrep_info/r/plugin.result index 31d66ab8b34..f33a628d428 100644 --- a/plugin/wsrep_info/mysql-test/wsrep_info/r/plugin.result +++ b/plugin/wsrep_info/mysql-test/wsrep_info/r/plugin.result @@ -1,4 +1,5 @@ # On node 1 +connection node_1; SELECT * FROM INFORMATION_SCHEMA.WSREP_STATUS; NODE_INDEX NODE_STATUS CLUSTER_STATUS CLUSTER_SIZE CLUSTER_STATE_UUID CLUSTER_STATE_SEQNO CLUSTER_CONF_ID GAP PROTOCOL_VERSION <IDX> Synced Primary 2 <CLUSTER_STATE_UUID> 0 <CLUSTER_CONF_ID> NO 3 @@ -7,6 +8,7 @@ INDEX UUID NAME ADDRESS <IDX> <MEMBER_ID> test-node-1 <ADDRESS> <IDX> <MEMBER_ID> test-node-2 <ADDRESS> # On node 2 +connection node_2; SELECT * FROM INFORMATION_SCHEMA.WSREP_STATUS; NODE_INDEX NODE_STATUS CLUSTER_STATUS CLUSTER_SIZE CLUSTER_STATE_UUID CLUSTER_STATE_SEQNO CLUSTER_CONF_ID GAP PROTOCOL_VERSION <IDX> Synced Primary 2 <CLUSTER_STATE_UUID> 0 <CLUSTER_CONF_ID> YES 3 @@ -14,4 +16,6 @@ SELECT * FROM INFORMATION_SCHEMA.WSREP_MEMBERSHIP ORDER BY NAME; INDEX UUID NAME ADDRESS <IDX> <MEMBER_ID> test-node-1 <ADDRESS> <IDX> <MEMBER_ID> test-node-2 <ADDRESS> +disconnect node_2; +disconnect node_1; # End of test diff --git a/plugin/wsrep_info/plugin.cc b/plugin/wsrep_info/plugin.cc index 6e95438c3b6..e0545828ff4 100644 --- a/plugin/wsrep_info/plugin.cc +++ b/plugin/wsrep_info/plugin.cc @@ -120,10 +120,10 @@ static int wsrep_memb_fill_table(THD *thd, TABLE_LIST *tables, COND *cond) if (check_global_access(thd, SUPER_ACL, true)) return rc; - wsrep_config_state.lock(); + wsrep_config_state->lock(); Dynamic_array<wsrep_member_info_t> *memb_arr= - wsrep_config_state.get_member_info(); + wsrep_config_state->get_member_info(); TABLE *table= tables->table; @@ -151,7 +151,7 @@ static int wsrep_memb_fill_table(THD *thd, TABLE_LIST *tables, COND *cond) } end: - wsrep_config_state.unlock(); + wsrep_config_state->unlock(); return rc; } @@ -175,10 +175,10 @@ static int wsrep_status_fill_table(THD *thd, TABLE_LIST *tables, COND *cond) if (check_global_access(thd, SUPER_ACL, true)) return rc; - wsrep_config_state.lock(); + wsrep_config_state->lock(); - wsrep_view_info_t view= wsrep_config_state.get_view_info(); - wsrep_member_status_t status= wsrep_config_state.get_status(); + wsrep_view_info_t view= wsrep_config_state->get_view_info(); + wsrep_member_status_t status= wsrep_config_state->get_status(); TABLE *table= tables->table; @@ -210,7 +210,7 @@ static int wsrep_status_fill_table(THD *thd, TABLE_LIST *tables, COND *cond) if (schema_table_store_record(thd, table)) rc= 1; - wsrep_config_state.unlock(); + wsrep_config_state->unlock(); return rc; } |