xref: /onnv-gate/usr/src/uts/common/c2/audit_kernel.h (revision 12918:32a41a5f8110)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52425Sgww  * Common Development and Distribution License (the "License").
62425Sgww  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
2212273SCasper.Dik@Sun.COM  * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate  */
240Sstevel@tonic-gate 
250Sstevel@tonic-gate #ifndef _BSM_AUDIT_KERNEL_H
260Sstevel@tonic-gate #define	_BSM_AUDIT_KERNEL_H
270Sstevel@tonic-gate 
280Sstevel@tonic-gate 
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate  * This file contains the basic auditing control structure definitions.
310Sstevel@tonic-gate  */
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #include <c2/audit_kevents.h>
340Sstevel@tonic-gate #include <sys/priv_impl.h>
350Sstevel@tonic-gate #include <sys/taskq.h>
360Sstevel@tonic-gate #include <sys/zone.h>
370Sstevel@tonic-gate 
382425Sgww #include <sys/tsol/label.h>
392425Sgww 
400Sstevel@tonic-gate #ifdef __cplusplus
410Sstevel@tonic-gate extern "C" {
420Sstevel@tonic-gate #endif
430Sstevel@tonic-gate 
440Sstevel@tonic-gate /*
450Sstevel@tonic-gate  * This table contains the mapping from the system call ID to a corresponding
460Sstevel@tonic-gate  * audit event.
470Sstevel@tonic-gate  *
480Sstevel@tonic-gate  *   au_init() is a function called at the beginning of the system call that
490Sstevel@tonic-gate  *   performs any necessary setup/processing. It maps the call into the
500Sstevel@tonic-gate  *   appropriate event, depending on the system call arguments. It is called
510Sstevel@tonic-gate  *   by audit_start() from trap.c .
520Sstevel@tonic-gate  *
530Sstevel@tonic-gate  *   au_event is the audit event associated with the system call. Most of the
540Sstevel@tonic-gate  *   time it will map directly from the system call i.e. There is one system
550Sstevel@tonic-gate  *   call associated with the event. In some cases, such as shmsys, or open,
560Sstevel@tonic-gate  *   the au_start() function will map the system call to more than one event,
570Sstevel@tonic-gate  *   depending on the system call arguments.
580Sstevel@tonic-gate  *
590Sstevel@tonic-gate  *   au_start() is a function that provides per system call processing at the
600Sstevel@tonic-gate  *   beginning of a system call. It is mainly concerned with preseving the
610Sstevel@tonic-gate  *   audit record components that may be altered so that we can determine
620Sstevel@tonic-gate  *   what the original paramater was before as well as after the system call.
630Sstevel@tonic-gate  *   It is possible that au_start() may be taken away. It might be cleaner to
640Sstevel@tonic-gate  *   define flags in au_ctrl to save a designated argument. For the moment we
650Sstevel@tonic-gate  *   support both mechanisms, however the use of au_start() will be reviewed
660Sstevel@tonic-gate  *   for 4.1.1 and CMW and ZEUS to see if such a general method is justified.
670Sstevel@tonic-gate  *
680Sstevel@tonic-gate  *   au_finish() is a function that provides per system call processing at the
690Sstevel@tonic-gate  *   completion of a system call. In certain circumstances, the type of audit
700Sstevel@tonic-gate  *   event depends on intermidiate results during the processing of the system
710Sstevel@tonic-gate  *   call. It is called in audit_finish() from trap.c .
720Sstevel@tonic-gate  *
730Sstevel@tonic-gate  *   au_ctrl is a control vector that indicates what processing might have to
740Sstevel@tonic-gate  *   be performed, even if there is no auditing for this system call. At
750Sstevel@tonic-gate  *   present this is mostly for path processing for chmod, chroot. We need to
760Sstevel@tonic-gate  *   process the path information in vfs_lookup, even when we are not auditing
770Sstevel@tonic-gate  *   the system call in the case of chdir and chroot.
780Sstevel@tonic-gate  */
790Sstevel@tonic-gate /*
800Sstevel@tonic-gate  * Defines for au_ctrl
810Sstevel@tonic-gate  */
8212617SMarek.Pospisil@Sun.COM #define	S2E_SP  TAD_SAVPATH	/* save path for later use */
8312617SMarek.Pospisil@Sun.COM #define	S2E_MLD TAD_MLD		/* only one lookup per system call */
8412617SMarek.Pospisil@Sun.COM #define	S2E_NPT TAD_NOPATH	/* force no path in audit record */
8512617SMarek.Pospisil@Sun.COM #define	S2E_PUB TAD_PUBLIC_EV	/* syscall is defined as a public op */
860Sstevel@tonic-gate 
870Sstevel@tonic-gate /*
880Sstevel@tonic-gate  * At present, we are using the audit classes imbedded with in the kernel. Each
890Sstevel@tonic-gate  * event has a bit mask determining which classes the event is associated.
900Sstevel@tonic-gate  * The table audit_e2s maps the audit event ID to the audit state.
910Sstevel@tonic-gate  *
920Sstevel@tonic-gate  * Note that this may change radically. If we use a bit vector for the audit
930Sstevel@tonic-gate  * class, we can allow granularity at the event ID for each user. In this
940Sstevel@tonic-gate  * case, the vector would be determined at user level and passed to the kernel
950Sstevel@tonic-gate  * via the setaudit system call.
960Sstevel@tonic-gate  */
970Sstevel@tonic-gate 
980Sstevel@tonic-gate /*
990Sstevel@tonic-gate  * The audit_pad structure holds paths for the current root and directory
1000Sstevel@tonic-gate  * for the process, as well as for open files and directly manipulated objects.
1010Sstevel@tonic-gate  * The reference count minimizes data copies since the process's current
1020Sstevel@tonic-gate  * directory changes very seldom.
1030Sstevel@tonic-gate  */
1040Sstevel@tonic-gate struct audit_path {
1050Sstevel@tonic-gate 	uint_t		audp_ref;	/* reference count */
1060Sstevel@tonic-gate 	uint_t		audp_size;	/* allocated size of this structure */
1070Sstevel@tonic-gate 	uint_t		audp_cnt;	/* number of path sections */
1080Sstevel@tonic-gate 	char		*audp_sect[1];	/* path section pointers */
1090Sstevel@tonic-gate 					/* audp_sect[0] is the path name */
1100Sstevel@tonic-gate 					/* audp_sect[1+] are attribute paths */
1110Sstevel@tonic-gate };
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate /*
1140Sstevel@tonic-gate  * The structure of the terminal ID within the kernel is different from the
1150Sstevel@tonic-gate  * terminal ID in user space. It is a combination of port and IP address.
1160Sstevel@tonic-gate  */
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate struct au_termid {
1190Sstevel@tonic-gate 	dev_t	at_port;
1200Sstevel@tonic-gate 	uint_t	at_type;
1210Sstevel@tonic-gate 	uint_t	at_addr[4];
1220Sstevel@tonic-gate };
1230Sstevel@tonic-gate typedef struct au_termid au_termid_t;
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate /*
1260Sstevel@tonic-gate  * Attributes for deferring the queuing of an event.
1270Sstevel@tonic-gate  */
1280Sstevel@tonic-gate typedef struct au_defer_info {
1290Sstevel@tonic-gate 	struct au_defer_info	*audi_next;	/* next on linked list */
1300Sstevel@tonic-gate 	void	 *audi_ad;		/* audit record */
1317753STon.Nguyen@Sun.COM 	au_event_t	audi_e_type;	/* audit event id */
1327753STon.Nguyen@Sun.COM 	au_emod_t	audi_e_mod;	/* audit event modifier */
1330Sstevel@tonic-gate 	int	audi_flag;		/* au_close*() flags */
1340Sstevel@tonic-gate 	timestruc_t	audi_atime;	/* audit event timestamp */
1350Sstevel@tonic-gate } au_defer_info_t;
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate /*
1380Sstevel@tonic-gate  * The structure p_audit_data hangs off of the process structure. It contains
1390Sstevel@tonic-gate  * all of the audit information necessary to manage the audit record generation
1400Sstevel@tonic-gate  * for each process.
1410Sstevel@tonic-gate  *
1420Sstevel@tonic-gate  * The pad_lock is constructed in the kmem_cache; the rest is combined
1430Sstevel@tonic-gate  * in a sub structure so it can be copied/zeroed in one statement.
1440Sstevel@tonic-gate  *
1450Sstevel@tonic-gate  * The members have been reordered for maximum packing on 64 bit Solaris.
1460Sstevel@tonic-gate  */
1470Sstevel@tonic-gate struct p_audit_data {
1480Sstevel@tonic-gate 	kmutex_t	pad_lock;	/* lock pad data during changes */
1490Sstevel@tonic-gate 	struct _pad_data {
1500Sstevel@tonic-gate 		struct audit_path	*pad_root;	/* process root path */
1510Sstevel@tonic-gate 		struct audit_path	*pad_cwd;	/* process cwd path */
1520Sstevel@tonic-gate 		au_mask_t		pad_newmask;	/* pending new mask */
1530Sstevel@tonic-gate 		int			pad_flags;
1540Sstevel@tonic-gate 	} pad_data;
1550Sstevel@tonic-gate };
1560Sstevel@tonic-gate typedef struct p_audit_data p_audit_data_t;
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate #define	pad_root	pad_data.pad_root
1590Sstevel@tonic-gate #define	pad_cwd		pad_data.pad_cwd
1600Sstevel@tonic-gate #define	pad_newmask	pad_data.pad_newmask
1610Sstevel@tonic-gate #define	pad_flags	pad_data.pad_flags
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate /*
16412617SMarek.Pospisil@Sun.COM  * Defines for process audit flags (pad_flags)
1650Sstevel@tonic-gate  */
1660Sstevel@tonic-gate #define	PAD_SETMASK 	0x00000001	/* need to complete pending setmask */
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate extern kmem_cache_t *au_pad_cache;
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate /*
17112617SMarek.Pospisil@Sun.COM  * Defines for thread audit control/status flags (tad_ctrl)
1720Sstevel@tonic-gate  */
17312617SMarek.Pospisil@Sun.COM #define	TAD_ABSPATH 	0x00000001	/* path from lookup is absolute */
17412617SMarek.Pospisil@Sun.COM #define	TAD_ATCALL	0x00000002	/* *at() syscall, like openat() */
17512617SMarek.Pospisil@Sun.COM #define	TAD_ATTPATH  	0x00000004	/* attribute file lookup */
17612617SMarek.Pospisil@Sun.COM #define	TAD_CORE	0x00000008	/* save attribute during core dump */
17712617SMarek.Pospisil@Sun.COM #define	TAD_ERRJMP	0x00000010	/* abort record generation on error */
17812617SMarek.Pospisil@Sun.COM #define	TAD_MLD		0x00000020	/* system call involves MLD */
17912617SMarek.Pospisil@Sun.COM #define	TAD_NOATTRB 	0x00000040	/* do not automatically add attribute */
18012617SMarek.Pospisil@Sun.COM #define	TAD_NOAUDIT 	0x00000080	/* discard audit record */
18112617SMarek.Pospisil@Sun.COM #define	TAD_NOPATH  	0x00000100	/* force no paths in audit record */
18212617SMarek.Pospisil@Sun.COM #define	TAD_PATHFND 	0x00000200	/* found path, don't retry lookup */
18312617SMarek.Pospisil@Sun.COM #define	TAD_PUBLIC_EV	0x00000400	/* syscall is defined as a public op */
18412617SMarek.Pospisil@Sun.COM #define	TAD_SAVPATH 	0x00000800	/* save path for further processing */
18512617SMarek.Pospisil@Sun.COM #define	TAD_TRUE_CREATE 0x00001000	/* true create, file not found */
1860Sstevel@tonic-gate 
1870Sstevel@tonic-gate /*
1880Sstevel@tonic-gate  * The structure t_audit_data hangs off of the thread structure. It contains
1890Sstevel@tonic-gate  * all of the audit information necessary to manage the audit record generation
1900Sstevel@tonic-gate  * for each thread.
1910Sstevel@tonic-gate  *
1920Sstevel@tonic-gate  */
1930Sstevel@tonic-gate 
1940Sstevel@tonic-gate struct t_audit_data {
1950Sstevel@tonic-gate 	kthread_id_t  tad_thread;	/* DEBUG pointer to parent thread */
1960Sstevel@tonic-gate 	unsigned int  tad_scid;		/* system call ID for finish */
1977753STon.Nguyen@Sun.COM 	au_event_t	tad_event;	/* event for audit record */
1987753STon.Nguyen@Sun.COM 	au_emod_t	tad_evmod;	/* event modifier for audit record */
1990Sstevel@tonic-gate 	int	tad_ctrl;	/* audit control/status flags */
2000Sstevel@tonic-gate 	void	*tad_errjmp;	/* error longjmp (audit record aborted) */
2010Sstevel@tonic-gate 	int	tad_flag;	/* to audit or not to audit */
20211861SMarek.Pospisil@Sun.COM 	uint32_t tad_audit;	/* auditing enabled/disabled */
2030Sstevel@tonic-gate 	struct audit_path	*tad_aupath;	/* captured at vfs_lookup */
2040Sstevel@tonic-gate 	struct audit_path	*tad_atpath;	/* openat prefix, path of fd */
2050Sstevel@tonic-gate 	caddr_t tad_ad;		/* base of accumulated audit data */
2060Sstevel@tonic-gate 	au_defer_info_t	*tad_defer_head;	/* queue of records to defer */
2070Sstevel@tonic-gate 						/* until syscall end: */
2080Sstevel@tonic-gate 	au_defer_info_t	*tad_defer_tail;	/* tail of defer queue */
2090Sstevel@tonic-gate 	priv_set_t tad_sprivs;	/* saved (success) used privs */
2100Sstevel@tonic-gate 	priv_set_t tad_fprivs;	/* saved (failed) used privs */
2110Sstevel@tonic-gate };
2120Sstevel@tonic-gate typedef struct t_audit_data t_audit_data_t;
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate /*
2150Sstevel@tonic-gate  * The f_audit_data structure hangs off of the file structure. It contains
2160Sstevel@tonic-gate  * three fields of data. The audit ID, the audit state, and a path name.
2170Sstevel@tonic-gate  */
2180Sstevel@tonic-gate 
2190Sstevel@tonic-gate struct f_audit_data {
2200Sstevel@tonic-gate 	kthread_id_t	fad_thread;	/* DEBUG creating thread */
2210Sstevel@tonic-gate 	int		fad_flags;	/* audit control flags */
2220Sstevel@tonic-gate 	struct audit_path	*fad_aupath;	/* path from vfs_lookup */
2230Sstevel@tonic-gate };
2240Sstevel@tonic-gate typedef struct f_audit_data f_audit_data_t;
2250Sstevel@tonic-gate 
2260Sstevel@tonic-gate #define	FAD_READ	0x0001		/* read system call seen */
2270Sstevel@tonic-gate #define	FAD_WRITE	0x0002		/* write system call seen */
2280Sstevel@tonic-gate 
2290Sstevel@tonic-gate #define	P2A(p)	(p->p_audit_data)
2300Sstevel@tonic-gate #define	T2A(t)	(t->t_audit_data)
2310Sstevel@tonic-gate #define	U2A(u)	(curthread->t_audit_data)
2320Sstevel@tonic-gate #define	F2A(f)	(f->f_audit_data)
2330Sstevel@tonic-gate 
2340Sstevel@tonic-gate #define	u_ad    ((U2A(u))->tad_ad)
2350Sstevel@tonic-gate #define	ad_ctrl ((U2A(u))->tad_ctrl)
2360Sstevel@tonic-gate #define	ad_flag ((U2A(u))->tad_flag)
2370Sstevel@tonic-gate 
2380Sstevel@tonic-gate #define	AU_BUFSIZE	128		/* buffer size for the buffer pool */
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate struct au_buff {
2410Sstevel@tonic-gate 	char		buf[AU_BUFSIZE];
2420Sstevel@tonic-gate 	struct au_buff	*next_buf;
2430Sstevel@tonic-gate 	struct au_buff	*next_rec;
2440Sstevel@tonic-gate 	ushort_t	rec_len;
2450Sstevel@tonic-gate 	uchar_t		len;
2460Sstevel@tonic-gate 	uchar_t		flag;
2470Sstevel@tonic-gate };
2480Sstevel@tonic-gate 
2490Sstevel@tonic-gate typedef struct au_buff au_buff_t;
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate /*
2520Sstevel@tonic-gate  * Kernel audit queue structure.
2530Sstevel@tonic-gate  */
2540Sstevel@tonic-gate struct audit_queue {
2550Sstevel@tonic-gate 	au_buff_t *head;	/* head of queue */
2560Sstevel@tonic-gate 	au_buff_t *tail;	/* tail of queue */
2570Sstevel@tonic-gate 	ssize_t	cnt;		/* number elements on queue */
2580Sstevel@tonic-gate 	size_t	hiwater;	/* high water mark to block */
2590Sstevel@tonic-gate 	size_t	lowater;	/* low water mark to restart */
2600Sstevel@tonic-gate 	size_t	bufsz;		/* audit trail write buffer size */
2610Sstevel@tonic-gate 	size_t	buflen;		/* audit trail buffer length in use */
2620Sstevel@tonic-gate 	clock_t	delay;		/* delay before flushing queue */
2630Sstevel@tonic-gate 	int	wt_block;	/* writer is blocked (1) */
2640Sstevel@tonic-gate 	int	rd_block;	/* reader is blocked (1) */
2650Sstevel@tonic-gate 	kmutex_t lock;		/* mutex lock for queue modification */
2660Sstevel@tonic-gate 	kcondvar_t write_cv;	/* sleep structure for write block */
2670Sstevel@tonic-gate 	kcondvar_t read_cv;	/* sleep structure for read block */
2680Sstevel@tonic-gate };
2690Sstevel@tonic-gate 
2700Sstevel@tonic-gate 
2710Sstevel@tonic-gate union rval;
2720Sstevel@tonic-gate struct audit_s2e {
2730Sstevel@tonic-gate 	au_event_t (*au_init)(au_event_t);
2740Sstevel@tonic-gate 				/* convert au_event to real audit event ID */
2750Sstevel@tonic-gate 
2760Sstevel@tonic-gate 	int au_event;		/* default audit event for this system call */
2770Sstevel@tonic-gate 	void (*au_start)(struct t_audit_data *);
2780Sstevel@tonic-gate 				/* pre-system call audit processing */
2790Sstevel@tonic-gate 	void (*au_finish)(struct t_audit_data *, int, union rval *);
2800Sstevel@tonic-gate 				/* post-system call audit processing */
2810Sstevel@tonic-gate 	int au_ctrl;		/* control flags for auditing actions */
2820Sstevel@tonic-gate };
2830Sstevel@tonic-gate 
2840Sstevel@tonic-gate extern struct audit_s2e audit_s2e[];
2850Sstevel@tonic-gate 
2860Sstevel@tonic-gate #define	AUK_VALID	0x5A5A5A5A
2870Sstevel@tonic-gate #define	AUK_INVALID	0
2880Sstevel@tonic-gate /*
2890Sstevel@tonic-gate  * per zone audit context
2900Sstevel@tonic-gate  */
2910Sstevel@tonic-gate struct au_kcontext {
2920Sstevel@tonic-gate 	uint32_t		auk_valid;
2930Sstevel@tonic-gate 	zoneid_t		auk_zid;
2940Sstevel@tonic-gate 
2950Sstevel@tonic-gate 	boolean_t		auk_hostaddr_valid;
2960Sstevel@tonic-gate 	int			auk_sequence;
2970Sstevel@tonic-gate 	int			auk_auditstate;
2980Sstevel@tonic-gate 	int			auk_output_active;
2990Sstevel@tonic-gate 	struct vnode		*auk_current_vp;
30011871SMarek.Pospisil@Sun.COM 	uint32_t		auk_policy;
3010Sstevel@tonic-gate 
3020Sstevel@tonic-gate 	struct audit_queue	auk_queue;
3030Sstevel@tonic-gate 
3040Sstevel@tonic-gate 	au_dbuf_t		*auk_dbuffer;	/* auditdoor output */
3050Sstevel@tonic-gate 
3060Sstevel@tonic-gate 	au_stat_t		auk_statistics;
3070Sstevel@tonic-gate 
308*12918SJan.Friedel@Sun.COM 	k_auditinfo_addr_t	auk_info;
3090Sstevel@tonic-gate 	kmutex_t		auk_eagain_mutex; /* door call retry */
3100Sstevel@tonic-gate 	kcondvar_t		auk_eagain_cv;
3110Sstevel@tonic-gate 
3120Sstevel@tonic-gate 	taskq_t			*auk_taskq;	/* output thread */
3130Sstevel@tonic-gate 
3140Sstevel@tonic-gate 	/* Only one audit svc per zone at a time */
3155992Sgww 	/* With the elimination of auditsvc, can this also go? see 6648414 */
3160Sstevel@tonic-gate 	kmutex_t 		auk_svc_lock;
3175992Sgww 
3182640Srica 	au_state_t		auk_ets[MAX_KEVENTS + 1];
3190Sstevel@tonic-gate };
3200Sstevel@tonic-gate #ifndef AUK_CONTEXT_T
3210Sstevel@tonic-gate #define	AUK_CONTEXT_T
3220Sstevel@tonic-gate typedef struct au_kcontext au_kcontext_t;
3230Sstevel@tonic-gate #endif
3240Sstevel@tonic-gate 
3250Sstevel@tonic-gate extern zone_key_t au_zone_key;
3260Sstevel@tonic-gate 
3270Sstevel@tonic-gate /*
3280Sstevel@tonic-gate  * Kernel auditing external variables
3290Sstevel@tonic-gate  */
33011871SMarek.Pospisil@Sun.COM extern uint32_t audit_policy;
3310Sstevel@tonic-gate extern int audit_active;
3320Sstevel@tonic-gate 
3330Sstevel@tonic-gate extern struct audit_queue au_queue;
3340Sstevel@tonic-gate extern struct p_audit_data *pad0;
3350Sstevel@tonic-gate extern struct t_audit_data *tad0;
3360Sstevel@tonic-gate 
3370Sstevel@tonic-gate /*
3380Sstevel@tonic-gate  * audit_path support routines
3390Sstevel@tonic-gate  */
3400Sstevel@tonic-gate void au_pathhold(struct audit_path *);
3410Sstevel@tonic-gate void au_pathrele(struct audit_path *);
3420Sstevel@tonic-gate struct audit_path *au_pathdup(const struct audit_path *, int, int);
3430Sstevel@tonic-gate 
34411861SMarek.Pospisil@Sun.COM void au_pad_init(void);
34511861SMarek.Pospisil@Sun.COM 
34611861SMarek.Pospisil@Sun.COM int auditctl(int cmd, caddr_t data, int length);
34711861SMarek.Pospisil@Sun.COM int auditdoor(int fd);
34811861SMarek.Pospisil@Sun.COM int getauid(caddr_t);
34911861SMarek.Pospisil@Sun.COM int setauid(caddr_t);
35011861SMarek.Pospisil@Sun.COM int getaudit(caddr_t);
35111861SMarek.Pospisil@Sun.COM int getaudit_addr(caddr_t, int);
35211861SMarek.Pospisil@Sun.COM int setaudit(caddr_t);
35311861SMarek.Pospisil@Sun.COM int setaudit_addr(caddr_t, int);
35411861SMarek.Pospisil@Sun.COM 
3550Sstevel@tonic-gate /*
3560Sstevel@tonic-gate  * Macros to hide asynchronous, non-blocking audit record start and finish
3570Sstevel@tonic-gate  * processing.
3580Sstevel@tonic-gate  *
3590Sstevel@tonic-gate  * NOTE: must be used in (void) funcction () { ... }
3600Sstevel@tonic-gate  */
3610Sstevel@tonic-gate 
3620Sstevel@tonic-gate #define	AUDIT_ASYNC_START(rp, audit_event, sorf) \
3630Sstevel@tonic-gate { \
3640Sstevel@tonic-gate 	label_t jb; \
3650Sstevel@tonic-gate 	if (setjmp(&jb)) { \
3660Sstevel@tonic-gate 		/* cleanup any residual audit data */ \
3670Sstevel@tonic-gate 		audit_async_drop((caddr_t *)&(rp), 0); \
3680Sstevel@tonic-gate 		return; \
3690Sstevel@tonic-gate 	} \
3700Sstevel@tonic-gate 	/* auditing enabled and we're preselected for this event? */ \
3710Sstevel@tonic-gate 	if (audit_async_start(&jb, audit_event, sorf)) { \
3720Sstevel@tonic-gate 		return; \
3730Sstevel@tonic-gate 	} \
3740Sstevel@tonic-gate }
3750Sstevel@tonic-gate 
37611861SMarek.Pospisil@Sun.COM #define	AUDIT_ASYNC_FINISH(rp, audit_event, event_modifier, event_time) \
37711861SMarek.Pospisil@Sun.COM 	audit_async_finish((caddr_t *)&(rp), audit_event, event_modifier, \
37811861SMarek.Pospisil@Sun.COM 	event_time);
3790Sstevel@tonic-gate 
3800Sstevel@tonic-gate 
3810Sstevel@tonic-gate #ifdef	_KERNEL
3820Sstevel@tonic-gate au_buff_t *au_get_buff(void), *au_free_buff(au_buff_t *);
3830Sstevel@tonic-gate #endif
3840Sstevel@tonic-gate 
3850Sstevel@tonic-gate /*
3862425Sgww  * Macro for uniform "subject" token(s) generation
3870Sstevel@tonic-gate  */
3886900Sjf206706 #define	AUDIT_SETSUBJ_GENERIC(u, c, a, k, p)		\
3896900Sjf206706 	(au_write((u), au_to_subject(crgetuid(c),	\
3906900Sjf206706 	    crgetgid(c), crgetruid(c), crgetrgid(c),	\
3916900Sjf206706 	    p, (a)->ai_auid, (a)->ai_asid,		\
3926900Sjf206706 	    &((a)->ai_termid))));			\
3936900Sjf206706 	((is_system_labeled()) ?  au_write((u),		\
3946900Sjf206706 	    au_to_label(CR_SL((c)))) : (void) 0);	\
3956900Sjf206706 	(((k)->auk_policy & AUDIT_GROUP) ? au_write((u),\
3966900Sjf206706 	    au_to_groups(crgetgroups(c),		\
3976900Sjf206706 	    crgetngroups(c))) : (void) 0)
3980Sstevel@tonic-gate 
3994165Stz204579 #define	AUDIT_SETSUBJ(u, c, a, k)      		\
4004165Stz204579 	AUDIT_SETSUBJ_GENERIC(u, c, a, k, curproc->p_pid)
4014165Stz204579 
40212273SCasper.Dik@Sun.COM #define	AUDIT_SETPROC_GENERIC(u, c, a, p)		\
40312273SCasper.Dik@Sun.COM 	(au_write((u), au_to_process(crgetuid(c),	\
40412273SCasper.Dik@Sun.COM 	    crgetgid(c), crgetruid(c), crgetrgid(c),	\
40512273SCasper.Dik@Sun.COM 	    p, (a)->ai_auid, (a)->ai_asid,		\
40612273SCasper.Dik@Sun.COM 	    &((a)->ai_termid))));
40712273SCasper.Dik@Sun.COM 
40812273SCasper.Dik@Sun.COM #define	AUDIT_SETPROC(u, c, a)      		\
40912273SCasper.Dik@Sun.COM 	AUDIT_SETPROC_GENERIC(u, c, a, curproc->p_pid)
41012273SCasper.Dik@Sun.COM 
4110Sstevel@tonic-gate /*
4120Sstevel@tonic-gate  * Macros for type conversion
4130Sstevel@tonic-gate  */
4140Sstevel@tonic-gate 
4150Sstevel@tonic-gate /* au_membuf head, to typed data */
4160Sstevel@tonic-gate #define	memtod(x, t)	((t)x->buf)
4170Sstevel@tonic-gate 
4180Sstevel@tonic-gate /* au_membuf types */
4190Sstevel@tonic-gate #define	MT_FREE		0	/* should be on free list */
4200Sstevel@tonic-gate #define	MT_DATA		1	/* dynamic (data) allocation */
4210Sstevel@tonic-gate 
4220Sstevel@tonic-gate /* flags to au_memget */
4230Sstevel@tonic-gate #define	DONTWAIT	0
4240Sstevel@tonic-gate #define	WAIT		1
4250Sstevel@tonic-gate 
4260Sstevel@tonic-gate #define	AU_PACK	1	/* pack data in au_append_rec() */
4270Sstevel@tonic-gate #define	AU_LINK 0	/* link data in au_append_rec() */
4280Sstevel@tonic-gate 
4290Sstevel@tonic-gate /* flags to async routines */
4300Sstevel@tonic-gate #define	AU_BACKEND	1	/* called from softcall backend */
4310Sstevel@tonic-gate 
4320Sstevel@tonic-gate #ifdef __cplusplus
4330Sstevel@tonic-gate }
4340Sstevel@tonic-gate #endif
4350Sstevel@tonic-gate 
4360Sstevel@tonic-gate #endif /* _BSM_AUDIT_KERNEL_H */
437