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