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 */ 29184902Srwatson 30191273Srwatson#ifndef _BSM_AUDIT_H 31184902Srwatson#define _BSM_AUDIT_H 32184902Srwatson 33191273Srwatson#include <sys/param.h> 34186647Srwatson#include <sys/types.h> 35186647Srwatson 36184902Srwatson#define AUDIT_RECORD_MAGIC 0x828a0f1b 37184902Srwatson#define MAX_AUDIT_RECORDS 20 38184902Srwatson#define MAXAUDITDATA (0x8000 - 1) 39184902Srwatson#define MAX_AUDIT_RECORD_SIZE MAXAUDITDATA 40184902Srwatson#define MIN_AUDIT_FILE_SIZE (512 * 1024) 41184902Srwatson 42184902Srwatson/* 43186647Srwatson * Minimum noumber of free blocks on the filesystem containing the audit 44186647Srwatson * log necessary to avoid a hard log rotation. DO NOT SET THIS VALUE TO 0 45186647Srwatson * as the kernel does an unsigned compare, plus we want to leave a few blocks 46186647Srwatson * free so userspace can terminate the log, etc. 47186647Srwatson */ 48186647Srwatson#define AUDIT_HARD_LIMIT_FREE_BLOCKS 4 49186647Srwatson 50186647Srwatson/* 51184902Srwatson * Triggers for the audit daemon. 52184902Srwatson */ 53184902Srwatson#define AUDIT_TRIGGER_MIN 1 54184902Srwatson#define AUDIT_TRIGGER_LOW_SPACE 1 /* Below low watermark. */ 55184902Srwatson#define AUDIT_TRIGGER_ROTATE_KERNEL 2 /* Kernel requests rotate. */ 56184902Srwatson#define AUDIT_TRIGGER_READ_FILE 3 /* Re-read config file. */ 57184902Srwatson#define AUDIT_TRIGGER_CLOSE_AND_DIE 4 /* Terminate audit. */ 58184902Srwatson#define AUDIT_TRIGGER_NO_SPACE 5 /* Below min free space. */ 59186647Srwatson#define AUDIT_TRIGGER_ROTATE_USER 6 /* User requests rotate. */ 60189279Srwatson#define AUDIT_TRIGGER_INITIALIZE 7 /* User initialize of auditd. */ 61189279Srwatson#define AUDIT_TRIGGER_EXPIRE_TRAILS 8 /* User expiration of trails. */ 62189279Srwatson#define AUDIT_TRIGGER_MAX 8 63184902Srwatson 64184902Srwatson/* 65184902Srwatson * The special device filename (FreeBSD). 66184902Srwatson */ 67184902Srwatson#define AUDITDEV_FILENAME "audit" 68184902Srwatson#define AUDIT_TRIGGER_FILE ("/dev/" AUDITDEV_FILENAME) 69184902Srwatson 70184902Srwatson/* 71184902Srwatson * Pre-defined audit IDs 72184902Srwatson */ 73186647Srwatson#define AU_DEFAUDITID (uid_t)(-1) 74186647Srwatson#define AU_DEFAUDITSID 0 75186647Srwatson#define AU_ASSIGN_ASID -1 76184902Srwatson 77184902Srwatson/* 78184902Srwatson * IPC types. 79184902Srwatson */ 80184902Srwatson#define AT_IPC_MSG ((u_char)1) /* Message IPC id. */ 81184902Srwatson#define AT_IPC_SEM ((u_char)2) /* Semaphore IPC id. */ 82184902Srwatson#define AT_IPC_SHM ((u_char)3) /* Shared mem IPC id. */ 83184902Srwatson 84184902Srwatson/* 85184902Srwatson * Audit conditions. 86184902Srwatson */ 87184902Srwatson#define AUC_UNSET 0 88184902Srwatson#define AUC_AUDITING 1 89184902Srwatson#define AUC_NOAUDIT 2 90184902Srwatson#define AUC_DISABLED -1 91184902Srwatson 92184902Srwatson/* 93184902Srwatson * auditon(2) commands. 94184902Srwatson */ 95191273Srwatson#define A_OLDGETPOLICY 2 96191273Srwatson#define A_OLDSETPOLICY 3 97184902Srwatson#define A_GETKMASK 4 98184902Srwatson#define A_SETKMASK 5 99191273Srwatson#define A_OLDGETQCTRL 6 100191273Srwatson#define A_OLDSETQCTRL 7 101184902Srwatson#define A_GETCWD 8 102184902Srwatson#define A_GETCAR 9 103184902Srwatson#define A_GETSTAT 12 104184902Srwatson#define A_SETSTAT 13 105184902Srwatson#define A_SETUMASK 14 106184902Srwatson#define A_SETSMASK 15 107191273Srwatson#define A_OLDGETCOND 20 108191273Srwatson#define A_OLDSETCOND 21 109184902Srwatson#define A_GETCLASS 22 110184902Srwatson#define A_SETCLASS 23 111184902Srwatson#define A_GETPINFO 24 112184902Srwatson#define A_SETPMASK 25 113184902Srwatson#define A_SETFSIZE 26 114184902Srwatson#define A_GETFSIZE 27 115184902Srwatson#define A_GETPINFO_ADDR 28 116184902Srwatson#define A_GETKAUDIT 29 117184902Srwatson#define A_SETKAUDIT 30 118184902Srwatson#define A_SENDTRIGGER 31 119186647Srwatson#define A_GETSINFO_ADDR 32 120191273Srwatson#define A_GETPOLICY 33 121191273Srwatson#define A_SETPOLICY 34 122191273Srwatson#define A_GETQCTRL 35 123191273Srwatson#define A_SETQCTRL 36 124191273Srwatson#define A_GETCOND 37 125191273Srwatson#define A_SETCOND 38 126184902Srwatson 127184902Srwatson/* 128184902Srwatson * Audit policy controls. 129184902Srwatson */ 130184902Srwatson#define AUDIT_CNT 0x0001 131184902Srwatson#define AUDIT_AHLT 0x0002 132184902Srwatson#define AUDIT_ARGV 0x0004 133184902Srwatson#define AUDIT_ARGE 0x0008 134184902Srwatson#define AUDIT_SEQ 0x0010 135184902Srwatson#define AUDIT_WINDATA 0x0020 136184902Srwatson#define AUDIT_USER 0x0040 137184902Srwatson#define AUDIT_GROUP 0x0080 138184902Srwatson#define AUDIT_TRAIL 0x0100 139184902Srwatson#define AUDIT_PATH 0x0200 140184902Srwatson#define AUDIT_SCNT 0x0400 141184902Srwatson#define AUDIT_PUBLIC 0x0800 142184902Srwatson#define AUDIT_ZONENAME 0x1000 143184902Srwatson#define AUDIT_PERZONE 0x2000 144184902Srwatson 145184902Srwatson/* 146184902Srwatson * Default audit queue control parameters. 147184902Srwatson */ 148184902Srwatson#define AQ_HIWATER 100 149184902Srwatson#define AQ_MAXHIGH 10000 150184902Srwatson#define AQ_LOWATER 10 151184902Srwatson#define AQ_BUFSZ MAXAUDITDATA 152184902Srwatson#define AQ_MAXBUFSZ 1048576 153184902Srwatson 154184902Srwatson/* 155184902Srwatson * Default minimum percentage free space on file system. 156184902Srwatson */ 157184902Srwatson#define AU_FS_MINFREE 20 158184902Srwatson 159184902Srwatson/* 160184902Srwatson * Type definitions used indicating the length of variable length addresses 161184902Srwatson * in tokens containing addresses, such as header fields. 162184902Srwatson */ 163184902Srwatson#define AU_IPv4 4 164184902Srwatson#define AU_IPv6 16 165184902Srwatson 166184902Srwatson__BEGIN_DECLS 167184902Srwatson 168184902Srwatsontypedef uid_t au_id_t; 169184902Srwatsontypedef pid_t au_asid_t; 170184902Srwatsontypedef u_int16_t au_event_t; 171184902Srwatsontypedef u_int16_t au_emod_t; 172184902Srwatsontypedef u_int32_t au_class_t; 173195740Srwatsontypedef u_int64_t au_asflgs_t __attribute__ ((aligned (8))); 174184902Srwatson 175184902Srwatsonstruct au_tid { 176184902Srwatson dev_t port; 177184902Srwatson u_int32_t machine; 178184902Srwatson}; 179184902Srwatsontypedef struct au_tid au_tid_t; 180184902Srwatson 181184902Srwatsonstruct au_tid_addr { 182184902Srwatson dev_t at_port; 183184902Srwatson u_int32_t at_type; 184184902Srwatson u_int32_t at_addr[4]; 185184902Srwatson}; 186184902Srwatsontypedef struct au_tid_addr au_tid_addr_t; 187184902Srwatson 188184902Srwatsonstruct au_mask { 189184902Srwatson unsigned int am_success; /* Success bits. */ 190184902Srwatson unsigned int am_failure; /* Failure bits. */ 191184902Srwatson}; 192184902Srwatsontypedef struct au_mask au_mask_t; 193184902Srwatson 194184902Srwatsonstruct auditinfo { 195184902Srwatson au_id_t ai_auid; /* Audit user ID. */ 196184902Srwatson au_mask_t ai_mask; /* Audit masks. */ 197184902Srwatson au_tid_t ai_termid; /* Terminal ID. */ 198184902Srwatson au_asid_t ai_asid; /* Audit session ID. */ 199184902Srwatson}; 200184902Srwatsontypedef struct auditinfo auditinfo_t; 201184902Srwatson 202184902Srwatsonstruct auditinfo_addr { 203184902Srwatson au_id_t ai_auid; /* Audit user ID. */ 204184902Srwatson au_mask_t ai_mask; /* Audit masks. */ 205184902Srwatson au_tid_addr_t ai_termid; /* Terminal ID. */ 206184902Srwatson au_asid_t ai_asid; /* Audit session ID. */ 207195740Srwatson au_asflgs_t ai_flags; /* Audit session flags. */ 208184902Srwatson}; 209184902Srwatsontypedef struct auditinfo_addr auditinfo_addr_t; 210184902Srwatson 211184902Srwatsonstruct auditpinfo { 212184902Srwatson pid_t ap_pid; /* ID of target process. */ 213184902Srwatson au_id_t ap_auid; /* Audit user ID. */ 214184902Srwatson au_mask_t ap_mask; /* Audit masks. */ 215184902Srwatson au_tid_t ap_termid; /* Terminal ID. */ 216184902Srwatson au_asid_t ap_asid; /* Audit session ID. */ 217184902Srwatson}; 218184902Srwatsontypedef struct auditpinfo auditpinfo_t; 219184902Srwatson 220184902Srwatsonstruct auditpinfo_addr { 221184902Srwatson pid_t ap_pid; /* ID of target process. */ 222184902Srwatson au_id_t ap_auid; /* Audit user ID. */ 223184902Srwatson au_mask_t ap_mask; /* Audit masks. */ 224184902Srwatson au_tid_addr_t ap_termid; /* Terminal ID. */ 225184902Srwatson au_asid_t ap_asid; /* Audit session ID. */ 226195740Srwatson au_asflgs_t ap_flags; /* Audit session flags. */ 227184902Srwatson}; 228184902Srwatsontypedef struct auditpinfo_addr auditpinfo_addr_t; 229184902Srwatson 230186647Srwatsonstruct au_session { 231186647Srwatson auditinfo_addr_t *as_aia_p; /* Ptr to full audit info. */ 232186647Srwatson au_mask_t as_mask; /* Process Audit Masks. */ 233186647Srwatson}; 234186647Srwatsontypedef struct au_session au_session_t; 235186647Srwatson 236184902Srwatson/* 237184902Srwatson * Contents of token_t are opaque outside of libbsm. 238184902Srwatson */ 239184902Srwatsontypedef struct au_token token_t; 240184902Srwatson 241184902Srwatson/* 242191273Srwatson * Kernel audit queue control parameters: 243191273Srwatson * Default: Maximum: 244191273Srwatson * aq_hiwater: AQ_HIWATER (100) AQ_MAXHIGH (10000) 245191273Srwatson * aq_lowater: AQ_LOWATER (10) <aq_hiwater 246191273Srwatson * aq_bufsz: AQ_BUFSZ (32767) AQ_MAXBUFSZ (1048576) 247191273Srwatson * aq_delay: 20 20000 (not used) 248184902Srwatson */ 249184902Srwatsonstruct au_qctrl { 250191273Srwatson int aq_hiwater; /* Max # of audit recs in queue when */ 251191273Srwatson /* threads with new ARs get blocked. */ 252191273Srwatson 253191273Srwatson int aq_lowater; /* # of audit recs in queue when */ 254191273Srwatson /* blocked threads get unblocked. */ 255191273Srwatson 256191273Srwatson int aq_bufsz; /* Max size of audit record for audit(2). */ 257191273Srwatson int aq_delay; /* Queue delay (not used). */ 258184902Srwatson int aq_minfree; /* Minimum filesystem percent free space. */ 259184902Srwatson}; 260184902Srwatsontypedef struct au_qctrl au_qctrl_t; 261184902Srwatson 262184902Srwatson/* 263184902Srwatson * Structure for the audit statistics. 264184902Srwatson */ 265184902Srwatsonstruct audit_stat { 266184902Srwatson unsigned int as_version; 267184902Srwatson unsigned int as_numevent; 268184902Srwatson int as_generated; 269184902Srwatson int as_nonattrib; 270184902Srwatson int as_kernel; 271184902Srwatson int as_audit; 272184902Srwatson int as_auditctl; 273184902Srwatson int as_enqueue; 274184902Srwatson int as_written; 275184902Srwatson int as_wblocked; 276184902Srwatson int as_rblocked; 277184902Srwatson int as_dropped; 278184902Srwatson int as_totalsize; 279184902Srwatson unsigned int as_memused; 280184902Srwatson}; 281184902Srwatsontypedef struct audit_stat au_stat_t; 282184902Srwatson 283184902Srwatson/* 284184902Srwatson * Structure for the audit file statistics. 285184902Srwatson */ 286184902Srwatsonstruct audit_fstat { 287187214Srwatson u_int64_t af_filesz; 288187214Srwatson u_int64_t af_currsz; 289184902Srwatson}; 290184902Srwatsontypedef struct audit_fstat au_fstat_t; 291184902Srwatson 292184902Srwatson/* 293184902Srwatson * Audit to event class mapping. 294184902Srwatson */ 295184902Srwatsonstruct au_evclass_map { 296184902Srwatson au_event_t ec_number; 297184902Srwatson au_class_t ec_class; 298184902Srwatson}; 299184902Srwatsontypedef struct au_evclass_map au_evclass_map_t; 300184902Srwatson 301184902Srwatson/* 302184902Srwatson * Audit system calls. 303184902Srwatson */ 304184902Srwatson#if !defined(_KERNEL) && !defined(KERNEL) 305184902Srwatsonint audit(const void *, int); 306184902Srwatsonint auditon(int, void *, int); 307184902Srwatsonint auditctl(const char *); 308184902Srwatsonint getauid(au_id_t *); 309184902Srwatsonint setauid(const au_id_t *); 310184902Srwatsonint getaudit(struct auditinfo *); 311184902Srwatsonint setaudit(const struct auditinfo *); 312184902Srwatsonint getaudit_addr(struct auditinfo_addr *, int); 313184902Srwatsonint setaudit_addr(const struct auditinfo_addr *, int); 314191273Srwatson 315191273Srwatson#ifdef __APPLE_API_PRIVATE 316191273Srwatson#include <mach/port.h> 317191273Srwatsonmach_port_name_t audit_session_self(void); 318191273Srwatsonau_asid_t audit_session_join(mach_port_name_t port); 319191273Srwatson#endif /* __APPLE_API_PRIVATE */ 320191273Srwatson 321184902Srwatson#endif /* defined(_KERNEL) || defined(KERNEL) */ 322184902Srwatson 323184902Srwatson__END_DECLS 324184902Srwatson 325184902Srwatson#endif /* !_BSM_AUDIT_H */ 326