1185573Srwatson/*- 2191270Srwatson * Copyright (c) 2005-2009 Apple Inc. 3146759Srwatson * All rights reserved. 4146759Srwatson * 5146759Srwatson * Redistribution and use in source and binary forms, with or without 6146759Srwatson * modification, are permitted provided that the following conditions 7146759Srwatson * are met: 8146759Srwatson * 9155191Srwatson * 1. Redistributions of source code must retain the above copyright 10155191Srwatson * notice, this list of conditions and the following disclaimer. 11155191Srwatson * 2. Redistributions in binary form must reproduce the above copyright 12155191Srwatson * notice, this list of conditions and the following disclaimer in the 13155191Srwatson * documentation and/or other materials provided with the distribution. 14181053Srwatson * 3. Neither the name of Apple Inc. ("Apple") nor the names of 15155191Srwatson * its contributors may be used to endorse or promote products derived 16155191Srwatson * from this software without specific prior written permission. 17146759Srwatson * 18155191Srwatson * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 19155191Srwatson * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20155191Srwatson * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21155191Srwatson * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 22155191Srwatson * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23155191Srwatson * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24155191Srwatson * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25155191Srwatson * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26155191Srwatson * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27155191Srwatson * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28155191Srwatson * 29195740Srwatson * P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit.h#10 30146759Srwatson * $FreeBSD$ 31146759Srwatson */ 32146759Srwatson 33191270Srwatson#ifndef _BSM_AUDIT_H 34155191Srwatson#define _BSM_AUDIT_H 35146759Srwatson 36191270Srwatson#include <sys/param.h> 37186647Srwatson#include <sys/types.h> 38155191Srwatson 39155191Srwatson#define AUDIT_RECORD_MAGIC 0x828a0f1b 40155191Srwatson#define MAX_AUDIT_RECORDS 20 41161635Srwatson#define MAXAUDITDATA (0x8000 - 1) 42161635Srwatson#define MAX_AUDIT_RECORD_SIZE MAXAUDITDATA 43155191Srwatson#define MIN_AUDIT_FILE_SIZE (512 * 1024) 44155191Srwatson 45146759Srwatson/* 46155191Srwatson * Minimum noumber of free blocks on the filesystem containing the audit 47155191Srwatson * log necessary to avoid a hard log rotation. DO NOT SET THIS VALUE TO 0 48155191Srwatson * as the kernel does an unsigned compare, plus we want to leave a few blocks 49155191Srwatson * free so userspace can terminate the log, etc. 50146759Srwatson */ 51155191Srwatson#define AUDIT_HARD_LIMIT_FREE_BLOCKS 4 52155191Srwatson 53155191Srwatson/* 54161635Srwatson * Triggers for the audit daemon. 55155191Srwatson */ 56155191Srwatson#define AUDIT_TRIGGER_MIN 1 57162508Srwatson#define AUDIT_TRIGGER_LOW_SPACE 1 /* Below low watermark. */ 58162508Srwatson#define AUDIT_TRIGGER_ROTATE_KERNEL 2 /* Kernel requests rotate. */ 59162508Srwatson#define AUDIT_TRIGGER_READ_FILE 3 /* Re-read config file. */ 60162508Srwatson#define AUDIT_TRIGGER_CLOSE_AND_DIE 4 /* Terminate audit. */ 61162508Srwatson#define AUDIT_TRIGGER_NO_SPACE 5 /* Below min free space. */ 62186647Srwatson#define AUDIT_TRIGGER_ROTATE_USER 6 /* User requests rotate. */ 63189279Srwatson#define AUDIT_TRIGGER_INITIALIZE 7 /* User initialize of auditd. */ 64189279Srwatson#define AUDIT_TRIGGER_EXPIRE_TRAILS 8 /* User expiration of trails. */ 65189279Srwatson#define AUDIT_TRIGGER_MAX 8 66155191Srwatson 67155191Srwatson/* 68162508Srwatson * The special device filename (FreeBSD). 69155191Srwatson */ 70155191Srwatson#define AUDITDEV_FILENAME "audit" 71162508Srwatson#define AUDIT_TRIGGER_FILE ("/dev/" AUDITDEV_FILENAME) 72155191Srwatson 73155191Srwatson/* 74155191Srwatson * Pre-defined audit IDs 75155191Srwatson */ 76186647Srwatson#define AU_DEFAUDITID (uid_t)(-1) 77186647Srwatson#define AU_DEFAUDITSID 0 78186647Srwatson#define AU_ASSIGN_ASID -1 79155191Srwatson 80155191Srwatson/* 81161635Srwatson * IPC types. 82155191Srwatson */ 83155191Srwatson#define AT_IPC_MSG ((u_char)1) /* Message IPC id. */ 84155191Srwatson#define AT_IPC_SEM ((u_char)2) /* Semaphore IPC id. */ 85155191Srwatson#define AT_IPC_SHM ((u_char)3) /* Shared mem IPC id. */ 86155191Srwatson 87155191Srwatson/* 88155191Srwatson * Audit conditions. 89155191Srwatson */ 90155191Srwatson#define AUC_UNSET 0 91155191Srwatson#define AUC_AUDITING 1 92155191Srwatson#define AUC_NOAUDIT 2 93155191Srwatson#define AUC_DISABLED -1 94155191Srwatson 95155191Srwatson/* 96155191Srwatson * auditon(2) commands. 97155191Srwatson */ 98191270Srwatson#define A_OLDGETPOLICY 2 99191270Srwatson#define A_OLDSETPOLICY 3 100155191Srwatson#define A_GETKMASK 4 101155191Srwatson#define A_SETKMASK 5 102191270Srwatson#define A_OLDGETQCTRL 6 103191270Srwatson#define A_OLDSETQCTRL 7 104155191Srwatson#define A_GETCWD 8 105155191Srwatson#define A_GETCAR 9 106155191Srwatson#define A_GETSTAT 12 107155191Srwatson#define A_SETSTAT 13 108155191Srwatson#define A_SETUMASK 14 109155191Srwatson#define A_SETSMASK 15 110191270Srwatson#define A_OLDGETCOND 20 111191270Srwatson#define A_OLDSETCOND 21 112155191Srwatson#define A_GETCLASS 22 113155191Srwatson#define A_SETCLASS 23 114155191Srwatson#define A_GETPINFO 24 115155191Srwatson#define A_SETPMASK 25 116155191Srwatson#define A_SETFSIZE 26 117155191Srwatson#define A_GETFSIZE 27 118155191Srwatson#define A_GETPINFO_ADDR 28 119155191Srwatson#define A_GETKAUDIT 29 120155191Srwatson#define A_SETKAUDIT 30 121155191Srwatson#define A_SENDTRIGGER 31 122186647Srwatson#define A_GETSINFO_ADDR 32 123191270Srwatson#define A_GETPOLICY 33 124191270Srwatson#define A_SETPOLICY 34 125191270Srwatson#define A_GETQCTRL 35 126191270Srwatson#define A_SETQCTRL 36 127191270Srwatson#define A_GETCOND 37 128191270Srwatson#define A_SETCOND 38 129155191Srwatson 130155191Srwatson/* 131155191Srwatson * Audit policy controls. 132155191Srwatson */ 133155191Srwatson#define AUDIT_CNT 0x0001 134155191Srwatson#define AUDIT_AHLT 0x0002 135155191Srwatson#define AUDIT_ARGV 0x0004 136155191Srwatson#define AUDIT_ARGE 0x0008 137161635Srwatson#define AUDIT_SEQ 0x0010 138161635Srwatson#define AUDIT_WINDATA 0x0020 139161635Srwatson#define AUDIT_USER 0x0040 140161635Srwatson#define AUDIT_GROUP 0x0080 141161635Srwatson#define AUDIT_TRAIL 0x0100 142161635Srwatson#define AUDIT_PATH 0x0200 143161635Srwatson#define AUDIT_SCNT 0x0400 144161635Srwatson#define AUDIT_PUBLIC 0x0800 145161635Srwatson#define AUDIT_ZONENAME 0x1000 146161635Srwatson#define AUDIT_PERZONE 0x2000 147155191Srwatson 148155191Srwatson/* 149162508Srwatson * Default audit queue control parameters. 150155191Srwatson */ 151155191Srwatson#define AQ_HIWATER 100 152155191Srwatson#define AQ_MAXHIGH 10000 153155191Srwatson#define AQ_LOWATER 10 154162508Srwatson#define AQ_BUFSZ MAXAUDITDATA 155155191Srwatson#define AQ_MAXBUFSZ 1048576 156155191Srwatson 157155191Srwatson/* 158155191Srwatson * Default minimum percentage free space on file system. 159155191Srwatson */ 160155191Srwatson#define AU_FS_MINFREE 20 161155191Srwatson 162155191Srwatson/* 163155191Srwatson * Type definitions used indicating the length of variable length addresses 164155191Srwatson * in tokens containing addresses, such as header fields. 165155191Srwatson */ 166155191Srwatson#define AU_IPv4 4 167155191Srwatson#define AU_IPv6 16 168155191Srwatson 169155191Srwatson__BEGIN_DECLS 170155191Srwatson 171155191Srwatsontypedef uid_t au_id_t; 172155191Srwatsontypedef pid_t au_asid_t; 173146759Srwatsontypedef u_int16_t au_event_t; 174155191Srwatsontypedef u_int16_t au_emod_t; 175155191Srwatsontypedef u_int32_t au_class_t; 176195740Srwatsontypedef u_int64_t au_asflgs_t __attribute__ ((aligned (8))); 177146759Srwatson 178155191Srwatsonstruct au_tid { 179155191Srwatson dev_t port; 180155191Srwatson u_int32_t machine; 181155191Srwatson}; 182155191Srwatsontypedef struct au_tid au_tid_t; 183155191Srwatson 184155191Srwatsonstruct au_tid_addr { 185155191Srwatson dev_t at_port; 186155191Srwatson u_int32_t at_type; 187155191Srwatson u_int32_t at_addr[4]; 188155191Srwatson}; 189155191Srwatsontypedef struct au_tid_addr au_tid_addr_t; 190155191Srwatson 191155191Srwatsonstruct au_mask { 192155191Srwatson unsigned int am_success; /* Success bits. */ 193155191Srwatson unsigned int am_failure; /* Failure bits. */ 194155191Srwatson}; 195155191Srwatsontypedef struct au_mask au_mask_t; 196155191Srwatson 197155191Srwatsonstruct auditinfo { 198155191Srwatson au_id_t ai_auid; /* Audit user ID. */ 199155191Srwatson au_mask_t ai_mask; /* Audit masks. */ 200155191Srwatson au_tid_t ai_termid; /* Terminal ID. */ 201155191Srwatson au_asid_t ai_asid; /* Audit session ID. */ 202155191Srwatson}; 203155191Srwatsontypedef struct auditinfo auditinfo_t; 204155191Srwatson 205155191Srwatsonstruct auditinfo_addr { 206155191Srwatson au_id_t ai_auid; /* Audit user ID. */ 207155191Srwatson au_mask_t ai_mask; /* Audit masks. */ 208155191Srwatson au_tid_addr_t ai_termid; /* Terminal ID. */ 209155191Srwatson au_asid_t ai_asid; /* Audit session ID. */ 210195740Srwatson au_asflgs_t ai_flags; /* Audit session flags. */ 211155191Srwatson}; 212155191Srwatsontypedef struct auditinfo_addr auditinfo_addr_t; 213155191Srwatson 214155191Srwatsonstruct auditpinfo { 215155191Srwatson pid_t ap_pid; /* ID of target process. */ 216155191Srwatson au_id_t ap_auid; /* Audit user ID. */ 217155191Srwatson au_mask_t ap_mask; /* Audit masks. */ 218155191Srwatson au_tid_t ap_termid; /* Terminal ID. */ 219155191Srwatson au_asid_t ap_asid; /* Audit session ID. */ 220155191Srwatson}; 221155191Srwatsontypedef struct auditpinfo auditpinfo_t; 222155191Srwatson 223155191Srwatsonstruct auditpinfo_addr { 224155191Srwatson pid_t ap_pid; /* ID of target process. */ 225155191Srwatson au_id_t ap_auid; /* Audit user ID. */ 226155191Srwatson au_mask_t ap_mask; /* Audit masks. */ 227155191Srwatson au_tid_addr_t ap_termid; /* Terminal ID. */ 228155191Srwatson au_asid_t ap_asid; /* Audit session ID. */ 229195740Srwatson au_asflgs_t ap_flags; /* Audit session flags. */ 230155191Srwatson}; 231155191Srwatsontypedef struct auditpinfo_addr auditpinfo_addr_t; 232155191Srwatson 233186647Srwatsonstruct au_session { 234186647Srwatson auditinfo_addr_t *as_aia_p; /* Ptr to full audit info. */ 235186647Srwatson au_mask_t as_mask; /* Process Audit Masks. */ 236186647Srwatson}; 237186647Srwatsontypedef struct au_session au_session_t; 238186647Srwatson 239156289Srwatson/* 240156289Srwatson * Contents of token_t are opaque outside of libbsm. 241156289Srwatson */ 242155191Srwatsontypedef struct au_token token_t; 243155191Srwatson 244155191Srwatson/* 245191270Srwatson * Kernel audit queue control parameters: 246191270Srwatson * Default: Maximum: 247191270Srwatson * aq_hiwater: AQ_HIWATER (100) AQ_MAXHIGH (10000) 248191270Srwatson * aq_lowater: AQ_LOWATER (10) <aq_hiwater 249191270Srwatson * aq_bufsz: AQ_BUFSZ (32767) AQ_MAXBUFSZ (1048576) 250191270Srwatson * aq_delay: 20 20000 (not used) 251155191Srwatson */ 252155191Srwatsonstruct au_qctrl { 253191270Srwatson int aq_hiwater; /* Max # of audit recs in queue when */ 254191270Srwatson /* threads with new ARs get blocked. */ 255191270Srwatson 256191270Srwatson int aq_lowater; /* # of audit recs in queue when */ 257191270Srwatson /* blocked threads get unblocked. */ 258191270Srwatson 259191270Srwatson int aq_bufsz; /* Max size of audit record for audit(2). */ 260191270Srwatson int aq_delay; /* Queue delay (not used). */ 261155191Srwatson int aq_minfree; /* Minimum filesystem percent free space. */ 262155191Srwatson}; 263155191Srwatsontypedef struct au_qctrl au_qctrl_t; 264155191Srwatson 265155191Srwatson/* 266155191Srwatson * Structure for the audit statistics. 267155191Srwatson */ 268155191Srwatsonstruct audit_stat { 269155191Srwatson unsigned int as_version; 270155191Srwatson unsigned int as_numevent; 271155191Srwatson int as_generated; 272159256Srwatson int as_nonattrib; 273155191Srwatson int as_kernel; 274155191Srwatson int as_audit; 275155191Srwatson int as_auditctl; 276159256Srwatson int as_enqueue; 277155191Srwatson int as_written; 278155191Srwatson int as_wblocked; 279155191Srwatson int as_rblocked; 280155191Srwatson int as_dropped; 281155191Srwatson int as_totalsize; 282155191Srwatson unsigned int as_memused; 283155191Srwatson}; 284155191Srwatsontypedef struct audit_stat au_stat_t; 285155191Srwatson 286155191Srwatson/* 287155191Srwatson * Structure for the audit file statistics. 288155191Srwatson */ 289155191Srwatsonstruct audit_fstat { 290187214Srwatson u_int64_t af_filesz; 291187214Srwatson u_int64_t af_currsz; 292155191Srwatson}; 293155191Srwatsontypedef struct audit_fstat au_fstat_t; 294155191Srwatson 295155191Srwatson/* 296155191Srwatson * Audit to event class mapping. 297155191Srwatson */ 298155191Srwatsonstruct au_evclass_map { 299155191Srwatson au_event_t ec_number; 300155191Srwatson au_class_t ec_class; 301155191Srwatson}; 302155191Srwatsontypedef struct au_evclass_map au_evclass_map_t; 303155191Srwatson 304156289Srwatson/* 305156289Srwatson * Audit system calls. 306156289Srwatson */ 307155191Srwatson#if !defined(_KERNEL) && !defined(KERNEL) 308155191Srwatsonint audit(const void *, int); 309155191Srwatsonint auditon(int, void *, int); 310155191Srwatsonint auditctl(const char *); 311155191Srwatsonint getauid(au_id_t *); 312155191Srwatsonint setauid(const au_id_t *); 313155191Srwatsonint getaudit(struct auditinfo *); 314155191Srwatsonint setaudit(const struct auditinfo *); 315155191Srwatsonint getaudit_addr(struct auditinfo_addr *, int); 316155191Srwatsonint setaudit_addr(const struct auditinfo_addr *, int); 317191270Srwatson 318191270Srwatson#ifdef __APPLE_API_PRIVATE 319191270Srwatson#include <mach/port.h> 320191270Srwatsonmach_port_name_t audit_session_self(void); 321191270Srwatsonau_asid_t audit_session_join(mach_port_name_t port); 322191270Srwatson#endif /* __APPLE_API_PRIVATE */ 323191270Srwatson 324155191Srwatson#endif /* defined(_KERNEL) || defined(KERNEL) */ 325155191Srwatson 326155191Srwatson__END_DECLS 327155191Srwatson 328155191Srwatson#endif /* !_BSM_AUDIT_H */ 329