xref: /titanic_44/usr/src/lib/libbsm/common/adt_xlate.h (revision ea8dc4b6d2251b437950c0056bc626b311c73c27)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * adt_xlate.h
24  *
25  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  *
28  * Automatically generated code; do not edit
29  */
30 
31 #ifndef _BSM_XLATE_H
32 #define	_BSM_XLATE_H
33 
34 #pragma ident	"%Z%%M%	%I%	%E% SMI"
35 
36 #include <bsm/libbsm.h>
37 #include <priv.h>
38 #include <bsm/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	0x16
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 
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 
87 enum datatype {ADT_UNDEFINED = 0,
88     ADT_DATE,
89     ADT_MSG,
90     ADT_UINT,
91     ADT_INT,
92     ADT_INT32,
93     ADT_UINT16,
94     ADT_UINT32,
95     ADT_UINT32STAR,
96     ADT_UINT32ARRAY,
97     ADT_UID,
98     ADT_GID,
99     ADT_UIDSTAR,
100     ADT_GIDSTAR,
101     ADT_UINT64,
102     ADT_LONG,
103     ADT_ULONG,
104     ADT_CHAR,
105     ADT_CHARSTAR,
106     ADT_CHAR2STAR,	/* char **			*/
107     ADT_PID,
108     ADT_PRIVSTAR,
109     ADT_TERMIDSTAR
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 };
137 
138 struct adt_event_state {
139 	union union_of_events	ae_event_data;
140 
141 	/* above is user's area; below is internal.  Order matters */
142 
143 	uint_t		ae_check;	/* see adt_internal_state	*/
144 	int		ae_event_handle;
145 	au_event_t	ae_event_id;	/* external id			*/
146 	au_event_t	ae_internal_id; /* translated			*/
147 	int		ae_rc;		/* exit token rc		*/
148 	int		ae_type;	/* exit error type		*/
149 	struct adt_internal_state *ae_session;
150 };
151 
152 struct datadefs {
153 	datatype_t	dd_datatype;	/* input data type */
154 	size_t		dd_input_size;	/* input data size */
155 };
156 typedef struct datadefs datadef;
157 
158 typedef void (* adt_token_func_t)(datadef *, void *, int,
159     struct adt_event_state *, char *);
160 
161 typedef char *(* adt_msg_func_t)(enum adt_generic);
162 
163 #define	ADT_VALID	0xAAAA5555
164 
165 struct adt_internal_state {
166 	uint32_t	as_check;	/* == ADT_VALID when created,	*/
167 					/* == zero when freed		*/
168 	uid_t		as_euid;
169 	uid_t		as_ruid;
170 	gid_t		as_egid;
171 	gid_t		as_rgid;
172 
173 	struct auditinfo_addr as_info;
174 	/*
175 	 * ai_auid				audit id
176 	 * ai_mask.am_success			pre-selection mask
177 	 * ai_mask.am_failure
178 	 * ai_termid	.at_port		terminal id
179 	 *		.at_type
180 	 *		.ai_termid.at_addr[0]
181 	 *		.ai_termid.at_addr[1]
182 	 *		.ai_termid.at_addr[2]
183 	 *		.ai_termid.at_addr[3]
184 	 * ai_asid				session id
185 	 */
186 	int		as_audit_enabled;	/* audit enable/disable state */
187 	/*
188 	 * data above this line is exported / imported
189 	 * To maintain upward compatibility, the above structures
190 	 * can't change, so for version 2, all changes will need
191 	 * to be added here and the old format (above) maintained.
192 	 */
193 
194 	uint32_t		as_have_user_data;
195 
196 	int			as_kernel_audit_policy;
197 	int			as_session_model;
198 	adt_session_flags_t	as_flags;
199 };
200 
201 /*
202  * export data format
203  * version number changes when adt_internal_state's export portion
204  * changes.
205  */
206 #define	PROTOCOL_VERSION 1
207 
208 /*
209  * most recent version is at the top; down level consumers are
210  * expected to search down via "prev_offsetX" to a version they
211  * understand.  "v1" is first, "v0" is used to illustrate correct
212  * order for future use.
213  */
214 
215 struct adt_export_v1 {
216 	int32_t		ax_euid;
217 	int32_t		ax_ruid;
218 	int32_t		ax_egid;
219 	int32_t		ax_rgid;
220 	int32_t		ax_auid;
221 	uint32_t	ax_mask_success;
222 	uint32_t	ax_mask_failure;
223 	uint32_t	ax_port;
224 	uint32_t	ax_type;
225 	uint32_t	ax_addr[4];
226 	uint32_t	ax_asid;
227 	int		ax_audit_enabled;
228 	uint32_t	ax_size_of_tsol_data;	/* zero for non-TSOL systems */
229 };
230 struct export_link {
231 	int32_t		ax_version;
232 	int32_t		ax_offset;
233 };
234 struct export_header {
235 	uint32_t		ax_check;
236 	int32_t			ax_buffer_length;
237 	struct export_link	ax_link;
238 };
239 
240 struct adt_export_data {
241 	struct export_header	ax_header;
242 
243 	struct		adt_export_v1 ax_v1;
244 	/*
245 	 * end of version 1 data
246 	 * struct export_link	ax_next_A;
247 	 * data for older version
248 	 * struct adt_export_v0 ax_v0;
249 	 */
250 	struct export_link	ax_last; /* terminator */
251 };
252 
253 /*
254  * struct entry defines rows in tables defined in adt_xlate.c
255  */
256 
257 struct entry {
258 	char		en_token_id;	/* token id */
259 	int		en_count_types;	/* # of input fields for this token */
260 	datadef		*en_type_def;	/* field type and size of each input */
261 	struct entry	*en_next_token;	/* linked list pointer */
262 	size_t		en_offset;	/* offset into structure for input */
263 	int		en_required;	/* if 1, always output a token */
264 	int		en_tsol;	/* if 1, output only #ifdef TSOL */
265 	char		*en_msg_format;	/* pointer to sprintf format string */
266 };
267 
268 struct translation {
269 	int		tx_offsetsCalculated;	/* eponymous */
270 	au_event_t	tx_external_event;	/* event id, external view */
271 	au_event_t	tx_internal_event;	/* event id, internal view */
272 	int		tx_entries;		/* array size of entry array */
273 	struct entry	*tx_first_entry;	/* start of linked list */
274 	struct entry	*tx_top_entry;		/* first array element */
275 };
276 
277 extern struct translation *xlate_table[];
278 
279 struct token_jmp {
280 	long			jmp_id;
281 	adt_token_func_t	jmp_to;
282 };
283 
284 struct msg_text {
285 	int	ml_min_index;
286 	int	ml_max_index;
287 	char	**ml_msg_list;
288 	int	ml_offset;
289 };
290 
291 extern void adt_write_syslog(const char *, int);
292 extern void adt_token_open(struct adt_event_state *);
293 extern void adt_token_close(struct adt_event_state *);
294 extern void adt_generate_token(struct entry *, void *,
295     struct adt_event_state *);
296 extern void *adt_adjust_address(void *, size_t, size_t);
297 extern void adt_preload(au_event_t, adt_event_data_t *);
298 
299 extern struct msg_text adt_msg_text[];
300 
301 #ifdef	__cplusplus
302 }
303 #endif
304 
305 #endif	/* _BSM_XLATE_H */
306