[molecule] add support for enforcing super user privileges requirements

This commit is contained in:
Fabio Erculiani
2010-08-01 18:21:11 +02:00
parent 83dd67e84b
commit 0495f25a81
3 changed files with 28 additions and 1 deletions
+13 -1
View File
@@ -25,7 +25,8 @@ sys.path.insert(0,'molecule/')
sys.path.insert(0,'.')
import molecule.cmdline
from molecule.handlers import Runner
from molecule.utils import RUNNING_PIDS
from molecule.utils import RUNNING_PIDS, is_super_user
from molecule.i18n import _
def kill_pids():
for pid in RUNNING_PIDS:
@@ -36,6 +37,17 @@ if not molecule_data_order:
molecule.cmdline.print_help()
raise SystemExit(1)
super_user = is_super_user()
for el in molecule_data_order:
spec_data = molecule_data.get(el)
if spec_data is None:
# wtf
continue
super_user_required = spec_data['__plugin__'].require_super_user()
if super_user_required and (not super_user):
sys.stderr.write("%s: %s\n" % (el, _("required super user access"),))
raise SystemExit(1)
for el in molecule_data_order:
my = Runner(el, molecule_data.get(el))
try:
+9
View File
@@ -152,6 +152,15 @@ class GenericSpec(GenericSpecFunctions):
# Molecule Plugin factory support
BASE_PLUGIN_API_VERSION = 0
@staticmethod
def require_super_user():
"""
Determine whether super user access is required in order to execute
the given GenericSpec subclass. Default: True. Please override if
you allow unprivileged user execution.
"""
return True
@staticmethod
def execution_strategy():
"""
+6
View File
@@ -33,6 +33,12 @@ def get_year():
"""
return time.strftime("%Y")
def is_super_user():
"""
Return True if current process has uid = 0.
"""
return os.getuid() == 0
def valid_exec_check(path):
"""
Determine whethern give path is valid executable (by running it).