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