]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: tweak privilege tests for two more tests
authorLennart Poettering <lennart@poettering.net>
Wed, 2 Jun 2021 20:10:22 +0000 (22:10 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 3 Jun 2021 09:30:56 +0000 (11:30 +0200)
These tests require properly privileged root users, hence skip things
when we don't have CAP_SYS_ADMIN.

Fixes: #19746
src/test/test-execute.c
src/test/test-mount-util.c

index 239fcea5e3d90e1f46a1d39b6bea6bb0fe7963c9..125e0bbf4f75c781ae5aaaef7dfe3826558879f7 100644 (file)
@@ -924,8 +924,8 @@ int main(int argc, char *argv[]) {
         can_unshare = have_namespaces();
 
         /* It is needed otherwise cgroup creation fails */
-        if (getuid() != 0)
-                return log_tests_skipped("not root");
+        if (geteuid() != 0 || have_effective_cap(CAP_SYS_ADMIN) <= 0)
+                return log_tests_skipped("not privileged");
 
         r = enter_cgroup_subroot(NULL);
         if (r == -ENOMEDIUM)
index 2e9116d359dbeb9306f99a75a844541dd70d5753..ab5184121c8e6998d0cb1d551a25ddf40049eb68 100644 (file)
@@ -4,6 +4,7 @@
 #include <sys/statvfs.h>
 
 #include "alloc-util.h"
+#include "capability-util.h"
 #include "fd-util.h"
 #include "fileio.h"
 #include "mount-util.h"
@@ -75,8 +76,8 @@ static void test_bind_remount_recursive(void) {
         _cleanup_free_ char *subdir = NULL;
         const char *p;
 
-        if (geteuid() != 0) {
-                (void) log_tests_skipped("not running as root");
+        if (geteuid() != 0 || have_effective_cap(CAP_SYS_ADMIN) <= 0) {
+                (void) log_tests_skipped("not running privileged");
                 return;
         }
 
@@ -128,8 +129,8 @@ static void test_bind_remount_recursive(void) {
 static void test_bind_remount_one(void) {
         pid_t pid;
 
-        if (geteuid() != 0) {
-                (void) log_tests_skipped("not running as root");
+        if (geteuid() != 0 || have_effective_cap(CAP_SYS_ADMIN) <= 0) {
+                (void) log_tests_skipped("not running privileged");
                 return;
         }