audit_record.h revision 168765
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 * 33162508Srwatson * $P4: //depot/projects/trustedbsd/audit3/sys/bsm/audit_record.h#21 $ 34155191Srwatson * $FreeBSD: head/sys/bsm/audit_record.h 168765 2007-04-15 17:24:41Z csjp $ 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 89168765Scsjp#define AUT_ZONENAME 0x60 90155191Srwatson/* XXXRW: OpenBSM AUT_HOST 0x70? */ 91155191Srwatson#define AUT_ARG64 0x71 92155191Srwatson#define AUT_RETURN64 0x72 93155191Srwatson#define AUT_ATTR64 0x73 94155191Srwatson#define AUT_HEADER64 0x74 95155191Srwatson#define AUT_SUBJECT64 0x75 96155191Srwatson#define AUT_SERVER64 0x76 97155191Srwatson#define AUT_PROCESS64 0x77 98155191Srwatson#define AUT_OTHER_FILE64 0x78 99155191Srwatson#define AUT_HEADER64_EX 0x79 100155191Srwatson#define AUT_SUBJECT32_EX 0x7a 101155191Srwatson#define AUT_PROCESS32_EX 0x7b 102155191Srwatson#define AUT_SUBJECT64_EX 0x7c 103155191Srwatson#define AUT_PROCESS64_EX 0x7d 104155191Srwatson#define AUT_IN_ADDR_EX 0x7e 105155191Srwatson#define AUT_SOCKET_EX 0x7f 106155191Srwatson 107155191Srwatson/* 108155191Srwatson * Pre-64-bit BSM, 32-bit tokens weren't explicitly named as '32'. We have 109155191Srwatson * compatibility defines. 110155191Srwatson */ 111155191Srwatson#define AUT_HEADER AUT_HEADER32 112155191Srwatson#define AUT_ARG AUT_ARG32 113155191Srwatson#define AUT_RETURN AUT_RETURN32 114155191Srwatson#define AUT_SUBJECT AUT_SUBJECT32 115155191Srwatson#define AUT_SERVER AUT_SERVER32 116155191Srwatson#define AUT_PROCESS AUT_PROCESS32 117155191Srwatson#define AUT_OTHER_FILE AUT_OTHER_FILE32 118155191Srwatson 119155191Srwatson/* 120155191Srwatson * Darwin's bsm distribution uses the following non-BSM token name defines. 121155191Srwatson * We provide them for a single OpenBSM release for compatibility reasons. 122155191Srwatson */ 123155191Srwatson#define AU_FILE_TOKEN AUT_OTHER_FILE32 124155191Srwatson#define AU_TRAILER_TOKEN AUT_TRAILER 125155191Srwatson#define AU_HEADER_32_TOKEN AUT_HEADER32 126155191Srwatson#define AU_DATA_TOKEN AUT_DATA 127155191Srwatson#define AU_ARB_TOKEN AUT_DATA 128155191Srwatson#define AU_IPC_TOKEN AUT_IPC 129155191Srwatson#define AU_PATH_TOKEN AUT_PATH 130155191Srwatson#define AU_SUBJECT_32_TOKEN AUT_SUBJECT32 131155191Srwatson#define AU_PROCESS_32_TOKEN AUT_PROCESS32 132155191Srwatson#define AU_RETURN_32_TOKEN AUT_RETURN32 133155191Srwatson#define AU_TEXT_TOKEN AUT_TEXT 134155191Srwatson#define AU_OPAQUE_TOKEN AUT_OPAQUE 135155191Srwatson#define AU_IN_ADDR_TOKEN AUT_IN_ADDR 136155191Srwatson#define AU_IP_TOKEN AUT_IP 137155191Srwatson#define AU_IPORT_TOKEN AUT_IPORT 138155191Srwatson#define AU_ARG32_TOKEN AUT_ARG32 139155191Srwatson#define AU_SOCK_TOKEN AUT_SOCKET 140155191Srwatson#define AU_SEQ_TOKEN AUT_SEQ 141155191Srwatson#define AU_ATTR_TOKEN AUT_ATTR 142155191Srwatson#define AU_IPCPERM_TOKEN AUT_IPC_PERM 143155191Srwatson#define AU_NEWGROUPS_TOKEN AUT_NEWGROUPS 144155191Srwatson#define AU_EXEC_ARG_TOKEN AUT_EXEC_ARGS 145155191Srwatson#define AU_EXEC_ENV_TOKEN AUT_EXEC_ENV 146155191Srwatson#define AU_ATTR32_TOKEN AUT_ATTR32 147155191Srwatson#define AU_CMD_TOKEN AUT_CMD 148155191Srwatson#define AU_EXIT_TOKEN AUT_EXIT 149155191Srwatson#define AU_ARG64_TOKEN AUT_ARG64 150155191Srwatson#define AU_RETURN_64_TOKEN AUT_RETURN64 151155191Srwatson#define AU_ATTR64_TOKEN AUT_ATTR64 152155191Srwatson#define AU_HEADER_64_TOKEN AUT_HEADER64 153155191Srwatson#define AU_SUBJECT_64_TOKEN AUT_SUBJECT64 154155191Srwatson#define AU_PROCESS_64_TOKEN AUT_PROCESS64 155155191Srwatson#define AU_HEADER_64_EX_TOKEN AUT_HEADER64_EX 156155191Srwatson#define AU_SUBJECT_32_EX_TOKEN AUT_SUBJECT32_EX 157155191Srwatson#define AU_PROCESS_32_EX_TOKEN AUT_PROCESS32_EX 158155191Srwatson#define AU_SUBJECT_64_EX_TOKEN AUT_SUBJECT64_EX 159155191Srwatson#define AU_PROCESS_64_EX_TOKEN AUT_PROCESS64_EX 160155191Srwatson#define AU_IN_ADDR_EX_TOKEN AUT_IN_ADDR_EX 161155191Srwatson#define AU_SOCK_32_EX_TOKEN AUT_SOCKET_EX 162155191Srwatson 163155191Srwatson/* 164155191Srwatson * The values for the following token ids are not defined by BSM. 165155191Srwatson * 166155191Srwatson * XXXRW: Not sure how to handle these in OpenBSM yet, but I'll give them 167155191Srwatson * names more consistent with Sun's BSM. These originally came from Apple's 168155191Srwatson * BSM. 169155191Srwatson */ 170155191Srwatson#define AUT_SOCKINET32 0x80 /* XXX */ 171155191Srwatson#define AUT_SOCKINET128 0x81 /* XXX */ 172155191Srwatson#define AUT_SOCKUNIX 0x82 /* XXX */ 173155191Srwatson#define AU_SOCK_INET_32_TOKEN AUT_SOCKINET32 174155191Srwatson#define AU_SOCK_INET_128_TOKEN AUT_SOCKINET128 175155191Srwatson#define AU_SOCK_UNIX_TOKEN AUT_SOCKUNIX 176155191Srwatson 177155191Srwatson/* print values for the arbitrary token */ 178155191Srwatson#define AUP_BINARY 0 179155191Srwatson#define AUP_OCTAL 1 180155191Srwatson#define AUP_DECIMAL 2 181155191Srwatson#define AUP_HEX 3 182155191Srwatson#define AUP_STRING 4 183155191Srwatson 184155191Srwatson/* data-types for the arbitrary token */ 185155191Srwatson#define AUR_BYTE 0 186159257Srwatson#define AUR_CHAR AUR_BYTE 187155191Srwatson#define AUR_SHORT 1 188159257Srwatson#define AUR_INT32 2 189161635Srwatson#define AUR_INT AUR_INT32 190159257Srwatson#define AUR_INT64 3 191155191Srwatson 192155191Srwatson/* ... and their sizes */ 193155191Srwatson#define AUR_BYTE_SIZE sizeof(u_char) 194159257Srwatson#define AUR_CHAR_SIZE AUR_BYTE_SIZE 195155191Srwatson#define AUR_SHORT_SIZE sizeof(uint16_t) 196159257Srwatson#define AUR_INT32_SIZE sizeof(uint32_t) 197159257Srwatson#define AUR_INT_SIZE AUR_INT32_SIZE 198159257Srwatson#define AUR_INT64_SIZE sizeof(uint64_t) 199155191Srwatson 200155191Srwatson/* Modifiers for the header token */ 201155191Srwatson#define PAD_NOTATTR 0x4000 /* nonattributable event */ 202155191Srwatson#define PAD_FAILURE 0x8000 /* fail audit event */ 203155191Srwatson 204161635Srwatson#define AUDIT_MAX_GROUPS 16 205155191Srwatson 206161635Srwatson/* 207161635Srwatson * A number of BSM versions are floating around and defined. Here are 208161635Srwatson * constants for them. OpenBSM uses the same token types, etc, used in the 209161635Srwatson * Solaris BSM version, but has a separate version number in order to 210161635Srwatson * identify a potentially different event identifier name space. 211161635Srwatson */ 212161635Srwatson#define AUDIT_HEADER_VERSION_OLDDARWIN 1 /* In retrospect, a mistake. */ 213161635Srwatson#define AUDIT_HEADER_VERSION_SOLARIS 2 214161635Srwatson#define AUDIT_HEADER_VERSION_TSOL25 3 215161635Srwatson#define AUDIT_HEADER_VERSION_TSOL 4 216161635Srwatson#define AUDIT_HEADER_VERSION_OPENBSM 10 217155191Srwatson 218155191Srwatson/* 219155191Srwatson * BSM define is AUT_TRAILER_MAGIC; Apple BSM define is TRAILER_PAD_MAGIC; we 220155191Srwatson * split the difference, will remove the Apple define for the next release. 221155191Srwatson */ 222155191Srwatson#define AUT_TRAILER_MAGIC 0xb105 223155191Srwatson#define TRAILER_PAD_MAGIC AUT_TRAILER_MAGIC 224155191Srwatson 225155191Srwatson/* BSM library calls */ 226155191Srwatson 227155191Srwatson__BEGIN_DECLS 228155191Srwatson 229155191Srwatsonstruct in_addr; 230155191Srwatsonstruct in6_addr; 231155191Srwatsonstruct ip; 232155191Srwatsonstruct ipc_perm; 233155191Srwatsonstruct kevent; 234155191Srwatsonstruct sockaddr_in; 235155191Srwatsonstruct sockaddr_in6; 236155191Srwatsonstruct sockaddr_un; 237155191Srwatson#if defined(_KERNEL) || defined(KERNEL) 238155191Srwatsonstruct vnode_au_info; 239155191Srwatson#endif 240155191Srwatson 241155191Srwatsonint au_open(void); 242155191Srwatsonint au_write(int d, token_t *m); 243155191Srwatsonint au_close(int d, int keep, short event); 244155191Srwatsonint au_close_buffer(int d, short event, u_char *buffer, size_t *buflen); 245159257Srwatsonint au_close_token(token_t *tok, u_char *buffer, size_t *buflen); 246155191Srwatson 247155191Srwatsontoken_t *au_to_file(char *file, struct timeval tm); 248155191Srwatson 249159257Srwatsontoken_t *au_to_header32_tm(int rec_size, au_event_t e_type, au_emod_t e_mod, 250155191Srwatson struct timeval tm); 251159257Srwatson#if !defined(KERNEL) && !defined(_KERNEL) 252155191Srwatsontoken_t *au_to_header(int rec_size, au_event_t e_type, au_emod_t e_mod); 253155191Srwatsontoken_t *au_to_header32(int rec_size, au_event_t e_type, au_emod_t e_mod); 254159257Srwatsontoken_t *au_to_header64(int rec_size, au_event_t e_type, au_emod_t e_mod); 255155191Srwatson#endif 256155191Srwatson 257155191Srwatsontoken_t *au_to_me(void); 258155191Srwatsontoken_t *au_to_arg(char n, char *text, uint32_t v); 259155191Srwatsontoken_t *au_to_arg32(char n, char *text, uint32_t v); 260155191Srwatsontoken_t *au_to_arg64(char n, char *text, uint64_t v); 261155191Srwatson 262155191Srwatson#if defined(_KERNEL) || defined(KERNEL) 263155191Srwatsontoken_t *au_to_attr(struct vnode_au_info *vni); 264155191Srwatsontoken_t *au_to_attr32(struct vnode_au_info *vni); 265155191Srwatsontoken_t *au_to_attr64(struct vnode_au_info *vni); 266155191Srwatson#endif 267155191Srwatson 268155191Srwatsontoken_t *au_to_data(char unit_print, char unit_type, char unit_count, 269155191Srwatson char *p); 270155191Srwatsontoken_t *au_to_exit(int retval, int err); 271155191Srwatsontoken_t *au_to_groups(int *groups); 272155191Srwatsontoken_t *au_to_newgroups(uint16_t n, gid_t *groups); 273155191Srwatsontoken_t *au_to_in_addr(struct in_addr *internet_addr); 274155191Srwatsontoken_t *au_to_in_addr_ex(struct in6_addr *internet_addr); 275155191Srwatsontoken_t *au_to_ip(struct ip *ip); 276155191Srwatsontoken_t *au_to_ipc(char type, int id); 277155191Srwatsontoken_t *au_to_ipc_perm(struct ipc_perm *perm); 278155191Srwatsontoken_t *au_to_iport(uint16_t iport); 279155191Srwatsontoken_t *au_to_opaque(char *data, uint16_t bytes); 280155191Srwatsontoken_t *au_to_path(char *path); 281155191Srwatsontoken_t *au_to_process(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, 282155191Srwatson gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid); 283155191Srwatsontoken_t *au_to_process32(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, 284155191Srwatson gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid); 285155191Srwatsontoken_t *au_to_process64(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, 286155191Srwatson gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid); 287155191Srwatsontoken_t *au_to_process_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, 288155191Srwatson gid_t rgid, pid_t pid, au_asid_t sid, au_tid_addr_t *tid); 289155191Srwatsontoken_t *au_to_process32_ex(au_id_t auid, uid_t euid, gid_t egid, 290155191Srwatson uid_t ruid, gid_t rgid, pid_t pid, au_asid_t sid, 291155191Srwatson au_tid_addr_t *tid); 292155191Srwatsontoken_t *au_to_process64_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, 293155191Srwatson gid_t rgid, pid_t pid, au_asid_t sid, au_tid_addr_t *tid); 294155191Srwatsontoken_t *au_to_return(char status, uint32_t ret); 295155191Srwatsontoken_t *au_to_return32(char status, uint32_t ret); 296155191Srwatsontoken_t *au_to_return64(char status, uint64_t ret); 297155191Srwatsontoken_t *au_to_seq(long audit_count); 298155191Srwatson 299155191Srwatson#if defined(_KERNEL) || defined(KERNEL) 300155191Srwatsontoken_t *au_to_socket(struct socket *so); 301155191Srwatsontoken_t *au_to_socket_ex_32(uint16_t lp, uint16_t rp, struct sockaddr *la, 302155191Srwatson struct sockaddr *ta); 303155191Srwatsontoken_t *au_to_socket_ex_128(uint16_t lp, uint16_t rp, struct sockaddr *la, 304155191Srwatson struct sockaddr *ta); 305155191Srwatson#endif 306155191Srwatson 307155191Srwatsontoken_t *au_to_sock_inet(struct sockaddr_in *so); 308155191Srwatsontoken_t *au_to_sock_inet32(struct sockaddr_in *so); 309155191Srwatsontoken_t *au_to_sock_inet128(struct sockaddr_in6 *so); 310155191Srwatsontoken_t *au_to_sock_unix(struct sockaddr_un *so); 311155191Srwatsontoken_t *au_to_subject(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, 312155191Srwatson gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid); 313155191Srwatsontoken_t *au_to_subject32(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, 314155191Srwatson gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid); 315155191Srwatsontoken_t *au_to_subject64(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, 316155191Srwatson gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid); 317155191Srwatsontoken_t *au_to_subject_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, 318155191Srwatson gid_t rgid, pid_t pid, au_asid_t sid, au_tid_addr_t *tid); 319155191Srwatsontoken_t *au_to_subject32_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, 320155191Srwatson gid_t rgid, pid_t pid, au_asid_t sid, au_tid_addr_t *tid); 321155191Srwatsontoken_t *au_to_subject64_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, 322155191Srwatson gid_t rgid, pid_t pid, au_asid_t sid, au_tid_addr_t *tid); 323161813Swsalamon#if defined(_KERNEL) || defined(KERNEL) 324161813Swsalamontoken_t *au_to_exec_args(char *args, int argc); 325161813Swsalamontoken_t *au_to_exec_env(char *envs, int envc); 326161813Swsalamon#else 327161813Swsalamontoken_t *au_to_exec_args(char **argv); 328161813Swsalamontoken_t *au_to_exec_env(char **envp); 329161813Swsalamon#endif 330155191Srwatsontoken_t *au_to_text(char *text); 331155191Srwatsontoken_t *au_to_kevent(struct kevent *kev); 332155191Srwatsontoken_t *au_to_trailer(int rec_size); 333168765Scsjptoken_t *au_to_zonename(char *zonename); 334155191Srwatson 335155191Srwatson__END_DECLS 336155191Srwatson 337155191Srwatson#endif /* ! _BSM_AUDIT_RECORD_H_ */ 338