summaryrefslogtreecommitdiff
path: root/eclass
diff options
context:
space:
mode:
authorThomas Deutschmann <whissi@gentoo.org>2016-09-26 20:48:50 +0200
committerThomas Deutschmann <whissi@gentoo.org>2016-09-26 20:48:50 +0200
commit58d95ca48419704686b7ad7115b609a98d2adea9 (patch)
treef193168dd63fdde2198e1fd9a399fbc268c7964f /eclass
parentmysql-multilib-r1.eclass: Use *_is_at_least from versionator eclass (diff)
downloadgentoo-58d95ca48419704686b7ad7115b609a98d2adea9.tar.gz
gentoo-58d95ca48419704686b7ad7115b609a98d2adea9.tar.bz2
gentoo-58d95ca48419704686b7ad7115b609a98d2adea9.zip
mysql-multilib-r1.eclass: Fix password reading from my.cnf
We are reading multiple sections from my.cnf at once from my.cnf when looking for the password for the mysql root user in mysql-multilib-r1_pkg_config(). If each section has set a password option this will result in the following invalid password value (with "set -x"): ++ local extra_options= ++ //usr/bin/my_print_defaults client mysql ++ sed -n '/^--password=/s,--password=,,gp' + MYSQL_ROOT_PASSWORD='***** *****' + [[ ***** ***** == \*\*\*\*\* ]] + set +x Like you can see the two passwords are concatenated via newline in one string which is not what we want. With this commit we will no longer read all sections at once instead we read section per section. We are now also telling the user where we are looking for the password and where we found one. In addition this commit adds a sanity check for newline to catch scenarios where the user for example has inadvertently set multiple password options in one section which we can't handle: In that case it is better to prompt for a password like no password was set in my.cnf instead of initializing mysqld with a mysql root password the user is not expecting. Gentoo-Bug: https://bugs.gentoo.org/510724
Diffstat (limited to 'eclass')
-rw-r--r--eclass/mysql-multilib-r1.eclass22
1 files changed, 20 insertions, 2 deletions
diff --git a/eclass/mysql-multilib-r1.eclass b/eclass/mysql-multilib-r1.eclass
index 3f7372c0f633..ebf89f28f94f 100644
--- a/eclass/mysql-multilib-r1.eclass
+++ b/eclass/mysql-multilib-r1.eclass
@@ -817,11 +817,29 @@ mysql-multilib-r1_pkg_config() {
local maxtry=15
if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then
- MYSQL_ROOT_PASSWORD="$(mysql-multilib-r1_getoptval 'client mysql' password)"
+ local tmp_mysqld_password_source=
+
+ for tmp_mysqld_password_source in mysql client; do
+ einfo "Trying to get password for mysql 'root' user from '${tmp_mysqld_password_source}' section ..."
+ MYSQL_ROOT_PASSWORD="$(mysql-multilib-r1_getoptval "${tmp_mysqld_password_source}" password)"
+ if [[ -n "${MYSQL_ROOT_PASSWORD}" ]]; then
+ if [[ ${MYSQL_ROOT_PASSWORD} == *$'\n'* ]]; then
+ ewarn "Ignoring password from '${tmp_mysqld_password_source}' section due to newline character (do you have multiple password options set?)!"
+ MYSQL_ROOT_PASSWORD=
+ continue
+ fi
+
+ einfo "Found password in '${tmp_mysqld_password_source}' section!"
+ break
+ fi
+ done
+
# Sometimes --show is required to display passwords in some implementations of my_print_defaults
if [[ "${MYSQL_ROOT_PASSWORD}" == '*****' ]]; then
- MYSQL_ROOT_PASSWORD="$(mysql-multilib-r1_getoptval 'client mysql' password --show)"
+ MYSQL_ROOT_PASSWORD="$(mysql-multilib-r1_getoptval "${tmp_mysqld_password_source}" password --show)"
fi
+
+ unset tmp_mysqld_password_source
fi
MYSQL_TMPDIR="$(mysql-multilib-r1_getoptval mysqld tmpdir)"
# These are dir+prefix