xref: /titanic_52/usr/src/lib/libbsm/common/adt_token.c (revision 930176a00b697a09f5256ff3d4b1550f8e73c3a6)
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_token.c
23  *
24  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  *
27  * This file does not provide any user callable functions.  See adt.c
28  */
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <bsm/adt.h>
32 #include <bsm/adt_event.h>
33 #include <bsm/audit.h>
34 #include <adt_xlate.h>
35 #include <assert.h>
36 #include <netdb.h>
37 #include <priv.h>
38 #include <string.h>
39 #include <strings.h>
40 #include <sys/priv_names.h>
41 #include <sys/types.h>
42 #include <sys/vnode.h>
43 #include <tsol/label.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 	if (is_system_labeled())
535 		(void) au_write(event->ae_event_handle, au_to_mylabel());
536 }
537 
538 /*
539  * adt_to_text()
540  *
541  * The format string, normally null, is sort of a wrapper around
542  * the input.  adt_write_text() is a wrapper around au_write that
543  * handles the format string
544  *
545  */
546 #define	TEXT_LENGTH 49
547 
548 static void
549 adt_write_text(int handle, char *main_text, const char *format)
550 {
551 	char	buffer[TEXT_LENGTH * 2 + 1];
552 
553 	if (format == NULL)
554 		(void) au_write(handle, au_to_text(main_text));
555 	else {
556 		(void) snprintf(buffer, TEXT_LENGTH * 2, format, main_text);
557 		(void) au_write(handle, au_to_text(buffer));
558 	}
559 }
560 
561 static void
562 adt_to_text(datadef *def, void *p_data, int required,
563     struct adt_event_state *event, char *format)
564 {
565 	static int	have_syslogged = 0;
566 	char		*string;
567 	char		**string_list;
568 	char		buffer[TEXT_LENGTH + 1];
569 	time_t		date;
570 	struct tm	tm;
571 	uint32_t	*int_list;
572 	int		written, available;
573 	int		i, arrayCount;
574 	struct msg_text *list;
575 	int		list_index;
576 
577 	DPRINTF(("  adt_to_text dd_datatype=%d\n", def->dd_datatype));
578 	switch (def->dd_datatype) {
579 	case ADT_DATE:
580 		/*
581 		 * Consider creating a separate token type for dates
582 		 * -- store as longs and format them in praudit.
583 		 * For now, a date is input as a time_t and output as
584 		 * a text token.  If we do this, we need to consider
585 		 * carrying timezone info so that praudit can
586 		 * represent times in an unambiguous manner.
587 		 */
588 		date = ((union convert *)p_data)->tlong;
589 		if (strftime(buffer, sizeof (buffer), "%x",
590 		    localtime_r(&date, &tm)) > TEXT_LENGTH) {
591 			if (required)
592 				(void) strncpy(buffer, "invalid date",
593 				    TEXT_LENGTH);
594 			else
595 				break;
596 		}
597 		DPRINTF(("  text=%s\n", buffer));
598 		adt_write_text(event->ae_event_handle, buffer, format);
599 		break;
600 		/*
601 		 * The "input size" is overloaded to mean the list number
602 		 * and the msg_selector indexes the desired string in
603 		 * that list
604 		 */
605 	case ADT_MSG:
606 		list = &adt_msg_text[(enum adt_login_text)def->dd_input_size];
607 		list_index = ((union convert *)p_data)->msg_selector;
608 
609 		if ((list_index < list->ml_min_index) |
610 		    (list_index > list->ml_max_index))
611 			string = "Invalid message index";
612 		else
613 			string = list->ml_msg_list[list_index +
614 			    list->ml_offset];
615 
616 		if (string == NULL) {	/* null is valid; means skip */
617 			if (required) {
618 				string = empty;
619 			} else
620 				break;
621 		}
622 		DPRINTF(("  text=%s\n", string));
623 		adt_write_text(event->ae_event_handle, string, format);
624 		break;
625 	case ADT_UID:
626 	case ADT_GID:
627 	case ADT_UINT:
628 		(void) snprintf(buffer, TEXT_LENGTH, "%d",
629 		    ((union convert *)p_data)->tuint);
630 
631 		DPRINTF(("  text=%s\n", buffer));
632 		adt_write_text(event->ae_event_handle, buffer, format);
633 		break;
634 	case ADT_UIDSTAR:
635 	case ADT_GIDSTAR:
636 	case ADT_UINT32STAR:
637 		int_list = ((union convert *)p_data)->tuint32star;
638 		p_data = adt_adjust_address(p_data, sizeof (int *),
639 		    sizeof (int));
640 		arrayCount = ((union convert *)p_data)->tint;
641 
642 		string = buffer;
643 		available = TEXT_LENGTH;	/* space available in buffer */
644 
645 		if (arrayCount < 0)
646 			arrayCount = 0;
647 
648 		if ((arrayCount > 0) && (int_list != NULL)) {
649 			for (; arrayCount > 0; arrayCount--) {
650 				written = snprintf(string, available,
651 				    "%d ", *int_list++);
652 				if (written < 1)
653 					break;
654 				string += written;
655 				available -= written;
656 			}
657 		} else if (required)
658 			string = empty;
659 		else
660 			break;
661 
662 		adt_write_text(event->ae_event_handle, buffer, format);
663 		break;
664 	case ADT_ULONG:
665 		(void) snprintf(buffer, TEXT_LENGTH, "%ld",
666 		    ((union convert *)p_data)->tulong);
667 
668 		DPRINTF(("  text=%s\n", buffer));
669 		adt_write_text(event->ae_event_handle, buffer, format);
670 		break;
671 	case ADT_CHARSTAR:
672 		string = ((union convert *)p_data)->tcharstar;
673 
674 		if (string == NULL) {
675 			if (required)
676 				string = empty;
677 			else
678 				break;
679 		}
680 		DPRINTF(("  text=%s\n", string));
681 		adt_write_text(event->ae_event_handle, string, format);
682 		break;
683 	case ADT_CHAR2STAR:
684 		string_list = ((union convert *)p_data)->tchar2star;
685 		p_data = adt_adjust_address(p_data, sizeof (char **),
686 		    sizeof (int));
687 		arrayCount = ((union convert *)p_data)->tint;
688 
689 		if (arrayCount < 0)
690 			arrayCount = 0;
691 
692 		if ((arrayCount > 0) && (string_list != NULL)) {
693 			for (i = 0; i < arrayCount; i++) {
694 				string = string_list[i];
695 				if (string != NULL)
696 					adt_write_text(event->ae_event_handle,
697 					    string, format);
698 			}
699 		} else if (required)
700 			adt_write_text(event->ae_event_handle, empty, format);
701 		else
702 			break;
703 		break;
704 	default:
705 		if (!have_syslogged) { /* don't flood the log */
706 			adt_write_syslog("unsupported data conversion",
707 			    ENOTSUP);
708 			have_syslogged = 1;
709 		}
710 		break;
711 	}
712 	DFLUSH
713 }
714 
715 /* ARGSUSED */
716 static void
717 adt_to_uauth(datadef *def, void *p_data, int required,
718     struct adt_event_state *event, char *format)
719 {
720 	char		*string;
721 
722 	DPRINTF(("  adt_to_uauth dd_datatype=%d\n", def->dd_datatype));
723 
724 	string = ((union convert *)p_data)->tcharstar;
725 
726 	if (string == NULL) {
727 		if (required)
728 			string = empty;
729 		else
730 			return;
731 	}
732 	DPRINTF(("  text=%s\n", string));
733 	(void) au_write(event->ae_event_handle, au_to_uauth(string));
734 }
735 
736 /* ARGSUSED */
737 static void
738 adt_to_zonename(datadef *def, void *p_data, int required,
739     struct adt_event_state *event, char *notUsed)
740 {
741 	char	*name;
742 
743 	name = ((union convert *)p_data)->tcharstar;
744 
745 	if (name != NULL) {
746 		DPRINTF(("  name=%s\n", name));
747 		(void) au_write(event->ae_event_handle, au_to_zonename(name));
748 	} else {
749 		DPRINTF(("  Null name\n"));
750 		if (required)
751 			(void) au_write(event->ae_event_handle,
752 			    au_to_zonename(empty));
753 	}
754 }
755 
756 
757 /*
758  * no function for header -- the header is generated by au_close()
759  *
760  * no function for trailer -- the trailer is generated by au_close()
761  */
762 
763 #define	MAX_TOKEN_JMP 15
764 
765 static struct token_jmp token_table[MAX_TOKEN_JMP] =
766 {
767 	{AUT_CMD, adt_to_cmd},
768 	{ADT_CMD_ALT, adt_to_cmd1},
769 	{AUT_TID, adt_to_tid},
770 	{AUT_NEWGROUPS, adt_to_newgroups},
771 	{AUT_PATH, adt_to_path},
772 	{-AUT_PATH, adt_to_pathlist},	/* private extension of token values */
773 	{ADT_AUT_PRIV_L, adt_to_priv_limit},
774 	{ADT_AUT_PRIV_I, adt_to_priv_inherit},
775 	{ADT_AUT_PRIV_E, adt_to_priv_effective},
776 	{AUT_PROCESS, adt_to_process},
777 	{AUT_RETURN, adt_to_return},
778 	{AUT_SUBJECT, adt_to_subject},
779 	{AUT_TEXT, adt_to_text},
780 	{AUT_UAUTH, adt_to_uauth},
781 	{AUT_ZONENAME, adt_to_zonename}
782 };
783 /*
784  * {AUT_ARG, adt_to_arg},		   not used
785  * {AUT_ACL, adt_to_acl},                  not used
786  * {AUT_ARBITRARY, adt_to_arbitrary},      AUT_ARBITRARY is undefined
787  * {AUT_ATTR, adt_to_attr},		   not used in mountd
788  * {AUT_EXEC_ARGS, adt_to_exec_args},      not used
789  * {AUT_EXEC_ENV, adt_to_exec_env},        not used
790  * {AUT_EXIT, adt_to_exit},		   obsolete
791  * {AUT_FILE, adt_to_file},                AUT_FILE is undefined
792  * {AUT_GROUPS, adt_to_groups},            obsolete
793  * {AUT_HEADER, adt_to_header}             not used
794  * {AUT_IN_ADDR, adt_to_in_addr},	   not used
795  * {AUT_IP, adt_to_ip},			   not used
796  * {AUT_IPC, adt_to_ipc},                  not used
797  * {AUT_IPC_PERM, adt_to_ipc_perm},        not used
798  * {AUT_OPAQUE, adt_to_opaque},            not used
799  * {AUT_SEQ, adt_to_seq},                  not used
800  * {AUT_SOCKET, adt_to_socket},            not used
801  * {AUT_SOCKET_INET, adt_to_socket_inet},  AUT_SOCKET_INET is undefined
802  * {AUT_TRAILER, adt_to_trailer}           not used
803  */
804 
805 /* find function to generate token */
806 
807 static adt_token_func_t
808 adt_getTokenFunction(char token_id)
809 {
810 	int	i;
811 	struct token_jmp	*p_jmp = token_table;
812 
813 	for (i = 0; i < MAX_TOKEN_JMP; i++) {
814 		if (token_id == p_jmp->jmp_id) {
815 			return (p_jmp->jmp_to);
816 		}
817 		p_jmp++;
818 	}
819 	errno = EINVAL;
820 	return (NULL);
821 }
822 
823 /*
824  * adjustAddress -- given the address of data, its size, and the type of
825  * the next data field, calculate the offset to the next piece of data.
826  * Depending on the caller, "current" and "next" mean the current pointer
827  * and the next pointer or the last pointer and the current pointer.
828  */
829 void *
830 adt_adjust_address(void *current_address, size_t current_size,
831     size_t next_size)
832 {
833 	ptrdiff_t adjustment;
834 	ptrdiff_t remainder;
835 
836 	adjustment = (size_t)current_address + current_size;
837 
838 	if (next_size) {
839 		remainder = adjustment % next_size;
840 		if (remainder != 0)
841 			adjustment += next_size - remainder;
842 	}
843 	return ((char *)adjustment);
844 }
845