1172106Srwatson/*- 2172106Srwatson * Copyright (c) 2007 Robert M. M. Watson 3172106Srwatson * All rights reserved. 4172106Srwatson * 5172106Srwatson * This software was developed by Robert N. M. Watson for the TrustedBSD 6172106Srwatson * Project. 7172106Srwatson * 8172106Srwatson * Redistribution and use in source and binary forms, with or without 9172106Srwatson * modification, are permitted provided that the following conditions 10172106Srwatson * are met: 11172106Srwatson * 1. Redistributions of source code must retain the above copyright 12172106Srwatson * notice, this list of conditions and the following disclaimer. 13172106Srwatson * 2. Redistributions in binary form must reproduce the above copyright 14172106Srwatson * notice, this list of conditions and the following disclaimer in the 15172106Srwatson * documentation and/or other materials provided with the distribution. 16172106Srwatson * 17172106Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18172106Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19172106Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20172106Srwatson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR, NCIRCLE NETWORK SECURITY, 21172106Srwatson * INC., OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22172106Srwatson * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 23172106Srwatson * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 24172106Srwatson * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25172106Srwatson * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26172106Srwatson * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27172106Srwatson * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28172106Srwatson * 29172106Srwatson * $FreeBSD: releng/10.3/tools/regression/priv/priv_audit_setaudit.c 172106 2007-09-09 23:08:39Z rwatson $ 30172106Srwatson */ 31172106Srwatson 32172106Srwatson/* 33172106Srwatson * Confirm privilege is required to set process audit properties; we first 34172106Srwatson * query current properties so that the attempted operation is a no-op. 35172106Srwatson */ 36172106Srwatson 37172106Srwatson#include <sys/types.h> 38172106Srwatson 39172106Srwatson#include <bsm/audit.h> 40172106Srwatson 41172106Srwatson#include <err.h> 42172106Srwatson#include <errno.h> 43172106Srwatson#include <stdio.h> 44172106Srwatson 45172106Srwatson#include "main.h" 46172106Srwatson 47172106Srwatsonstatic auditinfo_t ai; 48172106Srwatsonstatic auditinfo_addr_t aia; 49172106Srwatson 50172106Srwatsonint 51172106Srwatsonpriv_audit_setaudit_setup(int asroot, int injail, struct test *test) 52172106Srwatson{ 53172106Srwatson 54172106Srwatson if (getaudit(&ai) < 0) { 55172106Srwatson warn("priv_audit_setaudit_setup: getaudit"); 56172106Srwatson return (-1); 57172106Srwatson } 58172106Srwatson if (getaudit_addr(&aia, sizeof(aia)) < 0) { 59172106Srwatson warn("priv_audit_setaudit_setup: getaudit_addr"); 60172106Srwatson return (-1); 61172106Srwatson } 62172106Srwatson 63172106Srwatson return (0); 64172106Srwatson} 65172106Srwatson 66172106Srwatsonvoid 67172106Srwatsonpriv_audit_setaudit(int asroot, int injail, struct test *test) 68172106Srwatson{ 69172106Srwatson int error; 70172106Srwatson 71172106Srwatson error = setaudit(&ai); 72172106Srwatson if (asroot && injail) 73172106Srwatson expect("priv_audit_setaudit(asroot, injail)", error, -1, 74172106Srwatson ENOSYS); 75172106Srwatson if (asroot && !injail) 76172106Srwatson expect("priv_audit_setaudit(asroot, !injail)", error, 0, 0); 77172106Srwatson if (!asroot && injail) 78172106Srwatson expect("priv_audit_setaudit(!asroot, injail)", error, -1, 79172106Srwatson ENOSYS); 80172106Srwatson if (!asroot && !injail) 81172106Srwatson expect("priv_audit_setaudit(!asroot, !injail)", error, -1, 82172106Srwatson EPERM); 83172106Srwatson} 84172106Srwatson 85172106Srwatsonvoid 86172106Srwatsonpriv_audit_setaudit_addr(int asroot, int injail, struct test *test) 87172106Srwatson{ 88172106Srwatson int error; 89172106Srwatson 90172106Srwatson error = setaudit_addr(&aia, sizeof(aia)); 91172106Srwatson if (asroot && injail) 92172106Srwatson expect("priv_audit_setaudit_addr(asroot, injail)", error, -1, 93172106Srwatson ENOSYS); 94172106Srwatson if (asroot && !injail) 95172106Srwatson expect("priv_audit_setaudit_addr(asroot, !injail)", error, 0, 96172106Srwatson 0); 97172106Srwatson if (!asroot && injail) 98172106Srwatson expect("priv_audit_setaudit_addr(!asroot, injail)", error, 99172106Srwatson -1, ENOSYS); 100172106Srwatson if (!asroot && !injail) 101172106Srwatson expect("priv_audit_setaudit_addr(!asroot, !injail)", error, 102172106Srwatson -1, EPERM); 103172106Srwatson} 104172106Srwatson 105172106Srwatsonvoid 106172106Srwatsonpriv_audit_setaudit_cleanup(int asroot, int injail, struct test *test) 107172106Srwatson{ 108172106Srwatson 109172106Srwatson} 110