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