Print this page
7029 want per-process exploit mitigation features (secflags)
7030 want basic address space layout randomization (aslr)
7031 noexec_user_stack should be a secflag
7032 want a means to forbid mappings around NULL.
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/praudit/token.c
+++ new/usr/src/cmd/praudit/token.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26
27 27 #include <ctype.h>
28 28 #include <dirent.h>
29 29 #include <grp.h>
30 30 #include <libintl.h>
31 31 #include <limits.h>
32 32 #include <locale.h>
33 33 #include <pwd.h>
34 34 #include <stdio.h>
35 35 #include <stdlib.h>
36 36 #include <string.h>
37 37 #include <sys/types.h>
38 38 #include <sys/inttypes.h>
39 39 #include <sys/file.h>
40 40 #include <sys/param.h>
41 41 #include <sys/uio.h>
42 42 #include <sys/stat.h>
43 43 #include <sys/acl.h>
44 44 #include <sys/socket.h>
45 45 #include <sys/errno.h>
46 46 #include <sys/ipc.h>
47 47 #include <sys/sem.h>
48 48 #include <sys/systm.h>
49 49 #include <netinet/in.h>
50 50 #include <sys/tiuser.h>
51 51 #include <rpc/types.h>
52 52 #include <rpc/auth.h>
53 53 #include <rpc/auth_unix.h>
54 54 #include <rpc/svc.h>
55 55 #include <rpc/xdr.h>
56 56 #include <nfs/nfs.h>
57 57 #include <sys/fs/ufs_quota.h>
58 58 #include <sys/time.h>
59 59 #include <sys/mkdev.h>
60 60 #include <unistd.h>
61 61
62 62 #include <bsm/audit.h>
63 63 #include <bsm/audit_record.h>
64 64 #include <bsm/libbsm.h>
65 65
66 66 #include <tsol/label.h>
67 67
68 68 #include "praudit.h"
69 69 #include "toktable.h"
70 70
71 71 #include <netdb.h>
72 72 #include <arpa/inet.h>
73 73
74 74 static char *anchor_path(char *);
75 75 static char *collapse_path(char *);
76 76
77 77
78 78 /*
79 79 * -----------------------------------------------------------------------
80 80 * is_file_token:
81 81 * Tests whether the specified token id represents a type
82 82 * of file token.
83 83 * return codes : 1 - tokenid is a file token type
84 84 * : 0 - otherwise
85 85 * -----------------------------------------------------------------------
86 86 */
87 87 int
88 88 is_file_token(int tokenid)
89 89 {
90 90 if ((tokenid == AUT_OTHER_FILE32) || (tokenid == AUT_OTHER_FILE64))
91 91 return (1);
92 92
93 93 return (0);
94 94 }
95 95
96 96 /*
97 97 * -----------------------------------------------------------------------
98 98 * is_header_token:
99 99 * Tests whether the specified token id represents a type
100 100 * of header token (signifying the start of a record).
101 101 * return codes : 1 - tokenid is a header type
102 102 * : 0 - otherwise
103 103 * -----------------------------------------------------------------------
104 104 */
105 105 int
106 106 is_header_token(int tokenid)
107 107 {
108 108 if ((tokenid == AUT_OHEADER) || (tokenid == AUT_HEADER32) ||
109 109 (tokenid == AUT_HEADER32_EX) || (tokenid == AUT_HEADER64) ||
110 110 (tokenid == AUT_HEADER64_EX))
111 111 return (1);
112 112
113 113 return (0);
114 114 }
115 115
116 116 /*
117 117 * -----------------------------------------------------------------------
118 118 * is_token:
119 119 * Tests whether the specified token id represents a true
120 120 * token, as opposed to a regular tag.
121 121 * return codes : 1 - tokenid is a true token
122 122 * : 0 - otherwise
123 123 * -----------------------------------------------------------------------
124 124 */
125 125 int
126 126 is_token(int tokenid)
127 127 {
128 128 if ((tokenid > 0) && (tokenid <= MAXTOKEN))
129 129 return (1);
130 130
131 131 return (0);
132 132 }
133 133
134 134
135 135 /*
136 136 * -----------------------------------------------------------------------
137 137 * exit_token() : Process information label token and display contents
138 138 * return codes : -1 - error
139 139 * : 0 - successful
140 140 * NOTE: At the time of call, the label token id has been retrieved
141 141 *
142 142 * Format of exit token:
143 143 * exit token id adr_char
144 144 * -----------------------------------------------------------------------
145 145 */
146 146 int
147 147 exit_token(pr_context_t *context)
148 148 {
149 149 int returnstat;
150 150 int retval;
151 151 uval_t uval;
152 152
153 153 if ((returnstat = open_tag(context, TAG_ERRVAL)) != 0)
154 154 return (returnstat);
155 155
156 156 if ((returnstat = pr_adr_int32(context, (int32_t *)&retval, 1)) == 0) {
157 157 if (!(context->format & PRF_RAWM)) {
158 158 char *emsg = strerror(retval);
159 159
160 160 if (emsg == NULL)
161 161 uval.string_val = gettext("Unknown errno");
162 162 else
163 163 uval.string_val = gettext(emsg);
164 164 uval.uvaltype = PRA_STRING;
165 165 } else {
166 166 uval.uvaltype = PRA_INT32;
167 167 uval.int32_val = retval;
168 168 }
169 169 returnstat = pa_print(context, &uval, 0);
170 170 }
171 171 if (returnstat == 0)
172 172 returnstat = close_tag(context, TAG_ERRVAL);
173 173
174 174 return (process_tag(context, TAG_RETVAL, returnstat, 1));
175 175 }
176 176
177 177 /*
178 178 * ------------------------------------------------------------------
179 179 * file_token() : prints out seconds of time and other file name
180 180 * return codes : -1 - error
181 181 * : 0 - successful, valid file token fields
182 182 * At the time of entry, the file token ID has already been retrieved
183 183 *
184 184 * Format of file token:
185 185 * file token id adr_char
186 186 * seconds of time adr_u_int
187 187 * name of other file adr_string
188 188 * ------------------------------------------------------------------
189 189 */
190 190 int
191 191 file_token(pr_context_t *context)
192 192 {
193 193 int returnstat;
194 194
195 195 returnstat = pa_utime32(context, 0, 0); /* time from usecs */
196 196
197 197 /* other file name */
198 198 returnstat = pa_file_string(context, returnstat, 1);
199 199
200 200 return (returnstat);
201 201 }
202 202
203 203 int
204 204 file64_token(pr_context_t *context)
205 205 {
206 206 int returnstat;
207 207
208 208 returnstat = pa_utime64(context, 0, 0); /* time from usecs */
209 209
210 210 /* other file name */
211 211 returnstat = pa_file_string(context, returnstat, 1);
212 212
213 213 return (returnstat);
214 214 }
215 215
216 216 /*
217 217 * -----------------------------------------------------------------------
218 218 * header_token() : Process record header token and display contents
219 219 * return codes : -1 - error
220 220 * : 0 - successful
221 221 * : 1 - warning, password entry not found
222 222 *
223 223 * NOTE: At the time of call, the header token id has been retrieved
224 224 *
225 225 * Format of header token:
226 226 * header token id adr_char
227 227 * record byte count adr_u_int
228 228 * event type adr_u_short (printed either ASCII or raw)
229 229 * event class adr_u_int (printed either ASCII or raw)
230 230 * event action adr_u_int
231 231 * if extended: extended host name (IPv4/IPv6)
232 232 * seconds of time adr_u_int (printed either ASCII or raw)
233 233 * nanoseconds of time adr_u_int
234 234 * -----------------------------------------------------------------------
235 235 */
236 236 int
237 237 header_token(pr_context_t *context)
238 238 {
239 239 int returnstat;
240 240
241 241 returnstat = pa_reclen(context, 0); /* record byte */
242 242 /* version ID */
243 243 returnstat = process_tag(context, TAG_TOKVERS, returnstat, 0);
244 244 /* event type */
245 245 returnstat = process_tag(context, TAG_EVTYPE, returnstat, 0);
246 246 /* event modifier */
247 247 returnstat = pa_event_modifier(context, returnstat, 0);
248 248 /* time from nsec */
249 249 returnstat = pa_ntime32(context, returnstat, 1);
250 250
251 251 return (returnstat);
252 252 }
253 253
254 254 int
255 255 header64_token(pr_context_t *context)
256 256 {
257 257 int returnstat;
258 258
259 259 returnstat = pa_reclen(context, 0); /* record byte */
260 260 /* version ID */
261 261 returnstat = process_tag(context, TAG_TOKVERS, returnstat, 0);
262 262 /* event type */
263 263 returnstat = process_tag(context, TAG_EVTYPE, returnstat, 0);
264 264 /* event modifier */
265 265 returnstat = pa_event_modifier(context, returnstat, 0);
266 266 /* time from nsec */
267 267 returnstat = pa_ntime64(context, returnstat, 1);
268 268
269 269 return (returnstat);
270 270 }
271 271
272 272 int
273 273 header32_ex_token(pr_context_t *context)
274 274 {
275 275 int returnstat;
276 276
277 277 returnstat = pa_reclen(context, 0); /* record byte */
278 278 /* version ID */
279 279 returnstat = process_tag(context, TAG_TOKVERS, returnstat, 0);
280 280 /* event type */
281 281 returnstat = process_tag(context, TAG_EVTYPE, returnstat, 0);
282 282 /* event modifier */
283 283 returnstat = pa_event_modifier(context, returnstat, 0);
284 284 /* machine name */
285 285 returnstat = pa_hostname_ex(context, returnstat, 0);
286 286 /* time from nsec */
287 287 returnstat = pa_ntime32(context, returnstat, 1);
288 288
289 289 return (returnstat);
290 290 }
291 291
292 292 int
293 293 header64_ex_token(pr_context_t *context)
294 294 {
295 295 int returnstat;
296 296
297 297 returnstat = pa_reclen(context, 0); /* record byte */
298 298 /* version ID */
299 299 returnstat = process_tag(context, TAG_TOKVERS, returnstat, 0);
300 300 /* event type */
301 301 returnstat = process_tag(context, TAG_EVTYPE, returnstat, 0);
302 302 /* event modifier */
303 303 returnstat = pa_event_modifier(context, returnstat, 0);
304 304 /* machine name */
305 305 returnstat = pa_hostname_ex(context, returnstat, 0);
306 306 /* time from nsec */
307 307 returnstat = pa_ntime64(context, returnstat, 1);
308 308
309 309 return (returnstat);
310 310 }
311 311
312 312 /*
313 313 * -----------------------------------------------------------------------
314 314 * trailer_token() : Process record trailer token and display contents
315 315 * return codes : -1 - error
316 316 * : 0 - successful
317 317 * NOTE: At the time of call, the trailer token id has already been
318 318 * retrieved
319 319 *
320 320 * Format of trailer token:
321 321 * trailer token id adr_char
322 322 * record sequence no adr_u_short (should be AUT_TRAILER_MAGIC)
323 323 * record byte count adr_u_int
324 324 * -----------------------------------------------------------------------
325 325 */
326 326 int
327 327 trailer_token(pr_context_t *context)
328 328 {
329 329 short magic_number;
330 330
331 331 if (pr_adr_u_short(context, (ushort_t *)&magic_number, 1) < 0) {
332 332 (void) fprintf(stderr, gettext(
333 333 "praudit: Cannot retrieve trailer magic number\n"));
334 334 return (-1);
335 335 } else {
336 336 if (magic_number != AUT_TRAILER_MAGIC) {
337 337 (void) fprintf(stderr, gettext(
338 338 "praudit: Invalid trailer magic number\n"));
339 339 return (-1);
340 340 } else
341 341 /* Do not display trailer in XML mode */
342 342 if (context->format & PRF_XMLM) {
343 343 uint32_t junk;
344 344 int retstat;
345 345
346 346 retstat = pr_adr_u_int32(context, &junk, 1);
347 347 return (retstat);
348 348 } else {
349 349 return (pa_adr_u_int32(context, 0, 1));
350 350 }
351 351 }
352 352 }
353 353
354 354 /*
355 355 * -----------------------------------------------------------------------
356 356 * arbitrary_data_token():
357 357 * Process arbitrary data token and display contents
358 358 * return codes : -1 - error
359 359 * : 0 - successful
360 360 * NOTE: At the time of call, the arbitrary data token id has already
361 361 * been retrieved
362 362 *
363 363 * Format of arbitrary data token:
364 364 * arbitrary data token id adr char
365 365 * how to print adr_char
366 366 * From audit_record.h, this may be either:
367 367 * AUP_BINARY binary
368 368 * AUP_OCTAL octal
369 369 * AUP_DECIMAL decimal
370 370 * AUP_HEX hexadecimal
371 371 * basic unit adr_char
372 372 * From audit_record.h, this may be either:
373 373 * AUR_BYTE byte
374 374 * AUR_CHAR char
375 375 * AUR_SHORT short
376 376 * AUR_INT32 int32_t
377 377 * AUR_INT64 int64_t
378 378 * unit count adr_char, specifying number of units of
379 379 * data in the "data items" parameter below
380 380 * data items depends on basic unit
381 381 *
382 382 * -----------------------------------------------------------------------
383 383 */
384 384 int
385 385 arbitrary_data_token(pr_context_t *context)
386 386 {
387 387 int returnstat;
388 388 int i;
389 389 char c1;
390 390 short c2;
391 391 int32_t c3;
392 392 int64_t c4;
393 393 char how_to_print, basic_unit, unit_count, fwid;
394 394 char *p;
395 395 int index = 0;
396 396 char *pformat = "%*s";
397 397
398 398 uval_t uval;
399 399
400 400 if ((returnstat = pr_adr_char(context, &how_to_print, 1)) != 0)
401 401 return (returnstat);
402 402
403 403 if ((returnstat = pr_adr_char(context, &basic_unit, 1)) != 0)
404 404 return (returnstat);
405 405
406 406 if ((returnstat = pr_adr_char(context, &unit_count, 1)) != 0)
407 407 return (returnstat);
408 408
409 409 if (!(context->format & PRF_RAWM)) {
410 410 uval.uvaltype = PRA_STRING;
411 411 uval.string_val = htp2string(how_to_print);
412 412 } else {
413 413 uval.uvaltype = PRA_INT32;
414 414 uval.int32_val = (int)how_to_print;
415 415 }
416 416
417 417 if ((returnstat = open_tag(context, TAG_ARBPRINT)) != 0)
418 418 return (returnstat);
419 419 if ((returnstat = pa_print(context, &uval, 0)) < 0)
420 420 return (returnstat);
421 421 if ((returnstat = close_tag(context, TAG_ARBPRINT)) != 0)
422 422 return (returnstat);
423 423
424 424 if (!(context->format & PRF_RAWM)) {
425 425 uval.uvaltype = PRA_STRING;
426 426 uval.string_val = bu2string(basic_unit);
427 427 } else {
428 428 uval.uvaltype = PRA_INT32;
429 429 uval.int32_val = (int32_t)basic_unit;
430 430 }
431 431
432 432 if ((returnstat = open_tag(context, TAG_ARBTYPE)) != 0)
433 433 return (returnstat);
434 434 if ((returnstat = pa_print(context, &uval, 0)) < 0)
435 435 return (returnstat);
436 436 if ((returnstat = close_tag(context, TAG_ARBTYPE)) != 0)
437 437 return (returnstat);
438 438
439 439 uval.uvaltype = PRA_INT32;
440 440 uval.int32_val = (int32_t)unit_count;
441 441
442 442 if ((returnstat = open_tag(context, TAG_ARBCOUNT)) != 0)
443 443 return (returnstat);
444 444 if ((returnstat = pa_print(context, &uval, 1)) < 0)
445 445 return (returnstat);
446 446 if ((returnstat = close_tag(context, TAG_ARBCOUNT)) != 0)
447 447 return (returnstat);
448 448
449 449 /* Done with attributes; force end of token open */
450 450 if ((returnstat = finish_open_tag(context)) != 0)
451 451 return (returnstat);
452 452
453 453 /* get the field width in case we need to format output */
454 454 fwid = findfieldwidth(basic_unit, how_to_print);
455 455 p = (char *)malloc(80);
456 456
457 457 /* now get the data items and print them */
458 458 for (i = 0; (i < unit_count); i++) {
459 459 switch (basic_unit) {
460 460 /* case AUR_BYTE: */
461 461 case AUR_CHAR:
462 462 if (pr_adr_char(context, &c1, 1) == 0)
463 463 (void) convert_char_to_string(how_to_print,
464 464 c1, p);
465 465 else {
466 466 free(p);
467 467 return (-1);
468 468 }
469 469 break;
470 470 case AUR_SHORT:
471 471 if (pr_adr_short(context, &c2, 1) == 0)
472 472 (void) convert_short_to_string(how_to_print,
473 473 c2, p);
474 474 else {
475 475 free(p);
476 476 return (-1);
477 477 }
478 478 break;
479 479 case AUR_INT32:
480 480 if (pr_adr_int32(context, &c3, 1) == 0)
481 481 (void) convert_int32_to_string(how_to_print,
482 482 c3, p);
483 483 else {
484 484 free(p);
485 485 return (-1);
486 486 }
487 487 break;
488 488 case AUR_INT64:
489 489 if (pr_adr_int64(context, &c4, 1) == 0)
490 490 (void) convert_int64_to_string(how_to_print,
491 491 c4, p);
492 492 else {
493 493 free(p);
494 494 return (-1);
495 495 }
496 496 break;
497 497 default:
498 498 free(p);
499 499 return (-1);
500 500 /*NOTREACHED*/
501 501 }
502 502
503 503 /*
504 504 * At this point, we have successfully retrieved a data
505 505 * item and converted it into an ASCII string pointed to
506 506 * by p. If all output is to be printed on one line,
507 507 * simply separate the data items by a space (or by the
508 508 * delimiter if this is the last data item), otherwise, we
509 509 * need to format the output before display.
510 510 */
511 511 if (context->format & PRF_ONELINE) {
512 512 returnstat = pr_printf(context, "%s", p);
513 513 if ((returnstat >= 0) && (i == (unit_count - 1)))
514 514 returnstat = pr_printf(context, "%s",
515 515 context->SEPARATOR);
516 516 else
517 517 returnstat = pr_putchar(context, ' ');
518 518 } else { /* format output */
519 519 returnstat = pr_printf(context, pformat, fwid, p);
520 520 index += fwid;
521 521 if ((returnstat >= 0) &&
522 522 (((index + fwid) > 75) ||
523 523 (i == (unit_count - 1)))) {
524 524 returnstat = pr_putchar(context, '\n');
525 525 index = 0;
526 526 }
527 527 } /* else if PRF_ONELINE */
528 528 if (returnstat < 0) {
529 529 free(p);
530 530 return (returnstat);
531 531 }
532 532 }
533 533 free(p);
534 534
535 535 return (returnstat);
536 536 }
537 537
538 538 /*
539 539 * -----------------------------------------------------------------------
540 540 * opaque_token() : Process opaque token and display contents
541 541 * return codes : -1 - error
542 542 * : 0 - successful
543 543 * NOTE: At the time of call, the opaque token id has already been
544 544 * retrieved
545 545 *
546 546 * Format of opaque token:
547 547 * opaque token id adr_char
548 548 * size adr_short
549 549 * data adr_char, size times
550 550 * -----------------------------------------------------------------------
551 551 */
552 552 int
553 553 opaque_token(pr_context_t *context)
554 554 {
555 555 int returnstat;
556 556 short size;
557 557 char *charp;
558 558 uval_t uval;
559 559
560 560
561 561 /* print the size of the token */
562 562 if (pr_adr_short(context, &size, 1) == 0) {
563 563 uval.uvaltype = PRA_SHORT;
564 564 uval.short_val = size;
565 565 returnstat = pa_print(context, &uval, 0);
566 566 } else
567 567 returnstat = -1;
568 568
569 569 /* now print out the data field in hexadecimal */
570 570 if (returnstat >= 0) {
571 571 /* try to allocate memory for the character string */
572 572 if ((charp = (char *)malloc(size * sizeof (char))) == NULL)
573 573 returnstat = -1;
574 574 else {
575 575 if ((returnstat = pr_adr_char(context, charp,
576 576 size)) == 0) {
577 577 /* print out in hexadecimal format */
578 578 uval.uvaltype = PRA_STRING;
579 579 uval.string_val = hexconvert(charp, size, size);
580 580 if (uval.string_val) {
581 581 returnstat = pa_print(context,
582 582 &uval, 1);
583 583 free(uval.string_val);
584 584 }
585 585 }
586 586 free(charp);
587 587 }
588 588 }
589 589
590 590 return (returnstat);
591 591 }
592 592
593 593 /*
594 594 * -----------------------------------------------------------------------
595 595 * path_token() : Process path token and display contents
596 596 * return codes : -1 - error
597 597 * : 0 - successful
598 598 * NOTE: At the time of call, the path token id has been retrieved
599 599 *
600 600 * Format of path token:
601 601 * token id adr_char
602 602 * path adr_string
603 603 * -----------------------------------------------------------------------
604 604 */
605 605 int
606 606 path_token(pr_context_t *context)
607 607 {
608 608 char *path; /* path */
609 609 char *apath; /* anchored path */
610 610 char *cpath; /* collapsed path */
611 611 short length;
612 612 int returnstat;
613 613 uval_t uval;
614 614
615 615 /*
616 616 * We need to know how much space to allocate for our string, so
617 617 * read the length first, then call pr_adr_char to read those bytes.
618 618 */
619 619 if (pr_adr_short(context, &length, 1) == 0) {
620 620 if ((path = (char *)malloc(length + 1)) == NULL) {
621 621 returnstat = -1;
622 622 } else if (pr_adr_char(context, path, length) == 0) {
623 623 path[length] = '\0';
624 624 uval.uvaltype = PRA_STRING;
625 625 if (*path != '/') {
626 626 apath = anchor_path(path);
627 627 free(path);
628 628 } else
629 629 apath = path;
630 630 cpath = collapse_path(apath);
631 631 uval.string_val = cpath;
632 632 returnstat = pa_print(context, &uval, 1);
633 633 free(cpath);
634 634 } else {
635 635 free(path);
636 636 returnstat = -1;
637 637 }
638 638 return (returnstat);
639 639 } else
640 640 return (-1);
641 641 }
642 642
643 643 /*
644 644 * anchor a path name with a slash
645 645 */
646 646 char *
647 647 anchor_path(char *sp)
648 648 {
649 649 char *dp; /* destination path */
650 650 char *tp; /* temporary path */
651 651 size_t len;
652 652
653 653 len = strlen(sp) + 2;
654 654 if ((dp = tp = (char *)calloc(1, len)) == (char *)0)
655 655 return ((char *)0);
656 656
657 657 *dp++ = '/';
658 658
659 659 (void) strlcpy(dp, sp, len);
660 660
661 661 return (tp);
662 662 }
663 663
664 664 /*
665 665 * copy path to collapsed path.
666 666 * collapsed path does not contain:
667 667 * successive slashes
668 668 * instances of dot-slash
669 669 * instances of dot-dot-slash
670 670 * passed path must be anchored with a '/'
671 671 */
672 672 char *
673 673 collapse_path(char *s)
674 674 {
675 675 int id; /* index of where we are in destination string */
676 676 int is; /* index of where we are in source string */
677 677 int slashseen; /* have we seen a slash */
678 678 int ls; /* length of source string */
679 679
680 680 ls = strlen(s) + 1;
681 681
682 682 slashseen = 0;
683 683 for (is = 0, id = 0; is < ls; is++) {
684 684 /* thats all folks, we've reached the end of input */
685 685 if (s[is] == '\0') {
686 686 if (id > 1 && s[id-1] == '/') {
687 687 --id;
688 688 }
689 689 s[id++] = '\0';
690 690 break;
691 691 }
692 692 /* previous character was a / */
693 693 if (slashseen) {
694 694 if (s[is] == '/')
695 695 continue; /* another slash, ignore it */
696 696 } else if (s[is] == '/') {
697 697 /* we see a /, just copy it and try again */
698 698 slashseen = 1;
699 699 s[id++] = '/';
700 700 continue;
701 701 }
702 702 /* /./ seen */
703 703 if (s[is] == '.' && s[is+1] == '/') {
704 704 is += 1;
705 705 continue;
706 706 }
707 707 /* XXX/. seen */
708 708 if (s[is] == '.' && s[is+1] == '\0') {
709 709 if (id > 1)
710 710 id--;
711 711 continue;
712 712 }
713 713 /* XXX/.. seen */
714 714 if (s[is] == '.' && s[is+1] == '.' && s[is+2] == '\0') {
715 715 is += 1;
716 716 if (id > 0)
717 717 id--;
718 718 while (id > 0 && s[--id] != '/')
719 719 continue;
720 720 id++;
721 721 continue;
722 722 }
723 723 /* XXX/../ seen */
724 724 if (s[is] == '.' && s[is+1] == '.' && s[is+2] == '/') {
725 725 is += 2;
726 726 if (id > 0)
727 727 id--;
728 728 while (id > 0 && s[--id] != '/')
729 729 continue;
730 730 id++;
731 731 continue;
732 732 }
733 733 while (is < ls && (s[id++] = s[is++]) != '/')
734 734 continue;
735 735 is--;
736 736 }
737 737 return (s);
738 738 }
739 739
740 740 /*
741 741 * -----------------------------------------------------------------------
742 742 * cmd_token() : Process cmd token and display contents
743 743 * return codes : -1 - error
744 744 * : 0 - successful
745 745 * NOTE: At the time of call, the cmd token id has been retrieved
746 746 *
747 747 * Format of command token:
748 748 * token id adr_char
749 749 * argc adr_short
750 750 * N*argv[i] adr_string (short, string)
751 751 * env cnt adr_short
752 752 * N*arge[i] adr_string (short, string)
753 753 * -----------------------------------------------------------------------
754 754 */
755 755 int
756 756 cmd_token(pr_context_t *context)
757 757 {
758 758 int returnstat;
759 759 short num;
760 760
761 761 returnstat = pr_adr_short(context, &num, 1);
762 762 if (returnstat < 0)
763 763 return (returnstat);
764 764
765 765 if (!(context->format & PRF_XMLM)) {
766 766 returnstat = pr_printf(context, "%s%s%d%s",
767 767 (context->format & PRF_ONELINE) ? "" : gettext("argcnt"),
768 768 (context->format & PRF_ONELINE) ? "" : context->SEPARATOR,
769 769 num, context->SEPARATOR);
770 770 if (returnstat < 0)
771 771 return (returnstat);
772 772 }
773 773
774 774 for (; num > 0; num--) {
775 775 if ((returnstat = process_tag(context, TAG_ARGV,
776 776 returnstat, 0)) < 0)
777 777 return (returnstat);
778 778 }
779 779
780 780 if ((returnstat = pr_adr_short(context, &num, 1)) < 0)
781 781 return (returnstat);
782 782
783 783 if (!(context->format & PRF_XMLM)) {
784 784 returnstat = pr_printf(context, "%s%s%d%s",
785 785 (context->format & PRF_ONELINE) ? "" : gettext("envcnt"),
786 786 (context->format & PRF_ONELINE) ? "" : context->SEPARATOR,
787 787 num, context->SEPARATOR);
788 788 if (returnstat < 0)
789 789 return (returnstat);
790 790 }
791 791
792 792 if ((num == 0) && !(context->format & PRF_XMLM)) {
793 793 returnstat = do_newline(context, 1);
794 794 if (returnstat < 0)
795 795 return (returnstat);
796 796 }
797 797
798 798 for (; num > 1; num--) {
799 799 if ((returnstat = process_tag(context, TAG_ARGE,
800 800 returnstat, 0)) < 0)
801 801 return (returnstat);
802 802 }
803 803 if (num)
804 804 returnstat = process_tag(context, TAG_ARGE, returnstat, 1);
805 805
806 806 return (returnstat);
807 807
808 808 }
809 809
810 810 /*
811 811 * -----------------------------------------------------------------------
812 812 * argument32_token() : Process argument token and display contents
813 813 * return codes : -1 - error
814 814 * : 0 - successful
815 815 * NOTE: At the time of call, the arg token id has been retrieved
816 816 *
817 817 * Format of argument token:
818 818 * current directory token id adr_char
819 819 * argument number adr_char
820 820 * argument value adr_int32
821 821 * argument description adr_string
822 822 * -----------------------------------------------------------------------
823 823 */
824 824 int
825 825 argument32_token(pr_context_t *context)
826 826 {
827 827 int returnstat;
828 828
829 829 returnstat = process_tag(context, TAG_ARGNUM, 0, 0);
830 830 returnstat = process_tag(context, TAG_ARGVAL32, returnstat, 0);
831 831 returnstat = process_tag(context, TAG_ARGDESC, returnstat, 1);
832 832
833 833 return (returnstat);
834 834
835 835 }
836 836
837 837 /*
838 838 * -----------------------------------------------------------------------
839 839 * argument64_token() : Process argument token and display contents
840 840 * return codes : -1 - error
841 841 * : 0 - successful
842 842 * NOTE: At the time of call, the arg token id has been retrieved
843 843 *
844 844 * Format of 64 bit argument token:
845 845 * current directory token id adr_char
846 846 * argument number adr_char
847 847 * argument value adr_int64
848 848 * argument description adr_string
849 849 * -----------------------------------------------------------------------
850 850 */
851 851 int
852 852 argument64_token(pr_context_t *context)
853 853 {
854 854 int returnstat;
855 855
856 856 returnstat = process_tag(context, TAG_ARGNUM, 0, 0);
857 857 returnstat = process_tag(context, TAG_ARGVAL64, returnstat, 0);
858 858 returnstat = process_tag(context, TAG_ARGDESC, returnstat, 1);
859 859
860 860 return (returnstat);
861 861
862 862 }
863 863
864 864 /*
865 865 * -----------------------------------------------------------------------
866 866 * process_token() : Process process token and display contents
867 867 * return codes : -1 - error
868 868 * : 0 - successful
869 869 * NOTE: At the time of call, the process token id has been retrieved
870 870 *
871 871 * Format of process token:
872 872 * process token id adr_char
873 873 * auid adr_u_int32
874 874 * euid adr_u_int32
875 875 * egid adr_u_int32
876 876 * ruid adr_u_int32
877 877 * egid adr_u_int32
878 878 * pid adr_u_int32
879 879 * sid adr_u_int32
880 880 * tid adr_u_int32, adr_u_int32
881 881 * -----------------------------------------------------------------------
882 882 */
883 883 int
884 884 process32_token(pr_context_t *context)
885 885 {
886 886 int returnstat;
887 887
888 888 /* auid */
889 889 returnstat = process_tag(context, TAG_AUID, 0, 0);
890 890 /* uid */
891 891 returnstat = process_tag(context, TAG_UID, returnstat, 0);
892 892 /* gid */
893 893 returnstat = process_tag(context, TAG_GID, returnstat, 0);
894 894 /* ruid */
895 895 returnstat = process_tag(context, TAG_RUID, returnstat, 0);
896 896 /* rgid */
897 897 returnstat = process_tag(context, TAG_RGID, returnstat, 0);
898 898 /* pid */
899 899 returnstat = process_tag(context, TAG_PID, returnstat, 0);
900 900 /* sid */
901 901 returnstat = process_tag(context, TAG_SID, returnstat, 0);
902 902 /* tid */
903 903 returnstat = process_tag(context, TAG_TID32, returnstat, 1);
904 904
905 905 return (returnstat);
906 906 }
907 907
908 908 int
909 909 process64_token(pr_context_t *context)
910 910 {
911 911 int returnstat;
912 912
913 913 /* auid */
914 914 returnstat = process_tag(context, TAG_AUID, 0, 0);
915 915 /* uid */
916 916 returnstat = process_tag(context, TAG_UID, returnstat, 0);
917 917 /* gid */
918 918 returnstat = process_tag(context, TAG_GID, returnstat, 0);
919 919 /* ruid */
920 920 returnstat = process_tag(context, TAG_RUID, returnstat, 0);
921 921 /* rgid */
922 922 returnstat = process_tag(context, TAG_RGID, returnstat, 0);
923 923 /* pid */
924 924 returnstat = process_tag(context, TAG_PID, returnstat, 0);
925 925 /* sid */
926 926 returnstat = process_tag(context, TAG_SID, returnstat, 0);
927 927 /* tid */
928 928 returnstat = process_tag(context, TAG_TID64, returnstat, 1);
929 929
930 930 return (returnstat);
931 931 }
932 932
933 933 /*
934 934 * -----------------------------------------------------------------------
935 935 * process_ex_token() : Process process token and display contents
936 936 * return codes : -1 - error
937 937 * : 0 - successful
938 938 * NOTE: At the time of call, the process token id has been retrieved
939 939 *
940 940 * Format of extended process token:
941 941 * process token id adr_char
942 942 * auid adr_u_int32
943 943 * euid adr_u_int32
944 944 * egid adr_u_int32
945 945 * ruid adr_u_int32
946 946 * egid adr_u_int32
947 947 * pid adr_u_int32
948 948 * sid adr_u_int32
949 949 * tid adr_u_int32, adr_u_int32, 4*adr_u_int32
950 950 * -----------------------------------------------------------------------
951 951 */
952 952 int
953 953 process32_ex_token(pr_context_t *context)
954 954 {
955 955 int returnstat;
956 956
957 957 /* auid */
958 958 returnstat = process_tag(context, TAG_AUID, 0, 0);
959 959 /* uid */
960 960 returnstat = process_tag(context, TAG_UID, returnstat, 0);
961 961 /* gid */
962 962 returnstat = process_tag(context, TAG_GID, returnstat, 0);
963 963 /* ruid */
964 964 returnstat = process_tag(context, TAG_RUID, returnstat, 0);
965 965 /* rgid */
966 966 returnstat = process_tag(context, TAG_RGID, returnstat, 0);
967 967 /* pid */
968 968 returnstat = process_tag(context, TAG_PID, returnstat, 0);
969 969 /* sid */
970 970 returnstat = process_tag(context, TAG_SID, returnstat, 0);
971 971 /* tid */
972 972 returnstat = process_tag(context, TAG_TID32_EX, returnstat, 1);
973 973
974 974 return (returnstat);
975 975 }
976 976
977 977 int
978 978 process64_ex_token(pr_context_t *context)
979 979 {
980 980 int returnstat;
981 981
982 982 /* auid */
983 983 returnstat = process_tag(context, TAG_AUID, 0, 0);
984 984 /* uid */
985 985 returnstat = process_tag(context, TAG_UID, returnstat, 0);
986 986 /* gid */
987 987 returnstat = process_tag(context, TAG_GID, returnstat, 0);
988 988 /* ruid */
989 989 returnstat = process_tag(context, TAG_RUID, returnstat, 0);
990 990 /* rgid */
991 991 returnstat = process_tag(context, TAG_RGID, returnstat, 0);
992 992 /* pid */
993 993 returnstat = process_tag(context, TAG_PID, returnstat, 0);
994 994 /* sid */
995 995 returnstat = process_tag(context, TAG_SID, returnstat, 0);
996 996 /* tid */
997 997 returnstat = process_tag(context, TAG_TID64_EX, returnstat, 1);
998 998
999 999 return (returnstat);
1000 1000 }
1001 1001
1002 1002 /*
1003 1003 * -----------------------------------------------------------------------
1004 1004 * return_value32_token(): Process return value and display contents
1005 1005 * return codes : -1 - error
1006 1006 * : 0 - successful
1007 1007 * NOTE: At the time of call, the return value token id has been retrieved
1008 1008 *
1009 1009 * Format of return value token:
1010 1010 * return value token id adr_char
1011 1011 * error number adr_char
1012 1012 * return value adr_int32
1013 1013 * -----------------------------------------------------------------------
1014 1014 */
1015 1015 int
1016 1016 return_value32_token(pr_context_t *context)
1017 1017 {
1018 1018 int returnstat;
1019 1019 uchar_t number;
1020 1020 int32_t value;
1021 1021 char pb[512]; /* print buffer */
1022 1022 uval_t uval;
1023 1023 bool_t used_ret_val = 0;
1024 1024
1025 1025 /*
1026 1026 * Every audit record generated contains a return token.
1027 1027 *
1028 1028 * The return token is a special token. It indicates the success
1029 1029 * or failure of the event that contains it.
1030 1030 * The return32 token contains two pieces of data:
1031 1031 *
1032 1032 * char number;
1033 1033 * int32_t return_value;
1034 1034 *
1035 1035 * For audit records generated by the kernel:
1036 1036 * The kernel always puts a positive value in "number".
1037 1037 * Upon success "number" is 0.
1038 1038 * Upon failure "number" is a positive errno value that is less than
1039 1039 * sys_nerr.
1040 1040 *
1041 1041 * For audit records generated at the user level:
1042 1042 * Upon success "number" is 0.
1043 1043 * Upon failure "number" is -1.
1044 1044 *
1045 1045 * For both kernel and user land the value of "return_value" is
1046 1046 * arbitrary. For the kernel it contains the return value of
1047 1047 * the system call. For user land it contains an arbitrary return
1048 1048 * value if it is less than ADT_FAIL_VALUE; ADT_FAIL_VALUE
1049 1049 * and above are messages defined in adt_event.h. ADT_FAIL_PAM and
1050 1050 * above are messages from pam_strerror(). No interpretation is done
1051 1051 * on "return_value" if it is outside the range of ADT_FAIL_VALUE_* or
1052 1052 * ADT_FAIL_PAM values.
1053 1053 */
1054 1054 if ((returnstat = open_tag(context, TAG_ERRVAL)) != 0)
1055 1055 return (returnstat);
1056 1056
1057 1057 if ((returnstat = pr_adr_u_char(context, &number, 1)) == 0) {
1058 1058 if (!(context->format & PRF_RAWM)) {
1059 1059 used_ret_val = 1;
1060 1060 pa_error(number, pb, sizeof (pb));
1061 1061 uval.uvaltype = PRA_STRING;
1062 1062 uval.string_val = pb;
1063 1063 if ((returnstat = pa_print(context, &uval, 0)) != 0)
1064 1064 return (returnstat);
1065 1065 if ((returnstat = close_tag(context, TAG_ERRVAL)) != 0)
1066 1066 return (returnstat);
1067 1067 if ((returnstat = open_tag(context, TAG_RETVAL)) != 0)
1068 1068 return (returnstat);
1069 1069
1070 1070 if ((returnstat = pr_adr_int32(
1071 1071 context, &value, 1)) != 0)
1072 1072 return (returnstat);
1073 1073
1074 1074 pa_retval(number, value, pb, sizeof (pb));
1075 1075 } else {
1076 1076 uval.uvaltype = PRA_INT32;
1077 1077 if ((char)number == -1)
1078 1078 uval.int32_val = -1;
1079 1079 else
1080 1080 uval.int32_val = number;
1081 1081 }
1082 1082 returnstat = pa_print(context, &uval, used_ret_val);
1083 1083 }
1084 1084 if (used_ret_val) {
1085 1085 if (returnstat == 0)
1086 1086 returnstat = close_tag(context, TAG_RETVAL);
1087 1087 return (returnstat);
1088 1088 }
1089 1089 if (!returnstat)
1090 1090 if (returnstat = close_tag(context, TAG_ERRVAL))
1091 1091 return (returnstat);
1092 1092
1093 1093 return (process_tag(context, TAG_RETVAL, returnstat, 1));
1094 1094 }
1095 1095
1096 1096 /*
1097 1097 * -----------------------------------------------------------------------
1098 1098 * return_value64_token(): Process return value and display contents
1099 1099 * return codes : -1 - error
1100 1100 * : 0 - successful
1101 1101 * NOTE: At the time of call, the return value token id has been retrieved
1102 1102 *
1103 1103 * Format of return value token:
1104 1104 * return value token id adr_char
1105 1105 * error number adr_char
1106 1106 * return value adr_int64
1107 1107 *
1108 1108 * HOWEVER, the 64 bit return value is a concatenation of two
1109 1109 * 32 bit return values; the first of which is the same as is
1110 1110 * carried in the return32 token. The second 32 bits are ignored
1111 1111 * here so that the displayed return token will have the same
1112 1112 * number whether the application is 32 or 64 bits.
1113 1113 * -----------------------------------------------------------------------
1114 1114 */
1115 1115 int
1116 1116 return_value64_token(pr_context_t *context)
1117 1117 {
1118 1118 int returnstat;
1119 1119 uchar_t number;
1120 1120 rval_t rval;
1121 1121 char pb[512]; /* print buffer */
1122 1122 uval_t uval;
1123 1123
1124 1124 /*
1125 1125 * Every audit record generated contains a return token.
1126 1126 *
1127 1127 * The return token is a special token. It indicates the success
1128 1128 * or failure of the event that contains it.
1129 1129 * The return64 token contains two pieces of data:
1130 1130 *
1131 1131 * char number;
1132 1132 * int64_t return_value;
1133 1133 *
1134 1134 * For audit records generated by the kernel:
1135 1135 * The kernel always puts a positive value in "number".
1136 1136 * Upon success "number" is 0.
1137 1137 * Upon failure "number" is a positive errno value that is less than
1138 1138 * sys_nerr.
1139 1139 *
1140 1140 * For audit records generated at the user level:
1141 1141 * Upon success "number" is 0.
1142 1142 * Upon failure "number" is -1.
1143 1143 *
1144 1144 * For both kernel and user land the value of "return_value" is
1145 1145 * arbitrary. For the kernel it contains the return value of
1146 1146 * the system call. For user land it contains an arbitrary return
1147 1147 * value if it is less than ADT_FAIL_VALUE; ADT_FAIL_VALUE
1148 1148 * and above are messages defined in adt_event.h. ADT_FAIL_PAM and
1149 1149 * above are messages from pam_strerror(). No interpretation is done
1150 1150 * on "return_value" if it is outside the range of ADT_FAIL_VALUE_* or
1151 1151 * ADT_FAIL_PAM values.
1152 1152 *
1153 1153 * The 64 bit return value consists of two 32bit parts; for
1154 1154 * system calls, the first part is the value returned by the
1155 1155 * system call and the second part depends on the system call
1156 1156 * implementation. In most cases, the second part is either 0
1157 1157 * or garbage; because of that, it is omitted from the praudit
1158 1158 * output.
1159 1159 */
1160 1160 if ((returnstat = open_tag(context, TAG_ERRVAL)) != 0)
1161 1161 return (returnstat);
1162 1162
1163 1163 if ((returnstat = pr_adr_u_char(context, &number, 1)) == 0) {
1164 1164 if (!(context->format & PRF_RAWM)) {
1165 1165 pa_error(number, pb, sizeof (pb));
1166 1166 uval.uvaltype = PRA_STRING;
1167 1167 uval.string_val = pb;
1168 1168 if ((returnstat = pa_print(context, &uval, 0)) != 0)
1169 1169 return (returnstat);
1170 1170
1171 1171 if ((returnstat = close_tag(context, TAG_ERRVAL)) != 0)
1172 1172 return (returnstat);
1173 1173 if ((returnstat = open_tag(context, TAG_RETVAL)) != 0)
1174 1174 return (returnstat);
1175 1175
1176 1176 if ((returnstat = pr_adr_int64(context,
1177 1177 &rval.r_vals, 1)) != 0)
1178 1178 return (returnstat);
1179 1179 pa_retval(number, rval.r_val1, pb, sizeof (pb));
1180 1180 } else {
1181 1181 uval.uvaltype = PRA_INT32;
1182 1182 if ((char)number == -1)
1183 1183 uval.int32_val = -1;
1184 1184 else
1185 1185 uval.int32_val = number;
1186 1186
1187 1187 if ((returnstat = pa_print(context, &uval, 0)) != 0)
1188 1188 return (returnstat);
1189 1189
1190 1190 if ((returnstat = close_tag(context, TAG_ERRVAL)) != 0)
1191 1191 return (returnstat);
1192 1192 if ((returnstat = open_tag(context, TAG_RETVAL)) != 0)
1193 1193 return (returnstat);
1194 1194
1195 1195 if ((returnstat = pr_adr_int64(context,
1196 1196 &rval.r_vals, 1)) != 0)
1197 1197 return (returnstat);
1198 1198 uval.int32_val = rval.r_val1;
1199 1199 }
1200 1200 returnstat = pa_print(context, &uval, 1);
1201 1201 } else {
1202 1202 return (returnstat);
1203 1203 }
1204 1204
1205 1205 if (returnstat == 0)
1206 1206 returnstat = close_tag(context, TAG_RETVAL);
1207 1207
1208 1208 return (returnstat);
1209 1209 }
1210 1210
1211 1211 /*
1212 1212 * -----------------------------------------------------------------------
1213 1213 * subject32_token() : Process subject token and display contents
1214 1214 * return codes : -1 - error
1215 1215 * : 0 - successful
1216 1216 * NOTE: At the time of call, the subject token id has been retrieved
1217 1217 *
1218 1218 * Format of subject token:
1219 1219 * subject token id adr_char
1220 1220 * auid adr_u_int32
1221 1221 * euid adr_u_int32
1222 1222 * egid adr_u_int32
1223 1223 * ruid adr_u_int32
1224 1224 * egid adr_u_int32
1225 1225 * pid adr_u_int32
1226 1226 * sid adr_u_int32
1227 1227 * tid adr_u_int32, adr_u_int32
1228 1228 * -----------------------------------------------------------------------
1229 1229 */
1230 1230 int
1231 1231 subject32_token(pr_context_t *context)
1232 1232 {
1233 1233 int returnstat;
1234 1234
1235 1235 /* auid */
1236 1236 returnstat = process_tag(context, TAG_AUID, 0, 0);
1237 1237 /* uid */
1238 1238 returnstat = process_tag(context, TAG_UID, returnstat, 0);
1239 1239 /* gid */
1240 1240 returnstat = process_tag(context, TAG_GID, returnstat, 0);
1241 1241 /* ruid */
1242 1242 returnstat = process_tag(context, TAG_RUID, returnstat, 0);
1243 1243 /* rgid */
1244 1244 returnstat = process_tag(context, TAG_RGID, returnstat, 0);
1245 1245 /* pid */
1246 1246 returnstat = process_tag(context, TAG_PID, returnstat, 0);
1247 1247 /* sid */
1248 1248 returnstat = process_tag(context, TAG_SID, returnstat, 0);
1249 1249 /* tid */
1250 1250 returnstat = process_tag(context, TAG_TID32, returnstat, 1);
1251 1251
1252 1252 return (returnstat);
1253 1253 }
1254 1254
1255 1255 int
1256 1256 subject64_token(pr_context_t *context)
1257 1257 {
1258 1258 int returnstat;
1259 1259
1260 1260 /* auid */
1261 1261 returnstat = process_tag(context, TAG_AUID, 0, 0);
1262 1262 /* uid */
1263 1263 returnstat = process_tag(context, TAG_UID, returnstat, 0);
1264 1264 /* gid */
1265 1265 returnstat = process_tag(context, TAG_GID, returnstat, 0);
1266 1266 /* ruid */
1267 1267 returnstat = process_tag(context, TAG_RUID, returnstat, 0);
1268 1268 /* rgid */
1269 1269 returnstat = process_tag(context, TAG_RGID, returnstat, 0);
1270 1270 /* pid */
1271 1271 returnstat = process_tag(context, TAG_PID, returnstat, 0);
1272 1272 /* sid */
1273 1273 returnstat = process_tag(context, TAG_SID, returnstat, 0);
1274 1274 /* tid */
1275 1275 returnstat = process_tag(context, TAG_TID64, returnstat, 1);
1276 1276
1277 1277 return (returnstat);
1278 1278 }
1279 1279
1280 1280 /*
1281 1281 * -----------------------------------------------------------------------
1282 1282 * subject_ex_token(): Process subject token and display contents
1283 1283 * return codes : -1 - error
1284 1284 * : 0 - successful
1285 1285 * NOTE: At the time of call, the subject token id has been retrieved
1286 1286 *
1287 1287 * Format of extended subject token:
1288 1288 * subject token id adr_char
1289 1289 * auid adr_u_int32
1290 1290 * euid adr_u_int32
1291 1291 * egid adr_u_int32
1292 1292 * ruid adr_u_int32
1293 1293 * egid adr_u_int32
1294 1294 * pid adr_u_int32
1295 1295 * sid adr_u_int32
1296 1296 * tid adr_u_int32, adr_u_int32
1297 1297 * -----------------------------------------------------------------------
1298 1298 */
1299 1299 int
1300 1300 subject32_ex_token(pr_context_t *context)
1301 1301 {
1302 1302 int returnstat;
1303 1303
1304 1304 /* auid */
1305 1305 returnstat = process_tag(context, TAG_AUID, 0, 0);
1306 1306 /* uid */
1307 1307 returnstat = process_tag(context, TAG_UID, returnstat, 0);
1308 1308 /* gid */
1309 1309 returnstat = process_tag(context, TAG_GID, returnstat, 0);
1310 1310 /* ruid */
1311 1311 returnstat = process_tag(context, TAG_RUID, returnstat, 0);
1312 1312 /* rgid */
1313 1313 returnstat = process_tag(context, TAG_RGID, returnstat, 0);
1314 1314 /* pid */
1315 1315 returnstat = process_tag(context, TAG_PID, returnstat, 0);
1316 1316 /* sid */
1317 1317 returnstat = process_tag(context, TAG_SID, returnstat, 0);
1318 1318 /* tid */
1319 1319 returnstat = process_tag(context, TAG_TID32_EX, returnstat, 1);
1320 1320
1321 1321 return (returnstat);
1322 1322 }
1323 1323
1324 1324 int
1325 1325 subject64_ex_token(pr_context_t *context)
1326 1326 {
1327 1327 int returnstat;
1328 1328
1329 1329 /* auid */
1330 1330 returnstat = process_tag(context, TAG_AUID, 0, 0);
1331 1331 /* uid */
1332 1332 returnstat = process_tag(context, TAG_UID, returnstat, 0);
1333 1333 /* gid */
1334 1334 returnstat = process_tag(context, TAG_GID, returnstat, 0);
1335 1335 /* ruid */
1336 1336 returnstat = process_tag(context, TAG_RUID, returnstat, 0);
1337 1337 /* rgid */
1338 1338 returnstat = process_tag(context, TAG_RGID, returnstat, 0);
1339 1339 /* pid */
1340 1340 returnstat = process_tag(context, TAG_PID, returnstat, 0);
1341 1341 /* sid */
1342 1342 returnstat = process_tag(context, TAG_SID, returnstat, 0);
1343 1343 /* tid */
1344 1344 returnstat = process_tag(context, TAG_TID64_EX, returnstat, 1);
1345 1345
1346 1346 return (returnstat);
1347 1347 }
1348 1348
1349 1349 /*
1350 1350 * -----------------------------------------------------------------------
1351 1351 * s5_IPC_token() : Process System V IPC token and display contents
1352 1352 * return codes : -1 - error
1353 1353 * : 0 - successful
1354 1354 * NOTE: At the time of call, the System V IPC id has been retrieved
1355 1355 *
1356 1356 * Format of System V IPC token:
1357 1357 * System V IPC token id adr_char
1358 1358 * object id adr_int32
1359 1359 * -----------------------------------------------------------------------
1360 1360 */
1361 1361 int
1362 1362 s5_IPC_token(pr_context_t *context)
1363 1363 {
1364 1364 int returnstat;
1365 1365 uchar_t ipctype;
1366 1366 uval_t uval;
1367 1367
1368 1368 /*
1369 1369 * TRANSLATION_NOTE
1370 1370 * These names refer to the type of System V IPC object:
1371 1371 * message queue, semaphore, shared memory.
1372 1372 */
1373 1373
1374 1374 if (pr_adr_u_char(context, &ipctype, 1) == 0) {
1375 1375 if ((returnstat = open_tag(context, TAG_IPCTYPE)) != 0)
1376 1376 return (returnstat);
1377 1377
1378 1378 if (!(context->format & PRF_RAWM)) {
1379 1379 /* print in ASCII form */
1380 1380 uval.uvaltype = PRA_STRING;
1381 1381 switch (ipctype) {
1382 1382 case AT_IPC_MSG:
1383 1383 uval.string_val = gettext("msg");
1384 1384 break;
1385 1385 case AT_IPC_SEM:
1386 1386 uval.string_val = gettext("sem");
1387 1387 break;
1388 1388 case AT_IPC_SHM:
1389 1389 uval.string_val = gettext("shm");
1390 1390 break;
1391 1391 }
1392 1392 returnstat = pa_print(context, &uval, 0);
1393 1393 }
1394 1394 /* print in integer form */
1395 1395 if ((context->format & PRF_RAWM) || (returnstat == 1)) {
1396 1396 uval.uvaltype = PRA_BYTE;
1397 1397 uval.char_val = ipctype;
1398 1398 returnstat = pa_print(context, &uval, 0);
1399 1399 }
1400 1400 if ((returnstat = close_tag(context, TAG_IPCTYPE)) != 0)
1401 1401 return (returnstat);
1402 1402
1403 1403 /* next get and print ipc id */
1404 1404 return (process_tag(context, TAG_IPCID, returnstat, 1));
1405 1405 } else {
1406 1406 /* cannot retrieve ipc type */
1407 1407 return (-1);
1408 1408 }
1409 1409 }
1410 1410
1411 1411 /*
1412 1412 * -----------------------------------------------------------------------
1413 1413 * text_token() : Process text token and display contents
1414 1414 * return codes : -1 - error
1415 1415 * : 0 - successful
1416 1416 * NOTE: At the time of call, the text token id has been retrieved
1417 1417 *
1418 1418 * Format of text token:
1419 1419 * text token id adr_char
1420 1420 * text adr_string
1421 1421 * -----------------------------------------------------------------------
1422 1422 */
1423 1423 int
1424 1424 text_token(pr_context_t *context)
1425 1425 {
1426 1426 return (pa_adr_string(context, 0, 1));
1427 1427 }
1428 1428
1429 1429 /*
1430 1430 * -----------------------------------------------------------------------
1431 1431 * tid_token() : Process a generic terminal id token / AUT_TID
1432 1432 * return codes : -1 - error
1433 1433 * : 0 - successful
1434 1434 * NOTE: At the time of call, the token id has been retrieved
1435 1435 *
1436 1436 * Format of tid token:
1437 1437 * ip token id adr_char
1438 1438 * terminal type adr_char
1439 1439 * terminal type = AU_IPADR:
1440 1440 * remote port: adr_short
1441 1441 * local port: adr_short
1442 1442 * IP type: adt_int32 -- AU_IPv4 or AU_IPv6
1443 1443 * address: adr_int32 if IPv4, else 4 * adr_int32
1444 1444 * -----------------------------------------------------------------------
1445 1445 */
1446 1446 int
1447 1447 tid_token(pr_context_t *context)
1448 1448 {
1449 1449 int returnstat;
1450 1450 uchar_t type;
1451 1451 uval_t uval;
1452 1452
1453 1453 if ((returnstat = pr_adr_u_char(context, &type, 1)) != 0)
1454 1454 return (returnstat);
1455 1455 uval.uvaltype = PRA_STRING;
1456 1456 if ((returnstat = open_tag(context, TAG_TID_TYPE)) != 0)
1457 1457 return (returnstat);
1458 1458
1459 1459 switch (type) {
1460 1460 default:
1461 1461 return (-1); /* other than IP type is not implemented */
1462 1462 case AU_IPADR:
1463 1463 uval.string_val = "ip";
1464 1464 returnstat = pa_print(context, &uval, 0);
1465 1465 returnstat = close_tag(context, TAG_TID_TYPE);
1466 1466 returnstat = open_tag(context, TAG_IP);
1467 1467 returnstat = process_tag(context, TAG_IP_REMOTE, returnstat, 0);
1468 1468 returnstat = process_tag(context, TAG_IP_LOCAL, returnstat, 0);
1469 1469 returnstat = process_tag(context, TAG_IP_ADR, returnstat, 1);
1470 1470 returnstat = close_tag(context, TAG_IP);
1471 1471 break;
1472 1472 }
1473 1473 return (returnstat);
1474 1474 }
1475 1475
1476 1476 /*
1477 1477 * -----------------------------------------------------------------------
1478 1478 * ip_addr_token() : Process ip token and display contents
1479 1479 * return codes : -1 - error
1480 1480 * : 0 - successful
1481 1481 * NOTE: At the time of call, the ip token id has been retrieved
1482 1482 *
1483 1483 * Format of ip address token:
1484 1484 * ip token id adr_char
1485 1485 * address adr_int32 (printed in hex)
1486 1486 * -----------------------------------------------------------------------
1487 1487 */
1488 1488
1489 1489 int
1490 1490 ip_addr_token(pr_context_t *context)
1491 1491 {
1492 1492 return (pa_hostname(context, 0, 1));
1493 1493 }
1494 1494
1495 1495 int
1496 1496 ip_addr_ex_token(pr_context_t *context)
1497 1497 {
1498 1498 int returnstat;
1499 1499 uint32_t ip_addr[16];
1500 1500 uint32_t ip_type;
1501 1501 struct in_addr ia;
1502 1502 char *ipstring;
1503 1503 char buf[256];
1504 1504 uval_t uval;
1505 1505
1506 1506 /* get address type */
1507 1507 if ((returnstat = pr_adr_u_int32(context, &ip_type, 1)) != 0)
1508 1508 return (returnstat);
1509 1509
1510 1510 /* legal address types are either AU_IPv4 or AU_IPv6 only */
1511 1511 if ((ip_type != AU_IPv4) && (ip_type != AU_IPv6))
1512 1512 return (-1);
1513 1513
1514 1514 /* get address (4/16) */
1515 1515 if ((returnstat = pr_adr_char(context, (char *)ip_addr, ip_type)) != 0)
1516 1516 return (returnstat);
1517 1517
1518 1518 uval.uvaltype = PRA_STRING;
1519 1519 if (ip_type == AU_IPv4) {
1520 1520 uval.string_val = buf;
1521 1521
1522 1522 if (!(context->format & PRF_RAWM)) {
1523 1523 get_Hname(ip_addr[0], buf, sizeof (buf));
1524 1524 return (pa_print(context, &uval, 1));
1525 1525 }
1526 1526
1527 1527 ia.s_addr = ip_addr[0];
1528 1528 if ((ipstring = inet_ntoa(ia)) == NULL)
1529 1529 return (-1);
1530 1530
1531 1531 (void) snprintf(buf, sizeof (buf), "%s", ipstring);
1532 1532
1533 1533 } else {
1534 1534 uval.string_val = buf;
1535 1535
1536 1536 if (!(context->format & PRF_RAWM)) {
1537 1537 get_Hname_ex(ip_addr, buf, sizeof (buf));
1538 1538 return (pa_print(context, &uval, 1));
1539 1539 }
1540 1540
1541 1541 (void) inet_ntop(AF_INET6, (void *) ip_addr, buf,
1542 1542 sizeof (buf));
1543 1543
1544 1544 }
1545 1545
1546 1546 return (pa_print(context, &uval, 1));
1547 1547 }
1548 1548
1549 1549 /*
1550 1550 * -----------------------------------------------------------------------
1551 1551 * ip_token() : Process ip header token and display contents
1552 1552 * return codes : -1 - error
1553 1553 * : 0 - successful
1554 1554 * NOTE: At the time of call, the ip token id has been retrieved
1555 1555 *
1556 1556 * Format of ip header token:
1557 1557 * ip header token id adr_char
1558 1558 * version adr_char (printed in hex)
1559 1559 * type of service adr_char (printed in hex)
1560 1560 * length adr_short
1561 1561 * id adr_u_short
1562 1562 * offset adr_u_short
1563 1563 * ttl adr_char (printed in hex)
1564 1564 * protocol adr_char (printed in hex)
1565 1565 * checksum adr_u_short
1566 1566 * source address adr_int32 (printed in hex)
1567 1567 * destination address adr_int32 (printed in hex)
1568 1568 * -----------------------------------------------------------------------
1569 1569 */
1570 1570 int
1571 1571 ip_token(pr_context_t *context)
1572 1572 {
1573 1573 int returnstat;
1574 1574
1575 1575 returnstat = process_tag(context, TAG_IPVERS, 0, 0);
1576 1576 returnstat = process_tag(context, TAG_IPSERV, returnstat, 0);
1577 1577 returnstat = process_tag(context, TAG_IPLEN, returnstat, 0);
1578 1578 returnstat = process_tag(context, TAG_IPID, returnstat, 0);
1579 1579 returnstat = process_tag(context, TAG_IPOFFS, returnstat, 0);
1580 1580 returnstat = process_tag(context, TAG_IPTTL, returnstat, 0);
1581 1581 returnstat = process_tag(context, TAG_IPPROTO, returnstat, 0);
1582 1582 returnstat = process_tag(context, TAG_IPCKSUM, returnstat, 0);
1583 1583 returnstat = process_tag(context, TAG_IPSRC, returnstat, 0);
1584 1584 returnstat = process_tag(context, TAG_IPDEST, returnstat, 1);
1585 1585
1586 1586 return (returnstat);
1587 1587 }
1588 1588
1589 1589 /*
1590 1590 * -----------------------------------------------------------------------
1591 1591 * iport_token() : Process ip port address token and display contents
1592 1592 * return codes : -1 - error
1593 1593 * : 0 - successful
1594 1594 * NOTE: At time of call, the ip port address token id has been retrieved
1595 1595 *
1596 1596 * Format of ip port token:
1597 1597 * ip port address token id adr_char
1598 1598 * port address adr_short (in_port_t == uint16_t)
1599 1599 * -----------------------------------------------------------------------
1600 1600 */
1601 1601 int
1602 1602 iport_token(pr_context_t *context)
1603 1603 {
1604 1604 return (pa_adr_u_short(context, 0, 1));
1605 1605 }
1606 1606
1607 1607 /*
1608 1608 * -----------------------------------------------------------------------
1609 1609 * socket_token() : Process socket token and display contents
1610 1610 * return codes : -1 - error
1611 1611 * : 0 - successful
1612 1612 * NOTE: At time of call, the socket token id has been retrieved
1613 1613 *
1614 1614 * Format of socket token:
1615 1615 * ip socket token id adr_char
1616 1616 * socket type adr_short (in hex)
1617 1617 * foreign port adr_short (in hex)
1618 1618 * foreign internet address adr_hostname/adr_int32 (in ascii/hex)
1619 1619 * -----------------------------------------------------------------------
1620 1620 *
1621 1621 * Note: local port and local internet address have been removed for 5.x
1622 1622 */
1623 1623 int
1624 1624 socket_token(pr_context_t *context)
1625 1625 {
1626 1626 int returnstat;
1627 1627
1628 1628 returnstat = process_tag(context, TAG_SOCKTYPE, 0, 0);
1629 1629 returnstat = process_tag(context, TAG_SOCKPORT, returnstat, 0);
1630 1630 if (returnstat != 0)
1631 1631 return (returnstat);
1632 1632
1633 1633 if ((returnstat = open_tag(context, TAG_SOCKADDR)) != 0)
1634 1634 return (returnstat);
1635 1635
1636 1636 if ((returnstat = pa_hostname(context, returnstat, 1)) != 0)
1637 1637 return (returnstat);
1638 1638
1639 1639 return (close_tag(context, TAG_SOCKADDR));
1640 1640 }
1641 1641
1642 1642 /*
1643 1643 * -----------------------------------------------------------------------
1644 1644 * socket_ex_token() : Process socket token and display contents
1645 1645 * return codes : -1 - error
1646 1646 * : 0 - successful
1647 1647 * NOTE: At time of call, the extended socket token id has been retrieved
1648 1648 *
1649 1649 * Format of extended socket token:
1650 1650 * token id adr_char
1651 1651 * socket domain adr_short (in hex)
1652 1652 * socket type adr_short (in hex)
1653 1653 * IP address type adr_short (in hex) [not displayed]
1654 1654 * local port adr_short (in hex)
1655 1655 * local internet address adr_hostname/adr_int32 (in ascii/hex)
1656 1656 * foreign port adr_short (in hex)
1657 1657 * foreign internet address adr_hostname/adr_int32 (in ascii/hex)
1658 1658 * -----------------------------------------------------------------------
1659 1659 *
1660 1660 * Note: local port and local internet address have been removed for 5.x
1661 1661 */
1662 1662 int
1663 1663 socket_ex_token(pr_context_t *context)
1664 1664 {
1665 1665 int returnstat;
1666 1666
1667 1667 returnstat = process_tag(context, TAG_SOCKEXDOM, 0, 0);
1668 1668 returnstat = process_tag(context, TAG_SOCKEXTYPE, returnstat, 0);
1669 1669 returnstat = pa_hostname_so(context, returnstat, 1);
1670 1670
1671 1671 return (returnstat);
1672 1672 }
1673 1673
1674 1674 /*
1675 1675 * -----------------------------------------------------------------------
1676 1676 * sequence_token() : Process sequence token and display contents
1677 1677 * return codes : -1 - error
1678 1678 * : 0 - successful
1679 1679 * NOTE: At time of call, the socket token id has been retrieved
1680 1680 *
1681 1681 * Format of sequence token:
1682 1682 * sequence token id adr_char
1683 1683 * sequence number adr_u_int32 (in hex)
1684 1684 * -----------------------------------------------------------------------
1685 1685 */
1686 1686 int
1687 1687 sequence_token(pr_context_t *context)
1688 1688 {
1689 1689 return (process_tag(context, TAG_SEQNUM, 0, 1));
1690 1690 }
1691 1691
1692 1692 /*
1693 1693 * -----------------------------------------------------------------------
1694 1694 * acl_token() : Process access control list term
1695 1695 * return codes : -1 - error
1696 1696 * : 0 - successful
1697 1697 *
1698 1698 * Format of acl token:
1699 1699 * token id adr_char
1700 1700 * term type adr_u_int32
1701 1701 * term value adr_u_int32 (depends on type)
1702 1702 * file mode adr_u_int (in octal)
1703 1703 * -----------------------------------------------------------------------
1704 1704 */
1705 1705 int
1706 1706 acl_token(pr_context_t *context)
1707 1707 {
1708 1708 int returnstat;
1709 1709
1710 1710 returnstat = pa_pw_uid_gr_gid(context, 0, 0);
1711 1711
1712 1712 return (process_tag(context, TAG_MODE, returnstat, 1));
1713 1713 }
1714 1714
1715 1715 /*
1716 1716 * -----------------------------------------------------------------------
1717 1717 * ace_token() : Process ZFS/NFSv4 access control list term
1718 1718 * return codes : -1 - error
1719 1719 * : 0 - successful
1720 1720 *
1721 1721 * Format of ace token:
1722 1722 * token id adr_char
1723 1723 * term who adr_u_int32 (uid/gid)
1724 1724 * term mask adr_u_int32
1725 1725 * term flags adr_u_int16
1726 1726 * term type adr_u_int16
1727 1727 * -----------------------------------------------------------------------
1728 1728 */
1729 1729 int
1730 1730 ace_token(pr_context_t *context)
1731 1731 {
1732 1732 return (pa_ace(context, 0, 1));
1733 1733 }
1734 1734
1735 1735 /*
1736 1736 * -----------------------------------------------------------------------
1737 1737 * attribute_token() : Process attribute token and display contents
1738 1738 * return codes : -1 - error
1739 1739 * : 0 - successful
1740 1740 * NOTE: At the time of call, the attribute token id has been retrieved
1741 1741 *
1742 1742 * Format of attribute token:
1743 1743 * attribute token id adr_char
1744 1744 * mode adr_u_int (printed in octal)
1745 1745 * uid adr_u_int
1746 1746 * gid adr_u_int
1747 1747 * file system id adr_int
1748 1748 *
1749 1749 * node id adr_int (attribute_token
1750 1750 * pre SunOS 5.7)
1751 1751 * device adr_u_int
1752 1752 * or
1753 1753 * node id adr_int64 (attribute32_token)
1754 1754 * device adr_u_int
1755 1755 * or
1756 1756 * node id adr_int64 (attribute64_token)
1757 1757 * device adr_u_int64
1758 1758 * -----------------------------------------------------------------------
1759 1759 */
1760 1760 int
1761 1761 attribute_token(pr_context_t *context)
1762 1762 {
1763 1763 int returnstat;
1764 1764
1765 1765 returnstat = process_tag(context, TAG_MODE, 0, 0);
1766 1766 returnstat = process_tag(context, TAG_UID, returnstat, 0);
1767 1767 returnstat = process_tag(context, TAG_GID, returnstat, 0);
1768 1768 returnstat = process_tag(context, TAG_FSID, returnstat, 0);
1769 1769 returnstat = process_tag(context, TAG_NODEID32, returnstat, 0);
1770 1770 returnstat = process_tag(context, TAG_DEVICE32, returnstat, 1);
1771 1771
1772 1772 return (returnstat);
1773 1773 }
1774 1774
1775 1775 int
1776 1776 attribute32_token(pr_context_t *context)
1777 1777 {
1778 1778 int returnstat;
1779 1779
1780 1780 returnstat = process_tag(context, TAG_MODE, 0, 0);
1781 1781 returnstat = process_tag(context, TAG_UID, returnstat, 0);
1782 1782 returnstat = process_tag(context, TAG_GID, returnstat, 0);
1783 1783 returnstat = process_tag(context, TAG_FSID, returnstat, 0);
1784 1784 returnstat = process_tag(context, TAG_NODEID64, returnstat, 0);
1785 1785 returnstat = process_tag(context, TAG_DEVICE32, returnstat, 1);
1786 1786
1787 1787 return (returnstat);
1788 1788 }
1789 1789
1790 1790 int
1791 1791 attribute64_token(pr_context_t *context)
1792 1792 {
1793 1793 int returnstat;
1794 1794
1795 1795 returnstat = process_tag(context, TAG_MODE, 0, 0);
1796 1796 returnstat = process_tag(context, TAG_UID, returnstat, 0);
1797 1797 returnstat = process_tag(context, TAG_GID, returnstat, 0);
1798 1798 returnstat = process_tag(context, TAG_FSID, returnstat, 0);
1799 1799 returnstat = process_tag(context, TAG_NODEID64, returnstat, 0);
1800 1800 returnstat = process_tag(context, TAG_DEVICE64, returnstat, 1);
1801 1801
1802 1802 return (returnstat);
1803 1803 }
1804 1804
1805 1805 /*
1806 1806 * -----------------------------------------------------------------------
1807 1807 * group_token() : Process group token and display contents
1808 1808 * return codes : -1 - error
1809 1809 * : 0 - successful
1810 1810 * NOTE: At the time of call, the group token id has been retrieved
1811 1811 * NOTE: This token is obsolete; it supports exactly NGROUPS_MAX
1812 1812 * groups.
1813 1813 *
1814 1814 * Format of group token:
1815 1815 * group token id adr_char
1816 1816 * group list adr_long, 16 times
1817 1817 * -----------------------------------------------------------------------
1818 1818 */
1819 1819 int
1820 1820 group_token(pr_context_t *context)
1821 1821 {
1822 1822 int returnstat = 0;
1823 1823 int i;
1824 1824
1825 1825 for (i = 0; i < NGROUPS_MAX - 1; i++) {
1826 1826 if ((returnstat = process_tag(context, TAG_GROUPID,
1827 1827 returnstat, 0)) < 0)
1828 1828 return (returnstat);
1829 1829 }
1830 1830
1831 1831 return (process_tag(context, TAG_GROUPID, returnstat, 1));
1832 1832 }
1833 1833
1834 1834 /*
1835 1835 * -----------------------------------------------------------------------
1836 1836 * newgroup_token() : Process group token and display contents
1837 1837 * return codes : -1 - error
1838 1838 * : 0 - successful
1839 1839 * NOTE: At the time of call, the group token id has been retrieved
1840 1840 *
1841 1841 * Format of new group token:
1842 1842 * group token id adr_char
1843 1843 * group number adr_short
1844 1844 * group list adr_int32, group number times
1845 1845 * -----------------------------------------------------------------------
1846 1846 */
1847 1847 int
1848 1848 newgroup_token(pr_context_t *context)
1849 1849 {
1850 1850 int returnstat;
1851 1851 int i, num;
1852 1852 short n_groups;
1853 1853
1854 1854 returnstat = pr_adr_short(context, &n_groups, 1);
1855 1855 if (returnstat != 0)
1856 1856 return (returnstat);
1857 1857
1858 1858 num = (int)n_groups;
1859 1859 if (num == 0) {
1860 1860 if (!(context->format & PRF_XMLM)) {
1861 1861 returnstat = do_newline(context, 1);
1862 1862 }
1863 1863 return (returnstat);
1864 1864 }
1865 1865 for (i = 0; i < num - 1; i++) {
1866 1866 if ((returnstat = process_tag(context, TAG_GROUPID,
1867 1867 returnstat, 0)) < 0)
1868 1868 return (returnstat);
1869 1869 }
1870 1870
1871 1871 return (process_tag(context, TAG_GROUPID, returnstat, 1));
1872 1872 }
1873 1873
1874 1874 static int
1875 1875 string_token_common(pr_context_t *context, int tag)
1876 1876 {
1877 1877 int returnstat;
1878 1878 int num;
1879 1879
1880 1880 returnstat = pr_adr_int32(context, (int32_t *)&num, 1);
1881 1881 if (returnstat != 0)
1882 1882 return (returnstat);
1883 1883
1884 1884 if (!(context->format & PRF_XMLM)) {
1885 1885 returnstat = pr_printf(context, "%d%s", num,
1886 1886 context->SEPARATOR);
1887 1887 if (returnstat != 0)
1888 1888 return (returnstat);
1889 1889 }
1890 1890
1891 1891 if (num == 0)
1892 1892 return (do_newline(context, 1));
1893 1893
1894 1894 for (; num > 1; num--) {
1895 1895 if ((returnstat = (process_tag(context, tag,
1896 1896 returnstat, 0))) < 0)
1897 1897 return (returnstat);
1898 1898 }
1899 1899
1900 1900 return (process_tag(context, tag, returnstat, 1));
1901 1901 }
1902 1902
1903 1903 int
1904 1904 path_attr_token(pr_context_t *context)
1905 1905 {
1906 1906 return (string_token_common(context, TAG_XAT));
1907 1907 }
1908 1908
1909 1909 int
1910 1910 exec_args_token(pr_context_t *context)
1911 1911 {
1912 1912 return (string_token_common(context, TAG_ARG));
1913 1913 }
1914 1914
1915 1915 int
1916 1916 exec_env_token(pr_context_t *context)
1917 1917 {
1918 1918 return (string_token_common(context, TAG_ENV));
1919 1919 }
1920 1920
1921 1921 /*
1922 1922 * -----------------------------------------------------------------------
1923 1923 * s5_IPC_perm_token() : Process System V IPC permission token and display
1924 1924 * contents
1925 1925 * return codes : -1 - error
1926 1926 * : 0 - successful
1927 1927 * NOTE: At the time of call, the System V IPC permission token id
1928 1928 * has been retrieved
1929 1929 *
1930 1930 * Format of System V IPC permission token:
1931 1931 * System V IPC permission token id adr_char
1932 1932 * uid adr_u_int32
1933 1933 * gid adr_u_int32
1934 1934 * cuid adr_u_int32
1935 1935 * cgid adr_u_int32
1936 1936 * mode adr_u_int32
1937 1937 * seq adr_u_int32
1938 1938 * key adr_int32
1939 1939 * -----------------------------------------------------------------------
1940 1940 */
1941 1941 int
1942 1942 s5_IPC_perm_token(pr_context_t *context)
1943 1943 {
1944 1944 int returnstat;
1945 1945
1946 1946 returnstat = process_tag(context, TAG_UID, 0, 0);
1947 1947 returnstat = process_tag(context, TAG_GID, returnstat, 0);
1948 1948 returnstat = process_tag(context, TAG_CUID, returnstat, 0);
1949 1949 returnstat = process_tag(context, TAG_CGID, returnstat, 0);
1950 1950 returnstat = process_tag(context, TAG_MODE, returnstat, 0);
1951 1951 returnstat = process_tag(context, TAG_SEQ, returnstat, 0);
1952 1952 returnstat = process_tag(context, TAG_KEY, returnstat, 1);
1953 1953
1954 1954 return (returnstat);
1955 1955 }
1956 1956
1957 1957 /*
1958 1958 * -----------------------------------------------------------------------
1959 1959 * host_token() : Process host token and display contents
1960 1960 * return codes : -1 - error
1961 1961 * : 0 - successful
1962 1962 * NOTE: At the time of call, the host token id has been retrieved
1963 1963 *
1964 1964 * Format of host token:
1965 1965 * host token id adr_char
1966 1966 * hostid adr_u_int32
1967 1967 * -----------------------------------------------------------------------
1968 1968 */
1969 1969 int
1970 1970 host_token(pr_context_t *context)
1971 1971 {
1972 1972 return (pa_hostname(context, 0, 1));
1973 1973 }
1974 1974
1975 1975 /*
1976 1976 * -----------------------------------------------------------------------
1977 1977 * liaison_token() : Process liaison token and display contents
1978 1978 * return codes : -1 - error
1979 1979 * : 0 - successful
1980 1980 * NOTE: At the time of call, the liaison token id has been retrieved
1981 1981 *
1982 1982 * Format of liaison token:
1983 1983 * liaison token id adr_char
1984 1984 * liaison adr_u_int32
1985 1985 * -----------------------------------------------------------------------
1986 1986 */
1987 1987 int
1988 1988 liaison_token(pr_context_t *context)
1989 1989 {
1990 1990 return (pa_liaison(context, 0, 1));
1991 1991 }
1992 1992
1993 1993 /*
1994 1994 * -----------------------------------------------------------------------
1995 1995 * useofauth_token(): Process useofauth token and display contents
1996 1996 * return codes : -1 - error
1997 1997 * : 0 - successful
1998 1998 * NOTE: At the time of call, the uauth token id has been retrieved
1999 1999 *
2000 2000 * Format of useofauth token:
2001 2001 * uauth token id adr_char
2002 2002 * uauth adr_string
2003 2003 * -----------------------------------------------------------------------
2004 2004 */
2005 2005 int
2006 2006 useofauth_token(pr_context_t *context)
2007 2007 {
2008 2008 return (pa_adr_string(context, 0, 1));
2009 2009 }
2010 2010
2011 2011 /*
2012 2012 * -----------------------------------------------------------------------
2013 2013 * user_token(): Process user token and display contents
2014 2014 * return codes : -1 - error
2015 2015 * : 0 - successful
2016 2016 * NOTE: At the time of call, the user token id has been retrieved
2017 2017 *
2018 2018 * Format of user token:
2019 2019 * user token id adr_char
2020 2020 * user id adr_uid
2021 2021 * user name adr_string
2022 2022 * -----------------------------------------------------------------------
2023 2023 */
2024 2024 int
2025 2025 user_token(pr_context_t *context)
2026 2026 {
2027 2027 int returnstat;
2028 2028
2029 2029 returnstat = process_tag(context, TAG_UID, 0, 0);
2030 2030 return (process_tag(context, TAG_USERNAME, returnstat, 1));
2031 2031 }
2032 2032
2033 2033 /*
2034 2034 * -----------------------------------------------------------------------
2035 2035 * zonename_token(): Process zonename token and display contents
2036 2036 * return codes : -1 - error
2037 2037 * : 0 - successful
2038 2038 * NOTE: At the time of call, the zonename token id has been retrieved
2039 2039 *
2040 2040 * Format of zonename token:
2041 2041 * zonename token id adr_char
2042 2042 * zone name adr_string
2043 2043 * -----------------------------------------------------------------------
2044 2044 */
2045 2045 int
2046 2046 zonename_token(pr_context_t *context)
2047 2047 {
2048 2048 return (process_tag(context, TAG_ZONENAME, 0, 1));
2049 2049 }
2050 2050
2051 2051 /*
2052 2052 * -----------------------------------------------------------------------
2053 2053 * fmri_token(): Process fmri token and display contents
2054 2054 * return codes : -1 - error
2055 2055 * : 0 - successful
2056 2056 * NOTE: At the time of call, the fmri token id has been retrieved
2057 2057 *
2058 2058 * Format of fmri token:
2059 2059 * fmri token id adr_char
2060 2060 * service instance name adr_string
2061 2061 * -----------------------------------------------------------------------
2062 2062 */
2063 2063 int
2064 2064 fmri_token(pr_context_t *context)
2065 2065 {
2066 2066 return (pa_adr_string(context, 0, 1));
2067 2067 }
2068 2068
2069 2069 /*
2070 2070 * -----------------------------------------------------------------------
2071 2071 * xatom_token() : Process Xatom token and display contents in hex.
2072 2072 * return codes : -1 - error
2073 2073 * : 0 - successful
2074 2074 * NOTE: At the time of call, the xatom token id has been retrieved
2075 2075 *
2076 2076 * Format of xatom token:
2077 2077 * token id adr_char
2078 2078 * length adr_short
2079 2079 * atom adr_char length times
2080 2080 * -----------------------------------------------------------------------
2081 2081 */
2082 2082 int
2083 2083 xatom_token(pr_context_t *context)
2084 2084 {
2085 2085 return (pa_adr_string(context, 0, 1));
2086 2086 }
2087 2087
2088 2088 int
2089 2089 xcolormap_token(pr_context_t *context)
2090 2090 {
2091 2091 return (pa_xgeneric(context));
2092 2092 }
2093 2093
2094 2094 int
2095 2095 xcursor_token(pr_context_t *context)
2096 2096 {
2097 2097 return (pa_xgeneric(context));
2098 2098 }
2099 2099
2100 2100 int
2101 2101 xfont_token(pr_context_t *context)
2102 2102 {
2103 2103 return (pa_xgeneric(context));
2104 2104 }
2105 2105
2106 2106 int
2107 2107 xgc_token(pr_context_t *context)
2108 2108 {
2109 2109 return (pa_xgeneric(context));
2110 2110 }
2111 2111
2112 2112 int
2113 2113 xpixmap_token(pr_context_t *context)
2114 2114 {
2115 2115 return (pa_xgeneric(context));
2116 2116 }
2117 2117
2118 2118 int
2119 2119 xwindow_token(pr_context_t *context)
2120 2120 {
2121 2121 return (pa_xgeneric(context));
2122 2122 }
2123 2123
2124 2124 /*
2125 2125 * -----------------------------------------------------------------------
2126 2126 * xproperty_token(): Process Xproperty token and display contents
2127 2127 *
2128 2128 * return codes : -1 - error
2129 2129 * : 0 - successful
2130 2130 * NOTE: At the time of call, the xproperty token id has been retrieved
2131 2131 *
2132 2132 * Format of xproperty token:
2133 2133 * token id adr_char
2134 2134 * XID adr_u_int32
2135 2135 * creator UID adr_u_int32
2136 2136 * text adr_text
2137 2137 * -----------------------------------------------------------------------
2138 2138 */
2139 2139 int
2140 2140 xproperty_token(pr_context_t *context)
2141 2141 {
2142 2142 int returnstat;
2143 2143
2144 2144 returnstat = process_tag(context, TAG_XID, 0, 0);
2145 2145 returnstat = process_tag(context, TAG_XCUID, returnstat, 0);
2146 2146
2147 2147 /* Done with attributes; force end of token open */
2148 2148 if (returnstat == 0)
2149 2149 returnstat = finish_open_tag(context);
2150 2150
2151 2151 returnstat = pa_adr_string(context, returnstat, 1);
2152 2152
2153 2153 return (returnstat);
2154 2154 }
2155 2155
2156 2156 /*
2157 2157 * -----------------------------------------------------------------------
2158 2158 * xselect_token(): Process Xselect token and display contents in hex
2159 2159 *
2160 2160 * return codes : -1 - error
2161 2161 * : 0 - successful
2162 2162 * NOTE: At the time of call, the xselect token id has been retrieved
2163 2163 *
2164 2164 * Format of xselect token
2165 2165 * text token id adr_char
2166 2166 * property text adr_string
2167 2167 * property type adr_string
2168 2168 * property data adr_string
2169 2169 * -----------------------------------------------------------------------
2170 2170 */
2171 2171 int
2172 2172 xselect_token(pr_context_t *context)
2173 2173 {
2174 2174 int returnstat;
2175 2175
2176 2176 returnstat = process_tag(context, TAG_XSELTEXT, 0, 0);
2177 2177 returnstat = process_tag(context, TAG_XSELTYPE, returnstat, 0);
2178 2178 returnstat = process_tag(context, TAG_XSELDATA, returnstat, 1);
2179 2179
2180 2180 return (returnstat);
2181 2181 }
2182 2182
2183 2183 /*
2184 2184 * -----------------------------------------------------------------------
2185 2185 * xclient_token(): Process Xclient token and display contents in hex.
2186 2186 *
2187 2187 * return codes : -1 - error
2188 2188 * : 0 - successful
2189 2189 *
2190 2190 * Format of xclient token:
2191 2191 * token id adr_char
2192 2192 * client adr_int32
2193 2193 * -----------------------------------------------------------------------
2194 2194 */
2195 2195 int
2196 2196 xclient_token(pr_context_t *context)
2197 2197 {
2198 2198 return (pa_adr_int32(context, 0, 1));
2199 2199 }
2200 2200
2201 2201 /*
2202 2202 * -----------------------------------------------------------------------
2203 2203 * label_token() : Process label token and display contents
2204 2204 * return codes : -1 - error
2205 2205 * : 0 - successful
2206 2206 * NOTE: At the time of call, the label token id has been retrieved
2207 2207 *
2208 2208 * Format of label token:
2209 2209 * label token id adr_char
2210 2210 * label ID adr_char
2211 2211 * label compartment length adr_char
2212 2212 * label classification adr_short
2213 2213 * label compartment words <compartment length> * 4 adr_char
2214 2214 * -----------------------------------------------------------------------
2215 2215 */
2216 2216 /*ARGSUSED*/
2217 2217 int
2218 2218 label_token(pr_context_t *context)
2219 2219 {
2220 2220 static m_label_t *label = NULL;
2221 2221 static size32_t l_size;
2222 2222 int len;
2223 2223 int returnstat;
2224 2224 uval_t uval;
2225 2225
2226 2226 if (label == NULL) {
2227 2227 if ((label = m_label_alloc(MAC_LABEL)) == NULL) {
2228 2228 return (-1);
2229 2229 }
2230 2230 l_size = blabel_size() - 4;
2231 2231 }
2232 2232 if ((returnstat = pr_adr_char(context, (char *)label, 4)) == 0) {
2233 2233 len = (int)(((char *)label)[1] * 4);
2234 2234 if ((len > l_size) ||
2235 2235 (pr_adr_char(context, &((char *)label)[4], len) != 0)) {
2236 2236 return (-1);
2237 2237 }
2238 2238 uval.uvaltype = PRA_STRING;
2239 2239 if (!(context->format & PRF_RAWM)) {
2240 2240 /* print in ASCII form */
2241 2241 if (label_to_str(label, &uval.string_val, M_LABEL,
2242 2242 DEF_NAMES) == 0) {
2243 2243 returnstat = pa_print(context, &uval, 1);
2244 2244 } else /* cannot convert to string */
2245 2245 returnstat = 1;
2246 2246 }
2247 2247 /* print in hexadecimal form */
2248 2248 if ((context->format & PRF_RAWM) || (returnstat == 1)) {
2249 2249 uval.string_val = hexconvert((char *)label, len, len);
2250 2250 if (uval.string_val) {
2251 2251 returnstat = pa_print(context, &uval, 1);
2252 2252 }
2253 2253 }
2254 2254 free(uval.string_val);
2255 2255 }
2256 2256 return (returnstat);
2257 2257 }
2258 2258
2259 2259 /*
2260 2260 * -----------------------------------------------------------------------
2261 2261 * useofpriv_token() : Process priv token and display contents
2262 2262 * return codes : -1 - error
2263 2263 * : 0 - successful
2264 2264 * NOTE: At the time of call, the useofpriv token id has been retrieved
2265 2265 *
2266 2266 * Format of useofpriv token:
2267 2267 * useofpriv token id adr_char
2268 2268 * success/failure flag adr_char
2269 2269 * priv adr_int32 (Trusted Solaris)
2270 2270 * priv_set '\0' separated privileges.
2271 2271 * -----------------------------------------------------------------------
2272 2272 */
2273 2273 /*ARGSUSED*/
2274 2274 int
2275 2275 useofpriv_token(pr_context_t *context)
2276 2276 {
2277 2277 int returnstat;
2278 2278 char sf;
2279 2279 uval_t uval;
2280 2280
2281 2281 if ((returnstat = pr_adr_char(context, &sf, 1)) != 0) {
2282 2282 return (returnstat);
2283 2283 }
2284 2284 if (!(context->format & PRF_RAWM)) {
2285 2285 /* print in ASCII form */
2286 2286
2287 2287 if ((returnstat = open_tag(context, TAG_RESULT)) != 0)
2288 2288 return (returnstat);
2289 2289
2290 2290 uval.uvaltype = PRA_STRING;
2291 2291 if (sf) {
2292 2292 uval.string_val = gettext("successful use of priv");
2293 2293 returnstat = pa_print(context, &uval, 0);
2294 2294 } else {
2295 2295 uval.string_val = gettext("failed use of priv");
2296 2296 returnstat = pa_print(context, &uval, 0);
2297 2297 }
2298 2298 if (returnstat == 0)
2299 2299 returnstat = close_tag(context, TAG_RESULT);
2300 2300
2301 2301 /* Done with attributes; force end of token open */
2302 2302 if (returnstat == 0)
2303 2303 returnstat = finish_open_tag(context);
2304 2304 } else {
2305 2305 /* print in hexadecimal form */
2306 2306 if ((returnstat = open_tag(context, TAG_RESULT)) != 0)
2307 2307 return (returnstat);
2308 2308 uval.uvaltype = PRA_SHORT;
2309 2309 uval.short_val = sf;
2310 2310 returnstat = pa_print(context, &uval, 0);
2311 2311 if (returnstat == 0)
2312 2312 returnstat = close_tag(context, TAG_RESULT);
2313 2313
2314 2314 /* Done with attributes; force end of token open */
2315 2315 if (returnstat == 0)
2316 2316 returnstat = finish_open_tag(context);
2317 2317 }
2318 2318 return (pa_adr_string(context, 0, 1));
2319 2319 }
2320 2320
2321 2321 /*
2322 2322 * -----------------------------------------------------------------------
2323 2323 * privilege_token() : Process privilege token and display contents
2324 2324 * return codes : -1 - error
2325 2325 * : 0 - successful
2326 2326 * NOTE: At the time of call, the privilege token id has been retrieved
2327 2327 *
2328 2328 * Format of privilege token:
2329 2329 * privilege token id adr_char
2330 2330 * privilege type adr_string
2331 2331 * privilege adr_string
2332 2332 * -----------------------------------------------------------------------
2333 2333 */
2334 2334 int
2335 2335 privilege_token(pr_context_t *context)
2336 2336 {
2337 2337 int returnstat;
2338 2338
↓ open down ↓ |
2338 lines elided |
↑ open up ↑ |
2339 2339 /* privilege type: */
2340 2340 returnstat = process_tag(context, TAG_SETTYPE, 0, 0);
2341 2341
2342 2342 /* Done with attributes; force end of token open */
2343 2343 if (returnstat == 0)
2344 2344 returnstat = finish_open_tag(context);
2345 2345
2346 2346 /* privilege: */
2347 2347 return (pa_adr_string(context, returnstat, 1));
2348 2348 }
2349 +
2350 +/*
2351 + * -----------------------------------------------------------------------
2352 + * secflags_token() : Process privilege token and display contents
2353 + * return codes : -1 - error
2354 + * : 0 - successful
2355 + * NOTE: At the time of call, the secflags token id has been retrieved
2356 + *
2357 + * Format of secflags token:
2358 + * secflags token id adr_char
2359 + * secflag set name adr_string
2360 + * secflags adr_string
2361 + * -----------------------------------------------------------------------
2362 + */
2363 +int
2364 +secflags_token(pr_context_t *context)
2365 +{
2366 + int returnstat;
2367 +
2368 + /* Set name */
2369 + returnstat = process_tag(context, TAG_SETTYPE, 0, 0);
2370 +
2371 + /* Done with attributes; force end of token open */
2372 + if (returnstat == 0)
2373 + returnstat = finish_open_tag(context);
2374 +
2375 + /* set */
2376 + return (pa_adr_string(context, returnstat, 1));
2377 +}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX