dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / praudit / token.c
blobe8c76b92e3d11f90afde9f4f3d7dd7f386530c3d
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 #include <ctype.h>
28 #include <dirent.h>
29 #include <grp.h>
30 #include <libintl.h>
31 #include <limits.h>
32 #include <locale.h>
33 #include <pwd.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include <sys/types.h>
38 #include <sys/inttypes.h>
39 #include <sys/file.h>
40 #include <sys/param.h>
41 #include <sys/uio.h>
42 #include <sys/stat.h>
43 #include <sys/acl.h>
44 #include <sys/socket.h>
45 #include <sys/errno.h>
46 #include <sys/ipc.h>
47 #include <sys/sem.h>
48 #include <sys/systm.h>
49 #include <netinet/in.h>
50 #include <sys/tiuser.h>
51 #include <rpc/types.h>
52 #include <rpc/auth.h>
53 #include <rpc/auth_unix.h>
54 #include <rpc/svc.h>
55 #include <rpc/xdr.h>
56 #include <nfs/nfs.h>
57 #include <sys/fs/ufs_quota.h>
58 #include <sys/time.h>
59 #include <sys/mkdev.h>
60 #include <unistd.h>
62 #include <bsm/audit.h>
63 #include <bsm/audit_record.h>
64 #include <bsm/libbsm.h>
66 #include "praudit.h"
67 #include "toktable.h"
69 #include <netdb.h>
70 #include <arpa/inet.h>
72 static char *anchor_path(char *);
73 static char *collapse_path(char *);
77 * -----------------------------------------------------------------------
78 * is_file_token:
79 * Tests whether the specified token id represents a type
80 * of file token.
81 * return codes : 1 - tokenid is a file token type
82 * : 0 - otherwise
83 * -----------------------------------------------------------------------
85 int
86 is_file_token(int tokenid)
88 if ((tokenid == AUT_OTHER_FILE32) || (tokenid == AUT_OTHER_FILE64))
89 return (1);
91 return (0);
95 * -----------------------------------------------------------------------
96 * is_header_token:
97 * Tests whether the specified token id represents a type
98 * of header token (signifying the start of a record).
99 * return codes : 1 - tokenid is a header type
100 * : 0 - otherwise
101 * -----------------------------------------------------------------------
104 is_header_token(int tokenid)
106 if ((tokenid == AUT_OHEADER) || (tokenid == AUT_HEADER32) ||
107 (tokenid == AUT_HEADER32_EX) || (tokenid == AUT_HEADER64) ||
108 (tokenid == AUT_HEADER64_EX))
109 return (1);
111 return (0);
115 * -----------------------------------------------------------------------
116 * is_token:
117 * Tests whether the specified token id represents a true
118 * token, as opposed to a regular tag.
119 * return codes : 1 - tokenid is a true token
120 * : 0 - otherwise
121 * -----------------------------------------------------------------------
124 is_token(int tokenid)
126 if ((tokenid > 0) && (tokenid <= MAXTOKEN))
127 return (1);
129 return (0);
134 * -----------------------------------------------------------------------
135 * exit_token() : Process information label token and display contents
136 * return codes : -1 - error
137 * : 0 - successful
138 * NOTE: At the time of call, the label token id has been retrieved
140 * Format of exit token:
141 * exit token id adr_char
142 * -----------------------------------------------------------------------
145 exit_token(pr_context_t *context)
147 int returnstat;
148 int retval;
149 uval_t uval;
151 if ((returnstat = open_tag(context, TAG_ERRVAL)) != 0)
152 return (returnstat);
154 if ((returnstat = pr_adr_int32(context, (int32_t *)&retval, 1)) == 0) {
155 if (!(context->format & PRF_RAWM)) {
156 char *emsg = strerror(retval);
158 if (emsg == NULL)
159 uval.string_val = gettext("Unknown errno");
160 else
161 uval.string_val = gettext(emsg);
162 uval.uvaltype = PRA_STRING;
163 } else {
164 uval.uvaltype = PRA_INT32;
165 uval.int32_val = retval;
167 returnstat = pa_print(context, &uval, 0);
169 if (returnstat == 0)
170 returnstat = close_tag(context, TAG_ERRVAL);
172 return (process_tag(context, TAG_RETVAL, returnstat, 1));
176 * ------------------------------------------------------------------
177 * file_token() : prints out seconds of time and other file name
178 * return codes : -1 - error
179 * : 0 - successful, valid file token fields
180 * At the time of entry, the file token ID has already been retrieved
182 * Format of file token:
183 * file token id adr_char
184 * seconds of time adr_u_int
185 * name of other file adr_string
186 * ------------------------------------------------------------------
189 file_token(pr_context_t *context)
191 int returnstat;
193 returnstat = pa_utime32(context, 0, 0); /* time from usecs */
195 /* other file name */
196 returnstat = pa_file_string(context, returnstat, 1);
198 return (returnstat);
202 file64_token(pr_context_t *context)
204 int returnstat;
206 returnstat = pa_utime64(context, 0, 0); /* time from usecs */
208 /* other file name */
209 returnstat = pa_file_string(context, returnstat, 1);
211 return (returnstat);
215 * -----------------------------------------------------------------------
216 * header_token() : Process record header token and display contents
217 * return codes : -1 - error
218 * : 0 - successful
219 * : 1 - warning, password entry not found
221 * NOTE: At the time of call, the header token id has been retrieved
223 * Format of header token:
224 * header token id adr_char
225 * record byte count adr_u_int
226 * event type adr_u_short (printed either ASCII or raw)
227 * event class adr_u_int (printed either ASCII or raw)
228 * event action adr_u_int
229 * if extended: extended host name (IPv4/IPv6)
230 * seconds of time adr_u_int (printed either ASCII or raw)
231 * nanoseconds of time adr_u_int
232 * -----------------------------------------------------------------------
235 header_token(pr_context_t *context)
237 int returnstat;
239 returnstat = pa_reclen(context, 0); /* record byte */
240 /* version ID */
241 returnstat = process_tag(context, TAG_TOKVERS, returnstat, 0);
242 /* event type */
243 returnstat = process_tag(context, TAG_EVTYPE, returnstat, 0);
244 /* event modifier */
245 returnstat = pa_event_modifier(context, returnstat, 0);
246 /* time from nsec */
247 returnstat = pa_ntime32(context, returnstat, 1);
249 return (returnstat);
253 header64_token(pr_context_t *context)
255 int returnstat;
257 returnstat = pa_reclen(context, 0); /* record byte */
258 /* version ID */
259 returnstat = process_tag(context, TAG_TOKVERS, returnstat, 0);
260 /* event type */
261 returnstat = process_tag(context, TAG_EVTYPE, returnstat, 0);
262 /* event modifier */
263 returnstat = pa_event_modifier(context, returnstat, 0);
264 /* time from nsec */
265 returnstat = pa_ntime64(context, returnstat, 1);
267 return (returnstat);
271 header32_ex_token(pr_context_t *context)
273 int returnstat;
275 returnstat = pa_reclen(context, 0); /* record byte */
276 /* version ID */
277 returnstat = process_tag(context, TAG_TOKVERS, returnstat, 0);
278 /* event type */
279 returnstat = process_tag(context, TAG_EVTYPE, returnstat, 0);
280 /* event modifier */
281 returnstat = pa_event_modifier(context, returnstat, 0);
282 /* machine name */
283 returnstat = pa_hostname_ex(context, returnstat, 0);
284 /* time from nsec */
285 returnstat = pa_ntime32(context, returnstat, 1);
287 return (returnstat);
291 header64_ex_token(pr_context_t *context)
293 int returnstat;
295 returnstat = pa_reclen(context, 0); /* record byte */
296 /* version ID */
297 returnstat = process_tag(context, TAG_TOKVERS, returnstat, 0);
298 /* event type */
299 returnstat = process_tag(context, TAG_EVTYPE, returnstat, 0);
300 /* event modifier */
301 returnstat = pa_event_modifier(context, returnstat, 0);
302 /* machine name */
303 returnstat = pa_hostname_ex(context, returnstat, 0);
304 /* time from nsec */
305 returnstat = pa_ntime64(context, returnstat, 1);
307 return (returnstat);
311 * -----------------------------------------------------------------------
312 * trailer_token() : Process record trailer token and display contents
313 * return codes : -1 - error
314 * : 0 - successful
315 * NOTE: At the time of call, the trailer token id has already been
316 * retrieved
318 * Format of trailer token:
319 * trailer token id adr_char
320 * record sequence no adr_u_short (should be AUT_TRAILER_MAGIC)
321 * record byte count adr_u_int
322 * -----------------------------------------------------------------------
325 trailer_token(pr_context_t *context)
327 short magic_number;
329 if (pr_adr_u_short(context, (ushort_t *)&magic_number, 1) < 0) {
330 (void) fprintf(stderr, gettext(
331 "praudit: Cannot retrieve trailer magic number\n"));
332 return (-1);
333 } else {
334 if (magic_number != AUT_TRAILER_MAGIC) {
335 (void) fprintf(stderr, gettext(
336 "praudit: Invalid trailer magic number\n"));
337 return (-1);
338 } else
339 /* Do not display trailer in XML mode */
340 if (context->format & PRF_XMLM) {
341 uint32_t junk;
342 int retstat;
344 retstat = pr_adr_u_int32(context, &junk, 1);
345 return (retstat);
346 } else {
347 return (pa_adr_u_int32(context, 0, 1));
353 * -----------------------------------------------------------------------
354 * arbitrary_data_token():
355 * Process arbitrary data token and display contents
356 * return codes : -1 - error
357 * : 0 - successful
358 * NOTE: At the time of call, the arbitrary data token id has already
359 * been retrieved
361 * Format of arbitrary data token:
362 * arbitrary data token id adr char
363 * how to print adr_char
364 * From audit_record.h, this may be either:
365 * AUP_BINARY binary
366 * AUP_OCTAL octal
367 * AUP_DECIMAL decimal
368 * AUP_HEX hexadecimal
369 * basic unit adr_char
370 * From audit_record.h, this may be either:
371 * AUR_BYTE byte
372 * AUR_CHAR char
373 * AUR_SHORT short
374 * AUR_INT32 int32_t
375 * AUR_INT64 int64_t
376 * unit count adr_char, specifying number of units of
377 * data in the "data items" parameter below
378 * data items depends on basic unit
380 * -----------------------------------------------------------------------
383 arbitrary_data_token(pr_context_t *context)
385 int returnstat;
386 int i;
387 char c1;
388 short c2;
389 int32_t c3;
390 int64_t c4;
391 char how_to_print, basic_unit, unit_count, fwid;
392 char *p;
393 int index = 0;
394 char *pformat = "%*s";
396 uval_t uval;
398 if ((returnstat = pr_adr_char(context, &how_to_print, 1)) != 0)
399 return (returnstat);
401 if ((returnstat = pr_adr_char(context, &basic_unit, 1)) != 0)
402 return (returnstat);
404 if ((returnstat = pr_adr_char(context, &unit_count, 1)) != 0)
405 return (returnstat);
407 if (!(context->format & PRF_RAWM)) {
408 uval.uvaltype = PRA_STRING;
409 uval.string_val = htp2string(how_to_print);
410 } else {
411 uval.uvaltype = PRA_INT32;
412 uval.int32_val = (int)how_to_print;
415 if ((returnstat = open_tag(context, TAG_ARBPRINT)) != 0)
416 return (returnstat);
417 if ((returnstat = pa_print(context, &uval, 0)) < 0)
418 return (returnstat);
419 if ((returnstat = close_tag(context, TAG_ARBPRINT)) != 0)
420 return (returnstat);
422 if (!(context->format & PRF_RAWM)) {
423 uval.uvaltype = PRA_STRING;
424 uval.string_val = bu2string(basic_unit);
425 } else {
426 uval.uvaltype = PRA_INT32;
427 uval.int32_val = (int32_t)basic_unit;
430 if ((returnstat = open_tag(context, TAG_ARBTYPE)) != 0)
431 return (returnstat);
432 if ((returnstat = pa_print(context, &uval, 0)) < 0)
433 return (returnstat);
434 if ((returnstat = close_tag(context, TAG_ARBTYPE)) != 0)
435 return (returnstat);
437 uval.uvaltype = PRA_INT32;
438 uval.int32_val = (int32_t)unit_count;
440 if ((returnstat = open_tag(context, TAG_ARBCOUNT)) != 0)
441 return (returnstat);
442 if ((returnstat = pa_print(context, &uval, 1)) < 0)
443 return (returnstat);
444 if ((returnstat = close_tag(context, TAG_ARBCOUNT)) != 0)
445 return (returnstat);
447 /* Done with attributes; force end of token open */
448 if ((returnstat = finish_open_tag(context)) != 0)
449 return (returnstat);
451 /* get the field width in case we need to format output */
452 fwid = findfieldwidth(basic_unit, how_to_print);
453 p = (char *)malloc(80);
455 /* now get the data items and print them */
456 for (i = 0; (i < unit_count); i++) {
457 switch (basic_unit) {
458 /* case AUR_BYTE: */
459 case AUR_CHAR:
460 if (pr_adr_char(context, &c1, 1) == 0)
461 (void) convert_char_to_string(how_to_print,
462 c1, p);
463 else {
464 free(p);
465 return (-1);
467 break;
468 case AUR_SHORT:
469 if (pr_adr_short(context, &c2, 1) == 0)
470 (void) convert_short_to_string(how_to_print,
471 c2, p);
472 else {
473 free(p);
474 return (-1);
476 break;
477 case AUR_INT32:
478 if (pr_adr_int32(context, &c3, 1) == 0)
479 (void) convert_int32_to_string(how_to_print,
480 c3, p);
481 else {
482 free(p);
483 return (-1);
485 break;
486 case AUR_INT64:
487 if (pr_adr_int64(context, &c4, 1) == 0)
488 (void) convert_int64_to_string(how_to_print,
489 c4, p);
490 else {
491 free(p);
492 return (-1);
494 break;
495 default:
496 free(p);
497 return (-1);
498 /*NOTREACHED*/
502 * At this point, we have successfully retrieved a data
503 * item and converted it into an ASCII string pointed to
504 * by p. If all output is to be printed on one line,
505 * simply separate the data items by a space (or by the
506 * delimiter if this is the last data item), otherwise, we
507 * need to format the output before display.
509 if (context->format & PRF_ONELINE) {
510 returnstat = pr_printf(context, "%s", p);
511 if ((returnstat >= 0) && (i == (unit_count - 1)))
512 returnstat = pr_printf(context, "%s",
513 context->SEPARATOR);
514 else
515 returnstat = pr_putchar(context, ' ');
516 } else { /* format output */
517 returnstat = pr_printf(context, pformat, fwid, p);
518 index += fwid;
519 if ((returnstat >= 0) &&
520 (((index + fwid) > 75) ||
521 (i == (unit_count - 1)))) {
522 returnstat = pr_putchar(context, '\n');
523 index = 0;
525 } /* else if PRF_ONELINE */
526 if (returnstat < 0) {
527 free(p);
528 return (returnstat);
531 free(p);
533 return (returnstat);
537 * -----------------------------------------------------------------------
538 * opaque_token() : Process opaque token and display contents
539 * return codes : -1 - error
540 * : 0 - successful
541 * NOTE: At the time of call, the opaque token id has already been
542 * retrieved
544 * Format of opaque token:
545 * opaque token id adr_char
546 * size adr_short
547 * data adr_char, size times
548 * -----------------------------------------------------------------------
551 opaque_token(pr_context_t *context)
553 int returnstat;
554 short size;
555 char *charp;
556 uval_t uval;
559 /* print the size of the token */
560 if (pr_adr_short(context, &size, 1) == 0) {
561 uval.uvaltype = PRA_SHORT;
562 uval.short_val = size;
563 returnstat = pa_print(context, &uval, 0);
564 } else
565 returnstat = -1;
567 /* now print out the data field in hexadecimal */
568 if (returnstat >= 0) {
569 /* try to allocate memory for the character string */
570 if ((charp = (char *)malloc(size * sizeof (char))) == NULL)
571 returnstat = -1;
572 else {
573 if ((returnstat = pr_adr_char(context, charp,
574 size)) == 0) {
575 /* print out in hexadecimal format */
576 uval.uvaltype = PRA_STRING;
577 uval.string_val = hexconvert(charp, size, size);
578 if (uval.string_val) {
579 returnstat = pa_print(context,
580 &uval, 1);
581 free(uval.string_val);
584 free(charp);
588 return (returnstat);
592 * -----------------------------------------------------------------------
593 * path_token() : Process path token and display contents
594 * return codes : -1 - error
595 * : 0 - successful
596 * NOTE: At the time of call, the path token id has been retrieved
598 * Format of path token:
599 * token id adr_char
600 * path adr_string
601 * -----------------------------------------------------------------------
604 path_token(pr_context_t *context)
606 char *path; /* path */
607 char *apath; /* anchored path */
608 char *cpath; /* collapsed path */
609 short length;
610 int returnstat;
611 uval_t uval;
614 * We need to know how much space to allocate for our string, so
615 * read the length first, then call pr_adr_char to read those bytes.
617 if (pr_adr_short(context, &length, 1) == 0) {
618 if ((path = (char *)malloc(length + 1)) == NULL) {
619 returnstat = -1;
620 } else if (pr_adr_char(context, path, length) == 0) {
621 path[length] = '\0';
622 uval.uvaltype = PRA_STRING;
623 if (*path != '/') {
624 apath = anchor_path(path);
625 free(path);
626 } else
627 apath = path;
628 cpath = collapse_path(apath);
629 uval.string_val = cpath;
630 returnstat = pa_print(context, &uval, 1);
631 free(cpath);
632 } else {
633 free(path);
634 returnstat = -1;
636 return (returnstat);
637 } else
638 return (-1);
642 * anchor a path name with a slash
644 char *
645 anchor_path(char *sp)
647 char *dp; /* destination path */
648 char *tp; /* temporary path */
649 size_t len;
651 len = strlen(sp) + 2;
652 if ((dp = tp = (char *)calloc(1, len)) == NULL)
653 return (NULL);
655 *dp++ = '/';
657 (void) strlcpy(dp, sp, len);
659 return (tp);
663 * copy path to collapsed path.
664 * collapsed path does not contain:
665 * successive slashes
666 * instances of dot-slash
667 * instances of dot-dot-slash
668 * passed path must be anchored with a '/'
670 char *
671 collapse_path(char *s)
673 int id; /* index of where we are in destination string */
674 int is; /* index of where we are in source string */
675 int slashseen; /* have we seen a slash */
676 int ls; /* length of source string */
678 ls = strlen(s) + 1;
680 slashseen = 0;
681 for (is = 0, id = 0; is < ls; is++) {
682 /* thats all folks, we've reached the end of input */
683 if (s[is] == '\0') {
684 if (id > 1 && s[id-1] == '/') {
685 --id;
687 s[id++] = '\0';
688 break;
690 /* previous character was a / */
691 if (slashseen) {
692 if (s[is] == '/')
693 continue; /* another slash, ignore it */
694 } else if (s[is] == '/') {
695 /* we see a /, just copy it and try again */
696 slashseen = 1;
697 s[id++] = '/';
698 continue;
700 /* /./ seen */
701 if (s[is] == '.' && s[is+1] == '/') {
702 is += 1;
703 continue;
705 /* XXX/. seen */
706 if (s[is] == '.' && s[is+1] == '\0') {
707 if (id > 1)
708 id--;
709 continue;
711 /* XXX/.. seen */
712 if (s[is] == '.' && s[is+1] == '.' && s[is+2] == '\0') {
713 is += 1;
714 if (id > 0)
715 id--;
716 while (id > 0 && s[--id] != '/')
717 continue;
718 id++;
719 continue;
721 /* XXX/../ seen */
722 if (s[is] == '.' && s[is+1] == '.' && s[is+2] == '/') {
723 is += 2;
724 if (id > 0)
725 id--;
726 while (id > 0 && s[--id] != '/')
727 continue;
728 id++;
729 continue;
731 while (is < ls && (s[id++] = s[is++]) != '/')
732 continue;
733 is--;
735 return (s);
739 * -----------------------------------------------------------------------
740 * cmd_token() : Process cmd token and display contents
741 * return codes : -1 - error
742 * : 0 - successful
743 * NOTE: At the time of call, the cmd token id has been retrieved
745 * Format of command token:
746 * token id adr_char
747 * argc adr_short
748 * N*argv[i] adr_string (short, string)
749 * env cnt adr_short
750 * N*arge[i] adr_string (short, string)
751 * -----------------------------------------------------------------------
754 cmd_token(pr_context_t *context)
756 int returnstat;
757 short num;
759 returnstat = pr_adr_short(context, &num, 1);
760 if (returnstat < 0)
761 return (returnstat);
763 if (!(context->format & PRF_XMLM)) {
764 returnstat = pr_printf(context, "%s%s%d%s",
765 (context->format & PRF_ONELINE) ? "" : gettext("argcnt"),
766 (context->format & PRF_ONELINE) ? "" : context->SEPARATOR,
767 num, context->SEPARATOR);
768 if (returnstat < 0)
769 return (returnstat);
772 for (; num > 0; num--) {
773 if ((returnstat = process_tag(context, TAG_ARGV,
774 returnstat, 0)) < 0)
775 return (returnstat);
778 if ((returnstat = pr_adr_short(context, &num, 1)) < 0)
779 return (returnstat);
781 if (!(context->format & PRF_XMLM)) {
782 returnstat = pr_printf(context, "%s%s%d%s",
783 (context->format & PRF_ONELINE) ? "" : gettext("envcnt"),
784 (context->format & PRF_ONELINE) ? "" : context->SEPARATOR,
785 num, context->SEPARATOR);
786 if (returnstat < 0)
787 return (returnstat);
790 if ((num == 0) && !(context->format & PRF_XMLM)) {
791 returnstat = do_newline(context, 1);
792 if (returnstat < 0)
793 return (returnstat);
796 for (; num > 1; num--) {
797 if ((returnstat = process_tag(context, TAG_ARGE,
798 returnstat, 0)) < 0)
799 return (returnstat);
801 if (num)
802 returnstat = process_tag(context, TAG_ARGE, returnstat, 1);
804 return (returnstat);
809 * -----------------------------------------------------------------------
810 * argument32_token() : Process argument token and display contents
811 * return codes : -1 - error
812 * : 0 - successful
813 * NOTE: At the time of call, the arg token id has been retrieved
815 * Format of argument token:
816 * current directory token id adr_char
817 * argument number adr_char
818 * argument value adr_int32
819 * argument description adr_string
820 * -----------------------------------------------------------------------
823 argument32_token(pr_context_t *context)
825 int returnstat;
827 returnstat = process_tag(context, TAG_ARGNUM, 0, 0);
828 returnstat = process_tag(context, TAG_ARGVAL32, returnstat, 0);
829 returnstat = process_tag(context, TAG_ARGDESC, returnstat, 1);
831 return (returnstat);
836 * -----------------------------------------------------------------------
837 * argument64_token() : Process argument token and display contents
838 * return codes : -1 - error
839 * : 0 - successful
840 * NOTE: At the time of call, the arg token id has been retrieved
842 * Format of 64 bit argument token:
843 * current directory token id adr_char
844 * argument number adr_char
845 * argument value adr_int64
846 * argument description adr_string
847 * -----------------------------------------------------------------------
850 argument64_token(pr_context_t *context)
852 int returnstat;
854 returnstat = process_tag(context, TAG_ARGNUM, 0, 0);
855 returnstat = process_tag(context, TAG_ARGVAL64, returnstat, 0);
856 returnstat = process_tag(context, TAG_ARGDESC, returnstat, 1);
858 return (returnstat);
863 * -----------------------------------------------------------------------
864 * process_token() : Process process token and display contents
865 * return codes : -1 - error
866 * : 0 - successful
867 * NOTE: At the time of call, the process token id has been retrieved
869 * Format of process token:
870 * process token id adr_char
871 * auid adr_u_int32
872 * euid adr_u_int32
873 * egid adr_u_int32
874 * ruid adr_u_int32
875 * egid adr_u_int32
876 * pid adr_u_int32
877 * sid adr_u_int32
878 * tid adr_u_int32, adr_u_int32
879 * -----------------------------------------------------------------------
882 process32_token(pr_context_t *context)
884 int returnstat;
886 /* auid */
887 returnstat = process_tag(context, TAG_AUID, 0, 0);
888 /* uid */
889 returnstat = process_tag(context, TAG_UID, returnstat, 0);
890 /* gid */
891 returnstat = process_tag(context, TAG_GID, returnstat, 0);
892 /* ruid */
893 returnstat = process_tag(context, TAG_RUID, returnstat, 0);
894 /* rgid */
895 returnstat = process_tag(context, TAG_RGID, returnstat, 0);
896 /* pid */
897 returnstat = process_tag(context, TAG_PID, returnstat, 0);
898 /* sid */
899 returnstat = process_tag(context, TAG_SID, returnstat, 0);
900 /* tid */
901 returnstat = process_tag(context, TAG_TID32, returnstat, 1);
903 return (returnstat);
907 process64_token(pr_context_t *context)
909 int returnstat;
911 /* auid */
912 returnstat = process_tag(context, TAG_AUID, 0, 0);
913 /* uid */
914 returnstat = process_tag(context, TAG_UID, returnstat, 0);
915 /* gid */
916 returnstat = process_tag(context, TAG_GID, returnstat, 0);
917 /* ruid */
918 returnstat = process_tag(context, TAG_RUID, returnstat, 0);
919 /* rgid */
920 returnstat = process_tag(context, TAG_RGID, returnstat, 0);
921 /* pid */
922 returnstat = process_tag(context, TAG_PID, returnstat, 0);
923 /* sid */
924 returnstat = process_tag(context, TAG_SID, returnstat, 0);
925 /* tid */
926 returnstat = process_tag(context, TAG_TID64, returnstat, 1);
928 return (returnstat);
932 * -----------------------------------------------------------------------
933 * process_ex_token() : Process process token and display contents
934 * return codes : -1 - error
935 * : 0 - successful
936 * NOTE: At the time of call, the process token id has been retrieved
938 * Format of extended process token:
939 * process token id adr_char
940 * auid adr_u_int32
941 * euid adr_u_int32
942 * egid adr_u_int32
943 * ruid adr_u_int32
944 * egid adr_u_int32
945 * pid adr_u_int32
946 * sid adr_u_int32
947 * tid adr_u_int32, adr_u_int32, 4*adr_u_int32
948 * -----------------------------------------------------------------------
951 process32_ex_token(pr_context_t *context)
953 int returnstat;
955 /* auid */
956 returnstat = process_tag(context, TAG_AUID, 0, 0);
957 /* uid */
958 returnstat = process_tag(context, TAG_UID, returnstat, 0);
959 /* gid */
960 returnstat = process_tag(context, TAG_GID, returnstat, 0);
961 /* ruid */
962 returnstat = process_tag(context, TAG_RUID, returnstat, 0);
963 /* rgid */
964 returnstat = process_tag(context, TAG_RGID, returnstat, 0);
965 /* pid */
966 returnstat = process_tag(context, TAG_PID, returnstat, 0);
967 /* sid */
968 returnstat = process_tag(context, TAG_SID, returnstat, 0);
969 /* tid */
970 returnstat = process_tag(context, TAG_TID32_EX, returnstat, 1);
972 return (returnstat);
976 process64_ex_token(pr_context_t *context)
978 int returnstat;
980 /* auid */
981 returnstat = process_tag(context, TAG_AUID, 0, 0);
982 /* uid */
983 returnstat = process_tag(context, TAG_UID, returnstat, 0);
984 /* gid */
985 returnstat = process_tag(context, TAG_GID, returnstat, 0);
986 /* ruid */
987 returnstat = process_tag(context, TAG_RUID, returnstat, 0);
988 /* rgid */
989 returnstat = process_tag(context, TAG_RGID, returnstat, 0);
990 /* pid */
991 returnstat = process_tag(context, TAG_PID, returnstat, 0);
992 /* sid */
993 returnstat = process_tag(context, TAG_SID, returnstat, 0);
994 /* tid */
995 returnstat = process_tag(context, TAG_TID64_EX, returnstat, 1);
997 return (returnstat);
1001 * -----------------------------------------------------------------------
1002 * return_value32_token(): Process return value and display contents
1003 * return codes : -1 - error
1004 * : 0 - successful
1005 * NOTE: At the time of call, the return value token id has been retrieved
1007 * Format of return value token:
1008 * return value token id adr_char
1009 * error number adr_char
1010 * return value adr_int32
1011 * -----------------------------------------------------------------------
1014 return_value32_token(pr_context_t *context)
1016 int returnstat;
1017 uchar_t number;
1018 int32_t value;
1019 char pb[512]; /* print buffer */
1020 uval_t uval;
1021 bool_t used_ret_val = 0;
1024 * Every audit record generated contains a return token.
1026 * The return token is a special token. It indicates the success
1027 * or failure of the event that contains it.
1028 * The return32 token contains two pieces of data:
1030 * char number;
1031 * int32_t return_value;
1033 * For audit records generated by the kernel:
1034 * The kernel always puts a positive value in "number".
1035 * Upon success "number" is 0.
1036 * Upon failure "number" is a positive errno value that is less than
1037 * sys_nerr.
1039 * For audit records generated at the user level:
1040 * Upon success "number" is 0.
1041 * Upon failure "number" is -1.
1043 * For both kernel and user land the value of "return_value" is
1044 * arbitrary. For the kernel it contains the return value of
1045 * the system call. For user land it contains an arbitrary return
1046 * value if it is less than ADT_FAIL_VALUE; ADT_FAIL_VALUE
1047 * and above are messages defined in adt_event.h. ADT_FAIL_PAM and
1048 * above are messages from pam_strerror(). No interpretation is done
1049 * on "return_value" if it is outside the range of ADT_FAIL_VALUE_* or
1050 * ADT_FAIL_PAM values.
1052 if ((returnstat = open_tag(context, TAG_ERRVAL)) != 0)
1053 return (returnstat);
1055 if ((returnstat = pr_adr_u_char(context, &number, 1)) == 0) {
1056 if (!(context->format & PRF_RAWM)) {
1057 used_ret_val = 1;
1058 pa_error(number, pb, sizeof (pb));
1059 uval.uvaltype = PRA_STRING;
1060 uval.string_val = pb;
1061 if ((returnstat = pa_print(context, &uval, 0)) != 0)
1062 return (returnstat);
1063 if ((returnstat = close_tag(context, TAG_ERRVAL)) != 0)
1064 return (returnstat);
1065 if ((returnstat = open_tag(context, TAG_RETVAL)) != 0)
1066 return (returnstat);
1068 if ((returnstat = pr_adr_int32(
1069 context, &value, 1)) != 0)
1070 return (returnstat);
1072 pa_retval(number, value, pb, sizeof (pb));
1073 } else {
1074 uval.uvaltype = PRA_INT32;
1075 if ((char)number == -1)
1076 uval.int32_val = -1;
1077 else
1078 uval.int32_val = number;
1080 returnstat = pa_print(context, &uval, used_ret_val);
1082 if (used_ret_val) {
1083 if (returnstat == 0)
1084 returnstat = close_tag(context, TAG_RETVAL);
1085 return (returnstat);
1087 if (!returnstat)
1088 if (returnstat = close_tag(context, TAG_ERRVAL))
1089 return (returnstat);
1091 return (process_tag(context, TAG_RETVAL, returnstat, 1));
1095 * -----------------------------------------------------------------------
1096 * return_value64_token(): Process return value and display contents
1097 * return codes : -1 - error
1098 * : 0 - successful
1099 * NOTE: At the time of call, the return value token id has been retrieved
1101 * Format of return value token:
1102 * return value token id adr_char
1103 * error number adr_char
1104 * return value adr_int64
1106 * HOWEVER, the 64 bit return value is a concatenation of two
1107 * 32 bit return values; the first of which is the same as is
1108 * carried in the return32 token. The second 32 bits are ignored
1109 * here so that the displayed return token will have the same
1110 * number whether the application is 32 or 64 bits.
1111 * -----------------------------------------------------------------------
1114 return_value64_token(pr_context_t *context)
1116 int returnstat;
1117 uchar_t number;
1118 rval_t rval;
1119 char pb[512]; /* print buffer */
1120 uval_t uval;
1123 * Every audit record generated contains a return token.
1125 * The return token is a special token. It indicates the success
1126 * or failure of the event that contains it.
1127 * The return64 token contains two pieces of data:
1129 * char number;
1130 * int64_t return_value;
1132 * For audit records generated by the kernel:
1133 * The kernel always puts a positive value in "number".
1134 * Upon success "number" is 0.
1135 * Upon failure "number" is a positive errno value that is less than
1136 * sys_nerr.
1138 * For audit records generated at the user level:
1139 * Upon success "number" is 0.
1140 * Upon failure "number" is -1.
1142 * For both kernel and user land the value of "return_value" is
1143 * arbitrary. For the kernel it contains the return value of
1144 * the system call. For user land it contains an arbitrary return
1145 * value if it is less than ADT_FAIL_VALUE; ADT_FAIL_VALUE
1146 * and above are messages defined in adt_event.h. ADT_FAIL_PAM and
1147 * above are messages from pam_strerror(). No interpretation is done
1148 * on "return_value" if it is outside the range of ADT_FAIL_VALUE_* or
1149 * ADT_FAIL_PAM values.
1151 * The 64 bit return value consists of two 32bit parts; for
1152 * system calls, the first part is the value returned by the
1153 * system call and the second part depends on the system call
1154 * implementation. In most cases, the second part is either 0
1155 * or garbage; because of that, it is omitted from the praudit
1156 * output.
1158 if ((returnstat = open_tag(context, TAG_ERRVAL)) != 0)
1159 return (returnstat);
1161 if ((returnstat = pr_adr_u_char(context, &number, 1)) == 0) {
1162 if (!(context->format & PRF_RAWM)) {
1163 pa_error(number, pb, sizeof (pb));
1164 uval.uvaltype = PRA_STRING;
1165 uval.string_val = pb;
1166 if ((returnstat = pa_print(context, &uval, 0)) != 0)
1167 return (returnstat);
1169 if ((returnstat = close_tag(context, TAG_ERRVAL)) != 0)
1170 return (returnstat);
1171 if ((returnstat = open_tag(context, TAG_RETVAL)) != 0)
1172 return (returnstat);
1174 if ((returnstat = pr_adr_int64(context,
1175 &rval.r_vals, 1)) != 0)
1176 return (returnstat);
1177 pa_retval(number, rval.r_val1, pb, sizeof (pb));
1178 } else {
1179 uval.uvaltype = PRA_INT32;
1180 if ((char)number == -1)
1181 uval.int32_val = -1;
1182 else
1183 uval.int32_val = number;
1185 if ((returnstat = pa_print(context, &uval, 0)) != 0)
1186 return (returnstat);
1188 if ((returnstat = close_tag(context, TAG_ERRVAL)) != 0)
1189 return (returnstat);
1190 if ((returnstat = open_tag(context, TAG_RETVAL)) != 0)
1191 return (returnstat);
1193 if ((returnstat = pr_adr_int64(context,
1194 &rval.r_vals, 1)) != 0)
1195 return (returnstat);
1196 uval.int32_val = rval.r_val1;
1198 returnstat = pa_print(context, &uval, 1);
1199 } else {
1200 return (returnstat);
1203 if (returnstat == 0)
1204 returnstat = close_tag(context, TAG_RETVAL);
1206 return (returnstat);
1210 * -----------------------------------------------------------------------
1211 * subject32_token() : Process subject token and display contents
1212 * return codes : -1 - error
1213 * : 0 - successful
1214 * NOTE: At the time of call, the subject token id has been retrieved
1216 * Format of subject token:
1217 * subject token id adr_char
1218 * auid adr_u_int32
1219 * euid adr_u_int32
1220 * egid adr_u_int32
1221 * ruid adr_u_int32
1222 * egid adr_u_int32
1223 * pid adr_u_int32
1224 * sid adr_u_int32
1225 * tid adr_u_int32, adr_u_int32
1226 * -----------------------------------------------------------------------
1229 subject32_token(pr_context_t *context)
1231 int returnstat;
1233 /* auid */
1234 returnstat = process_tag(context, TAG_AUID, 0, 0);
1235 /* uid */
1236 returnstat = process_tag(context, TAG_UID, returnstat, 0);
1237 /* gid */
1238 returnstat = process_tag(context, TAG_GID, returnstat, 0);
1239 /* ruid */
1240 returnstat = process_tag(context, TAG_RUID, returnstat, 0);
1241 /* rgid */
1242 returnstat = process_tag(context, TAG_RGID, returnstat, 0);
1243 /* pid */
1244 returnstat = process_tag(context, TAG_PID, returnstat, 0);
1245 /* sid */
1246 returnstat = process_tag(context, TAG_SID, returnstat, 0);
1247 /* tid */
1248 returnstat = process_tag(context, TAG_TID32, returnstat, 1);
1250 return (returnstat);
1254 subject64_token(pr_context_t *context)
1256 int returnstat;
1258 /* auid */
1259 returnstat = process_tag(context, TAG_AUID, 0, 0);
1260 /* uid */
1261 returnstat = process_tag(context, TAG_UID, returnstat, 0);
1262 /* gid */
1263 returnstat = process_tag(context, TAG_GID, returnstat, 0);
1264 /* ruid */
1265 returnstat = process_tag(context, TAG_RUID, returnstat, 0);
1266 /* rgid */
1267 returnstat = process_tag(context, TAG_RGID, returnstat, 0);
1268 /* pid */
1269 returnstat = process_tag(context, TAG_PID, returnstat, 0);
1270 /* sid */
1271 returnstat = process_tag(context, TAG_SID, returnstat, 0);
1272 /* tid */
1273 returnstat = process_tag(context, TAG_TID64, returnstat, 1);
1275 return (returnstat);
1279 * -----------------------------------------------------------------------
1280 * subject_ex_token(): Process subject token and display contents
1281 * return codes : -1 - error
1282 * : 0 - successful
1283 * NOTE: At the time of call, the subject token id has been retrieved
1285 * Format of extended subject token:
1286 * subject token id adr_char
1287 * auid adr_u_int32
1288 * euid adr_u_int32
1289 * egid adr_u_int32
1290 * ruid adr_u_int32
1291 * egid adr_u_int32
1292 * pid adr_u_int32
1293 * sid adr_u_int32
1294 * tid adr_u_int32, adr_u_int32
1295 * -----------------------------------------------------------------------
1298 subject32_ex_token(pr_context_t *context)
1300 int returnstat;
1302 /* auid */
1303 returnstat = process_tag(context, TAG_AUID, 0, 0);
1304 /* uid */
1305 returnstat = process_tag(context, TAG_UID, returnstat, 0);
1306 /* gid */
1307 returnstat = process_tag(context, TAG_GID, returnstat, 0);
1308 /* ruid */
1309 returnstat = process_tag(context, TAG_RUID, returnstat, 0);
1310 /* rgid */
1311 returnstat = process_tag(context, TAG_RGID, returnstat, 0);
1312 /* pid */
1313 returnstat = process_tag(context, TAG_PID, returnstat, 0);
1314 /* sid */
1315 returnstat = process_tag(context, TAG_SID, returnstat, 0);
1316 /* tid */
1317 returnstat = process_tag(context, TAG_TID32_EX, returnstat, 1);
1319 return (returnstat);
1323 subject64_ex_token(pr_context_t *context)
1325 int returnstat;
1327 /* auid */
1328 returnstat = process_tag(context, TAG_AUID, 0, 0);
1329 /* uid */
1330 returnstat = process_tag(context, TAG_UID, returnstat, 0);
1331 /* gid */
1332 returnstat = process_tag(context, TAG_GID, returnstat, 0);
1333 /* ruid */
1334 returnstat = process_tag(context, TAG_RUID, returnstat, 0);
1335 /* rgid */
1336 returnstat = process_tag(context, TAG_RGID, returnstat, 0);
1337 /* pid */
1338 returnstat = process_tag(context, TAG_PID, returnstat, 0);
1339 /* sid */
1340 returnstat = process_tag(context, TAG_SID, returnstat, 0);
1341 /* tid */
1342 returnstat = process_tag(context, TAG_TID64_EX, returnstat, 1);
1344 return (returnstat);
1348 * -----------------------------------------------------------------------
1349 * s5_IPC_token() : Process System V IPC token and display contents
1350 * return codes : -1 - error
1351 * : 0 - successful
1352 * NOTE: At the time of call, the System V IPC id has been retrieved
1354 * Format of System V IPC token:
1355 * System V IPC token id adr_char
1356 * object id adr_int32
1357 * -----------------------------------------------------------------------
1360 s5_IPC_token(pr_context_t *context)
1362 int returnstat;
1363 uchar_t ipctype;
1364 uval_t uval;
1367 * TRANSLATION_NOTE
1368 * These names refer to the type of System V IPC object:
1369 * message queue, semaphore, shared memory.
1372 if (pr_adr_u_char(context, &ipctype, 1) == 0) {
1373 if ((returnstat = open_tag(context, TAG_IPCTYPE)) != 0)
1374 return (returnstat);
1376 if (!(context->format & PRF_RAWM)) {
1377 /* print in ASCII form */
1378 uval.uvaltype = PRA_STRING;
1379 switch (ipctype) {
1380 case AT_IPC_MSG:
1381 uval.string_val = gettext("msg");
1382 break;
1383 case AT_IPC_SEM:
1384 uval.string_val = gettext("sem");
1385 break;
1386 case AT_IPC_SHM:
1387 uval.string_val = gettext("shm");
1388 break;
1390 returnstat = pa_print(context, &uval, 0);
1392 /* print in integer form */
1393 if ((context->format & PRF_RAWM) || (returnstat == 1)) {
1394 uval.uvaltype = PRA_BYTE;
1395 uval.char_val = ipctype;
1396 returnstat = pa_print(context, &uval, 0);
1398 if ((returnstat = close_tag(context, TAG_IPCTYPE)) != 0)
1399 return (returnstat);
1401 /* next get and print ipc id */
1402 return (process_tag(context, TAG_IPCID, returnstat, 1));
1403 } else {
1404 /* cannot retrieve ipc type */
1405 return (-1);
1410 * -----------------------------------------------------------------------
1411 * text_token() : Process text token and display contents
1412 * return codes : -1 - error
1413 * : 0 - successful
1414 * NOTE: At the time of call, the text token id has been retrieved
1416 * Format of text token:
1417 * text token id adr_char
1418 * text adr_string
1419 * -----------------------------------------------------------------------
1422 text_token(pr_context_t *context)
1424 return (pa_adr_string(context, 0, 1));
1428 * -----------------------------------------------------------------------
1429 * tid_token() : Process a generic terminal id token / AUT_TID
1430 * return codes : -1 - error
1431 * : 0 - successful
1432 * NOTE: At the time of call, the token id has been retrieved
1434 * Format of tid token:
1435 * ip token id adr_char
1436 * terminal type adr_char
1437 * terminal type = AU_IPADR:
1438 * remote port: adr_short
1439 * local port: adr_short
1440 * IP type: adt_int32 -- AU_IPv4 or AU_IPv6
1441 * address: adr_int32 if IPv4, else 4 * adr_int32
1442 * -----------------------------------------------------------------------
1445 tid_token(pr_context_t *context)
1447 int returnstat;
1448 uchar_t type;
1449 uval_t uval;
1451 if ((returnstat = pr_adr_u_char(context, &type, 1)) != 0)
1452 return (returnstat);
1453 uval.uvaltype = PRA_STRING;
1454 if ((returnstat = open_tag(context, TAG_TID_TYPE)) != 0)
1455 return (returnstat);
1457 switch (type) {
1458 default:
1459 return (-1); /* other than IP type is not implemented */
1460 case AU_IPADR:
1461 uval.string_val = "ip";
1462 returnstat = pa_print(context, &uval, 0);
1463 returnstat = close_tag(context, TAG_TID_TYPE);
1464 returnstat = open_tag(context, TAG_IP);
1465 returnstat = process_tag(context, TAG_IP_REMOTE, returnstat, 0);
1466 returnstat = process_tag(context, TAG_IP_LOCAL, returnstat, 0);
1467 returnstat = process_tag(context, TAG_IP_ADR, returnstat, 1);
1468 returnstat = close_tag(context, TAG_IP);
1469 break;
1471 return (returnstat);
1475 * -----------------------------------------------------------------------
1476 * ip_addr_token() : Process ip token and display contents
1477 * return codes : -1 - error
1478 * : 0 - successful
1479 * NOTE: At the time of call, the ip token id has been retrieved
1481 * Format of ip address token:
1482 * ip token id adr_char
1483 * address adr_int32 (printed in hex)
1484 * -----------------------------------------------------------------------
1488 ip_addr_token(pr_context_t *context)
1490 return (pa_hostname(context, 0, 1));
1494 ip_addr_ex_token(pr_context_t *context)
1496 int returnstat;
1497 uint32_t ip_addr[16];
1498 uint32_t ip_type;
1499 struct in_addr ia;
1500 char *ipstring;
1501 char buf[256];
1502 uval_t uval;
1504 /* get address type */
1505 if ((returnstat = pr_adr_u_int32(context, &ip_type, 1)) != 0)
1506 return (returnstat);
1508 /* legal address types are either AU_IPv4 or AU_IPv6 only */
1509 if ((ip_type != AU_IPv4) && (ip_type != AU_IPv6))
1510 return (-1);
1512 /* get address (4/16) */
1513 if ((returnstat = pr_adr_char(context, (char *)ip_addr, ip_type)) != 0)
1514 return (returnstat);
1516 uval.uvaltype = PRA_STRING;
1517 if (ip_type == AU_IPv4) {
1518 uval.string_val = buf;
1520 if (!(context->format & PRF_RAWM)) {
1521 get_Hname(ip_addr[0], buf, sizeof (buf));
1522 return (pa_print(context, &uval, 1));
1525 ia.s_addr = ip_addr[0];
1526 if ((ipstring = inet_ntoa(ia)) == NULL)
1527 return (-1);
1529 (void) snprintf(buf, sizeof (buf), "%s", ipstring);
1531 } else {
1532 uval.string_val = buf;
1534 if (!(context->format & PRF_RAWM)) {
1535 get_Hname_ex(ip_addr, buf, sizeof (buf));
1536 return (pa_print(context, &uval, 1));
1539 (void) inet_ntop(AF_INET6, (void *) ip_addr, buf,
1540 sizeof (buf));
1544 return (pa_print(context, &uval, 1));
1548 * -----------------------------------------------------------------------
1549 * ip_token() : Process ip header token and display contents
1550 * return codes : -1 - error
1551 * : 0 - successful
1552 * NOTE: At the time of call, the ip token id has been retrieved
1554 * Format of ip header token:
1555 * ip header token id adr_char
1556 * version adr_char (printed in hex)
1557 * type of service adr_char (printed in hex)
1558 * length adr_short
1559 * id adr_u_short
1560 * offset adr_u_short
1561 * ttl adr_char (printed in hex)
1562 * protocol adr_char (printed in hex)
1563 * checksum adr_u_short
1564 * source address adr_int32 (printed in hex)
1565 * destination address adr_int32 (printed in hex)
1566 * -----------------------------------------------------------------------
1569 ip_token(pr_context_t *context)
1571 int returnstat;
1573 returnstat = process_tag(context, TAG_IPVERS, 0, 0);
1574 returnstat = process_tag(context, TAG_IPSERV, returnstat, 0);
1575 returnstat = process_tag(context, TAG_IPLEN, returnstat, 0);
1576 returnstat = process_tag(context, TAG_IPID, returnstat, 0);
1577 returnstat = process_tag(context, TAG_IPOFFS, returnstat, 0);
1578 returnstat = process_tag(context, TAG_IPTTL, returnstat, 0);
1579 returnstat = process_tag(context, TAG_IPPROTO, returnstat, 0);
1580 returnstat = process_tag(context, TAG_IPCKSUM, returnstat, 0);
1581 returnstat = process_tag(context, TAG_IPSRC, returnstat, 0);
1582 returnstat = process_tag(context, TAG_IPDEST, returnstat, 1);
1584 return (returnstat);
1588 * -----------------------------------------------------------------------
1589 * iport_token() : Process ip port address token and display contents
1590 * return codes : -1 - error
1591 * : 0 - successful
1592 * NOTE: At time of call, the ip port address token id has been retrieved
1594 * Format of ip port token:
1595 * ip port address token id adr_char
1596 * port address adr_short (in_port_t == uint16_t)
1597 * -----------------------------------------------------------------------
1600 iport_token(pr_context_t *context)
1602 return (pa_adr_u_short(context, 0, 1));
1606 * -----------------------------------------------------------------------
1607 * socket_token() : Process socket token and display contents
1608 * return codes : -1 - error
1609 * : 0 - successful
1610 * NOTE: At time of call, the socket token id has been retrieved
1612 * Format of socket token:
1613 * ip socket token id adr_char
1614 * socket type adr_short (in hex)
1615 * foreign port adr_short (in hex)
1616 * foreign internet address adr_hostname/adr_int32 (in ascii/hex)
1617 * -----------------------------------------------------------------------
1619 * Note: local port and local internet address have been removed for 5.x
1622 socket_token(pr_context_t *context)
1624 int returnstat;
1626 returnstat = process_tag(context, TAG_SOCKTYPE, 0, 0);
1627 returnstat = process_tag(context, TAG_SOCKPORT, returnstat, 0);
1628 if (returnstat != 0)
1629 return (returnstat);
1631 if ((returnstat = open_tag(context, TAG_SOCKADDR)) != 0)
1632 return (returnstat);
1634 if ((returnstat = pa_hostname(context, returnstat, 1)) != 0)
1635 return (returnstat);
1637 return (close_tag(context, TAG_SOCKADDR));
1641 * -----------------------------------------------------------------------
1642 * socket_ex_token() : Process socket token and display contents
1643 * return codes : -1 - error
1644 * : 0 - successful
1645 * NOTE: At time of call, the extended socket token id has been retrieved
1647 * Format of extended socket token:
1648 * token id adr_char
1649 * socket domain adr_short (in hex)
1650 * socket type adr_short (in hex)
1651 * IP address type adr_short (in hex) [not displayed]
1652 * local port adr_short (in hex)
1653 * local internet address adr_hostname/adr_int32 (in ascii/hex)
1654 * foreign port adr_short (in hex)
1655 * foreign internet address adr_hostname/adr_int32 (in ascii/hex)
1656 * -----------------------------------------------------------------------
1658 * Note: local port and local internet address have been removed for 5.x
1661 socket_ex_token(pr_context_t *context)
1663 int returnstat;
1665 returnstat = process_tag(context, TAG_SOCKEXDOM, 0, 0);
1666 returnstat = process_tag(context, TAG_SOCKEXTYPE, returnstat, 0);
1667 returnstat = pa_hostname_so(context, returnstat, 1);
1669 return (returnstat);
1673 * -----------------------------------------------------------------------
1674 * sequence_token() : Process sequence token and display contents
1675 * return codes : -1 - error
1676 * : 0 - successful
1677 * NOTE: At time of call, the socket token id has been retrieved
1679 * Format of sequence token:
1680 * sequence token id adr_char
1681 * sequence number adr_u_int32 (in hex)
1682 * -----------------------------------------------------------------------
1685 sequence_token(pr_context_t *context)
1687 return (process_tag(context, TAG_SEQNUM, 0, 1));
1691 * -----------------------------------------------------------------------
1692 * acl_token() : Process access control list term
1693 * return codes : -1 - error
1694 * : 0 - successful
1696 * Format of acl token:
1697 * token id adr_char
1698 * term type adr_u_int32
1699 * term value adr_u_int32 (depends on type)
1700 * file mode adr_u_int (in octal)
1701 * -----------------------------------------------------------------------
1704 acl_token(pr_context_t *context)
1706 int returnstat;
1708 returnstat = pa_pw_uid_gr_gid(context, 0, 0);
1710 return (process_tag(context, TAG_MODE, returnstat, 1));
1714 * -----------------------------------------------------------------------
1715 * ace_token() : Process ZFS/NFSv4 access control list term
1716 * return codes : -1 - error
1717 * : 0 - successful
1719 * Format of ace token:
1720 * token id adr_char
1721 * term who adr_u_int32 (uid/gid)
1722 * term mask adr_u_int32
1723 * term flags adr_u_int16
1724 * term type adr_u_int16
1725 * -----------------------------------------------------------------------
1728 ace_token(pr_context_t *context)
1730 return (pa_ace(context, 0, 1));
1734 * -----------------------------------------------------------------------
1735 * attribute_token() : Process attribute token and display contents
1736 * return codes : -1 - error
1737 * : 0 - successful
1738 * NOTE: At the time of call, the attribute token id has been retrieved
1740 * Format of attribute token:
1741 * attribute token id adr_char
1742 * mode adr_u_int (printed in octal)
1743 * uid adr_u_int
1744 * gid adr_u_int
1745 * file system id adr_int
1747 * node id adr_int (attribute_token
1748 * pre SunOS 5.7)
1749 * device adr_u_int
1750 * or
1751 * node id adr_int64 (attribute32_token)
1752 * device adr_u_int
1753 * or
1754 * node id adr_int64 (attribute64_token)
1755 * device adr_u_int64
1756 * -----------------------------------------------------------------------
1759 attribute_token(pr_context_t *context)
1761 int returnstat;
1763 returnstat = process_tag(context, TAG_MODE, 0, 0);
1764 returnstat = process_tag(context, TAG_UID, returnstat, 0);
1765 returnstat = process_tag(context, TAG_GID, returnstat, 0);
1766 returnstat = process_tag(context, TAG_FSID, returnstat, 0);
1767 returnstat = process_tag(context, TAG_NODEID32, returnstat, 0);
1768 returnstat = process_tag(context, TAG_DEVICE32, returnstat, 1);
1770 return (returnstat);
1774 attribute32_token(pr_context_t *context)
1776 int returnstat;
1778 returnstat = process_tag(context, TAG_MODE, 0, 0);
1779 returnstat = process_tag(context, TAG_UID, returnstat, 0);
1780 returnstat = process_tag(context, TAG_GID, returnstat, 0);
1781 returnstat = process_tag(context, TAG_FSID, returnstat, 0);
1782 returnstat = process_tag(context, TAG_NODEID64, returnstat, 0);
1783 returnstat = process_tag(context, TAG_DEVICE32, returnstat, 1);
1785 return (returnstat);
1789 attribute64_token(pr_context_t *context)
1791 int returnstat;
1793 returnstat = process_tag(context, TAG_MODE, 0, 0);
1794 returnstat = process_tag(context, TAG_UID, returnstat, 0);
1795 returnstat = process_tag(context, TAG_GID, returnstat, 0);
1796 returnstat = process_tag(context, TAG_FSID, returnstat, 0);
1797 returnstat = process_tag(context, TAG_NODEID64, returnstat, 0);
1798 returnstat = process_tag(context, TAG_DEVICE64, returnstat, 1);
1800 return (returnstat);
1804 * -----------------------------------------------------------------------
1805 * group_token() : Process group token and display contents
1806 * return codes : -1 - error
1807 * : 0 - successful
1808 * NOTE: At the time of call, the group token id has been retrieved
1809 * NOTE: This token is obsolete; it supports exactly NGROUPS_MAX
1810 * groups.
1812 * Format of group token:
1813 * group token id adr_char
1814 * group list adr_long, 16 times
1815 * -----------------------------------------------------------------------
1818 group_token(pr_context_t *context)
1820 int returnstat = 0;
1821 int i;
1823 for (i = 0; i < NGROUPS_MAX - 1; i++) {
1824 if ((returnstat = process_tag(context, TAG_GROUPID,
1825 returnstat, 0)) < 0)
1826 return (returnstat);
1829 return (process_tag(context, TAG_GROUPID, returnstat, 1));
1833 * -----------------------------------------------------------------------
1834 * newgroup_token() : Process group token and display contents
1835 * return codes : -1 - error
1836 * : 0 - successful
1837 * NOTE: At the time of call, the group token id has been retrieved
1839 * Format of new group token:
1840 * group token id adr_char
1841 * group number adr_short
1842 * group list adr_int32, group number times
1843 * -----------------------------------------------------------------------
1846 newgroup_token(pr_context_t *context)
1848 int returnstat;
1849 int i, num;
1850 short n_groups;
1852 returnstat = pr_adr_short(context, &n_groups, 1);
1853 if (returnstat != 0)
1854 return (returnstat);
1856 num = (int)n_groups;
1857 if (num == 0) {
1858 if (!(context->format & PRF_XMLM)) {
1859 returnstat = do_newline(context, 1);
1861 return (returnstat);
1863 for (i = 0; i < num - 1; i++) {
1864 if ((returnstat = process_tag(context, TAG_GROUPID,
1865 returnstat, 0)) < 0)
1866 return (returnstat);
1869 return (process_tag(context, TAG_GROUPID, returnstat, 1));
1872 static int
1873 string_token_common(pr_context_t *context, int tag)
1875 int returnstat;
1876 int num;
1878 returnstat = pr_adr_int32(context, (int32_t *)&num, 1);
1879 if (returnstat != 0)
1880 return (returnstat);
1882 if (!(context->format & PRF_XMLM)) {
1883 returnstat = pr_printf(context, "%d%s", num,
1884 context->SEPARATOR);
1885 if (returnstat != 0)
1886 return (returnstat);
1889 if (num == 0)
1890 return (do_newline(context, 1));
1892 for (; num > 1; num--) {
1893 if ((returnstat = (process_tag(context, tag,
1894 returnstat, 0))) < 0)
1895 return (returnstat);
1898 return (process_tag(context, tag, returnstat, 1));
1902 path_attr_token(pr_context_t *context)
1904 return (string_token_common(context, TAG_XAT));
1908 exec_args_token(pr_context_t *context)
1910 return (string_token_common(context, TAG_ARG));
1914 exec_env_token(pr_context_t *context)
1916 return (string_token_common(context, TAG_ENV));
1920 * -----------------------------------------------------------------------
1921 * s5_IPC_perm_token() : Process System V IPC permission token and display
1922 * contents
1923 * return codes : -1 - error
1924 * : 0 - successful
1925 * NOTE: At the time of call, the System V IPC permission token id
1926 * has been retrieved
1928 * Format of System V IPC permission token:
1929 * System V IPC permission token id adr_char
1930 * uid adr_u_int32
1931 * gid adr_u_int32
1932 * cuid adr_u_int32
1933 * cgid adr_u_int32
1934 * mode adr_u_int32
1935 * seq adr_u_int32
1936 * key adr_int32
1937 * -----------------------------------------------------------------------
1940 s5_IPC_perm_token(pr_context_t *context)
1942 int returnstat;
1944 returnstat = process_tag(context, TAG_UID, 0, 0);
1945 returnstat = process_tag(context, TAG_GID, returnstat, 0);
1946 returnstat = process_tag(context, TAG_CUID, returnstat, 0);
1947 returnstat = process_tag(context, TAG_CGID, returnstat, 0);
1948 returnstat = process_tag(context, TAG_MODE, returnstat, 0);
1949 returnstat = process_tag(context, TAG_SEQ, returnstat, 0);
1950 returnstat = process_tag(context, TAG_KEY, returnstat, 1);
1952 return (returnstat);
1956 * -----------------------------------------------------------------------
1957 * host_token() : Process host token and display contents
1958 * return codes : -1 - error
1959 * : 0 - successful
1960 * NOTE: At the time of call, the host token id has been retrieved
1962 * Format of host token:
1963 * host token id adr_char
1964 * hostid adr_u_int32
1965 * -----------------------------------------------------------------------
1968 host_token(pr_context_t *context)
1970 return (pa_hostname(context, 0, 1));
1974 * -----------------------------------------------------------------------
1975 * liaison_token() : Process liaison token and display contents
1976 * return codes : -1 - error
1977 * : 0 - successful
1978 * NOTE: At the time of call, the liaison token id has been retrieved
1980 * Format of liaison token:
1981 * liaison token id adr_char
1982 * liaison adr_u_int32
1983 * -----------------------------------------------------------------------
1986 liaison_token(pr_context_t *context)
1988 return (pa_liaison(context, 0, 1));
1992 * -----------------------------------------------------------------------
1993 * useofauth_token(): Process useofauth token and display contents
1994 * return codes : -1 - error
1995 * : 0 - successful
1996 * NOTE: At the time of call, the uauth token id has been retrieved
1998 * Format of useofauth token:
1999 * uauth token id adr_char
2000 * uauth adr_string
2001 * -----------------------------------------------------------------------
2004 useofauth_token(pr_context_t *context)
2006 return (pa_adr_string(context, 0, 1));
2010 * -----------------------------------------------------------------------
2011 * user_token(): Process user token and display contents
2012 * return codes : -1 - error
2013 * : 0 - successful
2014 * NOTE: At the time of call, the user token id has been retrieved
2016 * Format of user token:
2017 * user token id adr_char
2018 * user id adr_uid
2019 * user name adr_string
2020 * -----------------------------------------------------------------------
2023 user_token(pr_context_t *context)
2025 int returnstat;
2027 returnstat = process_tag(context, TAG_UID, 0, 0);
2028 return (process_tag(context, TAG_USERNAME, returnstat, 1));
2032 * -----------------------------------------------------------------------
2033 * zonename_token(): Process zonename token and display contents
2034 * return codes : -1 - error
2035 * : 0 - successful
2036 * NOTE: At the time of call, the zonename token id has been retrieved
2038 * Format of zonename token:
2039 * zonename token id adr_char
2040 * zone name adr_string
2041 * -----------------------------------------------------------------------
2044 zonename_token(pr_context_t *context)
2046 return (process_tag(context, TAG_ZONENAME, 0, 1));
2050 * -----------------------------------------------------------------------
2051 * fmri_token(): Process fmri token and display contents
2052 * return codes : -1 - error
2053 * : 0 - successful
2054 * NOTE: At the time of call, the fmri token id has been retrieved
2056 * Format of fmri token:
2057 * fmri token id adr_char
2058 * service instance name adr_string
2059 * -----------------------------------------------------------------------
2062 fmri_token(pr_context_t *context)
2064 return (pa_adr_string(context, 0, 1));
2068 * -----------------------------------------------------------------------
2069 * xatom_token() : Process Xatom token and display contents in hex.
2070 * return codes : -1 - error
2071 * : 0 - successful
2072 * NOTE: At the time of call, the xatom token id has been retrieved
2074 * Format of xatom token:
2075 * token id adr_char
2076 * length adr_short
2077 * atom adr_char length times
2078 * -----------------------------------------------------------------------
2081 xatom_token(pr_context_t *context)
2083 return (pa_adr_string(context, 0, 1));
2087 xcolormap_token(pr_context_t *context)
2089 return (pa_xgeneric(context));
2093 xcursor_token(pr_context_t *context)
2095 return (pa_xgeneric(context));
2099 xfont_token(pr_context_t *context)
2101 return (pa_xgeneric(context));
2105 xgc_token(pr_context_t *context)
2107 return (pa_xgeneric(context));
2111 xpixmap_token(pr_context_t *context)
2113 return (pa_xgeneric(context));
2117 xwindow_token(pr_context_t *context)
2119 return (pa_xgeneric(context));
2123 * -----------------------------------------------------------------------
2124 * xproperty_token(): Process Xproperty token and display contents
2126 * return codes : -1 - error
2127 * : 0 - successful
2128 * NOTE: At the time of call, the xproperty token id has been retrieved
2130 * Format of xproperty token:
2131 * token id adr_char
2132 * XID adr_u_int32
2133 * creator UID adr_u_int32
2134 * text adr_text
2135 * -----------------------------------------------------------------------
2138 xproperty_token(pr_context_t *context)
2140 int returnstat;
2142 returnstat = process_tag(context, TAG_XID, 0, 0);
2143 returnstat = process_tag(context, TAG_XCUID, returnstat, 0);
2145 /* Done with attributes; force end of token open */
2146 if (returnstat == 0)
2147 returnstat = finish_open_tag(context);
2149 returnstat = pa_adr_string(context, returnstat, 1);
2151 return (returnstat);
2155 * -----------------------------------------------------------------------
2156 * xselect_token(): Process Xselect token and display contents in hex
2158 * return codes : -1 - error
2159 * : 0 - successful
2160 * NOTE: At the time of call, the xselect token id has been retrieved
2162 * Format of xselect token
2163 * text token id adr_char
2164 * property text adr_string
2165 * property type adr_string
2166 * property data adr_string
2167 * -----------------------------------------------------------------------
2170 xselect_token(pr_context_t *context)
2172 int returnstat;
2174 returnstat = process_tag(context, TAG_XSELTEXT, 0, 0);
2175 returnstat = process_tag(context, TAG_XSELTYPE, returnstat, 0);
2176 returnstat = process_tag(context, TAG_XSELDATA, returnstat, 1);
2178 return (returnstat);
2182 * -----------------------------------------------------------------------
2183 * xclient_token(): Process Xclient token and display contents in hex.
2185 * return codes : -1 - error
2186 * : 0 - successful
2188 * Format of xclient token:
2189 * token id adr_char
2190 * client adr_int32
2191 * -----------------------------------------------------------------------
2194 xclient_token(pr_context_t *context)
2196 return (pa_adr_int32(context, 0, 1));
2200 * -----------------------------------------------------------------------
2201 * useofpriv_token() : Process priv token and display contents
2202 * return codes : -1 - error
2203 * : 0 - successful
2204 * NOTE: At the time of call, the useofpriv token id has been retrieved
2206 * Format of useofpriv token:
2207 * useofpriv token id adr_char
2208 * success/failure flag adr_char
2209 * priv adr_int32 (Trusted Solaris)
2210 * priv_set '\0' separated privileges.
2211 * -----------------------------------------------------------------------
2213 /*ARGSUSED*/
2215 useofpriv_token(pr_context_t *context)
2217 int returnstat;
2218 char sf;
2219 uval_t uval;
2221 if ((returnstat = pr_adr_char(context, &sf, 1)) != 0) {
2222 return (returnstat);
2224 if (!(context->format & PRF_RAWM)) {
2225 /* print in ASCII form */
2227 if ((returnstat = open_tag(context, TAG_RESULT)) != 0)
2228 return (returnstat);
2230 uval.uvaltype = PRA_STRING;
2231 if (sf) {
2232 uval.string_val = gettext("successful use of priv");
2233 returnstat = pa_print(context, &uval, 0);
2234 } else {
2235 uval.string_val = gettext("failed use of priv");
2236 returnstat = pa_print(context, &uval, 0);
2238 if (returnstat == 0)
2239 returnstat = close_tag(context, TAG_RESULT);
2241 /* Done with attributes; force end of token open */
2242 if (returnstat == 0)
2243 returnstat = finish_open_tag(context);
2244 } else {
2245 /* print in hexadecimal form */
2246 if ((returnstat = open_tag(context, TAG_RESULT)) != 0)
2247 return (returnstat);
2248 uval.uvaltype = PRA_SHORT;
2249 uval.short_val = sf;
2250 returnstat = pa_print(context, &uval, 0);
2251 if (returnstat == 0)
2252 returnstat = close_tag(context, TAG_RESULT);
2254 /* Done with attributes; force end of token open */
2255 if (returnstat == 0)
2256 returnstat = finish_open_tag(context);
2258 return (pa_adr_string(context, 0, 1));
2262 * -----------------------------------------------------------------------
2263 * privilege_token() : Process privilege token and display contents
2264 * return codes : -1 - error
2265 * : 0 - successful
2266 * NOTE: At the time of call, the privilege token id has been retrieved
2268 * Format of privilege token:
2269 * privilege token id adr_char
2270 * privilege type adr_string
2271 * privilege adr_string
2272 * -----------------------------------------------------------------------
2275 privilege_token(pr_context_t *context)
2277 int returnstat;
2279 /* privilege type: */
2280 returnstat = process_tag(context, TAG_SETTYPE, 0, 0);
2282 /* Done with attributes; force end of token open */
2283 if (returnstat == 0)
2284 returnstat = finish_open_tag(context);
2286 /* privilege: */
2287 return (pa_adr_string(context, returnstat, 1));
2291 * -----------------------------------------------------------------------
2292 * secflags_token() : Process privilege token and display contents
2293 * return codes : -1 - error
2294 * : 0 - successful
2295 * NOTE: At the time of call, the secflags token id has been retrieved
2297 * Format of secflags token:
2298 * secflags token id adr_char
2299 * secflag set name adr_string
2300 * secflags adr_string
2301 * -----------------------------------------------------------------------
2304 secflags_token(pr_context_t *context)
2306 int returnstat;
2308 /* Set name */
2309 returnstat = process_tag(context, TAG_SETTYPE, 0, 0);
2311 /* Done with attributes; force end of token open */
2312 if (returnstat == 0)
2313 returnstat = finish_open_tag(context);
2315 /* set */
2316 return (pa_adr_string(context, returnstat, 1));