xref: /titanic_51/usr/src/lib/libbsm/common/adt_token.c (revision fa9e4066f08beec538e775443c5be79dd423fcab)
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_token.c
24  *
25  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  *
28  * This file does not provide any user callable functions.  See adt.c
29  */
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <bsm/adt.h>
33 #include <bsm/adt_event.h>
34 #include <bsm/audit.h>
35 #include <adt_xlate.h>
36 #include <assert.h>
37 #include <netdb.h>
38 #include <priv.h>
39 #include <string.h>
40 #include <strings.h>
41 #include <sys/priv_names.h>
42 #include <sys/types.h>
43 #include <sys/vnode.h>
44 #include <time.h>
45 #include <unistd.h>
46 
47 #ifdef C2_DEBUG
48 #define	DPRINTF(x) {printf x; }
49 #define	DFLUSH fflush(stdout);
50 #else
51 #define	DPRINTF(x)
52 #define	DFLUSH
53 #endif
54 
55 static adt_token_func_t adt_getTokenFunction(char);
56 
57 static char	*empty = "";
58 
59 /*
60  * call adt_token_open() first and adt_token_close() last.
61  *
62  * au_open is sort of broken; it returns a -1 when out of memory that
63  * you're supposed to ignore; au_write and au_close return without
64  * doing anything when a -1 is passed.  This code sort of follows the
65  * au_open model except that it calls syslog to indicate underlying
66  * brokenness.  Other than that, -1 is ignored.
67  */
68 
69 void
70 adt_token_open(struct adt_event_state *event)
71 {
72 	static int	have_syslogged = 0;
73 
74 	event->ae_event_handle = au_open();
75 	if (event->ae_event_handle < 0) {
76 		if (!have_syslogged) {
77 			adt_write_syslog("au_open failed", ENOMEM);
78 			have_syslogged = 1;
79 		}
80 	}
81 	else
82 		have_syslogged = 0;
83 }
84 
85 /*
86  * call generate_token for each token in the order you want the tokens
87  * generated.
88  */
89 
90 void
91 adt_generate_token(struct entry *p_entry, void *p_data,
92     struct adt_event_state *event)
93 {
94 	adt_token_func_t	p_func;
95 
96 	assert((p_entry != NULL) && (p_data != NULL) && (event != NULL));
97 
98 	p_func = adt_getTokenFunction(p_entry->en_token_id);
99 	assert(p_func != NULL);
100 
101 	DPRINTF(("p_entry=%08X, p_data=%08X, offset=%X, msgFmt=%X\n",
102 	    p_entry, p_data, p_entry->en_offset, p_entry->en_msg_format));
103 	DFLUSH
104 
105 	(*p_func)(p_entry->en_type_def,
106 	    (char *)p_data + p_entry->en_offset, p_entry->en_required, event,
107 	    p_entry->en_msg_format);
108 }
109 
110 /* call this last */
111 
112 void
113 adt_token_close(struct adt_event_state *event)
114 {
115 	int	rc;
116 
117 	rc = au_close(event->ae_event_handle, AU_TO_WRITE,
118 	    event->ae_internal_id);
119 	if (rc < 0)
120 		adt_write_syslog("au_close failed", errno);
121 }
122 
123 /*
124  * one function per token -- see the jump table at the end of file
125  */
126 
127 /* ARGSUSED */
128 static void
129 adt_to_return(datadef *def, void *p_data, int required,
130     struct adt_event_state *event, char *notUsed)
131 {
132 
133 #ifdef _LP64
134 	(void) au_write(event->ae_event_handle,
135 	    au_to_return64((int64_t)event->ae_rc, event->ae_type));
136 #else
137 	(void) au_write(event->ae_event_handle,
138 	    au_to_return32((int32_t)event->ae_rc, event->ae_type));
139 #endif
140 }
141 
142 /*
143  * AUT_CMD
144  *
145  * the command line is described with argc and argv and the environment
146  * with envp.  The envp list is NULL terminated and has no separate
147  * counter; envp will be a NULL list unless the AUDIT_ARGE policy is
148  * set.
149  */
150 
151 /* ARGSUSED */
152 static void
153 adt_to_cmd(datadef *def, void *p_data, int required,
154     struct adt_event_state *event, char *notUsed)
155 {
156 	struct adt_internal_state	*sp = event->ae_session;
157 	int				argc;
158 	char				**argv;
159 	char				**envp = NULL;
160 
161 	argc = ((union convert *)p_data)->tint;
162 	p_data = adt_adjust_address(p_data, sizeof (int), sizeof (char **));
163 	argv = ((union convert *)p_data)->tchar2star;
164 	p_data = adt_adjust_address(p_data, sizeof (char **), sizeof (char **));
165 
166 	if (sp->as_kernel_audit_policy & AUDIT_ARGE)
167 		envp = ((union convert *)p_data)->tchar2star;
168 
169 	(void) au_write(event->ae_event_handle,
170 	    au_to_cmd(argc, argv, envp));
171 }
172 
173 /*
174  * special case of AUT_CMD with 1 argument that is
175  * a string showing the whole command and no envp
176  */
177 /* ARGSUSED */
178 static void
179 adt_to_cmd1(datadef *def, void *p_data, int required,
180     struct adt_event_state *event, char *notUsed)
181 {
182 	char	*string;
183 
184 	string = ((union convert *)p_data)->tcharstar;
185 
186 	if (string == NULL) {
187 		if (required)
188 			string = empty;
189 		else
190 			return;
191 	}
192 	/* argc is hardcoded as 1 */
193 	(void) au_write(event->ae_event_handle, au_to_cmd(1, &string,
194 	    NULL));
195 }
196 
197 /*
198  * adt_to_tid	-- generic address (ip is only one defined at present)
199  *	input:
200  *		terminal type:  ADT_IPv4, ADT_IPv6...
201  *		case: ADT_IPv4 or ADT_IPv6...
202  *			ip type
203  *			remote port
204  *			local port
205  *			address
206  *		case: not defined...
207  */
208 /* ARGSUSED */
209 static void
210 adt_to_tid(datadef *def, void *p_data, int required,
211     struct adt_event_state *event, char *notUsed)
212 {
213 	au_generic_tid_t	tid;
214 	uint32_t		type;
215 	au_ip_t			*ip;
216 
217 	type = ((union convert *)p_data)->tuint32;
218 
219 	switch (type) {
220 	case ADT_IPv4:
221 	case ADT_IPv6:
222 		p_data = adt_adjust_address(p_data, sizeof (uint32_t),
223 		    sizeof (uint32_t));
224 
225 		tid.gt_type = AU_IPADR;
226 		ip = &(tid.gt_adr.at_ip);
227 
228 		ip->at_type = (type == ADT_IPv4) ?
229 		    AU_IPv4 : AU_IPv6;
230 
231 		ip->at_r_port = ((union convert *)p_data)->tuint16;
232 		p_data = adt_adjust_address(p_data, sizeof (uint16_t),
233 		    sizeof (uint16_t));
234 
235 		ip->at_l_port = ((union convert *)p_data)->tuint16;
236 
237 		/* arg3 is for the array element, not the array size */
238 		p_data = adt_adjust_address(p_data, sizeof (uint16_t),
239 		    sizeof (uint32_t));
240 
241 		(void) memcpy(ip->at_addr, p_data, ip->at_type);
242 		break;
243 	default:
244 		adt_write_syslog("Invalid terminal id type", EINVAL);
245 		return;
246 	}
247 	(void) au_write(event->ae_event_handle, au_to_tid(&tid));
248 }
249 
250 /*
251  * au_to_newgroups takes a length and an array of gids
252  * as input.  The input to adt_to_newgroups is a length
253  * and a pointer to an array of gids.
254  */
255 
256 /* ARGSUSED */
257 static void
258 adt_to_newgroups(datadef *def, void *p_data, int required,
259     struct adt_event_state *event, char *notUsed)
260 {
261 	int	n;
262 	gid_t	*groups;
263 
264 	n = ((union convert *)p_data)->tint;
265 	if (n < 1) {
266 		if (required) {
267 			n = 0;  /* in case negative n was passed */
268 		} else
269 			return;
270 	}
271 	p_data = adt_adjust_address(p_data, sizeof (int), sizeof (int32_t *));
272 
273 	groups = ((union convert *)p_data)->tgidstar;
274 
275 	(void) au_write(event->ae_event_handle, au_to_newgroups(n, groups));
276 }
277 
278 /* ARGSUSED */
279 static void
280 adt_to_path(datadef *def, void *p_data, int required,
281     struct adt_event_state *event, char *notUsed)
282 {
283 	char	*path;
284 
285 	path = ((union convert *)p_data)->tcharstar;
286 
287 	if (path != NULL) {
288 		DPRINTF(("  path=%s\n", path));
289 		(void) au_write(event->ae_event_handle, au_to_path(path));
290 	} else {
291 		DPRINTF(("  Null path\n"));
292 		if (required)
293 			(void) au_write(event->ae_event_handle,
294 			    au_to_path(empty));
295 	}
296 }
297 
298 /*
299  * dummy token id:  AUT_PATHLIST
300  */
301 
302 /* ARGSUSED */
303 static void
304 adt_to_pathlist(datadef *def, void *p_data, int required,
305     struct adt_event_state *event, char *notUsed)
306 {
307 	char	*path;
308 	char	*working_buf;
309 	char	*pathlist;
310 	char	*last_str;
311 
312 	pathlist = ((union convert *)p_data)->tcharstar;
313 
314 	if (pathlist != NULL) {
315 		working_buf = strdup(pathlist);
316 		if (working_buf == NULL) {
317 			adt_write_syslog("audit failure", errno);
318 			if (required)
319 				(void) au_write(event->ae_event_handle,
320 				    au_to_path(empty));
321 			return;
322 		}
323 		for (path = strtok_r(working_buf, " ", &last_str);
324 		    path; path = strtok_r(NULL, " ", &last_str)) {
325 			DPRINTF(("  path=%s\n", path));
326 			(void) au_write(event->ae_event_handle,
327 			    au_to_path(path));
328 		}
329 	} else {
330 		DPRINTF(("  Null path list\n"));
331 		if (required)
332 			(void) au_write(event->ae_event_handle,
333 			    au_to_path(empty));
334 	}
335 }
336 
337 /*
338  * AUT_PRIV
339  */
340 
341 /* ARGSUSED */
342 static void
343 adt_to_priv(datadef *def, void *p_data, int required,
344     struct adt_event_state *event, const char *priv_type)
345 {
346 	priv_set_t	*privilege;
347 
348 	privilege = ((union convert *)p_data)->tprivstar;
349 
350 	if (privilege != NULL) {
351 		(void) au_write(event->ae_event_handle,
352 		    au_to_privset(priv_type, privilege));
353 	} else {
354 		if (required) {
355 			DPRINTF(("  Null privilege\n"));
356 			(void) au_write(event->ae_event_handle,
357 			    au_to_privset(empty, NULL));
358 		}
359 	}
360 }
361 
362 /*
363  * -AUT_PRIV_L	AUT_PRIV for a limit set
364  */
365 
366 /* ARGSUSED */
367 static void
368 adt_to_priv_limit(datadef *def, void *p_data, int required,
369     struct adt_event_state *event, char *notUsed)
370 {
371 	adt_to_priv(def, p_data, required, event, PRIV_LIMIT);
372 }
373 
374 /*
375  * -AUT_PRIV_I	AUT_PRIV for an inherit set
376  */
377 
378 /* ARGSUSED */
379 static void
380 adt_to_priv_inherit(datadef *def, void *p_data, int required,
381     struct adt_event_state *event, char *notUsed)
382 {
383 	adt_to_priv(def, p_data, required, event, PRIV_INHERITABLE);
384 }
385 
386 /* ARGSUSED */
387 static void
388 adt_to_priv_effective(datadef *def, void *p_data, int required,
389     struct adt_event_state *event, char *notUsed)
390 {
391 	adt_to_priv(def, p_data, required, event, PRIV_EFFECTIVE);
392 }
393 
394 static void
395 getCharacteristics(struct auditpinfo_addr *info, pid_t *pid)
396 {
397 	int	rc;
398 
399 	if (*pid == 0)			/* getpinfo for this pid */
400 		info->ap_pid = getpid();
401 	else
402 		info->ap_pid = *pid;
403 
404 	rc = auditon(A_GETPINFO_ADDR, (caddr_t)info,
405 	    sizeof (struct auditpinfo_addr));
406 	if (rc == -1) {
407 		info->ap_auid = AU_NOAUDITID;
408 		info->ap_asid = 0;
409 		(void) memset((void *)&(info->ap_termid), 0,
410 		    sizeof (au_tid_addr_t));
411 		info->ap_termid.at_type = AU_IPv4;
412 	}
413 }
414 
415 /*
416  * AUT_PROCESS
417  *
418  */
419 
420 /* ARGSUSED */
421 static void
422 adt_to_process(datadef *def, void *p_data, int required,
423     struct adt_event_state *event, char *notUsed)
424 {
425 	au_id_t			auid;
426 	uid_t			euid;
427 	gid_t			egid;
428 	uid_t			ruid;
429 	gid_t			rgid;
430 	pid_t			pid;
431 	au_asid_t		sid;
432 	au_tid_addr_t		*tid;
433 	struct auditpinfo_addr	info;
434 
435 	auid = ((union convert *)p_data)->tuid;
436 	p_data = adt_adjust_address(p_data, sizeof (uid_t), sizeof (uid_t));
437 	euid = ((union convert *)p_data)->tuid;
438 	p_data = adt_adjust_address(p_data, sizeof (uid_t), sizeof (gid_t));
439 	egid = ((union convert *)p_data)->tgid;
440 	p_data = adt_adjust_address(p_data, sizeof (gid_t), sizeof (uid_t));
441 	ruid = ((union convert *)p_data)->tuid;
442 	p_data = adt_adjust_address(p_data, sizeof (uid_t), sizeof (gid_t));
443 	rgid = ((union convert *)p_data)->tgid;
444 	p_data = adt_adjust_address(p_data, sizeof (gid_t), sizeof (pid_t));
445 	pid  = ((union convert *)p_data)->tpid;
446 	p_data = adt_adjust_address(p_data, sizeof (pid_t), sizeof (uint32_t));
447 	sid  = ((union convert *)p_data)->tuint32;
448 	p_data = adt_adjust_address(p_data, sizeof (uint32_t),
449 	    sizeof (au_tid_addr_t *));
450 	tid  = ((union convert *)p_data)->ttermid;
451 
452 	getCharacteristics(&info, &pid);
453 
454 	if (auid == AU_NOAUDITID)
455 		auid = info.ap_auid;
456 
457 	if (euid == AU_NOAUDITID)
458 		euid = geteuid();
459 
460 	if (egid == AU_NOAUDITID)
461 		egid = getegid();
462 
463 	if (ruid == AU_NOAUDITID)
464 		ruid = getuid();
465 
466 	if (rgid == AU_NOAUDITID)
467 		rgid = getgid();
468 
469 	if (tid == NULL)
470 		tid = &(info.ap_termid);
471 
472 	if (sid == 0)
473 		sid = info.ap_asid;
474 
475 	if (pid == 0)
476 		pid = info.ap_pid;
477 
478 	(void) au_write(event->ae_event_handle,
479 	    au_to_process_ex(auid, euid, egid, ruid, rgid, pid, sid, tid));
480 }
481 
482 /*
483  * generate a subject token and, depending on audit policy, a
484  * group token.  For TSOL, this is probably the right place
485  * to generate a label token.  Alternatively, a TSOL token could
486  * be defined in adt.xml with 'opt="none".
487  *
488  * The required flag does not apply here.
489  *
490  * Non-attributable records are indicated by an auid of AU_NOAUDITID;
491  * no subject token or group token is generated for a non-attributable
492  * record.
493  */
494 
495 /* ARGSUSED */
496 static void
497 adt_to_subject(datadef *def, void *p_data, int required,
498     struct adt_event_state *event, char *notUsed)
499 {
500 	struct adt_internal_state	*sp = event->ae_session;
501 
502 	if (sp->as_info.ai_auid == AU_NOAUDITID)
503 		return;
504 
505 	assert(sp->as_have_user_data == ADT_HAVE_ALL);
506 
507 	(void) au_write(event->ae_event_handle,
508 	    au_to_subject_ex(sp->as_info.ai_auid,
509 		sp->as_euid, sp->as_egid, sp->as_ruid, sp->as_rgid,
510 		getpid(), sp->as_info.ai_asid,
511 		&(sp->as_info.ai_termid)));
512 	/*
513 	 * If AUDIT_GROUP is set, a groups token must be output.
514 	 * In a session model, the groups list is undefined, so output an
515 	 * empty list.  In a process model, ship it!
516 	 */
517 	if (sp->as_kernel_audit_policy & AUDIT_GROUP) {
518 		int group_count;
519 		gid_t grouplist[NGROUPS_MAX];
520 
521 		(void) memset(grouplist, 0, sizeof (grouplist));
522 		if (sp->as_session_model == ADT_PROCESS_MODEL) {
523 			if ((group_count = getgroups(NGROUPS_UMAX,
524 			    grouplist))) {
525 				(void) au_write(event->ae_event_handle,
526 				    au_to_newgroups(group_count, grouplist));
527 			}
528 		} else { /* consider deleting this null output */
529 			(void) au_write(event->ae_event_handle,
530 			    au_to_newgroups(0, grouplist));
531 		}
532 	}
533 }
534 
535 /*
536  * adt_to_text()
537  *
538  * The format string, normally null, is sort of a wrapper around
539  * the input.  adt_write_text() is a wrapper around au_write that
540  * handles the format string
541  *
542  */
543 #define	TEXT_LENGTH 49
544 
545 static void
546 adt_write_text(int handle, char *main_text, const char *format)
547 {
548 	char	buffer[TEXT_LENGTH * 2 + 1];
549 
550 	if (format == NULL)
551 		(void) au_write(handle, au_to_text(main_text));
552 	else {
553 		(void) snprintf(buffer, TEXT_LENGTH * 2, format, main_text);
554 		(void) au_write(handle, au_to_text(buffer));
555 	}
556 }
557 
558 static void
559 adt_to_text(datadef *def, void *p_data, int required,
560     struct adt_event_state *event, char *format)
561 {
562 	static int	have_syslogged = 0;
563 	char		*string;
564 	char		**string_list;
565 	char		buffer[TEXT_LENGTH + 1];
566 	time_t		date;
567 	struct tm	tm;
568 	uint32_t	*int_list;
569 	int		written, available;
570 	int		i, arrayCount;
571 	struct msg_text *list;
572 	int		list_index;
573 
574 	DPRINTF(("  adt_to_text dd_datatype=%d\n", def->dd_datatype));
575 	switch (def->dd_datatype) {
576 	case ADT_DATE:
577 		/*
578 		 * Consider creating a separate token type for dates
579 		 * -- store as longs and format them in praudit.
580 		 * For now, a date is input as a time_t and output as
581 		 * a text token.  If we do this, we need to consider
582 		 * carrying timezone info so that praudit can
583 		 * represent times in an unambiguous manner.
584 		 */
585 		date = ((union convert *)p_data)->tlong;
586 		if (strftime(buffer, sizeof (buffer), "%x",
587 		    localtime_r(&date, &tm)) > TEXT_LENGTH) {
588 			if (required)
589 				(void) strncpy(buffer, "invalid date",
590 				    TEXT_LENGTH);
591 			else
592 				break;
593 		}
594 		DPRINTF(("  text=%s\n", buffer));
595 		adt_write_text(event->ae_event_handle, buffer, format);
596 		break;
597 		/*
598 		 * The "input size" is overloaded to mean the list number
599 		 * and the msg_selector indexes the desired string in
600 		 * that list
601 		 */
602 	case ADT_MSG:
603 		list = &adt_msg_text[(enum adt_login_text)def->dd_input_size];
604 		list_index = ((union convert *)p_data)->msg_selector;
605 
606 		if ((list_index < list->ml_min_index) |
607 		    (list_index > list->ml_max_index))
608 			string = "Invalid message index";
609 		else
610 			string = list->ml_msg_list[list_index +
611 			    list->ml_offset];
612 
613 		if (string == NULL) {	/* null is valid; means skip */
614 			if (required) {
615 				string = empty;
616 			} else
617 				break;
618 		}
619 		DPRINTF(("  text=%s\n", string));
620 		adt_write_text(event->ae_event_handle, string, format);
621 		break;
622 	case ADT_UID:
623 	case ADT_GID:
624 	case ADT_UINT:
625 		(void) snprintf(buffer, TEXT_LENGTH, "%d",
626 		    ((union convert *)p_data)->tuint);
627 
628 		DPRINTF(("  text=%s\n", buffer));
629 		adt_write_text(event->ae_event_handle, buffer, format);
630 		break;
631 	case ADT_UIDSTAR:
632 	case ADT_GIDSTAR:
633 	case ADT_UINT32STAR:
634 		int_list = ((union convert *)p_data)->tuint32star;
635 		p_data = adt_adjust_address(p_data, sizeof (int *),
636 		    sizeof (int));
637 		arrayCount = ((union convert *)p_data)->tint;
638 
639 		string = buffer;
640 		available = TEXT_LENGTH;	/* space available in buffer */
641 
642 		if (arrayCount < 0)
643 			arrayCount = 0;
644 
645 		if ((arrayCount > 0) && (int_list != NULL)) {
646 			for (; arrayCount > 0; arrayCount--) {
647 				written = snprintf(string, available,
648 				    "%d ", *int_list++);
649 				if (written < 1)
650 					break;
651 				string += written;
652 				available -= written;
653 			}
654 		} else if (required)
655 			string = empty;
656 		else
657 			break;
658 
659 		adt_write_text(event->ae_event_handle, buffer, format);
660 		break;
661 	case ADT_ULONG:
662 		(void) snprintf(buffer, TEXT_LENGTH, "%ld",
663 		    ((union convert *)p_data)->tulong);
664 
665 		DPRINTF(("  text=%s\n", buffer));
666 		adt_write_text(event->ae_event_handle, buffer, format);
667 		break;
668 	case ADT_CHARSTAR:
669 		string = ((union convert *)p_data)->tcharstar;
670 
671 		if (string == NULL) {
672 			if (required)
673 				string = empty;
674 			else
675 				break;
676 		}
677 		DPRINTF(("  text=%s\n", string));
678 		adt_write_text(event->ae_event_handle, string, format);
679 		break;
680 	case ADT_CHAR2STAR:
681 		string_list = ((union convert *)p_data)->tchar2star;
682 		p_data = adt_adjust_address(p_data, sizeof (char **),
683 		    sizeof (int));
684 		arrayCount = ((union convert *)p_data)->tint;
685 
686 		if (arrayCount < 0)
687 			arrayCount = 0;
688 
689 		if ((arrayCount > 0) && (string_list != NULL)) {
690 			for (i = 0; i < arrayCount; i++) {
691 				string = string_list[i];
692 				if (string != NULL)
693 					adt_write_text(event->ae_event_handle,
694 					    string, format);
695 			}
696 		} else if (required)
697 			adt_write_text(event->ae_event_handle, empty, format);
698 		else
699 			break;
700 		break;
701 	default:
702 		if (!have_syslogged) { /* don't flood the log */
703 			adt_write_syslog("unsupported data conversion",
704 			    ENOTSUP);
705 			have_syslogged = 1;
706 		}
707 		break;
708 	}
709 	DFLUSH
710 }
711 
712 /* ARGSUSED */
713 static void
714 adt_to_uauth(datadef *def, void *p_data, int required,
715     struct adt_event_state *event, char *format)
716 {
717 	char		*string;
718 
719 	DPRINTF(("  adt_to_uauth dd_datatype=%d\n", def->dd_datatype));
720 
721 	string = ((union convert *)p_data)->tcharstar;
722 
723 	if (string == NULL) {
724 		if (required)
725 			string = empty;
726 		else
727 			return;
728 	}
729 	DPRINTF(("  text=%s\n", string));
730 	(void) au_write(event->ae_event_handle, au_to_uauth(string));
731 }
732 
733 /* ARGSUSED */
734 static void
735 adt_to_zonename(datadef *def, void *p_data, int required,
736     struct adt_event_state *event, char *notUsed)
737 {
738 	char	*name;
739 
740 	name = ((union convert *)p_data)->tcharstar;
741 
742 	if (name != NULL) {
743 		DPRINTF(("  name=%s\n", name));
744 		(void) au_write(event->ae_event_handle, au_to_zonename(name));
745 	} else {
746 		DPRINTF(("  Null name\n"));
747 		if (required)
748 			(void) au_write(event->ae_event_handle,
749 			    au_to_zonename(empty));
750 	}
751 }
752 
753 
754 /*
755  * no function for header -- the header is generated by au_close()
756  *
757  * no function for trailer -- the trailer is generated by au_close()
758  */
759 
760 #define	MAX_TOKEN_JMP 15
761 
762 static struct token_jmp token_table[MAX_TOKEN_JMP] =
763 {
764 	{AUT_CMD, adt_to_cmd},
765 	{ADT_CMD_ALT, adt_to_cmd1},
766 	{AUT_TID, adt_to_tid},
767 	{AUT_NEWGROUPS, adt_to_newgroups},
768 	{AUT_PATH, adt_to_path},
769 	{-AUT_PATH, adt_to_pathlist},	/* private extension of token values */
770 	{ADT_AUT_PRIV_L, adt_to_priv_limit},
771 	{ADT_AUT_PRIV_I, adt_to_priv_inherit},
772 	{ADT_AUT_PRIV_E, adt_to_priv_effective},
773 	{AUT_PROCESS, adt_to_process},
774 	{AUT_RETURN, adt_to_return},
775 	{AUT_SUBJECT, adt_to_subject},
776 	{AUT_TEXT, adt_to_text},
777 	{AUT_UAUTH, adt_to_uauth},
778 	{AUT_ZONENAME, adt_to_zonename}
779 };
780 /*
781  * {AUT_ARG, adt_to_arg},		   not used
782  * {AUT_ACL, adt_to_acl},                  not used
783  * {AUT_ARBITRARY, adt_to_arbitrary},      AUT_ARBITRARY is undefined
784  * {AUT_ATTR, adt_to_attr},		   not used in mountd
785  * {AUT_EXEC_ARGS, adt_to_exec_args},      not used
786  * {AUT_EXEC_ENV, adt_to_exec_env},        not used
787  * {AUT_EXIT, adt_to_exit},		   obsolete
788  * {AUT_FILE, adt_to_file},                AUT_FILE is undefined
789  * {AUT_GROUPS, adt_to_groups},            obsolete
790  * {AUT_HEADER, adt_to_header}             not used
791  * {AUT_IN_ADDR, adt_to_in_addr},	   not used
792  * {AUT_IP, adt_to_ip},			   not used
793  * {AUT_IPC, adt_to_ipc},                  not used
794  * {AUT_IPC_PERM, adt_to_ipc_perm},        not used
795  * {AUT_OPAQUE, adt_to_opaque},            not used
796  * {AUT_SEQ, adt_to_seq},                  not used
797  * {AUT_SOCKET, adt_to_socket},            not used
798  * {AUT_SOCKET_INET, adt_to_socket_inet},  AUT_SOCKET_INET is undefined
799  * {AUT_TRAILER, adt_to_trailer}           not used
800  */
801 
802 /* find function to generate token */
803 
804 static adt_token_func_t
805 adt_getTokenFunction(char token_id)
806 {
807 	int	i;
808 	struct token_jmp	*p_jmp = token_table;
809 
810 	for (i = 0; i < MAX_TOKEN_JMP; i++) {
811 		if (token_id == p_jmp->jmp_id) {
812 			return (p_jmp->jmp_to);
813 		}
814 		p_jmp++;
815 	}
816 	errno = EINVAL;
817 	return (NULL);
818 }
819 
820 /*
821  * adjustAddress -- given the address of data, its size, and the type of
822  * the next data field, calculate the offset to the next piece of data.
823  * Depending on the caller, "current" and "next" mean the current pointer
824  * and the next pointer or the last pointer and the current pointer.
825  */
826 void *
827 adt_adjust_address(void *current_address, size_t current_size,
828     size_t next_size)
829 {
830 	ptrdiff_t adjustment;
831 	ptrdiff_t remainder;
832 
833 	adjustment = (size_t)current_address + current_size;
834 
835 	if (next_size) {
836 		remainder = adjustment % next_size;
837 		if (remainder != 0)
838 			adjustment += next_size - remainder;
839 	}
840 	return ((char *)adjustment);
841 }
842