]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: Move check whether we are running as root
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 19 Mar 2021 18:53:40 +0000 (18:53 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 19 Mar 2021 18:53:40 +0000 (18:53 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/pakfire.c
src/pakfire/base.py

index 1abe0982fa80b826af638123b04b9f276d96a90f..d8e0cdebc267a6a2493c19aabddce585a0259764 100644 (file)
@@ -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;
index 204a0f5de4e8654a74e5173eec8a3a92584d9812..e59b1501a0574eec6678d20662fd1287f68125da 100644 (file)
@@ -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")