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