audit.h revision 171542
1/*
2 * Copyright (c) 2005 Apple Computer, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1.  Redistributions of source code must retain the above copyright
10 *     notice, this list of conditions and the following disclaimer.
11 * 2.  Redistributions in binary form must reproduce the above copyright
12 *     notice, this list of conditions and the following disclaimer in the
13 *     documentation and/or other materials provided with the distribution.
14 * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 *     its contributors may be used to endorse or promote products derived
16 *     from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * P4: //depot/projects/trustedbsd/audit3/sys/bsm/audit.h#38
30 * $FreeBSD: head/sys/bsm/audit.h 171542 2007-07-22 12:28:13Z rwatson $
31 */
32
33#ifndef _BSM_AUDIT_H
34#define	_BSM_AUDIT_H
35
36#include <sys/param.h>
37#include <sys/cdefs.h>
38#include <sys/queue.h>
39
40#define	AUDIT_RECORD_MAGIC	0x828a0f1b
41#define	MAX_AUDIT_RECORDS	20
42#define	MAXAUDITDATA		(0x8000 - 1)
43#define	MAX_AUDIT_RECORD_SIZE	MAXAUDITDATA
44#define	MIN_AUDIT_FILE_SIZE	(512 * 1024)
45
46/*
47 * Minimum noumber of free blocks on the filesystem containing the audit
48 * log necessary to avoid a hard log rotation. DO NOT SET THIS VALUE TO 0
49 * as the kernel does an unsigned compare, plus we want to leave a few blocks
50 * free so userspace can terminate the log, etc.
51 */
52#define	AUDIT_HARD_LIMIT_FREE_BLOCKS	4
53
54/*
55 * Triggers for the audit daemon.
56 */
57#define	AUDIT_TRIGGER_MIN		1
58#define	AUDIT_TRIGGER_LOW_SPACE		1	/* Below low watermark. */
59#define	AUDIT_TRIGGER_ROTATE_KERNEL	2	/* Kernel requests rotate. */
60#define	AUDIT_TRIGGER_READ_FILE		3	/* Re-read config file. */
61#define	AUDIT_TRIGGER_CLOSE_AND_DIE	4	/* Terminate audit. */
62#define	AUDIT_TRIGGER_NO_SPACE		5	/* Below min free space. */
63#define	AUDIT_TRIGGER_ROTATE_USER	6	/* User requests roate. */
64#define	AUDIT_TRIGGER_MAX		6
65
66/*
67 * The special device filename (FreeBSD).
68 */
69#define	AUDITDEV_FILENAME	"audit"
70#define	AUDIT_TRIGGER_FILE	("/dev/" AUDITDEV_FILENAME)
71
72/*
73 * Pre-defined audit IDs
74 */
75#define	AU_DEFAUDITID	-1
76
77/*
78 * Define the masks for the classes of audit events.
79 */
80#define	AU_NULL		0x00000000
81#define	AU_FREAD	0x00000001
82#define	AU_FWRITE	0x00000002
83#define	AU_FACCESS	0x00000004
84#define	AU_FMODIFY	0x00000008
85#define	AU_FCREATE	0x00000010
86#define	AU_FDELETE	0x00000020
87#define	AU_CLOSE	0x00000040
88#define	AU_PROCESS	0x00000080
89#define	AU_NET		0x00000100
90#define	AU_IPC		0x00000200
91#define	AU_NONAT	0x00000400
92#define	AU_ADMIN	0x00000800
93#define	AU_LOGIN	0x00001000
94#define	AU_TFM		0x00002000
95#define	AU_APPL		0x00004000
96#define	AU_SETL		0x00008000
97#define	AU_IFLOAT	0x00010000
98#define	AU_PRIV		0x00020000
99#define	AU_MAC_RW	0x00040000
100#define	AU_XCONN	0x00080000
101#define	AU_XCREATE	0x00100000
102#define	AU_XDELETE	0x00200000
103#define	AU_XIFLOAT	0x00400000
104#define	AU_XPRIVS	0x00800000
105#define	AU_XPRIVF	0x01000000
106#define	AU_XMOVE	0x02000000
107#define	AU_XDACF	0x04000000
108#define	AU_XMACF	0x08000000
109#define	AU_XSECATTR	0x10000000
110#define	AU_IOCTL	0x20000000
111#define	AU_EXEC		0x40000000
112#define	AU_OTHER	0x80000000
113#define	AU_ALL		0xffffffff
114
115/*
116 * IPC types.
117 */
118#define	AT_IPC_MSG	((u_char)1)	/* Message IPC id. */
119#define	AT_IPC_SEM	((u_char)2)	/* Semaphore IPC id. */
120#define	AT_IPC_SHM	((u_char)3)	/* Shared mem IPC id. */
121
122/*
123 * Audit conditions.
124 */
125#define	AUC_UNSET		0
126#define	AUC_AUDITING		1
127#define	AUC_NOAUDIT		2
128#define	AUC_DISABLED		-1
129
130/*
131 * auditon(2) commands.
132 */
133#define	A_GETPOLICY	2
134#define	A_SETPOLICY	3
135#define	A_GETKMASK	4
136#define	A_SETKMASK	5
137#define	A_GETQCTRL	6
138#define	A_SETQCTRL	7
139#define	A_GETCWD	8
140#define	A_GETCAR	9
141#define	A_GETSTAT	12
142#define	A_SETSTAT	13
143#define	A_SETUMASK	14
144#define	A_SETSMASK	15
145#define	A_GETCOND	20
146#define	A_SETCOND	21
147#define	A_GETCLASS	22
148#define	A_SETCLASS	23
149#define	A_GETPINFO	24
150#define	A_SETPMASK	25
151#define	A_SETFSIZE	26
152#define	A_GETFSIZE	27
153#define	A_GETPINFO_ADDR	28
154#define	A_GETKAUDIT	29
155#define	A_SETKAUDIT	30
156#define	A_SENDTRIGGER	31
157
158/*
159 * Audit policy controls.
160 */
161#define	AUDIT_CNT	0x0001
162#define	AUDIT_AHLT	0x0002
163#define	AUDIT_ARGV	0x0004
164#define	AUDIT_ARGE	0x0008
165#define	AUDIT_SEQ	0x0010
166#define	AUDIT_WINDATA	0x0020
167#define	AUDIT_USER	0x0040
168#define	AUDIT_GROUP	0x0080
169#define	AUDIT_TRAIL	0x0100
170#define	AUDIT_PATH	0x0200
171#define	AUDIT_SCNT	0x0400
172#define	AUDIT_PUBLIC	0x0800
173#define	AUDIT_ZONENAME	0x1000
174#define	AUDIT_PERZONE	0x2000
175
176/*
177 * Default audit queue control parameters.
178 */
179#define	AQ_HIWATER	100
180#define	AQ_MAXHIGH	10000
181#define	AQ_LOWATER	10
182#define	AQ_BUFSZ	MAXAUDITDATA
183#define	AQ_MAXBUFSZ	1048576
184
185/*
186 * Default minimum percentage free space on file system.
187 */
188#define	AU_FS_MINFREE	20
189
190/*
191 * Type definitions used indicating the length of variable length addresses
192 * in tokens containing addresses, such as header fields.
193 */
194#define	AU_IPv4		4
195#define	AU_IPv6		16
196
197__BEGIN_DECLS
198
199typedef	uid_t		au_id_t;
200typedef	pid_t		au_asid_t;
201typedef	u_int16_t	au_event_t;
202typedef	u_int16_t	au_emod_t;
203typedef	u_int32_t	au_class_t;
204
205struct au_tid {
206	dev_t		port;
207	u_int32_t	machine;
208};
209typedef	struct au_tid	au_tid_t;
210
211struct au_tid_addr {
212	dev_t		at_port;
213	u_int32_t	at_type;
214	u_int32_t	at_addr[4];
215};
216typedef	struct au_tid_addr	au_tid_addr_t;
217
218struct au_mask {
219	unsigned int    am_success;     /* Success bits. */
220	unsigned int    am_failure;     /* Failure bits. */
221};
222typedef	struct au_mask	au_mask_t;
223
224struct auditinfo {
225	au_id_t		ai_auid;	/* Audit user ID. */
226	au_mask_t	ai_mask;	/* Audit masks. */
227	au_tid_t	ai_termid;	/* Terminal ID. */
228	au_asid_t	ai_asid;	/* Audit session ID. */
229};
230typedef	struct auditinfo	auditinfo_t;
231
232struct auditinfo_addr {
233	au_id_t		ai_auid;	/* Audit user ID. */
234	au_mask_t	ai_mask;	/* Audit masks. */
235	au_tid_addr_t	ai_termid;	/* Terminal ID. */
236	au_asid_t	ai_asid;	/* Audit session ID. */
237};
238typedef	struct auditinfo_addr	auditinfo_addr_t;
239
240struct auditpinfo {
241	pid_t		ap_pid;		/* ID of target process. */
242	au_id_t		ap_auid;	/* Audit user ID. */
243	au_mask_t	ap_mask;	/* Audit masks. */
244	au_tid_t	ap_termid;	/* Terminal ID. */
245	au_asid_t	ap_asid;	/* Audit session ID. */
246};
247typedef	struct auditpinfo	auditpinfo_t;
248
249struct auditpinfo_addr {
250	pid_t		ap_pid;		/* ID of target process. */
251	au_id_t		ap_auid;	/* Audit user ID. */
252	au_mask_t	ap_mask;	/* Audit masks. */
253	au_tid_addr_t	ap_termid;	/* Terminal ID. */
254	au_asid_t	ap_asid;	/* Audit session ID. */
255};
256typedef	struct auditpinfo_addr	auditpinfo_addr_t;
257
258/*
259 * Contents of token_t are opaque outside of libbsm.
260 */
261typedef	struct au_token	token_t;
262
263/*
264 * Kernel audit queue control parameters.
265 */
266struct au_qctrl {
267	size_t	aq_hiwater;
268	size_t	aq_lowater;
269	size_t	aq_bufsz;
270	clock_t	aq_delay;
271	int	aq_minfree;	/* Minimum filesystem percent free space. */
272};
273typedef	struct au_qctrl	au_qctrl_t;
274
275/*
276 * Structure for the audit statistics.
277 */
278struct audit_stat {
279	unsigned int	as_version;
280	unsigned int	as_numevent;
281	int		as_generated;
282	int		as_nonattrib;
283	int		as_kernel;
284	int		as_audit;
285	int		as_auditctl;
286	int		as_enqueue;
287	int		as_written;
288	int		as_wblocked;
289	int		as_rblocked;
290	int		as_dropped;
291	int		as_totalsize;
292	unsigned int	as_memused;
293};
294typedef	struct audit_stat	au_stat_t;
295
296/*
297 * Structure for the audit file statistics.
298 */
299struct audit_fstat {
300	u_quad_t	af_filesz;
301	u_quad_t	af_currsz;
302};
303typedef	struct audit_fstat	au_fstat_t;
304
305/*
306 * Audit to event class mapping.
307 */
308struct au_evclass_map {
309	au_event_t	ec_number;
310	au_class_t	ec_class;
311};
312typedef	struct au_evclass_map	au_evclass_map_t;
313
314/*
315 * Audit system calls.
316 */
317#if !defined(_KERNEL) && !defined(KERNEL)
318int	audit(const void *, int);
319int	auditon(int, void *, int);
320int	auditctl(const char *);
321int	getauid(au_id_t *);
322int	setauid(const au_id_t *);
323int	getaudit(struct auditinfo *);
324int	setaudit(const struct auditinfo *);
325int	getaudit_addr(struct auditinfo_addr *, int);
326int	setaudit_addr(const struct auditinfo_addr *, int);
327#endif /* defined(_KERNEL) || defined(KERNEL) */
328
329__END_DECLS
330
331#endif /* !_BSM_AUDIT_H */
332