audit.h revision 155191
1155191Srwatson/* 2155191Srwatson * Copyright (c) 2005 Apple Computer, Inc. 3146759Srwatson * All rights reserved. 4146759Srwatson * 5155191Srwatson * @APPLE_BSD_LICENSE_HEADER_START@ 6155191Srwatson * 7146759Srwatson * Redistribution and use in source and binary forms, with or without 8146759Srwatson * modification, are permitted provided that the following conditions 9146759Srwatson * are met: 10146759Srwatson * 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. 19146759Srwatson * 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 * 33155191Srwatson * $P4: //depot/projects/trustedbsd/audit3/sys/bsm/audit.h#22 $ 34146759Srwatson * $FreeBSD: head/sys/bsm/audit.h 155191 2006-02-01 19:54:22Z rwatson $ 35146759Srwatson */ 36146759Srwatson 37155191Srwatson#ifndef _BSM_AUDIT_H 38155191Srwatson#define _BSM_AUDIT_H 39146759Srwatson 40155191Srwatson#include <sys/param.h> 41155191Srwatson#include <sys/cdefs.h> 42155191Srwatson#include <sys/queue.h> 43155191Srwatson 44155191Srwatson#define AUDIT_RECORD_MAGIC 0x828a0f1b 45155191Srwatson#define MAX_AUDIT_RECORDS 20 46155191Srwatson#define MAX_AUDIT_RECORD_SIZE 4096 47155191Srwatson#define MIN_AUDIT_FILE_SIZE (512 * 1024) 48155191Srwatson 49146759Srwatson/* 50155191Srwatson * Minimum noumber of free blocks on the filesystem containing the audit 51155191Srwatson * log necessary to avoid a hard log rotation. DO NOT SET THIS VALUE TO 0 52155191Srwatson * as the kernel does an unsigned compare, plus we want to leave a few blocks 53155191Srwatson * free so userspace can terminate the log, etc. 54146759Srwatson */ 55155191Srwatson#define AUDIT_HARD_LIMIT_FREE_BLOCKS 4 56155191Srwatson 57155191Srwatson/* 58155191Srwatson * Triggers for the audit daemon 59155191Srwatson */ 60155191Srwatson#define AUDIT_TRIGGER_MIN 1 61155191Srwatson#define AUDIT_TRIGGER_LOW_SPACE 1 62155191Srwatson#define AUDIT_TRIGGER_OPEN_NEW 2 63155191Srwatson#define AUDIT_TRIGGER_READ_FILE 3 64155191Srwatson#define AUDIT_TRIGGER_CLOSE_AND_DIE 4 65155191Srwatson#define AUDIT_TRIGGER_NO_SPACE 5 66155191Srwatson#define AUDIT_TRIGGER_MAX 5 67155191Srwatson 68155191Srwatson/* 69155191Srwatson * File that will be read for trigger events from the kernel. 70155191Srwatson */ 71155191Srwatson#define AUDIT_TRIGGER_FILE "/dev/audit" 72155191Srwatson 73155191Srwatson/* 74155191Srwatson * The special device filename. 75155191Srwatson */ 76155191Srwatson#define AUDITDEV_FILENAME "audit" 77155191Srwatson 78155191Srwatson/* 79155191Srwatson * Pre-defined audit IDs 80155191Srwatson */ 81155191Srwatson#define AU_DEFAUDITID -1 82155191Srwatson 83155191Srwatson/* 84155191Srwatson * Define the masks for the classes of audit events. 85155191Srwatson */ 86155191Srwatson#define AU_NULL 0x00000000 87155191Srwatson#define AU_FREAD 0x00000001 88155191Srwatson#define AU_FWRITE 0x00000002 89155191Srwatson#define AU_FACCESS 0x00000004 90155191Srwatson#define AU_FMODIFY 0x00000008 91155191Srwatson#define AU_FCREATE 0x00000010 92155191Srwatson#define AU_FDELETE 0x00000020 93155191Srwatson#define AU_CLOSE 0x00000040 94155191Srwatson#define AU_PROCESS 0x00000080 95155191Srwatson#define AU_NET 0x00000100 96155191Srwatson#define AU_IPC 0x00000200 97155191Srwatson#define AU_NONAT 0x00000400 98155191Srwatson#define AU_ADMIN 0x00000800 99155191Srwatson#define AU_LOGIN 0x00001000 100155191Srwatson#define AU_TFM 0x00002000 101155191Srwatson#define AU_APPL 0x00004000 102155191Srwatson#define AU_SETL 0x00008000 103155191Srwatson#define AU_IFLOAT 0x00010000 104155191Srwatson#define AU_PRIV 0x00020000 105155191Srwatson#define AU_MAC_RW 0x00040000 106155191Srwatson#define AU_XCONN 0x00080000 107155191Srwatson#define AU_XCREATE 0x00100000 108155191Srwatson#define AU_XDELETE 0x00200000 109155191Srwatson#define AU_XIFLOAT 0x00400000 110155191Srwatson#define AU_XPRIVS 0x00800000 111155191Srwatson#define AU_XPRIVF 0x01000000 112155191Srwatson#define AU_XMOVE 0x02000000 113155191Srwatson#define AU_XDACF 0x04000000 114155191Srwatson#define AU_XMACF 0x08000000 115155191Srwatson#define AU_XSECATTR 0x10000000 116155191Srwatson#define AU_IOCTL 0x20000000 117155191Srwatson#define AU_EXEC 0x40000000 118155191Srwatson#define AU_OTHER 0x80000000 119155191Srwatson#define AU_ALL 0xffffffff 120155191Srwatson 121155191Srwatson/* 122155191Srwatson * IPC types 123155191Srwatson */ 124155191Srwatson#define AT_IPC_MSG ((u_char)1) /* Message IPC id. */ 125155191Srwatson#define AT_IPC_SEM ((u_char)2) /* Semaphore IPC id. */ 126155191Srwatson#define AT_IPC_SHM ((u_char)3) /* Shared mem IPC id. */ 127155191Srwatson 128155191Srwatson/* 129155191Srwatson * Audit conditions. 130155191Srwatson */ 131155191Srwatson#define AUC_UNSET 0 132155191Srwatson#define AUC_AUDITING 1 133155191Srwatson#define AUC_NOAUDIT 2 134155191Srwatson#define AUC_DISABLED -1 135155191Srwatson 136155191Srwatson/* 137155191Srwatson * auditon(2) commands. 138155191Srwatson */ 139155191Srwatson#define A_GETPOLICY 2 140155191Srwatson#define A_SETPOLICY 3 141155191Srwatson#define A_GETKMASK 4 142155191Srwatson#define A_SETKMASK 5 143155191Srwatson#define A_GETQCTRL 6 144155191Srwatson#define A_SETQCTRL 7 145155191Srwatson#define A_GETCWD 8 146155191Srwatson#define A_GETCAR 9 147155191Srwatson#define A_GETSTAT 12 148155191Srwatson#define A_SETSTAT 13 149155191Srwatson#define A_SETUMASK 14 150155191Srwatson#define A_SETSMASK 15 151155191Srwatson#define A_GETCOND 20 152155191Srwatson#define A_SETCOND 21 153155191Srwatson#define A_GETCLASS 22 154155191Srwatson#define A_SETCLASS 23 155155191Srwatson#define A_GETPINFO 24 156155191Srwatson#define A_SETPMASK 25 157155191Srwatson#define A_SETFSIZE 26 158155191Srwatson#define A_GETFSIZE 27 159155191Srwatson#define A_GETPINFO_ADDR 28 160155191Srwatson#define A_GETKAUDIT 29 161155191Srwatson#define A_SETKAUDIT 30 162155191Srwatson#define A_SENDTRIGGER 31 163155191Srwatson 164155191Srwatson/* 165155191Srwatson * Audit policy controls. 166155191Srwatson */ 167155191Srwatson#define AUDIT_CNT 0x0001 168155191Srwatson#define AUDIT_AHLT 0x0002 169155191Srwatson#define AUDIT_ARGV 0x0004 170155191Srwatson#define AUDIT_ARGE 0x0008 171155191Srwatson#define AUDIT_PASSWD 0x0010 172155191Srwatson#define AUDIT_SEQ 0x0020 173155191Srwatson#define AUDIT_WINDATA 0x0040 174155191Srwatson#define AUDIT_USER 0x0080 175155191Srwatson#define AUDIT_GROUP 0x0100 176155191Srwatson#define AUDIT_TRAIL 0x0200 177155191Srwatson#define AUDIT_PATH 0x0400 178155191Srwatson 179155191Srwatson/* 180155191Srwatson * Audit queue control parameters 181155191Srwatson */ 182155191Srwatson#define AQ_HIWATER 100 183155191Srwatson#define AQ_MAXHIGH 10000 184155191Srwatson#define AQ_LOWATER 10 185155191Srwatson#define AQ_BUFSZ 1024 186155191Srwatson#define AQ_MAXBUFSZ 1048576 187155191Srwatson 188155191Srwatson/* 189155191Srwatson * Default minimum percentage free space on file system. 190155191Srwatson */ 191155191Srwatson#define AU_FS_MINFREE 20 192155191Srwatson 193155191Srwatson/* 194155191Srwatson * Type definitions used indicating the length of variable length addresses 195155191Srwatson * in tokens containing addresses, such as header fields. 196155191Srwatson */ 197155191Srwatson#define AU_IPv4 4 198155191Srwatson#define AU_IPv6 16 199155191Srwatson 200155191Srwatson__BEGIN_DECLS 201155191Srwatson 202155191Srwatsontypedef uid_t au_id_t; 203155191Srwatsontypedef pid_t au_asid_t; 204146759Srwatsontypedef u_int16_t au_event_t; 205155191Srwatsontypedef u_int16_t au_emod_t; 206155191Srwatsontypedef u_int32_t au_class_t; 207146759Srwatson 208155191Srwatsonstruct au_tid { 209155191Srwatson dev_t port; 210155191Srwatson u_int32_t machine; 211155191Srwatson}; 212155191Srwatsontypedef struct au_tid au_tid_t; 213155191Srwatson 214155191Srwatsonstruct au_tid_addr { 215155191Srwatson dev_t at_port; 216155191Srwatson u_int32_t at_type; 217155191Srwatson u_int32_t at_addr[4]; 218155191Srwatson}; 219155191Srwatsontypedef struct au_tid_addr au_tid_addr_t; 220155191Srwatson 221155191Srwatsonstruct au_mask { 222155191Srwatson unsigned int am_success; /* Success bits. */ 223155191Srwatson unsigned int am_failure; /* Failure bits. */ 224155191Srwatson}; 225155191Srwatsontypedef struct au_mask au_mask_t; 226155191Srwatson 227155191Srwatsonstruct auditinfo { 228155191Srwatson au_id_t ai_auid; /* Audit user ID. */ 229155191Srwatson au_mask_t ai_mask; /* Audit masks. */ 230155191Srwatson au_tid_t ai_termid; /* Terminal ID. */ 231155191Srwatson au_asid_t ai_asid; /* Audit session ID. */ 232155191Srwatson}; 233155191Srwatsontypedef struct auditinfo auditinfo_t; 234155191Srwatson 235155191Srwatsonstruct auditinfo_addr { 236155191Srwatson au_id_t ai_auid; /* Audit user ID. */ 237155191Srwatson au_mask_t ai_mask; /* Audit masks. */ 238155191Srwatson au_tid_addr_t ai_termid; /* Terminal ID. */ 239155191Srwatson au_asid_t ai_asid; /* Audit session ID. */ 240155191Srwatson}; 241155191Srwatsontypedef struct auditinfo_addr auditinfo_addr_t; 242155191Srwatson 243155191Srwatsonstruct auditpinfo { 244155191Srwatson pid_t ap_pid; /* ID of target process. */ 245155191Srwatson au_id_t ap_auid; /* Audit user ID. */ 246155191Srwatson au_mask_t ap_mask; /* Audit masks. */ 247155191Srwatson au_tid_t ap_termid; /* Terminal ID. */ 248155191Srwatson au_asid_t ap_asid; /* Audit session ID. */ 249155191Srwatson}; 250155191Srwatsontypedef struct auditpinfo auditpinfo_t; 251155191Srwatson 252155191Srwatsonstruct auditpinfo_addr { 253155191Srwatson pid_t ap_pid; /* ID of target process. */ 254155191Srwatson au_id_t ap_auid; /* Audit user ID. */ 255155191Srwatson au_mask_t ap_mask; /* Audit masks. */ 256155191Srwatson au_tid_addr_t ap_termid; /* Terminal ID. */ 257155191Srwatson au_asid_t ap_asid; /* Audit session ID. */ 258155191Srwatson}; 259155191Srwatsontypedef struct auditpinfo_addr auditpinfo_addr_t; 260155191Srwatson 261155191Srwatson/* Token and record structures. */ 262155191Srwatson 263155191Srwatsonstruct au_token { 264155191Srwatson u_char *t_data; 265155191Srwatson size_t len; 266155191Srwatson TAILQ_ENTRY(au_token) tokens; 267155191Srwatson}; 268155191Srwatsontypedef struct au_token token_t; 269155191Srwatson 270155191Srwatsonstruct au_record { 271155191Srwatson char used; /* Record currently in use? */ 272155191Srwatson int desc; /* Descriptor for record. */ 273155191Srwatson TAILQ_HEAD(, au_token) token_q; /* Queue of BSM tokens. */ 274155191Srwatson u_char *data; 275155191Srwatson size_t len; 276155191Srwatson LIST_ENTRY(au_record) au_rec_q; 277155191Srwatson}; 278155191Srwatsontypedef struct au_record au_record_t; 279155191Srwatson 280155191Srwatson/* 281155191Srwatson * Kernel audit queue control parameters. 282155191Srwatson */ 283155191Srwatsonstruct au_qctrl { 284155191Srwatson size_t aq_hiwater; 285155191Srwatson size_t aq_lowater; 286155191Srwatson size_t aq_bufsz; 287155191Srwatson clock_t aq_delay; 288155191Srwatson int aq_minfree; /* Minimum filesystem percent free space. */ 289155191Srwatson}; 290155191Srwatsontypedef struct au_qctrl au_qctrl_t; 291155191Srwatson 292155191Srwatson/* 293155191Srwatson * Structure for the audit statistics. 294155191Srwatson */ 295155191Srwatsonstruct audit_stat { 296155191Srwatson unsigned int as_version; 297155191Srwatson unsigned int as_numevent; 298155191Srwatson int as_generated; 299155191Srwatson int as_nonattring; 300155191Srwatson int as_kernel; 301155191Srwatson int as_audit; 302155191Srwatson int as_auditctl; 303155191Srwatson int as_enqueu; 304155191Srwatson int as_written; 305155191Srwatson int as_wblocked; 306155191Srwatson int as_rblocked; 307155191Srwatson int as_dropped; 308155191Srwatson int as_totalsize; 309155191Srwatson unsigned int as_memused; 310155191Srwatson}; 311155191Srwatsontypedef struct audit_stat au_stat_t; 312155191Srwatson 313155191Srwatson/* 314155191Srwatson * Structure for the audit file statistics. 315155191Srwatson */ 316155191Srwatsonstruct audit_fstat { 317155191Srwatson u_quad_t af_filesz; 318155191Srwatson u_quad_t af_currsz; 319155191Srwatson}; 320155191Srwatsontypedef struct audit_fstat au_fstat_t; 321155191Srwatson 322155191Srwatson/* 323155191Srwatson * Audit to event class mapping. 324155191Srwatson */ 325155191Srwatsonstruct au_evclass_map { 326155191Srwatson au_event_t ec_number; 327155191Srwatson au_class_t ec_class; 328155191Srwatson}; 329155191Srwatsontypedef struct au_evclass_map au_evclass_map_t; 330155191Srwatson 331155191Srwatson#if !defined(_KERNEL) && !defined(KERNEL) 332155191Srwatsonint audit(const void *, int); 333155191Srwatsonint auditon(int, void *, int); 334155191Srwatsonint auditctl(const char *); 335155191Srwatsonint getauid(au_id_t *); 336155191Srwatsonint setauid(const au_id_t *); 337155191Srwatsonint getaudit(struct auditinfo *); 338155191Srwatsonint setaudit(const struct auditinfo *); 339155191Srwatsonint getaudit_addr(struct auditinfo_addr *, int); 340155191Srwatsonint setaudit_addr(const struct auditinfo_addr *, int); 341155191Srwatson#endif /* defined(_KERNEL) || defined(KERNEL) */ 342155191Srwatson 343155191Srwatson__END_DECLS 344155191Srwatson 345155191Srwatson#endif /* !_BSM_AUDIT_H */ 346