17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*81490fd2Sgww * Common Development and Distribution License (the "License"). 6*81490fd2Sgww * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*81490fd2Sgww * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #define _REENTRANT 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #include <ctype.h> 317c478bd9Sstevel@tonic-gate #include <errno.h> 327c478bd9Sstevel@tonic-gate #include <grp.h> 337c478bd9Sstevel@tonic-gate #include <libintl.h> 347c478bd9Sstevel@tonic-gate #include <netdb.h> 357c478bd9Sstevel@tonic-gate #include <time.h> 367c478bd9Sstevel@tonic-gate #include <pwd.h> 377c478bd9Sstevel@tonic-gate #include <stdio.h> 387c478bd9Sstevel@tonic-gate #include <stdlib.h> 397c478bd9Sstevel@tonic-gate #include <string.h> 407c478bd9Sstevel@tonic-gate #include <wchar.h> 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate #include <arpa/inet.h> 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate #include <bsm/audit.h> 457c478bd9Sstevel@tonic-gate #include <bsm/audit_record.h> 467c478bd9Sstevel@tonic-gate #include <bsm/libbsm.h> 477c478bd9Sstevel@tonic-gate #include <security/pam_appl.h> 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate #include <sys/inttypes.h> 507c478bd9Sstevel@tonic-gate #include <sys/mkdev.h> 517c478bd9Sstevel@tonic-gate #include <sys/types.h> 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate #include "praudit.h" 547c478bd9Sstevel@tonic-gate #include "toktable.h" 557c478bd9Sstevel@tonic-gate #include "adt_xlate.h" 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate static void convertascii(char *p, char *c, int size); 587c478bd9Sstevel@tonic-gate static int convertbinary(char *p, char *c, int size); 597c478bd9Sstevel@tonic-gate static void eventmodifier2string(ushort_t emodifier, char *modstring, 607c478bd9Sstevel@tonic-gate size_t modlen); 617c478bd9Sstevel@tonic-gate static int do_mtime32(pr_context_t *context, int status, int flag, 627c478bd9Sstevel@tonic-gate uint32_t scale); 637c478bd9Sstevel@tonic-gate static int do_mtime64(pr_context_t *context, int status, int flag, 647c478bd9Sstevel@tonic-gate uint64_t scale); 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate /* 677c478bd9Sstevel@tonic-gate * ------------------------------------------------------ 687c478bd9Sstevel@tonic-gate * field widths for arbitrary data token type 697c478bd9Sstevel@tonic-gate * ------------------------------------------------------ 707c478bd9Sstevel@tonic-gate */ 717c478bd9Sstevel@tonic-gate static struct fw { 727c478bd9Sstevel@tonic-gate char basic_unit; 737c478bd9Sstevel@tonic-gate struct { 747c478bd9Sstevel@tonic-gate char print_base; 757c478bd9Sstevel@tonic-gate int field_width; 767c478bd9Sstevel@tonic-gate } pwidth[5]; 777c478bd9Sstevel@tonic-gate } fwidth[] = { 787c478bd9Sstevel@tonic-gate /* character data type, 8 bits */ 797c478bd9Sstevel@tonic-gate AUR_CHAR, AUP_BINARY, 12, 807c478bd9Sstevel@tonic-gate AUP_OCTAL, 6, 817c478bd9Sstevel@tonic-gate AUP_DECIMAL, 6, 827c478bd9Sstevel@tonic-gate AUP_HEX, 6, 837c478bd9Sstevel@tonic-gate AUP_STRING, 4, 847c478bd9Sstevel@tonic-gate AUR_BYTE, AUP_BINARY, 12, 857c478bd9Sstevel@tonic-gate AUP_OCTAL, 6, 867c478bd9Sstevel@tonic-gate AUP_DECIMAL, 6, 877c478bd9Sstevel@tonic-gate AUP_HEX, 6, 887c478bd9Sstevel@tonic-gate AUP_STRING, 4, 897c478bd9Sstevel@tonic-gate AUR_SHORT, AUP_BINARY, 20, 907c478bd9Sstevel@tonic-gate AUP_OCTAL, 10, 917c478bd9Sstevel@tonic-gate AUP_DECIMAL, 10, 927c478bd9Sstevel@tonic-gate AUP_HEX, 8, 937c478bd9Sstevel@tonic-gate AUP_STRING, 6, 947c478bd9Sstevel@tonic-gate AUR_INT32, AUP_BINARY, 36, 957c478bd9Sstevel@tonic-gate AUP_OCTAL, 18, 967c478bd9Sstevel@tonic-gate AUP_DECIMAL, 18, 977c478bd9Sstevel@tonic-gate AUP_HEX, 12, 987c478bd9Sstevel@tonic-gate AUP_STRING, 10, 997c478bd9Sstevel@tonic-gate AUR_INT64, AUP_BINARY, 68, 1007c478bd9Sstevel@tonic-gate AUP_OCTAL, 34, 1017c478bd9Sstevel@tonic-gate AUP_DECIMAL, 34, 1027c478bd9Sstevel@tonic-gate AUP_HEX, 20, 1037c478bd9Sstevel@tonic-gate AUP_STRING, 20}; 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate static int numwidthentries = sizeof (fwidth) 1077c478bd9Sstevel@tonic-gate / sizeof (struct fw); 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate /* 1117c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 1127c478bd9Sstevel@tonic-gate * do_newline: 1137c478bd9Sstevel@tonic-gate * Print a newline, if needed according to various formatting 1147c478bd9Sstevel@tonic-gate * rules. 1157c478bd9Sstevel@tonic-gate * return codes : 0 - success 1167c478bd9Sstevel@tonic-gate * : -1 - error 1177c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 1187c478bd9Sstevel@tonic-gate */ 1197c478bd9Sstevel@tonic-gate int 1207c478bd9Sstevel@tonic-gate do_newline(pr_context_t *context, int flag) 1217c478bd9Sstevel@tonic-gate { 1227c478bd9Sstevel@tonic-gate int retstat = 0; 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate if (!(context->format & PRF_ONELINE) && (flag == 1)) 1257c478bd9Sstevel@tonic-gate retstat = pr_putchar(context, '\n'); 1267c478bd9Sstevel@tonic-gate else if (!(context->format & PRF_XMLM)) 1277c478bd9Sstevel@tonic-gate retstat = pr_printf(context, "%s", context->SEPARATOR); 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate return (retstat); 1307c478bd9Sstevel@tonic-gate } 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate int 1337c478bd9Sstevel@tonic-gate open_tag(pr_context_t *context, int tagnum) 1347c478bd9Sstevel@tonic-gate { 1357c478bd9Sstevel@tonic-gate int err = 0; 1367c478bd9Sstevel@tonic-gate token_desc_t *tag; 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate /* no-op if not doing XML format */ 1397c478bd9Sstevel@tonic-gate if (!(context->format & PRF_XMLM)) 1407c478bd9Sstevel@tonic-gate return (0); 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate tag = &tokentable[tagnum]; 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate /* 1457c478bd9Sstevel@tonic-gate * First if needed do an implicit finish of a pending open for an 1467c478bd9Sstevel@tonic-gate * extended tag. I.e., for the extended tag xxx: 1477c478bd9Sstevel@tonic-gate * <xxx a=".." b=".."> ... </xxx> 1487c478bd9Sstevel@tonic-gate * -- insert a close bracket after the last attribute 1497c478bd9Sstevel@tonic-gate * (in other words, when the 1st non-attribute is opened while 1507c478bd9Sstevel@tonic-gate * this is pending). Note that only one tag could be pending at 1517c478bd9Sstevel@tonic-gate * a given time -- it couldn't be nested. 1527c478bd9Sstevel@tonic-gate */ 1537c478bd9Sstevel@tonic-gate if (context->pending_flag && (tag->t_type != T_ATTRIBUTE)) { 1547c478bd9Sstevel@tonic-gate /* complete pending extended open */ 1557c478bd9Sstevel@tonic-gate err = pr_putchar(context, '>'); 1567c478bd9Sstevel@tonic-gate if (err != 0) 1577c478bd9Sstevel@tonic-gate return (err); 1587c478bd9Sstevel@tonic-gate context->pending_flag = 0; 1597c478bd9Sstevel@tonic-gate } 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate if (is_header_token(tagnum) || is_file_token(tagnum)) { 1627c478bd9Sstevel@tonic-gate /* File token or new record on new line */ 1637c478bd9Sstevel@tonic-gate err = pr_putchar(context, '\n'); 1647c478bd9Sstevel@tonic-gate } else if (is_token(tagnum)) { 1657c478bd9Sstevel@tonic-gate /* Each token on new line if possible */ 1667c478bd9Sstevel@tonic-gate err = do_newline(context, 1); 1677c478bd9Sstevel@tonic-gate } 1687c478bd9Sstevel@tonic-gate if (err != 0) 1697c478bd9Sstevel@tonic-gate return (err); 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate switch (tag->t_type) { 1727c478bd9Sstevel@tonic-gate case T_ATTRIBUTE: 1737c478bd9Sstevel@tonic-gate err = pr_printf(context, " %s=\"", tag->t_tagname); 1747c478bd9Sstevel@tonic-gate break; 1757c478bd9Sstevel@tonic-gate case T_ELEMENT: 1767c478bd9Sstevel@tonic-gate err = pr_printf(context, "<%s>", tag->t_tagname); 1777c478bd9Sstevel@tonic-gate break; 1787c478bd9Sstevel@tonic-gate case T_ENCLOSED: 1797c478bd9Sstevel@tonic-gate err = pr_printf(context, "<%s", tag->t_tagname); 1807c478bd9Sstevel@tonic-gate break; 1817c478bd9Sstevel@tonic-gate case T_EXTENDED: 1827c478bd9Sstevel@tonic-gate err = pr_printf(context, "<%s", tag->t_tagname); 1837c478bd9Sstevel@tonic-gate if (err == 0) 1847c478bd9Sstevel@tonic-gate context->pending_flag = tagnum; 1857c478bd9Sstevel@tonic-gate break; 1867c478bd9Sstevel@tonic-gate default: 1877c478bd9Sstevel@tonic-gate break; 1887c478bd9Sstevel@tonic-gate } 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate if (is_header_token(tagnum) && (err == 0)) 1917c478bd9Sstevel@tonic-gate context->current_rec = tagnum; /* set start of new record */ 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate return (err); 1947c478bd9Sstevel@tonic-gate } 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate /* 1977c478bd9Sstevel@tonic-gate * Do an implicit close of a record when needed. 1987c478bd9Sstevel@tonic-gate */ 1997c478bd9Sstevel@tonic-gate int 2007c478bd9Sstevel@tonic-gate check_close_rec(pr_context_t *context, int tagnum) 2017c478bd9Sstevel@tonic-gate { 2027c478bd9Sstevel@tonic-gate int err = 0; 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate /* no-op if not doing XML format */ 2057c478bd9Sstevel@tonic-gate if (!(context->format & PRF_XMLM)) 2067c478bd9Sstevel@tonic-gate return (0); 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate /* 2097c478bd9Sstevel@tonic-gate * If we're opening a header or the file token (i.e., starting a new 2107c478bd9Sstevel@tonic-gate * record), if there's a current record in progress do an implicit 2117c478bd9Sstevel@tonic-gate * close of it. 2127c478bd9Sstevel@tonic-gate */ 2137c478bd9Sstevel@tonic-gate if ((is_header_token(tagnum) || is_file_token(tagnum)) && 2147c478bd9Sstevel@tonic-gate context->current_rec) { 2157c478bd9Sstevel@tonic-gate err = do_newline(context, 1); 2167c478bd9Sstevel@tonic-gate if (err == 0) 2177c478bd9Sstevel@tonic-gate err = close_tag(context, context->current_rec); 2187c478bd9Sstevel@tonic-gate } 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate return (err); 2217c478bd9Sstevel@tonic-gate } 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate /* 2247c478bd9Sstevel@tonic-gate * explicit finish of a pending open for an extended tag. 2257c478bd9Sstevel@tonic-gate */ 2267c478bd9Sstevel@tonic-gate int 2277c478bd9Sstevel@tonic-gate finish_open_tag(pr_context_t *context) 2287c478bd9Sstevel@tonic-gate { 2297c478bd9Sstevel@tonic-gate int err = 0; 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate /* no-op if not doing XML format */ 2327c478bd9Sstevel@tonic-gate if (!(context->format & PRF_XMLM)) 2337c478bd9Sstevel@tonic-gate return (0); 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate if (context->pending_flag) { 2367c478bd9Sstevel@tonic-gate /* complete pending extended open */ 2377c478bd9Sstevel@tonic-gate err = pr_putchar(context, '>'); 2387c478bd9Sstevel@tonic-gate if (err == 0) 2397c478bd9Sstevel@tonic-gate context->pending_flag = 0; 2407c478bd9Sstevel@tonic-gate } 2417c478bd9Sstevel@tonic-gate return (err); 2427c478bd9Sstevel@tonic-gate } 2437c478bd9Sstevel@tonic-gate 2447c478bd9Sstevel@tonic-gate int 2457c478bd9Sstevel@tonic-gate close_tag(pr_context_t *context, int tagnum) 2467c478bd9Sstevel@tonic-gate { 2477c478bd9Sstevel@tonic-gate int err = 0; 2487c478bd9Sstevel@tonic-gate token_desc_t *tag; 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate /* no-op if not doing XML format */ 2517c478bd9Sstevel@tonic-gate if (!(context->format & PRF_XMLM)) 2527c478bd9Sstevel@tonic-gate return (0); 2537c478bd9Sstevel@tonic-gate 2547c478bd9Sstevel@tonic-gate tag = &tokentable[tagnum]; 2557c478bd9Sstevel@tonic-gate 2567c478bd9Sstevel@tonic-gate switch (tag->t_type) { 2577c478bd9Sstevel@tonic-gate case T_ATTRIBUTE: 2587c478bd9Sstevel@tonic-gate err = pr_putchar(context, '\"'); 2597c478bd9Sstevel@tonic-gate break; 2607c478bd9Sstevel@tonic-gate case T_ELEMENT: 2617c478bd9Sstevel@tonic-gate err = pr_printf(context, "</%s>", tag->t_tagname); 2627c478bd9Sstevel@tonic-gate break; 2637c478bd9Sstevel@tonic-gate case T_ENCLOSED: 2647c478bd9Sstevel@tonic-gate err = pr_printf(context, "/>"); 2657c478bd9Sstevel@tonic-gate break; 2667c478bd9Sstevel@tonic-gate case T_EXTENDED: 2677c478bd9Sstevel@tonic-gate err = pr_printf(context, "</%s>", tag->t_tagname); 2687c478bd9Sstevel@tonic-gate break; 2697c478bd9Sstevel@tonic-gate default: 2707c478bd9Sstevel@tonic-gate break; 2717c478bd9Sstevel@tonic-gate } 2727c478bd9Sstevel@tonic-gate 2737c478bd9Sstevel@tonic-gate if (is_header_token(tagnum) && (err == 0)) 2747c478bd9Sstevel@tonic-gate context->current_rec = 0; /* closing rec; none current */ 2757c478bd9Sstevel@tonic-gate 2767c478bd9Sstevel@tonic-gate return (err); 2777c478bd9Sstevel@tonic-gate } 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate /* 2807c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 2817c478bd9Sstevel@tonic-gate * process_tag: 2827c478bd9Sstevel@tonic-gate * Calls the routine corresponding to the tag 2837c478bd9Sstevel@tonic-gate * Note that to use this mechanism, all such routines must 2847c478bd9Sstevel@tonic-gate * take 2 ints for their parameters; the first of these is 2857c478bd9Sstevel@tonic-gate * the current status. 2867c478bd9Sstevel@tonic-gate * 2877c478bd9Sstevel@tonic-gate * flag = 1 for newline / delimiter, else 0 2887c478bd9Sstevel@tonic-gate * return codes : -1 - error 2897c478bd9Sstevel@tonic-gate * : 0 - successful 2907c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 2917c478bd9Sstevel@tonic-gate */ 2927c478bd9Sstevel@tonic-gate int 2937c478bd9Sstevel@tonic-gate process_tag(pr_context_t *context, int tagnum, int status, int flag) 2947c478bd9Sstevel@tonic-gate { 2957c478bd9Sstevel@tonic-gate int retstat; 2967c478bd9Sstevel@tonic-gate 2977c478bd9Sstevel@tonic-gate retstat = status; 2987c478bd9Sstevel@tonic-gate 2997c478bd9Sstevel@tonic-gate if (retstat) 3007c478bd9Sstevel@tonic-gate return (retstat); 3017c478bd9Sstevel@tonic-gate 3027c478bd9Sstevel@tonic-gate if ((tagnum > 0) && (tagnum <= MAXTAG) && 3037c478bd9Sstevel@tonic-gate (tokentable[tagnum].func != NOFUNC)) { 3047c478bd9Sstevel@tonic-gate retstat = open_tag(context, tagnum); 3057c478bd9Sstevel@tonic-gate if (!retstat) 3067c478bd9Sstevel@tonic-gate retstat = (*tokentable[tagnum].func)(context, status, 3077c478bd9Sstevel@tonic-gate flag); 3087c478bd9Sstevel@tonic-gate if (!retstat) 3097c478bd9Sstevel@tonic-gate retstat = close_tag(context, tagnum); 3107c478bd9Sstevel@tonic-gate return (retstat); 3117c478bd9Sstevel@tonic-gate } 3127c478bd9Sstevel@tonic-gate /* here if token id is not in table */ 3137c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("praudit: No code associated with " 3147c478bd9Sstevel@tonic-gate "tag id %d\n"), tagnum); 3157c478bd9Sstevel@tonic-gate return (0); 3167c478bd9Sstevel@tonic-gate } 3177c478bd9Sstevel@tonic-gate 3187c478bd9Sstevel@tonic-gate void 3197c478bd9Sstevel@tonic-gate get_Hname(uint32_t addr, char *buf, size_t buflen) 3207c478bd9Sstevel@tonic-gate { 3217c478bd9Sstevel@tonic-gate extern char *inet_ntoa(const struct in_addr); 3227c478bd9Sstevel@tonic-gate struct hostent *phe; 3237c478bd9Sstevel@tonic-gate struct in_addr ia; 3247c478bd9Sstevel@tonic-gate 3257c478bd9Sstevel@tonic-gate phe = gethostbyaddr((const char *)&addr, 4, AF_INET); 3267c478bd9Sstevel@tonic-gate if (phe == (struct hostent *)0) { 3277c478bd9Sstevel@tonic-gate ia.s_addr = addr; 3287c478bd9Sstevel@tonic-gate (void) snprintf(buf, buflen, "%s", inet_ntoa(ia)); 3297c478bd9Sstevel@tonic-gate return; 3307c478bd9Sstevel@tonic-gate } 3317c478bd9Sstevel@tonic-gate ia.s_addr = addr; 3327c478bd9Sstevel@tonic-gate (void) snprintf(buf, buflen, "%s", phe->h_name); 3337c478bd9Sstevel@tonic-gate } 3347c478bd9Sstevel@tonic-gate 3357c478bd9Sstevel@tonic-gate void 3367c478bd9Sstevel@tonic-gate get_Hname_ex(uint32_t *addr, char *buf, size_t buflen) 3377c478bd9Sstevel@tonic-gate { 3387c478bd9Sstevel@tonic-gate struct hostent *phe; 3397c478bd9Sstevel@tonic-gate int err; 3407c478bd9Sstevel@tonic-gate 3417c478bd9Sstevel@tonic-gate phe = getipnodebyaddr((const void *)addr, 16, AF_INET6, &err); 3427c478bd9Sstevel@tonic-gate 3437c478bd9Sstevel@tonic-gate if (phe == (struct hostent *)0) { 3447c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET6, (void *)addr, buf, buflen); 3457c478bd9Sstevel@tonic-gate } else 3467c478bd9Sstevel@tonic-gate (void) snprintf(buf, buflen, "%s", phe->h_name); 3477c478bd9Sstevel@tonic-gate 3487c478bd9Sstevel@tonic-gate if (phe) 3497c478bd9Sstevel@tonic-gate freehostent(phe); 3507c478bd9Sstevel@tonic-gate } 3517c478bd9Sstevel@tonic-gate 3527c478bd9Sstevel@tonic-gate int 3537c478bd9Sstevel@tonic-gate pa_hostname(pr_context_t *context, int status, int flag) 3547c478bd9Sstevel@tonic-gate { 3557c478bd9Sstevel@tonic-gate int returnstat; 3567c478bd9Sstevel@tonic-gate uint32_t ip_addr; 3577c478bd9Sstevel@tonic-gate struct in_addr ia; 3587c478bd9Sstevel@tonic-gate uval_t uval; 3597c478bd9Sstevel@tonic-gate char buf[256]; 3607c478bd9Sstevel@tonic-gate 3617c478bd9Sstevel@tonic-gate if (status < 0) 3627c478bd9Sstevel@tonic-gate return (status); 3637c478bd9Sstevel@tonic-gate 3647c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, (char *)&ip_addr, 4)) != 0) 3657c478bd9Sstevel@tonic-gate return (returnstat); 3667c478bd9Sstevel@tonic-gate 3677c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 3687c478bd9Sstevel@tonic-gate 3697c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 3707c478bd9Sstevel@tonic-gate uval.string_val = buf; 3717c478bd9Sstevel@tonic-gate get_Hname(ip_addr, buf, sizeof (buf)); 3727c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 3737c478bd9Sstevel@tonic-gate } else { 3747c478bd9Sstevel@tonic-gate ia.s_addr = ip_addr; 3757c478bd9Sstevel@tonic-gate if ((uval.string_val = inet_ntoa(ia)) == NULL) 3767c478bd9Sstevel@tonic-gate return (-1); 3777c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 3787c478bd9Sstevel@tonic-gate } 3797c478bd9Sstevel@tonic-gate return (returnstat); 3807c478bd9Sstevel@tonic-gate } 3817c478bd9Sstevel@tonic-gate 3827c478bd9Sstevel@tonic-gate int 3837c478bd9Sstevel@tonic-gate pa_hostname_ex(pr_context_t *context, int status, int flag) 3847c478bd9Sstevel@tonic-gate { 3857c478bd9Sstevel@tonic-gate int returnstat; 3867c478bd9Sstevel@tonic-gate uint32_t ip_type; 3877c478bd9Sstevel@tonic-gate uint32_t ip_addr[4]; 3887c478bd9Sstevel@tonic-gate struct in_addr ia; 3897c478bd9Sstevel@tonic-gate char buf[256]; 3907c478bd9Sstevel@tonic-gate uval_t uval; 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate if (status < 0) 3937c478bd9Sstevel@tonic-gate return (status); 3947c478bd9Sstevel@tonic-gate 3957c478bd9Sstevel@tonic-gate /* get ip type */ 3967c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_int32(context, (int32_t *)&ip_type, 1)) != 0) 3977c478bd9Sstevel@tonic-gate return (returnstat); 3987c478bd9Sstevel@tonic-gate 3997c478bd9Sstevel@tonic-gate /* only IPv4 and IPv6 addresses are legal */ 4007c478bd9Sstevel@tonic-gate if ((ip_type != AU_IPv4) && (ip_type != AU_IPv6)) 4017c478bd9Sstevel@tonic-gate return (-1); 4027c478bd9Sstevel@tonic-gate 4037c478bd9Sstevel@tonic-gate /* get ip address */ 4047c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, (char *)ip_addr, ip_type)) != 0) 4057c478bd9Sstevel@tonic-gate return (returnstat); 4067c478bd9Sstevel@tonic-gate 4077c478bd9Sstevel@tonic-gate if ((returnstat = open_tag(context, TAG_HOSTID)) != 0) 4087c478bd9Sstevel@tonic-gate return (returnstat); 4097c478bd9Sstevel@tonic-gate 4107c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 4117c478bd9Sstevel@tonic-gate if (ip_type == AU_IPv4) { /* ipv4 address */ 4127c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 4137c478bd9Sstevel@tonic-gate uval.string_val = buf; 4147c478bd9Sstevel@tonic-gate get_Hname(ip_addr[0], buf, sizeof (buf)); 4157c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 4167c478bd9Sstevel@tonic-gate } else { 4177c478bd9Sstevel@tonic-gate ia.s_addr = ip_addr[0]; 4187c478bd9Sstevel@tonic-gate if ((uval.string_val = inet_ntoa(ia)) == NULL) 4197c478bd9Sstevel@tonic-gate return (-1); 4207c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 4217c478bd9Sstevel@tonic-gate } 4227c478bd9Sstevel@tonic-gate } else if (ip_type == AU_IPv6) { /* IPv6 addresss (128 bits) */ 4237c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 4247c478bd9Sstevel@tonic-gate uval.string_val = buf; 4257c478bd9Sstevel@tonic-gate get_Hname_ex(ip_addr, buf, sizeof (buf)); 4267c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 4277c478bd9Sstevel@tonic-gate } else { 4287c478bd9Sstevel@tonic-gate uval.string_val = (char *)buf; 4297c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET6, (void *)ip_addr, buf, 4307c478bd9Sstevel@tonic-gate sizeof (buf)); 4317c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 4327c478bd9Sstevel@tonic-gate } 4337c478bd9Sstevel@tonic-gate } 4347c478bd9Sstevel@tonic-gate 4357c478bd9Sstevel@tonic-gate if (returnstat != 0) 4367c478bd9Sstevel@tonic-gate return (returnstat); 4377c478bd9Sstevel@tonic-gate return (close_tag(context, TAG_HOSTID)); 4387c478bd9Sstevel@tonic-gate } 4397c478bd9Sstevel@tonic-gate 4407c478bd9Sstevel@tonic-gate int 4417c478bd9Sstevel@tonic-gate pa_hostname_so(pr_context_t *context, int status, int flag) 4427c478bd9Sstevel@tonic-gate { 4437c478bd9Sstevel@tonic-gate int returnstat; 4447c478bd9Sstevel@tonic-gate short ip_type; 4457c478bd9Sstevel@tonic-gate ushort_t ip_port; 4467c478bd9Sstevel@tonic-gate uint32_t ip_addr[4]; 4477c478bd9Sstevel@tonic-gate struct in_addr ia; 4487c478bd9Sstevel@tonic-gate char buf[256]; 4497c478bd9Sstevel@tonic-gate uval_t uval; 4507c478bd9Sstevel@tonic-gate 4517c478bd9Sstevel@tonic-gate if (status < 0) 4527c478bd9Sstevel@tonic-gate return (status); 4537c478bd9Sstevel@tonic-gate 4547c478bd9Sstevel@tonic-gate /* get ip type */ 4557c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_short(context, &ip_type, 1)) != 0) 4567c478bd9Sstevel@tonic-gate return (returnstat); 4577c478bd9Sstevel@tonic-gate 4587c478bd9Sstevel@tonic-gate /* only IPv4 and IPv6 addresses are legal */ 4597c478bd9Sstevel@tonic-gate if ((ip_type != AU_IPv4) && (ip_type != AU_IPv6)) 4607c478bd9Sstevel@tonic-gate return (-1); 4617c478bd9Sstevel@tonic-gate 4627c478bd9Sstevel@tonic-gate /* get local ip port */ 4637c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_short(context, &ip_port, 1)) != 0) 4647c478bd9Sstevel@tonic-gate return (returnstat); 4657c478bd9Sstevel@tonic-gate 4667c478bd9Sstevel@tonic-gate if ((returnstat = open_tag(context, TAG_SOCKEXLPORT)) != 0) 4677c478bd9Sstevel@tonic-gate return (returnstat); 4687c478bd9Sstevel@tonic-gate 4697c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 4707c478bd9Sstevel@tonic-gate uval.string_val = hexconvert((char *)&ip_port, sizeof (ip_port), 4717c478bd9Sstevel@tonic-gate sizeof (ip_port)); 4727c478bd9Sstevel@tonic-gate if (uval.string_val) { 4737c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, 0); 4747c478bd9Sstevel@tonic-gate free(uval.string_val); 4757c478bd9Sstevel@tonic-gate } else 4767c478bd9Sstevel@tonic-gate returnstat = -1; 4777c478bd9Sstevel@tonic-gate if (returnstat) 4787c478bd9Sstevel@tonic-gate return (returnstat); 4797c478bd9Sstevel@tonic-gate 4807c478bd9Sstevel@tonic-gate if ((returnstat = close_tag(context, TAG_SOCKEXLPORT)) != 0) 4817c478bd9Sstevel@tonic-gate return (returnstat); 4827c478bd9Sstevel@tonic-gate 4837c478bd9Sstevel@tonic-gate /* get local ip address */ 4847c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, (char *)ip_addr, ip_type)) != 0) 4857c478bd9Sstevel@tonic-gate return (returnstat); 4867c478bd9Sstevel@tonic-gate 4877c478bd9Sstevel@tonic-gate if ((returnstat = open_tag(context, TAG_SOCKEXLADDR)) != 0) 4887c478bd9Sstevel@tonic-gate return (returnstat); 4897c478bd9Sstevel@tonic-gate 4907c478bd9Sstevel@tonic-gate if (ip_type == AU_IPv4) { /* ipv4 address */ 4917c478bd9Sstevel@tonic-gate 4927c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 4937c478bd9Sstevel@tonic-gate uval.string_val = buf; 4947c478bd9Sstevel@tonic-gate get_Hname(ip_addr[0], buf, sizeof (buf)); 4957c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, 0); 4967c478bd9Sstevel@tonic-gate } else { 4977c478bd9Sstevel@tonic-gate ia.s_addr = ip_addr[0]; 4987c478bd9Sstevel@tonic-gate if ((uval.string_val = inet_ntoa(ia)) == NULL) 4997c478bd9Sstevel@tonic-gate return (-1); 5007c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, 0); 5017c478bd9Sstevel@tonic-gate } 5027c478bd9Sstevel@tonic-gate 5037c478bd9Sstevel@tonic-gate } else if (ip_type == AU_IPv6) { /* IPv6 addresss (128 bits) */ 5047c478bd9Sstevel@tonic-gate 5057c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 5067c478bd9Sstevel@tonic-gate uval.string_val = buf; 5077c478bd9Sstevel@tonic-gate get_Hname_ex(ip_addr, buf, sizeof (buf)); 5087c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, 0); 5097c478bd9Sstevel@tonic-gate } else { 5107c478bd9Sstevel@tonic-gate uval.string_val = (char *)buf; 5117c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET6, (void *)ip_addr, buf, 5127c478bd9Sstevel@tonic-gate sizeof (buf)); 5137c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, 0); 5147c478bd9Sstevel@tonic-gate } 5157c478bd9Sstevel@tonic-gate } else 5167c478bd9Sstevel@tonic-gate returnstat = -1; 5177c478bd9Sstevel@tonic-gate 5187c478bd9Sstevel@tonic-gate if (returnstat) 5197c478bd9Sstevel@tonic-gate return (returnstat); 5207c478bd9Sstevel@tonic-gate 5217c478bd9Sstevel@tonic-gate if ((returnstat = close_tag(context, TAG_SOCKEXLADDR)) != 0) 5227c478bd9Sstevel@tonic-gate return (returnstat); 5237c478bd9Sstevel@tonic-gate 5247c478bd9Sstevel@tonic-gate /* get foreign ip port */ 5257c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_short(context, &ip_port, 1)) != 0) 5267c478bd9Sstevel@tonic-gate return (returnstat); 5277c478bd9Sstevel@tonic-gate 5287c478bd9Sstevel@tonic-gate if ((returnstat = open_tag(context, TAG_SOCKEXFPORT)) != 0) 5297c478bd9Sstevel@tonic-gate return (returnstat); 5307c478bd9Sstevel@tonic-gate 5317c478bd9Sstevel@tonic-gate uval.string_val = hexconvert((char *)&ip_port, sizeof (ip_port), 5327c478bd9Sstevel@tonic-gate sizeof (ip_port)); 5337c478bd9Sstevel@tonic-gate if (uval.string_val) { 5347c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, 0); 5357c478bd9Sstevel@tonic-gate free(uval.string_val); 5367c478bd9Sstevel@tonic-gate } else 5377c478bd9Sstevel@tonic-gate returnstat = -1; 5387c478bd9Sstevel@tonic-gate 5397c478bd9Sstevel@tonic-gate if (returnstat) 5407c478bd9Sstevel@tonic-gate return (returnstat); 5417c478bd9Sstevel@tonic-gate 5427c478bd9Sstevel@tonic-gate if ((returnstat = close_tag(context, TAG_SOCKEXFPORT)) != 0) 5437c478bd9Sstevel@tonic-gate return (returnstat); 5447c478bd9Sstevel@tonic-gate 5457c478bd9Sstevel@tonic-gate /* get foreign ip address */ 5467c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, (char *)ip_addr, ip_type)) != 0) 5477c478bd9Sstevel@tonic-gate return (returnstat); 5487c478bd9Sstevel@tonic-gate 5497c478bd9Sstevel@tonic-gate if ((returnstat = open_tag(context, TAG_SOCKEXFADDR)) != 0) 5507c478bd9Sstevel@tonic-gate return (returnstat); 5517c478bd9Sstevel@tonic-gate 5527c478bd9Sstevel@tonic-gate if (ip_type == AU_IPv4) { /* ipv4 address */ 5537c478bd9Sstevel@tonic-gate 5547c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 5557c478bd9Sstevel@tonic-gate uval.string_val = buf; 5567c478bd9Sstevel@tonic-gate get_Hname(ip_addr[0], buf, sizeof (buf)); 5577c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 5587c478bd9Sstevel@tonic-gate } else { 5597c478bd9Sstevel@tonic-gate ia.s_addr = ip_addr[0]; 5607c478bd9Sstevel@tonic-gate if ((uval.string_val = inet_ntoa(ia)) == NULL) 5617c478bd9Sstevel@tonic-gate return (-1); 5627c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 5637c478bd9Sstevel@tonic-gate } 5647c478bd9Sstevel@tonic-gate 5657c478bd9Sstevel@tonic-gate } else if (ip_type == AU_IPv6) { /* IPv6 addresss (128 bits) */ 5667c478bd9Sstevel@tonic-gate 5677c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 5687c478bd9Sstevel@tonic-gate uval.string_val = buf; 5697c478bd9Sstevel@tonic-gate get_Hname_ex(ip_addr, buf, sizeof (buf)); 5707c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 5717c478bd9Sstevel@tonic-gate } else { 5727c478bd9Sstevel@tonic-gate uval.string_val = (char *)buf; 5737c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET6, (void *)ip_addr, buf, 5747c478bd9Sstevel@tonic-gate sizeof (buf)); 5757c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 5767c478bd9Sstevel@tonic-gate } 5777c478bd9Sstevel@tonic-gate } else 5787c478bd9Sstevel@tonic-gate returnstat = -1; 5797c478bd9Sstevel@tonic-gate 5807c478bd9Sstevel@tonic-gate if (returnstat) 5817c478bd9Sstevel@tonic-gate return (returnstat); 5827c478bd9Sstevel@tonic-gate 5837c478bd9Sstevel@tonic-gate if ((returnstat = close_tag(context, TAG_SOCKEXFADDR)) != 0) 5847c478bd9Sstevel@tonic-gate return (returnstat); 5857c478bd9Sstevel@tonic-gate 5867c478bd9Sstevel@tonic-gate return (returnstat); 5877c478bd9Sstevel@tonic-gate } 5887c478bd9Sstevel@tonic-gate 5897c478bd9Sstevel@tonic-gate 5907c478bd9Sstevel@tonic-gate #define NBITSMAJOR64 32 /* # of major device bits in 64-bit Solaris */ 5917c478bd9Sstevel@tonic-gate #define NBITSMINOR64 32 /* # of minor device bits in 64-bit Solaris */ 5927c478bd9Sstevel@tonic-gate #define MAXMAJ64 0xfffffffful /* max major value */ 5937c478bd9Sstevel@tonic-gate #define MAXMIN64 0xfffffffful /* max minor value */ 5947c478bd9Sstevel@tonic-gate 5957c478bd9Sstevel@tonic-gate #define NBITSMAJOR32 14 /* # of SVR4 major device bits */ 5967c478bd9Sstevel@tonic-gate #define NBITSMINOR32 18 /* # of SVR4 minor device bits */ 5977c478bd9Sstevel@tonic-gate #define NMAXMAJ32 0x3fff /* SVR4 max major value */ 5987c478bd9Sstevel@tonic-gate #define NMAXMIN32 0x3ffff /* MAX minor for 3b2 software drivers. */ 5997c478bd9Sstevel@tonic-gate 6007c478bd9Sstevel@tonic-gate 6017c478bd9Sstevel@tonic-gate static int32_t 6027c478bd9Sstevel@tonic-gate minor_64(uint64_t dev) 6037c478bd9Sstevel@tonic-gate { 6047c478bd9Sstevel@tonic-gate if (dev == NODEV) { 6057c478bd9Sstevel@tonic-gate errno = EINVAL; 6067c478bd9Sstevel@tonic-gate return (NODEV); 6077c478bd9Sstevel@tonic-gate } 6087c478bd9Sstevel@tonic-gate return (int32_t)(dev & MAXMIN64); 6097c478bd9Sstevel@tonic-gate } 6107c478bd9Sstevel@tonic-gate 6117c478bd9Sstevel@tonic-gate static int32_t 6127c478bd9Sstevel@tonic-gate major_64(uint64_t dev) 6137c478bd9Sstevel@tonic-gate { 6147c478bd9Sstevel@tonic-gate uint32_t maj; 6157c478bd9Sstevel@tonic-gate 6167c478bd9Sstevel@tonic-gate maj = (uint32_t)(dev >> NBITSMINOR64); 6177c478bd9Sstevel@tonic-gate 6187c478bd9Sstevel@tonic-gate if (dev == NODEV || maj > MAXMAJ64) { 6197c478bd9Sstevel@tonic-gate errno = EINVAL; 6207c478bd9Sstevel@tonic-gate return (NODEV); 6217c478bd9Sstevel@tonic-gate } 6227c478bd9Sstevel@tonic-gate return (int32_t)(maj); 6237c478bd9Sstevel@tonic-gate } 6247c478bd9Sstevel@tonic-gate 6257c478bd9Sstevel@tonic-gate static int32_t 6267c478bd9Sstevel@tonic-gate minor_32(uint32_t dev) 6277c478bd9Sstevel@tonic-gate { 6287c478bd9Sstevel@tonic-gate if (dev == NODEV) { 6297c478bd9Sstevel@tonic-gate errno = EINVAL; 6307c478bd9Sstevel@tonic-gate return (NODEV); 6317c478bd9Sstevel@tonic-gate } 6327c478bd9Sstevel@tonic-gate return (int32_t)(dev & MAXMIN32); 6337c478bd9Sstevel@tonic-gate } 6347c478bd9Sstevel@tonic-gate 6357c478bd9Sstevel@tonic-gate static int32_t 6367c478bd9Sstevel@tonic-gate major_32(uint32_t dev) 6377c478bd9Sstevel@tonic-gate { 6387c478bd9Sstevel@tonic-gate uint32_t maj; 6397c478bd9Sstevel@tonic-gate 6407c478bd9Sstevel@tonic-gate maj = (uint32_t)(dev >> NBITSMINOR32); 6417c478bd9Sstevel@tonic-gate 6427c478bd9Sstevel@tonic-gate if (dev == NODEV || maj > MAXMAJ32) { 6437c478bd9Sstevel@tonic-gate errno = EINVAL; 6447c478bd9Sstevel@tonic-gate return (NODEV); 6457c478bd9Sstevel@tonic-gate } 6467c478bd9Sstevel@tonic-gate return (int32_t)(maj); 6477c478bd9Sstevel@tonic-gate } 6487c478bd9Sstevel@tonic-gate 6497c478bd9Sstevel@tonic-gate 6507c478bd9Sstevel@tonic-gate /* 6517c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 6527c478bd9Sstevel@tonic-gate * pa_tid() : Process terminal id and display contents 6537c478bd9Sstevel@tonic-gate * return codes : -1 - error 6547c478bd9Sstevel@tonic-gate * : 0 - successful 6557c478bd9Sstevel@tonic-gate * 6567c478bd9Sstevel@tonic-gate * terminal id port adr_int32 6577c478bd9Sstevel@tonic-gate * terminal id machine adr_int32 6587c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 6597c478bd9Sstevel@tonic-gate */ 6607c478bd9Sstevel@tonic-gate int 6617c478bd9Sstevel@tonic-gate pa_tid32(pr_context_t *context, int status, int flag) 6627c478bd9Sstevel@tonic-gate { 6637c478bd9Sstevel@tonic-gate int returnstat; 6647c478bd9Sstevel@tonic-gate int32_t dev_maj_min; 6657c478bd9Sstevel@tonic-gate uint32_t ip_addr; 6667c478bd9Sstevel@tonic-gate struct in_addr ia; 6677c478bd9Sstevel@tonic-gate char *ipstring; 6687c478bd9Sstevel@tonic-gate char buf[256]; 6697c478bd9Sstevel@tonic-gate uval_t uval; 6707c478bd9Sstevel@tonic-gate 6717c478bd9Sstevel@tonic-gate if (status < 0) 6727c478bd9Sstevel@tonic-gate return (status); 6737c478bd9Sstevel@tonic-gate 6747c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_int32(context, &dev_maj_min, 1)) != 0) 6757c478bd9Sstevel@tonic-gate return (returnstat); 6767c478bd9Sstevel@tonic-gate 6777c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, (char *)&ip_addr, 4)) != 0) 6787c478bd9Sstevel@tonic-gate return (returnstat); 6797c478bd9Sstevel@tonic-gate 6807c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 6817c478bd9Sstevel@tonic-gate uval.string_val = buf; 6827c478bd9Sstevel@tonic-gate 6837c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 6847c478bd9Sstevel@tonic-gate char hostname[256]; 6857c478bd9Sstevel@tonic-gate 6867c478bd9Sstevel@tonic-gate get_Hname(ip_addr, hostname, sizeof (hostname)); 6877c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s", 6887c478bd9Sstevel@tonic-gate major_32(dev_maj_min), 6897c478bd9Sstevel@tonic-gate minor_32(dev_maj_min), 6907c478bd9Sstevel@tonic-gate hostname); 6917c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 6927c478bd9Sstevel@tonic-gate } 6937c478bd9Sstevel@tonic-gate 6947c478bd9Sstevel@tonic-gate ia.s_addr = ip_addr; 6957c478bd9Sstevel@tonic-gate if ((ipstring = inet_ntoa(ia)) == NULL) 6967c478bd9Sstevel@tonic-gate return (-1); 6977c478bd9Sstevel@tonic-gate 6987c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s", 6997c478bd9Sstevel@tonic-gate major_32(dev_maj_min), 7007c478bd9Sstevel@tonic-gate minor_32(dev_maj_min), 7017c478bd9Sstevel@tonic-gate ipstring); 7027c478bd9Sstevel@tonic-gate 7037c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 7047c478bd9Sstevel@tonic-gate } 7057c478bd9Sstevel@tonic-gate 7067c478bd9Sstevel@tonic-gate int 7077c478bd9Sstevel@tonic-gate pa_tid32_ex(pr_context_t *context, int status, int flag) 7087c478bd9Sstevel@tonic-gate { 7097c478bd9Sstevel@tonic-gate int returnstat; 7107c478bd9Sstevel@tonic-gate int32_t dev_maj_min; 7117c478bd9Sstevel@tonic-gate uint32_t ip_addr[16]; 7127c478bd9Sstevel@tonic-gate uint32_t ip_type; 7137c478bd9Sstevel@tonic-gate struct in_addr ia; 7147c478bd9Sstevel@tonic-gate char *ipstring; 7157c478bd9Sstevel@tonic-gate char hostname[256]; 7167c478bd9Sstevel@tonic-gate char buf[256]; 7177c478bd9Sstevel@tonic-gate char tbuf[256]; 7187c478bd9Sstevel@tonic-gate uval_t uval; 7197c478bd9Sstevel@tonic-gate 7207c478bd9Sstevel@tonic-gate if (status < 0) 7217c478bd9Sstevel@tonic-gate return (status); 7227c478bd9Sstevel@tonic-gate 7237c478bd9Sstevel@tonic-gate /* get port info */ 7247c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_int32(context, &dev_maj_min, 1)) != 0) 7257c478bd9Sstevel@tonic-gate return (returnstat); 7267c478bd9Sstevel@tonic-gate 7277c478bd9Sstevel@tonic-gate /* get address type */ 7287c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_int32(context, &ip_type, 1)) != 0) 7297c478bd9Sstevel@tonic-gate return (returnstat); 7307c478bd9Sstevel@tonic-gate 7317c478bd9Sstevel@tonic-gate /* legal address types are either AU_IPv4 or AU_IPv6 only */ 7327c478bd9Sstevel@tonic-gate if ((ip_type != AU_IPv4) && (ip_type != AU_IPv6)) 7337c478bd9Sstevel@tonic-gate return (-1); 7347c478bd9Sstevel@tonic-gate 7357c478bd9Sstevel@tonic-gate /* get address (4/16) */ 7367c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, (char *)ip_addr, ip_type)) != 0) 7377c478bd9Sstevel@tonic-gate return (returnstat); 7387c478bd9Sstevel@tonic-gate 7397c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 7407c478bd9Sstevel@tonic-gate if (ip_type == AU_IPv4) { 7417c478bd9Sstevel@tonic-gate uval.string_val = buf; 7427c478bd9Sstevel@tonic-gate 7437c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 7447c478bd9Sstevel@tonic-gate get_Hname(ip_addr[0], hostname, sizeof (hostname)); 7457c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s", 7467c478bd9Sstevel@tonic-gate major_32(dev_maj_min), 7477c478bd9Sstevel@tonic-gate minor_32(dev_maj_min), 7487c478bd9Sstevel@tonic-gate hostname); 7497c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 7507c478bd9Sstevel@tonic-gate } 7517c478bd9Sstevel@tonic-gate 7527c478bd9Sstevel@tonic-gate ia.s_addr = ip_addr[0]; 7537c478bd9Sstevel@tonic-gate if ((ipstring = inet_ntoa(ia)) == NULL) 7547c478bd9Sstevel@tonic-gate return (-1); 7557c478bd9Sstevel@tonic-gate 7567c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s", 7577c478bd9Sstevel@tonic-gate major_32(dev_maj_min), 7587c478bd9Sstevel@tonic-gate minor_32(dev_maj_min), 7597c478bd9Sstevel@tonic-gate ipstring); 7607c478bd9Sstevel@tonic-gate 7617c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 7627c478bd9Sstevel@tonic-gate } else { 7637c478bd9Sstevel@tonic-gate uval.string_val = buf; 7647c478bd9Sstevel@tonic-gate 7657c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 7667c478bd9Sstevel@tonic-gate get_Hname_ex(ip_addr, hostname, sizeof (hostname)); 7677c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s", 7687c478bd9Sstevel@tonic-gate major_32(dev_maj_min), 7697c478bd9Sstevel@tonic-gate minor_32(dev_maj_min), 7707c478bd9Sstevel@tonic-gate hostname); 7717c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 7727c478bd9Sstevel@tonic-gate } 7737c478bd9Sstevel@tonic-gate 7747c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET6, (void *) ip_addr, tbuf, 7757c478bd9Sstevel@tonic-gate sizeof (tbuf)); 7767c478bd9Sstevel@tonic-gate 7777c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s", 7787c478bd9Sstevel@tonic-gate major_32(dev_maj_min), 7797c478bd9Sstevel@tonic-gate minor_32(dev_maj_min), 7807c478bd9Sstevel@tonic-gate tbuf); 7817c478bd9Sstevel@tonic-gate 7827c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 7837c478bd9Sstevel@tonic-gate } 7847c478bd9Sstevel@tonic-gate } 7857c478bd9Sstevel@tonic-gate 7867c478bd9Sstevel@tonic-gate int 7877c478bd9Sstevel@tonic-gate pa_ip_addr(pr_context_t *context, int status, int flag) 7887c478bd9Sstevel@tonic-gate { 7897c478bd9Sstevel@tonic-gate int returnstat; 7907c478bd9Sstevel@tonic-gate uval_t uval; 7917c478bd9Sstevel@tonic-gate uint32_t ip_addr[4]; 7927c478bd9Sstevel@tonic-gate uint32_t ip_type; 7937c478bd9Sstevel@tonic-gate struct in_addr ia; 7947c478bd9Sstevel@tonic-gate char *ipstring; 7957c478bd9Sstevel@tonic-gate char hostname[256]; 7967c478bd9Sstevel@tonic-gate char buf[256]; 7977c478bd9Sstevel@tonic-gate char tbuf[256]; 7987c478bd9Sstevel@tonic-gate 7997c478bd9Sstevel@tonic-gate if (status < 0) 8007c478bd9Sstevel@tonic-gate return (status); 8017c478bd9Sstevel@tonic-gate 8027c478bd9Sstevel@tonic-gate /* get address type */ 8037c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_int32(context, &ip_type, 1)) != 0) 8047c478bd9Sstevel@tonic-gate return (returnstat); 8057c478bd9Sstevel@tonic-gate 8067c478bd9Sstevel@tonic-gate /* legal address type is AU_IPv4 or AU_IPv6 */ 8077c478bd9Sstevel@tonic-gate if ((ip_type != AU_IPv4) && (ip_type != AU_IPv6)) 8087c478bd9Sstevel@tonic-gate return (-1); 8097c478bd9Sstevel@tonic-gate 8107c478bd9Sstevel@tonic-gate /* get address (4/16) */ 8117c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, (char *)ip_addr, ip_type)) != 0) 8127c478bd9Sstevel@tonic-gate return (returnstat); 8137c478bd9Sstevel@tonic-gate 8147c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 8157c478bd9Sstevel@tonic-gate if (ip_type == AU_IPv4) { 8167c478bd9Sstevel@tonic-gate uval.string_val = buf; 8177c478bd9Sstevel@tonic-gate 8187c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 8197c478bd9Sstevel@tonic-gate get_Hname(ip_addr[0], hostname, sizeof (hostname)); 8207c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%s", 8217c478bd9Sstevel@tonic-gate hostname); 8227c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 8237c478bd9Sstevel@tonic-gate } 8247c478bd9Sstevel@tonic-gate 8257c478bd9Sstevel@tonic-gate ia.s_addr = ip_addr[0]; 8267c478bd9Sstevel@tonic-gate if ((ipstring = inet_ntoa(ia)) == NULL) 8277c478bd9Sstevel@tonic-gate return (-1); 8287c478bd9Sstevel@tonic-gate 8297c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%s", 8307c478bd9Sstevel@tonic-gate ipstring); 8317c478bd9Sstevel@tonic-gate 8327c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 8337c478bd9Sstevel@tonic-gate } else { 8347c478bd9Sstevel@tonic-gate uval.string_val = buf; 8357c478bd9Sstevel@tonic-gate 8367c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 8377c478bd9Sstevel@tonic-gate get_Hname_ex(ip_addr, hostname, sizeof (hostname)); 8387c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%s", 8397c478bd9Sstevel@tonic-gate hostname); 8407c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 8417c478bd9Sstevel@tonic-gate } 8427c478bd9Sstevel@tonic-gate 8437c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET6, (void *) ip_addr, tbuf, 8447c478bd9Sstevel@tonic-gate sizeof (tbuf)); 8457c478bd9Sstevel@tonic-gate 8467c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%s", tbuf); 8477c478bd9Sstevel@tonic-gate 8487c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 8497c478bd9Sstevel@tonic-gate } 8507c478bd9Sstevel@tonic-gate 8517c478bd9Sstevel@tonic-gate } 8527c478bd9Sstevel@tonic-gate 8537c478bd9Sstevel@tonic-gate int 8547c478bd9Sstevel@tonic-gate pa_tid64(pr_context_t *context, int status, int flag) 8557c478bd9Sstevel@tonic-gate { 8567c478bd9Sstevel@tonic-gate int returnstat; 8577c478bd9Sstevel@tonic-gate int64_t dev_maj_min; 8587c478bd9Sstevel@tonic-gate uint32_t ip_addr; 8597c478bd9Sstevel@tonic-gate struct in_addr ia; 8607c478bd9Sstevel@tonic-gate char *ipstring; 8617c478bd9Sstevel@tonic-gate char buf[256]; 8627c478bd9Sstevel@tonic-gate uval_t uval; 8637c478bd9Sstevel@tonic-gate 8647c478bd9Sstevel@tonic-gate if (status < 0) 8657c478bd9Sstevel@tonic-gate return (status); 8667c478bd9Sstevel@tonic-gate 8677c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_int64(context, &dev_maj_min, 1)) != 0) 8687c478bd9Sstevel@tonic-gate return (returnstat); 8697c478bd9Sstevel@tonic-gate 8707c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, (char *)&ip_addr, 4)) != 0) 8717c478bd9Sstevel@tonic-gate return (returnstat); 8727c478bd9Sstevel@tonic-gate 8737c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 8747c478bd9Sstevel@tonic-gate uval.string_val = buf; 8757c478bd9Sstevel@tonic-gate 8767c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 8777c478bd9Sstevel@tonic-gate char hostname[256]; 8787c478bd9Sstevel@tonic-gate 8797c478bd9Sstevel@tonic-gate get_Hname(ip_addr, hostname, sizeof (hostname)); 8807c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s", 8817c478bd9Sstevel@tonic-gate major_64(dev_maj_min), 8827c478bd9Sstevel@tonic-gate minor_64(dev_maj_min), 8837c478bd9Sstevel@tonic-gate hostname); 8847c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 8857c478bd9Sstevel@tonic-gate } 8867c478bd9Sstevel@tonic-gate 8877c478bd9Sstevel@tonic-gate ia.s_addr = ip_addr; 8887c478bd9Sstevel@tonic-gate if ((ipstring = inet_ntoa(ia)) == NULL) 8897c478bd9Sstevel@tonic-gate return (-1); 8907c478bd9Sstevel@tonic-gate 8917c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s", 8927c478bd9Sstevel@tonic-gate major_64(dev_maj_min), 8937c478bd9Sstevel@tonic-gate minor_64(dev_maj_min), 8947c478bd9Sstevel@tonic-gate ipstring); 8957c478bd9Sstevel@tonic-gate 8967c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 8977c478bd9Sstevel@tonic-gate } 8987c478bd9Sstevel@tonic-gate 8997c478bd9Sstevel@tonic-gate int 9007c478bd9Sstevel@tonic-gate pa_tid64_ex(pr_context_t *context, int status, int flag) 9017c478bd9Sstevel@tonic-gate { 9027c478bd9Sstevel@tonic-gate int returnstat; 9037c478bd9Sstevel@tonic-gate int64_t dev_maj_min; 9047c478bd9Sstevel@tonic-gate uint32_t ip_addr[4]; 9057c478bd9Sstevel@tonic-gate uint32_t ip_type; 9067c478bd9Sstevel@tonic-gate struct in_addr ia; 9077c478bd9Sstevel@tonic-gate char *ipstring; 9087c478bd9Sstevel@tonic-gate char hostname[256]; 9097c478bd9Sstevel@tonic-gate char buf[256]; 9107c478bd9Sstevel@tonic-gate char tbuf[256]; 9117c478bd9Sstevel@tonic-gate uval_t uval; 9127c478bd9Sstevel@tonic-gate 9137c478bd9Sstevel@tonic-gate if (status < 0) 9147c478bd9Sstevel@tonic-gate return (status); 9157c478bd9Sstevel@tonic-gate 9167c478bd9Sstevel@tonic-gate /* get port info */ 9177c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_int64(context, &dev_maj_min, 1)) != 0) 9187c478bd9Sstevel@tonic-gate return (returnstat); 9197c478bd9Sstevel@tonic-gate 9207c478bd9Sstevel@tonic-gate /* get address type */ 9217c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_int32(context, &ip_type, 1)) != 0) 9227c478bd9Sstevel@tonic-gate return (returnstat); 9237c478bd9Sstevel@tonic-gate 9247c478bd9Sstevel@tonic-gate /* legal address types are either AU_IPv4 or AU_IPv6 only */ 9257c478bd9Sstevel@tonic-gate if ((ip_type != AU_IPv4) && (ip_type != AU_IPv6)) 9267c478bd9Sstevel@tonic-gate return (-1); 9277c478bd9Sstevel@tonic-gate 9287c478bd9Sstevel@tonic-gate /* get address (4/16) */ 9297c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, (char *)&ip_addr, ip_type)) != 0) 9307c478bd9Sstevel@tonic-gate return (returnstat); 9317c478bd9Sstevel@tonic-gate 9327c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 9337c478bd9Sstevel@tonic-gate if (ip_type == AU_IPv4) { 9347c478bd9Sstevel@tonic-gate uval.string_val = buf; 9357c478bd9Sstevel@tonic-gate 9367c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 9377c478bd9Sstevel@tonic-gate get_Hname(ip_addr[0], hostname, sizeof (hostname)); 9387c478bd9Sstevel@tonic-gate uval.string_val = buf; 9397c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s", 9407c478bd9Sstevel@tonic-gate major_64(dev_maj_min), 9417c478bd9Sstevel@tonic-gate minor_64(dev_maj_min), 9427c478bd9Sstevel@tonic-gate hostname); 9437c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 9447c478bd9Sstevel@tonic-gate } 9457c478bd9Sstevel@tonic-gate 9467c478bd9Sstevel@tonic-gate ia.s_addr = ip_addr[0]; 9477c478bd9Sstevel@tonic-gate if ((ipstring = inet_ntoa(ia)) == NULL) 9487c478bd9Sstevel@tonic-gate return (-1); 9497c478bd9Sstevel@tonic-gate 9507c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s", 9517c478bd9Sstevel@tonic-gate major_64(dev_maj_min), 9527c478bd9Sstevel@tonic-gate minor_64(dev_maj_min), 9537c478bd9Sstevel@tonic-gate ipstring); 9547c478bd9Sstevel@tonic-gate 9557c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 9567c478bd9Sstevel@tonic-gate } else { 9577c478bd9Sstevel@tonic-gate uval.string_val = buf; 9587c478bd9Sstevel@tonic-gate 9597c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 9607c478bd9Sstevel@tonic-gate get_Hname_ex(ip_addr, hostname, sizeof (hostname)); 9617c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s", 9627c478bd9Sstevel@tonic-gate major_64(dev_maj_min), 9637c478bd9Sstevel@tonic-gate minor_64(dev_maj_min), 9647c478bd9Sstevel@tonic-gate hostname); 9657c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 9667c478bd9Sstevel@tonic-gate } 9677c478bd9Sstevel@tonic-gate 9687c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET6, (void *)ip_addr, tbuf, 9697c478bd9Sstevel@tonic-gate sizeof (tbuf)); 9707c478bd9Sstevel@tonic-gate 9717c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s", 9727c478bd9Sstevel@tonic-gate major_64(dev_maj_min), 9737c478bd9Sstevel@tonic-gate minor_64(dev_maj_min), 9747c478bd9Sstevel@tonic-gate tbuf); 9757c478bd9Sstevel@tonic-gate 9767c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 9777c478bd9Sstevel@tonic-gate } 9787c478bd9Sstevel@tonic-gate } 9797c478bd9Sstevel@tonic-gate 9807c478bd9Sstevel@tonic-gate 9817c478bd9Sstevel@tonic-gate /* 9827c478bd9Sstevel@tonic-gate * ---------------------------------------------------------------- 9837c478bd9Sstevel@tonic-gate * findfieldwidth: 9847c478bd9Sstevel@tonic-gate * Returns the field width based on the basic unit and print mode. 9857c478bd9Sstevel@tonic-gate * This routine is called to determine the field width for the 9867c478bd9Sstevel@tonic-gate * data items in the arbitrary data token where the tokens are 9877c478bd9Sstevel@tonic-gate * to be printed in more than one line. The field width can be 9887c478bd9Sstevel@tonic-gate * found in the fwidth structure. 9897c478bd9Sstevel@tonic-gate * 9907c478bd9Sstevel@tonic-gate * Input parameters: 9917c478bd9Sstevel@tonic-gate * basicunit Can be one of AUR_CHAR, AUR_BYTE, AUR_SHORT, 9927c478bd9Sstevel@tonic-gate * AUR_INT32, or AUR_INT64 9937c478bd9Sstevel@tonic-gate * howtoprint Print mode. Can be one of AUP_BINARY, AUP_OCTAL, 9947c478bd9Sstevel@tonic-gate * AUP_DECIMAL, or AUP_HEX. 9957c478bd9Sstevel@tonic-gate * ---------------------------------------------------------------- 9967c478bd9Sstevel@tonic-gate */ 9977c478bd9Sstevel@tonic-gate int 9987c478bd9Sstevel@tonic-gate findfieldwidth(char basicunit, char howtoprint) 9997c478bd9Sstevel@tonic-gate { 10007c478bd9Sstevel@tonic-gate int i, j; 10017c478bd9Sstevel@tonic-gate 10027c478bd9Sstevel@tonic-gate for (i = 0; i < numwidthentries; i++) { 10037c478bd9Sstevel@tonic-gate if (fwidth[i].basic_unit == basicunit) { 10047c478bd9Sstevel@tonic-gate for (j = 0; j <= 4; j++) { 10057c478bd9Sstevel@tonic-gate if (fwidth[i].pwidth[j].print_base == 10067c478bd9Sstevel@tonic-gate howtoprint) 10077c478bd9Sstevel@tonic-gate return (fwidth[i].pwidth[j].field_width); 10087c478bd9Sstevel@tonic-gate } 10097c478bd9Sstevel@tonic-gate /* 10107c478bd9Sstevel@tonic-gate * if we got here, then we didn't get what we were after 10117c478bd9Sstevel@tonic-gate */ 10127c478bd9Sstevel@tonic-gate return (0); 10137c478bd9Sstevel@tonic-gate } 10147c478bd9Sstevel@tonic-gate } 10157c478bd9Sstevel@tonic-gate /* if we got here, we didn't get what we wanted either */ 10167c478bd9Sstevel@tonic-gate return (0); 10177c478bd9Sstevel@tonic-gate } 10187c478bd9Sstevel@tonic-gate 10197c478bd9Sstevel@tonic-gate 10207c478bd9Sstevel@tonic-gate /* 10217c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 10227c478bd9Sstevel@tonic-gate * pa_cmd: Retrieves the cmd item from the input stream. 10237c478bd9Sstevel@tonic-gate * return codes : -1 - error 10247c478bd9Sstevel@tonic-gate * : 0 - successful 10257c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 10267c478bd9Sstevel@tonic-gate */ 10277c478bd9Sstevel@tonic-gate int 10287c478bd9Sstevel@tonic-gate pa_cmd(pr_context_t *context, int status, int flag) 10297c478bd9Sstevel@tonic-gate { 10307c478bd9Sstevel@tonic-gate char *cmd; /* cmd */ 10317c478bd9Sstevel@tonic-gate short length; 10327c478bd9Sstevel@tonic-gate int returnstat; 10337c478bd9Sstevel@tonic-gate uval_t uval; 10347c478bd9Sstevel@tonic-gate 10357c478bd9Sstevel@tonic-gate /* 10367c478bd9Sstevel@tonic-gate * We need to know how much space to allocate for our string, so 10377c478bd9Sstevel@tonic-gate * read the length first, then call pr_adr_char to read those bytes. 10387c478bd9Sstevel@tonic-gate */ 10397c478bd9Sstevel@tonic-gate if (status >= 0) { 10407c478bd9Sstevel@tonic-gate if (pr_adr_short(context, &length, 1) == 0) { 10417c478bd9Sstevel@tonic-gate if ((cmd = (char *)malloc(length + 1)) == NULL) 10427c478bd9Sstevel@tonic-gate return (-1); 10437c478bd9Sstevel@tonic-gate if (pr_adr_char(context, cmd, length) == 0) { 10447c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 10457c478bd9Sstevel@tonic-gate uval.string_val = cmd; 10467c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 10477c478bd9Sstevel@tonic-gate } else { 10487c478bd9Sstevel@tonic-gate returnstat = -1; 10497c478bd9Sstevel@tonic-gate } 10507c478bd9Sstevel@tonic-gate free(cmd); 10517c478bd9Sstevel@tonic-gate return (returnstat); 10527c478bd9Sstevel@tonic-gate } else 10537c478bd9Sstevel@tonic-gate return (-1); 10547c478bd9Sstevel@tonic-gate } else 10557c478bd9Sstevel@tonic-gate return (status); 10567c478bd9Sstevel@tonic-gate } 10577c478bd9Sstevel@tonic-gate 10587c478bd9Sstevel@tonic-gate 10597c478bd9Sstevel@tonic-gate 10607c478bd9Sstevel@tonic-gate /* 10617c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 10627c478bd9Sstevel@tonic-gate * pa_adr_byte : Issues pr_adr_char to retrieve the next ADR item from 10637c478bd9Sstevel@tonic-gate * the input stream pointed to by audit_adr, and prints it 10647c478bd9Sstevel@tonic-gate * as an integer if status >= 0 10657c478bd9Sstevel@tonic-gate * return codes : -1 - error 10667c478bd9Sstevel@tonic-gate * : 0 - successful 10677c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 10687c478bd9Sstevel@tonic-gate */ 10697c478bd9Sstevel@tonic-gate int 10707c478bd9Sstevel@tonic-gate pa_adr_byte(pr_context_t *context, int status, int flag) 10717c478bd9Sstevel@tonic-gate { 10727c478bd9Sstevel@tonic-gate char c; 10737c478bd9Sstevel@tonic-gate uval_t uval; 10747c478bd9Sstevel@tonic-gate 10757c478bd9Sstevel@tonic-gate if (status >= 0) { 10767c478bd9Sstevel@tonic-gate if (pr_adr_char(context, &c, 1) == 0) { 10777c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_BYTE; 10787c478bd9Sstevel@tonic-gate uval.char_val = c; 10797c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 10807c478bd9Sstevel@tonic-gate } else 10817c478bd9Sstevel@tonic-gate return (-1); 10827c478bd9Sstevel@tonic-gate } else 10837c478bd9Sstevel@tonic-gate return (status); 10847c478bd9Sstevel@tonic-gate } 10857c478bd9Sstevel@tonic-gate 10867c478bd9Sstevel@tonic-gate /* 10877c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 10887c478bd9Sstevel@tonic-gate * pa_adr_charhex: Issues pr_adr_char to retrieve the next ADR item from 10897c478bd9Sstevel@tonic-gate * the input stream pointed to by audit_adr, and prints it 10907c478bd9Sstevel@tonic-gate * in hexadecimal if status >= 0 10917c478bd9Sstevel@tonic-gate * return codes : -1 - error 10927c478bd9Sstevel@tonic-gate * : 0 - successful 10937c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 10947c478bd9Sstevel@tonic-gate */ 10957c478bd9Sstevel@tonic-gate int 10967c478bd9Sstevel@tonic-gate pa_adr_charhex(pr_context_t *context, int status, int flag) 10977c478bd9Sstevel@tonic-gate { 10987c478bd9Sstevel@tonic-gate char p[2]; 10997c478bd9Sstevel@tonic-gate int returnstat; 11007c478bd9Sstevel@tonic-gate uval_t uval; 11017c478bd9Sstevel@tonic-gate 11027c478bd9Sstevel@tonic-gate if (status >= 0) { 11037c478bd9Sstevel@tonic-gate p[0] = p[1] = 0; 11047c478bd9Sstevel@tonic-gate 11057c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, p, 1)) == 0) { 11067c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 11077c478bd9Sstevel@tonic-gate uval.string_val = hexconvert(p, sizeof (char), 11087c478bd9Sstevel@tonic-gate sizeof (char)); 11097c478bd9Sstevel@tonic-gate if (uval.string_val) { 11107c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 11117c478bd9Sstevel@tonic-gate free(uval.string_val); 11127c478bd9Sstevel@tonic-gate } 11137c478bd9Sstevel@tonic-gate } 11147c478bd9Sstevel@tonic-gate return (returnstat); 11157c478bd9Sstevel@tonic-gate } else 11167c478bd9Sstevel@tonic-gate return (status); 11177c478bd9Sstevel@tonic-gate } 11187c478bd9Sstevel@tonic-gate 11197c478bd9Sstevel@tonic-gate /* 11207c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 11217c478bd9Sstevel@tonic-gate * pa_adr_int32 : Issues pr_adr_int32 to retrieve the next ADR item from the 11227c478bd9Sstevel@tonic-gate * input stream pointed to by audit_adr, and prints it 11237c478bd9Sstevel@tonic-gate * if status >= 0 11247c478bd9Sstevel@tonic-gate * return codes : -1 - error 11257c478bd9Sstevel@tonic-gate * : 0 - successful 11267c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 11277c478bd9Sstevel@tonic-gate */ 11287c478bd9Sstevel@tonic-gate int 11297c478bd9Sstevel@tonic-gate pa_adr_int32(pr_context_t *context, int status, int flag) 11307c478bd9Sstevel@tonic-gate { 11317c478bd9Sstevel@tonic-gate int32_t c; 11327c478bd9Sstevel@tonic-gate uval_t uval; 11337c478bd9Sstevel@tonic-gate 11347c478bd9Sstevel@tonic-gate if (status >= 0) { 11357c478bd9Sstevel@tonic-gate if (pr_adr_int32(context, &c, 1) == 0) { 11367c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_INT32; 11377c478bd9Sstevel@tonic-gate uval.int32_val = c; 11387c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 11397c478bd9Sstevel@tonic-gate } else 11407c478bd9Sstevel@tonic-gate return (-1); 11417c478bd9Sstevel@tonic-gate } else 11427c478bd9Sstevel@tonic-gate return (status); 11437c478bd9Sstevel@tonic-gate } 11447c478bd9Sstevel@tonic-gate 11457c478bd9Sstevel@tonic-gate 11467c478bd9Sstevel@tonic-gate 11477c478bd9Sstevel@tonic-gate 11487c478bd9Sstevel@tonic-gate /* 11497c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 11507c478bd9Sstevel@tonic-gate * pa_adr_int64 : Issues pr_adr_int64 to retrieve the next ADR item from the 11517c478bd9Sstevel@tonic-gate * input stream pointed to by audit_adr, and prints it 11527c478bd9Sstevel@tonic-gate * if status >= 0 11537c478bd9Sstevel@tonic-gate * return codes : -1 - error 11547c478bd9Sstevel@tonic-gate * : 0 - successful 11557c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 11567c478bd9Sstevel@tonic-gate */ 11577c478bd9Sstevel@tonic-gate int 11587c478bd9Sstevel@tonic-gate pa_adr_int64(pr_context_t *context, int status, int flag) 11597c478bd9Sstevel@tonic-gate { 11607c478bd9Sstevel@tonic-gate int64_t c; 11617c478bd9Sstevel@tonic-gate uval_t uval; 11627c478bd9Sstevel@tonic-gate 11637c478bd9Sstevel@tonic-gate if (status >= 0) { 11647c478bd9Sstevel@tonic-gate if (pr_adr_int64(context, &c, 1) == 0) { 11657c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_INT64; 11667c478bd9Sstevel@tonic-gate uval.int64_val = c; 11677c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 11687c478bd9Sstevel@tonic-gate } else 11697c478bd9Sstevel@tonic-gate return (-1); 11707c478bd9Sstevel@tonic-gate } else 11717c478bd9Sstevel@tonic-gate return (status); 11727c478bd9Sstevel@tonic-gate } 11737c478bd9Sstevel@tonic-gate 11747c478bd9Sstevel@tonic-gate /* 11757c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 11767c478bd9Sstevel@tonic-gate * pa_adr_int64hex: Issues pr_adr_int64 to retrieve the next ADR item from the 11777c478bd9Sstevel@tonic-gate * input stream pointed to by audit_adr, and prints it 11787c478bd9Sstevel@tonic-gate * in hexadecimal if status >= 0 11797c478bd9Sstevel@tonic-gate * return codes : -1 - error 11807c478bd9Sstevel@tonic-gate * : 0 - successful 11817c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 11827c478bd9Sstevel@tonic-gate */ 11837c478bd9Sstevel@tonic-gate int 11847c478bd9Sstevel@tonic-gate pa_adr_int32hex(pr_context_t *context, int status, int flag) 11857c478bd9Sstevel@tonic-gate { 11867c478bd9Sstevel@tonic-gate int32_t l; 11877c478bd9Sstevel@tonic-gate int returnstat; 11887c478bd9Sstevel@tonic-gate uval_t uval; 11897c478bd9Sstevel@tonic-gate 11907c478bd9Sstevel@tonic-gate if (status >= 0) { 11917c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_int32(context, &l, 1)) == 0) { 11927c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_HEX32; 11937c478bd9Sstevel@tonic-gate uval.int32_val = l; 11947c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 11957c478bd9Sstevel@tonic-gate } 11967c478bd9Sstevel@tonic-gate return (returnstat); 11977c478bd9Sstevel@tonic-gate } else 11987c478bd9Sstevel@tonic-gate return (status); 11997c478bd9Sstevel@tonic-gate } 12007c478bd9Sstevel@tonic-gate 12017c478bd9Sstevel@tonic-gate /* 12027c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 12037c478bd9Sstevel@tonic-gate * pa_adr_int64hex: Issues pr_adr_int64 to retrieve the next ADR item from the 12047c478bd9Sstevel@tonic-gate * input stream pointed to by audit_adr, and prints it 12057c478bd9Sstevel@tonic-gate * in hexadecimal if status >= 0 12067c478bd9Sstevel@tonic-gate * return codes : -1 - error 12077c478bd9Sstevel@tonic-gate * : 0 - successful 12087c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 12097c478bd9Sstevel@tonic-gate */ 12107c478bd9Sstevel@tonic-gate int 12117c478bd9Sstevel@tonic-gate pa_adr_int64hex(pr_context_t *context, int status, int flag) 12127c478bd9Sstevel@tonic-gate { 12137c478bd9Sstevel@tonic-gate int64_t l; 12147c478bd9Sstevel@tonic-gate int returnstat; 12157c478bd9Sstevel@tonic-gate uval_t uval; 12167c478bd9Sstevel@tonic-gate 12177c478bd9Sstevel@tonic-gate if (status >= 0) { 12187c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_int64(context, &l, 1)) == 0) { 12197c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_HEX64; 12207c478bd9Sstevel@tonic-gate uval.int64_val = l; 12217c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 12227c478bd9Sstevel@tonic-gate } 12237c478bd9Sstevel@tonic-gate return (returnstat); 12247c478bd9Sstevel@tonic-gate } else 12257c478bd9Sstevel@tonic-gate return (status); 12267c478bd9Sstevel@tonic-gate } 12277c478bd9Sstevel@tonic-gate 12287c478bd9Sstevel@tonic-gate 12297c478bd9Sstevel@tonic-gate /* 12307c478bd9Sstevel@tonic-gate * ------------------------------------------------------------------- 12317c478bd9Sstevel@tonic-gate * bu2string: Maps a print basic unit type to a string. 12327c478bd9Sstevel@tonic-gate * returns : The string mapping or "unknown basic unit type". 12337c478bd9Sstevel@tonic-gate * ------------------------------------------------------------------- 12347c478bd9Sstevel@tonic-gate */ 12357c478bd9Sstevel@tonic-gate char * 12367c478bd9Sstevel@tonic-gate bu2string(char basic_unit) 12377c478bd9Sstevel@tonic-gate { 12387c478bd9Sstevel@tonic-gate register int i; 12397c478bd9Sstevel@tonic-gate 12407c478bd9Sstevel@tonic-gate struct bu_map_ent { 12417c478bd9Sstevel@tonic-gate char basic_unit; 12427c478bd9Sstevel@tonic-gate char *string; 12437c478bd9Sstevel@tonic-gate }; 12447c478bd9Sstevel@tonic-gate 12457c478bd9Sstevel@tonic-gate /* 12467c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE 12477c478bd9Sstevel@tonic-gate * These names are data units when displaying the arbitrary data 12487c478bd9Sstevel@tonic-gate * token. 12497c478bd9Sstevel@tonic-gate */ 12507c478bd9Sstevel@tonic-gate 12517c478bd9Sstevel@tonic-gate static struct bu_map_ent bu_map[] = { 12527c478bd9Sstevel@tonic-gate { AUR_BYTE, "byte" }, 12537c478bd9Sstevel@tonic-gate { AUR_CHAR, "char" }, 12547c478bd9Sstevel@tonic-gate { AUR_SHORT, "short" }, 12557c478bd9Sstevel@tonic-gate { AUR_INT32, "int32" }, 12567c478bd9Sstevel@tonic-gate { AUR_INT64, "int64" } }; 12577c478bd9Sstevel@tonic-gate 12587c478bd9Sstevel@tonic-gate for (i = 0; i < sizeof (bu_map) / sizeof (struct bu_map_ent); i++) 12597c478bd9Sstevel@tonic-gate if (basic_unit == bu_map[i].basic_unit) 12607c478bd9Sstevel@tonic-gate return (gettext(bu_map[i].string)); 12617c478bd9Sstevel@tonic-gate 12627c478bd9Sstevel@tonic-gate return (gettext("unknown basic unit type")); 12637c478bd9Sstevel@tonic-gate } 12647c478bd9Sstevel@tonic-gate 12657c478bd9Sstevel@tonic-gate 12667c478bd9Sstevel@tonic-gate /* 12677c478bd9Sstevel@tonic-gate * ------------------------------------------------------------------- 12687c478bd9Sstevel@tonic-gate * eventmodifier2string: Maps event modifier flags to a readable string. 12697c478bd9Sstevel@tonic-gate * returns: The string mapping or "none". 12707c478bd9Sstevel@tonic-gate * ------------------------------------------------------------------- 12717c478bd9Sstevel@tonic-gate */ 12727c478bd9Sstevel@tonic-gate static void 12737c478bd9Sstevel@tonic-gate eventmodifier2string(ushort_t emodifier, char *modstring, size_t modlen) 12747c478bd9Sstevel@tonic-gate { 12757c478bd9Sstevel@tonic-gate register int i, j; 12767c478bd9Sstevel@tonic-gate 12777c478bd9Sstevel@tonic-gate struct em_map_ent { 12787c478bd9Sstevel@tonic-gate int mask; 12797c478bd9Sstevel@tonic-gate char *string; 12807c478bd9Sstevel@tonic-gate }; 12817c478bd9Sstevel@tonic-gate 12827c478bd9Sstevel@tonic-gate /* 12837c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE 12847c478bd9Sstevel@tonic-gate * These abbreviations represent the event modifier field of the 12857c478bd9Sstevel@tonic-gate * header token. To gain a better understanding of each modifier, 12867c478bd9Sstevel@tonic-gate * read the SunShield BSM Guide, part no. 802-1965-xx. 12877c478bd9Sstevel@tonic-gate */ 12887c478bd9Sstevel@tonic-gate 12897c478bd9Sstevel@tonic-gate static struct em_map_ent em_map[] = { 12907c478bd9Sstevel@tonic-gate { (int)PAD_READ, "rd" }, /* data read from object */ 12917c478bd9Sstevel@tonic-gate { (int)PAD_WRITE, "wr" }, /* data written to object */ 12927c478bd9Sstevel@tonic-gate { (int)PAD_SPRIVUSE, "sp" }, /* successfully used priv */ 12937c478bd9Sstevel@tonic-gate { (int)PAD_FPRIVUSE, "fp" }, /* failed use of priv */ 12947c478bd9Sstevel@tonic-gate { (int)PAD_NONATTR, "na" }, /* non-attributable event */ 12957c478bd9Sstevel@tonic-gate { (int)PAD_FAILURE, "fe" } /* fail audit event */ 12967c478bd9Sstevel@tonic-gate }; 12977c478bd9Sstevel@tonic-gate 12987c478bd9Sstevel@tonic-gate modstring[0] = '\0'; 12997c478bd9Sstevel@tonic-gate 13007c478bd9Sstevel@tonic-gate for (i = 0, j = 0; i < sizeof (em_map) / sizeof (struct em_map_ent); 13017c478bd9Sstevel@tonic-gate i++) { 13027c478bd9Sstevel@tonic-gate if ((int)emodifier & em_map[i].mask) { 13037c478bd9Sstevel@tonic-gate if (j++) 13047c478bd9Sstevel@tonic-gate (void) strlcat(modstring, ":", modlen); 13057c478bd9Sstevel@tonic-gate (void) strlcat(modstring, em_map[i].string, modlen); 13067c478bd9Sstevel@tonic-gate } 13077c478bd9Sstevel@tonic-gate } 13087c478bd9Sstevel@tonic-gate } 13097c478bd9Sstevel@tonic-gate 13107c478bd9Sstevel@tonic-gate 13117c478bd9Sstevel@tonic-gate /* 13127c478bd9Sstevel@tonic-gate * --------------------------------------------------------- 13137c478bd9Sstevel@tonic-gate * convert_char_to_string: 13147c478bd9Sstevel@tonic-gate * Converts a byte to string depending on the print mode 13157c478bd9Sstevel@tonic-gate * input : printmode, which may be one of AUP_BINARY, 13167c478bd9Sstevel@tonic-gate * AUP_OCTAL, AUP_DECIMAL, and AUP_HEX 13177c478bd9Sstevel@tonic-gate * c, which is the byte to convert 13187c478bd9Sstevel@tonic-gate * output : p, which is a pointer to the location where 13197c478bd9Sstevel@tonic-gate * the resulting string is to be stored 13207c478bd9Sstevel@tonic-gate * ---------------------------------------------------------- 13217c478bd9Sstevel@tonic-gate */ 13227c478bd9Sstevel@tonic-gate 13237c478bd9Sstevel@tonic-gate int 13247c478bd9Sstevel@tonic-gate convert_char_to_string(char printmode, char c, char *p) 13257c478bd9Sstevel@tonic-gate { 13267c478bd9Sstevel@tonic-gate union { 13277c478bd9Sstevel@tonic-gate char c1[4]; 13287c478bd9Sstevel@tonic-gate int c2; 13297c478bd9Sstevel@tonic-gate } dat; 13307c478bd9Sstevel@tonic-gate 13317c478bd9Sstevel@tonic-gate dat.c2 = 0; 13327c478bd9Sstevel@tonic-gate dat.c1[3] = c; 13337c478bd9Sstevel@tonic-gate 13347c478bd9Sstevel@tonic-gate if (printmode == AUP_BINARY) 13357c478bd9Sstevel@tonic-gate (void) convertbinary(p, &c, sizeof (char)); 13367c478bd9Sstevel@tonic-gate else if (printmode == AUP_OCTAL) 13377c478bd9Sstevel@tonic-gate (void) sprintf(p, "%o", (int)dat.c2); 13387c478bd9Sstevel@tonic-gate else if (printmode == AUP_DECIMAL) 13397c478bd9Sstevel@tonic-gate (void) sprintf(p, "%d", c); 13407c478bd9Sstevel@tonic-gate else if (printmode == AUP_HEX) 13417c478bd9Sstevel@tonic-gate (void) sprintf(p, "0x%x", (int)dat.c2); 13427c478bd9Sstevel@tonic-gate else if (printmode == AUP_STRING) 13437c478bd9Sstevel@tonic-gate convertascii(p, &c, sizeof (char)); 13447c478bd9Sstevel@tonic-gate return (0); 13457c478bd9Sstevel@tonic-gate } 13467c478bd9Sstevel@tonic-gate 13477c478bd9Sstevel@tonic-gate /* 13487c478bd9Sstevel@tonic-gate * -------------------------------------------------------------- 13497c478bd9Sstevel@tonic-gate * convert_short_to_string: 13507c478bd9Sstevel@tonic-gate * Converts a short integer to string depending on the print mode 13517c478bd9Sstevel@tonic-gate * input : printmode, which may be one of AUP_BINARY, 13527c478bd9Sstevel@tonic-gate * AUP_OCTAL, AUP_DECIMAL, and AUP_HEX 13537c478bd9Sstevel@tonic-gate * c, which is the short integer to convert 13547c478bd9Sstevel@tonic-gate * output : p, which is a pointer to the location where 13557c478bd9Sstevel@tonic-gate * the resulting string is to be stored 13567c478bd9Sstevel@tonic-gate * --------------------------------------------------------------- 13577c478bd9Sstevel@tonic-gate */ 13587c478bd9Sstevel@tonic-gate int 13597c478bd9Sstevel@tonic-gate convert_short_to_string(char printmode, short c, char *p) 13607c478bd9Sstevel@tonic-gate { 13617c478bd9Sstevel@tonic-gate union { 13627c478bd9Sstevel@tonic-gate short c1[2]; 13637c478bd9Sstevel@tonic-gate int c2; 13647c478bd9Sstevel@tonic-gate } dat; 13657c478bd9Sstevel@tonic-gate 13667c478bd9Sstevel@tonic-gate dat.c2 = 0; 13677c478bd9Sstevel@tonic-gate dat.c1[1] = c; 13687c478bd9Sstevel@tonic-gate 13697c478bd9Sstevel@tonic-gate if (printmode == AUP_BINARY) 13707c478bd9Sstevel@tonic-gate (void) convertbinary(p, (char *)&c, sizeof (short)); 13717c478bd9Sstevel@tonic-gate else if (printmode == AUP_OCTAL) 13727c478bd9Sstevel@tonic-gate (void) sprintf(p, "%o", (int)dat.c2); 13737c478bd9Sstevel@tonic-gate else if (printmode == AUP_DECIMAL) 13747c478bd9Sstevel@tonic-gate (void) sprintf(p, "%hd", c); 13757c478bd9Sstevel@tonic-gate else if (printmode == AUP_HEX) 13767c478bd9Sstevel@tonic-gate (void) sprintf(p, "0x%x", (int)dat.c2); 13777c478bd9Sstevel@tonic-gate else if (printmode == AUP_STRING) 13787c478bd9Sstevel@tonic-gate convertascii(p, (char *)&c, sizeof (short)); 13797c478bd9Sstevel@tonic-gate return (0); 13807c478bd9Sstevel@tonic-gate } 13817c478bd9Sstevel@tonic-gate 13827c478bd9Sstevel@tonic-gate /* 13837c478bd9Sstevel@tonic-gate * --------------------------------------------------------- 13847c478bd9Sstevel@tonic-gate * convert_int32_to_string: 13857c478bd9Sstevel@tonic-gate * Converts a integer to string depending on the print mode 13867c478bd9Sstevel@tonic-gate * input : printmode, which may be one of AUP_BINARY, 13877c478bd9Sstevel@tonic-gate * AUP_OCTAL, AUP_DECIMAL, and AUP_HEX 13887c478bd9Sstevel@tonic-gate * c, which is the integer to convert 13897c478bd9Sstevel@tonic-gate * output : p, which is a pointer to the location where 13907c478bd9Sstevel@tonic-gate * the resulting string is to be stored 13917c478bd9Sstevel@tonic-gate * ---------------------------------------------------------- 13927c478bd9Sstevel@tonic-gate */ 13937c478bd9Sstevel@tonic-gate int 13947c478bd9Sstevel@tonic-gate convert_int32_to_string(char printmode, int32_t c, char *p) 13957c478bd9Sstevel@tonic-gate { 13967c478bd9Sstevel@tonic-gate if (printmode == AUP_BINARY) 13977c478bd9Sstevel@tonic-gate (void) convertbinary(p, (char *)&c, sizeof (int32_t)); 13987c478bd9Sstevel@tonic-gate else if (printmode == AUP_OCTAL) 13997c478bd9Sstevel@tonic-gate (void) sprintf(p, "%o", c); 14007c478bd9Sstevel@tonic-gate else if (printmode == AUP_DECIMAL) 14017c478bd9Sstevel@tonic-gate (void) sprintf(p, "%d", c); 14027c478bd9Sstevel@tonic-gate else if (printmode == AUP_HEX) 14037c478bd9Sstevel@tonic-gate (void) sprintf(p, "0x%x", c); 14047c478bd9Sstevel@tonic-gate else if (printmode == AUP_STRING) 14057c478bd9Sstevel@tonic-gate convertascii(p, (char *)&c, sizeof (int)); 14067c478bd9Sstevel@tonic-gate return (0); 14077c478bd9Sstevel@tonic-gate } 14087c478bd9Sstevel@tonic-gate 14097c478bd9Sstevel@tonic-gate /* 14107c478bd9Sstevel@tonic-gate * --------------------------------------------------------- 14117c478bd9Sstevel@tonic-gate * convert_int64_to_string: 14127c478bd9Sstevel@tonic-gate * Converts a integer to string depending on the print mode 14137c478bd9Sstevel@tonic-gate * input : printmode, which may be one of AUP_BINARY, 14147c478bd9Sstevel@tonic-gate * AUP_OCTAL, AUP_DECIMAL, and AUP_HEX 14157c478bd9Sstevel@tonic-gate * c, which is the integer to convert 14167c478bd9Sstevel@tonic-gate * output : p, which is a pointer to the location where 14177c478bd9Sstevel@tonic-gate * the resulting string is to be stored 14187c478bd9Sstevel@tonic-gate * ---------------------------------------------------------- 14197c478bd9Sstevel@tonic-gate */ 14207c478bd9Sstevel@tonic-gate int 14217c478bd9Sstevel@tonic-gate convert_int64_to_string(char printmode, int64_t c, char *p) 14227c478bd9Sstevel@tonic-gate { 14237c478bd9Sstevel@tonic-gate if (printmode == AUP_BINARY) 14247c478bd9Sstevel@tonic-gate (void) convertbinary(p, (char *)&c, sizeof (int64_t)); 14257c478bd9Sstevel@tonic-gate else if (printmode == AUP_OCTAL) 14267c478bd9Sstevel@tonic-gate (void) sprintf(p, "%"PRIo64, c); 14277c478bd9Sstevel@tonic-gate else if (printmode == AUP_DECIMAL) 14287c478bd9Sstevel@tonic-gate (void) sprintf(p, "%"PRId64, c); 14297c478bd9Sstevel@tonic-gate else if (printmode == AUP_HEX) 14307c478bd9Sstevel@tonic-gate (void) sprintf(p, "0x%"PRIx64, c); 14317c478bd9Sstevel@tonic-gate else if (printmode == AUP_STRING) 14327c478bd9Sstevel@tonic-gate convertascii(p, (char *)&c, sizeof (int64_t)); 14337c478bd9Sstevel@tonic-gate return (0); 14347c478bd9Sstevel@tonic-gate } 14357c478bd9Sstevel@tonic-gate 14367c478bd9Sstevel@tonic-gate 14377c478bd9Sstevel@tonic-gate /* 14387c478bd9Sstevel@tonic-gate * ----------------------------------------------------------- 14397c478bd9Sstevel@tonic-gate * convertbinary: 14407c478bd9Sstevel@tonic-gate * Converts a unit c of 'size' bytes long into a binary string 14417c478bd9Sstevel@tonic-gate * and returns it into the position pointed to by p 14427c478bd9Sstevel@tonic-gate * ------------------------------------------------------------ 14437c478bd9Sstevel@tonic-gate */ 14447c478bd9Sstevel@tonic-gate int 14457c478bd9Sstevel@tonic-gate convertbinary(char *p, char *c, int size) 14467c478bd9Sstevel@tonic-gate { 14477c478bd9Sstevel@tonic-gate char *s, *t, *ss; 14487c478bd9Sstevel@tonic-gate int i, j; 14497c478bd9Sstevel@tonic-gate 14507c478bd9Sstevel@tonic-gate if ((s = (char *)malloc(8 * size + 1)) == NULL) 14517c478bd9Sstevel@tonic-gate return (0); 14527c478bd9Sstevel@tonic-gate 14537c478bd9Sstevel@tonic-gate ss = s; 14547c478bd9Sstevel@tonic-gate 14557c478bd9Sstevel@tonic-gate /* first convert to binary */ 14567c478bd9Sstevel@tonic-gate t = s; 14577c478bd9Sstevel@tonic-gate for (i = 0; i < size; i++) { 14587c478bd9Sstevel@tonic-gate for (j = 0; j < 8; j++) 14597c478bd9Sstevel@tonic-gate (void) sprintf(t++, "%d", ((*c >> (7 - j)) & (0x01))); 14607c478bd9Sstevel@tonic-gate c++; 14617c478bd9Sstevel@tonic-gate } 14627c478bd9Sstevel@tonic-gate *t = '\0'; 14637c478bd9Sstevel@tonic-gate 14647c478bd9Sstevel@tonic-gate /* now string leading zero's if any */ 14657c478bd9Sstevel@tonic-gate j = strlen(s) - 1; 14667c478bd9Sstevel@tonic-gate for (i = 0; i < j; i++) { 14677c478bd9Sstevel@tonic-gate if (*s != '0') 14687c478bd9Sstevel@tonic-gate break; 14697c478bd9Sstevel@tonic-gate else 14707c478bd9Sstevel@tonic-gate s++; 14717c478bd9Sstevel@tonic-gate } 14727c478bd9Sstevel@tonic-gate 14737c478bd9Sstevel@tonic-gate /* now copy the contents of s to p */ 14747c478bd9Sstevel@tonic-gate t = p; 14757c478bd9Sstevel@tonic-gate for (i = 0; i < (8 * size + 1); i++) { 14767c478bd9Sstevel@tonic-gate if (*s == '\0') { 14777c478bd9Sstevel@tonic-gate *t = '\0'; 14787c478bd9Sstevel@tonic-gate break; 14797c478bd9Sstevel@tonic-gate } 14807c478bd9Sstevel@tonic-gate *t++ = *s++; 14817c478bd9Sstevel@tonic-gate } 14827c478bd9Sstevel@tonic-gate free(ss); 14837c478bd9Sstevel@tonic-gate 14847c478bd9Sstevel@tonic-gate return (1); 14857c478bd9Sstevel@tonic-gate } 14867c478bd9Sstevel@tonic-gate 14877c478bd9Sstevel@tonic-gate 14887c478bd9Sstevel@tonic-gate static char hex[] = "0123456789abcdef"; 14897c478bd9Sstevel@tonic-gate /* 14907c478bd9Sstevel@tonic-gate * ------------------------------------------------------------------- 14917c478bd9Sstevel@tonic-gate * hexconvert : Converts a string of (size) bytes to hexadecimal, and 14927c478bd9Sstevel@tonic-gate * returns the hexadecimal string. 14937c478bd9Sstevel@tonic-gate * returns : - NULL if memory cannot be allocated for the string, or 14947c478bd9Sstevel@tonic-gate * - pointer to the hexadecimal string if successful 14957c478bd9Sstevel@tonic-gate * ------------------------------------------------------------------- 14967c478bd9Sstevel@tonic-gate */ 14977c478bd9Sstevel@tonic-gate char * 14987c478bd9Sstevel@tonic-gate hexconvert(char *c, int size, int chunk) 14997c478bd9Sstevel@tonic-gate { 15007c478bd9Sstevel@tonic-gate register char *s, *t; 15017c478bd9Sstevel@tonic-gate register int i, j, k; 15027c478bd9Sstevel@tonic-gate int numchunks; 15037c478bd9Sstevel@tonic-gate int leftovers; 15047c478bd9Sstevel@tonic-gate 15057c478bd9Sstevel@tonic-gate if (size <= 0) 15067c478bd9Sstevel@tonic-gate return (NULL); 15077c478bd9Sstevel@tonic-gate 15087c478bd9Sstevel@tonic-gate if ((s = (char *)malloc((size * 5) + 1)) == NULL) 15097c478bd9Sstevel@tonic-gate return (NULL); 15107c478bd9Sstevel@tonic-gate 15117c478bd9Sstevel@tonic-gate if (chunk > size || chunk <= 0) 15127c478bd9Sstevel@tonic-gate chunk = size; 15137c478bd9Sstevel@tonic-gate 15147c478bd9Sstevel@tonic-gate numchunks = size / chunk; 15157c478bd9Sstevel@tonic-gate leftovers = size % chunk; 15167c478bd9Sstevel@tonic-gate 15177c478bd9Sstevel@tonic-gate t = s; 15187c478bd9Sstevel@tonic-gate for (i = j = 0; i < numchunks; i++) { 15197c478bd9Sstevel@tonic-gate if (j++) { 15207c478bd9Sstevel@tonic-gate *t++ = ' '; 15217c478bd9Sstevel@tonic-gate } 15227c478bd9Sstevel@tonic-gate *t++ = '0'; 15237c478bd9Sstevel@tonic-gate *t++ = 'x'; 15247c478bd9Sstevel@tonic-gate for (k = 0; k < chunk; k++) { 15257c478bd9Sstevel@tonic-gate *t++ = hex[(uint_t)((uchar_t)*c >> 4)]; 15267c478bd9Sstevel@tonic-gate *t++ = hex[(uint_t)((uchar_t)*c & 0xF)]; 15277c478bd9Sstevel@tonic-gate c++; 15287c478bd9Sstevel@tonic-gate } 15297c478bd9Sstevel@tonic-gate } 15307c478bd9Sstevel@tonic-gate 15317c478bd9Sstevel@tonic-gate if (leftovers) { 15327c478bd9Sstevel@tonic-gate *t++ = ' '; 15337c478bd9Sstevel@tonic-gate *t++ = '0'; 15347c478bd9Sstevel@tonic-gate *t++ = 'x'; 15357c478bd9Sstevel@tonic-gate for (i = 0; i < leftovers; i++) { 15367c478bd9Sstevel@tonic-gate *t++ = hex[(uint_t)((uchar_t)*c >> 4)]; 15377c478bd9Sstevel@tonic-gate *t++ = hex[(uint_t)((uchar_t)*c & 0xF)]; 15387c478bd9Sstevel@tonic-gate c++; 15397c478bd9Sstevel@tonic-gate } 15407c478bd9Sstevel@tonic-gate } 15417c478bd9Sstevel@tonic-gate 15427c478bd9Sstevel@tonic-gate *t = '\0'; 15437c478bd9Sstevel@tonic-gate return (s); 15447c478bd9Sstevel@tonic-gate } 15457c478bd9Sstevel@tonic-gate 15467c478bd9Sstevel@tonic-gate 15477c478bd9Sstevel@tonic-gate /* 15487c478bd9Sstevel@tonic-gate * ------------------------------------------------------------------- 15497c478bd9Sstevel@tonic-gate * htp2string: Maps a print suggestion to a string. 15507c478bd9Sstevel@tonic-gate * returns : The string mapping or "unknown print suggestion". 15517c478bd9Sstevel@tonic-gate * ------------------------------------------------------------------- 15527c478bd9Sstevel@tonic-gate */ 15537c478bd9Sstevel@tonic-gate char * 15547c478bd9Sstevel@tonic-gate htp2string(char print_sugg) 15557c478bd9Sstevel@tonic-gate { 15567c478bd9Sstevel@tonic-gate register int i; 15577c478bd9Sstevel@tonic-gate 15587c478bd9Sstevel@tonic-gate struct htp_map_ent { 15597c478bd9Sstevel@tonic-gate char print_sugg; 15607c478bd9Sstevel@tonic-gate char *print_string; 15617c478bd9Sstevel@tonic-gate }; 15627c478bd9Sstevel@tonic-gate 15637c478bd9Sstevel@tonic-gate /* 15647c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE 15657c478bd9Sstevel@tonic-gate * These names are data types when displaying the arbitrary data 15667c478bd9Sstevel@tonic-gate * token. 15677c478bd9Sstevel@tonic-gate */ 15687c478bd9Sstevel@tonic-gate 15697c478bd9Sstevel@tonic-gate static struct htp_map_ent htp_map[] = { 15707c478bd9Sstevel@tonic-gate { AUP_BINARY, "binary" }, 15717c478bd9Sstevel@tonic-gate { AUP_OCTAL, "octal" }, 15727c478bd9Sstevel@tonic-gate { AUP_DECIMAL, "decimal" }, 15737c478bd9Sstevel@tonic-gate { AUP_HEX, "hexadecimal" }, 15747c478bd9Sstevel@tonic-gate { AUP_STRING, "string" } }; 15757c478bd9Sstevel@tonic-gate 15767c478bd9Sstevel@tonic-gate for (i = 0; i < sizeof (htp_map) / sizeof (struct htp_map_ent); i++) 15777c478bd9Sstevel@tonic-gate if (print_sugg == htp_map[i].print_sugg) 15787c478bd9Sstevel@tonic-gate return (gettext(htp_map[i].print_string)); 15797c478bd9Sstevel@tonic-gate 15807c478bd9Sstevel@tonic-gate return (gettext("unknown print suggestion")); 15817c478bd9Sstevel@tonic-gate } 15827c478bd9Sstevel@tonic-gate 15837c478bd9Sstevel@tonic-gate /* 15847c478bd9Sstevel@tonic-gate * ---------------------------------------------------------------------- 15857c478bd9Sstevel@tonic-gate * pa_adr_short: Issues pr_adr_short to retrieve the next ADR item from the 15867c478bd9Sstevel@tonic-gate * input stream pointed to by audit_adr, and prints it 15877c478bd9Sstevel@tonic-gate * if status >= 0 15887c478bd9Sstevel@tonic-gate * return codes: -1 - error 15897c478bd9Sstevel@tonic-gate * : 0 - successful 15907c478bd9Sstevel@tonic-gate * ---------------------------------------------------------------------- 15917c478bd9Sstevel@tonic-gate */ 15927c478bd9Sstevel@tonic-gate int 15937c478bd9Sstevel@tonic-gate pa_adr_short(pr_context_t *context, int status, int flag) 15947c478bd9Sstevel@tonic-gate { 15957c478bd9Sstevel@tonic-gate short c; 15967c478bd9Sstevel@tonic-gate uval_t uval; 15977c478bd9Sstevel@tonic-gate 15987c478bd9Sstevel@tonic-gate if (status >= 0) { 15997c478bd9Sstevel@tonic-gate if (pr_adr_short(context, &c, 1) == 0) { 16007c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_SHORT; 16017c478bd9Sstevel@tonic-gate uval.short_val = c; 16027c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 16037c478bd9Sstevel@tonic-gate } else 16047c478bd9Sstevel@tonic-gate return (-1); 16057c478bd9Sstevel@tonic-gate } else 16067c478bd9Sstevel@tonic-gate return (status); 16077c478bd9Sstevel@tonic-gate } 16087c478bd9Sstevel@tonic-gate 16097c478bd9Sstevel@tonic-gate /* 16107c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 16117c478bd9Sstevel@tonic-gate * pa_adr_shorthex: Issues pr_adr_short to retrieve the next ADR item from the 16127c478bd9Sstevel@tonic-gate * input stream pointed to by audit_adr, and prints it 16137c478bd9Sstevel@tonic-gate * in hexadecimal if status >= 0 16147c478bd9Sstevel@tonic-gate * return codes : -1 - error 16157c478bd9Sstevel@tonic-gate * : 0 - successful 16167c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 16177c478bd9Sstevel@tonic-gate */ 16187c478bd9Sstevel@tonic-gate int 16197c478bd9Sstevel@tonic-gate pa_adr_shorthex(pr_context_t *context, int status, int flag) 16207c478bd9Sstevel@tonic-gate { 16217c478bd9Sstevel@tonic-gate short s; 16227c478bd9Sstevel@tonic-gate int returnstat; 16237c478bd9Sstevel@tonic-gate uval_t uval; 16247c478bd9Sstevel@tonic-gate 16257c478bd9Sstevel@tonic-gate if (status >= 0) { 16267c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_short(context, &s, 1)) == 0) { 16277c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 16287c478bd9Sstevel@tonic-gate uval.string_val = hexconvert((char *)&s, sizeof (s), 16297c478bd9Sstevel@tonic-gate sizeof (s)); 16307c478bd9Sstevel@tonic-gate if (uval.string_val) { 16317c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 16327c478bd9Sstevel@tonic-gate free(uval.string_val); 16337c478bd9Sstevel@tonic-gate } 16347c478bd9Sstevel@tonic-gate } 16357c478bd9Sstevel@tonic-gate return (returnstat); 16367c478bd9Sstevel@tonic-gate } else 16377c478bd9Sstevel@tonic-gate return (status); 16387c478bd9Sstevel@tonic-gate } 16397c478bd9Sstevel@tonic-gate 16407c478bd9Sstevel@tonic-gate 16417c478bd9Sstevel@tonic-gate /* 16427c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 16437c478bd9Sstevel@tonic-gate * pa_adr_string: Retrieves a string from the input stream and prints it 16447c478bd9Sstevel@tonic-gate * if status >= 0 16457c478bd9Sstevel@tonic-gate * return codes : -1 - error 16467c478bd9Sstevel@tonic-gate * : 0 - successful 16477c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 16487c478bd9Sstevel@tonic-gate */ 16497c478bd9Sstevel@tonic-gate int 16507c478bd9Sstevel@tonic-gate pa_adr_string(pr_context_t *context, int status, int flag) 16517c478bd9Sstevel@tonic-gate { 16527c478bd9Sstevel@tonic-gate char *c; 16537c478bd9Sstevel@tonic-gate char *p; 16547c478bd9Sstevel@tonic-gate short length; 16557c478bd9Sstevel@tonic-gate int returnstat; 16567c478bd9Sstevel@tonic-gate uval_t uval; 16577c478bd9Sstevel@tonic-gate 16587c478bd9Sstevel@tonic-gate /* 16597c478bd9Sstevel@tonic-gate * We need to know how much space to allocate for our string, so 16607c478bd9Sstevel@tonic-gate * read the length first, then call pr_adr_char to read those bytes. 16617c478bd9Sstevel@tonic-gate */ 16627c478bd9Sstevel@tonic-gate if (status < 0) 16637c478bd9Sstevel@tonic-gate return (status); 16647c478bd9Sstevel@tonic-gate 16657c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_short(context, &length, 1)) != 0) 16667c478bd9Sstevel@tonic-gate return (returnstat); 16677c478bd9Sstevel@tonic-gate if ((c = (char *)malloc(length + 1)) == NULL) 16687c478bd9Sstevel@tonic-gate return (-1); 16697c478bd9Sstevel@tonic-gate if ((p = (char *)malloc((length * 2) + 1)) == NULL) { 16707c478bd9Sstevel@tonic-gate free(c); 16717c478bd9Sstevel@tonic-gate return (-1); 16727c478bd9Sstevel@tonic-gate } 16737c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, c, length)) != 0) { 16747c478bd9Sstevel@tonic-gate free(c); 16757c478bd9Sstevel@tonic-gate free(p); 16767c478bd9Sstevel@tonic-gate return (returnstat); 16777c478bd9Sstevel@tonic-gate } 16787c478bd9Sstevel@tonic-gate convertascii(p, c, length - 1); 16797c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 16807c478bd9Sstevel@tonic-gate uval.string_val = p; 16817c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 16827c478bd9Sstevel@tonic-gate free(c); 16837c478bd9Sstevel@tonic-gate free(p); 16847c478bd9Sstevel@tonic-gate return (returnstat); 16857c478bd9Sstevel@tonic-gate } 16867c478bd9Sstevel@tonic-gate 16877c478bd9Sstevel@tonic-gate /* 16887c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 16897c478bd9Sstevel@tonic-gate * pa_file_string: Retrieves a file string from the input stream and prints it 16907c478bd9Sstevel@tonic-gate * if status >= 0 16917c478bd9Sstevel@tonic-gate * return codes : -1 - error 16927c478bd9Sstevel@tonic-gate * : 0 - successful 16937c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 16947c478bd9Sstevel@tonic-gate */ 16957c478bd9Sstevel@tonic-gate int 16967c478bd9Sstevel@tonic-gate pa_file_string(pr_context_t *context, int status, int flag) 16977c478bd9Sstevel@tonic-gate { 16987c478bd9Sstevel@tonic-gate char *c; 16997c478bd9Sstevel@tonic-gate char *p; 17007c478bd9Sstevel@tonic-gate short length; 17017c478bd9Sstevel@tonic-gate int returnstat; 17027c478bd9Sstevel@tonic-gate uval_t uval; 17037c478bd9Sstevel@tonic-gate 17047c478bd9Sstevel@tonic-gate /* 17057c478bd9Sstevel@tonic-gate * We need to know how much space to allocate for our string, so 17067c478bd9Sstevel@tonic-gate * read the length first, then call pr_adr_char to read those bytes. 17077c478bd9Sstevel@tonic-gate */ 17087c478bd9Sstevel@tonic-gate if (status < 0) 17097c478bd9Sstevel@tonic-gate return (status); 17107c478bd9Sstevel@tonic-gate 17117c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_short(context, &length, 1)) != 0) 17127c478bd9Sstevel@tonic-gate return (returnstat); 17137c478bd9Sstevel@tonic-gate if ((c = (char *)malloc(length + 1)) == NULL) 17147c478bd9Sstevel@tonic-gate return (-1); 17157c478bd9Sstevel@tonic-gate if ((p = (char *)malloc((length * 2) + 1)) == NULL) { 17167c478bd9Sstevel@tonic-gate free(c); 17177c478bd9Sstevel@tonic-gate return (-1); 17187c478bd9Sstevel@tonic-gate } 17197c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, c, length)) != 0) { 17207c478bd9Sstevel@tonic-gate free(c); 17217c478bd9Sstevel@tonic-gate free(p); 17227c478bd9Sstevel@tonic-gate return (returnstat); 17237c478bd9Sstevel@tonic-gate } 17247c478bd9Sstevel@tonic-gate 17257c478bd9Sstevel@tonic-gate if (is_file_token(context->tokenid)) 17267c478bd9Sstevel@tonic-gate context->audit_rec_len += length; 17277c478bd9Sstevel@tonic-gate 17287c478bd9Sstevel@tonic-gate convertascii(p, c, length - 1); 17297c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 17307c478bd9Sstevel@tonic-gate uval.string_val = p; 17317c478bd9Sstevel@tonic-gate 17327c478bd9Sstevel@tonic-gate if (returnstat == 0) 17337c478bd9Sstevel@tonic-gate returnstat = finish_open_tag(context); 17347c478bd9Sstevel@tonic-gate 17357c478bd9Sstevel@tonic-gate if (returnstat == 0) 17367c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 17377c478bd9Sstevel@tonic-gate 17387c478bd9Sstevel@tonic-gate free(c); 17397c478bd9Sstevel@tonic-gate free(p); 17407c478bd9Sstevel@tonic-gate return (returnstat); 17417c478bd9Sstevel@tonic-gate } 17427c478bd9Sstevel@tonic-gate 17437c478bd9Sstevel@tonic-gate static int 17447c478bd9Sstevel@tonic-gate pa_putstr_xml(pr_context_t *context, int printable, char *str, size_t len) 17457c478bd9Sstevel@tonic-gate { 17467c478bd9Sstevel@tonic-gate int err; 17477c478bd9Sstevel@tonic-gate 17487c478bd9Sstevel@tonic-gate if (!printable) { 17497c478bd9Sstevel@tonic-gate /* 17507c478bd9Sstevel@tonic-gate * Unprintable chars should always be converted to the 17517c478bd9Sstevel@tonic-gate * visible form. If there are unprintable characters which 17527c478bd9Sstevel@tonic-gate * require special treatment in xml, those should be 17537c478bd9Sstevel@tonic-gate * handled here. 17547c478bd9Sstevel@tonic-gate */ 17557c478bd9Sstevel@tonic-gate do { 17567c478bd9Sstevel@tonic-gate err = pr_printf(context, "\\%03o", 17577c478bd9Sstevel@tonic-gate (unsigned char)*str++); 17587c478bd9Sstevel@tonic-gate } while (err == 0 && --len != 0); 17597c478bd9Sstevel@tonic-gate return (err); 17607c478bd9Sstevel@tonic-gate } 17617c478bd9Sstevel@tonic-gate /* printable characters */ 17627c478bd9Sstevel@tonic-gate if (len == 1) { 17637c478bd9Sstevel@tonic-gate /* 17647c478bd9Sstevel@tonic-gate * check for the special chars only when char size was 1 17657c478bd9Sstevel@tonic-gate * ie, ignore special chars appear in the middle of multibyte 17667c478bd9Sstevel@tonic-gate * sequence. 17677c478bd9Sstevel@tonic-gate */ 17687c478bd9Sstevel@tonic-gate 17697c478bd9Sstevel@tonic-gate /* Escape for XML */ 17707c478bd9Sstevel@tonic-gate switch (*str) { 17717c478bd9Sstevel@tonic-gate case '&': 17727c478bd9Sstevel@tonic-gate err = pr_printf(context, "%s", "&"); 17737c478bd9Sstevel@tonic-gate break; 17747c478bd9Sstevel@tonic-gate 17757c478bd9Sstevel@tonic-gate case '<': 17767c478bd9Sstevel@tonic-gate err = pr_printf(context, "%s", "<"); 17777c478bd9Sstevel@tonic-gate break; 17787c478bd9Sstevel@tonic-gate 17797c478bd9Sstevel@tonic-gate case '>': 17807c478bd9Sstevel@tonic-gate err = pr_printf(context, "%s", ">"); 17817c478bd9Sstevel@tonic-gate break; 17827c478bd9Sstevel@tonic-gate 17837c478bd9Sstevel@tonic-gate case '\"': 17847c478bd9Sstevel@tonic-gate err = pr_printf(context, "%s", """); 17857c478bd9Sstevel@tonic-gate break; 17867c478bd9Sstevel@tonic-gate 17877c478bd9Sstevel@tonic-gate case '\'': 17887c478bd9Sstevel@tonic-gate err = pr_printf(context, "%s", "'"); 17897c478bd9Sstevel@tonic-gate break; 17907c478bd9Sstevel@tonic-gate 17917c478bd9Sstevel@tonic-gate default: 17927c478bd9Sstevel@tonic-gate err = pr_putchar(context, *str); 17937c478bd9Sstevel@tonic-gate break; 17947c478bd9Sstevel@tonic-gate } 17957c478bd9Sstevel@tonic-gate return (err); 17967c478bd9Sstevel@tonic-gate } 17977c478bd9Sstevel@tonic-gate do { 17987c478bd9Sstevel@tonic-gate err = pr_putchar(context, *str++); 17997c478bd9Sstevel@tonic-gate } while (err == 0 && --len != 0); 18007c478bd9Sstevel@tonic-gate return (err); 18017c478bd9Sstevel@tonic-gate } 18027c478bd9Sstevel@tonic-gate 18037c478bd9Sstevel@tonic-gate static int 18047c478bd9Sstevel@tonic-gate pa_putstr(pr_context_t *context, int printable, char *str, size_t len) 18057c478bd9Sstevel@tonic-gate { 18067c478bd9Sstevel@tonic-gate int err; 18077c478bd9Sstevel@tonic-gate 18087c478bd9Sstevel@tonic-gate if (context->format & PRF_XMLM) 18097c478bd9Sstevel@tonic-gate return (pa_putstr_xml(context, printable, str, len)); 18107c478bd9Sstevel@tonic-gate 18117c478bd9Sstevel@tonic-gate if (!printable) { 18127c478bd9Sstevel@tonic-gate do { 18137c478bd9Sstevel@tonic-gate err = pr_printf(context, "\\%03o", 18147c478bd9Sstevel@tonic-gate (unsigned char)*str++); 18157c478bd9Sstevel@tonic-gate } while (err == 0 && --len != 0); 18167c478bd9Sstevel@tonic-gate return (err); 18177c478bd9Sstevel@tonic-gate } 18187c478bd9Sstevel@tonic-gate do { 18197c478bd9Sstevel@tonic-gate err = pr_putchar(context, *str++); 18207c478bd9Sstevel@tonic-gate } while (err == 0 && --len != 0); 18217c478bd9Sstevel@tonic-gate return (err); 18227c478bd9Sstevel@tonic-gate } 18237c478bd9Sstevel@tonic-gate 18247c478bd9Sstevel@tonic-gate int 18257c478bd9Sstevel@tonic-gate pa_string(pr_context_t *context, int status, int flag) 18267c478bd9Sstevel@tonic-gate { 18277c478bd9Sstevel@tonic-gate int rstat, wstat; 18287c478bd9Sstevel@tonic-gate int i, printable, eos; 18297c478bd9Sstevel@tonic-gate int mlen, rlen; 18307c478bd9Sstevel@tonic-gate int mbmax = MB_CUR_MAX; 18317c478bd9Sstevel@tonic-gate wchar_t wc; 18327c478bd9Sstevel@tonic-gate char mbuf[MB_LEN_MAX + 1]; 18337c478bd9Sstevel@tonic-gate char c; 18347c478bd9Sstevel@tonic-gate 18357c478bd9Sstevel@tonic-gate if (status < 0) 18367c478bd9Sstevel@tonic-gate return (status); 18377c478bd9Sstevel@tonic-gate 18387c478bd9Sstevel@tonic-gate rstat = wstat = 0; 18397c478bd9Sstevel@tonic-gate 18407c478bd9Sstevel@tonic-gate if (mbmax == 1) { 18417c478bd9Sstevel@tonic-gate while (wstat == 0) { 18427c478bd9Sstevel@tonic-gate if ((rstat = pr_adr_char(context, &c, 1)) < 0) 18437c478bd9Sstevel@tonic-gate break; 18447c478bd9Sstevel@tonic-gate if (c == '\0') 18457c478bd9Sstevel@tonic-gate break; 18467c478bd9Sstevel@tonic-gate printable = isprint((unsigned char)c); 18477c478bd9Sstevel@tonic-gate wstat = pa_putstr(context, printable, &c, 1); 18487c478bd9Sstevel@tonic-gate } 18497c478bd9Sstevel@tonic-gate goto done; 18507c478bd9Sstevel@tonic-gate } 18517c478bd9Sstevel@tonic-gate 18527c478bd9Sstevel@tonic-gate mlen = eos = 0; 18537c478bd9Sstevel@tonic-gate while (wstat == 0) { 18547c478bd9Sstevel@tonic-gate rlen = 0; 18557c478bd9Sstevel@tonic-gate do { 18567c478bd9Sstevel@tonic-gate if (!eos) { 18577c478bd9Sstevel@tonic-gate rstat = pr_adr_char(context, &c, 1); 18587c478bd9Sstevel@tonic-gate if (rstat != 0 || c == '\0') 18597c478bd9Sstevel@tonic-gate eos = 1; 18607c478bd9Sstevel@tonic-gate else 18617c478bd9Sstevel@tonic-gate mbuf[mlen++] = c; 18627c478bd9Sstevel@tonic-gate } 18637c478bd9Sstevel@tonic-gate rlen = mbtowc(&wc, mbuf, mlen); 18647c478bd9Sstevel@tonic-gate } while (!eos && mlen < mbmax && rlen <= 0); 18657c478bd9Sstevel@tonic-gate 18667c478bd9Sstevel@tonic-gate if (mlen == 0) 18677c478bd9Sstevel@tonic-gate break; /* end of string */ 18687c478bd9Sstevel@tonic-gate 18697c478bd9Sstevel@tonic-gate if (rlen <= 0) { /* no good sequence */ 18707c478bd9Sstevel@tonic-gate rlen = 1; 18717c478bd9Sstevel@tonic-gate printable = 0; 18727c478bd9Sstevel@tonic-gate } else { 18737c478bd9Sstevel@tonic-gate printable = iswprint(wc); 18747c478bd9Sstevel@tonic-gate } 18757c478bd9Sstevel@tonic-gate wstat = pa_putstr(context, printable, mbuf, rlen); 18767c478bd9Sstevel@tonic-gate mlen -= rlen; 18777c478bd9Sstevel@tonic-gate if (mlen > 0) { 18787c478bd9Sstevel@tonic-gate for (i = 0; i < mlen; i++) 18797c478bd9Sstevel@tonic-gate mbuf[i] = mbuf[rlen + i]; 18807c478bd9Sstevel@tonic-gate } 18817c478bd9Sstevel@tonic-gate } 18827c478bd9Sstevel@tonic-gate 18837c478bd9Sstevel@tonic-gate done: 18847c478bd9Sstevel@tonic-gate if (wstat == 0) 18857c478bd9Sstevel@tonic-gate wstat = do_newline(context, flag); 18867c478bd9Sstevel@tonic-gate 18877c478bd9Sstevel@tonic-gate if (wstat == 0 && context->data_mode == FILEMODE) 18887c478bd9Sstevel@tonic-gate (void) fflush(stdout); 18897c478bd9Sstevel@tonic-gate 18907c478bd9Sstevel@tonic-gate return ((rstat != 0 || wstat != 0) ? -1 : 0); 18917c478bd9Sstevel@tonic-gate } 18927c478bd9Sstevel@tonic-gate 18937c478bd9Sstevel@tonic-gate /* 18947c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 18957c478bd9Sstevel@tonic-gate * pa_adr_u_int32: Issues pr_adr_u_int32 to retrieve the next ADR item from 18967c478bd9Sstevel@tonic-gate * the input stream pointed to by audit_adr, and prints it 18977c478bd9Sstevel@tonic-gate * if status = 0 18987c478bd9Sstevel@tonic-gate * return codes : -1 - error 18997c478bd9Sstevel@tonic-gate * : 0 - successful 19007c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 19017c478bd9Sstevel@tonic-gate */ 19027c478bd9Sstevel@tonic-gate 19037c478bd9Sstevel@tonic-gate 19047c478bd9Sstevel@tonic-gate int 19057c478bd9Sstevel@tonic-gate pa_adr_u_int32(pr_context_t *context, int status, int flag) 19067c478bd9Sstevel@tonic-gate { 19077c478bd9Sstevel@tonic-gate uint32_t c; 19087c478bd9Sstevel@tonic-gate uval_t uval; 19097c478bd9Sstevel@tonic-gate 19107c478bd9Sstevel@tonic-gate if (status >= 0) { 19117c478bd9Sstevel@tonic-gate if (pr_adr_u_int32(context, &c, 1) == 0) { 19127c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT32; 19137c478bd9Sstevel@tonic-gate uval.uint32_val = c; 19147c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 19157c478bd9Sstevel@tonic-gate } else 19167c478bd9Sstevel@tonic-gate return (-1); 19177c478bd9Sstevel@tonic-gate } else 19187c478bd9Sstevel@tonic-gate return (status); 19197c478bd9Sstevel@tonic-gate } 19207c478bd9Sstevel@tonic-gate 19217c478bd9Sstevel@tonic-gate 19227c478bd9Sstevel@tonic-gate 19237c478bd9Sstevel@tonic-gate /* 19247c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 19257c478bd9Sstevel@tonic-gate * pa_adr_u_int64: Issues pr_adr_u_int64 to retrieve the next ADR item from the 19267c478bd9Sstevel@tonic-gate * input stream pointed to by audit_adr, and prints it 19277c478bd9Sstevel@tonic-gate * if status = 0 19287c478bd9Sstevel@tonic-gate * return codes : -1 - error 19297c478bd9Sstevel@tonic-gate * : 0 - successful 19307c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 19317c478bd9Sstevel@tonic-gate */ 19327c478bd9Sstevel@tonic-gate int 19337c478bd9Sstevel@tonic-gate pa_adr_u_int64(pr_context_t *context, int status, int flag) 19347c478bd9Sstevel@tonic-gate { 19357c478bd9Sstevel@tonic-gate uint64_t c; 19367c478bd9Sstevel@tonic-gate uval_t uval; 19377c478bd9Sstevel@tonic-gate 19387c478bd9Sstevel@tonic-gate if (status >= 0) { 19397c478bd9Sstevel@tonic-gate if (pr_adr_u_int64(context, &c, 1) == 0) { 19407c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT64; 19417c478bd9Sstevel@tonic-gate uval.uint64_val = c; 19427c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 19437c478bd9Sstevel@tonic-gate } else 19447c478bd9Sstevel@tonic-gate return (-1); 19457c478bd9Sstevel@tonic-gate } else 19467c478bd9Sstevel@tonic-gate return (status); 19477c478bd9Sstevel@tonic-gate } 19487c478bd9Sstevel@tonic-gate 19497c478bd9Sstevel@tonic-gate 19507c478bd9Sstevel@tonic-gate /* 19517c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 19527c478bd9Sstevel@tonic-gate * pa_adr_u_short: Issues pr_adr_u_short to retrieve the next ADR item from 19537c478bd9Sstevel@tonic-gate * the input stream pointed to by audit_adr, and prints it 19547c478bd9Sstevel@tonic-gate * if status = 0 19557c478bd9Sstevel@tonic-gate * return codes : -1 - error 19567c478bd9Sstevel@tonic-gate * : 0 - successful 19577c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 19587c478bd9Sstevel@tonic-gate */ 19597c478bd9Sstevel@tonic-gate int 19607c478bd9Sstevel@tonic-gate pa_adr_u_short(pr_context_t *context, int status, int flag) 19617c478bd9Sstevel@tonic-gate { 19627c478bd9Sstevel@tonic-gate ushort_t c; 19637c478bd9Sstevel@tonic-gate uval_t uval; 19647c478bd9Sstevel@tonic-gate 19657c478bd9Sstevel@tonic-gate if (status >= 0) { 19667c478bd9Sstevel@tonic-gate if (pr_adr_u_short(context, &c, 1) == 0) { 19677c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_USHORT; 19687c478bd9Sstevel@tonic-gate uval.ushort_val = c; 19697c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 19707c478bd9Sstevel@tonic-gate } else 19717c478bd9Sstevel@tonic-gate return (-1); 19727c478bd9Sstevel@tonic-gate } else 19737c478bd9Sstevel@tonic-gate return (status); 19747c478bd9Sstevel@tonic-gate } 19757c478bd9Sstevel@tonic-gate 19767c478bd9Sstevel@tonic-gate /* 19777c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 19787c478bd9Sstevel@tonic-gate * pa_reclen: Issues pr_adr_u_long to retrieve the length of the record 19797c478bd9Sstevel@tonic-gate * from the input stream pointed to by audit_adr, 19807c478bd9Sstevel@tonic-gate * and prints it (unless format is XML) if status = 0 19817c478bd9Sstevel@tonic-gate * return codes : -1 - error 19827c478bd9Sstevel@tonic-gate * : 0 - successful 19837c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 19847c478bd9Sstevel@tonic-gate */ 19857c478bd9Sstevel@tonic-gate int 19867c478bd9Sstevel@tonic-gate pa_reclen(pr_context_t *context, int status) 19877c478bd9Sstevel@tonic-gate { 19887c478bd9Sstevel@tonic-gate uint32_t c; 19897c478bd9Sstevel@tonic-gate uval_t uval; 19907c478bd9Sstevel@tonic-gate 19917c478bd9Sstevel@tonic-gate if (status >= 0) { 19927c478bd9Sstevel@tonic-gate if ((int)pr_adr_u_int32(context, &c, 1) == 0) { 19937c478bd9Sstevel@tonic-gate context->audit_rec_len = c; 19947c478bd9Sstevel@tonic-gate 19957c478bd9Sstevel@tonic-gate /* Don't print this for XML format */ 19967c478bd9Sstevel@tonic-gate if (context->format & PRF_XMLM) { 19977c478bd9Sstevel@tonic-gate return (0); 19987c478bd9Sstevel@tonic-gate } else { 19997c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT32; 20007c478bd9Sstevel@tonic-gate uval.uint32_val = c; 20017c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, 0)); 20027c478bd9Sstevel@tonic-gate } 20037c478bd9Sstevel@tonic-gate } else 20047c478bd9Sstevel@tonic-gate return (-1); 20057c478bd9Sstevel@tonic-gate } else 20067c478bd9Sstevel@tonic-gate return (status); 20077c478bd9Sstevel@tonic-gate } 20087c478bd9Sstevel@tonic-gate 20097c478bd9Sstevel@tonic-gate /* 20107c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 20117c478bd9Sstevel@tonic-gate * pa_mode : Issues pr_adr_u_short to retrieve the next ADR item from 20127c478bd9Sstevel@tonic-gate * the input stream pointed to by audit_adr, and prints it 20137c478bd9Sstevel@tonic-gate * in octal if status = 0 20147c478bd9Sstevel@tonic-gate * return codes : -1 - error 20157c478bd9Sstevel@tonic-gate * : 0 - successful 20167c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 20177c478bd9Sstevel@tonic-gate */ 20187c478bd9Sstevel@tonic-gate int 20197c478bd9Sstevel@tonic-gate pa_mode(pr_context_t *context, int status, int flag) 20207c478bd9Sstevel@tonic-gate { 20217c478bd9Sstevel@tonic-gate uint32_t c; 20227c478bd9Sstevel@tonic-gate uval_t uval; 20237c478bd9Sstevel@tonic-gate 20247c478bd9Sstevel@tonic-gate if (status >= 0) { 20257c478bd9Sstevel@tonic-gate if (pr_adr_u_int32(context, &c, 1) == 0) { 20267c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_LOCT; 20277c478bd9Sstevel@tonic-gate uval.uint32_val = c; 20287c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 20297c478bd9Sstevel@tonic-gate } else 20307c478bd9Sstevel@tonic-gate return (-1); 20317c478bd9Sstevel@tonic-gate } else 20327c478bd9Sstevel@tonic-gate return (status); 20337c478bd9Sstevel@tonic-gate } 20347c478bd9Sstevel@tonic-gate 20357c478bd9Sstevel@tonic-gate 20367c478bd9Sstevel@tonic-gate /* 20377c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 20387c478bd9Sstevel@tonic-gate * pa_pw_uid() : Issues pr_adr_u_int32 to reads uid from input stream 20397c478bd9Sstevel@tonic-gate * pointed to by audit_adr, and displays it in either 20407c478bd9Sstevel@tonic-gate * raw form or its ASCII representation, if status >= 0. 20417c478bd9Sstevel@tonic-gate * return codes : -1 - error 20427c478bd9Sstevel@tonic-gate * : 1 - warning, passwd entry not found 20437c478bd9Sstevel@tonic-gate * : 0 - successful 20447c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 20457c478bd9Sstevel@tonic-gate */ 20467c478bd9Sstevel@tonic-gate int 20477c478bd9Sstevel@tonic-gate pa_pw_uid(pr_context_t *context, int status, int flag) 20487c478bd9Sstevel@tonic-gate { 20497c478bd9Sstevel@tonic-gate int returnstat; 20507c478bd9Sstevel@tonic-gate struct passwd *pw; 20517c478bd9Sstevel@tonic-gate uint32_t uid; 20527c478bd9Sstevel@tonic-gate uval_t uval; 20537c478bd9Sstevel@tonic-gate 20547c478bd9Sstevel@tonic-gate if (status < 0) 20557c478bd9Sstevel@tonic-gate return (status); 20567c478bd9Sstevel@tonic-gate 20577c478bd9Sstevel@tonic-gate if (pr_adr_u_int32(context, &uid, 1) != 0) 20587c478bd9Sstevel@tonic-gate /* cannot retrieve uid */ 20597c478bd9Sstevel@tonic-gate return (-1); 20607c478bd9Sstevel@tonic-gate 20617c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 20627c478bd9Sstevel@tonic-gate /* get password file entry */ 20637c478bd9Sstevel@tonic-gate if ((pw = getpwuid(uid)) == NULL) { 20647c478bd9Sstevel@tonic-gate returnstat = 1; 20657c478bd9Sstevel@tonic-gate } else { 20667c478bd9Sstevel@tonic-gate /* print in ASCII form */ 20677c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 20687c478bd9Sstevel@tonic-gate uval.string_val = pw->pw_name; 20697c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 20707c478bd9Sstevel@tonic-gate } 20717c478bd9Sstevel@tonic-gate } 20727c478bd9Sstevel@tonic-gate /* print in integer form */ 20737c478bd9Sstevel@tonic-gate if ((context->format & PRF_RAWM) || (returnstat == 1)) { 20747c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_INT32; 20757c478bd9Sstevel@tonic-gate uval.int32_val = uid; 20767c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 20777c478bd9Sstevel@tonic-gate } 20787c478bd9Sstevel@tonic-gate return (returnstat); 20797c478bd9Sstevel@tonic-gate } 20807c478bd9Sstevel@tonic-gate 20817c478bd9Sstevel@tonic-gate 20827c478bd9Sstevel@tonic-gate /* 20837c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 20847c478bd9Sstevel@tonic-gate * pa_gr_uid() : Issues pr_adr_u_int32 to reads group uid from input stream 20857c478bd9Sstevel@tonic-gate * pointed to by audit_adr, and displays it in either 20867c478bd9Sstevel@tonic-gate * raw form or its ASCII representation, if status >= 0. 20877c478bd9Sstevel@tonic-gate * return codes : -1 - error 20887c478bd9Sstevel@tonic-gate * : 1 - warning, passwd entry not found 20897c478bd9Sstevel@tonic-gate * : 0 - successful 20907c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 20917c478bd9Sstevel@tonic-gate */ 20927c478bd9Sstevel@tonic-gate int 20937c478bd9Sstevel@tonic-gate pa_gr_uid(pr_context_t *context, int status, int flag) 20947c478bd9Sstevel@tonic-gate { 20957c478bd9Sstevel@tonic-gate int returnstat; 20967c478bd9Sstevel@tonic-gate struct group *gr; 20977c478bd9Sstevel@tonic-gate uint32_t gid; 20987c478bd9Sstevel@tonic-gate uval_t uval; 20997c478bd9Sstevel@tonic-gate 21007c478bd9Sstevel@tonic-gate if (status < 0) 21017c478bd9Sstevel@tonic-gate return (status); 21027c478bd9Sstevel@tonic-gate 21037c478bd9Sstevel@tonic-gate if (pr_adr_u_int32(context, &gid, 1) != 0) 21047c478bd9Sstevel@tonic-gate /* cannot retrieve gid */ 21057c478bd9Sstevel@tonic-gate return (-1); 21067c478bd9Sstevel@tonic-gate 21077c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 21087c478bd9Sstevel@tonic-gate /* get group file entry */ 21097c478bd9Sstevel@tonic-gate if ((gr = getgrgid(gid)) == NULL) { 21107c478bd9Sstevel@tonic-gate returnstat = 1; 21117c478bd9Sstevel@tonic-gate } else { 21127c478bd9Sstevel@tonic-gate /* print in ASCII form */ 21137c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 21147c478bd9Sstevel@tonic-gate uval.string_val = gr->gr_name; 21157c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 21167c478bd9Sstevel@tonic-gate } 21177c478bd9Sstevel@tonic-gate } 21187c478bd9Sstevel@tonic-gate /* print in integer form */ 21197c478bd9Sstevel@tonic-gate if ((context->format & PRF_RAWM) || (returnstat == 1)) { 21207c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_INT32; 21217c478bd9Sstevel@tonic-gate uval.int32_val = gid; 21227c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 21237c478bd9Sstevel@tonic-gate } 21247c478bd9Sstevel@tonic-gate return (returnstat); 21257c478bd9Sstevel@tonic-gate } 21267c478bd9Sstevel@tonic-gate 21277c478bd9Sstevel@tonic-gate 21287c478bd9Sstevel@tonic-gate /* 21297c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 21307c478bd9Sstevel@tonic-gate * pa_pw_uid_gr_gid() : Issues pr_adr_u_int32 to reads uid or group uid 21317c478bd9Sstevel@tonic-gate * from input stream 21327c478bd9Sstevel@tonic-gate * pointed to by audit_adr, and displays it in either 21337c478bd9Sstevel@tonic-gate * raw form or its ASCII representation, if status >= 0. 21347c478bd9Sstevel@tonic-gate * return codes : -1 - error 21357c478bd9Sstevel@tonic-gate * : 1 - warning, passwd entry not found 21367c478bd9Sstevel@tonic-gate * : 0 - successful 21377c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 21387c478bd9Sstevel@tonic-gate */ 21397c478bd9Sstevel@tonic-gate int 21407c478bd9Sstevel@tonic-gate pa_pw_uid_gr_gid(pr_context_t *context, int status, int flag) 21417c478bd9Sstevel@tonic-gate { 21427c478bd9Sstevel@tonic-gate int returnstat; 21437c478bd9Sstevel@tonic-gate uint32_t value; 21447c478bd9Sstevel@tonic-gate uval_t uval; 21457c478bd9Sstevel@tonic-gate 21467c478bd9Sstevel@tonic-gate if (status < 0) 21477c478bd9Sstevel@tonic-gate return (status); 21487c478bd9Sstevel@tonic-gate 21497c478bd9Sstevel@tonic-gate /* get value of a_type */ 21507c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_int32(context, &value, 1)) != 0) 21517c478bd9Sstevel@tonic-gate return (returnstat); 21527c478bd9Sstevel@tonic-gate 21537c478bd9Sstevel@tonic-gate if ((returnstat = open_tag(context, TAG_ACLTYPE)) != 0) 21547c478bd9Sstevel@tonic-gate return (returnstat); 21557c478bd9Sstevel@tonic-gate 21567c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT32; 21577c478bd9Sstevel@tonic-gate uval.uint32_val = value; 21587c478bd9Sstevel@tonic-gate if ((returnstat = pa_print(context, &uval, flag)) != 0) 21597c478bd9Sstevel@tonic-gate return (returnstat); 21607c478bd9Sstevel@tonic-gate 21617c478bd9Sstevel@tonic-gate if ((returnstat = close_tag(context, TAG_ACLTYPE)) != 0) 21627c478bd9Sstevel@tonic-gate return (returnstat); 21637c478bd9Sstevel@tonic-gate 21647c478bd9Sstevel@tonic-gate if ((returnstat = open_tag(context, TAG_ACLVAL)) != 0) 21657c478bd9Sstevel@tonic-gate return (returnstat); 21667c478bd9Sstevel@tonic-gate /* 21677c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE 21687c478bd9Sstevel@tonic-gate * The "mask" and "other" strings refer to the class mask 21697c478bd9Sstevel@tonic-gate * and other (or world) entries in an ACL. 21707c478bd9Sstevel@tonic-gate * The "unrecognized" string refers to an unrecognized ACL 21717c478bd9Sstevel@tonic-gate * entry. 21727c478bd9Sstevel@tonic-gate */ 21737c478bd9Sstevel@tonic-gate switch (value) { 21747c478bd9Sstevel@tonic-gate case USER_OBJ: 21757c478bd9Sstevel@tonic-gate case USER: 21767c478bd9Sstevel@tonic-gate returnstat = pa_pw_uid(context, returnstat, flag); 21777c478bd9Sstevel@tonic-gate break; 21787c478bd9Sstevel@tonic-gate case GROUP_OBJ: 21797c478bd9Sstevel@tonic-gate case GROUP: 21807c478bd9Sstevel@tonic-gate returnstat = pa_gr_uid(context, returnstat, flag); 21817c478bd9Sstevel@tonic-gate break; 21827c478bd9Sstevel@tonic-gate case CLASS_OBJ: 21837c478bd9Sstevel@tonic-gate returnstat = pr_adr_u_int32(context, &value, 1); 21847c478bd9Sstevel@tonic-gate if (returnstat != 0) 21857c478bd9Sstevel@tonic-gate return (returnstat); 21867c478bd9Sstevel@tonic-gate 21877c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 21887c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 21897c478bd9Sstevel@tonic-gate uval.string_val = gettext("mask"); 21907c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 21917c478bd9Sstevel@tonic-gate } else { 21927c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT32; 21937c478bd9Sstevel@tonic-gate uval.uint32_val = value; 21947c478bd9Sstevel@tonic-gate if ((returnstat = pa_print(context, &uval, flag)) != 0) 21957c478bd9Sstevel@tonic-gate return (returnstat); 21967c478bd9Sstevel@tonic-gate } 21977c478bd9Sstevel@tonic-gate break; 21987c478bd9Sstevel@tonic-gate case OTHER_OBJ: 21997c478bd9Sstevel@tonic-gate returnstat = pr_adr_u_int32(context, &value, 1); 22007c478bd9Sstevel@tonic-gate if (returnstat != 0) 22017c478bd9Sstevel@tonic-gate return (returnstat); 22027c478bd9Sstevel@tonic-gate 22037c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 22047c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 22057c478bd9Sstevel@tonic-gate uval.string_val = gettext("other"); 22067c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 22077c478bd9Sstevel@tonic-gate } else { 22087c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT32; 22097c478bd9Sstevel@tonic-gate uval.uint32_val = value; 22107c478bd9Sstevel@tonic-gate if ((returnstat = pa_print(context, &uval, flag)) != 0) 22117c478bd9Sstevel@tonic-gate return (returnstat); 22127c478bd9Sstevel@tonic-gate } 22137c478bd9Sstevel@tonic-gate break; 22147c478bd9Sstevel@tonic-gate default: 22157c478bd9Sstevel@tonic-gate returnstat = pr_adr_u_int32(context, &value, 1); 22167c478bd9Sstevel@tonic-gate if (returnstat != 0) 22177c478bd9Sstevel@tonic-gate return (returnstat); 22187c478bd9Sstevel@tonic-gate 22197c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 22207c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 22217c478bd9Sstevel@tonic-gate uval.string_val = gettext("unrecognized"); 22227c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 22237c478bd9Sstevel@tonic-gate } else { 22247c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT32; 22257c478bd9Sstevel@tonic-gate uval.uint32_val = value; 22267c478bd9Sstevel@tonic-gate if ((returnstat = pa_print(context, &uval, flag)) != 0) 22277c478bd9Sstevel@tonic-gate return (returnstat); 22287c478bd9Sstevel@tonic-gate } 22297c478bd9Sstevel@tonic-gate } 22307c478bd9Sstevel@tonic-gate 22317c478bd9Sstevel@tonic-gate if ((returnstat = close_tag(context, TAG_ACLVAL)) != 0) 22327c478bd9Sstevel@tonic-gate return (returnstat); 22337c478bd9Sstevel@tonic-gate 22347c478bd9Sstevel@tonic-gate return (returnstat); 22357c478bd9Sstevel@tonic-gate } 22367c478bd9Sstevel@tonic-gate 22377c478bd9Sstevel@tonic-gate 22387c478bd9Sstevel@tonic-gate /* 22397c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 22407c478bd9Sstevel@tonic-gate * pa_event_modifier(): Issues pr_adr_u_short to retrieve the next ADR item from 22417c478bd9Sstevel@tonic-gate * the input stream pointed to by audit_adr. This is the 22427c478bd9Sstevel@tonic-gate * event type, and is displayed in hex; 22437c478bd9Sstevel@tonic-gate * return codes : -1 - error 22447c478bd9Sstevel@tonic-gate * : 0 - successful 22457c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 22467c478bd9Sstevel@tonic-gate */ 22477c478bd9Sstevel@tonic-gate int 22487c478bd9Sstevel@tonic-gate pa_event_modifier(pr_context_t *context, int status, int flag) 22497c478bd9Sstevel@tonic-gate { 22507c478bd9Sstevel@tonic-gate int returnstat; 22517c478bd9Sstevel@tonic-gate ushort_t emodifier; 22527c478bd9Sstevel@tonic-gate uval_t uval; 22537c478bd9Sstevel@tonic-gate char modstring[64]; 22547c478bd9Sstevel@tonic-gate 22557c478bd9Sstevel@tonic-gate if (status < 0) 22567c478bd9Sstevel@tonic-gate return (status); 22577c478bd9Sstevel@tonic-gate 22587c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_short(context, &emodifier, 1)) != 0) 22597c478bd9Sstevel@tonic-gate return (returnstat); 22607c478bd9Sstevel@tonic-gate 22617c478bd9Sstevel@tonic-gate /* For XML, only print when modifier is non-zero */ 22627c478bd9Sstevel@tonic-gate if (!(context->format & PRF_XMLM) || (emodifier != 0)) { 22637c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 22647c478bd9Sstevel@tonic-gate 22657c478bd9Sstevel@tonic-gate returnstat = open_tag(context, TAG_EVMOD); 22667c478bd9Sstevel@tonic-gate 22677c478bd9Sstevel@tonic-gate if (returnstat >= 0) { 22687c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 22697c478bd9Sstevel@tonic-gate eventmodifier2string(emodifier, modstring, 22707c478bd9Sstevel@tonic-gate sizeof (modstring)); 22717c478bd9Sstevel@tonic-gate uval.string_val = modstring; 22727c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 22737c478bd9Sstevel@tonic-gate } else { 22747c478bd9Sstevel@tonic-gate uval.string_val = hexconvert((char *)&emodifier, 22757c478bd9Sstevel@tonic-gate sizeof (emodifier), sizeof (emodifier)); 22767c478bd9Sstevel@tonic-gate if (uval.string_val) { 22777c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, 22787c478bd9Sstevel@tonic-gate flag); 22797c478bd9Sstevel@tonic-gate free(uval.string_val); 22807c478bd9Sstevel@tonic-gate } 22817c478bd9Sstevel@tonic-gate } 22827c478bd9Sstevel@tonic-gate } 22837c478bd9Sstevel@tonic-gate if (returnstat >= 0) 22847c478bd9Sstevel@tonic-gate returnstat = close_tag(context, TAG_EVMOD); 22857c478bd9Sstevel@tonic-gate } 22867c478bd9Sstevel@tonic-gate 22877c478bd9Sstevel@tonic-gate return (returnstat); 22887c478bd9Sstevel@tonic-gate } 22897c478bd9Sstevel@tonic-gate 22907c478bd9Sstevel@tonic-gate 22917c478bd9Sstevel@tonic-gate /* 22927c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 22937c478bd9Sstevel@tonic-gate * pa_event_type(): Issues pr_adr_u_short to retrieve the next ADR item from 22947c478bd9Sstevel@tonic-gate * the input stream pointed to by audit_adr. This is the 22957c478bd9Sstevel@tonic-gate * event type, and is displayed in either raw or 22967c478bd9Sstevel@tonic-gate * ASCII form as appropriate 22977c478bd9Sstevel@tonic-gate * return codes : -1 - error 22987c478bd9Sstevel@tonic-gate * : 0 - successful 22997c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 23007c478bd9Sstevel@tonic-gate */ 23017c478bd9Sstevel@tonic-gate int 23027c478bd9Sstevel@tonic-gate pa_event_type(pr_context_t *context, int status, int flag) 23037c478bd9Sstevel@tonic-gate { 23047c478bd9Sstevel@tonic-gate ushort_t etype; 23057c478bd9Sstevel@tonic-gate int returnstat; 23067c478bd9Sstevel@tonic-gate au_event_ent_t *p_event = NULL; 23077c478bd9Sstevel@tonic-gate uval_t uval; 23087c478bd9Sstevel@tonic-gate 23097c478bd9Sstevel@tonic-gate if (status >= 0) { 23107c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_short(context, &etype, 1)) == 0) { 23117c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 23127c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 23137c478bd9Sstevel@tonic-gate if (context->format & PRF_NOCACHE) { 23147c478bd9Sstevel@tonic-gate p_event = getauevnum(etype); 23157c478bd9Sstevel@tonic-gate } else { 23167c478bd9Sstevel@tonic-gate (void) cacheauevent(&p_event, etype); 23177c478bd9Sstevel@tonic-gate } 23187c478bd9Sstevel@tonic-gate if (p_event != NULL) { 23197c478bd9Sstevel@tonic-gate if (context->format & PRF_SHORTM) 23207c478bd9Sstevel@tonic-gate uval.string_val = 23217c478bd9Sstevel@tonic-gate p_event->ae_name; 23227c478bd9Sstevel@tonic-gate else 23237c478bd9Sstevel@tonic-gate uval.string_val = 23247c478bd9Sstevel@tonic-gate p_event->ae_desc; 23257c478bd9Sstevel@tonic-gate } else { 23267c478bd9Sstevel@tonic-gate uval.string_val = 23277c478bd9Sstevel@tonic-gate gettext("invalid event number"); 23287c478bd9Sstevel@tonic-gate } 23297c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 23307c478bd9Sstevel@tonic-gate } else { 23317c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_USHORT; 23327c478bd9Sstevel@tonic-gate uval.ushort_val = etype; 23337c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 23347c478bd9Sstevel@tonic-gate } 23357c478bd9Sstevel@tonic-gate } 23367c478bd9Sstevel@tonic-gate return (returnstat); 23377c478bd9Sstevel@tonic-gate } else 23387c478bd9Sstevel@tonic-gate return (status); 23397c478bd9Sstevel@tonic-gate 23407c478bd9Sstevel@tonic-gate } 23417c478bd9Sstevel@tonic-gate 23427c478bd9Sstevel@tonic-gate 23437c478bd9Sstevel@tonic-gate /* 23447c478bd9Sstevel@tonic-gate * Print time from struct timeval to millisecond resolution. 23457c478bd9Sstevel@tonic-gate * 23467c478bd9Sstevel@tonic-gate * typedef long time_t; time of day in seconds 23477c478bd9Sstevel@tonic-gate * typedef long useconds_t; signed # of microseconds 23487c478bd9Sstevel@tonic-gate * 23497c478bd9Sstevel@tonic-gate * struct timeval { 23507c478bd9Sstevel@tonic-gate * time_t tv_sec; seconds 23517c478bd9Sstevel@tonic-gate * suseconds_t tv_usec; and microseconds 23527c478bd9Sstevel@tonic-gate * }; 23537c478bd9Sstevel@tonic-gate */ 23547c478bd9Sstevel@tonic-gate 23557c478bd9Sstevel@tonic-gate int 23567c478bd9Sstevel@tonic-gate pa_utime32(pr_context_t *context, int status, int flag) 23577c478bd9Sstevel@tonic-gate { 23587c478bd9Sstevel@tonic-gate uint32_t scale = 1000; /* usec to msec */ 23597c478bd9Sstevel@tonic-gate 23607c478bd9Sstevel@tonic-gate return (do_mtime32(context, status, flag, scale)); 23617c478bd9Sstevel@tonic-gate } 23627c478bd9Sstevel@tonic-gate 23637c478bd9Sstevel@tonic-gate /* 23647c478bd9Sstevel@tonic-gate * Print time from timestruc_t to millisecond resolution. 23657c478bd9Sstevel@tonic-gate * 23667c478bd9Sstevel@tonic-gate * typedef struct timespec timestruct_t; 23677c478bd9Sstevel@tonic-gate * struct timespec{ 23687c478bd9Sstevel@tonic-gate * time_t tv_sec; seconds 23697c478bd9Sstevel@tonic-gate * long tv_nsec; and nanoseconds 23707c478bd9Sstevel@tonic-gate * }; 23717c478bd9Sstevel@tonic-gate */ 23727c478bd9Sstevel@tonic-gate int 23737c478bd9Sstevel@tonic-gate pa_ntime32(pr_context_t *context, int status, int flag) 23747c478bd9Sstevel@tonic-gate { 23757c478bd9Sstevel@tonic-gate uint32_t scale = 1000000; /* nsec to msec */ 23767c478bd9Sstevel@tonic-gate 23777c478bd9Sstevel@tonic-gate return (do_mtime32(context, status, flag, scale)); 23787c478bd9Sstevel@tonic-gate } 23797c478bd9Sstevel@tonic-gate 23807c478bd9Sstevel@tonic-gate /* 23817c478bd9Sstevel@tonic-gate * Format the timezone +/- HH:MM and terminate the string 23827c478bd9Sstevel@tonic-gate * Note tm and tv_sec are the same time. 23837c478bd9Sstevel@tonic-gate * Too bad strftime won't produce an ISO 8601 time zone numeric 23847c478bd9Sstevel@tonic-gate */ 23857c478bd9Sstevel@tonic-gate 23867c478bd9Sstevel@tonic-gate #define MINS (24L * 60) 23877c478bd9Sstevel@tonic-gate static void 23887c478bd9Sstevel@tonic-gate tzone(struct tm *tm, time_t *tv_sec, char *p) 23897c478bd9Sstevel@tonic-gate { 23907c478bd9Sstevel@tonic-gate struct tm *gmt; 23917c478bd9Sstevel@tonic-gate int min_off; 23927c478bd9Sstevel@tonic-gate 23937c478bd9Sstevel@tonic-gate gmt = gmtime(tv_sec); 23947c478bd9Sstevel@tonic-gate 23957c478bd9Sstevel@tonic-gate min_off = ((tm->tm_hour - gmt->tm_hour) * 60) + 23967c478bd9Sstevel@tonic-gate (tm->tm_min - gmt->tm_min); 23977c478bd9Sstevel@tonic-gate 23987c478bd9Sstevel@tonic-gate if (tm->tm_year < gmt->tm_year) /* cross new year */ 23997c478bd9Sstevel@tonic-gate min_off -= MINS; 24007c478bd9Sstevel@tonic-gate else if (tm->tm_year > gmt->tm_year) 24017c478bd9Sstevel@tonic-gate min_off += MINS; 24027c478bd9Sstevel@tonic-gate else if (tm->tm_yday < gmt->tm_yday) /* cross dateline */ 24037c478bd9Sstevel@tonic-gate min_off -= MINS; 24047c478bd9Sstevel@tonic-gate else if (tm->tm_yday > gmt->tm_yday) 24057c478bd9Sstevel@tonic-gate min_off += MINS; 24067c478bd9Sstevel@tonic-gate 24077c478bd9Sstevel@tonic-gate if (min_off < 0) { 24087c478bd9Sstevel@tonic-gate min_off = -min_off; 24097c478bd9Sstevel@tonic-gate *p++ = '-'; 24107c478bd9Sstevel@tonic-gate } else { 24117c478bd9Sstevel@tonic-gate *p++ = '+'; 24127c478bd9Sstevel@tonic-gate } 24137c478bd9Sstevel@tonic-gate 24147c478bd9Sstevel@tonic-gate *p++ = min_off / 600 + '0'; /* 10s of hours */ 24157c478bd9Sstevel@tonic-gate min_off = min_off - min_off / 600 * 600; 24167c478bd9Sstevel@tonic-gate *p++ = min_off / 60 % 10 + '0'; /* hours */ 24177c478bd9Sstevel@tonic-gate min_off = min_off - min_off / 60 * 60; 24187c478bd9Sstevel@tonic-gate *p++ = ':'; 24197c478bd9Sstevel@tonic-gate *p++ = min_off / 10 + '0'; /* 10s of minutes */ 24207c478bd9Sstevel@tonic-gate *p++ = min_off % 10 + '0'; /* minutes */ 24217c478bd9Sstevel@tonic-gate *p = '\0'; 24227c478bd9Sstevel@tonic-gate } 24237c478bd9Sstevel@tonic-gate 24247c478bd9Sstevel@tonic-gate /* 24257c478bd9Sstevel@tonic-gate * Format the milliseconds in place in the string. 24267c478bd9Sstevel@tonic-gate * Borrowed from strftime.c:itoa() 24277c478bd9Sstevel@tonic-gate */ 24287c478bd9Sstevel@tonic-gate static void 24297c478bd9Sstevel@tonic-gate msec32(uint32_t msec, char *p) 24307c478bd9Sstevel@tonic-gate { 24317c478bd9Sstevel@tonic-gate *p++ = msec / 100 + '0'; 24327c478bd9Sstevel@tonic-gate msec = msec - msec / 100 * 100; 24337c478bd9Sstevel@tonic-gate *p++ = msec / 10 + '0'; 24347c478bd9Sstevel@tonic-gate *p++ = msec % 10 +'0'; 24357c478bd9Sstevel@tonic-gate } 24367c478bd9Sstevel@tonic-gate 24377c478bd9Sstevel@tonic-gate /* 24387c478bd9Sstevel@tonic-gate * Format time and print relative to scale factor from micro/nano seconds. 24397c478bd9Sstevel@tonic-gate */ 24407c478bd9Sstevel@tonic-gate static int 24417c478bd9Sstevel@tonic-gate do_mtime32(pr_context_t *context, int status, int flag, uint32_t scale) 24427c478bd9Sstevel@tonic-gate { 24437c478bd9Sstevel@tonic-gate uint32_t t32; 24447c478bd9Sstevel@tonic-gate time_t tv_sec; 24457c478bd9Sstevel@tonic-gate struct tm tm; 24467c478bd9Sstevel@tonic-gate char time_created[sizeof ("YYYY-MM-DD HH:MM:SS.sss -HH:MM")]; 24477c478bd9Sstevel@tonic-gate int returnstat; 24487c478bd9Sstevel@tonic-gate uval_t uval; 24497c478bd9Sstevel@tonic-gate 24507c478bd9Sstevel@tonic-gate if (status < 0) 24517c478bd9Sstevel@tonic-gate return (status); 24527c478bd9Sstevel@tonic-gate 24537c478bd9Sstevel@tonic-gate if ((returnstat = open_tag(context, TAG_ISO)) != 0) 24547c478bd9Sstevel@tonic-gate return (returnstat); 24557c478bd9Sstevel@tonic-gate 24567c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_int32(context, 24577c478bd9Sstevel@tonic-gate (uint32_t *)&tv_sec, 1)) != 0) 24587c478bd9Sstevel@tonic-gate return (returnstat); 24597c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_int32(context, &t32, 1)) == 0) { 24607c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 24617c478bd9Sstevel@tonic-gate (void) localtime_r(&tv_sec, &tm); 24627c478bd9Sstevel@tonic-gate (void) strftime(time_created, 24637c478bd9Sstevel@tonic-gate sizeof ("YYYY-MM-DD HH:MM:SS.xxx "), 24647c478bd9Sstevel@tonic-gate "%Y-%m-%d %H:%M:%S.xxx ", &tm); 24657c478bd9Sstevel@tonic-gate msec32(t32/scale, 24667c478bd9Sstevel@tonic-gate &time_created[sizeof ("YYYY-MM-DD HH:MM:SS.")-1]); 24677c478bd9Sstevel@tonic-gate tzone(&tm, &tv_sec, 24687c478bd9Sstevel@tonic-gate &time_created[ 24697c478bd9Sstevel@tonic-gate sizeof ("YYYY-MM-DD HH:MM:SS.xxx ")-1]); 24707c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 24717c478bd9Sstevel@tonic-gate uval.string_val = time_created; 24727c478bd9Sstevel@tonic-gate } else { 24737c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT32; 24747c478bd9Sstevel@tonic-gate uval.uint32_val = (uint32_t)tv_sec; 24757c478bd9Sstevel@tonic-gate (void) pa_print(context, &uval, 0); 24767c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT32; 24777c478bd9Sstevel@tonic-gate uval.uint32_val = t32; 24787c478bd9Sstevel@tonic-gate } 24797c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 24807c478bd9Sstevel@tonic-gate } 24817c478bd9Sstevel@tonic-gate 24827c478bd9Sstevel@tonic-gate if (returnstat == 0) 24837c478bd9Sstevel@tonic-gate return (close_tag(context, TAG_ISO)); 24847c478bd9Sstevel@tonic-gate else 24857c478bd9Sstevel@tonic-gate return (returnstat); 24867c478bd9Sstevel@tonic-gate } 24877c478bd9Sstevel@tonic-gate 24887c478bd9Sstevel@tonic-gate /* 24897c478bd9Sstevel@tonic-gate * Print time from struct timeval to millisecond resolution. 24907c478bd9Sstevel@tonic-gate * 24917c478bd9Sstevel@tonic-gate * typedef long time_t; time of day in seconds 24927c478bd9Sstevel@tonic-gate * typedef long useconds_t; signed # of microseconds 24937c478bd9Sstevel@tonic-gate * 24947c478bd9Sstevel@tonic-gate * struct timeval { 24957c478bd9Sstevel@tonic-gate * time_t tv_sec; seconds 24967c478bd9Sstevel@tonic-gate * suseconds_t tv_usec; and microseconds 24977c478bd9Sstevel@tonic-gate * }; 24987c478bd9Sstevel@tonic-gate */ 24997c478bd9Sstevel@tonic-gate 25007c478bd9Sstevel@tonic-gate int 25017c478bd9Sstevel@tonic-gate pa_utime64(pr_context_t *context, int status, int flag) 25027c478bd9Sstevel@tonic-gate { 25037c478bd9Sstevel@tonic-gate uint64_t scale = 1000; /* usec to msec */ 25047c478bd9Sstevel@tonic-gate 25057c478bd9Sstevel@tonic-gate return (do_mtime64(context, status, flag, scale)); 25067c478bd9Sstevel@tonic-gate } 25077c478bd9Sstevel@tonic-gate 25087c478bd9Sstevel@tonic-gate /* 25097c478bd9Sstevel@tonic-gate * Print time from timestruc_t to millisecond resolution. 25107c478bd9Sstevel@tonic-gate * 25117c478bd9Sstevel@tonic-gate * typedef struct timespec timestruct_t; 25127c478bd9Sstevel@tonic-gate * struct timespec{ 25137c478bd9Sstevel@tonic-gate * time_t tv_sec; seconds 25147c478bd9Sstevel@tonic-gate * long tv_nsec; and nanoseconds 25157c478bd9Sstevel@tonic-gate * }; 25167c478bd9Sstevel@tonic-gate */ 25177c478bd9Sstevel@tonic-gate int 25187c478bd9Sstevel@tonic-gate pa_ntime64(pr_context_t *context, int status, int flag) 25197c478bd9Sstevel@tonic-gate { 25207c478bd9Sstevel@tonic-gate uint64_t scale = 1000000; /* nsec to msec */ 25217c478bd9Sstevel@tonic-gate 25227c478bd9Sstevel@tonic-gate return (do_mtime64(context, status, flag, scale)); 25237c478bd9Sstevel@tonic-gate } 25247c478bd9Sstevel@tonic-gate 25257c478bd9Sstevel@tonic-gate /* 25267c478bd9Sstevel@tonic-gate * Format the milliseconds in place in the string. 25277c478bd9Sstevel@tonic-gate * Borrowed from strftime.c:itoa() 25287c478bd9Sstevel@tonic-gate */ 25297c478bd9Sstevel@tonic-gate static void 25307c478bd9Sstevel@tonic-gate msec64(uint64_t msec, char *p) 25317c478bd9Sstevel@tonic-gate { 25327c478bd9Sstevel@tonic-gate *p++ = msec / 100 + '0'; 25337c478bd9Sstevel@tonic-gate msec = msec - msec / 100 * 100; 25347c478bd9Sstevel@tonic-gate *p++ = msec / 10 + '0'; 25357c478bd9Sstevel@tonic-gate *p++ = msec % 10 +'0'; 25367c478bd9Sstevel@tonic-gate } 25377c478bd9Sstevel@tonic-gate 25387c478bd9Sstevel@tonic-gate /* 25397c478bd9Sstevel@tonic-gate * Format time and print relative to scale factor from micro/nano seconds. 25407c478bd9Sstevel@tonic-gate */ 25417c478bd9Sstevel@tonic-gate static int 25427c478bd9Sstevel@tonic-gate do_mtime64(pr_context_t *context, int status, int flag, uint64_t scale) 25437c478bd9Sstevel@tonic-gate { 25447c478bd9Sstevel@tonic-gate uint64_t t64_sec; 25457c478bd9Sstevel@tonic-gate uint64_t t64_msec; 25467c478bd9Sstevel@tonic-gate time_t tv_sec; 25477c478bd9Sstevel@tonic-gate struct tm tm; 25487c478bd9Sstevel@tonic-gate char time_created[sizeof ("YYYY-MM-DD HH:MM:SS.sss -HH:MM")]; 25497c478bd9Sstevel@tonic-gate int returnstat; 25507c478bd9Sstevel@tonic-gate uval_t uval; 25517c478bd9Sstevel@tonic-gate 25527c478bd9Sstevel@tonic-gate if (status < 0) 25537c478bd9Sstevel@tonic-gate return (status); 25547c478bd9Sstevel@tonic-gate 25557c478bd9Sstevel@tonic-gate if ((returnstat = open_tag(context, TAG_ISO)) != 0) 25567c478bd9Sstevel@tonic-gate return (returnstat); 25577c478bd9Sstevel@tonic-gate 25587c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_int64(context, &t64_sec, 1)) != 0) 25597c478bd9Sstevel@tonic-gate return (returnstat); 25607c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_int64(context, &t64_msec, 1)) == 0) { 25617c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 25627c478bd9Sstevel@tonic-gate #ifndef _LP64 25637c478bd9Sstevel@tonic-gate /* 25647c478bd9Sstevel@tonic-gate * N.B. 25657c478bd9Sstevel@tonic-gate * This fails for years from 2038 25667c478bd9Sstevel@tonic-gate * The Y2K+38 problem 25677c478bd9Sstevel@tonic-gate */ 25687c478bd9Sstevel@tonic-gate #endif /* !_LP64 */ 25697c478bd9Sstevel@tonic-gate tv_sec = (time_t)t64_sec; 25707c478bd9Sstevel@tonic-gate (void) localtime_r(&tv_sec, &tm); 25717c478bd9Sstevel@tonic-gate (void) strftime(time_created, 25727c478bd9Sstevel@tonic-gate sizeof ("YYYY-MM-DD HH:MM:SS.xxx "), 25737c478bd9Sstevel@tonic-gate "%Y-%m-%d %H:%M:%S.xxx ", &tm); 25747c478bd9Sstevel@tonic-gate msec64(t64_msec/scale, 25757c478bd9Sstevel@tonic-gate &time_created[sizeof ("YYYY-MM-DD HH:MM:SS.")-1]); 25767c478bd9Sstevel@tonic-gate tzone(&tm, &tv_sec, 25777c478bd9Sstevel@tonic-gate &time_created[ 25787c478bd9Sstevel@tonic-gate sizeof ("YYYY-MM-DD HH:MM:SS.xxx ")-1]); 25797c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 25807c478bd9Sstevel@tonic-gate uval.string_val = time_created; 25817c478bd9Sstevel@tonic-gate } else { 25827c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT64; 25837c478bd9Sstevel@tonic-gate uval.uint64_val = t64_sec; 25847c478bd9Sstevel@tonic-gate (void) pa_print(context, &uval, 0); 25857c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT64; 25867c478bd9Sstevel@tonic-gate uval.uint64_val = t64_msec; 25877c478bd9Sstevel@tonic-gate } 25887c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 25897c478bd9Sstevel@tonic-gate } 25907c478bd9Sstevel@tonic-gate 25917c478bd9Sstevel@tonic-gate if (returnstat < 0) 25927c478bd9Sstevel@tonic-gate return (returnstat); 25937c478bd9Sstevel@tonic-gate 25947c478bd9Sstevel@tonic-gate return (close_tag(context, TAG_ISO)); 25957c478bd9Sstevel@tonic-gate } 25967c478bd9Sstevel@tonic-gate 25977c478bd9Sstevel@tonic-gate /* 25987c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 25997c478bd9Sstevel@tonic-gate * pa_error() : convert the return token error code. 26007c478bd9Sstevel@tonic-gate * 26017c478bd9Sstevel@tonic-gate * output : buf string representing return token error code. 26027c478bd9Sstevel@tonic-gate * 26037c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 26047c478bd9Sstevel@tonic-gate */ 26057c478bd9Sstevel@tonic-gate void 26067c478bd9Sstevel@tonic-gate pa_error(const uchar_t err, char *buf, size_t buflen) 26077c478bd9Sstevel@tonic-gate { 26087c478bd9Sstevel@tonic-gate if (err == 0) { 26097c478bd9Sstevel@tonic-gate (void) strlcpy(buf, gettext("success"), buflen); 26107c478bd9Sstevel@tonic-gate } else if ((char)err == -1) { 26117c478bd9Sstevel@tonic-gate (void) strlcpy(buf, gettext("failure"), buflen); 26127c478bd9Sstevel@tonic-gate } else { 26137c478bd9Sstevel@tonic-gate char *emsg = strerror(err); 26147c478bd9Sstevel@tonic-gate 26157c478bd9Sstevel@tonic-gate if (emsg != NULL) { 26167c478bd9Sstevel@tonic-gate (void) strlcpy(buf, gettext("failure: "), buflen); 26177c478bd9Sstevel@tonic-gate (void) strlcat(buf, emsg, buflen); 26187c478bd9Sstevel@tonic-gate } else { 26197c478bd9Sstevel@tonic-gate (void) snprintf(buf, buflen, "%s%d", 26207c478bd9Sstevel@tonic-gate gettext("failure: "), err); 26217c478bd9Sstevel@tonic-gate } 26227c478bd9Sstevel@tonic-gate } 26237c478bd9Sstevel@tonic-gate } 26247c478bd9Sstevel@tonic-gate 26257c478bd9Sstevel@tonic-gate /* 26267c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 26277c478bd9Sstevel@tonic-gate * pa_retval() : convert the return token return value code. 26287c478bd9Sstevel@tonic-gate * 26297c478bd9Sstevel@tonic-gate * output : buf string representing return token error code. 26307c478bd9Sstevel@tonic-gate * 26317c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 26327c478bd9Sstevel@tonic-gate */ 26337c478bd9Sstevel@tonic-gate void 26347c478bd9Sstevel@tonic-gate pa_retval(const int32_t retval, char *buf, size_t buflen) 26357c478bd9Sstevel@tonic-gate { 26367c478bd9Sstevel@tonic-gate struct msg_text *msglist = &adt_msg_text[ADT_LIST_FAIL_VALUE]; 26377c478bd9Sstevel@tonic-gate 26387c478bd9Sstevel@tonic-gate if ((retval + msglist->ml_offset >= msglist->ml_min_index) && 26397c478bd9Sstevel@tonic-gate (retval + msglist->ml_offset <= msglist->ml_max_index)) { 26407c478bd9Sstevel@tonic-gate 26417c478bd9Sstevel@tonic-gate (void) strlcpy(buf, 26427c478bd9Sstevel@tonic-gate gettext(msglist->ml_msg_list[retval + msglist->ml_offset]), 26437c478bd9Sstevel@tonic-gate buflen); 26447c478bd9Sstevel@tonic-gate } else if ((retval >= ADT_FAIL_PAM) && 26457c478bd9Sstevel@tonic-gate (retval < ADT_FAIL_PAM + PAM_TOTAL_ERRNUM)) 26467c478bd9Sstevel@tonic-gate (void) strlcpy(buf, pam_strerror(NULL, retval - ADT_FAIL_PAM), 26477c478bd9Sstevel@tonic-gate buflen); 26487c478bd9Sstevel@tonic-gate else 26497c478bd9Sstevel@tonic-gate (void) snprintf(buf, buflen, "%d", retval); 26507c478bd9Sstevel@tonic-gate } 26517c478bd9Sstevel@tonic-gate 26527c478bd9Sstevel@tonic-gate 26537c478bd9Sstevel@tonic-gate /* 26547c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 26557c478bd9Sstevel@tonic-gate * pa_printstr() : print a given string, translating unprintables 26567c478bd9Sstevel@tonic-gate * : as needed. 26577c478bd9Sstevel@tonic-gate */ 26587c478bd9Sstevel@tonic-gate static int 26597c478bd9Sstevel@tonic-gate pa_printstr(pr_context_t *context, char *str) 26607c478bd9Sstevel@tonic-gate { 26617c478bd9Sstevel@tonic-gate int err = 0; 26627c478bd9Sstevel@tonic-gate int len, printable; 26637c478bd9Sstevel@tonic-gate int mbmax = MB_CUR_MAX; 26647c478bd9Sstevel@tonic-gate wchar_t wc; 26657c478bd9Sstevel@tonic-gate char c; 26667c478bd9Sstevel@tonic-gate 26677c478bd9Sstevel@tonic-gate if (mbmax == 1) { 26687c478bd9Sstevel@tonic-gate /* fast path */ 26697c478bd9Sstevel@tonic-gate while (err == 0 && *str != '\0') { 26707c478bd9Sstevel@tonic-gate c = *str++; 26717c478bd9Sstevel@tonic-gate printable = isprint((unsigned char)c); 26727c478bd9Sstevel@tonic-gate err = pa_putstr(context, printable, &c, 1); 26737c478bd9Sstevel@tonic-gate } 26747c478bd9Sstevel@tonic-gate return (err); 26757c478bd9Sstevel@tonic-gate } 26767c478bd9Sstevel@tonic-gate while (err == 0 && *str != '\0') { 26777c478bd9Sstevel@tonic-gate len = mbtowc(&wc, str, mbmax); 26787c478bd9Sstevel@tonic-gate if (len <= 0) { 26797c478bd9Sstevel@tonic-gate len = 1; 26807c478bd9Sstevel@tonic-gate printable = 0; 26817c478bd9Sstevel@tonic-gate } else { 26827c478bd9Sstevel@tonic-gate printable = iswprint(wc); 26837c478bd9Sstevel@tonic-gate } 26847c478bd9Sstevel@tonic-gate err = pa_putstr(context, printable, str, len); 26857c478bd9Sstevel@tonic-gate str += len; 26867c478bd9Sstevel@tonic-gate } 26877c478bd9Sstevel@tonic-gate return (err); 26887c478bd9Sstevel@tonic-gate } 26897c478bd9Sstevel@tonic-gate 26907c478bd9Sstevel@tonic-gate /* 26917c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 26927c478bd9Sstevel@tonic-gate * pa_print() : print as one str or formatted for easy reading. 26937c478bd9Sstevel@tonic-gate * : flag - indicates whether to output a new line for 26947c478bd9Sstevel@tonic-gate * : multi-line output. 26957c478bd9Sstevel@tonic-gate * : = 0; no new line 26967c478bd9Sstevel@tonic-gate * : = 1; new line if regular output 26977c478bd9Sstevel@tonic-gate * output : The audit record information is displayed in the 26987c478bd9Sstevel@tonic-gate * type specified by uvaltype and value specified in 26997c478bd9Sstevel@tonic-gate * uval. The printing of the delimiter or newline is 27007c478bd9Sstevel@tonic-gate * determined by PRF_ONELINE, and the flag value, 27017c478bd9Sstevel@tonic-gate * as follows: 27027c478bd9Sstevel@tonic-gate * +--------+------+------+-----------------+ 27037c478bd9Sstevel@tonic-gate * |ONELINE | flag | last | Action | 27047c478bd9Sstevel@tonic-gate * +--------+------+------+-----------------+ 27057c478bd9Sstevel@tonic-gate * | Y | Y | T | print new line | 27067c478bd9Sstevel@tonic-gate * | Y | Y | F | print delimiter | 27077c478bd9Sstevel@tonic-gate * | Y | N | T | print new line | 27087c478bd9Sstevel@tonic-gate * | Y | N | F | print delimiter | 27097c478bd9Sstevel@tonic-gate * | N | Y | T | print new line | 27107c478bd9Sstevel@tonic-gate * | N | Y | F | print new line | 27117c478bd9Sstevel@tonic-gate * | N | N | T | print new line | 27127c478bd9Sstevel@tonic-gate * | N | N | F | print delimiter | 27137c478bd9Sstevel@tonic-gate * +--------+------+------+-----------------+ 27147c478bd9Sstevel@tonic-gate * 27157c478bd9Sstevel@tonic-gate * return codes : -1 - error 27167c478bd9Sstevel@tonic-gate * 0 - successful 27177c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 27187c478bd9Sstevel@tonic-gate */ 27197c478bd9Sstevel@tonic-gate int 27207c478bd9Sstevel@tonic-gate pa_print(pr_context_t *context, uval_t *uval, int flag) 27217c478bd9Sstevel@tonic-gate { 27227c478bd9Sstevel@tonic-gate int returnstat = 0; 27237c478bd9Sstevel@tonic-gate int last; 27247c478bd9Sstevel@tonic-gate 27257c478bd9Sstevel@tonic-gate switch (uval->uvaltype) { 27267c478bd9Sstevel@tonic-gate case PRA_INT32: 27277c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%d", uval->int32_val); 27287c478bd9Sstevel@tonic-gate break; 27297c478bd9Sstevel@tonic-gate case PRA_UINT32: 27307c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%u", uval->uint32_val); 27317c478bd9Sstevel@tonic-gate break; 27327c478bd9Sstevel@tonic-gate case PRA_INT64: 27337c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%"PRId64, uval->int64_val); 27347c478bd9Sstevel@tonic-gate break; 27357c478bd9Sstevel@tonic-gate case PRA_UINT64: 27367c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%"PRIu64, uval->uint64_val); 27377c478bd9Sstevel@tonic-gate break; 27387c478bd9Sstevel@tonic-gate case PRA_SHORT: 27397c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%hd", uval->short_val); 27407c478bd9Sstevel@tonic-gate break; 27417c478bd9Sstevel@tonic-gate case PRA_USHORT: 27427c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%hu", uval->ushort_val); 27437c478bd9Sstevel@tonic-gate break; 27447c478bd9Sstevel@tonic-gate case PRA_CHAR: 27457c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%c", uval->char_val); 27467c478bd9Sstevel@tonic-gate break; 27477c478bd9Sstevel@tonic-gate case PRA_BYTE: 27487c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%d", uval->char_val); 27497c478bd9Sstevel@tonic-gate break; 27507c478bd9Sstevel@tonic-gate case PRA_STRING: 27517c478bd9Sstevel@tonic-gate returnstat = pa_printstr(context, uval->string_val); 27527c478bd9Sstevel@tonic-gate break; 27537c478bd9Sstevel@tonic-gate case PRA_HEX32: 27547c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "0x%x", uval->int32_val); 27557c478bd9Sstevel@tonic-gate break; 27567c478bd9Sstevel@tonic-gate case PRA_HEX64: 27577c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "0x%"PRIx64, uval->int64_val); 27587c478bd9Sstevel@tonic-gate break; 27597c478bd9Sstevel@tonic-gate case PRA_SHEX: 27607c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "0x%hx", uval->short_val); 27617c478bd9Sstevel@tonic-gate break; 27627c478bd9Sstevel@tonic-gate case PRA_OCT: 27637c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%ho", uval->ushort_val); 27647c478bd9Sstevel@tonic-gate break; 27657c478bd9Sstevel@tonic-gate case PRA_LOCT: 27667c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%o", (int)uval->uint32_val); 27677c478bd9Sstevel@tonic-gate break; 27687c478bd9Sstevel@tonic-gate default: 27697c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("praudit: Unknown type.\n")); 27707c478bd9Sstevel@tonic-gate returnstat = -1; 27717c478bd9Sstevel@tonic-gate break; 27727c478bd9Sstevel@tonic-gate } 27737c478bd9Sstevel@tonic-gate if (returnstat < 0) 27747c478bd9Sstevel@tonic-gate return (returnstat); 27757c478bd9Sstevel@tonic-gate 27767c478bd9Sstevel@tonic-gate last = (context->audit_adr->adr_now == 27777c478bd9Sstevel@tonic-gate (context->audit_rec_start + context->audit_rec_len)); 27787c478bd9Sstevel@tonic-gate 27797c478bd9Sstevel@tonic-gate if (!(context->format & PRF_XMLM)) { 27807c478bd9Sstevel@tonic-gate if (!(context->format & PRF_ONELINE)) { 27817c478bd9Sstevel@tonic-gate if ((flag == 1) || last) 27827c478bd9Sstevel@tonic-gate returnstat = pr_putchar(context, '\n'); 27837c478bd9Sstevel@tonic-gate else 27847c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%s", 27857c478bd9Sstevel@tonic-gate context->SEPARATOR); 27867c478bd9Sstevel@tonic-gate } else { 27877c478bd9Sstevel@tonic-gate if (!last) 27887c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%s", 27897c478bd9Sstevel@tonic-gate context->SEPARATOR); 27907c478bd9Sstevel@tonic-gate else 27917c478bd9Sstevel@tonic-gate returnstat = pr_putchar(context, '\n'); 27927c478bd9Sstevel@tonic-gate } 27937c478bd9Sstevel@tonic-gate } 27947c478bd9Sstevel@tonic-gate if ((returnstat == 0) && (context->data_mode == FILEMODE)) 27957c478bd9Sstevel@tonic-gate (void) fflush(stdout); 27967c478bd9Sstevel@tonic-gate 27977c478bd9Sstevel@tonic-gate return (returnstat); 27987c478bd9Sstevel@tonic-gate } 27997c478bd9Sstevel@tonic-gate 28007c478bd9Sstevel@tonic-gate /* 28017c478bd9Sstevel@tonic-gate * Convert binary data to ASCII for printing. 28027c478bd9Sstevel@tonic-gate */ 28037c478bd9Sstevel@tonic-gate void 28047c478bd9Sstevel@tonic-gate convertascii(char *p, char *c, int size) 28057c478bd9Sstevel@tonic-gate { 28067c478bd9Sstevel@tonic-gate register int i; 28077c478bd9Sstevel@tonic-gate 28087c478bd9Sstevel@tonic-gate for (i = 0; i < size; i++) { 28097c478bd9Sstevel@tonic-gate *(c + i) = (char)toascii(*(c + i)); 28107c478bd9Sstevel@tonic-gate if ((int)iscntrl(*(c + i))) { 28117c478bd9Sstevel@tonic-gate *p++ = '^'; 28127c478bd9Sstevel@tonic-gate *p++ = (char)(*(c + i) + 0x40); 28137c478bd9Sstevel@tonic-gate } else 28147c478bd9Sstevel@tonic-gate *p++ = *(c + i); 28157c478bd9Sstevel@tonic-gate } 28167c478bd9Sstevel@tonic-gate 28177c478bd9Sstevel@tonic-gate *p = '\0'; 28187c478bd9Sstevel@tonic-gate 28197c478bd9Sstevel@tonic-gate } 28207c478bd9Sstevel@tonic-gate 28217c478bd9Sstevel@tonic-gate 28227c478bd9Sstevel@tonic-gate /* 28237c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 28247c478bd9Sstevel@tonic-gate * pa_xgeneric: Process Xobject token and display contents 28257c478bd9Sstevel@tonic-gate * This routine will handle many of the attribute 28267c478bd9Sstevel@tonic-gate * types introduced in TS 2.x, such as: 28277c478bd9Sstevel@tonic-gate * 28287c478bd9Sstevel@tonic-gate * AUT_XCOLORMAP, AUT_XCURSOR, AUT_XFONT, 28297c478bd9Sstevel@tonic-gate * AUT_XGC, AUT_XPIXMAP, AUT_XWINDOW 28307c478bd9Sstevel@tonic-gate * 28317c478bd9Sstevel@tonic-gate * NOTE: At the time of call, the token id has been retrieved 28327c478bd9Sstevel@tonic-gate * 28337c478bd9Sstevel@tonic-gate * return codes : -1 - error 28347c478bd9Sstevel@tonic-gate * : 0 - successful 28357c478bd9Sstevel@tonic-gate * NOTE: At the time of call, the xatom token id has been retrieved 28367c478bd9Sstevel@tonic-gate * 28377c478bd9Sstevel@tonic-gate * Format of xobj 28387c478bd9Sstevel@tonic-gate * text token id adr_char 28397c478bd9Sstevel@tonic-gate * XID adr_u_int32 28407c478bd9Sstevel@tonic-gate * creator uid adr_pw_uid 28417c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 28427c478bd9Sstevel@tonic-gate */ 28437c478bd9Sstevel@tonic-gate int 28447c478bd9Sstevel@tonic-gate pa_xgeneric(pr_context_t *context) 28457c478bd9Sstevel@tonic-gate { 28467c478bd9Sstevel@tonic-gate int returnstat; 28477c478bd9Sstevel@tonic-gate 28487c478bd9Sstevel@tonic-gate returnstat = process_tag(context, TAG_XID, 0, 0); 28497c478bd9Sstevel@tonic-gate return (process_tag(context, TAG_XCUID, returnstat, 1)); 28507c478bd9Sstevel@tonic-gate } 28517c478bd9Sstevel@tonic-gate 28527c478bd9Sstevel@tonic-gate 28537c478bd9Sstevel@tonic-gate /* 28547c478bd9Sstevel@tonic-gate * ------------------------------------------------------------------------ 28557c478bd9Sstevel@tonic-gate * pa_liaison : Issues pr_adr_char to retrieve the next ADR item from the 28567c478bd9Sstevel@tonic-gate * input stream pointed to by audit_adr, and prints it 28577c478bd9Sstevel@tonic-gate * if status >= 0 either in ASCII or raw form 28587c478bd9Sstevel@tonic-gate * return codes : -1 - error 28597c478bd9Sstevel@tonic-gate * : 0 - successful 28607c478bd9Sstevel@tonic-gate * : 1 - warning, unknown label type 28617c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 28627c478bd9Sstevel@tonic-gate */ 28637c478bd9Sstevel@tonic-gate int 28647c478bd9Sstevel@tonic-gate pa_liaison(pr_context_t *context, int status, int flag) 28657c478bd9Sstevel@tonic-gate { 28667c478bd9Sstevel@tonic-gate int returnstat; 28677c478bd9Sstevel@tonic-gate int32_t li; 28687c478bd9Sstevel@tonic-gate uval_t uval; 28697c478bd9Sstevel@tonic-gate 28707c478bd9Sstevel@tonic-gate if (status >= 0) { 28717c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_int32(context, &li, 1)) != 0) { 28727c478bd9Sstevel@tonic-gate return (returnstat); 28737c478bd9Sstevel@tonic-gate } 28747c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 28757c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT32; 28767c478bd9Sstevel@tonic-gate uval.uint32_val = li; 28777c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 28787c478bd9Sstevel@tonic-gate } 28797c478bd9Sstevel@tonic-gate /* print in hexadecimal form */ 28807c478bd9Sstevel@tonic-gate if ((context->format & PRF_RAWM) || (returnstat == 1)) { 28817c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_HEX32; 28827c478bd9Sstevel@tonic-gate uval.uint32_val = li; 28837c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 28847c478bd9Sstevel@tonic-gate } 28857c478bd9Sstevel@tonic-gate return (returnstat); 28867c478bd9Sstevel@tonic-gate } else 28877c478bd9Sstevel@tonic-gate return (status); 28887c478bd9Sstevel@tonic-gate } 28897c478bd9Sstevel@tonic-gate 28907c478bd9Sstevel@tonic-gate /* 28917c478bd9Sstevel@tonic-gate * ------------------------------------------------------------------------ 28927c478bd9Sstevel@tonic-gate * pa_xid : Issues pr_adr_int32 to retrieve the XID from the input 28937c478bd9Sstevel@tonic-gate * stream pointed to by audit_adr, and prints it if 28947c478bd9Sstevel@tonic-gate * status >= 0 either in ASCII or raw form 28957c478bd9Sstevel@tonic-gate * return codes : -1 - error 28967c478bd9Sstevel@tonic-gate * : 0 - successful 28977c478bd9Sstevel@tonic-gate * : 1 - warning, unknown label type 28987c478bd9Sstevel@tonic-gate * ------------------------------------------------------------------------ 28997c478bd9Sstevel@tonic-gate */ 29007c478bd9Sstevel@tonic-gate 29017c478bd9Sstevel@tonic-gate int 29027c478bd9Sstevel@tonic-gate pa_xid(pr_context_t *context, int status, int flag) 29037c478bd9Sstevel@tonic-gate { 29047c478bd9Sstevel@tonic-gate int returnstat; 29057c478bd9Sstevel@tonic-gate int32_t xid; 29067c478bd9Sstevel@tonic-gate uval_t uval; 29077c478bd9Sstevel@tonic-gate 29087c478bd9Sstevel@tonic-gate if (status < 0) 29097c478bd9Sstevel@tonic-gate return (status); 29107c478bd9Sstevel@tonic-gate 29117c478bd9Sstevel@tonic-gate /* get XID from stream */ 29127c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_int32(context, (int32_t *)&xid, 1)) != 0) 29137c478bd9Sstevel@tonic-gate return (returnstat); 29147c478bd9Sstevel@tonic-gate 29157c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 29167c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 29177c478bd9Sstevel@tonic-gate uval.string_val = hexconvert((char *)&xid, sizeof (xid), 29187c478bd9Sstevel@tonic-gate sizeof (xid)); 29197c478bd9Sstevel@tonic-gate if (uval.string_val) { 29207c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 29217c478bd9Sstevel@tonic-gate free(uval.string_val); 29227c478bd9Sstevel@tonic-gate } 29237c478bd9Sstevel@tonic-gate } else { 29247c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_INT32; 29257c478bd9Sstevel@tonic-gate uval.int32_val = xid; 29267c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 29277c478bd9Sstevel@tonic-gate } 29287c478bd9Sstevel@tonic-gate 29297c478bd9Sstevel@tonic-gate return (returnstat); 29307c478bd9Sstevel@tonic-gate } 2931