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