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