Skip to content

Commit 377acb2

Browse files
committed
mysql_adaptor: add TLS parameters
References: GXF-1774, GXF-2005
1 parent 6adbe14 commit 377acb2

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

doc/mysql_adaptor.4gx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.\" SPDX-License-Identifier: CC-BY-SA-4.0 or-later
2-
.\" SPDX-FileCopyrightText: 2020-2022 grommunio GmbH
2+
.\" SPDX-FileCopyrightText: 2020–2025 grommunio GmbH
33
.TH mysql_adaptor 4gx "" "Gromox" "Gromox admin reference"
44
.SH Name
55
mysql_adaptor \(em MySQL/MariaDB connector for user metadata and authentication
@@ -47,6 +47,12 @@ on the MySQL connection.
4747
.br
4848
Default: \fI0\fP (no timeout)
4949
.TP
50+
\fBmysql_tls_cert\fP
51+
The path name of the client public key certificate file.
52+
.TP
53+
\fBmysql_tls_key\fP
54+
The path name of the client private key file.
55+
.TP
5056
\fBmysql_username\fP
5157
Default: \fIroot\fP
5258
.TP

exch/mysql_adaptor/sql2.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: AGPL-3.0-or-later, OR GPL-2.0-or-later WITH linking exception
2-
// SPDX-FileCopyrightText: 2021–2024 grommunio GmbH
2+
// SPDX-FileCopyrightText: 2021–2025 grommunio GmbH
33
// This file is part of Gromox.
44
#ifdef HAVE_CONFIG_H
55
# include "config.h"
@@ -144,6 +144,10 @@ MYSQL *mysql_plugin::sql_make_conn()
144144
mysql_options(conn, MYSQL_OPT_READ_TIMEOUT, &g_parm.timeout);
145145
mysql_options(conn, MYSQL_OPT_WRITE_TIMEOUT, &g_parm.timeout);
146146
}
147+
if (!g_parm.certfile.empty())
148+
mysql_options(conn, MYSQL_OPT_SSL_CERT, g_parm.certfile.c_str());
149+
if (!g_parm.keyfile.empty())
150+
mysql_options(conn, MYSQL_OPT_SSL_KEY, g_parm.keyfile.c_str());
147151
if (mysql_real_connect(conn, g_parm.host.c_str(), g_parm.user.c_str(),
148152
g_parm.pass.size() != 0 ? g_parm.pass.c_str() : nullptr,
149153
g_parm.dbname.c_str(), g_parm.port, nullptr, 0) == nullptr) {
@@ -526,6 +530,8 @@ static constexpr cfg_directive mysql_adaptor_cfg_defaults[] = {
526530
{"mysql_password", ""},
527531
{"mysql_port", "3306"},
528532
{"mysql_rdwr_timeout", "0", CFG_TIME},
533+
{"mysql_tls_cert", ""},
534+
{"mysql_tls_key", ""},
529535
{"mysql_username", "root"},
530536
CFG_TABLE_END,
531537
};
@@ -546,6 +552,8 @@ bool mysql_plugin::reload_config(std::shared_ptr<config_file> &&cfg)
546552
par.port = cfg->get_ll("mysql_port");
547553
par.user = cfg->get_value("mysql_username");
548554
par.pass = cfg->get_value("mysql_password");
555+
par.certfile = cfg->get_value("mysql_tls_cert");
556+
par.keyfile = cfg->get_value("mysql_tls_key");
549557
auto p2 = cfg->get_value("mysql_password_mode_id107");
550558
if (p2 != nullptr)
551559
par.pass = zstd_decompress(base64_decode(p2));

include/gromox/mysql_adaptor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ enum sql_schema_upgrade : uint8_t {
4343
};
4444

4545
struct mysql_adaptor_init_param {
46-
std::string host, user, pass, dbname;
46+
std::string host, user, pass, dbname, certfile, keyfile;
4747
int port = 0, conn_num = 0, timeout = 0;
4848
enum sql_schema_upgrade schema_upgrade = SSU_NOT_ENABLED;
4949
bool enable_firsttimepw = false;

0 commit comments

Comments
 (0)