Blame SOURCES/sos-bz1159835-obtain-postgres-password-from-environment.patch

a1ee45
diff -up sos-3.0/sos/plugins/postgresql.py.orig sos-3.0/sos/plugins/postgresql.py
a1ee45
--- sos-3.0/sos/plugins/postgresql.py.orig	2014-11-11 17:22:24.973592961 +0000
a1ee45
+++ sos-3.0/sos/plugins/postgresql.py	2014-11-11 17:29:02.374434446 +0000
a1ee45
@@ -13,23 +13,27 @@ class PostgreSQL(Plugin):
a1ee45
 
a1ee45
     tmp_dir = None
a1ee45
 
a1ee45
+    password_warn_text = " (password visible in process listings)"
a1ee45
+
a1ee45
     option_list = [
a1ee45
         ("pghome",  'PostgreSQL server home directory.', '', '/var/lib/pgsql'),
a1ee45
         ("username",  'username for pg_dump', '', 'postgres'),
a1ee45
-        ("password",  'password for pg_dump', '', ''),
a1ee45
-        ("dbname",  'database name to dump for pg_dump', '', ''),
a1ee45
+        ('password', 'password for pg_dump' + password_warn_text, '', ''),
a1ee45
+        ("dbname",  'database name to dump for pg_dump', '', '')
a1ee45
     ]
a1ee45
 
a1ee45
     def pg_dump(self):
a1ee45
         dest_file = os.path.join(self.tmp_dir, "sos_pgdump.tar")
a1ee45
-        old_env_pgpassword = os.environ.get("PGPASSWORD")
a1ee45
-        os.environ["PGPASSWORD"] = self.get_option("password")
a1ee45
+        # We're only modifying this for ourself and our children so there
a1ee45
+        # is no need to save and restore environment variables if the user
a1ee45
+        # decided to pass the password on the command line.
a1ee45
+        if self.get_option("password") is not None:
a1ee45
+            os.environ["PGPASSWORD"] = self.get_option("password")
a1ee45
+
a1ee45
         (status, output, rtime) = self.call_ext_prog("pg_dump %s -U %s -w -f %s -F t" %
a1ee45
                                                    (self.get_option("dbname"),
a1ee45
                                                     self.get_option("username"),
a1ee45
                                                     dest_file))
a1ee45
-        if old_env_pgpassword is not None:
a1ee45
-            os.environ["PGPASSWORD"] = old_env_pgpassword
a1ee45
         if (status == 0):
a1ee45
             self.add_copy_spec(dest_file)
a1ee45
         else:
a1ee45
@@ -37,7 +41,7 @@ class PostgreSQL(Plugin):
a1ee45
 
a1ee45
     def setup(self):
a1ee45
         if self.get_option("dbname"):
a1ee45
-            if self.get_option("password"):
a1ee45
+            if self.get_option("password") or "PGPASSWORD" in os.environ:
a1ee45
                 self.tmp_dir = tempfile.mkdtemp()
a1ee45
                 self.pg_dump()
a1ee45
             else: