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