audit.h revision 189279
1185573Srwatson/*- 2181053Srwatson * Copyright (c) 2005 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 * 29189279Srwatson * P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit.h#5 30146759Srwatson * $FreeBSD: head/sys/bsm/audit.h 189279 2009-03-02 13:29:18Z rwatson $ 31146759Srwatson */ 32146759Srwatson 33155191Srwatson#ifndef _BSM_AUDIT_H 34155191Srwatson#define _BSM_AUDIT_H 35146759Srwatson 36186647Srwatson#ifdef __APPLE__ 37186647Srwatson/* Temporary until rdar://problem/6133383 is resolved. */ 38186647Srwatson#include <sys/types.h> 39155191Srwatson#include <sys/param.h> 40186647Srwatson#include <sys/socket.h> 41155191Srwatson#include <sys/cdefs.h> 42155191Srwatson#include <sys/queue.h> 43186647Srwatson#endif /* __APPLE__ */ 44155191Srwatson 45155191Srwatson#define AUDIT_RECORD_MAGIC 0x828a0f1b 46155191Srwatson#define MAX_AUDIT_RECORDS 20 47161635Srwatson#define MAXAUDITDATA (0x8000 - 1) 48161635Srwatson#define MAX_AUDIT_RECORD_SIZE MAXAUDITDATA 49155191Srwatson#define MIN_AUDIT_FILE_SIZE (512 * 1024) 50155191Srwatson 51146759Srwatson/* 52155191Srwatson * Minimum noumber of free blocks on the filesystem containing the audit 53155191Srwatson * log necessary to avoid a hard log rotation. DO NOT SET THIS VALUE TO 0 54155191Srwatson * as the kernel does an unsigned compare, plus we want to leave a few blocks 55155191Srwatson * free so userspace can terminate the log, etc. 56146759Srwatson */ 57155191Srwatson#define AUDIT_HARD_LIMIT_FREE_BLOCKS 4 58155191Srwatson 59155191Srwatson/* 60161635Srwatson * Triggers for the audit daemon. 61155191Srwatson */ 62155191Srwatson#define AUDIT_TRIGGER_MIN 1 63162508Srwatson#define AUDIT_TRIGGER_LOW_SPACE 1 /* Below low watermark. */ 64162508Srwatson#define AUDIT_TRIGGER_ROTATE_KERNEL 2 /* Kernel requests rotate. */ 65162508Srwatson#define AUDIT_TRIGGER_READ_FILE 3 /* Re-read config file. */ 66162508Srwatson#define AUDIT_TRIGGER_CLOSE_AND_DIE 4 /* Terminate audit. */ 67162508Srwatson#define AUDIT_TRIGGER_NO_SPACE 5 /* Below min free space. */ 68186647Srwatson#define AUDIT_TRIGGER_ROTATE_USER 6 /* User requests rotate. */ 69189279Srwatson#define AUDIT_TRIGGER_INITIALIZE 7 /* User initialize of auditd. */ 70189279Srwatson#define AUDIT_TRIGGER_EXPIRE_TRAILS 8 /* User expiration of trails. */ 71189279Srwatson#define AUDIT_TRIGGER_MAX 8 72155191Srwatson 73155191Srwatson/* 74162508Srwatson * The special device filename (FreeBSD). 75155191Srwatson */ 76155191Srwatson#define AUDITDEV_FILENAME "audit" 77162508Srwatson#define AUDIT_TRIGGER_FILE ("/dev/" AUDITDEV_FILENAME) 78155191Srwatson 79155191Srwatson/* 80155191Srwatson * Pre-defined audit IDs 81155191Srwatson */ 82186647Srwatson#define AU_DEFAUDITID (uid_t)(-1) 83186647Srwatson#define AU_DEFAUDITSID 0 84186647Srwatson#define AU_ASSIGN_ASID -1 85155191Srwatson 86155191Srwatson/* 87161635Srwatson * IPC types. 88155191Srwatson */ 89155191Srwatson#define AT_IPC_MSG ((u_char)1) /* Message IPC id. */ 90155191Srwatson#define AT_IPC_SEM ((u_char)2) /* Semaphore IPC id. */ 91155191Srwatson#define AT_IPC_SHM ((u_char)3) /* Shared mem IPC id. */ 92155191Srwatson 93155191Srwatson/* 94155191Srwatson * Audit conditions. 95155191Srwatson */ 96155191Srwatson#define AUC_UNSET 0 97155191Srwatson#define AUC_AUDITING 1 98155191Srwatson#define AUC_NOAUDIT 2 99155191Srwatson#define AUC_DISABLED -1 100155191Srwatson 101155191Srwatson/* 102155191Srwatson * auditon(2) commands. 103155191Srwatson */ 104155191Srwatson#define A_GETPOLICY 2 105155191Srwatson#define A_SETPOLICY 3 106155191Srwatson#define A_GETKMASK 4 107155191Srwatson#define A_SETKMASK 5 108155191Srwatson#define A_GETQCTRL 6 109155191Srwatson#define A_SETQCTRL 7 110155191Srwatson#define A_GETCWD 8 111155191Srwatson#define A_GETCAR 9 112155191Srwatson#define A_GETSTAT 12 113155191Srwatson#define A_SETSTAT 13 114155191Srwatson#define A_SETUMASK 14 115155191Srwatson#define A_SETSMASK 15 116155191Srwatson#define A_GETCOND 20 117155191Srwatson#define A_SETCOND 21 118155191Srwatson#define A_GETCLASS 22 119155191Srwatson#define A_SETCLASS 23 120155191Srwatson#define A_GETPINFO 24 121155191Srwatson#define A_SETPMASK 25 122155191Srwatson#define A_SETFSIZE 26 123155191Srwatson#define A_GETFSIZE 27 124155191Srwatson#define A_GETPINFO_ADDR 28 125155191Srwatson#define A_GETKAUDIT 29 126155191Srwatson#define A_SETKAUDIT 30 127155191Srwatson#define A_SENDTRIGGER 31 128186647Srwatson#define A_GETSINFO_ADDR 32 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; 176146759Srwatson 177155191Srwatsonstruct au_tid { 178155191Srwatson dev_t port; 179155191Srwatson u_int32_t machine; 180155191Srwatson}; 181155191Srwatsontypedef struct au_tid au_tid_t; 182155191Srwatson 183155191Srwatsonstruct au_tid_addr { 184155191Srwatson dev_t at_port; 185155191Srwatson u_int32_t at_type; 186155191Srwatson u_int32_t at_addr[4]; 187155191Srwatson}; 188155191Srwatsontypedef struct au_tid_addr au_tid_addr_t; 189155191Srwatson 190155191Srwatsonstruct au_mask { 191155191Srwatson unsigned int am_success; /* Success bits. */ 192155191Srwatson unsigned int am_failure; /* Failure bits. */ 193155191Srwatson}; 194155191Srwatsontypedef struct au_mask au_mask_t; 195155191Srwatson 196155191Srwatsonstruct auditinfo { 197155191Srwatson au_id_t ai_auid; /* Audit user ID. */ 198155191Srwatson au_mask_t ai_mask; /* Audit masks. */ 199155191Srwatson au_tid_t ai_termid; /* Terminal ID. */ 200155191Srwatson au_asid_t ai_asid; /* Audit session ID. */ 201155191Srwatson}; 202155191Srwatsontypedef struct auditinfo auditinfo_t; 203155191Srwatson 204155191Srwatsonstruct auditinfo_addr { 205155191Srwatson au_id_t ai_auid; /* Audit user ID. */ 206155191Srwatson au_mask_t ai_mask; /* Audit masks. */ 207155191Srwatson au_tid_addr_t ai_termid; /* Terminal ID. */ 208155191Srwatson au_asid_t ai_asid; /* Audit session ID. */ 209186647Srwatson u_int64_t ai_flags; /* Audit session flags. */ 210155191Srwatson}; 211155191Srwatsontypedef struct auditinfo_addr auditinfo_addr_t; 212155191Srwatson 213155191Srwatsonstruct auditpinfo { 214155191Srwatson pid_t ap_pid; /* ID of target process. */ 215155191Srwatson au_id_t ap_auid; /* Audit user ID. */ 216155191Srwatson au_mask_t ap_mask; /* Audit masks. */ 217155191Srwatson au_tid_t ap_termid; /* Terminal ID. */ 218155191Srwatson au_asid_t ap_asid; /* Audit session ID. */ 219186647Srwatson u_int64_t ap_flags; /* Audit session flags. */ 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. */ 229155191Srwatson}; 230155191Srwatsontypedef struct auditpinfo_addr auditpinfo_addr_t; 231155191Srwatson 232186647Srwatsonstruct au_session { 233186647Srwatson auditinfo_addr_t *as_aia_p; /* Ptr to full audit info. */ 234186647Srwatson#define as_asid as_aia_p->ai_asid 235186647Srwatson#define as_auid as_aia_p->ai_auid 236186647Srwatson#define as_termid as_aia_p->ai_termid 237186647Srwatson 238186647Srwatson au_mask_t as_mask; /* Process Audit Masks. */ 239186647Srwatson}; 240186647Srwatsontypedef struct au_session au_session_t; 241186647Srwatson 242156289Srwatson/* 243156289Srwatson * Contents of token_t are opaque outside of libbsm. 244156289Srwatson */ 245155191Srwatsontypedef struct au_token token_t; 246155191Srwatson 247155191Srwatson/* 248155191Srwatson * Kernel audit queue control parameters. 249155191Srwatson */ 250155191Srwatsonstruct au_qctrl { 251155191Srwatson size_t aq_hiwater; 252155191Srwatson size_t aq_lowater; 253155191Srwatson size_t aq_bufsz; 254155191Srwatson clock_t aq_delay; 255155191Srwatson int aq_minfree; /* Minimum filesystem percent free space. */ 256155191Srwatson}; 257155191Srwatsontypedef struct au_qctrl au_qctrl_t; 258155191Srwatson 259155191Srwatson/* 260155191Srwatson * Structure for the audit statistics. 261155191Srwatson */ 262155191Srwatsonstruct audit_stat { 263155191Srwatson unsigned int as_version; 264155191Srwatson unsigned int as_numevent; 265155191Srwatson int as_generated; 266159256Srwatson int as_nonattrib; 267155191Srwatson int as_kernel; 268155191Srwatson int as_audit; 269155191Srwatson int as_auditctl; 270159256Srwatson int as_enqueue; 271155191Srwatson int as_written; 272155191Srwatson int as_wblocked; 273155191Srwatson int as_rblocked; 274155191Srwatson int as_dropped; 275155191Srwatson int as_totalsize; 276155191Srwatson unsigned int as_memused; 277155191Srwatson}; 278155191Srwatsontypedef struct audit_stat au_stat_t; 279155191Srwatson 280155191Srwatson/* 281155191Srwatson * Structure for the audit file statistics. 282155191Srwatson */ 283155191Srwatsonstruct audit_fstat { 284187214Srwatson u_int64_t af_filesz; 285187214Srwatson u_int64_t af_currsz; 286155191Srwatson}; 287155191Srwatsontypedef struct audit_fstat au_fstat_t; 288155191Srwatson 289155191Srwatson/* 290155191Srwatson * Audit to event class mapping. 291155191Srwatson */ 292155191Srwatsonstruct au_evclass_map { 293155191Srwatson au_event_t ec_number; 294155191Srwatson au_class_t ec_class; 295155191Srwatson}; 296155191Srwatsontypedef struct au_evclass_map au_evclass_map_t; 297155191Srwatson 298156289Srwatson/* 299156289Srwatson * Audit system calls. 300156289Srwatson */ 301155191Srwatson#if !defined(_KERNEL) && !defined(KERNEL) 302155191Srwatsonint audit(const void *, int); 303155191Srwatsonint auditon(int, void *, int); 304155191Srwatsonint auditctl(const char *); 305155191Srwatsonint getauid(au_id_t *); 306155191Srwatsonint setauid(const au_id_t *); 307155191Srwatsonint getaudit(struct auditinfo *); 308155191Srwatsonint setaudit(const struct auditinfo *); 309155191Srwatsonint getaudit_addr(struct auditinfo_addr *, int); 310155191Srwatsonint setaudit_addr(const struct auditinfo_addr *, int); 311155191Srwatson#endif /* defined(_KERNEL) || defined(KERNEL) */ 312155191Srwatson 313155191Srwatson__END_DECLS 314155191Srwatson 315155191Srwatson#endif /* !_BSM_AUDIT_H */ 316