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