/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 2005-2009 Apple Inc.4* Copyright (c) 2016 Robert N. M. Watson5* All rights reserved.6*7* Portions of this software were developed by BAE Systems, the University of8* Cambridge Computer Laboratory, and Memorial University under DARPA/AFRL9* contract FA8650-15-C-7558 ("CADETS"), as part of the DARPA Transparent10* Computing (TC) research program.11*12* Redistribution and use in source and binary forms, with or without13* modification, are permitted provided that the following conditions14* are met:15*16* 1. Redistributions of source code must retain the above copyright17* notice, this list of conditions and the following disclaimer.18* 2. Redistributions in binary form must reproduce the above copyright19* notice, this list of conditions and the following disclaimer in the20* documentation and/or other materials provided with the distribution.21* 3. Neither the name of Apple Inc. ("Apple") nor the names of22* its contributors may be used to endorse or promote products derived23* from this software without specific prior written permission.24*25* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY26* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED27* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE28* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY29* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES30* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;31* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND32* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT33* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF34* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.35*/3637#ifndef _BSM_AUDIT_H38#define _BSM_AUDIT_H3940#include <sys/param.h>41#include <sys/types.h>4243#define AUDIT_RECORD_MAGIC 0x828a0f1b44#define MAX_AUDIT_RECORDS 2045#define MAXAUDITDATA (0x8000 - 1)46#define MAX_AUDIT_RECORD_SIZE MAXAUDITDATA47#define MIN_AUDIT_FILE_SIZE (512 * 1024)4849/*50* Minimum noumber of free blocks on the filesystem containing the audit51* log necessary to avoid a hard log rotation. DO NOT SET THIS VALUE TO 052* as the kernel does an unsigned compare, plus we want to leave a few blocks53* free so userspace can terminate the log, etc.54*/55#define AUDIT_HARD_LIMIT_FREE_BLOCKS 45657/*58* Triggers for the audit daemon.59*/60#define AUDIT_TRIGGER_MIN 161#define AUDIT_TRIGGER_LOW_SPACE 1 /* Below low watermark. */62#define AUDIT_TRIGGER_ROTATE_KERNEL 2 /* Kernel requests rotate. */63#define AUDIT_TRIGGER_READ_FILE 3 /* Re-read config file. */64#define AUDIT_TRIGGER_CLOSE_AND_DIE 4 /* Terminate audit. */65#define AUDIT_TRIGGER_NO_SPACE 5 /* Below min free space. */66#define AUDIT_TRIGGER_ROTATE_USER 6 /* User requests rotate. */67#define AUDIT_TRIGGER_INITIALIZE 7 /* User initialize of auditd. */68#define AUDIT_TRIGGER_EXPIRE_TRAILS 8 /* User expiration of trails. */69#define AUDIT_TRIGGER_MAX 87071/*72* The special device filename (FreeBSD).73*/74#define AUDITDEV_FILENAME "audit"75#define AUDIT_TRIGGER_FILE ("/dev/" AUDITDEV_FILENAME)7677/*78* Pre-defined audit IDs79*/80#define AU_DEFAUDITID (uid_t)(-1)81#define AU_DEFAUDITSID 082#define AU_ASSIGN_ASID -18384/*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. */9091/*92* Audit conditions.93*/94#define AUC_UNSET 095#define AUC_AUDITING 196#define AUC_NOAUDIT 297#define AUC_DISABLED -19899/*100* auditon(2) commands.101*/102#define A_OLDGETPOLICY 2103#define A_OLDSETPOLICY 3104#define A_GETKMASK 4105#define A_SETKMASK 5106#define A_OLDGETQCTRL 6107#define A_OLDSETQCTRL 7108#define A_GETCWD 8109#define A_GETCAR 9110#define A_GETSTAT 12111#define A_SETSTAT 13112#define A_SETUMASK 14113#define A_SETSMASK 15114#define A_OLDGETCOND 20115#define A_OLDSETCOND 21116#define A_GETCLASS 22117#define A_SETCLASS 23118#define A_GETPINFO 24119#define A_SETPMASK 25120#define A_SETFSIZE 26121#define A_GETFSIZE 27122#define A_GETPINFO_ADDR 28123#define A_GETKAUDIT 29124#define A_SETKAUDIT 30125#define A_SENDTRIGGER 31126#define A_GETSINFO_ADDR 32127#define A_GETPOLICY 33128#define A_SETPOLICY 34129#define A_GETQCTRL 35130#define A_SETQCTRL 36131#define A_GETCOND 37132#define A_SETCOND 38133#define A_GETEVENT 39 /* Get audit event-to-name mapping. */134#define A_SETEVENT 40 /* Set audit event-to-name mapping. */135136/*137* Audit policy controls.138*/139#define AUDIT_CNT 0x0001140#define AUDIT_AHLT 0x0002141#define AUDIT_ARGV 0x0004142#define AUDIT_ARGE 0x0008143#define AUDIT_SEQ 0x0010144#define AUDIT_WINDATA 0x0020145#define AUDIT_USER 0x0040146#define AUDIT_GROUP 0x0080147#define AUDIT_TRAIL 0x0100148#define AUDIT_PATH 0x0200149#define AUDIT_SCNT 0x0400150#define AUDIT_PUBLIC 0x0800151#define AUDIT_ZONENAME 0x1000152#define AUDIT_PERZONE 0x2000153154/*155* Default audit queue control parameters.156*/157#define AQ_HIWATER 100158#define AQ_MAXHIGH 10000159#define AQ_LOWATER 10160#define AQ_BUFSZ MAXAUDITDATA161#define AQ_MAXBUFSZ 1048576162163/*164* Default minimum percentage free space on file system.165*/166#define AU_FS_MINFREE 20167168/*169* Type definitions used indicating the length of variable length addresses170* in tokens containing addresses, such as header fields.171*/172#define AU_IPv4 4173#define AU_IPv6 16174175__BEGIN_DECLS176177typedef uid_t au_id_t;178typedef pid_t au_asid_t;179typedef u_int16_t au_event_t;180typedef u_int16_t au_emod_t;181typedef u_int32_t au_class_t;182typedef u_int64_t au_asflgs_t __attribute__ ((aligned (8)));183184struct au_tid {185u_int32_t port; /* XXX dev_t compatibility */186u_int32_t machine;187};188typedef struct au_tid au_tid_t;189190struct au_tid_addr {191u_int32_t at_port; /* XXX dev_t compatibility */192u_int32_t at_type;193u_int32_t at_addr[4];194};195typedef struct au_tid_addr au_tid_addr_t;196197struct au_mask {198unsigned int am_success; /* Success bits. */199unsigned int am_failure; /* Failure bits. */200};201typedef struct au_mask au_mask_t;202203struct auditinfo {204au_id_t ai_auid; /* Audit user ID. */205au_mask_t ai_mask; /* Audit masks. */206au_tid_t ai_termid; /* Terminal ID. */207au_asid_t ai_asid; /* Audit session ID. */208};209typedef struct auditinfo auditinfo_t;210211struct auditinfo_addr {212au_id_t ai_auid; /* Audit user ID. */213au_mask_t ai_mask; /* Audit masks. */214au_tid_addr_t ai_termid; /* Terminal ID. */215au_asid_t ai_asid; /* Audit session ID. */216au_asflgs_t ai_flags; /* Audit session flags. */217};218typedef struct auditinfo_addr auditinfo_addr_t;219220struct auditpinfo {221pid_t ap_pid; /* ID of target process. */222au_id_t ap_auid; /* Audit user ID. */223au_mask_t ap_mask; /* Audit masks. */224au_tid_t ap_termid; /* Terminal ID. */225au_asid_t ap_asid; /* Audit session ID. */226};227typedef struct auditpinfo auditpinfo_t;228229struct auditpinfo_addr {230pid_t ap_pid; /* ID of target process. */231au_id_t ap_auid; /* Audit user ID. */232au_mask_t ap_mask; /* Audit masks. */233au_tid_addr_t ap_termid; /* Terminal ID. */234au_asid_t ap_asid; /* Audit session ID. */235au_asflgs_t ap_flags; /* Audit session flags. */236};237typedef struct auditpinfo_addr auditpinfo_addr_t;238239struct au_session {240auditinfo_addr_t *as_aia_p; /* Ptr to full audit info. */241au_mask_t as_mask; /* Process Audit Masks. */242};243typedef struct au_session au_session_t;244245/*246* Contents of token_t are opaque outside of libbsm.247*/248typedef struct au_token token_t;249250/*251* Kernel audit queue control parameters:252* Default: Maximum:253* aq_hiwater: AQ_HIWATER (100) AQ_MAXHIGH (10000)254* aq_lowater: AQ_LOWATER (10) <aq_hiwater255* aq_bufsz: AQ_BUFSZ (32767) AQ_MAXBUFSZ (1048576)256* aq_delay: 20 20000 (not used)257*/258struct au_qctrl {259int aq_hiwater; /* Max # of audit recs in queue when */260/* threads with new ARs get blocked. */261262int aq_lowater; /* # of audit recs in queue when */263/* blocked threads get unblocked. */264265int aq_bufsz; /* Max size of audit record for audit(2). */266int aq_delay; /* Queue delay (not used). */267int aq_minfree; /* Minimum filesystem percent free space. */268};269typedef struct au_qctrl au_qctrl_t;270271/*272* Structure for the audit statistics.273*/274struct audit_stat {275unsigned int as_version;276unsigned int as_numevent;277int as_generated;278int as_nonattrib;279int as_kernel;280int as_audit;281int as_auditctl;282int as_enqueue;283int as_written;284int as_wblocked;285int as_rblocked;286int as_dropped;287int as_totalsize;288unsigned int as_memused;289};290typedef struct audit_stat au_stat_t;291292/*293* Structure for the audit file statistics.294*/295struct audit_fstat {296u_int64_t af_filesz;297u_int64_t af_currsz;298};299typedef struct audit_fstat au_fstat_t;300301/*302* Audit to event class mapping.303*/304struct au_evclass_map {305au_event_t ec_number;306au_class_t ec_class;307};308typedef struct au_evclass_map au_evclass_map_t;309310/*311* Event-to-name mapping.312*/313#define EVNAMEMAP_NAME_SIZE 64314struct au_evname_map {315au_event_t en_number;316char en_name[EVNAMEMAP_NAME_SIZE];317};318typedef struct au_evname_map au_evname_map_t;319320/*321* Audit system calls.322*/323#if !defined(_KERNEL) && !defined(KERNEL)324int audit(const void *, int);325int auditon(int, void *, int);326int auditctl(const char *);327int getauid(au_id_t *);328int setauid(const au_id_t *);329int getaudit(struct auditinfo *);330int setaudit(const struct auditinfo *);331int getaudit_addr(struct auditinfo_addr *, int);332int setaudit_addr(const struct auditinfo_addr *, int);333334#ifdef __APPLE_API_PRIVATE335#include <mach/port.h>336mach_port_name_t audit_session_self(void);337au_asid_t audit_session_join(mach_port_name_t port);338#endif /* __APPLE_API_PRIVATE */339340#endif /* defined(_KERNEL) || defined(KERNEL) */341342__END_DECLS343344#endif /* !_BSM_AUDIT_H */345346347