1184902Srwatson/*- 2186647Srwatson * Copyright (c) 2005-2008 Apple Inc. 3184902Srwatson * Copyright (c) 2005 SPARTA, Inc. 4184902Srwatson * All rights reserved. 5184902Srwatson * 6184902Srwatson * This code was developed in part by Robert N. M. Watson, Senior Principal 7184902Srwatson * Scientist, SPARTA, Inc. 8184902Srwatson * 9184902Srwatson * Redistribution and use in source and binary forms, with or without 10184902Srwatson * modification, are permitted provided that the following conditions 11184902Srwatson * are met: 12184902Srwatson * 13184902Srwatson * 1. Redistributions of source code must retain the above copyright 14184902Srwatson * notice, this list of conditions and the following disclaimer. 15184902Srwatson * 2. Redistributions in binary form must reproduce the above copyright 16184902Srwatson * notice, this list of conditions and the following disclaimer in the 17184902Srwatson * documentation and/or other materials provided with the distribution. 18244390Srwatson * 3. Neither the name of Apple Inc. ("Apple") nor the names of 19184902Srwatson * its contributors may be used to endorse or promote products derived 20184902Srwatson * from this software without specific prior written permission. 21184902Srwatson * 22184902Srwatson * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 23184902Srwatson * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24184902Srwatson * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25184902Srwatson * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 26184902Srwatson * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27184902Srwatson * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28184902Srwatson * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29184902Srwatson * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30184902Srwatson * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31184902Srwatson * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32184902Srwatson * 33244390Srwatson * $P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit_internal.h#6 $ 34184902Srwatson */ 35184902Srwatson 36184902Srwatson#ifndef _AUDIT_INTERNAL_H 37184902Srwatson#define _AUDIT_INTERNAL_H 38184902Srwatson 39184902Srwatson#if defined(__linux__) && !defined(__unused) 40184902Srwatson#define __unused 41184902Srwatson#endif 42184902Srwatson 43184902Srwatson/* 44184902Srwatson * audit_internal.h contains private interfaces that are shared by user space 45184902Srwatson * and the kernel for the purposes of assembling audit records. Applications 46184902Srwatson * should not include this file or use the APIs found within, or it may be 47184902Srwatson * broken with future releases of OpenBSM, which may delete, modify, or 48184902Srwatson * otherwise break these interfaces or the assumptions they rely on. 49184902Srwatson */ 50184902Srwatsonstruct au_token { 51184902Srwatson u_char *t_data; 52184902Srwatson size_t len; 53184902Srwatson TAILQ_ENTRY(au_token) tokens; 54184902Srwatson}; 55184902Srwatson 56184902Srwatsonstruct au_record { 57184902Srwatson char used; /* Record currently in use? */ 58184902Srwatson int desc; /* Descriptor for record. */ 59184902Srwatson TAILQ_HEAD(, au_token) token_q; /* Queue of BSM tokens. */ 60184902Srwatson u_char *data; 61184902Srwatson size_t len; 62184902Srwatson LIST_ENTRY(au_record) au_rec_q; 63184902Srwatson}; 64184902Srwatsontypedef struct au_record au_record_t; 65184902Srwatson 66184902Srwatson 67184902Srwatson/* 68184902Srwatson * We could determined the header and trailer sizes by defining appropriate 69184902Srwatson * structures. We hold off that approach until we have a consistent way of 70184902Srwatson * using structures for all tokens. This is not straightforward since these 71184902Srwatson * token structures may contain pointers of whose contents we do not know the 72184902Srwatson * size (e.g text tokens). 73184902Srwatson */ 74184902Srwatson#define AUDIT_HEADER_EX_SIZE(a) ((a)->ai_termid.at_type+18+sizeof(u_int32_t)) 75184902Srwatson#define AUDIT_HEADER_SIZE 18 76184902Srwatson#define MAX_AUDIT_HEADER_SIZE (5*sizeof(u_int32_t)+18) 77184902Srwatson#define AUDIT_TRAILER_SIZE 7 78184902Srwatson 79184902Srwatson/* 80184902Srwatson * BSM token streams store fields in big endian byte order, so as to be 81184902Srwatson * portable; when encoding and decoding, we must convert byte orders for 82184902Srwatson * typed values. 83184902Srwatson */ 84184902Srwatson#define ADD_U_CHAR(loc, val) \ 85184902Srwatson do { \ 86184902Srwatson *(loc) = (val); \ 87184902Srwatson (loc) += sizeof(u_char); \ 88184902Srwatson } while(0) 89184902Srwatson 90184902Srwatson 91184902Srwatson#define ADD_U_INT16(loc, val) \ 92184902Srwatson do { \ 93184902Srwatson be16enc((loc), (val)); \ 94184902Srwatson (loc) += sizeof(u_int16_t); \ 95184902Srwatson } while(0) 96184902Srwatson 97184902Srwatson#define ADD_U_INT32(loc, val) \ 98184902Srwatson do { \ 99184902Srwatson be32enc((loc), (val)); \ 100184902Srwatson (loc) += sizeof(u_int32_t); \ 101184902Srwatson } while(0) 102184902Srwatson 103184902Srwatson#define ADD_U_INT64(loc, val) \ 104184902Srwatson do { \ 105184902Srwatson be64enc((loc), (val)); \ 106184902Srwatson (loc) += sizeof(u_int64_t); \ 107184902Srwatson } while(0) 108184902Srwatson 109184902Srwatson#define ADD_MEM(loc, data, size) \ 110184902Srwatson do { \ 111184902Srwatson memcpy((loc), (data), (size)); \ 112184902Srwatson (loc) += size; \ 113184902Srwatson } while(0) 114184902Srwatson 115184902Srwatson#define ADD_STRING(loc, data, size) ADD_MEM(loc, data, size) 116184902Srwatson 117184902Srwatson#endif /* !_AUDIT_INTERNAL_H_ */ 118