audit_internal.h revision 293161
1/*-
2 * Copyright (c) 2005-2008 Apple Inc.
3 * Copyright (c) 2005 SPARTA, Inc.
4 * All rights reserved.
5 *
6 * This code was developed in part by Robert N. M. Watson, Senior Principal
7 * Scientist, SPARTA, Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1.  Redistributions of source code must retain the above copyright
14 *     notice, this list of conditions and the following disclaimer.
15 * 2.  Redistributions in binary form must reproduce the above copyright
16 *     notice, this list of conditions and the following disclaimer in the
17 *     documentation and/or other materials provided with the distribution.
18 * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
19 *     its contributors may be used to endorse or promote products derived
20 *     from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
23 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
26 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#ifndef _AUDIT_INTERNAL_H
35#define	_AUDIT_INTERNAL_H
36
37#if defined(__linux__) && !defined(__unused)
38#define	__unused
39#endif
40
41/*
42 * audit_internal.h contains private interfaces that are shared by user space
43 * and the kernel for the purposes of assembling audit records.  Applications
44 * should not include this file or use the APIs found within, or it may be
45 * broken with future releases of OpenBSM, which may delete, modify, or
46 * otherwise break these interfaces or the assumptions they rely on.
47 */
48struct au_token {
49	u_char			*t_data;
50	size_t			 len;
51	TAILQ_ENTRY(au_token)	 tokens;
52};
53
54struct au_record {
55	char			 used;		/* Record currently in use? */
56	int			 desc;		/* Descriptor for record. */
57	TAILQ_HEAD(, au_token)	 token_q;	/* Queue of BSM tokens. */
58	u_char			*data;
59	size_t			 len;
60	LIST_ENTRY(au_record)	 au_rec_q;
61};
62typedef	struct au_record	au_record_t;
63
64
65/*
66 * We could determined the header and trailer sizes by defining appropriate
67 * structures.  We hold off that approach until we have a consistent way of
68 * using structures for all tokens.  This is not straightforward since these
69 * token structures may contain pointers of whose contents we do not know the
70 * size (e.g text tokens).
71 */
72#define	AUDIT_HEADER_EX_SIZE(a)	((a)->ai_termid.at_type+18+sizeof(u_int32_t))
73#define	AUDIT_HEADER_SIZE	18
74#define	MAX_AUDIT_HEADER_SIZE	(5*sizeof(u_int32_t)+18)
75#define	AUDIT_TRAILER_SIZE	7
76
77/*
78 * BSM token streams store fields in big endian byte order, so as to be
79 * portable; when encoding and decoding, we must convert byte orders for
80 * typed values.
81 */
82#define	ADD_U_CHAR(loc, val)						\
83	do {								\
84		*(loc) = (val);						\
85		(loc) += sizeof(u_char);				\
86	} while(0)
87
88
89#define	ADD_U_INT16(loc, val)						\
90	do {								\
91		be16enc((loc), (val));					\
92		(loc) += sizeof(u_int16_t);				\
93	} while(0)
94
95#define	ADD_U_INT32(loc, val)						\
96	do {								\
97		be32enc((loc), (val));					\
98		(loc) += sizeof(u_int32_t);				\
99	} while(0)
100
101#define	ADD_U_INT64(loc, val)						\
102	do {								\
103		be64enc((loc), (val));					\
104		(loc) += sizeof(u_int64_t); 				\
105	} while(0)
106
107#define	ADD_MEM(loc, data, size)					\
108	do {								\
109		memcpy((loc), (data), (size));				\
110		(loc) += size;						\
111	} while(0)
112
113#define	ADD_STRING(loc, data, size)	ADD_MEM(loc, data, size)
114
115#endif /* !_AUDIT_INTERNAL_H_ */
116