Red Hat Bugzilla – Bug 888724
sos does not preserve permissions on collected files
Last modified: 2017-02-07 07:45:25 EST
Description of problem: sos-2.2 does not preserve permissions on files copied into the archive: # ll /etc/host.conf ----------. 1 root root 26 Jan 12 2010 /etc/host.conf # ll rhel6-vm1-2012121910251355912727/etc/host.conf -rw-r--r--. 1 root root 26 Dec 19 10:25 rhel6-vm1-2012121910251355912727/etc/host.conf This is a regression from RHEL5: # uname -r 2.6.18-308.1.1.el5 # ll /etc/host.conf ---------- 1 root root 17 Oct 31 15:07 /etc/host.conf # ll pe1950-2-318659/etc/host.conf ---------- 1 root root 17 Oct 31 15:07 pe1950-2-318659/etc/host.conf Appears to be a regression introduced with the switch to shutils from calling out to 'cp' during el6 development. Version-Release number of selected component (if applicable): sos-2.2-* How reproducible: 100% Steps to Reproduce: 1. Make a file sos collects have an 'odd' mode 2. Run sos 3. Extract archive 4. ls -l $that_file Actual results: # ll rhel6-vm1-2012121910251355912727/etc/host.conf -rw-r--r--. 1 root root 26 Dec 19 10:25 rhel6-vm1-2012121910251355912727/etc/host.conf Expected results: # ll rhel6-vm1-2012121910251355912727/etc/host.conf ----------. 1 root root 26 Dec 19 10:25 rhel6-vm1-2012121910251355912727/etc/host.conf Additional info: Preserving permissions is the expected behaviour of all versions of sos. This is needed to support useful analysis-side diagnostics.
commit 2ab4529daad2fd133d91379ce94a297d037fd372 Author: Bryn M. Reeves <bmr@redhat.com> Date: Wed Dec 19 21:06:19 2012 +0000 Preserve ownership and permission on copied files Preserve the ownership and permission information for collected files by using shutil.copy2 instead of copyfileobj() and calling os.chown() after copying. diff --git a/sos/plugintools.py b/sos/plugintools.py index 39b2368..ea29ea9 100644 --- a/sos/plugintools.py +++ b/sos/plugintools.py @@ -232,11 +232,9 @@ class PluginBase: linkto = os.readlink(src) os.symlink(linkto, new_fname) else: - fsrc = open(src,'r') - fdst = open(new_fname, 'w') - shutil.copyfileobj(fsrc, fdst, -1) - fsrc.close() - fdst.close() + shutil.copy2(src, new_fname) + stat = os.stat(src) + os.chown(new_fname, stat.st_uid, stat.st_gid) else: raise PluginException('Error copying file: already exists')
*** Bug 1003550 has been marked as a duplicate of this bug. ***
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory, and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. http://rhn.redhat.com/errata/RHBA-2013-1688.html