xref: /xnu-11215.41.3/tests/subsystem_root_path.c (revision 33de042d024d46de5ff4e89f2471de6608e37fa4)
1*33de042dSApple OSS Distributions #include <spawn_private.h>
2*33de042dSApple OSS Distributions #include "subsystem_root_path.h"
3*33de042dSApple OSS Distributions 
4*33de042dSApple OSS Distributions #include <darwintest.h>
5*33de042dSApple OSS Distributions #include <darwintest_utils.h>
6*33de042dSApple OSS Distributions 
7*33de042dSApple OSS Distributions #define UNENTITLED_EXECUTABLE_PATH "./subsystem_root_path_helper"
8*33de042dSApple OSS Distributions #define ENTITLED_EXECUTABLE_PATH "./subsystem_root_path_helper_entitled"
9*33de042dSApple OSS Distributions 
10*33de042dSApple OSS Distributions T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
11*33de042dSApple OSS Distributions 
12*33de042dSApple OSS Distributions T_DECL(subsystem_root_path,
13*33de042dSApple OSS Distributions     "Test the support for setting subsystem_root_path",
14*33de042dSApple OSS Distributions     T_META_CHECK_LEAKS(false))
15*33de042dSApple OSS Distributions {
16*33de042dSApple OSS Distributions 	char * args[] = { ENTITLED_EXECUTABLE_PATH, HELPER_BEHAVIOR_NOT_SET, "/main_root/", NULL};
17*33de042dSApple OSS Distributions 	int pid = 0;
18*33de042dSApple OSS Distributions 	posix_spawnattr_t attr = NULL;
19*33de042dSApple OSS Distributions 
20*33de042dSApple OSS Distributions 	T_ASSERT_EQ_INT(_spawn_and_wait(args, NULL), 0, "posix_spawn without attributes");
21*33de042dSApple OSS Distributions 	T_ASSERT_POSIX_SUCCESS(posix_spawnattr_init(&attr), "posix_spawnattr_init");
22*33de042dSApple OSS Distributions 	T_ASSERT_EQ_INT(_spawn_and_wait(args, &attr), 0, "posix_spawn with attributes");
23*33de042dSApple OSS Distributions 	T_ASSERT_POSIX_SUCCESS(posix_spawnattr_set_subsystem_root_path_np(&attr, args[2]), "Set subsystem root path");
24*33de042dSApple OSS Distributions 
25*33de042dSApple OSS Distributions 	args[1] = HELPER_BEHAVIOR_SET;
26*33de042dSApple OSS Distributions 
27*33de042dSApple OSS Distributions 	T_ASSERT_EQ_INT(_spawn_and_wait(args, &attr), 0, "posix_spawn with subsystem root path");
28*33de042dSApple OSS Distributions 	T_ASSERT_POSIX_SUCCESS(posix_spawnattr_set_subsystem_root_path_np(&attr, NULL), "Clear subsystem root path attribute");
29*33de042dSApple OSS Distributions 
30*33de042dSApple OSS Distributions 	args[1] = HELPER_BEHAVIOR_NOT_SET;
31*33de042dSApple OSS Distributions 
32*33de042dSApple OSS Distributions 	T_ASSERT_EQ_INT(_spawn_and_wait(args, &attr), 0, "Spawn without subsystem root path");
33*33de042dSApple OSS Distributions 
34*33de042dSApple OSS Distributions 	T_ASSERT_POSIX_SUCCESS(posix_spawnattr_set_subsystem_root_path_np(&attr, args[2]), "Set subsystem root path (again)");
35*33de042dSApple OSS Distributions 
36*33de042dSApple OSS Distributions 	args[1] = HELPER_BEHAVIOR_FORK_EXEC;
37*33de042dSApple OSS Distributions 
38*33de042dSApple OSS Distributions 	T_ASSERT_EQ_INT(_spawn_and_wait(args, &attr), 0, "Subsystem root path inheritence across fork/exec");
39*33de042dSApple OSS Distributions 
40*33de042dSApple OSS Distributions 	args[1] = HELPER_BEHAVIOR_SPAWN;
41*33de042dSApple OSS Distributions 
42*33de042dSApple OSS Distributions 	T_ASSERT_EQ_INT(_spawn_and_wait(args, &attr), 0, "Subsystem root path override through posix_spawn");
43*33de042dSApple OSS Distributions 
44*33de042dSApple OSS Distributions 	args[0] = UNENTITLED_EXECUTABLE_PATH;
45*33de042dSApple OSS Distributions 
46*33de042dSApple OSS Distributions 	T_ASSERT_NE_INT(_spawn_and_wait(args, &attr), 0, "Entitlement check");
47*33de042dSApple OSS Distributions 	T_ASSERT_POSIX_SUCCESS(posix_spawnattr_destroy(&attr), "posix_spawnattr_destroy");
48*33de042dSApple OSS Distributions }
49