xref: /titanic_52/usr/src/lib/libbsm/common/adt_xlate.h (revision 9525b14bcdeb5b5f6f95ab27c2f48f18bd2ec829)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * adt_xlate.h
23  *
24  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  *
27  */
28 
29 #ifndef _BSM_XLATE_H
30 #define	_BSM_XLATE_H
31 
32 #include <priv.h>
33 
34 #include <bsm/libbsm.h>
35 
36 #include <tsol/label.h>
37 
38 #include "adt_event.h"
39 
40 #ifdef	__cplusplus
41 extern "C" {
42 #endif
43 
44 #ifndef TEXT_DOMAIN
45 #define	TEXT_DOMAIN	"SYS_TEST"
46 #endif
47 
48 /*
49  * values for adt_session_model
50  * In the session model, the session and process are unrelated, so
51  * such things as the supplementary group token make no sense.  In
52  * the process model, the process and session are the same.
53  */
54 #define	ADT_SESSION_MODEL	1
55 #define	ADT_PROCESS_MODEL	0
56 
57 #define	ADT_HAVE_MASK	0x01
58 #define	ADT_HAVE_TID	0x02
59 #define	ADT_HAVE_AUID	0x04
60 #define	ADT_HAVE_ASID	0x08
61 #define	ADT_HAVE_IDS	0x10
62 #define	ADT_HAVE_ALL	(uint32_t)\
63 	(ADT_HAVE_MASK | ADT_HAVE_TID | ADT_HAVE_AUID | ADT_HAVE_ASID |\
64 	ADT_HAVE_IDS)
65 
66 /*
67  * dummy token types for privilege
68  */
69 #define	ADT_AUT_PRIV_L	-100	/* limit set */
70 #define	ADT_AUT_PRIV_I	-101	/* inherited set */
71 #define	ADT_AUT_PRIV_E	-102	/* effective set */
72 #define	ADT_CMD_ALT	-103	/* dummy token type for alternate command */
73 #define	ADT_IN_PEER	-104	/* peer address in_addr and in_port */
74 #define	ADT_IN_REMOTE	-105	/* specified address in_addr */
75 
76 enum adt_generic {ADT_GENERIC}; /* base for text enums */
77 
78 typedef struct adt_internal_state	adt_internal_state_t;
79 
80 union union_of_events {
81 	union adt_event_data	d0;
82 };
83 
84 /*
85  * The order of the lists MUST match the order in
86  * struct msg_text adt_msg_text that is generated by
87  * auditxml in adt_xlate.c.
88  */
89 enum adt_msg_list {
90 	ADT_LIST_FAIL_PAM,
91 	ADT_LIST_FAIL_VALUE,
92 	ADT_LIST_LOGIN_TEXT,
93 	ADT_LIST_TPM_E,
94 	ADT_LIST_UADMIN_FCN};
95 
96 enum datatype {ADT_UNDEFINED = 0,
97     ADT_DATE,
98     ADT_MSG,
99     ADT_UINT,
100     ADT_INT,
101     ADT_INT32,
102     ADT_UINT16,
103     ADT_UINT32,
104     ADT_UINT32STAR,
105     ADT_UINT32ARRAY,
106     ADT_UID,
107     ADT_GID,
108     ADT_UIDSTAR,
109     ADT_GIDSTAR,
110     ADT_UINT64,
111     ADT_LONG,
112     ADT_ULONG,
113     ADT_CHAR,
114     ADT_CHARSTAR,
115     ADT_CHAR2STAR,	/* char **			*/
116     ADT_PID,
117     ADT_PRIVSTAR,
118     ADT_TERMIDSTAR,
119     ADT_MLABELSTAR,
120     ADT_FD
121 };
122 typedef enum datatype datatype_t;
123 
124 union convert {
125     enum adt_generic	msg_selector;
126     boolean_t		tbool;
127     uint_t		tuint;
128     int			tint;
129     int32_t		tint32;
130     uint16_t		tuint16;
131     uint32_t		tuint32;
132     uint64_t		tuint64;
133     int32_t		*tint32star;
134     uint32_t		*tuint32star;
135     uid_t		tuid;
136     gid_t		tgid;
137     uid_t		*tuidstar;
138     gid_t		*tgidstar;
139     pid_t		tpid;
140     long		tlong;
141     ulong_t		tulong;
142     char		tchar;
143     char		*tcharstar;
144     char		**tchar2star;
145     au_tid_addr_t 	*ttermid;
146     priv_set_t		*tprivstar;
147     m_label_t		*tm_label;
148     fd_t		tfd;
149 };
150 
151 struct adt_event_state {
152 	union union_of_events	ae_event_data;
153 
154 	/* above is user's area; below is internal.  Order matters */
155 
156 	uint_t		ae_check;	/* see adt_internal_state	*/
157 	int		ae_event_handle;
158 	au_event_t	ae_event_id;	/* external id			*/
159 	au_event_t	ae_internal_id; /* translated			*/
160 	int		ae_rc;		/* exit token rc		*/
161 	int		ae_type;	/* exit error type		*/
162 	struct adt_internal_state *ae_session;
163 };
164 
165 struct datadefs {
166 	datatype_t	dd_datatype;	/* input data type */
167 	size_t		dd_input_size;	/* input data size */
168 };
169 typedef struct datadefs datadef;
170 
171 typedef void (* adt_token_func_t)(datadef *, void *, int,
172     struct adt_event_state *, char *);
173 
174 typedef char *(* adt_msg_func_t)(enum adt_generic);
175 
176 #define	ADT_VALID	0xAAAA5555
177 
178 struct adt_internal_state {
179 	uint32_t	as_check;	/* == ADT_VALID when created,	*/
180 					/* == zero when freed		*/
181 	uid_t		as_euid;
182 	uid_t		as_ruid;
183 	gid_t		as_egid;
184 	gid_t		as_rgid;
185 
186 	struct auditinfo_addr as_info;
187 	/*
188 	 * ai_auid				audit id
189 	 * ai_mask.am_success			pre-selection mask
190 	 * ai_mask.am_failure
191 	 * ai_termid	.at_port		terminal id
192 	 *		.at_type
193 	 *		.ai_termid.at_addr[0]
194 	 *		.ai_termid.at_addr[1]
195 	 *		.ai_termid.at_addr[2]
196 	 *		.ai_termid.at_addr[3]
197 	 * ai_asid				session id
198 	 */
199 	int		as_audit_enabled;	/* audit enable/disable state */
200 	/*
201 	 * data above this line is exported / imported
202 	 * To maintain upward compatibility, the above structures
203 	 * can't change, so for version 2, all changes will need
204 	 * to be added here and the old format (above) maintained.
205 	 */
206 
207 	uint32_t		as_have_user_data;
208 
209 	int			as_kernel_audit_policy;
210 	int			as_session_model;
211 	adt_session_flags_t	as_flags;
212 	pid_t			as_pid;
213 	m_label_t		*as_label;	/* if is_system_labeled */
214 	adt_translation_t	**as_xlate;
215 	void (*as_preload)(au_event_t, adt_event_data_t *);
216 };
217 
218 /*
219  * export data format
220  * version number changes when adt_internal_state's export portion
221  * changes.
222  */
223 #define	PROTOCOL_VERSION_1	1
224 #define	PROTOCOL_VERSION_2	2
225 
226 /*
227  * most recent version is at the top; down level consumers are
228  * expected to search down via "prev_offsetX" to a version they
229  * understand.  "v1" is first, "v0" is used to illustrate correct
230  * order for future use.
231  */
232 
233 struct adt_export_v2 {
234 	int32_t		ax_euid;
235 	int32_t		ax_ruid;
236 	int32_t		ax_egid;
237 	int32_t		ax_rgid;
238 	int32_t		ax_auid;
239 	uint32_t	ax_mask_success;
240 	uint32_t	ax_mask_failure;
241 	uint32_t	ax_port;
242 	uint32_t	ax_type;
243 	uint32_t	ax_addr[4];
244 	uint32_t	ax_asid;
245 	int		ax_audit_enabled;
246 	pid_t		ax_pid;
247 	size32_t	ax_label_len;	/* 0, unlabeled */
248 /*	char		ax_label[ax_label_len];	if, is_system_labeled */
249 };
250 struct adt_export_v1 {
251 	int32_t		ax_euid;
252 	int32_t		ax_ruid;
253 	int32_t		ax_egid;
254 	int32_t		ax_rgid;
255 	int32_t		ax_auid;
256 	uint32_t	ax_mask_success;
257 	uint32_t	ax_mask_failure;
258 	uint32_t	ax_port;
259 	uint32_t	ax_type;
260 	uint32_t	ax_addr[4];
261 	uint32_t	ax_asid;
262 	int		ax_audit_enabled;
263 	uint32_t	ax_size_of_tsol_data;	/* zero for non-TSOL systems */
264 };
265 struct export_link {
266 	int32_t		ax_version;
267 	int32_t		ax_offset;
268 };
269 struct export_header {
270 	uint32_t		ax_check;
271 	int32_t			ax_buffer_length;
272 	struct export_link	ax_link;
273 };
274 
275 struct adt_export_data {
276 	struct export_header	ax_header;
277 
278 	struct		adt_export_v2 ax_v2;
279 	/*
280 	 * end of version 2 data
281 	 */
282 	struct export_link	ax_next_v1;
283 	struct		adt_export_v1 ax_v1;
284 	/*
285 	 * end of version 1 data
286 	 * struct export_link	ax_next_A;
287 	 * data for older version
288 	 * struct adt_export_v0 ax_v0;
289 	 */
290 	struct export_link	ax_last; /* terminator */
291 };
292 
293 /*
294  * struct entry defines rows in tables defined in adt_xlate.c
295  */
296 
297 struct entry {
298 	char		en_token_id;	/* token id */
299 	int		en_count_types;	/* # of input fields for this token */
300 	datadef		*en_type_def;	/* field type and size of each input */
301 	struct entry	*en_next_token;	/* linked list pointer */
302 	size_t		en_offset;	/* offset into structure for input */
303 	int		en_required;	/* if 1, always output a token */
304 	int		en_tsol;	/* if 1, reserved if for TX */
305 	char		*en_msg_format;	/* pointer to sprintf format string */
306 };
307 
308 struct translation {
309 	int		tx_offsetsCalculated;	/* eponymous */
310 	au_event_t	tx_external_event;	/* event id, external view */
311 	au_event_t	tx_internal_event;	/* event id, internal view */
312 	int		tx_entries;		/* array size of entry array */
313 	struct entry	*tx_first_entry;	/* start of linked list */
314 	struct entry	*tx_top_entry;		/* first array element */
315 };
316 
317 struct token_jmp {
318 	long			jmp_id;
319 	adt_token_func_t	jmp_to;
320 };
321 
322 struct msg_text {
323 	int	ml_min_index;
324 	int	ml_max_index;
325 	char	**ml_msg_list;
326 	int	ml_offset;
327 };
328 
329 extern struct msg_text adt_msg_text[];
330 
331 extern void adt_write_syslog(const char *, int);
332 extern void adt_token_open(struct adt_event_state *);
333 extern int adt_token_close(struct adt_event_state *);
334 extern void adt_generate_token(struct entry *, void *,
335     struct adt_event_state *);
336 extern void *adt_adjust_address(void *, size_t, size_t);
337 
338 #ifdef	__cplusplus
339 }
340 #endif
341 
342 #endif	/* _BSM_XLATE_H */
343