xref: /xnu-10002.41.9/tests/sysctl_system_version.c (revision 699cd48037512bf4380799317ca44ca453c82f57)
1*699cd480SApple OSS Distributions #include <darwintest.h>
2*699cd480SApple OSS Distributions #include <sys/sysctl.h>
3*699cd480SApple OSS Distributions 
4*699cd480SApple OSS Distributions T_DECL(sysctl_osreleasetype_nowrite,
5*699cd480SApple OSS Distributions     "ensure the osreleasetype sysctl is not writeable by normal processes")
6*699cd480SApple OSS Distributions {
7*699cd480SApple OSS Distributions 	char nice_try[32] = "FactoryToAvoidSandbox!";
8*699cd480SApple OSS Distributions 	int ret = sysctlbyname("kern.osreleasetype", NULL, NULL, nice_try,
9*699cd480SApple OSS Distributions 	    sizeof(nice_try));
10*699cd480SApple OSS Distributions 	T_ASSERT_POSIX_FAILURE(ret, EPERM, "try to set kern.osreleasetype sysctl");
11*699cd480SApple OSS Distributions }
12*699cd480SApple OSS Distributions 
13*699cd480SApple OSS Distributions T_DECL(sysctl_osreleasetype_exists, "ensure the osreleasetype sysctl exists")
14*699cd480SApple OSS Distributions {
15*699cd480SApple OSS Distributions 	char release_type[64] = "";
16*699cd480SApple OSS Distributions 	size_t release_type_size = sizeof(release_type);
17*699cd480SApple OSS Distributions 	int ret = sysctlbyname("kern.osreleasetype", release_type,
18*699cd480SApple OSS Distributions 	    &release_type_size, NULL, 0);
19*699cd480SApple OSS Distributions 	T_ASSERT_POSIX_SUCCESS(ret, "kern.osreleasetype sysctl");
20*699cd480SApple OSS Distributions 	T_LOG("kern.osreleasetype = %s", release_type);
21*699cd480SApple OSS Distributions }
22