From: Zbigniew Jędrzejewski-Szmek Date: Fri, 4 Sep 2020 16:02:57 +0000 (+0200) Subject: test-execute: check if private directories have bad permissions before running test_e... X-Git-Tag: v247-rc1~282^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cced2b98efcf60f9dce573451ff637bb8227d90b;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/test/test-execute.c b/src/test/test-execute.c index b759786eafb..e32e0c0b6c4 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"))