xref: /xnu-8020.121.3/tests/rm/pthread_setugid.c (revision fdd8201d7b966f0c3ea610489d29bd841d358941)
1*fdd8201dSApple OSS Distributions #include <darwintest.h>
2*fdd8201dSApple OSS Distributions #include <dispatch/dispatch.h>
3*fdd8201dSApple OSS Distributions #include <sys/unistd.h>
4*fdd8201dSApple OSS Distributions 
5*fdd8201dSApple OSS Distributions T_GLOBAL_META(T_META_NAMESPACE("xnu.rm"),
6*fdd8201dSApple OSS Distributions     T_META_RADAR_COMPONENT_NAME("xnu"),
7*fdd8201dSApple OSS Distributions     T_META_RADAR_COMPONENT_VERSION("rm"),
8*fdd8201dSApple OSS Distributions     T_META_OWNER("phabouzit")
9*fdd8201dSApple OSS Distributions     );
10*fdd8201dSApple OSS Distributions 
11*fdd8201dSApple OSS Distributions T_DECL(pthread_setugid_np_81523076,
12*fdd8201dSApple OSS Distributions     "Make sure pthread_setugid_np() isn't sticky to workqueue threads",
13*fdd8201dSApple OSS Distributions     T_META_CHECK_LEAKS(false),
14*fdd8201dSApple OSS Distributions     T_META_ASROOT(true))
15*fdd8201dSApple OSS Distributions {
16*fdd8201dSApple OSS Distributions 	int rc;
17*fdd8201dSApple OSS Distributions 
18*fdd8201dSApple OSS Distributions 	rc = pthread_setugid_np(501, getgid());
19*fdd8201dSApple OSS Distributions 	T_ASSERT_POSIX_SUCCESS(rc, "pthread_setugid_np(501, getgid())");
20*fdd8201dSApple OSS Distributions 
21*fdd8201dSApple OSS Distributions 	dispatch_async(dispatch_get_global_queue(0, 0), ^{
22*fdd8201dSApple OSS Distributions 		T_ASSERT_EQ(getuid(), 0, "getuid should still be 0");
23*fdd8201dSApple OSS Distributions 		T_END;
24*fdd8201dSApple OSS Distributions 	});
25*fdd8201dSApple OSS Distributions 	pause();
26*fdd8201dSApple OSS Distributions }
27