From: Michael Tremer Date: Fri, 19 Mar 2021 18:53:40 +0000 (+0000) Subject: libpakfire: Move check whether we are running as root X-Git-Tag: 0.9.28~1285^2~504 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8c4649b2d3cda7f1fc8444362a475ddaa95d2ccc;p=pakfire.git libpakfire: Move check whether we are running as root Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 1abe0982f..d8e0cdebc 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -169,6 +169,12 @@ PAKFIRE_EXPORT int pakfire_create(Pakfire* pakfire, const char* path, const char return -ENOENT; } + // Check if we are running as root + uid_t uid = getuid(); + if (uid != 0) { + return -EPERM; + } + Pakfire p = calloc(1, sizeof(*p)); if (!p) return -ENOMEM; diff --git a/src/pakfire/base.py b/src/pakfire/base.py index 204a0f5de..e59b1501a 100644 --- a/src/pakfire/base.py +++ b/src/pakfire/base.py @@ -49,9 +49,6 @@ class Pakfire(_pakfire.Pakfire): # Default to system distribution self.distro = distro or system.distro - # Check if we are operating as the root user - self.check_root_user() - # check if we are actually running on an ipfire system if self.path == "/": self.check_is_ipfire() @@ -109,10 +106,6 @@ class Pakfire(_pakfire.Pakfire): for repo in self.repos: repo.refresh(force=force) - 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_is_ipfire(self): ret = os.path.exists("/etc/ipfire-release")