audit_record.h revision 161635
1155191Srwatson/*
2155191Srwatson * Copyright (c) 2005 Apple Computer, Inc.
3155191Srwatson * All rights reserved.
4155191Srwatson *
5155191Srwatson * @APPLE_BSD_LICENSE_HEADER_START@
6155191Srwatson *
7155191Srwatson * Redistribution and use in source and binary forms, with or without
8155191Srwatson * modification, are permitted provided that the following conditions
9155191Srwatson * are met:
10155191Srwatson *
11155191Srwatson * 1.  Redistributions of source code must retain the above copyright
12155191Srwatson *     notice, this list of conditions and the following disclaimer.
13155191Srwatson * 2.  Redistributions in binary form must reproduce the above copyright
14155191Srwatson *     notice, this list of conditions and the following disclaimer in the
15155191Srwatson *     documentation and/or other materials provided with the distribution.
16155191Srwatson * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
17155191Srwatson *     its contributors may be used to endorse or promote products derived
18155191Srwatson *     from this software without specific prior written permission.
19155191Srwatson *
20155191Srwatson * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
21155191Srwatson * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22155191Srwatson * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23155191Srwatson * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
24155191Srwatson * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25155191Srwatson * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26155191Srwatson * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27155191Srwatson * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28155191Srwatson * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29155191Srwatson * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30155191Srwatson *
31155191Srwatson * @APPLE_BSD_LICENSE_HEADER_END@
32155191Srwatson *
33161635Srwatson * $P4: //depot/projects/trustedbsd/audit3/sys/bsm/audit_record.h#19 $
34155191Srwatson * $FreeBSD: head/sys/bsm/audit_record.h 161635 2006-08-26 08:17:58Z rwatson $
35155191Srwatson */
36155191Srwatson
37155191Srwatson#ifndef _BSM_AUDIT_RECORD_H_
38155191Srwatson#define _BSM_AUDIT_RECORD_H_
39155191Srwatson
40160084Srwatson#include <sys/time.h>			/* struct timeval */
41160084Srwatson
42155191Srwatson/*
43159257Srwatson * Token type identifiers.
44155191Srwatson */
45155191Srwatson#define	AUT_INVALID		0x00
46155191Srwatson#define	AUT_OTHER_FILE32	0x11
47155191Srwatson#define	AUT_OHEADER		0x12
48155191Srwatson#define	AUT_TRAILER		0x13
49155191Srwatson#define	AUT_HEADER32		0x14
50155191Srwatson#define	AUT_HEADER32_EX		0x15
51155191Srwatson#define	AUT_DATA		0x21
52155191Srwatson#define	AUT_IPC			0x22
53155191Srwatson#define	AUT_PATH		0x23
54155191Srwatson#define	AUT_SUBJECT32		0x24
55155191Srwatson#define	AUT_SERVER32		0x25
56155191Srwatson#define	AUT_PROCESS32		0x26
57155191Srwatson#define	AUT_RETURN32		0x27
58155191Srwatson#define	AUT_TEXT		0x28
59155191Srwatson#define	AUT_OPAQUE		0x29
60155191Srwatson#define	AUT_IN_ADDR		0x2a
61155191Srwatson#define	AUT_IP			0x2b
62155191Srwatson#define	AUT_IPORT		0x2c
63155191Srwatson#define	AUT_ARG32		0x2d
64155191Srwatson#define	AUT_SOCKET		0x2e
65155191Srwatson#define	AUT_SEQ			0x2f
66155191Srwatson#define	AUT_ACL			0x30
67155191Srwatson#define	AUT_ATTR		0x31
68155191Srwatson#define	AUT_IPC_PERM		0x32
69155191Srwatson#define	AUT_LABEL		0x33
70155191Srwatson#define	AUT_GROUPS		0x34
71155191Srwatson#define	AUT_ILABEL		0x35
72155191Srwatson#define	AUT_SLABEL		0x36
73155191Srwatson#define	AUT_CLEAR		0x37
74155191Srwatson#define	AUT_PRIV		0x38
75155191Srwatson#define	AUT_UPRIV		0x39
76155191Srwatson#define	AUT_LIAISON		0x3a
77155191Srwatson#define	AUT_NEWGROUPS		0x3b
78155191Srwatson#define	AUT_EXEC_ARGS		0x3c
79155191Srwatson#define	AUT_EXEC_ENV		0x3d
80155191Srwatson#define	AUT_ATTR32		0x3e
81155191Srwatson/* #define	AUT_????	0x3f */
82155191Srwatson#define	AUT_XATOM		0x40
83155191Srwatson#define	AUT_XOBJ		0x41
84155191Srwatson#define	AUT_XPROTO		0x42
85155191Srwatson#define	AUT_XSELECT		0x43
86155191Srwatson/* XXXRW: Additional X11 tokens not defined? */
87155191Srwatson#define	AUT_CMD			0x51
88155191Srwatson#define	AUT_EXIT		0x52
89155191Srwatson/* XXXRW: OpenBSM AUT_HOST 0x70? */
90155191Srwatson#define	AUT_ARG64		0x71
91155191Srwatson#define	AUT_RETURN64		0x72
92155191Srwatson#define	AUT_ATTR64		0x73
93155191Srwatson#define	AUT_HEADER64		0x74
94155191Srwatson#define	AUT_SUBJECT64		0x75
95155191Srwatson#define	AUT_SERVER64		0x76
96155191Srwatson#define	AUT_PROCESS64		0x77
97155191Srwatson#define	AUT_OTHER_FILE64	0x78
98155191Srwatson#define	AUT_HEADER64_EX		0x79
99155191Srwatson#define	AUT_SUBJECT32_EX	0x7a
100155191Srwatson#define	AUT_PROCESS32_EX	0x7b
101155191Srwatson#define	AUT_SUBJECT64_EX	0x7c
102155191Srwatson#define	AUT_PROCESS64_EX	0x7d
103155191Srwatson#define	AUT_IN_ADDR_EX		0x7e
104155191Srwatson#define	AUT_SOCKET_EX		0x7f
105155191Srwatson
106155191Srwatson/*
107155191Srwatson * Pre-64-bit BSM, 32-bit tokens weren't explicitly named as '32'.  We have
108155191Srwatson * compatibility defines.
109155191Srwatson */
110155191Srwatson#define	AUT_HEADER		AUT_HEADER32
111155191Srwatson#define	AUT_ARG			AUT_ARG32
112155191Srwatson#define	AUT_RETURN		AUT_RETURN32
113155191Srwatson#define	AUT_SUBJECT		AUT_SUBJECT32
114155191Srwatson#define	AUT_SERVER		AUT_SERVER32
115155191Srwatson#define	AUT_PROCESS		AUT_PROCESS32
116155191Srwatson#define	AUT_OTHER_FILE		AUT_OTHER_FILE32
117155191Srwatson
118155191Srwatson/*
119155191Srwatson * Darwin's bsm distribution uses the following non-BSM token name defines.
120155191Srwatson * We provide them for a single OpenBSM release for compatibility reasons.
121155191Srwatson */
122155191Srwatson#define	AU_FILE_TOKEN		AUT_OTHER_FILE32
123155191Srwatson#define	AU_TRAILER_TOKEN	AUT_TRAILER
124155191Srwatson#define	AU_HEADER_32_TOKEN	AUT_HEADER32
125155191Srwatson#define	AU_DATA_TOKEN		AUT_DATA
126155191Srwatson#define	AU_ARB_TOKEN		AUT_DATA
127155191Srwatson#define	AU_IPC_TOKEN		AUT_IPC
128155191Srwatson#define	AU_PATH_TOKEN		AUT_PATH
129155191Srwatson#define	AU_SUBJECT_32_TOKEN	AUT_SUBJECT32
130155191Srwatson#define	AU_PROCESS_32_TOKEN	AUT_PROCESS32
131155191Srwatson#define	AU_RETURN_32_TOKEN	AUT_RETURN32
132155191Srwatson#define	AU_TEXT_TOKEN		AUT_TEXT
133155191Srwatson#define	AU_OPAQUE_TOKEN		AUT_OPAQUE
134155191Srwatson#define	AU_IN_ADDR_TOKEN	AUT_IN_ADDR
135155191Srwatson#define	AU_IP_TOKEN		AUT_IP
136155191Srwatson#define	AU_IPORT_TOKEN		AUT_IPORT
137155191Srwatson#define	AU_ARG32_TOKEN		AUT_ARG32
138155191Srwatson#define	AU_SOCK_TOKEN		AUT_SOCKET
139155191Srwatson#define	AU_SEQ_TOKEN		AUT_SEQ
140155191Srwatson#define	AU_ATTR_TOKEN		AUT_ATTR
141155191Srwatson#define	AU_IPCPERM_TOKEN	AUT_IPC_PERM
142155191Srwatson#define	AU_NEWGROUPS_TOKEN	AUT_NEWGROUPS
143155191Srwatson#define	AU_EXEC_ARG_TOKEN	AUT_EXEC_ARGS
144155191Srwatson#define	AU_EXEC_ENV_TOKEN	AUT_EXEC_ENV
145155191Srwatson#define	AU_ATTR32_TOKEN		AUT_ATTR32
146155191Srwatson#define	AU_CMD_TOKEN		AUT_CMD
147155191Srwatson#define	AU_EXIT_TOKEN		AUT_EXIT
148155191Srwatson#define	AU_ARG64_TOKEN		AUT_ARG64
149155191Srwatson#define	AU_RETURN_64_TOKEN	AUT_RETURN64
150155191Srwatson#define	AU_ATTR64_TOKEN		AUT_ATTR64
151155191Srwatson#define	AU_HEADER_64_TOKEN	AUT_HEADER64
152155191Srwatson#define	AU_SUBJECT_64_TOKEN	AUT_SUBJECT64
153155191Srwatson#define	AU_PROCESS_64_TOKEN	AUT_PROCESS64
154155191Srwatson#define	AU_HEADER_64_EX_TOKEN	AUT_HEADER64_EX
155155191Srwatson#define	AU_SUBJECT_32_EX_TOKEN	AUT_SUBJECT32_EX
156155191Srwatson#define	AU_PROCESS_32_EX_TOKEN	AUT_PROCESS32_EX
157155191Srwatson#define	AU_SUBJECT_64_EX_TOKEN	AUT_SUBJECT64_EX
158155191Srwatson#define	AU_PROCESS_64_EX_TOKEN	AUT_PROCESS64_EX
159155191Srwatson#define	AU_IN_ADDR_EX_TOKEN	AUT_IN_ADDR_EX
160155191Srwatson#define	AU_SOCK_32_EX_TOKEN	AUT_SOCKET_EX
161155191Srwatson
162155191Srwatson/*
163155191Srwatson * The values for the following token ids are not defined by BSM.
164155191Srwatson *
165155191Srwatson * XXXRW: Not sure how to handle these in OpenBSM yet, but I'll give them
166155191Srwatson * names more consistent with Sun's BSM.  These originally came from Apple's
167155191Srwatson * BSM.
168155191Srwatson */
169155191Srwatson#define	AUT_SOCKINET32		0x80		/* XXX */
170155191Srwatson#define	AUT_SOCKINET128		0x81		/* XXX */
171155191Srwatson#define	AUT_SOCKUNIX		0x82		/* XXX */
172155191Srwatson#define	AU_SOCK_INET_32_TOKEN	AUT_SOCKINET32
173155191Srwatson#define	AU_SOCK_INET_128_TOKEN	AUT_SOCKINET128
174155191Srwatson#define	AU_SOCK_UNIX_TOKEN	AUT_SOCKUNIX
175155191Srwatson
176155191Srwatson/* print values for the arbitrary token */
177155191Srwatson#define AUP_BINARY      0
178155191Srwatson#define AUP_OCTAL       1
179155191Srwatson#define AUP_DECIMAL     2
180155191Srwatson#define AUP_HEX         3
181155191Srwatson#define AUP_STRING      4
182155191Srwatson
183155191Srwatson/* data-types for the arbitrary token */
184155191Srwatson#define AUR_BYTE        0
185159257Srwatson#define AUR_CHAR        AUR_BYTE
186155191Srwatson#define AUR_SHORT       1
187159257Srwatson#define AUR_INT32       2
188161635Srwatson#define AUR_INT         AUR_INT32
189159257Srwatson#define AUR_INT64       3
190155191Srwatson
191155191Srwatson/* ... and their sizes */
192155191Srwatson#define AUR_BYTE_SIZE       sizeof(u_char)
193159257Srwatson#define AUR_CHAR_SIZE       AUR_BYTE_SIZE
194155191Srwatson#define AUR_SHORT_SIZE      sizeof(uint16_t)
195159257Srwatson#define AUR_INT32_SIZE      sizeof(uint32_t)
196159257Srwatson#define AUR_INT_SIZE        AUR_INT32_SIZE
197159257Srwatson#define AUR_INT64_SIZE      sizeof(uint64_t)
198155191Srwatson
199155191Srwatson/* Modifiers for the header token */
200155191Srwatson#define PAD_NOTATTR  0x4000   /* nonattributable event */
201155191Srwatson#define PAD_FAILURE  0x8000   /* fail audit event */
202155191Srwatson
203161635Srwatson#define AUDIT_MAX_GROUPS      16
204155191Srwatson
205161635Srwatson/*
206161635Srwatson * A number of BSM versions are floating around and defined.  Here are
207161635Srwatson * constants for them.  OpenBSM uses the same token types, etc, used in the
208161635Srwatson * Solaris BSM version, but has a separate version number in order to
209161635Srwatson * identify a potentially different event identifier name space.
210161635Srwatson */
211161635Srwatson#define	AUDIT_HEADER_VERSION_OLDDARWIN	1	/* In retrospect, a mistake. */
212161635Srwatson#define	AUDIT_HEADER_VERSION_SOLARIS	2
213161635Srwatson#define	AUDIT_HEADER_VERSION_TSOL25	3
214161635Srwatson#define	AUDIT_HEADER_VERSION_TSOL	4
215161635Srwatson#define	AUDIT_HEADER_VERSION_OPENBSM	10
216155191Srwatson
217155191Srwatson/*
218155191Srwatson * BSM define is AUT_TRAILER_MAGIC; Apple BSM define is TRAILER_PAD_MAGIC; we
219155191Srwatson * split the difference, will remove the Apple define for the next release.
220155191Srwatson */
221155191Srwatson#define	AUT_TRAILER_MAGIC	0xb105
222155191Srwatson#define	TRAILER_PAD_MAGIC	AUT_TRAILER_MAGIC
223155191Srwatson
224155191Srwatson/* BSM library calls */
225155191Srwatson
226155191Srwatson__BEGIN_DECLS
227155191Srwatson
228155191Srwatsonstruct in_addr;
229155191Srwatsonstruct in6_addr;
230155191Srwatsonstruct ip;
231155191Srwatsonstruct ipc_perm;
232155191Srwatsonstruct kevent;
233155191Srwatsonstruct sockaddr_in;
234155191Srwatsonstruct sockaddr_in6;
235155191Srwatsonstruct sockaddr_un;
236155191Srwatson#if defined(_KERNEL) || defined(KERNEL)
237155191Srwatsonstruct vnode_au_info;
238155191Srwatson#endif
239155191Srwatson
240155191Srwatsonint	 au_open(void);
241155191Srwatsonint	 au_write(int d, token_t *m);
242155191Srwatsonint	 au_close(int d, int keep, short event);
243155191Srwatsonint	 au_close_buffer(int d, short event, u_char *buffer, size_t *buflen);
244159257Srwatsonint	 au_close_token(token_t *tok, u_char *buffer, size_t *buflen);
245155191Srwatson
246155191Srwatsontoken_t	*au_to_file(char *file, struct timeval tm);
247155191Srwatson
248159257Srwatsontoken_t	*au_to_header32_tm(int rec_size, au_event_t e_type, au_emod_t e_mod,
249155191Srwatson	    struct timeval tm);
250159257Srwatson#if !defined(KERNEL) && !defined(_KERNEL)
251155191Srwatsontoken_t	*au_to_header(int rec_size, au_event_t e_type, au_emod_t e_mod);
252155191Srwatsontoken_t	*au_to_header32(int rec_size, au_event_t e_type, au_emod_t e_mod);
253159257Srwatsontoken_t	*au_to_header64(int rec_size, au_event_t e_type, au_emod_t e_mod);
254155191Srwatson#endif
255155191Srwatson
256155191Srwatsontoken_t	*au_to_me(void);
257155191Srwatsontoken_t	*au_to_arg(char n, char *text, uint32_t v);
258155191Srwatsontoken_t	*au_to_arg32(char n, char *text, uint32_t v);
259155191Srwatsontoken_t	*au_to_arg64(char n, char *text, uint64_t v);
260155191Srwatson
261155191Srwatson#if defined(_KERNEL) || defined(KERNEL)
262155191Srwatsontoken_t	*au_to_attr(struct vnode_au_info *vni);
263155191Srwatsontoken_t	*au_to_attr32(struct vnode_au_info *vni);
264155191Srwatsontoken_t	*au_to_attr64(struct vnode_au_info *vni);
265155191Srwatson#endif
266155191Srwatson
267155191Srwatsontoken_t	*au_to_data(char unit_print, char unit_type, char unit_count,
268155191Srwatson	    char *p);
269155191Srwatsontoken_t	*au_to_exit(int retval, int err);
270155191Srwatsontoken_t	*au_to_groups(int *groups);
271155191Srwatsontoken_t	*au_to_newgroups(uint16_t n, gid_t *groups);
272155191Srwatsontoken_t	*au_to_in_addr(struct in_addr *internet_addr);
273155191Srwatsontoken_t	*au_to_in_addr_ex(struct in6_addr *internet_addr);
274155191Srwatsontoken_t	*au_to_ip(struct ip *ip);
275155191Srwatsontoken_t	*au_to_ipc(char type, int id);
276155191Srwatsontoken_t	*au_to_ipc_perm(struct ipc_perm *perm);
277155191Srwatsontoken_t	*au_to_iport(uint16_t iport);
278155191Srwatsontoken_t	*au_to_opaque(char *data, uint16_t bytes);
279155191Srwatsontoken_t	*au_to_path(char *path);
280155191Srwatsontoken_t	*au_to_process(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
281155191Srwatson	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid);
282155191Srwatsontoken_t	*au_to_process32(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
283155191Srwatson	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid);
284155191Srwatsontoken_t	*au_to_process64(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
285155191Srwatson	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid);
286155191Srwatsontoken_t	*au_to_process_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
287155191Srwatson	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_addr_t *tid);
288155191Srwatsontoken_t	*au_to_process32_ex(au_id_t auid, uid_t euid, gid_t egid,
289155191Srwatson	    uid_t ruid, gid_t rgid, pid_t pid, au_asid_t sid,
290155191Srwatson	    au_tid_addr_t *tid);
291155191Srwatsontoken_t	*au_to_process64_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
292155191Srwatson	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_addr_t *tid);
293155191Srwatsontoken_t	*au_to_return(char status, uint32_t ret);
294155191Srwatsontoken_t	*au_to_return32(char status, uint32_t ret);
295155191Srwatsontoken_t	*au_to_return64(char status, uint64_t ret);
296155191Srwatsontoken_t	*au_to_seq(long audit_count);
297155191Srwatson
298155191Srwatson#if defined(_KERNEL) || defined(KERNEL)
299155191Srwatsontoken_t	*au_to_socket(struct socket *so);
300155191Srwatsontoken_t	*au_to_socket_ex_32(uint16_t lp, uint16_t rp, struct sockaddr *la,
301155191Srwatson	    struct sockaddr *ta);
302155191Srwatsontoken_t	*au_to_socket_ex_128(uint16_t lp, uint16_t rp, struct sockaddr *la,
303155191Srwatson	    struct sockaddr *ta);
304155191Srwatson#endif
305155191Srwatson
306155191Srwatsontoken_t	*au_to_sock_inet(struct sockaddr_in *so);
307155191Srwatsontoken_t	*au_to_sock_inet32(struct sockaddr_in *so);
308155191Srwatsontoken_t	*au_to_sock_inet128(struct sockaddr_in6 *so);
309155191Srwatsontoken_t	*au_to_sock_unix(struct sockaddr_un *so);
310155191Srwatsontoken_t	*au_to_subject(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
311155191Srwatson	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid);
312155191Srwatsontoken_t	*au_to_subject32(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
313155191Srwatson	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid);
314155191Srwatsontoken_t	*au_to_subject64(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
315155191Srwatson	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid);
316155191Srwatsontoken_t	*au_to_subject_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
317155191Srwatson	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_addr_t *tid);
318155191Srwatsontoken_t	*au_to_subject32_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
319155191Srwatson	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_addr_t *tid);
320155191Srwatsontoken_t	*au_to_subject64_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
321155191Srwatson	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_addr_t *tid);
322155191Srwatsontoken_t	*au_to_exec_args(const char **);
323155191Srwatsontoken_t	*au_to_exec_env(const char **);
324155191Srwatsontoken_t	*au_to_text(char *text);
325155191Srwatsontoken_t	*au_to_kevent(struct kevent *kev);
326155191Srwatsontoken_t	*au_to_trailer(int rec_size);
327155191Srwatson
328155191Srwatson__END_DECLS
329155191Srwatson
330155191Srwatson#endif /* ! _BSM_AUDIT_RECORD_H_ */
331