audit_record.h revision 159257
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 *
33159257Srwatson * $P4: //depot/projects/trustedbsd/audit3/sys/bsm/audit_record.h#13 $
34155191Srwatson * $FreeBSD: head/sys/bsm/audit_record.h 159257 2006-06-05 13:00:52Z rwatson $
35155191Srwatson */
36155191Srwatson
37155191Srwatson#ifndef _BSM_AUDIT_RECORD_H_
38155191Srwatson#define _BSM_AUDIT_RECORD_H_
39155191Srwatson
40155191Srwatson/*
41159257Srwatson * Token type identifiers.
42155191Srwatson */
43155191Srwatson#define	AUT_INVALID		0x00
44155191Srwatson#define	AUT_OTHER_FILE32	0x11
45155191Srwatson#define	AUT_OHEADER		0x12
46155191Srwatson#define	AUT_TRAILER		0x13
47155191Srwatson#define	AUT_HEADER32		0x14
48155191Srwatson#define	AUT_HEADER32_EX		0x15
49155191Srwatson#define	AUT_DATA		0x21
50155191Srwatson#define	AUT_IPC			0x22
51155191Srwatson#define	AUT_PATH		0x23
52155191Srwatson#define	AUT_SUBJECT32		0x24
53155191Srwatson#define	AUT_SERVER32		0x25
54155191Srwatson#define	AUT_PROCESS32		0x26
55155191Srwatson#define	AUT_RETURN32		0x27
56155191Srwatson#define	AUT_TEXT		0x28
57155191Srwatson#define	AUT_OPAQUE		0x29
58155191Srwatson#define	AUT_IN_ADDR		0x2a
59155191Srwatson#define	AUT_IP			0x2b
60155191Srwatson#define	AUT_IPORT		0x2c
61155191Srwatson#define	AUT_ARG32		0x2d
62155191Srwatson#define	AUT_SOCKET		0x2e
63155191Srwatson#define	AUT_SEQ			0x2f
64155191Srwatson#define	AUT_ACL			0x30
65155191Srwatson#define	AUT_ATTR		0x31
66155191Srwatson#define	AUT_IPC_PERM		0x32
67155191Srwatson#define	AUT_LABEL		0x33
68155191Srwatson#define	AUT_GROUPS		0x34
69155191Srwatson#define	AUT_ILABEL		0x35
70155191Srwatson#define	AUT_SLABEL		0x36
71155191Srwatson#define	AUT_CLEAR		0x37
72155191Srwatson#define	AUT_PRIV		0x38
73155191Srwatson#define	AUT_UPRIV		0x39
74155191Srwatson#define	AUT_LIAISON		0x3a
75155191Srwatson#define	AUT_NEWGROUPS		0x3b
76155191Srwatson#define	AUT_EXEC_ARGS		0x3c
77155191Srwatson#define	AUT_EXEC_ENV		0x3d
78155191Srwatson#define	AUT_ATTR32		0x3e
79155191Srwatson/* #define	AUT_????	0x3f */
80155191Srwatson#define	AUT_XATOM		0x40
81155191Srwatson#define	AUT_XOBJ		0x41
82155191Srwatson#define	AUT_XPROTO		0x42
83155191Srwatson#define	AUT_XSELECT		0x43
84155191Srwatson/* XXXRW: Additional X11 tokens not defined? */
85155191Srwatson#define	AUT_CMD			0x51
86155191Srwatson#define	AUT_EXIT		0x52
87155191Srwatson/* XXXRW: OpenBSM AUT_HOST 0x70? */
88155191Srwatson#define	AUT_ARG64		0x71
89155191Srwatson#define	AUT_RETURN64		0x72
90155191Srwatson#define	AUT_ATTR64		0x73
91155191Srwatson#define	AUT_HEADER64		0x74
92155191Srwatson#define	AUT_SUBJECT64		0x75
93155191Srwatson#define	AUT_SERVER64		0x76
94155191Srwatson#define	AUT_PROCESS64		0x77
95155191Srwatson#define	AUT_OTHER_FILE64	0x78
96155191Srwatson#define	AUT_HEADER64_EX		0x79
97155191Srwatson#define	AUT_SUBJECT32_EX	0x7a
98155191Srwatson#define	AUT_PROCESS32_EX	0x7b
99155191Srwatson#define	AUT_SUBJECT64_EX	0x7c
100155191Srwatson#define	AUT_PROCESS64_EX	0x7d
101155191Srwatson#define	AUT_IN_ADDR_EX		0x7e
102155191Srwatson#define	AUT_SOCKET_EX		0x7f
103155191Srwatson
104155191Srwatson/*
105155191Srwatson * Pre-64-bit BSM, 32-bit tokens weren't explicitly named as '32'.  We have
106155191Srwatson * compatibility defines.
107155191Srwatson */
108155191Srwatson#define	AUT_HEADER		AUT_HEADER32
109155191Srwatson#define	AUT_ARG			AUT_ARG32
110155191Srwatson#define	AUT_RETURN		AUT_RETURN32
111155191Srwatson#define	AUT_SUBJECT		AUT_SUBJECT32
112155191Srwatson#define	AUT_SERVER		AUT_SERVER32
113155191Srwatson#define	AUT_PROCESS		AUT_PROCESS32
114155191Srwatson#define	AUT_OTHER_FILE		AUT_OTHER_FILE32
115155191Srwatson
116155191Srwatson/*
117155191Srwatson * Darwin's bsm distribution uses the following non-BSM token name defines.
118155191Srwatson * We provide them for a single OpenBSM release for compatibility reasons.
119155191Srwatson */
120155191Srwatson#define	AU_FILE_TOKEN		AUT_OTHER_FILE32
121155191Srwatson#define	AU_TRAILER_TOKEN	AUT_TRAILER
122155191Srwatson#define	AU_HEADER_32_TOKEN	AUT_HEADER32
123155191Srwatson#define	AU_DATA_TOKEN		AUT_DATA
124155191Srwatson#define	AU_ARB_TOKEN		AUT_DATA
125155191Srwatson#define	AU_IPC_TOKEN		AUT_IPC
126155191Srwatson#define	AU_PATH_TOKEN		AUT_PATH
127155191Srwatson#define	AU_SUBJECT_32_TOKEN	AUT_SUBJECT32
128155191Srwatson#define	AU_PROCESS_32_TOKEN	AUT_PROCESS32
129155191Srwatson#define	AU_RETURN_32_TOKEN	AUT_RETURN32
130155191Srwatson#define	AU_TEXT_TOKEN		AUT_TEXT
131155191Srwatson#define	AU_OPAQUE_TOKEN		AUT_OPAQUE
132155191Srwatson#define	AU_IN_ADDR_TOKEN	AUT_IN_ADDR
133155191Srwatson#define	AU_IP_TOKEN		AUT_IP
134155191Srwatson#define	AU_IPORT_TOKEN		AUT_IPORT
135155191Srwatson#define	AU_ARG32_TOKEN		AUT_ARG32
136155191Srwatson#define	AU_SOCK_TOKEN		AUT_SOCKET
137155191Srwatson#define	AU_SEQ_TOKEN		AUT_SEQ
138155191Srwatson#define	AU_ATTR_TOKEN		AUT_ATTR
139155191Srwatson#define	AU_IPCPERM_TOKEN	AUT_IPC_PERM
140155191Srwatson#define	AU_NEWGROUPS_TOKEN	AUT_NEWGROUPS
141155191Srwatson#define	AU_EXEC_ARG_TOKEN	AUT_EXEC_ARGS
142155191Srwatson#define	AU_EXEC_ENV_TOKEN	AUT_EXEC_ENV
143155191Srwatson#define	AU_ATTR32_TOKEN		AUT_ATTR32
144155191Srwatson#define	AU_CMD_TOKEN		AUT_CMD
145155191Srwatson#define	AU_EXIT_TOKEN		AUT_EXIT
146155191Srwatson#define	AU_ARG64_TOKEN		AUT_ARG64
147155191Srwatson#define	AU_RETURN_64_TOKEN	AUT_RETURN64
148155191Srwatson#define	AU_ATTR64_TOKEN		AUT_ATTR64
149155191Srwatson#define	AU_HEADER_64_TOKEN	AUT_HEADER64
150155191Srwatson#define	AU_SUBJECT_64_TOKEN	AUT_SUBJECT64
151155191Srwatson#define	AU_PROCESS_64_TOKEN	AUT_PROCESS64
152155191Srwatson#define	AU_HEADER_64_EX_TOKEN	AUT_HEADER64_EX
153155191Srwatson#define	AU_SUBJECT_32_EX_TOKEN	AUT_SUBJECT32_EX
154155191Srwatson#define	AU_PROCESS_32_EX_TOKEN	AUT_PROCESS32_EX
155155191Srwatson#define	AU_SUBJECT_64_EX_TOKEN	AUT_SUBJECT64_EX
156155191Srwatson#define	AU_PROCESS_64_EX_TOKEN	AUT_PROCESS64_EX
157155191Srwatson#define	AU_IN_ADDR_EX_TOKEN	AUT_IN_ADDR_EX
158155191Srwatson#define	AU_SOCK_32_EX_TOKEN	AUT_SOCKET_EX
159155191Srwatson
160155191Srwatson/*
161155191Srwatson * The values for the following token ids are not defined by BSM.
162155191Srwatson *
163155191Srwatson * XXXRW: Not sure how to handle these in OpenBSM yet, but I'll give them
164155191Srwatson * names more consistent with Sun's BSM.  These originally came from Apple's
165155191Srwatson * BSM.
166155191Srwatson */
167155191Srwatson#define	AUT_SOCKINET32		0x80		/* XXX */
168155191Srwatson#define	AUT_SOCKINET128		0x81		/* XXX */
169155191Srwatson#define	AUT_SOCKUNIX		0x82		/* XXX */
170155191Srwatson#define	AU_SOCK_INET_32_TOKEN	AUT_SOCKINET32
171155191Srwatson#define	AU_SOCK_INET_128_TOKEN	AUT_SOCKINET128
172155191Srwatson#define	AU_SOCK_UNIX_TOKEN	AUT_SOCKUNIX
173155191Srwatson
174155191Srwatson/* print values for the arbitrary token */
175155191Srwatson#define AUP_BINARY      0
176155191Srwatson#define AUP_OCTAL       1
177155191Srwatson#define AUP_DECIMAL     2
178155191Srwatson#define AUP_HEX         3
179155191Srwatson#define AUP_STRING      4
180155191Srwatson
181155191Srwatson/* data-types for the arbitrary token */
182155191Srwatson#define AUR_BYTE        0
183159257Srwatson#define AUR_CHAR        AUR_BYTE
184155191Srwatson#define AUR_SHORT       1
185159257Srwatson#define AUR_INT32       2
186159257Srwatson#define AUR_INT         AUR_INT
187159257Srwatson#define AUR_INT64       3
188155191Srwatson
189155191Srwatson/* ... and their sizes */
190155191Srwatson#define AUR_BYTE_SIZE       sizeof(u_char)
191159257Srwatson#define AUR_CHAR_SIZE       AUR_BYTE_SIZE
192155191Srwatson#define AUR_SHORT_SIZE      sizeof(uint16_t)
193159257Srwatson#define AUR_INT32_SIZE      sizeof(uint32_t)
194159257Srwatson#define AUR_INT_SIZE        AUR_INT32_SIZE
195159257Srwatson#define AUR_INT64_SIZE      sizeof(uint64_t)
196155191Srwatson
197155191Srwatson/* Modifiers for the header token */
198155191Srwatson#define PAD_NOTATTR  0x4000   /* nonattributable event */
199155191Srwatson#define PAD_FAILURE  0x8000   /* fail audit event */
200155191Srwatson
201155191Srwatson
202155191Srwatson#define BSM_MAX_GROUPS      16
203155191Srwatson#define HEADER_VERSION      1
204155191Srwatson
205155191Srwatson/*
206155191Srwatson * BSM define is AUT_TRAILER_MAGIC; Apple BSM define is TRAILER_PAD_MAGIC; we
207155191Srwatson * split the difference, will remove the Apple define for the next release.
208155191Srwatson */
209155191Srwatson#define	AUT_TRAILER_MAGIC	0xb105
210155191Srwatson#define	TRAILER_PAD_MAGIC	AUT_TRAILER_MAGIC
211155191Srwatson
212155191Srwatson/* BSM library calls */
213155191Srwatson
214155191Srwatson__BEGIN_DECLS
215155191Srwatson
216155191Srwatsonstruct in_addr;
217155191Srwatsonstruct in6_addr;
218155191Srwatsonstruct ip;
219155191Srwatsonstruct ipc_perm;
220155191Srwatsonstruct kevent;
221155191Srwatsonstruct sockaddr_in;
222155191Srwatsonstruct sockaddr_in6;
223155191Srwatsonstruct sockaddr_un;
224155191Srwatson#if defined(_KERNEL) || defined(KERNEL)
225155191Srwatsonstruct vnode_au_info;
226155191Srwatson#endif
227155191Srwatson
228155191Srwatsonint	 au_open(void);
229155191Srwatsonint	 au_write(int d, token_t *m);
230155191Srwatsonint	 au_close(int d, int keep, short event);
231155191Srwatsonint	 au_close_buffer(int d, short event, u_char *buffer, size_t *buflen);
232159257Srwatsonint	 au_close_token(token_t *tok, u_char *buffer, size_t *buflen);
233155191Srwatson
234155191Srwatsontoken_t	*au_to_file(char *file, struct timeval tm);
235155191Srwatson
236159257Srwatsontoken_t	*au_to_header32_tm(int rec_size, au_event_t e_type, au_emod_t e_mod,
237155191Srwatson	    struct timeval tm);
238159257Srwatson#if !defined(KERNEL) && !defined(_KERNEL)
239155191Srwatsontoken_t	*au_to_header(int rec_size, au_event_t e_type, au_emod_t e_mod);
240155191Srwatsontoken_t	*au_to_header32(int rec_size, au_event_t e_type, au_emod_t e_mod);
241159257Srwatsontoken_t	*au_to_header64(int rec_size, au_event_t e_type, au_emod_t e_mod);
242155191Srwatson#endif
243155191Srwatson
244155191Srwatsontoken_t	*au_to_me(void);
245155191Srwatsontoken_t	*au_to_arg(char n, char *text, uint32_t v);
246155191Srwatsontoken_t	*au_to_arg32(char n, char *text, uint32_t v);
247155191Srwatsontoken_t	*au_to_arg64(char n, char *text, uint64_t v);
248155191Srwatson
249155191Srwatson#if defined(_KERNEL) || defined(KERNEL)
250155191Srwatsontoken_t	*au_to_attr(struct vnode_au_info *vni);
251155191Srwatsontoken_t	*au_to_attr32(struct vnode_au_info *vni);
252155191Srwatsontoken_t	*au_to_attr64(struct vnode_au_info *vni);
253155191Srwatson#endif
254155191Srwatson
255155191Srwatsontoken_t	*au_to_data(char unit_print, char unit_type, char unit_count,
256155191Srwatson	    char *p);
257155191Srwatsontoken_t	*au_to_exit(int retval, int err);
258155191Srwatsontoken_t	*au_to_groups(int *groups);
259155191Srwatsontoken_t	*au_to_newgroups(uint16_t n, gid_t *groups);
260155191Srwatsontoken_t	*au_to_in_addr(struct in_addr *internet_addr);
261155191Srwatsontoken_t	*au_to_in_addr_ex(struct in6_addr *internet_addr);
262155191Srwatsontoken_t	*au_to_ip(struct ip *ip);
263155191Srwatsontoken_t	*au_to_ipc(char type, int id);
264155191Srwatsontoken_t	*au_to_ipc_perm(struct ipc_perm *perm);
265155191Srwatsontoken_t	*au_to_iport(uint16_t iport);
266155191Srwatsontoken_t	*au_to_opaque(char *data, uint16_t bytes);
267155191Srwatsontoken_t	*au_to_path(char *path);
268155191Srwatsontoken_t	*au_to_process(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
269155191Srwatson	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid);
270155191Srwatsontoken_t	*au_to_process32(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
271155191Srwatson	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid);
272155191Srwatsontoken_t	*au_to_process64(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
273155191Srwatson	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid);
274155191Srwatsontoken_t	*au_to_process_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
275155191Srwatson	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_addr_t *tid);
276155191Srwatsontoken_t	*au_to_process32_ex(au_id_t auid, uid_t euid, gid_t egid,
277155191Srwatson	    uid_t ruid, gid_t rgid, pid_t pid, au_asid_t sid,
278155191Srwatson	    au_tid_addr_t *tid);
279155191Srwatsontoken_t	*au_to_process64_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
280155191Srwatson	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_addr_t *tid);
281155191Srwatsontoken_t	*au_to_return(char status, uint32_t ret);
282155191Srwatsontoken_t	*au_to_return32(char status, uint32_t ret);
283155191Srwatsontoken_t	*au_to_return64(char status, uint64_t ret);
284155191Srwatsontoken_t	*au_to_seq(long audit_count);
285155191Srwatson
286155191Srwatson#if defined(_KERNEL) || defined(KERNEL)
287155191Srwatsontoken_t	*au_to_socket(struct socket *so);
288155191Srwatsontoken_t	*au_to_socket_ex_32(uint16_t lp, uint16_t rp, struct sockaddr *la,
289155191Srwatson	    struct sockaddr *ta);
290155191Srwatsontoken_t	*au_to_socket_ex_128(uint16_t lp, uint16_t rp, struct sockaddr *la,
291155191Srwatson	    struct sockaddr *ta);
292155191Srwatson#endif
293155191Srwatson
294155191Srwatsontoken_t	*au_to_sock_inet(struct sockaddr_in *so);
295155191Srwatsontoken_t	*au_to_sock_inet32(struct sockaddr_in *so);
296155191Srwatsontoken_t	*au_to_sock_inet128(struct sockaddr_in6 *so);
297155191Srwatsontoken_t	*au_to_sock_unix(struct sockaddr_un *so);
298155191Srwatsontoken_t	*au_to_subject(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
299155191Srwatson	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid);
300155191Srwatsontoken_t	*au_to_subject32(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
301155191Srwatson	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid);
302155191Srwatsontoken_t	*au_to_subject64(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
303155191Srwatson	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid);
304155191Srwatsontoken_t	*au_to_subject_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
305155191Srwatson	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_addr_t *tid);
306155191Srwatsontoken_t	*au_to_subject32_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
307155191Srwatson	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_addr_t *tid);
308155191Srwatsontoken_t	*au_to_subject64_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
309155191Srwatson	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_addr_t *tid);
310155191Srwatsontoken_t	*au_to_exec_args(const char **);
311155191Srwatsontoken_t	*au_to_exec_env(const char **);
312155191Srwatsontoken_t	*au_to_text(char *text);
313155191Srwatsontoken_t	*au_to_kevent(struct kevent *kev);
314155191Srwatsontoken_t	*au_to_trailer(int rec_size);
315155191Srwatson
316155191Srwatson__END_DECLS
317155191Srwatson
318155191Srwatson#endif /* ! _BSM_AUDIT_RECORD_H_ */
319