From e03ff852ba35768362240d615d3e0960e3063ce1 Mon Sep 17 00:00:00 2001 From: Jesse Jaggars Date: Fri, 19 Aug 2011 16:35:02 -0500 Subject: Allowing plugins to specify whether or not they need root permissions in order to operate. This will allow for sosreport to run as a normal user provided that they only wish to execute plugins that require no super user permissions. --- build_jar.sh | 10 +++++----- sos/plugins/__init__.py | 3 +++ sos/sosreport.py | 14 ++++++++------ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/build_jar.sh b/build_jar.sh index e5517bce..1c5d1d33 100755 --- a/build_jar.sh +++ b/build_jar.sh @@ -1,11 +1,10 @@ #!/bin/bash BUILD_DIR=buildjar -DEST_JAR=$BUILD_DIR/sosreport.jar +ARCHIVE_NAME=sosreport.jar +DEST_JAR=$BUILD_DIR/$ARCHIVE_NAME PO_DIR=$BUILD_DIR/sos/po -cp $JYTHON_STANDALONE_JAR $DEST_JAR - echo "Making build directories ..." mkdir -p $PO_DIR @@ -21,8 +20,9 @@ done echo "Duplicating en ..." cp $PO_DIR/en.properties $PO_DIR/en_US.properties -echo "Removing .class files" +echo "Removing .class and .pyc files" find sos -name "*.class" | xargs rm +find sos -name "*.pyc" | xargs rm echo "Adding in sos ..." zip -r $DEST_JAR sos @@ -32,7 +32,7 @@ zip -r $DEST_JAR __run__.py echo "Adding in i18n ..." cd $BUILD_DIR -zip -r sosreport.jar sos +zip -r $ARCHIVE_NAME sos echo "Cleaning up ..." cd - diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index ff4e7606..5868ff09 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -74,6 +74,9 @@ class Plugin(object): be subclassed by platform specific superclasses. Actual plugins should not subclass this class directly. """ + + requires_root = True + def __init__(self, commons): if not getattr(self, "optionList", False): self.optionList = deque() diff --git a/sos/sosreport.py b/sos/sosreport.py index 048a5e49..43b645eb 100644 --- a/sos/sosreport.py +++ b/sos/sosreport.py @@ -262,6 +262,8 @@ No changes will be made to your system. signal.signal(signal.SIGTERM, self.get_exit_handler()) + self._is_root = (os.getuid() == 0) + self.opts, self.args = parse_options(opts) self._set_debug() self._read_config() @@ -275,6 +277,7 @@ No changes will be made to your system. self._check_for_unknown_plugins() self._set_plugin_options() + def print_header(self): print "\n%s\n" % _("sosreport (version %s)" % (__version__,)) @@ -470,6 +473,11 @@ No changes will be made to your system. self._skip(plugin_class) continue + if plugin_class.requires_root and not self._is_root: + self.soslog.warning(_("plugin %s requires root permissions to execute, skipping") % plug) + self._skip(plugin_class) + continue + # plug-in is valid, let's decide whether run it or not self.plugin_names.append(plugbase) @@ -817,11 +825,6 @@ No changes will be made to your system. # Close all log files and perform any cleanup logging.shutdown() - def ensure_root(self): - if os.getuid() != 0: - print _("sosreport requires root permissions to run.") - self._exit(1) - def ensure_plugins(self): if not self.loaded_plugins: self.soslog.error(_("no valid plugins were enabled")) @@ -834,7 +837,6 @@ def main(args): if sos.opts.listPlugins: sos.list_plugins() - sos.ensure_root() sos.ensure_plugins() sos.batch() -- cgit