Blame SOURCES/0050-mysql-improve-handling-of-dbuser-dbpass-and-MYSQL_PW.patch

0cd6dc
From 7c12e6c994b3320ef57a13e06f5c445b6bca7935 Mon Sep 17 00:00:00 2001
0cd6dc
From: "Bryn M. Reeves" <bmr@redhat.com>
0cd6dc
Date: Thu, 22 Jan 2015 15:37:15 +0000
0cd6dc
Subject: [PATCH 50/93] [mysql] improve handling of dbuser, dbpass and
0cd6dc
 MYSQL_PWD
0cd6dc
0cd6dc
Make sure that the mysql plugin behaves correctly when given
0cd6dc
different combinations of values for dbuser, dbpass and MYSQL_PWD.
0cd6dc
0cd6dc
* If dbdump is set then either dbpass or MYSQL_PWD must be set
0cd6dc
* Warn if dbdump is set and dbuser or dbpass is True/False/null
0cd6dc
  (indicates either 'sosreport -a' or '-k mysql.dbpass')
0cd6dc
0cd6dc
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
0cd6dc
---
0cd6dc
 sos/plugins/mysql.py | 24 ++++++++++++++++++++----
0cd6dc
 1 file changed, 20 insertions(+), 4 deletions(-)
0cd6dc
0cd6dc
diff --git a/sos/plugins/mysql.py b/sos/plugins/mysql.py
0cd6dc
index dd899a3..8dba204 100644
0cd6dc
--- a/sos/plugins/mysql.py
0cd6dc
+++ b/sos/plugins/mysql.py
0cd6dc
@@ -24,35 +24,51 @@ class Mysql(Plugin):
0cd6dc
     profiles = ('services',)
0cd6dc
     mysql_cnf = "/etc/my.cnf"
0cd6dc
 
0cd6dc
+    pw_warn_text = " (password visible in process listings)"
0cd6dc
+
0cd6dc
     option_list = [
0cd6dc
         ("dbuser", "username for database dumps", "", "mysql"),
0cd6dc
-        ("dbpass", "password for database dumps", "", False),
0cd6dc
+        ("dbpass", "password for database dumps" + pw_warn_text, "", False),
0cd6dc
         ("dbdump", "collect a database dump", "", False)
0cd6dc
     ]
0cd6dc
 
0cd6dc
     def setup(self):
0cd6dc
         super(Mysql, self).setup()
0cd6dc
+
0cd6dc
         self.add_copy_spec([
0cd6dc
             self.mysql_cnf,
0cd6dc
             "/var/log/mysql/mysqld.log",
0cd6dc
             "/var/log/mariadb/mariadb.log",
0cd6dc
         ])
0cd6dc
+
0cd6dc
         if self.get_option("all_logs"):
0cd6dc
             self.add_copy_spec([
0cd6dc
                 "/var/log/mysql*",
0cd6dc
                 "/var/log/mariadb*"
0cd6dc
             ])
0cd6dc
+
0cd6dc
         if self.get_option("dbdump"):
0cd6dc
+            msg = "database user name and password must be supplied"
0cd6dc
+            dbdump_err = "mysql.dbdump: %s" % msg
0cd6dc
+
0cd6dc
             dbuser = self.get_option("dbuser")
0cd6dc
             dbpass = self.get_option("dbpass")
0cd6dc
-            if isinstance(dbuser, bool) or isinstance(dbpass, bool):
0cd6dc
-                # sosreport -a
0cd6dc
-                return
0cd6dc
+
0cd6dc
             if 'MYSQL_PWD' in os.environ:
0cd6dc
                 dbpass = os.environ['MYSQL_PWD']
0cd6dc
+
0cd6dc
+            if dbuser is True or dbpass is True:
0cd6dc
+                # sosreport -a or -k mysql.{dbuser,dbpass}
0cd6dc
+                self.soslog.warning(dbdump_err)
0cd6dc
+                return
0cd6dc
+
0cd6dc
             if not dbpass or dbpass is False:
0cd6dc
                 # no MySQL password
0cd6dc
+                self.soslog.warning(dbdump_err)
0cd6dc
                 return
0cd6dc
+
0cd6dc
+            # no need to save/restore as this variable is private to
0cd6dc
+            # the mysql plugin.
0cd6dc
             os.environ['MYSQL_PWD'] = dbpass
0cd6dc
 
0cd6dc
             opts = "--user=%s --all-databases" % dbuser
0cd6dc
-- 
0cd6dc
1.9.3
0cd6dc