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