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 * 29244390Srwatson * $P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit_record.h#12 $ 30184902Srwatson */ 31184902Srwatson 32184902Srwatson#ifndef _BSM_AUDIT_RECORD_H_ 33184902Srwatson#define _BSM_AUDIT_RECORD_H_ 34184902Srwatson 35184902Srwatson#include <sys/time.h> /* struct timeval */ 36184902Srwatson 37184902Srwatson/* 38184902Srwatson * Token type identifiers. 39184902Srwatson */ 40184902Srwatson#define AUT_INVALID 0x00 41184902Srwatson#define AUT_OTHER_FILE32 0x11 42184902Srwatson#define AUT_OHEADER 0x12 43184902Srwatson#define AUT_TRAILER 0x13 44184902Srwatson#define AUT_HEADER32 0x14 45184902Srwatson#define AUT_HEADER32_EX 0x15 46184902Srwatson#define AUT_DATA 0x21 47184902Srwatson#define AUT_IPC 0x22 48184902Srwatson#define AUT_PATH 0x23 49184902Srwatson#define AUT_SUBJECT32 0x24 50184902Srwatson#define AUT_XATPATH 0x25 51184902Srwatson#define AUT_PROCESS32 0x26 52184902Srwatson#define AUT_RETURN32 0x27 53184902Srwatson#define AUT_TEXT 0x28 54184902Srwatson#define AUT_OPAQUE 0x29 55184902Srwatson#define AUT_IN_ADDR 0x2a 56184902Srwatson#define AUT_IP 0x2b 57184902Srwatson#define AUT_IPORT 0x2c 58184902Srwatson#define AUT_ARG32 0x2d 59184902Srwatson#define AUT_SOCKET 0x2e 60184902Srwatson#define AUT_SEQ 0x2f 61184902Srwatson#define AUT_ACL 0x30 62184902Srwatson#define AUT_ATTR 0x31 63184902Srwatson#define AUT_IPC_PERM 0x32 64184902Srwatson#define AUT_LABEL 0x33 65184902Srwatson#define AUT_GROUPS 0x34 66184902Srwatson#define AUT_ACE 0x35 67184902Srwatson#define AUT_PRIV 0x38 68184902Srwatson#define AUT_UPRIV 0x39 69184902Srwatson#define AUT_LIAISON 0x3a 70184902Srwatson#define AUT_NEWGROUPS 0x3b 71184902Srwatson#define AUT_EXEC_ARGS 0x3c 72184902Srwatson#define AUT_EXEC_ENV 0x3d 73184902Srwatson#define AUT_ATTR32 0x3e 74184902Srwatson#define AUT_UNAUTH 0x3f 75184902Srwatson#define AUT_XATOM 0x40 76184902Srwatson#define AUT_XOBJ 0x41 77184902Srwatson#define AUT_XPROTO 0x42 78184902Srwatson#define AUT_XSELECT 0x43 79184902Srwatson#define AUT_XCOLORMAP 0x44 80184902Srwatson#define AUT_XCURSOR 0x45 81184902Srwatson#define AUT_XFONT 0x46 82184902Srwatson#define AUT_XGC 0x47 83184902Srwatson#define AUT_XPIXMAP 0x48 84184902Srwatson#define AUT_XPROPERTY 0x49 85184902Srwatson#define AUT_XWINDOW 0x4a 86184902Srwatson#define AUT_XCLIENT 0x4b 87184902Srwatson#define AUT_CMD 0x51 88184902Srwatson#define AUT_EXIT 0x52 89184902Srwatson#define AUT_ZONENAME 0x60 90184902Srwatson#define AUT_HOST 0x70 91184902Srwatson#define AUT_ARG64 0x71 92184902Srwatson#define AUT_RETURN64 0x72 93184902Srwatson#define AUT_ATTR64 0x73 94184902Srwatson#define AUT_HEADER64 0x74 95184902Srwatson#define AUT_SUBJECT64 0x75 96184902Srwatson#define AUT_PROCESS64 0x77 97184902Srwatson#define AUT_OTHER_FILE64 0x78 98184902Srwatson#define AUT_HEADER64_EX 0x79 99184902Srwatson#define AUT_SUBJECT32_EX 0x7a 100184902Srwatson#define AUT_PROCESS32_EX 0x7b 101184902Srwatson#define AUT_SUBJECT64_EX 0x7c 102184902Srwatson#define AUT_PROCESS64_EX 0x7d 103184902Srwatson#define AUT_IN_ADDR_EX 0x7e 104184902Srwatson#define AUT_SOCKET_EX 0x7f 105184902Srwatson 106184902Srwatson/* 107184902Srwatson * Pre-64-bit BSM, 32-bit tokens weren't explicitly named as '32'. We have 108184902Srwatson * compatibility defines. 109184902Srwatson */ 110184902Srwatson#define AUT_HEADER AUT_HEADER32 111184902Srwatson#define AUT_ARG AUT_ARG32 112184902Srwatson#define AUT_RETURN AUT_RETURN32 113184902Srwatson#define AUT_SUBJECT AUT_SUBJECT32 114184902Srwatson#define AUT_PROCESS AUT_PROCESS32 115184902Srwatson#define AUT_OTHER_FILE AUT_OTHER_FILE32 116184902Srwatson 117184902Srwatson/* 118184902Srwatson * The values for the following token ids are not defined by BSM. 119184902Srwatson * 120184902Srwatson * XXXRW: Not sure how to handle these in OpenBSM yet, but I'll give them 121184902Srwatson * names more consistent with Sun's BSM. These originally came from Apple's 122184902Srwatson * BSM. 123184902Srwatson */ 124184902Srwatson#define AUT_SOCKINET32 0x80 /* XXX */ 125184902Srwatson#define AUT_SOCKINET128 0x81 /* XXX */ 126184902Srwatson#define AUT_SOCKUNIX 0x82 /* XXX */ 127184902Srwatson 128184902Srwatson/* print values for the arbitrary token */ 129184902Srwatson#define AUP_BINARY 0 130184902Srwatson#define AUP_OCTAL 1 131184902Srwatson#define AUP_DECIMAL 2 132184902Srwatson#define AUP_HEX 3 133184902Srwatson#define AUP_STRING 4 134184902Srwatson 135184902Srwatson/* data-types for the arbitrary token */ 136184902Srwatson#define AUR_BYTE 0 137184902Srwatson#define AUR_CHAR AUR_BYTE 138184902Srwatson#define AUR_SHORT 1 139184902Srwatson#define AUR_INT32 2 140184902Srwatson#define AUR_INT AUR_INT32 141184902Srwatson#define AUR_INT64 3 142184902Srwatson 143184902Srwatson/* ... and their sizes */ 144184902Srwatson#define AUR_BYTE_SIZE sizeof(u_char) 145184902Srwatson#define AUR_CHAR_SIZE AUR_BYTE_SIZE 146184902Srwatson#define AUR_SHORT_SIZE sizeof(uint16_t) 147184902Srwatson#define AUR_INT32_SIZE sizeof(uint32_t) 148184902Srwatson#define AUR_INT_SIZE AUR_INT32_SIZE 149184902Srwatson#define AUR_INT64_SIZE sizeof(uint64_t) 150184902Srwatson 151184902Srwatson/* Modifiers for the header token */ 152184902Srwatson#define PAD_NOTATTR 0x4000 /* nonattributable event */ 153184902Srwatson#define PAD_FAILURE 0x8000 /* fail audit event */ 154184902Srwatson 155184902Srwatson#define AUDIT_MAX_GROUPS 16 156184902Srwatson 157184902Srwatson/* 158184902Srwatson * A number of BSM versions are floating around and defined. Here are 159184902Srwatson * constants for them. OpenBSM uses the same token types, etc, used in the 160184902Srwatson * Solaris BSM version, but has a separate version number in order to 161184902Srwatson * identify a potentially different event identifier name space. 162184902Srwatson */ 163184902Srwatson#define AUDIT_HEADER_VERSION_OLDDARWIN 1 /* In retrospect, a mistake. */ 164184902Srwatson#define AUDIT_HEADER_VERSION_SOLARIS 2 165184902Srwatson#define AUDIT_HEADER_VERSION_TSOL25 3 166184902Srwatson#define AUDIT_HEADER_VERSION_TSOL 4 167186647Srwatson#define AUDIT_HEADER_VERSION_OPENBSM10 10 168186647Srwatson#define AUDIT_HEADER_VERSION_OPENBSM11 11 169186647Srwatson#define AUDIT_HEADER_VERSION_OPENBSM AUDIT_HEADER_VERSION_OPENBSM11 170184902Srwatson 171184902Srwatson#define AUT_TRAILER_MAGIC 0xb105 172184902Srwatson 173184902Srwatson/* BSM library calls */ 174184902Srwatson 175184902Srwatson__BEGIN_DECLS 176184902Srwatson 177184902Srwatsonstruct in_addr; 178184902Srwatsonstruct in6_addr; 179184902Srwatsonstruct ip; 180184902Srwatsonstruct ipc_perm; 181184902Srwatsonstruct kevent; 182186647Srwatsonstruct sockaddr; 183184902Srwatsonstruct sockaddr_in; 184184902Srwatsonstruct sockaddr_in6; 185184902Srwatsonstruct sockaddr_un; 186184902Srwatson#if defined(_KERNEL) || defined(KERNEL) 187184902Srwatsonstruct vnode_au_info; 188184902Srwatson#endif 189184902Srwatson 190184902Srwatsonint au_open(void); 191184902Srwatsonint au_write(int d, token_t *m); 192184902Srwatsonint au_close(int d, int keep, short event); 193184902Srwatsonint au_close_buffer(int d, short event, u_char *buffer, size_t *buflen); 194184902Srwatsonint au_close_token(token_t *tok, u_char *buffer, size_t *buflen); 195184902Srwatson 196184902Srwatsontoken_t *au_to_file(const char *file, struct timeval tm); 197184902Srwatson 198184902Srwatsontoken_t *au_to_header32_tm(int rec_size, au_event_t e_type, au_emod_t e_mod, 199184902Srwatson struct timeval tm); 200184902Srwatsontoken_t *au_to_header32_ex_tm(int rec_size, au_event_t e_type, au_emod_t e_mod, 201184902Srwatson struct timeval tm, struct auditinfo_addr *aia); 202184902Srwatsontoken_t *au_to_header64_tm(int rec_size, au_event_t e_type, au_emod_t e_mod, 203184902Srwatson struct timeval tm); 204184902Srwatson#if !defined(KERNEL) && !defined(_KERNEL) 205184902Srwatsontoken_t *au_to_header(int rec_size, au_event_t e_type, au_emod_t e_mod); 206184902Srwatsontoken_t *au_to_header_ex(int rec_size, au_event_t e_type, au_emod_t e_mod); 207184902Srwatsontoken_t *au_to_header32(int rec_size, au_event_t e_type, au_emod_t e_mod); 208184902Srwatsontoken_t *au_to_header64(int rec_size, au_event_t e_type, au_emod_t e_mod); 209186647Srwatsontoken_t *au_to_header32_ex(int rec_size, au_event_t e_type, au_emod_t e_mod); 210184902Srwatson#endif 211184902Srwatson 212184902Srwatsontoken_t *au_to_me(void); 213184902Srwatsontoken_t *au_to_arg(char n, const char *text, uint32_t v); 214184902Srwatsontoken_t *au_to_arg32(char n, const char *text, uint32_t v); 215184902Srwatsontoken_t *au_to_arg64(char n, const char *text, uint64_t v); 216184902Srwatson 217184902Srwatson#if defined(_KERNEL) || defined(KERNEL) 218184902Srwatsontoken_t *au_to_attr(struct vnode_au_info *vni); 219184902Srwatsontoken_t *au_to_attr32(struct vnode_au_info *vni); 220184902Srwatsontoken_t *au_to_attr64(struct vnode_au_info *vni); 221184902Srwatson#endif 222184902Srwatson 223184902Srwatsontoken_t *au_to_data(char unit_print, char unit_type, char unit_count, 224184902Srwatson const char *p); 225184902Srwatsontoken_t *au_to_exit(int retval, int err); 226184902Srwatsontoken_t *au_to_groups(int *groups); 227184902Srwatsontoken_t *au_to_newgroups(uint16_t n, gid_t *groups); 228184902Srwatsontoken_t *au_to_in_addr(struct in_addr *internet_addr); 229184902Srwatsontoken_t *au_to_in_addr_ex(struct in6_addr *internet_addr); 230184902Srwatsontoken_t *au_to_ip(struct ip *ip); 231184902Srwatsontoken_t *au_to_ipc(char type, int id); 232184902Srwatsontoken_t *au_to_ipc_perm(struct ipc_perm *perm); 233184902Srwatsontoken_t *au_to_iport(uint16_t iport); 234184902Srwatsontoken_t *au_to_opaque(const char *data, uint16_t bytes); 235184902Srwatsontoken_t *au_to_path(const char *path); 236244390Srwatsontoken_t *au_to_privset(char *privtypestr, char *privstr); 237184902Srwatsontoken_t *au_to_process(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, 238184902Srwatson gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid); 239184902Srwatsontoken_t *au_to_process32(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, 240184902Srwatson gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid); 241184902Srwatsontoken_t *au_to_process64(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, 242184902Srwatson gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid); 243184902Srwatsontoken_t *au_to_process_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, 244184902Srwatson gid_t rgid, pid_t pid, au_asid_t sid, au_tid_addr_t *tid); 245184902Srwatsontoken_t *au_to_process32_ex(au_id_t auid, uid_t euid, gid_t egid, 246184902Srwatson uid_t ruid, gid_t rgid, pid_t pid, au_asid_t sid, 247184902Srwatson au_tid_addr_t *tid); 248184902Srwatsontoken_t *au_to_process64_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, 249184902Srwatson gid_t rgid, pid_t pid, au_asid_t sid, au_tid_addr_t *tid); 250184902Srwatsontoken_t *au_to_return(char status, uint32_t ret); 251184902Srwatsontoken_t *au_to_return32(char status, uint32_t ret); 252184902Srwatsontoken_t *au_to_return64(char status, uint64_t ret); 253184902Srwatsontoken_t *au_to_seq(long audit_count); 254186647Srwatsontoken_t *au_to_socket_ex(u_short so_domain, u_short so_type, 255186647Srwatson struct sockaddr *sa_local, struct sockaddr *sa_remote); 256184902Srwatsontoken_t *au_to_sock_inet(struct sockaddr_in *so); 257184902Srwatsontoken_t *au_to_sock_inet32(struct sockaddr_in *so); 258184902Srwatsontoken_t *au_to_sock_inet128(struct sockaddr_in6 *so); 259184902Srwatsontoken_t *au_to_sock_unix(struct sockaddr_un *so); 260184902Srwatsontoken_t *au_to_subject(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, 261184902Srwatson gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid); 262184902Srwatsontoken_t *au_to_subject32(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, 263184902Srwatson gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid); 264184902Srwatsontoken_t *au_to_subject64(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, 265184902Srwatson gid_t rgid, pid_t pid, au_asid_t sid, au_tid_t *tid); 266184902Srwatsontoken_t *au_to_subject_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, 267184902Srwatson gid_t rgid, pid_t pid, au_asid_t sid, au_tid_addr_t *tid); 268184902Srwatsontoken_t *au_to_subject32_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, 269184902Srwatson gid_t rgid, pid_t pid, au_asid_t sid, au_tid_addr_t *tid); 270184902Srwatsontoken_t *au_to_subject64_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, 271184902Srwatson gid_t rgid, pid_t pid, au_asid_t sid, au_tid_addr_t *tid); 272184902Srwatson#if defined(_KERNEL) || defined(KERNEL) 273186647Srwatsontoken_t *au_to_exec_args(char *args, int argc); 274186647Srwatsontoken_t *au_to_exec_env(char *envs, int envc); 275184902Srwatson#else 276184902Srwatsontoken_t *au_to_exec_args(char **argv); 277184902Srwatsontoken_t *au_to_exec_env(char **envp); 278184902Srwatson#endif 279184902Srwatsontoken_t *au_to_text(const char *text); 280184902Srwatsontoken_t *au_to_kevent(struct kevent *kev); 281184902Srwatsontoken_t *au_to_trailer(int rec_size); 282244390Srwatsontoken_t *au_to_upriv(char sorf, char *priv); 283184902Srwatsontoken_t *au_to_zonename(const char *zonename); 284184902Srwatson 285186647Srwatson/* 286187214Srwatson * BSM library routines for converting between local and BSM constant spaces. 287186647Srwatson */ 288187214Srwatsonint au_bsm_to_domain(u_short bsm_domain, int *local_domainp); 289186647Srwatsonint au_bsm_to_errno(u_char bsm_error, int *errorp); 290191273Srwatsonint au_bsm_to_fcntl_cmd(u_short bsm_fcntl_cmd, int *local_fcntl_cmdp); 291187214Srwatsonint au_bsm_to_socket_type(u_short bsm_socket_type, 292187214Srwatson int *local_socket_typep); 293187214Srwatsonu_short au_domain_to_bsm(int local_domain); 294187214Srwatsonu_char au_errno_to_bsm(int local_errno); 295191273Srwatsonu_short au_fcntl_cmd_to_bsm(int local_fcntl_command); 296187214Srwatsonu_short au_socket_type_to_bsm(int local_socket_type); 297186647Srwatson 298184902Srwatson__END_DECLS 299184902Srwatson 300184902Srwatson#endif /* ! _BSM_AUDIT_RECORD_H_ */ 301