1ceb42a13SJonathan Anderson /*-
2ceb42a13SJonathan Anderson * Copyright (c) 2008-2011 Robert N. M. Watson
3f8c6c2cfSJonathan Anderson * Copyright (c) 2011 Jonathan Anderson
4ceb42a13SJonathan Anderson * All rights reserved.
5ceb42a13SJonathan Anderson *
6ceb42a13SJonathan Anderson * Redistribution and use in source and binary forms, with or without
7ceb42a13SJonathan Anderson * modification, are permitted provided that the following conditions
8ceb42a13SJonathan Anderson * are met:
9ceb42a13SJonathan Anderson * 1. Redistributions of source code must retain the above copyright
10ceb42a13SJonathan Anderson * notice, this list of conditions and the following disclaimer.
11ceb42a13SJonathan Anderson * 2. Redistributions in binary form must reproduce the above copyright
12ceb42a13SJonathan Anderson * notice, this list of conditions and the following disclaimer in the
13ceb42a13SJonathan Anderson * documentation and/or other materials provided with the distribution.
14ceb42a13SJonathan Anderson *
15ceb42a13SJonathan Anderson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16ceb42a13SJonathan Anderson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17ceb42a13SJonathan Anderson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ceb42a13SJonathan Anderson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19ceb42a13SJonathan Anderson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20ceb42a13SJonathan Anderson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21ceb42a13SJonathan Anderson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22ceb42a13SJonathan Anderson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23ceb42a13SJonathan Anderson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24ceb42a13SJonathan Anderson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25ceb42a13SJonathan Anderson * SUCH DAMAGE.
26ceb42a13SJonathan Anderson */
27ceb42a13SJonathan Anderson
28ceb42a13SJonathan Anderson /*
29ceb42a13SJonathan Anderson * Test that various sysctls are (and aren't) available on capability mode.
30ceb42a13SJonathan Anderson */
31ceb42a13SJonathan Anderson
32ceb42a13SJonathan Anderson #include <sys/types.h>
33*b881b8beSRobert Watson #include <sys/capsicum.h>
34f8c6c2cfSJonathan Anderson #include <sys/errno.h>
35ceb42a13SJonathan Anderson #include <sys/sysctl.h>
36ceb42a13SJonathan Anderson #include <sys/wait.h>
37ceb42a13SJonathan Anderson
38ceb42a13SJonathan Anderson #include <err.h>
39ceb42a13SJonathan Anderson #include <stdio.h>
40ceb42a13SJonathan Anderson #include <stdlib.h>
41ceb42a13SJonathan Anderson #include <unistd.h>
42ceb42a13SJonathan Anderson
43ceb42a13SJonathan Anderson #include "cap_test.h"
44ceb42a13SJonathan Anderson
45ceb42a13SJonathan Anderson /*
46ceb42a13SJonathan Anderson * Certain sysctls are permitted in capability mode, but most are not. Test
47ceb42a13SJonathan Anderson * for the ones that should be, and try one or two that shouldn't.
48ceb42a13SJonathan Anderson */
49f8c6c2cfSJonathan Anderson int
test_sysctl(void)50ceb42a13SJonathan Anderson test_sysctl(void)
51ceb42a13SJonathan Anderson {
52f8c6c2cfSJonathan Anderson int i, oid[2];
53f8c6c2cfSJonathan Anderson int success = PASSED;
54ceb42a13SJonathan Anderson size_t len;
55ceb42a13SJonathan Anderson
56ceb42a13SJonathan Anderson oid[0] = CTL_KERN;
57ceb42a13SJonathan Anderson oid[1] = KERN_OSRELDATE;
58ceb42a13SJonathan Anderson len = sizeof(i);
59f8c6c2cfSJonathan Anderson CHECK(sysctl(oid, 2, &i, &len, NULL, 0) == 0);
60ceb42a13SJonathan Anderson
61f8c6c2cfSJonathan Anderson return (success);
62ceb42a13SJonathan Anderson }
63