From: Michael Tremer Date: Fri, 25 Feb 2011 23:44:37 +0000 (+0100) Subject: Check if pakfire is run by the root user. X-Git-Tag: 0.9.3~122 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5c6f73b4f085d55dfa883b2ae1ac8f4fad0802cd;p=pakfire.git Check if pakfire is run by the root user. --- diff --git a/pakfire/__init__.py b/pakfire/__init__.py index 11e0f3723..ced0aae8e 100644 --- a/pakfire/__init__.py +++ b/pakfire/__init__.py @@ -26,6 +26,9 @@ __version__ = 0.1 class Pakfire(object): def __init__(self, path="/tmp/pakfire", builder=False, configs=[], disable_repos=None): + # Check if we are operating as the root user. + self.check_root_user() + # The path where we are operating in self.path = path @@ -73,6 +76,10 @@ class Pakfire(object): # always work with valid data. self.repos.update_indexes() + def check_root_user(self): + if not os.getuid() == 0 or not os.getgid() == 0: + raise Exception, "You must run pakfire as the root user." + def check_build_mode(self): """ Check if we are running in build mode. diff --git a/pakfire/cli.py b/pakfire/cli.py index 5bbe08a8c..40bd3e9b0 100644 --- a/pakfire/cli.py +++ b/pakfire/cli.py @@ -30,8 +30,6 @@ def ask_user(question): class Cli(object): - # XXX check if we are running as the root user - def __init__(self): self.parser = argparse.ArgumentParser( description = _("Pakfire command line interface."),