From c3e43855d27163cfea435a54ae8f425003ec0904 Mon Sep 17 00:00:00 2001 From: sconklin Date: Fri, 15 Dec 2006 19:59:35 +0000 Subject: Removed spurious messages, fixed file permissions to improve security, moved tar generation into policy module, delete tree in /tmp when done, and added option -g to only gather info and not create tarball git-svn-id: svn+ssh://svn.fedorahosted.org/svn/sos/trunk@58 ef72aa8b-4018-0410-8976-d6e080ef94d8 --- src/lib/sos/plugintools.py | 25 +++++++++++---------- src/lib/sos/policyredhat.py | 48 +++++++++++++++++++++++++++++++++++++--- src/lib/sos/reporters/tarball.py | 41 ---------------------------------- 3 files changed, 58 insertions(+), 56 deletions(-) delete mode 100644 src/lib/sos/reporters/tarball.py (limited to 'src/lib') diff --git a/src/lib/sos/plugintools.py b/src/lib/sos/plugintools.py index 7e69e262..eb9a32dc 100644 --- a/src/lib/sos/plugintools.py +++ b/src/lib/sos/plugintools.py @@ -74,12 +74,10 @@ class PluginBase: for path in self.forbiddenPaths: if ( srcpath.count(path) > 0 ): copyProhibited = 1 - + if copyProhibited: - sys.stderr.write("%s is on the copyProhibited list\n" % srcpath) - sys.stderr.flush() return '' - + if os.path.islink(srcpath): # This is a symlink - We need to also copy the file that it points to # file and dir symlinks ar ehandled the same @@ -112,7 +110,7 @@ class PluginBase: try: abspath = self.doCopyFileOrDir(srcpath+'/'+afile) except: - sys.stderr.write("1Problem at path %s\n" % srcpath+'/'+afile,) + sys.stderr.write("1Problem at path %s\n" % srcpath+'/'+afile) sys.stderr.flush() # if on forbidden list, abspath is null if not abspath == '': @@ -121,18 +119,21 @@ class PluginBase: else: try: dstslname, abspath = self.__copyFile(srcpath) + self.copiedFiles.append({'srcpath':srcpath, 'dstpath':dstslname, 'symlink':"yes", 'pointsto':link}) except: sys.stderr.write("2Problem at path %s\n" % srcpath) sys.stderr.flush() - self.copiedFiles.append({'srcpath':srcpath, 'dstpath':dstslname, 'symlink':"yes", 'pointsto':link}) + # Recurse to copy whatever it points to newpath = os.path.normpath(os.path.join(os.path.dirname(srcpath), link)) - try: - self.doCopyFileOrDir(newpath) - except: - sys.stderr.write("3Problem at path %s" % newpath,) - sys.stderr.flush() + if os.path.exists(newpath): + try: + self.doCopyFileOrDir(newpath) + except: + sys.stderr.write("3Problem at path %s" % newpath) + sys.stderr.flush() + return abspath else: @@ -349,7 +350,7 @@ class PluginBase: """ pass - def postproc(self, dstroot): + def postproc(self): """ perform any postprocessing. To be replaced by a plugin if desired """ diff --git a/src/lib/sos/policyredhat.py b/src/lib/sos/policyredhat.py index 14e5fa8a..791a6409 100755 --- a/src/lib/sos/policyredhat.py +++ b/src/lib/sos/policyredhat.py @@ -17,10 +17,11 @@ ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -#import os.path -#import copy -#import md5 import os +import sys +import string +from tempfile import gettempdir +from sos.helpers import * SOME_PATH = "/tmp/SomePath" @@ -39,6 +40,10 @@ class SosPolicy: #print "Policy init" return + def setCommons(self, commons): + self.cInfo = commons + return + def validatePlugin(self, pluginpath): "Validates the plugin as being acceptable to run" # return value @@ -68,3 +73,40 @@ class SosPolicy: name = "-".join(fields[:-3]) return (name, version, release, arch) + def packageResults(self): + print "Packaging reults to send to support . . ." + + print "Please enter your first initial and last name (jsmith): ", + name = sys.stdin.readline()[:-1] + + print "Please enter the case number that you are generating this", + print "report for: ", + ticketNumber = sys.stdin.readline()[:-1] + + namestr = name + "." + ticketNumber + ourtempdir = gettempdir() + tarballName = os.path.join(ourtempdir, namestr + ".tar.bz2") + + aliasdir = os.path.join(ourtempdir, namestr) + + tarcmd = "/bin/tar -jcf %s %s" % (tarballName, namestr) + + print "Creating tar file . . ." + if not os.access(string.split(tarcmd)[0], os.X_OK): + print "Unable to create tarball" + return + + # gotta be a better way . . . + os.system("/bin/mv %s %s" % (self.cInfo['dstroot'], aliasdir)) + curwd = os.getcwd() + os.chdir(ourtempdir) + oldmask = os.umask(077) + # pylint: disable-msg = W0612 + status, shout, sherr = sosGetCommandOutput(tarcmd) + os.umask(oldmask) + os.chdir(curwd) + os.system("/bin/mv %s %s" % (aliasdir, self.cInfo['dstroot'])) + + print "Your tarball is located at %s" % tarballName + return + diff --git a/src/lib/sos/reporters/tarball.py b/src/lib/sos/reporters/tarball.py deleted file mode 100644 index 4162951a..00000000 --- a/src/lib/sos/reporters/tarball.py +++ /dev/null @@ -1,41 +0,0 @@ -### This program is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or -## (at your option) any later version. - -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. - -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -import sys -import sos.plugintools -from sos.helpers import * - -class tarball(sos.plugintools.PluginBase): - """This plugin tars up the information gathered by sosreport - """ - def postproc(self, dstroot): - print "Please enter your first initial and last name (jsmith): ", - name = sys.stdin.readline()[:-1] - - print "Please enter the case number that you are generating this", - print "report for: ", - ticketNumber = sys.stdin.readline()[:-1] - - dirName = name + "." + ticketNumber - self.callExtProg("/bin/mkdir /tmp/%s" % dirName) - self.callExtProg("/bin/mv %s/* /tmp/%s" - % (dstroot, dirName)) - self.callExtProg("/bin/rm -rf %s" % dstroot) - self.callExtProg("/bin/tar --directory /tmp -jcf " - "/tmp/%s.tar.bz2 %s" - % (dirName, dirName)) - self.callExtProg("/bin/rm -rf /tmp/%s" % dirName) - print "Your tarball is located at /tmp/%s.tar.bz2" % dirName - return "/tmp/" + dirName - -- cgit