From 5c6f73b4f085d55dfa883b2ae1ac8f4fad0802cd Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 26 Feb 2011 00:44:37 +0100 Subject: [PATCH] Check if pakfire is run by the root user. --- pakfire/__init__.py | 7 +++++++ pakfire/cli.py | 2 -- 2 files changed, 7 insertions(+), 2 deletions(-) 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."), -- 2.39.5