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 ---------------------------------- src/setup.py | 3 +-- src/sos.spec | 9 +++++++- src/sosreport | 33 +++++++++++++++------------ 6 files changed, 86 insertions(+), 73 deletions(-) delete mode 100644 src/lib/sos/reporters/tarball.py (limited to 'src') 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 - diff --git a/src/setup.py b/src/setup.py index 08ab4404..c1448eb7 100644 --- a/src/setup.py +++ b/src/setup.py @@ -3,14 +3,13 @@ setup.py - Setup package with the help from Python's DistUtils """ from distutils.core import setup -#from distutils.core import setup, Extension from ConfigParser import ConfigParser import sys,os,time # change release in spec file along with this version string setup( name = 'sos', - version = '1.0', + version = '1.1', description = 'System Support Tools', long_description = """Sos is a set of tools that gathers information about system hardware and configuration. The information can then be used for diff --git a/src/sos.spec b/src/sos.spec index dc47e5da..06af8d1d 100644 --- a/src/sos.spec +++ b/src/sos.spec @@ -2,7 +2,7 @@ Summary: System Support Tools Name: sos -Version: 1.0 +Version: 1.1 Release: 1%{?dist} License: GPL Group: Development/Libraries @@ -46,6 +46,13 @@ rm -rf $RPM_BUILD_ROOT %doc README TODO %changelog +* Fri Dec 15 2006 Steve Conklin - 1.1-1 +- Tighten permissions of tmp directory so only readable by creator bz_219657 +- Don't try to copy nonexistant targets of symlinks bz_219654 +- Removed useless message bz_219670 +- Preserve file modification times bz_219674 +- Removed unneeded confusing message bz_219712 + * Wed Aug 30 2006 Steve Conklin - 1.0-1 - Seperated upstream and RPM versioning diff --git a/src/sosreport b/src/sosreport index a8c821d2..a04108dd 100755 --- a/src/sosreport +++ b/src/sosreport @@ -49,6 +49,9 @@ __cmdParser__.add_option("-a", "--alloptions", action="store_true", \ __cmdParser__.add_option("-f", "--fastoptions", action="store_true", \ dest="fastoptions", default=False, \ help="Use only fast options for loaded plugins") +__cmdParser__.add_option("-g", "--gatheronly", action="store_true", \ + dest="gatheronly", default=False, \ + help="Gather information locally but don't package or submit") __cmdParser__.add_option("-l", "--list-plugins", action="store_true", \ dest="listPlugins", default=False, \ help="list existing plugins") @@ -138,7 +141,6 @@ def sosreport(): # Set up common info and create destinations dstroot = sosFindTmpDir() - os.chmod(dstroot, 0755) cmddir = os.path.join(dstroot, "sos_commands") logdir = os.path.join(dstroot, "sos_logs") rptdir = os.path.join(dstroot, "sos_reports") @@ -154,6 +156,9 @@ def sosreport(): 'logfd': logfd, 'policy': policy, 'verbosity' : __cmdLineOpts__.verbosity} + # Make policy aware of the commons + policy.setCommons(commons) + # validate and load plugins plugins = os.listdir(pluginpath) if __cmdLineOpts__.listPlugins: @@ -262,10 +267,6 @@ def sosreport(): """) - rfd.write("Sosreport version blah blah
") - - - # Make a pass to gather Alerts and a list of module names allAlerts = [] @@ -308,19 +309,23 @@ def sosreport(): # Collect any needed user information (name, etc) - # Clean up left over files, make tarball, whatever. # Close all log files and perform any cleanup logfd.close() # Call the postproc method for each plugin - # Need to redo this completely to use only one selected reporter module - # This will require hackery and demagaugery, so for now, we'll just - # do something really offensively squinky. - import sos.reporters.tarball - sos.reporters.tarball.postproc() - - if root == dstroot: - print "The report is in " + rptdir + "/" + "sosreport.html" + for plugname, plug in loadedplugins: + plug.postproc() + + if __cmdLineOpts__.gatheronly: + print "Collected information is in " + dstroot + print "Your html report is in " + rptdir + "/" + "sosreport.html" + else: + # package up the results for the support organization + policy.packageResults() + # delete gathered files + os.system("rm -rf %s" % dstroot) + # automated submission will go here + if __name__ == '__main__': sosreport() -- cgit