diff options
author | Shauren <shauren.trinity@gmail.com> | 2024-09-25 10:46:46 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2024-09-25 10:46:46 +0200 |
commit | 726412d983a4ebea46e69cc65cc5aed3f55d4fe8 (patch) | |
tree | 1ad760f28cb58f39226033bfc7b169bdf12735b5 /src/server/database/Database | |
parent | 3238175a62750ea5127feb69ce86d0c3c05dfc52 (diff) |
Core/Database: Fix database connections failing to open over named pipes for users using caching_sha2_password authentication plugin if this is the first time this user attempts to log in since starting MySQL server
Diffstat (limited to 'src/server/database/Database')
-rw-r--r-- | src/server/database/Database/MySQLConnection.cpp | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/src/server/database/Database/MySQLConnection.cpp b/src/server/database/Database/MySQLConnection.cpp index 3437fc55b1d..25baf651b07 100644 --- a/src/server/database/Database/MySQLConnection.cpp +++ b/src/server/database/Database/MySQLConnection.cpp @@ -23,6 +23,7 @@ #include "MySQLPreparedStatement.h" #include "PreparedStatement.h" #include "QueryResult.h" +#include "StringConvert.h" #include "Timer.h" #include "Transaction.h" #include "Util.h" @@ -96,42 +97,40 @@ uint32 MySQLConnection::Open() return CR_UNKNOWN_ERROR; } - int port; - char const* unix_socket; + int port = 0; + char const* unix_socket = nullptr; //unsigned int timeout = 10; mysql_options(mysqlInit, MYSQL_SET_CHARSET_NAME, "utf8mb4"); //mysql_options(mysqlInit, MYSQL_OPT_READ_TIMEOUT, (char const*)&timeout); - #ifdef _WIN32 - if (m_connectionInfo.host == ".") // named pipe use option (Windows) + if (m_connectionInfo.host != ".") { - unsigned int opt = MYSQL_PROTOCOL_PIPE; - mysql_options(mysqlInit, MYSQL_OPT_PROTOCOL, (char const*)&opt); - port = 0; - unix_socket = nullptr; - } - else // generic case - { - port = atoi(m_connectionInfo.port_or_socket.c_str()); - unix_socket = nullptr; + port = Trinity::StringTo<int32>(m_connectionInfo.port_or_socket).value_or(0); } - #else - if (m_connectionInfo.host == ".") // socket use option (Unix/Linux) + else // named pipe/unix socket option { - unsigned int opt = MYSQL_PROTOCOL_SOCKET; - mysql_options(mysqlInit, MYSQL_OPT_PROTOCOL, (char const*)&opt); +#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS + unsigned int opt = MYSQL_PROTOCOL_PIPE; +#else m_connectionInfo.host = "localhost"; - port = 0; unix_socket = m_connectionInfo.port_or_socket.c_str(); + unsigned int opt = MYSQL_PROTOCOL_SOCKET; +#endif + mysql_options(mysqlInit, MYSQL_OPT_PROTOCOL, (char const*)&opt); + +#if !defined(MARIADB_VERSION_ID) && MYSQL_VERSION_ID >= 80000 + /* + ensure connections over named pipes work for users authenticating with caching_sha2_password + + If the mysql server is restarted, and you connect it using named pipe, the connection will fail and it will continue to fail until you connect it using tcp. + Source: https://bugs.mysql.com/bug.php?id=106852 + */ + MySQLBool geterverPublicKey = MySQLBool(1); + mysql_options(mysqlInit, MYSQL_OPT_GET_SERVER_PUBLIC_KEY, (char const*)&geterverPublicKey); +#endif } - else // generic case - { - port = atoi(m_connectionInfo.port_or_socket.c_str()); - unix_socket = nullptr; - } - #endif - if (m_connectionInfo.ssl != "") + if (!m_connectionInfo.ssl.empty()) { #if !defined(MARIADB_VERSION_ID) && MYSQL_VERSION_ID >= 80000 mysql_ssl_mode opt_use_ssl = SSL_MODE_DISABLED; |