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