audit_record.h revision 160084
146197Sphk/*
246197Sphk * Copyright (c) 2005 Apple Computer, Inc.
346197Sphk * All rights reserved.
446197Sphk *
546197Sphk * @APPLE_BSD_LICENSE_HEADER_START@
646197Sphk *
746197Sphk * Redistribution and use in source and binary forms, with or without
846197Sphk * modification, are permitted provided that the following conditions
950477Speter * are met:
1046197Sphk *
1146197Sphk * 1.  Redistributions of source code must retain the above copyright
1246155Sphk *     notice, this list of conditions and the following disclaimer.
1346155Sphk * 2.  Redistributions in binary form must reproduce the above copyright
1446155Sphk *     notice, this list of conditions and the following disclaimer in the
1546155Sphk *     documentation and/or other materials provided with the distribution.
1646155Sphk * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
1746155Sphk *     its contributors may be used to endorse or promote products derived
1846155Sphk *     from this software without specific prior written permission.
1946155Sphk *
2046155Sphk * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
2146155Sphk * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2246155Sphk * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2357163Srwatson * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
2446155Sphk * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2546155Sphk * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2646155Sphk * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2746155Sphk * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2846155Sphk * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2957163Srwatson * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3057163Srwatson *
3157163Srwatson * @APPLE_BSD_LICENSE_HEADER_END@
3257163Srwatson *
3357163Srwatson * $P4: //depot/projects/trustedbsd/audit3/sys/bsm/audit_record.h#13 $
3457163Srwatson * $FreeBSD: head/sys/bsm/audit_record.h 160084 2006-07-03 14:44:13Z rwatson $
3557163Srwatson */
3657163Srwatson
3761235Srwatson#ifndef _BSM_AUDIT_RECORD_H_
3861235Srwatson#define _BSM_AUDIT_RECORD_H_
3961235Srwatson
4061235Srwatson#include <sys/time.h>			/* struct timeval */
4161235Srwatson
4268024Srwatson/*
4368024Srwatson * Token type identifiers.
4468024Srwatson */
4568024Srwatson#define	AUT_INVALID		0x00
4668024Srwatson#define	AUT_OTHER_FILE32	0x11
4746155Sphk#define	AUT_OHEADER		0x12
4846155Sphk#define	AUT_TRAILER		0x13
4972786Srwatson#define	AUT_HEADER32		0x14
5072786Srwatson#define	AUT_HEADER32_EX		0x15
5172786Srwatson#define	AUT_DATA		0x21
5272786Srwatson#define	AUT_IPC			0x22
5346155Sphk#define	AUT_PATH		0x23
5446155Sphk#define	AUT_SUBJECT32		0x24
5546155Sphk#define	AUT_SERVER32		0x25
5646155Sphk#define	AUT_PROCESS32		0x26
5746155Sphk#define	AUT_RETURN32		0x27
5846155Sphk#define	AUT_TEXT		0x28
5972786Srwatson#define	AUT_OPAQUE		0x29
6046155Sphk#define	AUT_IN_ADDR		0x2a
6146155Sphk#define	AUT_IP			0x2b
6246155Sphk#define	AUT_IPORT		0x2c
6346155Sphk#define	AUT_ARG32		0x2d
6446155Sphk#define	AUT_SOCKET		0x2e
6546155Sphk#define	AUT_SEQ			0x2f
6651398Sphk#define	AUT_ACL			0x30
6751398Sphk#define	AUT_ATTR		0x31
6869781Sdwmalone#define	AUT_IPC_PERM		0x32
6946155Sphk#define	AUT_LABEL		0x33
7046155Sphk#define	AUT_GROUPS		0x34
7146155Sphk#define	AUT_ILABEL		0x35
7246155Sphk#define	AUT_SLABEL		0x36
7346155Sphk#define	AUT_CLEAR		0x37
7446155Sphk#define	AUT_PRIV		0x38
7546155Sphk#define	AUT_UPRIV		0x39
7646155Sphk#define	AUT_LIAISON		0x3a
7746155Sphk#define	AUT_NEWGROUPS		0x3b
7846155Sphk#define	AUT_EXEC_ARGS		0x3c
7972786Srwatson#define	AUT_EXEC_ENV		0x3d
8072786Srwatson#define	AUT_ATTR32		0x3e
8172786Srwatson/* #define	AUT_????	0x3f */
8246155Sphk#define	AUT_XATOM		0x40
8346155Sphk#define	AUT_XOBJ		0x41
8446155Sphk#define	AUT_XPROTO		0x42
8546155Sphk#define	AUT_XSELECT		0x43
8646155Sphk/* XXXRW: Additional X11 tokens not defined? */
8746155Sphk#define	AUT_CMD			0x51
8846155Sphk#define	AUT_EXIT		0x52
8972786Srwatson/* XXXRW: OpenBSM AUT_HOST 0x70? */
9072786Srwatson#define	AUT_ARG64		0x71
9172786Srwatson#define	AUT_RETURN64		0x72
9272786Srwatson#define	AUT_ATTR64		0x73
9372786Srwatson#define	AUT_HEADER64		0x74
9472786Srwatson#define	AUT_SUBJECT64		0x75
9572786Srwatson#define	AUT_SERVER64		0x76
9672786Srwatson#define	AUT_PROCESS64		0x77
9772786Srwatson#define	AUT_OTHER_FILE64	0x78
9872786Srwatson#define	AUT_HEADER64_EX		0x79
9972786Srwatson#define	AUT_SUBJECT32_EX	0x7a
10072786Srwatson#define	AUT_PROCESS32_EX	0x7b
10172786Srwatson#define	AUT_SUBJECT64_EX	0x7c
10272786Srwatson#define	AUT_PROCESS64_EX	0x7d
10372786Srwatson#define	AUT_IN_ADDR_EX		0x7e
10472786Srwatson#define	AUT_SOCKET_EX		0x7f
10572786Srwatson
10672786Srwatson/*
10772786Srwatson * Pre-64-bit BSM, 32-bit tokens weren't explicitly named as '32'.  We have
10846155Sphk * compatibility defines.
10972786Srwatson */
11046155Sphk#define	AUT_HEADER		AUT_HEADER32
11146155Sphk#define	AUT_ARG			AUT_ARG32
11246155Sphk#define	AUT_RETURN		AUT_RETURN32
11372786Srwatson#define	AUT_SUBJECT		AUT_SUBJECT32
11446155Sphk#define	AUT_SERVER		AUT_SERVER32
11546155Sphk#define	AUT_PROCESS		AUT_PROCESS32
11646155Sphk#define	AUT_OTHER_FILE		AUT_OTHER_FILE32
11746155Sphk
11846155Sphk/*
11946155Sphk * Darwin's bsm distribution uses the following non-BSM token name defines.
12046155Sphk * We provide them for a single OpenBSM release for compatibility reasons.
12172786Srwatson */
12246155Sphk#define	AU_FILE_TOKEN		AUT_OTHER_FILE32
12372786Srwatson#define	AU_TRAILER_TOKEN	AUT_TRAILER
12446155Sphk#define	AU_HEADER_32_TOKEN	AUT_HEADER32
12546155Sphk#define	AU_DATA_TOKEN		AUT_DATA
12681114Srwatson#define	AU_ARB_TOKEN		AUT_DATA
12781114Srwatson#define	AU_IPC_TOKEN		AUT_IPC
12881114Srwatson#define	AU_PATH_TOKEN		AUT_PATH
12981114Srwatson#define	AU_SUBJECT_32_TOKEN	AUT_SUBJECT32
13081114Srwatson#define	AU_PROCESS_32_TOKEN	AUT_PROCESS32
13181114Srwatson#define	AU_RETURN_32_TOKEN	AUT_RETURN32
13281114Srwatson#define	AU_TEXT_TOKEN		AUT_TEXT
13372786Srwatson#define	AU_OPAQUE_TOKEN		AUT_OPAQUE
13446155Sphk#define	AU_IN_ADDR_TOKEN	AUT_IN_ADDR
13546155Sphk#define	AU_IP_TOKEN		AUT_IP
13646155Sphk#define	AU_IPORT_TOKEN		AUT_IPORT
13746155Sphk#define	AU_ARG32_TOKEN		AUT_ARG32
13846155Sphk#define	AU_SOCK_TOKEN		AUT_SOCKET
13972786Srwatson#define	AU_SEQ_TOKEN		AUT_SEQ
14046155Sphk#define	AU_ATTR_TOKEN		AUT_ATTR
14146155Sphk#define	AU_IPCPERM_TOKEN	AUT_IPC_PERM
14246155Sphk#define	AU_NEWGROUPS_TOKEN	AUT_NEWGROUPS
14372786Srwatson#define	AU_EXEC_ARG_TOKEN	AUT_EXEC_ARGS
14446155Sphk#define	AU_EXEC_ENV_TOKEN	AUT_EXEC_ENV
14546155Sphk#define	AU_ATTR32_TOKEN		AUT_ATTR32
14646155Sphk#define	AU_CMD_TOKEN		AUT_CMD
14746155Sphk#define	AU_EXIT_TOKEN		AUT_EXIT
14846155Sphk#define	AU_ARG64_TOKEN		AUT_ARG64
14981114Srwatson#define	AU_RETURN_64_TOKEN	AUT_RETURN64
15046155Sphk#define	AU_ATTR64_TOKEN		AUT_ATTR64
15172786Srwatson#define	AU_HEADER_64_TOKEN	AUT_HEADER64
15246155Sphk#define	AU_SUBJECT_64_TOKEN	AUT_SUBJECT64
15372786Srwatson#define	AU_PROCESS_64_TOKEN	AUT_PROCESS64
15446155Sphk#define	AU_HEADER_64_EX_TOKEN	AUT_HEADER64_EX
15546155Sphk#define	AU_SUBJECT_32_EX_TOKEN	AUT_SUBJECT32_EX
15646155Sphk#define	AU_PROCESS_32_EX_TOKEN	AUT_PROCESS32_EX
15746155Sphk#define	AU_SUBJECT_64_EX_TOKEN	AUT_SUBJECT64_EX
15846155Sphk#define	AU_PROCESS_64_EX_TOKEN	AUT_PROCESS64_EX
15946155Sphk#define	AU_IN_ADDR_EX_TOKEN	AUT_IN_ADDR_EX
16072786Srwatson#define	AU_SOCK_32_EX_TOKEN	AUT_SOCKET_EX
16146155Sphk
16246155Sphk/*
16346155Sphk * The values for the following token ids are not defined by BSM.
16446155Sphk *
16561235Srwatson * XXXRW: Not sure how to handle these in OpenBSM yet, but I'll give them
16661235Srwatson * names more consistent with Sun's BSM.  These originally came from Apple's
16761235Srwatson * BSM.
16846155Sphk */
16972786Srwatson#define	AUT_SOCKINET32		0x80		/* XXX */
17046155Sphk#define	AUT_SOCKINET128		0x81		/* XXX */
17146155Sphk#define	AUT_SOCKUNIX		0x82		/* XXX */
17246155Sphk#define	AU_SOCK_INET_32_TOKEN	AUT_SOCKINET32
17346155Sphk#define	AU_SOCK_INET_128_TOKEN	AUT_SOCKINET128
17446155Sphk#define	AU_SOCK_UNIX_TOKEN	AUT_SOCKUNIX
17572786Srwatson
17672786Srwatson/* print values for the arbitrary token */
17772786Srwatson#define AUP_BINARY      0
17872786Srwatson#define AUP_OCTAL       1
17972786Srwatson#define AUP_DECIMAL     2
18072786Srwatson#define AUP_HEX         3
18172786Srwatson#define AUP_STRING      4
18272786Srwatson
18372786Srwatson/* data-types for the arbitrary token */
18472786Srwatson#define AUR_BYTE        0
18572786Srwatson#define AUR_CHAR        AUR_BYTE
18672786Srwatson#define AUR_SHORT       1
18772786Srwatson#define AUR_INT32       2
18872786Srwatson#define AUR_INT         AUR_INT
18972786Srwatson#define AUR_INT64       3
19072786Srwatson
19172786Srwatson/* ... and their sizes */
19272786Srwatson#define AUR_BYTE_SIZE       sizeof(u_char)
19372786Srwatson#define AUR_CHAR_SIZE       AUR_BYTE_SIZE
19472786Srwatson#define AUR_SHORT_SIZE      sizeof(uint16_t)
19572786Srwatson#define AUR_INT32_SIZE      sizeof(uint32_t)
19672786Srwatson#define AUR_INT_SIZE        AUR_INT32_SIZE
19772786Srwatson#define AUR_INT64_SIZE      sizeof(uint64_t)
19872786Srwatson
19972786Srwatson/* Modifiers for the header token */
20072786Srwatson#define PAD_NOTATTR  0x4000   /* nonattributable event */
20172786Srwatson#define PAD_FAILURE  0x8000   /* fail audit event */
20272786Srwatson
20372786Srwatson
204#define BSM_MAX_GROUPS      16
205#define HEADER_VERSION      1
206
207/*
208 * BSM define is AUT_TRAILER_MAGIC; Apple BSM define is TRAILER_PAD_MAGIC; we
209 * split the difference, will remove the Apple define for the next release.
210 */
211#define	AUT_TRAILER_MAGIC	0xb105
212#define	TRAILER_PAD_MAGIC	AUT_TRAILER_MAGIC
213
214/* BSM library calls */
215
216__BEGIN_DECLS
217
218struct in_addr;
219struct in6_addr;
220struct ip;
221struct ipc_perm;
222struct kevent;
223struct sockaddr_in;
224struct sockaddr_in6;
225struct sockaddr_un;
226#if defined(_KERNEL) || defined(KERNEL)
227struct vnode_au_info;
228#endif
229
230int	 au_open(void);
231int	 au_write(int d, token_t *m);
232int	 au_close(int d, int keep, short event);
233int	 au_close_buffer(int d, short event, u_char *buffer, size_t *buflen);
234int	 au_close_token(token_t *tok, u_char *buffer, size_t *buflen);
235
236token_t	*au_to_file(char *file, struct timeval tm);
237
238token_t	*au_to_header32_tm(int rec_size, au_event_t e_type, au_emod_t e_mod,
239	    struct timeval tm);
240#if !defined(KERNEL) && !defined(_KERNEL)
241token_t	*au_to_header(int rec_size, au_event_t e_type, au_emod_t e_mod);
242token_t	*au_to_header32(int rec_size, au_event_t e_type, au_emod_t e_mod);
243token_t	*au_to_header64(int rec_size, au_event_t e_type, au_emod_t e_mod);
244#endif
245
246token_t	*au_to_me(void);
247token_t	*au_to_arg(char n, char *text, uint32_t v);
248token_t	*au_to_arg32(char n, char *text, uint32_t v);
249token_t	*au_to_arg64(char n, char *text, uint64_t v);
250
251#if defined(_KERNEL) || defined(KERNEL)
252token_t	*au_to_attr(struct vnode_au_info *vni);
253token_t	*au_to_attr32(struct vnode_au_info *vni);
254token_t	*au_to_attr64(struct vnode_au_info *vni);
255#endif
256
257token_t	*au_to_data(char unit_print, char unit_type, char unit_count,
258	    char *p);
259token_t	*au_to_exit(int retval, int err);
260token_t	*au_to_groups(int *groups);
261token_t	*au_to_newgroups(uint16_t n, gid_t *groups);
262token_t	*au_to_in_addr(struct in_addr *internet_addr);
263token_t	*au_to_in_addr_ex(struct in6_addr *internet_addr);
264token_t	*au_to_ip(struct ip *ip);
265token_t	*au_to_ipc(char type, int id);
266token_t	*au_to_ipc_perm(struct ipc_perm *perm);
267token_t	*au_to_iport(uint16_t iport);
268token_t	*au_to_opaque(char *data, uint16_t bytes);
269token_t	*au_to_path(char *path);
270token_t	*au_to_process(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
271	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid);
272token_t	*au_to_process32(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
273	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid);
274token_t	*au_to_process64(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
275	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid);
276token_t	*au_to_process_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
277	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_addr_t *tid);
278token_t	*au_to_process32_ex(au_id_t auid, uid_t euid, gid_t egid,
279	    uid_t ruid, gid_t rgid, pid_t pid, au_asid_t sid,
280	    au_tid_addr_t *tid);
281token_t	*au_to_process64_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
282	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_addr_t *tid);
283token_t	*au_to_return(char status, uint32_t ret);
284token_t	*au_to_return32(char status, uint32_t ret);
285token_t	*au_to_return64(char status, uint64_t ret);
286token_t	*au_to_seq(long audit_count);
287
288#if defined(_KERNEL) || defined(KERNEL)
289token_t	*au_to_socket(struct socket *so);
290token_t	*au_to_socket_ex_32(uint16_t lp, uint16_t rp, struct sockaddr *la,
291	    struct sockaddr *ta);
292token_t	*au_to_socket_ex_128(uint16_t lp, uint16_t rp, struct sockaddr *la,
293	    struct sockaddr *ta);
294#endif
295
296token_t	*au_to_sock_inet(struct sockaddr_in *so);
297token_t	*au_to_sock_inet32(struct sockaddr_in *so);
298token_t	*au_to_sock_inet128(struct sockaddr_in6 *so);
299token_t	*au_to_sock_unix(struct sockaddr_un *so);
300token_t	*au_to_subject(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
301	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid);
302token_t	*au_to_subject32(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
303	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid);
304token_t	*au_to_subject64(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
305	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid);
306token_t	*au_to_subject_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
307	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_addr_t *tid);
308token_t	*au_to_subject32_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
309	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_addr_t *tid);
310token_t	*au_to_subject64_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid,
311	    gid_t rgid, pid_t pid, au_asid_t sid, au_tid_addr_t *tid);
312token_t	*au_to_exec_args(const char **);
313token_t	*au_to_exec_env(const char **);
314token_t	*au_to_text(char *text);
315token_t	*au_to_kevent(struct kevent *kev);
316token_t	*au_to_trailer(int rec_size);
317
318__END_DECLS
319
320#endif /* ! _BSM_AUDIT_RECORD_H_ */
321