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