From: Lennart Poettering Date: Wed, 2 Jun 2021 20:10:22 +0000 (+0200) Subject: test: tweak privilege tests for two more tests X-Git-Tag: v249-rc1~106^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c75370cc18d92a9a2cc3eafeb3b46e1d23ea0ac4;p=thirdparty%2Fsystemd.git test: tweak privilege tests for two more tests These tests require properly privileged root users, hence skip things when we don't have CAP_SYS_ADMIN. Fixes: #19746 --- diff --git a/src/test/test-execute.c b/src/test/test-execute.c index 239fcea5e3d..125e0bbf4f7 100644 --- a/src/test/test-execute.c +++ b/src/test/test-execute.c @@ -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) diff --git a/src/test/test-mount-util.c b/src/test/test-mount-util.c index 2e9116d359d..ab5184121c8 100644 --- a/src/test/test-mount-util.c +++ b/src/test/test-mount-util.c @@ -4,6 +4,7 @@ #include #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; }