audit.h revision 155195
133965Sjdp/* 233965Sjdp * Copyright (c) 1999-2005 Apple Computer, Inc. 333965Sjdp * All rights reserved. 433965Sjdp * 533965Sjdp * Redistribution and use in source and binary forms, with or without 633965Sjdp * modification, are permitted provided that the following conditions 733965Sjdp * are met: 833965Sjdp * 1. Redistributions of source code must retain the above copyright 933965Sjdp * notice, this list of conditions and the following disclaimer. 1033965Sjdp * 2. Redistributions in binary form must reproduce the above copyright 1133965Sjdp * notice, this list of conditions and the following disclaimer in the 1233965Sjdp * documentation and/or other materials provided with the distribution. 1333965Sjdp * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 1433965Sjdp * its contributors may be used to endorse or promote products derived 1533965Sjdp * from this software without specific prior written permission. 1633965Sjdp * 1733965Sjdp * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND 1833965Sjdp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1933965Sjdp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2033965Sjdp * ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR 2133965Sjdp * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2233965Sjdp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2333965Sjdp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2433965Sjdp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 2533965Sjdp * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 2633965Sjdp * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2733965Sjdp * POSSIBILITY OF SUCH DAMAGE. 2833965Sjdp * 2933965Sjdp * $FreeBSD: head/sys/security/audit/audit.h 155195 2006-02-02 00:37:05Z rwatson $ 3033965Sjdp */ 3133965Sjdp 3233965Sjdp/* 3333965Sjdp * This header includes function prototypes and type definitions that are 3433965Sjdp * necessary for the kernel as a whole to interact with the audit subsystem. 3533965Sjdp */ 3633965Sjdp 3733965Sjdp#ifndef _BSM_AUDIT_KERNEL_H 3833965Sjdp#define _BSM_AUDIT_KERNEL_H 3933965Sjdp 4033965Sjdp#ifndef _KERNEL 4133965Sjdp#error "no user-serviceable parts inside" 4233965Sjdp#endif 4333965Sjdp 4433965Sjdp#include <bsm/audit.h> 4533965Sjdp 4633965Sjdp#include <sys/file.h> 4733965Sjdp#include <sys/sysctl.h> 4833965Sjdp#include <sys/user.h> 4933965Sjdp 5033965Sjdp/* 5133965Sjdp * Audit subsystem condition flags. The audit_enabled flag is set and 5233965Sjdp * removed automatically as a result of configuring log files, and 5333965Sjdp * can be observed but should not be directly manipulated. The audit 5433965Sjdp * suspension flag permits audit to be temporarily disabled without 5533965Sjdp * reconfiguring the audit target. 5633965Sjdp */ 5733965Sjdpextern int audit_enabled; 5833965Sjdpextern int audit_suspended; 5933965Sjdp 6033965Sjdp/* 6133965Sjdp * Define the masks for the audited arguments. 6233965Sjdp * 6333965Sjdp * XXXRW: These need to remain in audit.h for now because our vnode and name 6433965Sjdp * lookup audit calls rely on passing in flags to indicate which name or 6533965Sjdp * vnode is being logged. These should move to audit_private.h when that is 6633965Sjdp * fixed. 6733965Sjdp */ 6833965Sjdp#define ARG_EUID 0x0000000000000001ULL 6933965Sjdp#define ARG_RUID 0x0000000000000002ULL 7033965Sjdp#define ARG_SUID 0x0000000000000004ULL 7133965Sjdp#define ARG_EGID 0x0000000000000008ULL 7233965Sjdp#define ARG_RGID 0x0000000000000010ULL 7333965Sjdp#define ARG_SGID 0x0000000000000020ULL 7433965Sjdp#define ARG_PID 0x0000000000000040ULL 7533965Sjdp#define ARG_UID 0x0000000000000080ULL 7633965Sjdp#define ARG_AUID 0x0000000000000100ULL 7733965Sjdp#define ARG_GID 0x0000000000000200ULL 7833965Sjdp#define ARG_FD 0x0000000000000400ULL 7933965Sjdp#define ARG_POSIX_IPC_PERM 0x0000000000000800ULL 8033965Sjdp#define ARG_FFLAGS 0x0000000000001000ULL 8133965Sjdp#define ARG_MODE 0x0000000000002000ULL 8233965Sjdp#define ARG_DEV 0x0000000000004000ULL 8333965Sjdp#define ARG_ADDR 0x0000000000008000ULL 8433965Sjdp#define ARG_LEN 0x0000000000010000ULL 8533965Sjdp#define ARG_MASK 0x0000000000020000ULL 8633965Sjdp#define ARG_SIGNUM 0x0000000000040000ULL 8733965Sjdp#define ARG_LOGIN 0x0000000000080000ULL 8833965Sjdp#define ARG_SADDRINET 0x0000000000100000ULL 8933965Sjdp#define ARG_SADDRINET6 0x0000000000200000ULL 9033965Sjdp#define ARG_SADDRUNIX 0x0000000000400000ULL 9133965Sjdp#define ARG_UNUSED1 0x0000000000800000ULL 9233965Sjdp#define ARG_UNUSED2 0x0000000001000000ULL 9333965Sjdp#define ARG_UPATH1 0x0000000002000000ULL 9433965Sjdp#define ARG_UPATH2 0x0000000004000000ULL 9533965Sjdp#define ARG_TEXT 0x0000000008000000ULL 9633965Sjdp#define ARG_VNODE1 0x0000000010000000ULL 9733965Sjdp#define ARG_VNODE2 0x0000000020000000ULL 9833965Sjdp#define ARG_SVIPC_CMD 0x0000000040000000ULL 9933965Sjdp#define ARG_SVIPC_PERM 0x0000000080000000ULL 10033965Sjdp#define ARG_SVIPC_ID 0x0000000100000000ULL 10133965Sjdp#define ARG_SVIPC_ADDR 0x0000000200000000ULL 10233965Sjdp#define ARG_GROUPSET 0x0000000400000000ULL 10333965Sjdp#define ARG_CMD 0x0000000800000000ULL 10433965Sjdp#define ARG_SOCKINFO 0x0000001000000000ULL 10533965Sjdp#define ARG_ASID 0x0000002000000000ULL 10633965Sjdp#define ARG_TERMID 0x0000004000000000ULL 10733965Sjdp#define ARG_AUDITON 0x0000008000000000ULL 10833965Sjdp#define ARG_VALUE 0x0000010000000000ULL 10933965Sjdp#define ARG_AMASK 0x0000020000000000ULL 11033965Sjdp#define ARG_CTLNAME 0x0000040000000000ULL 11133965Sjdp#define ARG_PROCESS 0x0000080000000000ULL 11233965Sjdp#define ARG_MACHPORT1 0x0000100000000000ULL 11333965Sjdp#define ARG_MACHPORT2 0x0000200000000000ULL 11433965Sjdp#define ARG_EXIT 0x0000400000000000ULL 11533965Sjdp#define ARG_NONE 0x0000000000000000ULL 11633965Sjdp#define ARG_ALL 0xFFFFFFFFFFFFFFFFULL 11733965Sjdp 11833965Sjdpvoid audit_syscall_enter(unsigned short code, 11933965Sjdp struct thread *td); 12033965Sjdpvoid audit_syscall_exit(int error, struct thread *td); 12133965Sjdp 12233965Sjdp/* 12333965Sjdp * The remaining kernel functions are conditionally compiled in as they 12433965Sjdp * are wrapped by a macro, and the macro should be the only place in 12533965Sjdp * the source tree where these functions are referenced. 12633965Sjdp */ 12733965Sjdp#ifdef AUDIT 12833965Sjdpstruct ipc_perm; 12933965Sjdpstruct sockaddr; 13033965Sjdpunion auditon_udata; 13133965Sjdpvoid audit_arg_addr(void * addr); 13233965Sjdpvoid audit_arg_exit(int status, int retval); 13333965Sjdpvoid audit_arg_len(int len); 13433965Sjdpvoid audit_arg_fd(int fd); 13533965Sjdpvoid audit_arg_fflags(int fflags); 13633965Sjdpvoid audit_arg_gid(gid_t gid); 13733965Sjdpvoid audit_arg_uid(uid_t uid); 13833965Sjdpvoid audit_arg_egid(gid_t egid); 13933965Sjdpvoid audit_arg_euid(uid_t euid); 14033965Sjdpvoid audit_arg_rgid(gid_t rgid); 14133965Sjdpvoid audit_arg_ruid(uid_t ruid); 14233965Sjdpvoid audit_arg_sgid(gid_t sgid); 14333965Sjdpvoid audit_arg_suid(uid_t suid); 14433965Sjdpvoid audit_arg_groupset(gid_t *gidset, u_int gidset_size); 14533965Sjdpvoid audit_arg_login(char *login); 14633965Sjdpvoid audit_arg_ctlname(int *name, int namelen); 14733965Sjdpvoid audit_arg_mask(int mask); 14833965Sjdpvoid audit_arg_mode(mode_t mode); 14933965Sjdpvoid audit_arg_dev(int dev); 15033965Sjdpvoid audit_arg_value(long value); 15133965Sjdpvoid audit_arg_owner(uid_t uid, gid_t gid); 15233965Sjdpvoid audit_arg_pid(pid_t pid); 15333965Sjdpvoid audit_arg_process(struct proc *p); 15433965Sjdpvoid audit_arg_signum(u_int signum); 15533965Sjdpvoid audit_arg_socket(int sodomain, int sotype, 15633965Sjdp int soprotocol); 15733965Sjdpvoid audit_arg_sockaddr(struct thread *td, 15833965Sjdp struct sockaddr *so); 15933965Sjdpvoid audit_arg_auid(uid_t auid); 16033965Sjdpvoid audit_arg_auditinfo(struct auditinfo *au_info); 16133965Sjdpvoid audit_arg_upath(struct thread *td, char *upath, 16233965Sjdp u_int64_t flags); 16333965Sjdpvoid audit_arg_vnode(struct vnode *vp, u_int64_t flags); 16433965Sjdpvoid audit_arg_text(char *text); 16533965Sjdpvoid audit_arg_cmd(int cmd); 16633965Sjdpvoid audit_arg_svipc_cmd(int cmd); 16733965Sjdpvoid audit_arg_svipc_perm(struct ipc_perm *perm); 16833965Sjdpvoid audit_arg_svipc_id(int id); 16933965Sjdpvoid audit_arg_svipc_addr(void *addr); 17033965Sjdpvoid audit_arg_posix_ipc_perm(uid_t uid, gid_t gid, 17133965Sjdp mode_t mode); 17233965Sjdpvoid audit_arg_auditon(union auditon_udata *udata); 17333965Sjdpvoid audit_arg_file(struct proc *p, struct file *fp); 17433965Sjdp 17533965Sjdpvoid audit_sysclose(struct thread *td, int fd); 17633965Sjdp 17733965Sjdpvoid audit_proc_alloc(struct proc *p); 17833965Sjdpvoid audit_proc_kproc0(struct proc *p); 17933965Sjdpvoid audit_proc_init(struct proc *p); 18033965Sjdpvoid audit_proc_fork(struct proc *parent, 18133965Sjdp struct proc *child); 18233965Sjdpvoid audit_proc_free(struct proc *p); 18333965Sjdpvoid audit_thread_alloc(struct thread *td); 18433965Sjdp 18533965Sjdp/* 18633965Sjdp * Define a macro to wrap the audit_arg_* calls by checking the global 18733965Sjdp * audit_enabled flag before performing the actual call. 18833965Sjdp */ 18933965Sjdp#define AUDIT_ARG(op, args...) do { \ 19033965Sjdp if (audit_enabled) \ 19133965Sjdp audit_arg_ ## op (args); \ 19233965Sjdp } while (0) 19333965Sjdp 19433965Sjdp#define AUDIT_SYSCALL_ENTER(code, td) do { \ 19533965Sjdp if (audit_enabled) { \ 19633965Sjdp audit_syscall_enter(code, td); \ 19733965Sjdp } \ 19833965Sjdp } while (0) 19933965Sjdp 20033965Sjdp/* 20133965Sjdp * Wrap the audit_syscall_exit() function so that it is called only when 20233965Sjdp * auditing is enabled, or we have a audit record on the thread. It is 20333965Sjdp * possible that an audit record was begun before auditing was turned off. 20433965Sjdp */ 20533965Sjdp#define AUDIT_SYSCALL_EXIT(error, td) do { \ 20633965Sjdp if (audit_enabled | (td->td_ar != NULL)) \ 20733965Sjdp audit_syscall_exit(error, td); \ 20833965Sjdp } while (0) 20933965Sjdp 21033965Sjdp/* 21133965Sjdp * A Macro to wrap the audit_sysclose() function. 21233965Sjdp */ 21333965Sjdp#define AUDIT_SYSCLOSE(td, fd) do { \ 21433965Sjdp if (audit_enabled) \ 21533965Sjdp audit_sysclose(td, fd); \ 21633965Sjdp } while (0) 21733965Sjdp 21833965Sjdp#else /* !AUDIT */ 21933965Sjdp 22033965Sjdpvoid audit_proc_init(struct proc *p); 22133965Sjdpvoid audit_proc_fork(struct proc *parent, 22233965Sjdp struct proc *child); 22333965Sjdpvoid audit_proc_free(struct proc *p); 22433965Sjdp 22533965Sjdp#define AUDIT_ARG(op, args...) do { \ 22633965Sjdp } while (0) 22733965Sjdp 22833965Sjdp#define AUDIT_SYSCALL_ENTER(code, td) do { \ 22933965Sjdp } while (0) 23033965Sjdp 23133965Sjdp#define AUDIT_SYSCALL_EXIT(error, td) do { \ 23233965Sjdp } while (0) 23333965Sjdp 23433965Sjdp#define AUDIT_SYSCLOSE(p, fd) do { \ 23533965Sjdp } while (0) 23633965Sjdp 23733965Sjdp#endif /* AUDIT */ 23833965Sjdp 23933965Sjdp#endif /* !_BSM_AUDIT_KERNEL_H */ 24033965Sjdp