cap_test_sysctl.c revision 221431
1131661Sdas/*- 2131661Sdas * Copyright (c) 2008-2011 Robert N. M. Watson 3131661Sdas * All rights reserved. 4131661Sdas * 5131661Sdas * Redistribution and use in source and binary forms, with or without 6131661Sdas * modification, are permitted provided that the following conditions 7131661Sdas * are met: 8131661Sdas * 1. Redistributions of source code must retain the above copyright 9131661Sdas * notice, this list of conditions and the following disclaimer. 10131661Sdas * 2. Redistributions in binary form must reproduce the above copyright 11131661Sdas * notice, this list of conditions and the following disclaimer in the 12131661Sdas * documentation and/or other materials provided with the distribution. 13131661Sdas * 14131661Sdas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15131661Sdas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16131661Sdas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17131661Sdas * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18131661Sdas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19131661Sdas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20131661Sdas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21131661Sdas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22131661Sdas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23131661Sdas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24131661Sdas * SUCH DAMAGE. 25131661Sdas * 26131661Sdas * $FreeBSD: head/tools/regression/security/cap_test/cap_test_sysctl.c 221431 2011-05-04 12:44:46Z jonathan $ 27131661Sdas */ 28131661Sdas 29131661Sdas/* 30131661Sdas * Test that various sysctls are (and aren't) available on capability mode. 31131661Sdas */ 32131661Sdas 33131661Sdas#include <sys/cdefs.h> 34131661Sdas__FBSDID("$FreeBSD: head/tools/regression/security/cap_test/cap_test_sysctl.c 221431 2011-05-04 12:44:46Z jonathan $"); 35131661Sdas 36131661Sdas#include <sys/types.h> 37131661Sdas#include <sys/capability.h> 38131661Sdas#include <sys/sysctl.h> 39131661Sdas#include <sys/wait.h> 40131661Sdas 41131661Sdas#include <err.h> 42131661Sdas#include <errno.h> 43131661Sdas#include <stdio.h> 44131661Sdas#include <stdlib.h> 45131661Sdas#include <unistd.h> 46131661Sdas 47131661Sdas#include "cap_test.h" 48131661Sdas 49131661Sdas/* 50131661Sdas * Certain sysctls are permitted in capability mode, but most are not. Test 51131661Sdas * for the ones that should be, and try one or two that shouldn't. 52131661Sdas */ 53131661Sdasvoid 54131661Sdastest_sysctl(void) 55131661Sdas{ 56131661Sdas int error, i, oid[2]; 57131661Sdas size_t len; 58131661Sdas 59131661Sdas oid[0] = CTL_KERN; 60131661Sdas oid[1] = KERN_OSRELDATE; 61131661Sdas len = sizeof(i); 62131661Sdas error = sysctl(oid, 2, &i, &len, NULL, 0); 63131661Sdas if (error) 64131661Sdas warnx("capmode and kern.osreldate failed error %d", errno); 65131661Sdas 66131661Sdas exit(0); 67131661Sdas} 68131661Sdas