From cced2b98efcf60f9dce573451ff637bb8227d90b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 4 Sep 2020 18:02:57 +0200 Subject: [PATCH] test-execute: check if private directories have bad permissions before running test_exec_dynamicuser() If the directory (/var/lib/private is most likely) has borked permissions, the test will fail with a cryptic message and EXIT_STATE_DIRECTORY or similar. The message from the child with more details gets lost somewhere. Let's avoid running the test in that case and provide a simple error message instead. E.g. systemd-238-12.git07f8cd5.fc28.ppc64 (which I encountered on a test machine) has /var/lib/private with 0755. --- src/test/test-execute.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/test/test-execute.c b/src/test/test-execute.c index b759786eaf..e32e0c0b6c 100644 --- a/src/test/test-execute.c +++ b/src/test/test-execute.c @@ -543,7 +543,29 @@ static void test_exec_supplementarygroups(Manager *m) { test(__func__, m, "exec-supplementarygroups-multiple-groups-withuid.service", 0, CLD_EXITED); } +static char* private_directory_bad(Manager *m) { + /* This mirrors setup_exec_directory(). */ + + for (ExecDirectoryType dt = 0; dt < _EXEC_DIRECTORY_TYPE_MAX; dt++) { + _cleanup_free_ char *p = NULL; + struct stat st; + + assert_se(p = path_join(m->prefix[dt], "private")); + + if (stat(p, &st) >= 0 && + (st.st_mode & (S_IRWXG|S_IRWXO))) + return TAKE_PTR(p); + } + + return NULL; +} + static void test_exec_dynamicuser(Manager *m) { + _cleanup_free_ char *bad = private_directory_bad(m); + if (bad) { + log_warning("%s: %s has bad permissions, skipping test.", __func__, bad); + return; + } test(__func__, m, "exec-dynamicuser-fixeduser.service", can_unshare ? 0 : EXIT_NAMESPACE, CLD_EXITED); if (check_user_has_group_with_same_name("adm"))