1184902Srwatson/*-
2191273Srwatson * Copyright (c) 2005-2009 Apple Inc.
3184902Srwatson * All rights reserved.
4184902Srwatson *
5184902Srwatson * Redistribution and use in source and binary forms, with or without
6184902Srwatson * modification, are permitted provided that the following conditions
7184902Srwatson * are met:
8184902Srwatson *
9184902Srwatson * 1.  Redistributions of source code must retain the above copyright
10184902Srwatson *     notice, this list of conditions and the following disclaimer.
11184902Srwatson * 2.  Redistributions in binary form must reproduce the above copyright
12184902Srwatson *     notice, this list of conditions and the following disclaimer in the
13184902Srwatson *     documentation and/or other materials provided with the distribution.
14184902Srwatson * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
15184902Srwatson *     its contributors may be used to endorse or promote products derived
16184902Srwatson *     from this software without specific prior written permission.
17184902Srwatson *
18184902Srwatson * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19184902Srwatson * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20184902Srwatson * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21184902Srwatson * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22184902Srwatson * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23184902Srwatson * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24184902Srwatson * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25184902Srwatson * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26184902Srwatson * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27184902Srwatson * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28184902Srwatson *
29195740Srwatson * $P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit.h#10 $
30184902Srwatson */
31184902Srwatson
32191273Srwatson#ifndef	_BSM_AUDIT_H
33184902Srwatson#define	_BSM_AUDIT_H
34184902Srwatson
35191273Srwatson#include <sys/param.h>
36186647Srwatson#include <sys/types.h>
37186647Srwatson
38184902Srwatson#define	AUDIT_RECORD_MAGIC	0x828a0f1b
39184902Srwatson#define	MAX_AUDIT_RECORDS	20
40184902Srwatson#define	MAXAUDITDATA		(0x8000 - 1)
41184902Srwatson#define	MAX_AUDIT_RECORD_SIZE	MAXAUDITDATA
42184902Srwatson#define	MIN_AUDIT_FILE_SIZE	(512 * 1024)
43184902Srwatson
44184902Srwatson/*
45186647Srwatson * Minimum noumber of free blocks on the filesystem containing the audit
46186647Srwatson * log necessary to avoid a hard log rotation. DO NOT SET THIS VALUE TO 0
47186647Srwatson * as the kernel does an unsigned compare, plus we want to leave a few blocks
48186647Srwatson * free so userspace can terminate the log, etc.
49186647Srwatson */
50186647Srwatson#define	AUDIT_HARD_LIMIT_FREE_BLOCKS	4
51186647Srwatson
52186647Srwatson/*
53184902Srwatson * Triggers for the audit daemon.
54184902Srwatson */
55184902Srwatson#define	AUDIT_TRIGGER_MIN		1
56184902Srwatson#define	AUDIT_TRIGGER_LOW_SPACE		1	/* Below low watermark. */
57184902Srwatson#define	AUDIT_TRIGGER_ROTATE_KERNEL	2	/* Kernel requests rotate. */
58184902Srwatson#define	AUDIT_TRIGGER_READ_FILE		3	/* Re-read config file. */
59184902Srwatson#define	AUDIT_TRIGGER_CLOSE_AND_DIE	4	/* Terminate audit. */
60184902Srwatson#define	AUDIT_TRIGGER_NO_SPACE		5	/* Below min free space. */
61186647Srwatson#define	AUDIT_TRIGGER_ROTATE_USER	6	/* User requests rotate. */
62189279Srwatson#define	AUDIT_TRIGGER_INITIALIZE	7	/* User initialize of auditd. */
63189279Srwatson#define	AUDIT_TRIGGER_EXPIRE_TRAILS	8	/* User expiration of trails. */
64189279Srwatson#define	AUDIT_TRIGGER_MAX		8
65184902Srwatson
66184902Srwatson/*
67184902Srwatson * The special device filename (FreeBSD).
68184902Srwatson */
69184902Srwatson#define	AUDITDEV_FILENAME	"audit"
70184902Srwatson#define	AUDIT_TRIGGER_FILE	("/dev/" AUDITDEV_FILENAME)
71184902Srwatson
72184902Srwatson/*
73184902Srwatson * Pre-defined audit IDs
74184902Srwatson */
75186647Srwatson#define	AU_DEFAUDITID	(uid_t)(-1)
76186647Srwatson#define	AU_DEFAUDITSID	 0
77186647Srwatson#define	AU_ASSIGN_ASID	-1
78184902Srwatson
79184902Srwatson/*
80184902Srwatson * IPC types.
81184902Srwatson */
82184902Srwatson#define	AT_IPC_MSG	((u_char)1)	/* Message IPC id. */
83184902Srwatson#define	AT_IPC_SEM	((u_char)2)	/* Semaphore IPC id. */
84184902Srwatson#define	AT_IPC_SHM	((u_char)3)	/* Shared mem IPC id. */
85184902Srwatson
86184902Srwatson/*
87184902Srwatson * Audit conditions.
88184902Srwatson */
89184902Srwatson#define	AUC_UNSET		0
90184902Srwatson#define	AUC_AUDITING		1
91184902Srwatson#define	AUC_NOAUDIT		2
92184902Srwatson#define	AUC_DISABLED		-1
93184902Srwatson
94184902Srwatson/*
95184902Srwatson * auditon(2) commands.
96184902Srwatson */
97191273Srwatson#define	A_OLDGETPOLICY	2
98191273Srwatson#define	A_OLDSETPOLICY	3
99184902Srwatson#define	A_GETKMASK	4
100184902Srwatson#define	A_SETKMASK	5
101191273Srwatson#define	A_OLDGETQCTRL	6
102191273Srwatson#define	A_OLDSETQCTRL	7
103184902Srwatson#define	A_GETCWD	8
104184902Srwatson#define	A_GETCAR	9
105184902Srwatson#define	A_GETSTAT	12
106184902Srwatson#define	A_SETSTAT	13
107184902Srwatson#define	A_SETUMASK	14
108184902Srwatson#define	A_SETSMASK	15
109191273Srwatson#define	A_OLDGETCOND	20
110191273Srwatson#define	A_OLDSETCOND	21
111184902Srwatson#define	A_GETCLASS	22
112184902Srwatson#define	A_SETCLASS	23
113184902Srwatson#define	A_GETPINFO	24
114184902Srwatson#define	A_SETPMASK	25
115184902Srwatson#define	A_SETFSIZE	26
116184902Srwatson#define	A_GETFSIZE	27
117184902Srwatson#define	A_GETPINFO_ADDR	28
118184902Srwatson#define	A_GETKAUDIT	29
119184902Srwatson#define	A_SETKAUDIT	30
120184902Srwatson#define	A_SENDTRIGGER	31
121186647Srwatson#define	A_GETSINFO_ADDR	32
122191273Srwatson#define	A_GETPOLICY	33
123191273Srwatson#define	A_SETPOLICY	34
124191273Srwatson#define	A_GETQCTRL	35
125191273Srwatson#define	A_SETQCTRL	36
126191273Srwatson#define	A_GETCOND	37
127191273Srwatson#define	A_SETCOND	38
128184902Srwatson
129184902Srwatson/*
130184902Srwatson * Audit policy controls.
131184902Srwatson */
132184902Srwatson#define	AUDIT_CNT	0x0001
133184902Srwatson#define	AUDIT_AHLT	0x0002
134184902Srwatson#define	AUDIT_ARGV	0x0004
135184902Srwatson#define	AUDIT_ARGE	0x0008
136184902Srwatson#define	AUDIT_SEQ	0x0010
137184902Srwatson#define	AUDIT_WINDATA	0x0020
138184902Srwatson#define	AUDIT_USER	0x0040
139184902Srwatson#define	AUDIT_GROUP	0x0080
140184902Srwatson#define	AUDIT_TRAIL	0x0100
141184902Srwatson#define	AUDIT_PATH	0x0200
142184902Srwatson#define	AUDIT_SCNT	0x0400
143184902Srwatson#define	AUDIT_PUBLIC	0x0800
144184902Srwatson#define	AUDIT_ZONENAME	0x1000
145184902Srwatson#define	AUDIT_PERZONE	0x2000
146184902Srwatson
147184902Srwatson/*
148184902Srwatson * Default audit queue control parameters.
149184902Srwatson */
150184902Srwatson#define	AQ_HIWATER	100
151184902Srwatson#define	AQ_MAXHIGH	10000
152184902Srwatson#define	AQ_LOWATER	10
153184902Srwatson#define	AQ_BUFSZ	MAXAUDITDATA
154184902Srwatson#define	AQ_MAXBUFSZ	1048576
155184902Srwatson
156184902Srwatson/*
157184902Srwatson * Default minimum percentage free space on file system.
158184902Srwatson */
159184902Srwatson#define	AU_FS_MINFREE	20
160184902Srwatson
161184902Srwatson/*
162184902Srwatson * Type definitions used indicating the length of variable length addresses
163184902Srwatson * in tokens containing addresses, such as header fields.
164184902Srwatson */
165184902Srwatson#define	AU_IPv4		4
166184902Srwatson#define	AU_IPv6		16
167184902Srwatson
168184902Srwatson__BEGIN_DECLS
169184902Srwatson
170184902Srwatsontypedef	uid_t		au_id_t;
171184902Srwatsontypedef	pid_t		au_asid_t;
172184902Srwatsontypedef	u_int16_t	au_event_t;
173184902Srwatsontypedef	u_int16_t	au_emod_t;
174184902Srwatsontypedef	u_int32_t	au_class_t;
175195740Srwatsontypedef	u_int64_t	au_asflgs_t __attribute__ ((aligned (8)));
176184902Srwatson
177184902Srwatsonstruct au_tid {
178184902Srwatson	dev_t		port;
179184902Srwatson	u_int32_t	machine;
180184902Srwatson};
181184902Srwatsontypedef	struct au_tid	au_tid_t;
182184902Srwatson
183184902Srwatsonstruct au_tid_addr {
184184902Srwatson	dev_t		at_port;
185184902Srwatson	u_int32_t	at_type;
186184902Srwatson	u_int32_t	at_addr[4];
187184902Srwatson};
188184902Srwatsontypedef	struct au_tid_addr	au_tid_addr_t;
189184902Srwatson
190184902Srwatsonstruct au_mask {
191184902Srwatson	unsigned int    am_success;     /* Success bits. */
192184902Srwatson	unsigned int    am_failure;     /* Failure bits. */
193184902Srwatson};
194184902Srwatsontypedef	struct au_mask	au_mask_t;
195184902Srwatson
196184902Srwatsonstruct auditinfo {
197184902Srwatson	au_id_t		ai_auid;	/* Audit user ID. */
198184902Srwatson	au_mask_t	ai_mask;	/* Audit masks. */
199184902Srwatson	au_tid_t	ai_termid;	/* Terminal ID. */
200184902Srwatson	au_asid_t	ai_asid;	/* Audit session ID. */
201184902Srwatson};
202184902Srwatsontypedef	struct auditinfo	auditinfo_t;
203184902Srwatson
204184902Srwatsonstruct auditinfo_addr {
205184902Srwatson	au_id_t		ai_auid;	/* Audit user ID. */
206184902Srwatson	au_mask_t	ai_mask;	/* Audit masks. */
207184902Srwatson	au_tid_addr_t	ai_termid;	/* Terminal ID. */
208184902Srwatson	au_asid_t	ai_asid;	/* Audit session ID. */
209195740Srwatson	au_asflgs_t	ai_flags;	/* Audit session flags. */
210184902Srwatson};
211184902Srwatsontypedef	struct auditinfo_addr	auditinfo_addr_t;
212184902Srwatson
213184902Srwatsonstruct auditpinfo {
214184902Srwatson	pid_t		ap_pid;		/* ID of target process. */
215184902Srwatson	au_id_t		ap_auid;	/* Audit user ID. */
216184902Srwatson	au_mask_t	ap_mask;	/* Audit masks. */
217184902Srwatson	au_tid_t	ap_termid;	/* Terminal ID. */
218184902Srwatson	au_asid_t	ap_asid;	/* Audit session ID. */
219184902Srwatson};
220184902Srwatsontypedef	struct auditpinfo	auditpinfo_t;
221184902Srwatson
222184902Srwatsonstruct auditpinfo_addr {
223184902Srwatson	pid_t		ap_pid;		/* ID of target process. */
224184902Srwatson	au_id_t		ap_auid;	/* Audit user ID. */
225184902Srwatson	au_mask_t	ap_mask;	/* Audit masks. */
226184902Srwatson	au_tid_addr_t	ap_termid;	/* Terminal ID. */
227184902Srwatson	au_asid_t	ap_asid;	/* Audit session ID. */
228195740Srwatson	au_asflgs_t	ap_flags;	/* Audit session flags. */
229184902Srwatson};
230184902Srwatsontypedef	struct auditpinfo_addr	auditpinfo_addr_t;
231184902Srwatson
232186647Srwatsonstruct au_session {
233186647Srwatson	auditinfo_addr_t	*as_aia_p;	/* Ptr to full audit info. */
234186647Srwatson	au_mask_t		 as_mask;	/* Process Audit Masks. */
235186647Srwatson};
236186647Srwatsontypedef struct au_session       au_session_t;
237186647Srwatson
238184902Srwatson/*
239184902Srwatson * Contents of token_t are opaque outside of libbsm.
240184902Srwatson */
241184902Srwatsontypedef	struct au_token	token_t;
242184902Srwatson
243184902Srwatson/*
244191273Srwatson * Kernel audit queue control parameters:
245191273Srwatson * 			Default:		Maximum:
246191273Srwatson * 	aq_hiwater:	AQ_HIWATER (100)	AQ_MAXHIGH (10000)
247191273Srwatson * 	aq_lowater:	AQ_LOWATER (10)		<aq_hiwater
248191273Srwatson * 	aq_bufsz:	AQ_BUFSZ (32767)	AQ_MAXBUFSZ (1048576)
249191273Srwatson * 	aq_delay:	20			20000 (not used)
250184902Srwatson */
251184902Srwatsonstruct au_qctrl {
252191273Srwatson	int	aq_hiwater;	/* Max # of audit recs in queue when */
253191273Srwatson				/* threads with new ARs get blocked. */
254191273Srwatson
255191273Srwatson	int	aq_lowater;	/* # of audit recs in queue when */
256191273Srwatson				/* blocked threads get unblocked. */
257191273Srwatson
258191273Srwatson	int	aq_bufsz;	/* Max size of audit record for audit(2). */
259191273Srwatson	int	aq_delay;	/* Queue delay (not used). */
260184902Srwatson	int	aq_minfree;	/* Minimum filesystem percent free space. */
261184902Srwatson};
262184902Srwatsontypedef	struct au_qctrl	au_qctrl_t;
263184902Srwatson
264184902Srwatson/*
265184902Srwatson * Structure for the audit statistics.
266184902Srwatson */
267184902Srwatsonstruct audit_stat {
268184902Srwatson	unsigned int	as_version;
269184902Srwatson	unsigned int	as_numevent;
270184902Srwatson	int		as_generated;
271184902Srwatson	int		as_nonattrib;
272184902Srwatson	int		as_kernel;
273184902Srwatson	int		as_audit;
274184902Srwatson	int		as_auditctl;
275184902Srwatson	int		as_enqueue;
276184902Srwatson	int		as_written;
277184902Srwatson	int		as_wblocked;
278184902Srwatson	int		as_rblocked;
279184902Srwatson	int		as_dropped;
280184902Srwatson	int		as_totalsize;
281184902Srwatson	unsigned int	as_memused;
282184902Srwatson};
283184902Srwatsontypedef	struct audit_stat	au_stat_t;
284184902Srwatson
285184902Srwatson/*
286184902Srwatson * Structure for the audit file statistics.
287184902Srwatson */
288184902Srwatsonstruct audit_fstat {
289187214Srwatson	u_int64_t	af_filesz;
290187214Srwatson	u_int64_t	af_currsz;
291184902Srwatson};
292184902Srwatsontypedef	struct audit_fstat	au_fstat_t;
293184902Srwatson
294184902Srwatson/*
295184902Srwatson * Audit to event class mapping.
296184902Srwatson */
297184902Srwatsonstruct au_evclass_map {
298184902Srwatson	au_event_t	ec_number;
299184902Srwatson	au_class_t	ec_class;
300184902Srwatson};
301184902Srwatsontypedef	struct au_evclass_map	au_evclass_map_t;
302184902Srwatson
303184902Srwatson/*
304184902Srwatson * Audit system calls.
305184902Srwatson */
306184902Srwatson#if !defined(_KERNEL) && !defined(KERNEL)
307184902Srwatsonint	audit(const void *, int);
308184902Srwatsonint	auditon(int, void *, int);
309184902Srwatsonint	auditctl(const char *);
310184902Srwatsonint	getauid(au_id_t *);
311184902Srwatsonint	setauid(const au_id_t *);
312184902Srwatsonint	getaudit(struct auditinfo *);
313184902Srwatsonint	setaudit(const struct auditinfo *);
314184902Srwatsonint	getaudit_addr(struct auditinfo_addr *, int);
315184902Srwatsonint	setaudit_addr(const struct auditinfo_addr *, int);
316191273Srwatson
317191273Srwatson#ifdef __APPLE_API_PRIVATE
318191273Srwatson#include <mach/port.h>
319191273Srwatsonmach_port_name_t audit_session_self(void);
320191273Srwatsonau_asid_t	 audit_session_join(mach_port_name_t port);
321191273Srwatson#endif /* __APPLE_API_PRIVATE */
322191273Srwatson
323184902Srwatson#endif /* defined(_KERNEL) || defined(KERNEL) */
324184902Srwatson
325184902Srwatson__END_DECLS
326184902Srwatson
327184902Srwatson#endif /* !_BSM_AUDIT_H */
328