audit.h revision 161635
1/* 2 * Copyright (c) 2005 Apple Computer, Inc. 3 * All rights reserved. 4 * 5 * @APPLE_BSD_LICENSE_HEADER_START@ 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 17 * its contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * 31 * @APPLE_BSD_LICENSE_HEADER_END@ 32 * 33 * $P4: //depot/projects/trustedbsd/audit3/sys/bsm/audit.h#31 $ 34 * $FreeBSD: head/sys/bsm/audit.h 161635 2006-08-26 08:17:58Z rwatson $ 35 */ 36 37#ifndef _BSM_AUDIT_H 38#define _BSM_AUDIT_H 39 40#include <sys/param.h> 41#include <sys/cdefs.h> 42#include <sys/queue.h> 43 44#define AUDIT_RECORD_MAGIC 0x828a0f1b 45#define MAX_AUDIT_RECORDS 20 46#define MAXAUDITDATA (0x8000 - 1) 47#define MAX_AUDIT_RECORD_SIZE MAXAUDITDATA 48#define MIN_AUDIT_FILE_SIZE (512 * 1024) 49 50/* 51 * Minimum noumber of free blocks on the filesystem containing the audit 52 * log necessary to avoid a hard log rotation. DO NOT SET THIS VALUE TO 0 53 * as the kernel does an unsigned compare, plus we want to leave a few blocks 54 * free so userspace can terminate the log, etc. 55 */ 56#define AUDIT_HARD_LIMIT_FREE_BLOCKS 4 57 58/* 59 * Triggers for the audit daemon. 60 */ 61#define AUDIT_TRIGGER_MIN 1 62#define AUDIT_TRIGGER_LOW_SPACE 1 63#define AUDIT_TRIGGER_OPEN_NEW 2 64#define AUDIT_TRIGGER_READ_FILE 3 65#define AUDIT_TRIGGER_CLOSE_AND_DIE 4 66#define AUDIT_TRIGGER_NO_SPACE 5 67#define AUDIT_TRIGGER_MAX 5 68 69/* 70 * Special file that will be read for trigger events from the kernel 71 * (FreeBSD). 72 */ 73#define AUDIT_TRIGGER_FILE "/dev/audit" 74 75/* 76 * The special device filename. 77 */ 78#define AUDITDEV_FILENAME "audit" 79 80/* 81 * Pre-defined audit IDs 82 */ 83#define AU_DEFAUDITID -1 84 85/* 86 * Define the masks for the classes of audit events. 87 */ 88#define AU_NULL 0x00000000 89#define AU_FREAD 0x00000001 90#define AU_FWRITE 0x00000002 91#define AU_FACCESS 0x00000004 92#define AU_FMODIFY 0x00000008 93#define AU_FCREATE 0x00000010 94#define AU_FDELETE 0x00000020 95#define AU_CLOSE 0x00000040 96#define AU_PROCESS 0x00000080 97#define AU_NET 0x00000100 98#define AU_IPC 0x00000200 99#define AU_NONAT 0x00000400 100#define AU_ADMIN 0x00000800 101#define AU_LOGIN 0x00001000 102#define AU_TFM 0x00002000 103#define AU_APPL 0x00004000 104#define AU_SETL 0x00008000 105#define AU_IFLOAT 0x00010000 106#define AU_PRIV 0x00020000 107#define AU_MAC_RW 0x00040000 108#define AU_XCONN 0x00080000 109#define AU_XCREATE 0x00100000 110#define AU_XDELETE 0x00200000 111#define AU_XIFLOAT 0x00400000 112#define AU_XPRIVS 0x00800000 113#define AU_XPRIVF 0x01000000 114#define AU_XMOVE 0x02000000 115#define AU_XDACF 0x04000000 116#define AU_XMACF 0x08000000 117#define AU_XSECATTR 0x10000000 118#define AU_IOCTL 0x20000000 119#define AU_EXEC 0x40000000 120#define AU_OTHER 0x80000000 121#define AU_ALL 0xffffffff 122 123/* 124 * IPC types. 125 */ 126#define AT_IPC_MSG ((u_char)1) /* Message IPC id. */ 127#define AT_IPC_SEM ((u_char)2) /* Semaphore IPC id. */ 128#define AT_IPC_SHM ((u_char)3) /* Shared mem IPC id. */ 129 130/* 131 * Audit conditions. 132 */ 133#define AUC_UNSET 0 134#define AUC_AUDITING 1 135#define AUC_NOAUDIT 2 136#define AUC_DISABLED -1 137 138/* 139 * auditon(2) commands. 140 */ 141#define A_GETPOLICY 2 142#define A_SETPOLICY 3 143#define A_GETKMASK 4 144#define A_SETKMASK 5 145#define A_GETQCTRL 6 146#define A_SETQCTRL 7 147#define A_GETCWD 8 148#define A_GETCAR 9 149#define A_GETSTAT 12 150#define A_SETSTAT 13 151#define A_SETUMASK 14 152#define A_SETSMASK 15 153#define A_GETCOND 20 154#define A_SETCOND 21 155#define A_GETCLASS 22 156#define A_SETCLASS 23 157#define A_GETPINFO 24 158#define A_SETPMASK 25 159#define A_SETFSIZE 26 160#define A_GETFSIZE 27 161#define A_GETPINFO_ADDR 28 162#define A_GETKAUDIT 29 163#define A_SETKAUDIT 30 164#define A_SENDTRIGGER 31 165 166/* 167 * Audit policy controls. 168 */ 169#define AUDIT_CNT 0x0001 170#define AUDIT_AHLT 0x0002 171#define AUDIT_ARGV 0x0004 172#define AUDIT_ARGE 0x0008 173#define AUDIT_SEQ 0x0010 174#define AUDIT_WINDATA 0x0020 175#define AUDIT_USER 0x0040 176#define AUDIT_GROUP 0x0080 177#define AUDIT_TRAIL 0x0100 178#define AUDIT_PATH 0x0200 179#define AUDIT_SCNT 0x0400 180#define AUDIT_PUBLIC 0x0800 181#define AUDIT_ZONENAME 0x1000 182#define AUDIT_PERZONE 0x2000 183 184/* 185 * Audit queue control parameters. 186 */ 187#define AQ_HIWATER 100 188#define AQ_MAXHIGH 10000 189#define AQ_LOWATER 10 190#define AQ_BUFSZ 1024 191#define AQ_MAXBUFSZ 1048576 192 193/* 194 * Default minimum percentage free space on file system. 195 */ 196#define AU_FS_MINFREE 20 197 198/* 199 * Type definitions used indicating the length of variable length addresses 200 * in tokens containing addresses, such as header fields. 201 */ 202#define AU_IPv4 4 203#define AU_IPv6 16 204 205__BEGIN_DECLS 206 207typedef uid_t au_id_t; 208typedef pid_t au_asid_t; 209typedef u_int16_t au_event_t; 210typedef u_int16_t au_emod_t; 211typedef u_int32_t au_class_t; 212 213struct au_tid { 214 dev_t port; 215 u_int32_t machine; 216}; 217typedef struct au_tid au_tid_t; 218 219struct au_tid_addr { 220 dev_t at_port; 221 u_int32_t at_type; 222 u_int32_t at_addr[4]; 223}; 224typedef struct au_tid_addr au_tid_addr_t; 225 226struct au_mask { 227 unsigned int am_success; /* Success bits. */ 228 unsigned int am_failure; /* Failure bits. */ 229}; 230typedef struct au_mask au_mask_t; 231 232struct auditinfo { 233 au_id_t ai_auid; /* Audit user ID. */ 234 au_mask_t ai_mask; /* Audit masks. */ 235 au_tid_t ai_termid; /* Terminal ID. */ 236 au_asid_t ai_asid; /* Audit session ID. */ 237}; 238typedef struct auditinfo auditinfo_t; 239 240struct auditinfo_addr { 241 au_id_t ai_auid; /* Audit user ID. */ 242 au_mask_t ai_mask; /* Audit masks. */ 243 au_tid_addr_t ai_termid; /* Terminal ID. */ 244 au_asid_t ai_asid; /* Audit session ID. */ 245}; 246typedef struct auditinfo_addr auditinfo_addr_t; 247 248struct auditpinfo { 249 pid_t ap_pid; /* ID of target process. */ 250 au_id_t ap_auid; /* Audit user ID. */ 251 au_mask_t ap_mask; /* Audit masks. */ 252 au_tid_t ap_termid; /* Terminal ID. */ 253 au_asid_t ap_asid; /* Audit session ID. */ 254}; 255typedef struct auditpinfo auditpinfo_t; 256 257struct auditpinfo_addr { 258 pid_t ap_pid; /* ID of target process. */ 259 au_id_t ap_auid; /* Audit user ID. */ 260 au_mask_t ap_mask; /* Audit masks. */ 261 au_tid_addr_t ap_termid; /* Terminal ID. */ 262 au_asid_t ap_asid; /* Audit session ID. */ 263}; 264typedef struct auditpinfo_addr auditpinfo_addr_t; 265 266/* 267 * Contents of token_t are opaque outside of libbsm. 268 */ 269typedef struct au_token token_t; 270 271/* 272 * Kernel audit queue control parameters. 273 */ 274struct au_qctrl { 275 size_t aq_hiwater; 276 size_t aq_lowater; 277 size_t aq_bufsz; 278 clock_t aq_delay; 279 int aq_minfree; /* Minimum filesystem percent free space. */ 280}; 281typedef struct au_qctrl au_qctrl_t; 282 283/* 284 * Structure for the audit statistics. 285 */ 286struct audit_stat { 287 unsigned int as_version; 288 unsigned int as_numevent; 289 int as_generated; 290 int as_nonattrib; 291 int as_kernel; 292 int as_audit; 293 int as_auditctl; 294 int as_enqueue; 295 int as_written; 296 int as_wblocked; 297 int as_rblocked; 298 int as_dropped; 299 int as_totalsize; 300 unsigned int as_memused; 301}; 302typedef struct audit_stat au_stat_t; 303 304/* 305 * Structure for the audit file statistics. 306 */ 307struct audit_fstat { 308 u_quad_t af_filesz; 309 u_quad_t af_currsz; 310}; 311typedef struct audit_fstat au_fstat_t; 312 313/* 314 * Audit to event class mapping. 315 */ 316struct au_evclass_map { 317 au_event_t ec_number; 318 au_class_t ec_class; 319}; 320typedef struct au_evclass_map au_evclass_map_t; 321 322/* 323 * Audit system calls. 324 */ 325#if !defined(_KERNEL) && !defined(KERNEL) 326int audit(const void *, int); 327int auditon(int, void *, int); 328int auditctl(const char *); 329int getauid(au_id_t *); 330int setauid(const au_id_t *); 331int getaudit(struct auditinfo *); 332int setaudit(const struct auditinfo *); 333int getaudit_addr(struct auditinfo_addr *, int); 334int setaudit_addr(const struct auditinfo_addr *, int); 335#endif /* defined(_KERNEL) || defined(KERNEL) */ 336 337__END_DECLS 338 339#endif /* !_BSM_AUDIT_H */ 340