From: Michael Tremer Date: Tue, 16 Aug 2022 12:41:04 +0000 (+0000) Subject: tests: jail: Check file ownership X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bddfe6687e1e08bff96b5ee9ced3376a205ebff3;p=people%2Fstevee%2Fpakfire.git tests: jail: Check file ownership Signed-off-by: Michael Tremer --- diff --git a/tests/libpakfire/jail.c b/tests/libpakfire/jail.c index 2b5240bc..008e05ef 100644 --- a/tests/libpakfire/jail.c +++ b/tests/libpakfire/jail.c @@ -35,6 +35,10 @@ static const char* cmd_fork_bomb[] = { "/command", "fork-bomb", NULL, }; +static const char* cmd_stat_ownership[] = { + "/command", "stat-ownership", NULL, +}; + static int test_create(const struct test* t) { struct pakfire_jail* jail = NULL; @@ -210,7 +214,6 @@ static int test_pid_limit(const struct test* t) { struct pakfire_jail* jail = NULL; int r = EXIT_FAILURE; - // Create cgroup ASSERT_SUCCESS(pakfire_cgroup_open(&cgroup, t->pakfire, "pakfire-test", 0)); @@ -240,6 +243,26 @@ FAIL: return r; } +static int test_file_ownership(const struct test* t) { + int r = EXIT_FAILURE; + char* output = NULL; + + // Execute a simple command + ASSERT_SUCCESS(pakfire_jail_run(t->pakfire, cmd_stat_ownership, 0, &output)); + + // Check if the file has been mapped to root/root + ASSERT_STRING_EQUALS(output, "uid=0 gid=0\n"); + + // Success + r = EXIT_SUCCESS; + +FAIL: + if (output) + free(output); + + return r; +} + int main(int argc, const char* argv[]) { testsuite_add_test(test_create); testsuite_add_test(test_env); @@ -248,6 +271,7 @@ int main(int argc, const char* argv[]) { testsuite_add_test(test_nice); testsuite_add_test(test_memory_limit); testsuite_add_test(test_pid_limit); + testsuite_add_test(test_file_ownership); return testsuite_run(argc, argv); }