xref: /titanic_51/usr/src/cmd/auditreduce/auditrt.h (revision db874c57ae335a07060499f1492b0d0e2593e26c)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _AUDITRT_H
28 #define	_AUDITRT_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  * Auditreduce data structures.
38  */
39 
40 /*
41  * File Control Block
42  * Controls a single file.
43  * These are held by the pcb's in audit_pcbs[] in a linked list.
44  * There is one fcb for each file controlled by the pcb,
45  * and all of the files in a list have the same suffix in their names.
46  */
47 struct audit_fcb {
48 	struct audit_fcb *fcb_next;	/* ptr to next fcb in list */
49 	int	fcb_flags;	/* flags - see below */
50 	time_t	fcb_start;	/* start time from filename */
51 	time_t	fcb_end;	/* end time from filename */
52 	char	*fcb_suffix;	/* ptr to suffix in fcb_file */
53 	char	*fcb_name;	/* ptr to name in fcb_file */
54 	char	fcb_file[1];	/* full path and name string */
55 };
56 
57 typedef struct audit_fcb audit_fcb_t;
58 
59 /*
60  * Flags for fcb_flags.
61  */
62 #define	FF_NOTTERM	0x01	/* file is "not_terminated" */
63 #define	FF_DELETE	0x02	/* we may delete this file if requested */
64 
65 /*
66  * Process Control Block
67  * A pcb comes in two types:
68  * It controls either:
69  *
70  * 1.	A single group of pcbs (processes that are lower on the process tree).
71  *	These are the pcb's that the process tree is built from.
72  *	These are allocated as needed while the process tree is	being built.
73  *
74  * 2.	A single group of files (fcbs).
75  *	All of the files in one pcb have the same suffix in their filename.
76  *	They are controlled by the leaf nodes of the process tree.
77  *	They are found in audit_pcbs[].
78  *	They are initially setup by process_fileopt() when the files to be
79  *	processes are gathered together. Then they are parsed out to
80  *	the leaf nodes by mfork().
81  *	A particular leaf node's range of audit_pcbs[] is determined
82  *	in the call to mfork() by the lo and hi paramters.
83  */
84 struct audit_pcb {
85 	struct audit_pcb *pcb_below;	/* ptr to group of pcb's */
86 	struct audit_pcb *pcb_next;	/* ptr to next - for list in mproc() */
87 	int	pcb_procno;	/* subprocess # */
88 	int	pcb_nrecs;	/* how many records read (current pcb/file) */
89 	int	pcb_nprecs;	/* how many records put (current pcb/file) */
90 	int	pcb_flags;	/* flags - see below */
91 	int	pcb_count;	/* count of active pcb's */
92 	int	pcb_lo;		/* low index for pcb's */
93 	int	pcb_hi;		/* hi index for pcb's */
94 	int	pcb_size;	/* size of current record buffer */
95 	time_t	pcb_time;	/* time of current record */
96 	time_t	pcb_otime;	/* time of previous record */
97 	char	*pcb_rec;	/* ptr to current record buffer */
98 	char	*pcb_suffix;	/* ptr to suffix name (string) */
99 	audit_fcb_t *pcb_first;	/* ptr to first fcb_ */
100 	audit_fcb_t *pcb_last;	/* ptr to last fcb_ */
101 	audit_fcb_t *pcb_cur;	/* ptr to current fcb_ */
102 	audit_fcb_t *pcb_dfirst; /* ptr to first fcb_ for deleting */
103 	audit_fcb_t *pcb_dlast;	/* ptr to last fcb_ for deleting */
104 	FILE	 *pcb_fpr;	/* read stream */
105 	FILE	 *pcb_fpw;	/* write stream */
106 };
107 
108 typedef struct audit_pcb audit_pcb_t;
109 
110 /*
111  * Flags for pcb_flags
112  */
113 #define	PF_ROOT		0x01	/* current pcb is the root of process tree */
114 #define	PF_LEAF		0x02	/* current pcb is a leaf of process tree */
115 #define	PF_FILE		0x04	/* current pcb uses files as input, not pipes */
116 
117 /*
118  * Message selection options
119  */
120 #define	M_AFTER		0x0001	/* 'a' after a time */
121 #define	M_BEFORE	0x0002	/* 'b' before a time */
122 #define	M_CLASS		0x0004	/* 'c' event class */
123 #define	M_GROUPE 	0x0008	/* 'f' effective group-id */
124 #define	M_GROUPR 	0x0010	/* 'g' real group-id */
125 #define	M_OBJECT	0x0020	/* 'o' object */
126 #define	M_SUBJECT	0x0040	/* 'j' subject */
127 #define	M_TYPE		0x0080	/* 'm' event type */
128 #define	M_USERA		0x0100	/* 'u' audit user */
129 #define	M_USERE		0x0200	/* 'e' effective user */
130 #define	M_USERR		0x0400	/* 'r' real user */
131 #define	M_LABEL		0x0800	/* 'l' mandatory label range */
132 #define	M_ZONENAME	0x1000	/* 'z' zone name */
133 #define	M_SID		0x2000	/* 's' session ID */
134 #define	M_SORF		0x4000	/* success or failure of event */
135 #define	M_TID		0x8000	/* 't' terminal ID */
136 /*
137  * object types
138  */
139 
140 /* XXX Why is this a bit map?  There can be only one M_OBJECT. */
141 
142 #define	OBJ_LP		0x00001  /* 'o' lp object */
143 #define	OBJ_MSG		0x00002  /* 'o' msgq object */
144 #define	OBJ_PATH	0x00004  /* 'o' file system object */
145 #define	OBJ_PROC	0x00008  /* 'o' process object */
146 #define	OBJ_SEM		0x00010  /* 'o' semaphore object */
147 #define	OBJ_SHM		0x00020  /* 'o' shared memory object */
148 #define	OBJ_SOCK	0x00040  /* 'o' socket object */
149 #define	OBJ_FGROUP	0x00080  /* 'o' file group */
150 #define	OBJ_FOWNER	0x00100  /* 'o' file owner */
151 #define	OBJ_MSGGROUP	0x00200	 /* 'o' msgq [c]group */
152 #define	OBJ_MSGOWNER	0x00400  /* 'o' msgq [c]owner */
153 #define	OBJ_PGROUP	0x00800  /* 'o' process [e]group */
154 #define	OBJ_POWNER	0x01000  /* 'o' process [e]owner */
155 #define	OBJ_SEMGROUP	0x02000  /* 'o' semaphore [c]group */
156 #define	OBJ_SEMOWNER	0x04000  /* 'o' semaphore [c]owner */
157 #define	OBJ_SHMGROUP	0x08000  /* 'o' shared memory [c]group */
158 #define	OBJ_SHMOWNER	0x10000  /* 'o' shared memory [c]owner */
159 
160 #define	SOCKFLG_MACHINE 0	/* search socket token by machine name */
161 #define	SOCKFLG_PORT    1	/* search socket token by port number */
162 
163 /*
164  * Global variables
165  */
166 extern unsigned short m_type;	/* 'm' message type */
167 extern gid_t	m_groupr;	/* 'g' real group-id */
168 extern gid_t	m_groupe;	/* 'f' effective group-id */
169 extern uid_t	m_usera;	/* 'u' audit user */
170 extern uid_t	m_userr;	/* 'r' real user */
171 extern uid_t	m_usere;	/* 'f' effective user */
172 extern au_asid_t m_sid;		/* 's' session-id */
173 extern time_t	m_after;	/* 'a' after a time */
174 extern time_t	m_before;	/* 'b' before a time */
175 extern audit_state_t mask;	/* used with m_class */
176 extern char	*zonename;	/* 'z' zonename */
177 
178 #ifdef	TSOL
179 extern brange_t m_label;	/* 'l' mandatory label range */
180 #endif	/* TSOL */
181 extern int	flags;
182 extern int	checkflags;
183 extern int	socket_flag;
184 extern int	ip_type;
185 extern int	ip_ipv6[4];	/* ip ipv6 object identifier */
186 extern int	obj_flag;	/* 'o' object type */
187 extern int	obj_id;		/* object identifier */
188 extern gid_t	obj_group;	/* object group */
189 extern uid_t	obj_owner;	/* object owner */
190 extern int	subj_id; 	/* subject identifier */
191 extern char	ipc_type;	/* 'o' object type - tell what type of IPC */
192 
193 /*
194  * File selection options
195  */
196 extern char	*f_machine;	/* 'M' machine (suffix) type */
197 extern char	*f_root;	/* 'R' audit root */
198 extern char	*f_server;	/* 'S' server */
199 extern char	*f_outfile;	/* 'W' output file */
200 extern int	f_all;		/* 'A' all records from a file */
201 extern int	f_complete;	/* 'C' only completed files */
202 extern int	f_delete;	/* 'D' delete when done */
203 extern int	f_quiet;	/* 'Q' sshhhh! */
204 extern int	f_verbose;	/* 'V' verbose */
205 extern int	f_stdin;	/* '-' read from stdin */
206 extern int	f_cmdline;	/*	files specified on the command line */
207 extern int	new_mode;	/* 'N' new object selection mode */
208 
209 /*
210  * Error reporting
211  * Error_str is set whenever an error occurs to point to a string describing
212  * the error. When the error message is printed error_str is also
213  * printed to describe exactly what went wrong.
214  * Errbuf is used to build messages with variables in them.
215  */
216 extern char	*error_str;	/* current error message */
217 extern char	errbuf[];	/* buffer for building error message */
218 extern char	*ar;		/* => "auditreduce:" */
219 
220 /*
221  * Control blocks
222  * Audit_pcbs[] is an array of pcbs that control files directly.
223  * In the program's initialization phase it will gather all of the input
224  * files it needs to process. Each file will have one fcb allocated for it,
225  * and each fcb will belong to one pcb from audit_pcbs[]. All of the files
226  * in a single pcb will have the same suffix in their filenames. If the
227  * number of active pcbs in audit_pcbs[] is greater that the number of open
228  * files a single process can have then the program will need to fork
229  * subprocesses to handle all of the files.
230  */
231 extern audit_pcb_t *audit_pcbs;	/* file-holding pcb's */
232 extern int	pcbsize;	/* current size of audit_pcbs[] */
233 extern int	pcbnum;		/* total # of active pcbs in audit_pcbs[] */
234 
235 /*
236  * Time values
237  */
238 extern time_t f_start;		/* time of start rec for outfile */
239 extern time_t f_end;		/* time of end rec for outfile */
240 extern time_t time_now;		/* time program began */
241 
242 /*
243  * Counting vars
244  */
245 extern int	filenum;	/* number of files total */
246 
247 /*
248  * Global variable, class of current record being processed.
249  */
250 extern int	global_class;
251 
252 #ifdef	__cplusplus
253 }
254 #endif
255 
256 #endif /* _AUDITRT_H */
257