Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MON-120717-mysql-non-native-authent-and-mysql-dynamic-link-backport-24.04 #1466

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/docker/Dockerfile.centreon-collect-alma9
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dnf --best install -y cmake \
openssh-server \
mariadb-server \
mariadb \
mariadb-connector-c-devel \
gnutls-devel \
libgcrypt-devel \
lua-devel \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ apt-get -y install git \
mariadb-server \
openssh-server \
libmariadb3 \
libmariadb-dev \
librrd-dev \
libgnutls28-dev \
liblua5.3-dev \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ apt-get -y install git \
mariadb-server \
openssh-server \
libmariadb3 \
libmariadb-dev \
librrd-dev \
libgnutls28-dev \
liblua5.3-dev \
Expand Down
1 change: 1 addition & 0 deletions .github/docker/Dockerfile.centreon-collect-mysql-alma9
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dnf --best install -y cmake \
gdb \
gettext \
git \
mariadb-connector-c-devel \
ninja-build \
openssh-server \
mysql-server \
Expand Down
5 changes: 3 additions & 2 deletions .github/docker/Dockerfile.centreon-collect-mysql-alma9-test
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dnf --best install -y gcc \
gdb \
git \
openssh-server \
mariadb-connector-c \
mysql-server \
mysql \
gnutls \
Expand All @@ -42,8 +43,8 @@ dnf clean all

echo "install robot and dependencies"

pip3 install -U robotframework robotframework-databaselibrary robotframework-httpctrl robotframework-examples pymysql python-dateutil psutil
pip3 install grpcio grpcio_tools py-cpuinfo cython unqlite gitpython boto3 robotframework-requests
pip3 install -U robotframework robotframework-databaselibrary robotframework-httpctrl robotframework-examples pymysql python-dateutil psutil
pip3 install grpcio grpcio_tools py-cpuinfo cython unqlite gitpython boto3 robotframework-requests cryptography

cd /tmp/collect

Expand Down
1 change: 1 addition & 0 deletions .github/docker/Dockerfile.centreon-collect-ubuntu-jammy
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ apt-get -y install cmake \
mariadb-server \
openssh-server \
libmariadb3 \
libmariadb-dev \
librrd-dev \
libgnutls28-dev \
liblua5.3-dev \
Expand Down
4 changes: 2 additions & 2 deletions .github/scripts/collect-prepare-test-robot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ if [ $database_type == 'mysql' ]; then
sleep 5
echo "########################### Init centreon database ############################"

mysql -e "CREATE USER IF NOT EXISTS 'centreon'@'localhost' IDENTIFIED WITH mysql_native_password BY 'centreon'"
mysql -e "CREATE USER IF NOT EXISTS 'root_centreon'@'localhost' IDENTIFIED WITH mysql_native_password BY 'centreon'"
mysql -e "CREATE USER IF NOT EXISTS 'centreon'@'localhost' IDENTIFIED BY 'centreon'"
mysql -e "CREATE USER IF NOT EXISTS 'root_centreon'@'localhost' IDENTIFIED BY 'centreon'"
else
echo "########################### Start MariaDB ######################################"
if [ "$distrib" = "ALMALINUX" ]; then
Expand Down
8 changes: 6 additions & 2 deletions broker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,24 @@ endif()
if(OS_DISTRIBUTOR STREQUAL "Debian" OR OS_DISTRIBUTOR STREQUAL "Ubuntu")
message(STATUS "deb based os")
add_definitions("-DMYSQL_SOCKET=\"/var/run/mysqld/mysqld.sock\"")
add_definitions("-DDEFAULT_MARIADB_EXTENSION_DIR=\"/usr/lib/x86_64-linux-gnu/libmariadb3/plugin\"")
elseif(OS_DISTRIBUTOR STREQUAL "CentOS" OR OS_DISTRIBUTOR STREQUAL "RedHat")
message(STATUS "rpm based os")
add_definitions("-DMYSQL_SOCKET=\"/var/lib/mysql/mysql.sock\"")
add_definitions("-DDEFAULT_MARIADB_EXTENSION_DIR=\"/usr/lib64/mariadb/plugin\"")
else()
message(STATUS "other os: ${OS_DISTRIBUTOR}")
add_definitions("-DMYSQL_SOCKET=/tmp/mysql.sock")
add_definitions("-DMYSQL_SOCKET=\"/tmp/mysql.sock\"")
add_definitions("-DDEFAULT_MARIADB_EXTENSION_DIR=\"/usr/lib/x86_64-linux-gnu/libmariadb3/plugin\"")
endif()

include_directories(
"${PROJECT_SOURCE_DIR}/core/inc"
"${PROJECT_SOURCE_DIR}/neb/inc"
"${CMAKE_SOURCE_DIR}/engine/inc"
"${PROJECT_SOURCE_DIR}/core/multiplexing/inc"
"${PROJECT_SOURCE_DIR}/core/sql/inc")
"${PROJECT_SOURCE_DIR}/core/sql/inc"
"${MARIADB_INCLUDE_DIRS}")
set(INC_DIR "${PROJECT_SOURCE_DIR}/core/inc/com/centreon/broker")
set(SRC_DIR "${PROJECT_SOURCE_DIR}/core/src")
set(TEST_DIR "${PROJECT_SOURCE_DIR}/core/test")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class database_config {
int get_connections_count() const;
unsigned get_max_commit_delay() const;
unsigned get_category() const;
const std::string& get_extension_directory() const {
return _extension_directory;
}

void set_type(std::string const& type);
void set_host(std::string const& host);
Expand All @@ -87,6 +90,9 @@ class database_config {
void set_queries_per_transaction(int qpt);
void set_check_replication(bool check_replication);
void set_category(unsigned category);
void set_extension_directory(std::string const& extension_directory) {
_extension_directory = extension_directory;
}

database_config auto_commit_conf() const;

Expand All @@ -105,6 +111,8 @@ class database_config {
int _connections_count;
unsigned _max_commit_delay;
unsigned _category;
// where mariadb will find extension such as caching_sha2_password.so
std::string _extension_directory;
};

std::ostream& operator<<(std::ostream& s, const database_config cfg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#ifndef CCB_MYSQL_BIND_BASE_HH
#define CCB_MYSQL_BIND_BASE_HH

#include <mysql/mysql.h>
#include <mysql.h>

namespace com::centreon::broker {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
#ifndef CCB_DATABASE_MYSQL_COLUMN_HH
#define CCB_DATABASE_MYSQL_COLUMN_HH

#include <mysql.h>

#include <fmt/format.h>
#include <mysql/mysql.h>
#include <cmath>

namespace com::centreon::broker {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class mysql_connection {
const std::string _pwd;
const std::string _name;
const int _port;
const std::string _extension_directory;
const unsigned _max_second_commit_delay;
time_t _last_commit;
std::atomic<connection_state> _state;
Expand Down
18 changes: 14 additions & 4 deletions broker/core/sql/src/database_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ std::ostream& operator<<(std::ostream& s, const database_config cfg) {
s << " queries per transaction:" << cfg.get_queries_per_transaction()
<< " check replication:" << cfg.get_check_replication()
<< " connection count:" << cfg.get_connections_count()
<< " max commit delay:" << cfg.get_max_commit_delay() << 's';
<< " max commit delay:" << cfg.get_max_commit_delay() << 's'
<< " extension_directory" << cfg.get_extension_directory();
return s;
}

Expand All @@ -49,7 +50,8 @@ database_config::database_config()
: _queries_per_transaction(1),
_check_replication(true),
_connections_count(1),
_category(SHARED) {}
_category(SHARED),
_extension_directory(DEFAULT_MARIADB_EXTENSION_DIR) {}

/**
* Constructor.
Expand Down Expand Up @@ -90,14 +92,16 @@ database_config::database_config(const std::string& type,
_check_replication(check_replication),
_connections_count(connections_count),
_max_commit_delay(max_commit_delay),
_category(SHARED) {}
_category(SHARED),
_extension_directory(DEFAULT_MARIADB_EXTENSION_DIR) {}

/**
* Build a database configuration from a configuration set.
*
* @param[in] cfg Endpoint configuration.
*/
database_config::database_config(config::endpoint const& cfg) {
database_config::database_config(config::endpoint const& cfg)
: _extension_directory(DEFAULT_MARIADB_EXTENSION_DIR) {
std::map<std::string, std::string>::const_iterator it, end;
end = cfg.params.end();

Expand Down Expand Up @@ -212,6 +216,11 @@ database_config::database_config(config::endpoint const& cfg) {
}
} else
_max_commit_delay = 5;

it = cfg.params.find("extension_directory");
if (it != end) {
_extension_directory = it->second;
}
}

/**
Expand Down Expand Up @@ -557,6 +566,7 @@ void database_config::_internal_copy(database_config const& other) {
_check_replication = other._check_replication;
_connections_count = other._connections_count;
_max_commit_delay = other._max_commit_delay;
_extension_directory = other._extension_directory;
}

/**
Expand Down
9 changes: 8 additions & 1 deletion broker/core/sql/src/mysql_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* For more information : [email protected]
*/
#include <mysql/errmsg.h>
#include <errmsg.h>

#include "com/centreon/broker/config/applier/init.hh"
#include "com/centreon/broker/misc/misc.hh"
Expand Down Expand Up @@ -190,6 +190,9 @@ bool mysql_connection::_try_to_reconnect() {
uint32_t timeout = 10;
mysql_options(_conn, MYSQL_OPT_CONNECT_TIMEOUT, &timeout);

mysql_optionsv(_conn, MYSQL_PLUGIN_DIR,
(const void*)_extension_directory.c_str());

if (!mysql_real_connect(_conn, _host.c_str(), _user.c_str(), _pwd.c_str(),
_name.c_str(), _port,
(_socket == "" ? nullptr : _socket.c_str()),
Expand Down Expand Up @@ -830,6 +833,9 @@ void mysql_connection::_run() {
uint32_t timeout = 10;
mysql_options(_conn, MYSQL_OPT_CONNECT_TIMEOUT, &timeout);

mysql_optionsv(_conn, MYSQL_PLUGIN_DIR,
(const void*)_extension_directory.c_str());

while (config::applier::mode != config::applier::finished &&
!mysql_real_connect(_conn, _host.c_str(), _user.c_str(),
_pwd.c_str(), _name.c_str(), _port,
Expand Down Expand Up @@ -1076,6 +1082,7 @@ mysql_connection::mysql_connection(
_pwd(db_cfg.get_password()),
_name(db_cfg.get_name()),
_port(db_cfg.get_port()),
_extension_directory(db_cfg.get_extension_directory()),
_max_second_commit_delay(db_cfg.get_max_commit_delay()),
_last_commit(db_cfg.get_queries_per_transaction() > 1
? 0
Expand Down
2 changes: 2 additions & 0 deletions packaging/centreon-broker-core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ overrides:
- centreon-clib = ${VERSION}-${RELEASE}${DIST}
- centreon-broker = ${VERSION}-${RELEASE}${DIST}
- gnutls >= 3.6.0
- mariadb-connector-c >= 3.1.10
conflicts:
- centreon-broker-storage
- centreon-broker-core-devel
Expand All @@ -59,6 +60,7 @@ overrides:
- centreon-broker (= ${VERSION}-${RELEASE}${DIST})
- libgnutls30
- libssl1.1 | libssl3
- libmariadb3
- zlib1g
conflicts:
- centreon-broker-storage
Expand Down
1 change: 0 additions & 1 deletion tests/mysql_docker_conf/centreon16.cnf
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[mysqld]
#mariadb conf optimized for a 16Gb ram machine
port = 3306
default-authentication-plugin=mysql_native_password

max_heap_table_size=1G
open_files_limit = 32000
Expand Down
1 change: 0 additions & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"cxx17"
]
},
"libmariadb",
"libssh2",
"curl",
"fmt",
Expand Down
Loading