cap_test_sysctl.c revision 221431
11573Srgrimes/*-
21573Srgrimes * Copyright (c) 2008-2011 Robert N. M. Watson
31573Srgrimes * All rights reserved.
41573Srgrimes *
51573Srgrimes * Redistribution and use in source and binary forms, with or without
61573Srgrimes * modification, are permitted provided that the following conditions
71573Srgrimes * are met:
81573Srgrimes * 1. Redistributions of source code must retain the above copyright
91573Srgrimes *    notice, this list of conditions and the following disclaimer.
101573Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111573Srgrimes *    notice, this list of conditions and the following disclaimer in the
121573Srgrimes *    documentation and/or other materials provided with the distribution.
131573Srgrimes *
141573Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
151573Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
161573Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
171573Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
181573Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
191573Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
201573Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
211573Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
221573Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
231573Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
241573Srgrimes * SUCH DAMAGE.
251573Srgrimes *
261573Srgrimes * $FreeBSD: head/tools/regression/security/cap_test/cap_test_sysctl.c 221431 2011-05-04 12:44:46Z jonathan $
271573Srgrimes */
281573Srgrimes
291573Srgrimes/*
301573Srgrimes * Test that various sysctls are (and aren't) available on capability mode.
311573Srgrimes */
321573Srgrimes
331573Srgrimes#include <sys/cdefs.h>
341573Srgrimes__FBSDID("$FreeBSD: head/tools/regression/security/cap_test/cap_test_sysctl.c 221431 2011-05-04 12:44:46Z jonathan $");
351573Srgrimes
361573Srgrimes#include <sys/types.h>
371573Srgrimes#include <sys/capability.h>
381573Srgrimes#include <sys/sysctl.h>
391573Srgrimes#include <sys/wait.h>
401573Srgrimes
411573Srgrimes#include <err.h>
421573Srgrimes#include <errno.h>
431573Srgrimes#include <stdio.h>
441573Srgrimes#include <stdlib.h>
451573Srgrimes#include <unistd.h>
461573Srgrimes
471573Srgrimes#include "cap_test.h"
481573Srgrimes
491573Srgrimes/*
501573Srgrimes * Certain sysctls are permitted in capability mode, but most are not.  Test
511573Srgrimes * for the ones that should be, and try one or two that shouldn't.
521573Srgrimes */
531573Srgrimesvoid
541573Srgrimestest_sysctl(void)
551573Srgrimes{
561573Srgrimes	int error, i, oid[2];
571573Srgrimes	size_t len;
581573Srgrimes
591573Srgrimes	oid[0] = CTL_KERN;
601573Srgrimes	oid[1] = KERN_OSRELDATE;
618870Srgrimes	len = sizeof(i);
621573Srgrimes	error = sysctl(oid, 2, &i, &len, NULL, 0);
631573Srgrimes	if (error)
641573Srgrimes		warnx("capmode and kern.osreldate failed error %d", errno);
651573Srgrimes
661573Srgrimes	exit(0);
671573Srgrimes}
681573Srgrimes