aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Jaggars <jjaggars@redhat.com>2011-08-19 16:35:02 -0500
committerJesse Jaggars <jjaggars@redhat.com>2011-08-19 16:35:02 -0500
commite03ff852ba35768362240d615d3e0960e3063ce1 (patch)
tree50700a121502c1e7b910b9d3b9e56581b965ac0b
parent8d8f6a5e2b832e7501174152c2f4903f85cba23a (diff)
downloadsos-r2.3.tar.gz
Allowing plugins to specify whether or not they need root permissionsr2.3
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.
-rwxr-xr-xbuild_jar.sh10
-rw-r--r--sos/plugins/__init__.py3
-rw-r--r--sos/sosreport.py14
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()