Skip to content

Commit

Permalink
Support unix-socket auth for mariadb (#642)
Browse files Browse the repository at this point in the history
Co-authored-by: 杨赫然 <[email protected]>
  • Loading branch information
feiniks and 杨赫然 authored Dec 26, 2023
1 parent 67dd146 commit 2d3513a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 4 additions & 0 deletions common/seaf-db.c
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,11 @@ mysql_db_get_connection (SeafDB *vdb)
int pro_type = MYSQL_PROTOCOL_SOCKET;
mysql_options (db_conn, MYSQL_OPT_PROTOCOL, &pro_type);
if (!db->user) {
#ifndef LIBMARIADB
mysql_options (db_conn, MYSQL_DEFAULT_AUTH, "unix_socket");
#else
mysql_options (db_conn, MARIADB_OPT_UNIXSOCKET, (void *)db->unix_socket);
#endif
}
}

Expand Down
17 changes: 9 additions & 8 deletions common/seaf-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,31 @@ mysql_db_start (SeafileSession *session)
unix_socket = seaf_key_file_get_string (session->config,
"database", "unix_socket", NULL);

host = seaf_key_file_get_string (session->config, "database", "host", &error);
host = seaf_key_file_get_string (session->config, "database", "host", NULL);
if (!host && !unix_socket) {
seaf_warning ("DB host not set in config.\n");
return -1;
}

port = g_key_file_get_integer (session->config, "database", "port", &error);
if (error) {
g_clear_error (&error);
port = MYSQL_DEFAULT_PORT;
}

user = seaf_key_file_get_string (session->config, "database", "user", &error);
user = seaf_key_file_get_string (session->config, "database", "user", NULL);
if (!user && !unix_socket) {
seaf_warning ("DB user not set in config.\n");
return -1;
}

passwd = seaf_key_file_get_string (session->config, "database", "password", &error);
passwd = seaf_key_file_get_string (session->config, "database", "password", NULL);
if (!passwd && !unix_socket) {
seaf_warning ("DB passwd not set in config.\n");
return -1;
}

db = seaf_key_file_get_string (session->config, "database", "db_name", &error);
db = seaf_key_file_get_string (session->config, "database", "db_name", NULL);
if (!db) {
seaf_warning ("DB name not set in config.\n");
return -1;
Expand All @@ -117,13 +118,12 @@ mysql_db_start (SeafileSession *session)
charset = seaf_key_file_get_string (session->config,
"database", "connection_charset", NULL);

if (error)
g_clear_error (&error);
max_connections = g_key_file_get_integer (session->config,
"database", "max_connections",
&error);
if (error || max_connections < 0) {
g_clear_error (&error);
if (error)
g_clear_error (&error);
max_connections = DEFAULT_MAX_CONNECTIONS;
}

Expand Down Expand Up @@ -320,7 +320,8 @@ ccnet_init_mysql_database (SeafileSession *session)
&error);
if (error || max_connections < 0) {
max_connections = DEFAULT_MAX_CONNECTIONS;
g_clear_error (&error);
if (error)
g_clear_error (&error);
}

session->ccnet_db = seaf_db_new_mysql (host, port, user, passwd, db, unix_socket, use_ssl, skip_verify, ca_path, charset, max_connections);
Expand Down

0 comments on commit 2d3513a

Please sign in to comment.