summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Hoffend <dh@dotlan.net>2019-11-26 09:18:46 +0100
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2019-11-26 09:18:46 +0100
commite374c311aba2e7e2f94275144b01eaea262908cd (patch)
treededa4250113c67fd6330df4e2008494be1212730
parentef261d5b5826c2c0f1a6aa7553cdf2e5cb226383 (diff)
downloadpykolab-e374c311aba2e7e2f94275144b01eaea262908cd.tar.gz
setup: add support my unix_socket authenticated mysql server
Summary: This patch adds support support for unix_socket based authentication against mariadb servers. Unix_socket support was also edit to the setup dial when calling `setup-kolab (roundcube|syncrotron|mysql)` Test Plan: Use `--mysqlserver=unix_socket` or `--mysqlserver=existing --mysqlrootpw=unix_socket`. Reviewers: #pykolab_developers, vanmeeuwen Reviewed By: #pykolab_developers, vanmeeuwen Subscribers: vanmeeuwen Differential Revision: https://git.kolab.org/D865
-rw-r--r--pykolab/setup/setup_mysql.py34
-rw-r--r--pykolab/setup/setup_roundcube.py30
-rw-r--r--pykolab/setup/setup_syncroton.py30
3 files changed, 85 insertions, 9 deletions
diff --git a/pykolab/setup/setup_mysql.py b/pykolab/setup/setup_mysql.py
index d5e62a0..c4cd90f 100644
--- a/pykolab/setup/setup_mysql.py
+++ b/pykolab/setup/setup_mysql.py
@@ -45,7 +45,7 @@ def cli_options():
"--mysqlserver",
dest="mysqlserver",
action="store",
- help=_("Specify whether to use an (existing) or (new) MySQL server.")
+ help=_("Specify whether to use an (existing), (unix_socket) or (new) MySQL server.")
)
mysql_group.add_option(
@@ -121,7 +121,8 @@ def execute(*args, **kw): # noqa: C901
options = {
1: "Existing MySQL server (with root password already set).",
- 2: "New MySQL server (needs to be initialized)."
+ 2: "Existing MySQL server (with unix_socket authentication plugin).",
+ 3: "New MySQL server (needs to be initialized)."
}
answer = 0
@@ -130,8 +131,10 @@ def execute(*args, **kw): # noqa: C901
if conf.mysqlserver:
if conf.mysqlserver == 'existing':
answer = 1
- elif conf.mysqlserver == 'new':
+ elif conf.mysqlserver == 'unix_socket':
answer = 2
+ elif conf.mysqlserver == 'new':
+ answer = 3
if answer == 0:
answer = utils.ask_menu(_("What MySQL server are we setting up?"), options)
else:
@@ -154,6 +157,9 @@ def execute(*args, **kw): # noqa: C901
else:
mysql_root_password = conf.mysqlrootpw
+ elif answer == "2" or answer == 2:
+ mysql_root_password = 'unix_socket'
+
else:
print >> sys.stderr, utils.multiline_message(
_("""
@@ -222,13 +228,33 @@ def execute(*args, **kw): # noqa: C901
p1.stdout.close()
p2.communicate()
- data = """
+ socket_path = None
+ socket_paths = [
+ "/var/lib/mysql/mysql.sock",
+ "/var/run/mysqld/mysqld.sock",
+ "/var/run/mysql/mysql.sock"
+ ]
+ for sp in socket_paths:
+ if os.path.exists(sp):
+ socket_path = sp
+
+ if mysql_root_password == "unix_socket" and socket_path is not None:
+ data = """
+[mysql]
+user=root
+password=
+host=localhost
+socket=%s
+""" % (socket_path)
+ else:
+ data = """
[mysql]
user=root
password='%s'
host=%s
""" % (mysql_root_password, conf.mysqlhost)
+
fp = open('/tmp/kolab-setup-my.cnf', 'w')
os.chmod('/tmp/kolab-setup-my.cnf', 600)
fp.write(data)
diff --git a/pykolab/setup/setup_roundcube.py b/pykolab/setup/setup_roundcube.py
index 36c7aa7..7c7964d 100644
--- a/pykolab/setup/setup_roundcube.py
+++ b/pykolab/setup/setup_roundcube.py
@@ -224,11 +224,35 @@ def execute(*args, **kw):
break
if not os.path.isfile('/tmp/kolab-setup-my.cnf'):
- utils.multiline_message("""Please supply the MySQL root password""")
+ print >> sys.stderr, utils.multiline_message(
+ """Please supply the MySQL root password (use 'unix_socket' for socket based authentication)"""
+ )
- mysql_root_password = utils.ask_question("MySQL root password", password=True)
+ mysql_root_password = utils.ask_question(
+ _("MySQL root password"),
+ password=True
+ )
- data = """
+ socket_path = None
+ socket_paths = [
+ "/var/lib/mysql/mysql.sock",
+ "/var/run/mysqld/mysqld.sock",
+ "/var/run/mysql/mysql.sock"
+ ]
+ for sp in socket_paths:
+ if os.path.exists(sp):
+ socket_path = sp
+
+ if mysql_root_password == "unix_socket" and socket_path is not None:
+ data = """
+[mysql]
+user=root
+password=
+host=localhost
+socket=%s
+""" % (socket_path)
+ else:
+ data = """
[mysql]
user=root
password='%s'
diff --git a/pykolab/setup/setup_syncroton.py b/pykolab/setup/setup_syncroton.py
index 446577f..c7c03ce 100644
--- a/pykolab/setup/setup_syncroton.py
+++ b/pykolab/setup/setup_syncroton.py
@@ -66,8 +66,8 @@ def execute(*args, **kw):
break
if not os.path.isfile('/tmp/kolab-setup-my.cnf'):
- utils.multiline_message(
- """Please supply the MySQL root password"""
+ print >> sys.stderr, utils.multiline_message(
+ """Please supply the MySQL root password (use 'unix_socket' for socket based authentication)"""
)
mysql_root_password = utils.ask_question(
@@ -75,6 +75,32 @@ def execute(*args, **kw):
password=True
)
+ socket_path = None
+ socket_paths = [
+ "/var/lib/mysql/mysql.sock",
+ "/var/run/mysqld/mysqld.sock",
+ "/var/run/mysql/mysql.sock"
+ ]
+ for sp in socket_paths:
+ if os.path.exists(sp):
+ socket_path = sp
+
+ if mysql_root_password == "unix_socket" and socket_path is not None:
+ data = """
+[mysql]
+user=root
+password=
+host=localhost
+socket=%s
+""" % (socket_path)
+ else:
+ data = """
+[mysql]
+user=root
+password='%s'
+host=%s
+""" % (mysql_root_password, conf.mysqlhost)
+
data = """
[mysql]
user=root