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 581490fd2Sgww * Common Development and Distribution License (the "License"). 681490fd2Sgww * 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*3929e195SMarek Pospisil * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #define _REENTRANT 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <ctype.h> 307c478bd9Sstevel@tonic-gate #include <errno.h> 317c478bd9Sstevel@tonic-gate #include <grp.h> 327c478bd9Sstevel@tonic-gate #include <libintl.h> 337c478bd9Sstevel@tonic-gate #include <netdb.h> 347c478bd9Sstevel@tonic-gate #include <time.h> 357c478bd9Sstevel@tonic-gate #include <pwd.h> 367c478bd9Sstevel@tonic-gate #include <stdio.h> 377c478bd9Sstevel@tonic-gate #include <stdlib.h> 387c478bd9Sstevel@tonic-gate #include <string.h> 397c478bd9Sstevel@tonic-gate #include <wchar.h> 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate #include <arpa/inet.h> 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate #include <bsm/audit.h> 447c478bd9Sstevel@tonic-gate #include <bsm/audit_record.h> 457c478bd9Sstevel@tonic-gate #include <bsm/libbsm.h> 467c478bd9Sstevel@tonic-gate #include <security/pam_appl.h> 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate #include <sys/inttypes.h> 497c478bd9Sstevel@tonic-gate #include <sys/mkdev.h> 507c478bd9Sstevel@tonic-gate #include <sys/types.h> 51a7746f66Stz204579 #include <aclutils.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); 59d0fa49b7STony Nguyen static void eventmodifier2string(au_emod_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, 838dc347dbStz204579 AUP_STRING, 1, 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, 888dc347dbStz204579 AUP_STRING, 1, 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 6988f9294f3Sgww (void) snprintf(buf, sizeof (buf), "%d %d %s", major_32(dev_maj_min), 6997c478bd9Sstevel@tonic-gate minor_32(dev_maj_min), 7007c478bd9Sstevel@tonic-gate ipstring); 7017c478bd9Sstevel@tonic-gate 7027c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 7037c478bd9Sstevel@tonic-gate } 7047c478bd9Sstevel@tonic-gate 7057c478bd9Sstevel@tonic-gate int 7067c478bd9Sstevel@tonic-gate pa_tid32_ex(pr_context_t *context, int status, int flag) 7077c478bd9Sstevel@tonic-gate { 7087c478bd9Sstevel@tonic-gate int returnstat; 7097c478bd9Sstevel@tonic-gate int32_t dev_maj_min; 7107c478bd9Sstevel@tonic-gate uint32_t ip_addr[16]; 7117c478bd9Sstevel@tonic-gate uint32_t ip_type; 7127c478bd9Sstevel@tonic-gate struct in_addr ia; 7137c478bd9Sstevel@tonic-gate char *ipstring; 7147c478bd9Sstevel@tonic-gate char hostname[256]; 7157c478bd9Sstevel@tonic-gate char buf[256]; 7167c478bd9Sstevel@tonic-gate char tbuf[256]; 7177c478bd9Sstevel@tonic-gate uval_t uval; 7187c478bd9Sstevel@tonic-gate 7197c478bd9Sstevel@tonic-gate if (status < 0) 7207c478bd9Sstevel@tonic-gate return (status); 7217c478bd9Sstevel@tonic-gate 7227c478bd9Sstevel@tonic-gate /* get port info */ 7237c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_int32(context, &dev_maj_min, 1)) != 0) 7247c478bd9Sstevel@tonic-gate return (returnstat); 7257c478bd9Sstevel@tonic-gate 7267c478bd9Sstevel@tonic-gate /* get address type */ 7277c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_int32(context, &ip_type, 1)) != 0) 7287c478bd9Sstevel@tonic-gate return (returnstat); 7297c478bd9Sstevel@tonic-gate 7307c478bd9Sstevel@tonic-gate /* legal address types are either AU_IPv4 or AU_IPv6 only */ 7317c478bd9Sstevel@tonic-gate if ((ip_type != AU_IPv4) && (ip_type != AU_IPv6)) 7327c478bd9Sstevel@tonic-gate return (-1); 7337c478bd9Sstevel@tonic-gate 7347c478bd9Sstevel@tonic-gate /* get address (4/16) */ 7357c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, (char *)ip_addr, ip_type)) != 0) 7367c478bd9Sstevel@tonic-gate return (returnstat); 7377c478bd9Sstevel@tonic-gate 7387c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 7397c478bd9Sstevel@tonic-gate if (ip_type == AU_IPv4) { 7407c478bd9Sstevel@tonic-gate uval.string_val = buf; 7417c478bd9Sstevel@tonic-gate 7427c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 7437c478bd9Sstevel@tonic-gate get_Hname(ip_addr[0], hostname, sizeof (hostname)); 7447c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s", 7458f9294f3Sgww major_32(dev_maj_min), minor_32(dev_maj_min), 7467c478bd9Sstevel@tonic-gate hostname); 7477c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 7487c478bd9Sstevel@tonic-gate } 7497c478bd9Sstevel@tonic-gate 7507c478bd9Sstevel@tonic-gate ia.s_addr = ip_addr[0]; 7517c478bd9Sstevel@tonic-gate if ((ipstring = inet_ntoa(ia)) == NULL) 7527c478bd9Sstevel@tonic-gate return (-1); 7537c478bd9Sstevel@tonic-gate 7547c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s", 7558f9294f3Sgww major_32(dev_maj_min), minor_32(dev_maj_min), ipstring); 7567c478bd9Sstevel@tonic-gate 7577c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 7587c478bd9Sstevel@tonic-gate } else { 7597c478bd9Sstevel@tonic-gate uval.string_val = buf; 7607c478bd9Sstevel@tonic-gate 7617c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 7627c478bd9Sstevel@tonic-gate get_Hname_ex(ip_addr, hostname, sizeof (hostname)); 7637c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s", 7648f9294f3Sgww major_32(dev_maj_min), minor_32(dev_maj_min), 7657c478bd9Sstevel@tonic-gate hostname); 7667c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 7677c478bd9Sstevel@tonic-gate } 7687c478bd9Sstevel@tonic-gate 7697c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET6, (void *) ip_addr, tbuf, 7707c478bd9Sstevel@tonic-gate sizeof (tbuf)); 7717c478bd9Sstevel@tonic-gate 7727c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s", 7738f9294f3Sgww major_32(dev_maj_min), minor_32(dev_maj_min), tbuf); 7747c478bd9Sstevel@tonic-gate 7757c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 7767c478bd9Sstevel@tonic-gate } 7777c478bd9Sstevel@tonic-gate } 7787c478bd9Sstevel@tonic-gate 7797c478bd9Sstevel@tonic-gate int 7807c478bd9Sstevel@tonic-gate pa_ip_addr(pr_context_t *context, int status, int flag) 7817c478bd9Sstevel@tonic-gate { 7827c478bd9Sstevel@tonic-gate int returnstat; 7837c478bd9Sstevel@tonic-gate uval_t uval; 7847c478bd9Sstevel@tonic-gate uint32_t ip_addr[4]; 7857c478bd9Sstevel@tonic-gate uint32_t ip_type; 7867c478bd9Sstevel@tonic-gate struct in_addr ia; 7877c478bd9Sstevel@tonic-gate char *ipstring; 7887c478bd9Sstevel@tonic-gate char hostname[256]; 7897c478bd9Sstevel@tonic-gate char buf[256]; 7907c478bd9Sstevel@tonic-gate char tbuf[256]; 7917c478bd9Sstevel@tonic-gate 7927c478bd9Sstevel@tonic-gate if (status < 0) 7937c478bd9Sstevel@tonic-gate return (status); 7947c478bd9Sstevel@tonic-gate 7957c478bd9Sstevel@tonic-gate /* get address type */ 7967c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_int32(context, &ip_type, 1)) != 0) 7977c478bd9Sstevel@tonic-gate return (returnstat); 7987c478bd9Sstevel@tonic-gate 7997c478bd9Sstevel@tonic-gate /* legal address type is AU_IPv4 or AU_IPv6 */ 8007c478bd9Sstevel@tonic-gate if ((ip_type != AU_IPv4) && (ip_type != AU_IPv6)) 8017c478bd9Sstevel@tonic-gate return (-1); 8027c478bd9Sstevel@tonic-gate 8037c478bd9Sstevel@tonic-gate /* get address (4/16) */ 8047c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, (char *)ip_addr, ip_type)) != 0) 8057c478bd9Sstevel@tonic-gate return (returnstat); 8067c478bd9Sstevel@tonic-gate 8077c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 8087c478bd9Sstevel@tonic-gate if (ip_type == AU_IPv4) { 8097c478bd9Sstevel@tonic-gate uval.string_val = buf; 8107c478bd9Sstevel@tonic-gate 8117c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 8127c478bd9Sstevel@tonic-gate get_Hname(ip_addr[0], hostname, sizeof (hostname)); 8138f9294f3Sgww (void) snprintf(buf, sizeof (buf), "%s", hostname); 8147c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 8157c478bd9Sstevel@tonic-gate } 8167c478bd9Sstevel@tonic-gate 8177c478bd9Sstevel@tonic-gate ia.s_addr = ip_addr[0]; 8187c478bd9Sstevel@tonic-gate if ((ipstring = inet_ntoa(ia)) == NULL) 8197c478bd9Sstevel@tonic-gate return (-1); 8207c478bd9Sstevel@tonic-gate 8218f9294f3Sgww (void) snprintf(buf, sizeof (buf), "%s", ipstring); 8227c478bd9Sstevel@tonic-gate 8237c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 8247c478bd9Sstevel@tonic-gate } else { 8257c478bd9Sstevel@tonic-gate uval.string_val = buf; 8267c478bd9Sstevel@tonic-gate 8277c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 8287c478bd9Sstevel@tonic-gate get_Hname_ex(ip_addr, hostname, sizeof (hostname)); 8297c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%s", 8307c478bd9Sstevel@tonic-gate hostname); 8317c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 8327c478bd9Sstevel@tonic-gate } 8337c478bd9Sstevel@tonic-gate 8347c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET6, (void *) ip_addr, tbuf, 8357c478bd9Sstevel@tonic-gate sizeof (tbuf)); 8367c478bd9Sstevel@tonic-gate 8377c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%s", tbuf); 8387c478bd9Sstevel@tonic-gate 8397c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 8407c478bd9Sstevel@tonic-gate } 8417c478bd9Sstevel@tonic-gate 8427c478bd9Sstevel@tonic-gate } 8437c478bd9Sstevel@tonic-gate 8447c478bd9Sstevel@tonic-gate int 8457c478bd9Sstevel@tonic-gate pa_tid64(pr_context_t *context, int status, int flag) 8467c478bd9Sstevel@tonic-gate { 8477c478bd9Sstevel@tonic-gate int returnstat; 8487c478bd9Sstevel@tonic-gate int64_t dev_maj_min; 8497c478bd9Sstevel@tonic-gate uint32_t ip_addr; 8507c478bd9Sstevel@tonic-gate struct in_addr ia; 8517c478bd9Sstevel@tonic-gate char *ipstring; 8527c478bd9Sstevel@tonic-gate char buf[256]; 8537c478bd9Sstevel@tonic-gate uval_t uval; 8547c478bd9Sstevel@tonic-gate 8557c478bd9Sstevel@tonic-gate if (status < 0) 8567c478bd9Sstevel@tonic-gate return (status); 8577c478bd9Sstevel@tonic-gate 8587c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_int64(context, &dev_maj_min, 1)) != 0) 8597c478bd9Sstevel@tonic-gate return (returnstat); 8607c478bd9Sstevel@tonic-gate 8617c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, (char *)&ip_addr, 4)) != 0) 8627c478bd9Sstevel@tonic-gate return (returnstat); 8637c478bd9Sstevel@tonic-gate 8647c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 8657c478bd9Sstevel@tonic-gate uval.string_val = buf; 8667c478bd9Sstevel@tonic-gate 8677c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 8687c478bd9Sstevel@tonic-gate char hostname[256]; 8697c478bd9Sstevel@tonic-gate 8707c478bd9Sstevel@tonic-gate get_Hname(ip_addr, hostname, sizeof (hostname)); 8717c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s", 8728f9294f3Sgww major_64(dev_maj_min), minor_64(dev_maj_min), hostname); 8737c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 8747c478bd9Sstevel@tonic-gate } 8757c478bd9Sstevel@tonic-gate 8767c478bd9Sstevel@tonic-gate ia.s_addr = ip_addr; 8777c478bd9Sstevel@tonic-gate if ((ipstring = inet_ntoa(ia)) == NULL) 8787c478bd9Sstevel@tonic-gate return (-1); 8797c478bd9Sstevel@tonic-gate 8807c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s", 8818f9294f3Sgww major_64(dev_maj_min), minor_64(dev_maj_min), ipstring); 8827c478bd9Sstevel@tonic-gate 8837c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 8847c478bd9Sstevel@tonic-gate } 8857c478bd9Sstevel@tonic-gate 8867c478bd9Sstevel@tonic-gate int 8877c478bd9Sstevel@tonic-gate pa_tid64_ex(pr_context_t *context, int status, int flag) 8887c478bd9Sstevel@tonic-gate { 8897c478bd9Sstevel@tonic-gate int returnstat; 8907c478bd9Sstevel@tonic-gate int64_t dev_maj_min; 8917c478bd9Sstevel@tonic-gate uint32_t ip_addr[4]; 8927c478bd9Sstevel@tonic-gate uint32_t ip_type; 8937c478bd9Sstevel@tonic-gate struct in_addr ia; 8947c478bd9Sstevel@tonic-gate char *ipstring; 8957c478bd9Sstevel@tonic-gate char hostname[256]; 8967c478bd9Sstevel@tonic-gate char buf[256]; 8977c478bd9Sstevel@tonic-gate char tbuf[256]; 8987c478bd9Sstevel@tonic-gate uval_t uval; 8997c478bd9Sstevel@tonic-gate 9007c478bd9Sstevel@tonic-gate if (status < 0) 9017c478bd9Sstevel@tonic-gate return (status); 9027c478bd9Sstevel@tonic-gate 9037c478bd9Sstevel@tonic-gate /* get port info */ 9047c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_int64(context, &dev_maj_min, 1)) != 0) 9057c478bd9Sstevel@tonic-gate return (returnstat); 9067c478bd9Sstevel@tonic-gate 9077c478bd9Sstevel@tonic-gate /* get address type */ 9087c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_int32(context, &ip_type, 1)) != 0) 9097c478bd9Sstevel@tonic-gate return (returnstat); 9107c478bd9Sstevel@tonic-gate 9117c478bd9Sstevel@tonic-gate /* legal address types are either AU_IPv4 or AU_IPv6 only */ 9127c478bd9Sstevel@tonic-gate if ((ip_type != AU_IPv4) && (ip_type != AU_IPv6)) 9137c478bd9Sstevel@tonic-gate return (-1); 9147c478bd9Sstevel@tonic-gate 9157c478bd9Sstevel@tonic-gate /* get address (4/16) */ 9167c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, (char *)&ip_addr, ip_type)) != 0) 9177c478bd9Sstevel@tonic-gate return (returnstat); 9187c478bd9Sstevel@tonic-gate 9197c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 9207c478bd9Sstevel@tonic-gate if (ip_type == AU_IPv4) { 9217c478bd9Sstevel@tonic-gate uval.string_val = buf; 9227c478bd9Sstevel@tonic-gate 9237c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 9247c478bd9Sstevel@tonic-gate get_Hname(ip_addr[0], hostname, sizeof (hostname)); 9257c478bd9Sstevel@tonic-gate uval.string_val = buf; 9267c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s", 9278f9294f3Sgww major_64(dev_maj_min), minor_64(dev_maj_min), 9287c478bd9Sstevel@tonic-gate hostname); 9297c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 9307c478bd9Sstevel@tonic-gate } 9317c478bd9Sstevel@tonic-gate 9327c478bd9Sstevel@tonic-gate ia.s_addr = ip_addr[0]; 9337c478bd9Sstevel@tonic-gate if ((ipstring = inet_ntoa(ia)) == NULL) 9347c478bd9Sstevel@tonic-gate return (-1); 9357c478bd9Sstevel@tonic-gate 9367c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s", 9378f9294f3Sgww major_64(dev_maj_min), minor_64(dev_maj_min), ipstring); 9387c478bd9Sstevel@tonic-gate 9397c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 9407c478bd9Sstevel@tonic-gate } else { 9417c478bd9Sstevel@tonic-gate uval.string_val = buf; 9427c478bd9Sstevel@tonic-gate 9437c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 9447c478bd9Sstevel@tonic-gate get_Hname_ex(ip_addr, hostname, sizeof (hostname)); 9457c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s", 9468f9294f3Sgww major_64(dev_maj_min), minor_64(dev_maj_min), 9477c478bd9Sstevel@tonic-gate hostname); 9487c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 9497c478bd9Sstevel@tonic-gate } 9507c478bd9Sstevel@tonic-gate 9517c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET6, (void *)ip_addr, tbuf, 9527c478bd9Sstevel@tonic-gate sizeof (tbuf)); 9537c478bd9Sstevel@tonic-gate 9547c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s", 9558f9294f3Sgww major_64(dev_maj_min), minor_64(dev_maj_min), tbuf); 9567c478bd9Sstevel@tonic-gate 9577c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 9587c478bd9Sstevel@tonic-gate } 9597c478bd9Sstevel@tonic-gate } 9607c478bd9Sstevel@tonic-gate 9617c478bd9Sstevel@tonic-gate 9627c478bd9Sstevel@tonic-gate /* 9637c478bd9Sstevel@tonic-gate * ---------------------------------------------------------------- 9647c478bd9Sstevel@tonic-gate * findfieldwidth: 9657c478bd9Sstevel@tonic-gate * Returns the field width based on the basic unit and print mode. 9667c478bd9Sstevel@tonic-gate * This routine is called to determine the field width for the 9677c478bd9Sstevel@tonic-gate * data items in the arbitrary data token where the tokens are 9687c478bd9Sstevel@tonic-gate * to be printed in more than one line. The field width can be 9697c478bd9Sstevel@tonic-gate * found in the fwidth structure. 9707c478bd9Sstevel@tonic-gate * 9717c478bd9Sstevel@tonic-gate * Input parameters: 9727c478bd9Sstevel@tonic-gate * basicunit Can be one of AUR_CHAR, AUR_BYTE, AUR_SHORT, 9737c478bd9Sstevel@tonic-gate * AUR_INT32, or AUR_INT64 9747c478bd9Sstevel@tonic-gate * howtoprint Print mode. Can be one of AUP_BINARY, AUP_OCTAL, 9757c478bd9Sstevel@tonic-gate * AUP_DECIMAL, or AUP_HEX. 9767c478bd9Sstevel@tonic-gate * ---------------------------------------------------------------- 9777c478bd9Sstevel@tonic-gate */ 9787c478bd9Sstevel@tonic-gate int 9797c478bd9Sstevel@tonic-gate findfieldwidth(char basicunit, char howtoprint) 9807c478bd9Sstevel@tonic-gate { 9817c478bd9Sstevel@tonic-gate int i, j; 9827c478bd9Sstevel@tonic-gate 9837c478bd9Sstevel@tonic-gate for (i = 0; i < numwidthentries; i++) { 9847c478bd9Sstevel@tonic-gate if (fwidth[i].basic_unit == basicunit) { 9857c478bd9Sstevel@tonic-gate for (j = 0; j <= 4; j++) { 9867c478bd9Sstevel@tonic-gate if (fwidth[i].pwidth[j].print_base == 9878f9294f3Sgww howtoprint) { 9888f9294f3Sgww return ( 9898f9294f3Sgww fwidth[i].pwidth[j].field_width); 9908f9294f3Sgww } 9917c478bd9Sstevel@tonic-gate } 9927c478bd9Sstevel@tonic-gate /* 9937c478bd9Sstevel@tonic-gate * if we got here, then we didn't get what we were after 9947c478bd9Sstevel@tonic-gate */ 9957c478bd9Sstevel@tonic-gate return (0); 9967c478bd9Sstevel@tonic-gate } 9977c478bd9Sstevel@tonic-gate } 9987c478bd9Sstevel@tonic-gate /* if we got here, we didn't get what we wanted either */ 9997c478bd9Sstevel@tonic-gate return (0); 10007c478bd9Sstevel@tonic-gate } 10017c478bd9Sstevel@tonic-gate 10027c478bd9Sstevel@tonic-gate 10037c478bd9Sstevel@tonic-gate /* 10047c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 10057c478bd9Sstevel@tonic-gate * pa_cmd: Retrieves the cmd item from the input stream. 10067c478bd9Sstevel@tonic-gate * return codes : -1 - error 10077c478bd9Sstevel@tonic-gate * : 0 - successful 10087c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 10097c478bd9Sstevel@tonic-gate */ 10107c478bd9Sstevel@tonic-gate int 10117c478bd9Sstevel@tonic-gate pa_cmd(pr_context_t *context, int status, int flag) 10127c478bd9Sstevel@tonic-gate { 10137c478bd9Sstevel@tonic-gate char *cmd; /* cmd */ 10147c478bd9Sstevel@tonic-gate short length; 10157c478bd9Sstevel@tonic-gate int returnstat; 10167c478bd9Sstevel@tonic-gate uval_t uval; 10177c478bd9Sstevel@tonic-gate 10187c478bd9Sstevel@tonic-gate /* 10197c478bd9Sstevel@tonic-gate * We need to know how much space to allocate for our string, so 10207c478bd9Sstevel@tonic-gate * read the length first, then call pr_adr_char to read those bytes. 10217c478bd9Sstevel@tonic-gate */ 10227c478bd9Sstevel@tonic-gate if (status >= 0) { 10237c478bd9Sstevel@tonic-gate if (pr_adr_short(context, &length, 1) == 0) { 10247c478bd9Sstevel@tonic-gate if ((cmd = (char *)malloc(length + 1)) == NULL) 10257c478bd9Sstevel@tonic-gate return (-1); 10267c478bd9Sstevel@tonic-gate if (pr_adr_char(context, cmd, length) == 0) { 10277c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 10287c478bd9Sstevel@tonic-gate uval.string_val = cmd; 10297c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 10307c478bd9Sstevel@tonic-gate } else { 10317c478bd9Sstevel@tonic-gate returnstat = -1; 10327c478bd9Sstevel@tonic-gate } 10337c478bd9Sstevel@tonic-gate free(cmd); 10347c478bd9Sstevel@tonic-gate return (returnstat); 10357c478bd9Sstevel@tonic-gate } else 10367c478bd9Sstevel@tonic-gate return (-1); 10377c478bd9Sstevel@tonic-gate } else 10387c478bd9Sstevel@tonic-gate return (status); 10397c478bd9Sstevel@tonic-gate } 10407c478bd9Sstevel@tonic-gate 10417c478bd9Sstevel@tonic-gate 10427c478bd9Sstevel@tonic-gate 10437c478bd9Sstevel@tonic-gate /* 10447c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 10457c478bd9Sstevel@tonic-gate * pa_adr_byte : Issues pr_adr_char to retrieve the next ADR item from 10467c478bd9Sstevel@tonic-gate * the input stream pointed to by audit_adr, and prints it 10477c478bd9Sstevel@tonic-gate * as an integer if status >= 0 10487c478bd9Sstevel@tonic-gate * return codes : -1 - error 10497c478bd9Sstevel@tonic-gate * : 0 - successful 10507c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 10517c478bd9Sstevel@tonic-gate */ 10527c478bd9Sstevel@tonic-gate int 10537c478bd9Sstevel@tonic-gate pa_adr_byte(pr_context_t *context, int status, int flag) 10547c478bd9Sstevel@tonic-gate { 10557c478bd9Sstevel@tonic-gate char c; 10567c478bd9Sstevel@tonic-gate uval_t uval; 10577c478bd9Sstevel@tonic-gate 10587c478bd9Sstevel@tonic-gate if (status >= 0) { 10597c478bd9Sstevel@tonic-gate if (pr_adr_char(context, &c, 1) == 0) { 10607c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_BYTE; 10617c478bd9Sstevel@tonic-gate uval.char_val = c; 10627c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 10637c478bd9Sstevel@tonic-gate } else 10647c478bd9Sstevel@tonic-gate return (-1); 10657c478bd9Sstevel@tonic-gate } else 10667c478bd9Sstevel@tonic-gate return (status); 10677c478bd9Sstevel@tonic-gate } 10687c478bd9Sstevel@tonic-gate 10697c478bd9Sstevel@tonic-gate /* 10707c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 10717c478bd9Sstevel@tonic-gate * pa_adr_charhex: Issues pr_adr_char to retrieve the next ADR item from 10727c478bd9Sstevel@tonic-gate * the input stream pointed to by audit_adr, and prints it 10737c478bd9Sstevel@tonic-gate * in hexadecimal if status >= 0 10747c478bd9Sstevel@tonic-gate * return codes : -1 - error 10757c478bd9Sstevel@tonic-gate * : 0 - successful 10767c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 10777c478bd9Sstevel@tonic-gate */ 10787c478bd9Sstevel@tonic-gate int 10797c478bd9Sstevel@tonic-gate pa_adr_charhex(pr_context_t *context, int status, int flag) 10807c478bd9Sstevel@tonic-gate { 10817c478bd9Sstevel@tonic-gate char p[2]; 10827c478bd9Sstevel@tonic-gate int returnstat; 10837c478bd9Sstevel@tonic-gate uval_t uval; 10847c478bd9Sstevel@tonic-gate 10857c478bd9Sstevel@tonic-gate if (status >= 0) { 10867c478bd9Sstevel@tonic-gate p[0] = p[1] = 0; 10877c478bd9Sstevel@tonic-gate 10887c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, p, 1)) == 0) { 10897c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 10907c478bd9Sstevel@tonic-gate uval.string_val = hexconvert(p, sizeof (char), 10917c478bd9Sstevel@tonic-gate sizeof (char)); 10927c478bd9Sstevel@tonic-gate if (uval.string_val) { 10937c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 10947c478bd9Sstevel@tonic-gate free(uval.string_val); 10957c478bd9Sstevel@tonic-gate } 10967c478bd9Sstevel@tonic-gate } 10977c478bd9Sstevel@tonic-gate return (returnstat); 10987c478bd9Sstevel@tonic-gate } else 10997c478bd9Sstevel@tonic-gate return (status); 11007c478bd9Sstevel@tonic-gate } 11017c478bd9Sstevel@tonic-gate 11027c478bd9Sstevel@tonic-gate /* 11037c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 11047c478bd9Sstevel@tonic-gate * pa_adr_int32 : Issues pr_adr_int32 to retrieve the next ADR item from the 11057c478bd9Sstevel@tonic-gate * input stream pointed to by audit_adr, and prints it 11067c478bd9Sstevel@tonic-gate * if status >= 0 11077c478bd9Sstevel@tonic-gate * return codes : -1 - error 11087c478bd9Sstevel@tonic-gate * : 0 - successful 11097c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 11107c478bd9Sstevel@tonic-gate */ 11117c478bd9Sstevel@tonic-gate int 11127c478bd9Sstevel@tonic-gate pa_adr_int32(pr_context_t *context, int status, int flag) 11137c478bd9Sstevel@tonic-gate { 11147c478bd9Sstevel@tonic-gate int32_t c; 11157c478bd9Sstevel@tonic-gate uval_t uval; 11167c478bd9Sstevel@tonic-gate 11177c478bd9Sstevel@tonic-gate if (status >= 0) { 11187c478bd9Sstevel@tonic-gate if (pr_adr_int32(context, &c, 1) == 0) { 11197c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_INT32; 11207c478bd9Sstevel@tonic-gate uval.int32_val = c; 11217c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 11227c478bd9Sstevel@tonic-gate } else 11237c478bd9Sstevel@tonic-gate return (-1); 11247c478bd9Sstevel@tonic-gate } else 11257c478bd9Sstevel@tonic-gate return (status); 11267c478bd9Sstevel@tonic-gate } 11277c478bd9Sstevel@tonic-gate 11287c478bd9Sstevel@tonic-gate 11297c478bd9Sstevel@tonic-gate 11307c478bd9Sstevel@tonic-gate 11317c478bd9Sstevel@tonic-gate /* 11327c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 11337c478bd9Sstevel@tonic-gate * pa_adr_int64 : Issues pr_adr_int64 to retrieve the next ADR item from the 11347c478bd9Sstevel@tonic-gate * input stream pointed to by audit_adr, and prints it 11357c478bd9Sstevel@tonic-gate * if status >= 0 11367c478bd9Sstevel@tonic-gate * return codes : -1 - error 11377c478bd9Sstevel@tonic-gate * : 0 - successful 11387c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 11397c478bd9Sstevel@tonic-gate */ 11407c478bd9Sstevel@tonic-gate int 11417c478bd9Sstevel@tonic-gate pa_adr_int64(pr_context_t *context, int status, int flag) 11427c478bd9Sstevel@tonic-gate { 11437c478bd9Sstevel@tonic-gate int64_t c; 11447c478bd9Sstevel@tonic-gate uval_t uval; 11457c478bd9Sstevel@tonic-gate 11467c478bd9Sstevel@tonic-gate if (status >= 0) { 11477c478bd9Sstevel@tonic-gate if (pr_adr_int64(context, &c, 1) == 0) { 11487c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_INT64; 11497c478bd9Sstevel@tonic-gate uval.int64_val = c; 11507c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 11517c478bd9Sstevel@tonic-gate } else 11527c478bd9Sstevel@tonic-gate return (-1); 11537c478bd9Sstevel@tonic-gate } else 11547c478bd9Sstevel@tonic-gate return (status); 11557c478bd9Sstevel@tonic-gate } 11567c478bd9Sstevel@tonic-gate 11577c478bd9Sstevel@tonic-gate /* 11587c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 11597c478bd9Sstevel@tonic-gate * pa_adr_int64hex: Issues pr_adr_int64 to retrieve the next ADR item from the 11607c478bd9Sstevel@tonic-gate * input stream pointed to by audit_adr, and prints it 11617c478bd9Sstevel@tonic-gate * in hexadecimal if status >= 0 11627c478bd9Sstevel@tonic-gate * return codes : -1 - error 11637c478bd9Sstevel@tonic-gate * : 0 - successful 11647c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 11657c478bd9Sstevel@tonic-gate */ 11667c478bd9Sstevel@tonic-gate int 11677c478bd9Sstevel@tonic-gate pa_adr_int32hex(pr_context_t *context, int status, int flag) 11687c478bd9Sstevel@tonic-gate { 11697c478bd9Sstevel@tonic-gate int32_t l; 11707c478bd9Sstevel@tonic-gate int returnstat; 11717c478bd9Sstevel@tonic-gate uval_t uval; 11727c478bd9Sstevel@tonic-gate 11737c478bd9Sstevel@tonic-gate if (status >= 0) { 11747c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_int32(context, &l, 1)) == 0) { 11757c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_HEX32; 11767c478bd9Sstevel@tonic-gate uval.int32_val = l; 11777c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 11787c478bd9Sstevel@tonic-gate } 11797c478bd9Sstevel@tonic-gate return (returnstat); 11807c478bd9Sstevel@tonic-gate } else 11817c478bd9Sstevel@tonic-gate return (status); 11827c478bd9Sstevel@tonic-gate } 11837c478bd9Sstevel@tonic-gate 11847c478bd9Sstevel@tonic-gate /* 11857c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 11867c478bd9Sstevel@tonic-gate * pa_adr_int64hex: Issues pr_adr_int64 to retrieve the next ADR item from the 11877c478bd9Sstevel@tonic-gate * input stream pointed to by audit_adr, and prints it 11887c478bd9Sstevel@tonic-gate * in hexadecimal if status >= 0 11897c478bd9Sstevel@tonic-gate * return codes : -1 - error 11907c478bd9Sstevel@tonic-gate * : 0 - successful 11917c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 11927c478bd9Sstevel@tonic-gate */ 11937c478bd9Sstevel@tonic-gate int 11947c478bd9Sstevel@tonic-gate pa_adr_int64hex(pr_context_t *context, int status, int flag) 11957c478bd9Sstevel@tonic-gate { 11967c478bd9Sstevel@tonic-gate int64_t l; 11977c478bd9Sstevel@tonic-gate int returnstat; 11987c478bd9Sstevel@tonic-gate uval_t uval; 11997c478bd9Sstevel@tonic-gate 12007c478bd9Sstevel@tonic-gate if (status >= 0) { 12017c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_int64(context, &l, 1)) == 0) { 12027c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_HEX64; 12037c478bd9Sstevel@tonic-gate uval.int64_val = l; 12047c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 12057c478bd9Sstevel@tonic-gate } 12067c478bd9Sstevel@tonic-gate return (returnstat); 12077c478bd9Sstevel@tonic-gate } else 12087c478bd9Sstevel@tonic-gate return (status); 12097c478bd9Sstevel@tonic-gate } 12107c478bd9Sstevel@tonic-gate 12117c478bd9Sstevel@tonic-gate 12127c478bd9Sstevel@tonic-gate /* 12137c478bd9Sstevel@tonic-gate * ------------------------------------------------------------------- 12147c478bd9Sstevel@tonic-gate * bu2string: Maps a print basic unit type to a string. 12157c478bd9Sstevel@tonic-gate * returns : The string mapping or "unknown basic unit type". 12167c478bd9Sstevel@tonic-gate * ------------------------------------------------------------------- 12177c478bd9Sstevel@tonic-gate */ 12187c478bd9Sstevel@tonic-gate char * 12197c478bd9Sstevel@tonic-gate bu2string(char basic_unit) 12207c478bd9Sstevel@tonic-gate { 12217c478bd9Sstevel@tonic-gate register int i; 12227c478bd9Sstevel@tonic-gate 12237c478bd9Sstevel@tonic-gate struct bu_map_ent { 12247c478bd9Sstevel@tonic-gate char basic_unit; 12257c478bd9Sstevel@tonic-gate char *string; 12267c478bd9Sstevel@tonic-gate }; 12277c478bd9Sstevel@tonic-gate 12287c478bd9Sstevel@tonic-gate /* 12297c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE 12307c478bd9Sstevel@tonic-gate * These names are data units when displaying the arbitrary data 12317c478bd9Sstevel@tonic-gate * token. 12327c478bd9Sstevel@tonic-gate */ 12337c478bd9Sstevel@tonic-gate 12347c478bd9Sstevel@tonic-gate static struct bu_map_ent bu_map[] = { 12357c478bd9Sstevel@tonic-gate { AUR_BYTE, "byte" }, 12367c478bd9Sstevel@tonic-gate { AUR_CHAR, "char" }, 12377c478bd9Sstevel@tonic-gate { AUR_SHORT, "short" }, 12387c478bd9Sstevel@tonic-gate { AUR_INT32, "int32" }, 12397c478bd9Sstevel@tonic-gate { AUR_INT64, "int64" } }; 12407c478bd9Sstevel@tonic-gate 12417c478bd9Sstevel@tonic-gate for (i = 0; i < sizeof (bu_map) / sizeof (struct bu_map_ent); i++) 12427c478bd9Sstevel@tonic-gate if (basic_unit == bu_map[i].basic_unit) 12437c478bd9Sstevel@tonic-gate return (gettext(bu_map[i].string)); 12447c478bd9Sstevel@tonic-gate 12457c478bd9Sstevel@tonic-gate return (gettext("unknown basic unit type")); 12467c478bd9Sstevel@tonic-gate } 12477c478bd9Sstevel@tonic-gate 12487c478bd9Sstevel@tonic-gate 12497c478bd9Sstevel@tonic-gate /* 12507c478bd9Sstevel@tonic-gate * ------------------------------------------------------------------- 12517c478bd9Sstevel@tonic-gate * eventmodifier2string: Maps event modifier flags to a readable string. 12527c478bd9Sstevel@tonic-gate * returns: The string mapping or "none". 12537c478bd9Sstevel@tonic-gate * ------------------------------------------------------------------- 12547c478bd9Sstevel@tonic-gate */ 12557c478bd9Sstevel@tonic-gate static void 1256d0fa49b7STony Nguyen eventmodifier2string(au_emod_t emodifier, char *modstring, size_t modlen) 12577c478bd9Sstevel@tonic-gate { 12587c478bd9Sstevel@tonic-gate register int i, j; 12597c478bd9Sstevel@tonic-gate 12607c478bd9Sstevel@tonic-gate struct em_map_ent { 12617c478bd9Sstevel@tonic-gate int mask; 12627c478bd9Sstevel@tonic-gate char *string; 12637c478bd9Sstevel@tonic-gate }; 12647c478bd9Sstevel@tonic-gate 12657c478bd9Sstevel@tonic-gate /* 12667c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE 12677c478bd9Sstevel@tonic-gate * These abbreviations represent the event modifier field of the 12687c478bd9Sstevel@tonic-gate * header token. To gain a better understanding of each modifier, 12698f9294f3Sgww * read 12708f9294f3Sgww * System Administration Guide: Security Services >> Solaris Auditing 12718f9294f3Sgww * at http://docs.sun.com. 12727c478bd9Sstevel@tonic-gate */ 12737c478bd9Sstevel@tonic-gate 12747c478bd9Sstevel@tonic-gate static struct em_map_ent em_map[] = { 12757c478bd9Sstevel@tonic-gate { (int)PAD_READ, "rd" }, /* data read from object */ 12767c478bd9Sstevel@tonic-gate { (int)PAD_WRITE, "wr" }, /* data written to object */ 12777c478bd9Sstevel@tonic-gate { (int)PAD_SPRIVUSE, "sp" }, /* successfully used priv */ 12787c478bd9Sstevel@tonic-gate { (int)PAD_FPRIVUSE, "fp" }, /* failed use of priv */ 12797c478bd9Sstevel@tonic-gate { (int)PAD_NONATTR, "na" }, /* non-attributable event */ 12807c478bd9Sstevel@tonic-gate { (int)PAD_FAILURE, "fe" } /* fail audit event */ 12817c478bd9Sstevel@tonic-gate }; 12827c478bd9Sstevel@tonic-gate 12837c478bd9Sstevel@tonic-gate modstring[0] = '\0'; 12847c478bd9Sstevel@tonic-gate 12857c478bd9Sstevel@tonic-gate for (i = 0, j = 0; i < sizeof (em_map) / sizeof (struct em_map_ent); 12867c478bd9Sstevel@tonic-gate i++) { 12877c478bd9Sstevel@tonic-gate if ((int)emodifier & em_map[i].mask) { 12887c478bd9Sstevel@tonic-gate if (j++) 12897c478bd9Sstevel@tonic-gate (void) strlcat(modstring, ":", modlen); 12907c478bd9Sstevel@tonic-gate (void) strlcat(modstring, em_map[i].string, modlen); 12917c478bd9Sstevel@tonic-gate } 12927c478bd9Sstevel@tonic-gate } 12937c478bd9Sstevel@tonic-gate } 12947c478bd9Sstevel@tonic-gate 12957c478bd9Sstevel@tonic-gate 12967c478bd9Sstevel@tonic-gate /* 12977c478bd9Sstevel@tonic-gate * --------------------------------------------------------- 12987c478bd9Sstevel@tonic-gate * convert_char_to_string: 12997c478bd9Sstevel@tonic-gate * Converts a byte to string depending on the print mode 13007c478bd9Sstevel@tonic-gate * input : printmode, which may be one of AUP_BINARY, 13017c478bd9Sstevel@tonic-gate * AUP_OCTAL, AUP_DECIMAL, and AUP_HEX 13027c478bd9Sstevel@tonic-gate * c, which is the byte to convert 13037c478bd9Sstevel@tonic-gate * output : p, which is a pointer to the location where 13047c478bd9Sstevel@tonic-gate * the resulting string is to be stored 13057c478bd9Sstevel@tonic-gate * ---------------------------------------------------------- 13067c478bd9Sstevel@tonic-gate */ 13077c478bd9Sstevel@tonic-gate 13087c478bd9Sstevel@tonic-gate int 13097c478bd9Sstevel@tonic-gate convert_char_to_string(char printmode, char c, char *p) 13107c478bd9Sstevel@tonic-gate { 13117c478bd9Sstevel@tonic-gate union { 13127c478bd9Sstevel@tonic-gate char c1[4]; 13137c478bd9Sstevel@tonic-gate int c2; 13147c478bd9Sstevel@tonic-gate } dat; 13157c478bd9Sstevel@tonic-gate 13167c478bd9Sstevel@tonic-gate dat.c2 = 0; 13177c478bd9Sstevel@tonic-gate dat.c1[3] = c; 13187c478bd9Sstevel@tonic-gate 13197c478bd9Sstevel@tonic-gate if (printmode == AUP_BINARY) 13207c478bd9Sstevel@tonic-gate (void) convertbinary(p, &c, sizeof (char)); 13217c478bd9Sstevel@tonic-gate else if (printmode == AUP_OCTAL) 13227c478bd9Sstevel@tonic-gate (void) sprintf(p, "%o", (int)dat.c2); 13237c478bd9Sstevel@tonic-gate else if (printmode == AUP_DECIMAL) 13247c478bd9Sstevel@tonic-gate (void) sprintf(p, "%d", c); 13257c478bd9Sstevel@tonic-gate else if (printmode == AUP_HEX) 13267c478bd9Sstevel@tonic-gate (void) sprintf(p, "0x%x", (int)dat.c2); 13277c478bd9Sstevel@tonic-gate else if (printmode == AUP_STRING) 13287c478bd9Sstevel@tonic-gate convertascii(p, &c, sizeof (char)); 13297c478bd9Sstevel@tonic-gate return (0); 13307c478bd9Sstevel@tonic-gate } 13317c478bd9Sstevel@tonic-gate 13327c478bd9Sstevel@tonic-gate /* 13337c478bd9Sstevel@tonic-gate * -------------------------------------------------------------- 13347c478bd9Sstevel@tonic-gate * convert_short_to_string: 13357c478bd9Sstevel@tonic-gate * Converts a short integer to string depending on the print mode 13367c478bd9Sstevel@tonic-gate * input : printmode, which may be one of AUP_BINARY, 13377c478bd9Sstevel@tonic-gate * AUP_OCTAL, AUP_DECIMAL, and AUP_HEX 13387c478bd9Sstevel@tonic-gate * c, which is the short integer to convert 13397c478bd9Sstevel@tonic-gate * output : p, which is a pointer to the location where 13407c478bd9Sstevel@tonic-gate * the resulting string is to be stored 13417c478bd9Sstevel@tonic-gate * --------------------------------------------------------------- 13427c478bd9Sstevel@tonic-gate */ 13437c478bd9Sstevel@tonic-gate int 13447c478bd9Sstevel@tonic-gate convert_short_to_string(char printmode, short c, char *p) 13457c478bd9Sstevel@tonic-gate { 13467c478bd9Sstevel@tonic-gate union { 13477c478bd9Sstevel@tonic-gate short c1[2]; 13487c478bd9Sstevel@tonic-gate int c2; 13497c478bd9Sstevel@tonic-gate } dat; 13507c478bd9Sstevel@tonic-gate 13517c478bd9Sstevel@tonic-gate dat.c2 = 0; 13527c478bd9Sstevel@tonic-gate dat.c1[1] = c; 13537c478bd9Sstevel@tonic-gate 13547c478bd9Sstevel@tonic-gate if (printmode == AUP_BINARY) 13557c478bd9Sstevel@tonic-gate (void) convertbinary(p, (char *)&c, sizeof (short)); 13567c478bd9Sstevel@tonic-gate else if (printmode == AUP_OCTAL) 13577c478bd9Sstevel@tonic-gate (void) sprintf(p, "%o", (int)dat.c2); 13587c478bd9Sstevel@tonic-gate else if (printmode == AUP_DECIMAL) 13597c478bd9Sstevel@tonic-gate (void) sprintf(p, "%hd", c); 13607c478bd9Sstevel@tonic-gate else if (printmode == AUP_HEX) 13617c478bd9Sstevel@tonic-gate (void) sprintf(p, "0x%x", (int)dat.c2); 13627c478bd9Sstevel@tonic-gate else if (printmode == AUP_STRING) 13637c478bd9Sstevel@tonic-gate convertascii(p, (char *)&c, sizeof (short)); 13647c478bd9Sstevel@tonic-gate return (0); 13657c478bd9Sstevel@tonic-gate } 13667c478bd9Sstevel@tonic-gate 13677c478bd9Sstevel@tonic-gate /* 13687c478bd9Sstevel@tonic-gate * --------------------------------------------------------- 13697c478bd9Sstevel@tonic-gate * convert_int32_to_string: 13707c478bd9Sstevel@tonic-gate * Converts a integer to string depending on the print mode 13717c478bd9Sstevel@tonic-gate * input : printmode, which may be one of AUP_BINARY, 13727c478bd9Sstevel@tonic-gate * AUP_OCTAL, AUP_DECIMAL, and AUP_HEX 13737c478bd9Sstevel@tonic-gate * c, which is the integer to convert 13747c478bd9Sstevel@tonic-gate * output : p, which is a pointer to the location where 13757c478bd9Sstevel@tonic-gate * the resulting string is to be stored 13767c478bd9Sstevel@tonic-gate * ---------------------------------------------------------- 13777c478bd9Sstevel@tonic-gate */ 13787c478bd9Sstevel@tonic-gate int 13797c478bd9Sstevel@tonic-gate convert_int32_to_string(char printmode, int32_t c, char *p) 13807c478bd9Sstevel@tonic-gate { 13817c478bd9Sstevel@tonic-gate if (printmode == AUP_BINARY) 13827c478bd9Sstevel@tonic-gate (void) convertbinary(p, (char *)&c, sizeof (int32_t)); 13837c478bd9Sstevel@tonic-gate else if (printmode == AUP_OCTAL) 13847c478bd9Sstevel@tonic-gate (void) sprintf(p, "%o", c); 13857c478bd9Sstevel@tonic-gate else if (printmode == AUP_DECIMAL) 13867c478bd9Sstevel@tonic-gate (void) sprintf(p, "%d", c); 13877c478bd9Sstevel@tonic-gate else if (printmode == AUP_HEX) 13887c478bd9Sstevel@tonic-gate (void) sprintf(p, "0x%x", c); 13897c478bd9Sstevel@tonic-gate else if (printmode == AUP_STRING) 13907c478bd9Sstevel@tonic-gate convertascii(p, (char *)&c, sizeof (int)); 13917c478bd9Sstevel@tonic-gate return (0); 13927c478bd9Sstevel@tonic-gate } 13937c478bd9Sstevel@tonic-gate 13947c478bd9Sstevel@tonic-gate /* 13957c478bd9Sstevel@tonic-gate * --------------------------------------------------------- 13967c478bd9Sstevel@tonic-gate * convert_int64_to_string: 13977c478bd9Sstevel@tonic-gate * Converts a integer to string depending on the print mode 13987c478bd9Sstevel@tonic-gate * input : printmode, which may be one of AUP_BINARY, 13997c478bd9Sstevel@tonic-gate * AUP_OCTAL, AUP_DECIMAL, and AUP_HEX 14007c478bd9Sstevel@tonic-gate * c, which is the integer to convert 14017c478bd9Sstevel@tonic-gate * output : p, which is a pointer to the location where 14027c478bd9Sstevel@tonic-gate * the resulting string is to be stored 14037c478bd9Sstevel@tonic-gate * ---------------------------------------------------------- 14047c478bd9Sstevel@tonic-gate */ 14057c478bd9Sstevel@tonic-gate int 14067c478bd9Sstevel@tonic-gate convert_int64_to_string(char printmode, int64_t c, char *p) 14077c478bd9Sstevel@tonic-gate { 14087c478bd9Sstevel@tonic-gate if (printmode == AUP_BINARY) 14097c478bd9Sstevel@tonic-gate (void) convertbinary(p, (char *)&c, sizeof (int64_t)); 14107c478bd9Sstevel@tonic-gate else if (printmode == AUP_OCTAL) 14117c478bd9Sstevel@tonic-gate (void) sprintf(p, "%"PRIo64, c); 14127c478bd9Sstevel@tonic-gate else if (printmode == AUP_DECIMAL) 14137c478bd9Sstevel@tonic-gate (void) sprintf(p, "%"PRId64, c); 14147c478bd9Sstevel@tonic-gate else if (printmode == AUP_HEX) 14157c478bd9Sstevel@tonic-gate (void) sprintf(p, "0x%"PRIx64, c); 14167c478bd9Sstevel@tonic-gate else if (printmode == AUP_STRING) 14177c478bd9Sstevel@tonic-gate convertascii(p, (char *)&c, sizeof (int64_t)); 14187c478bd9Sstevel@tonic-gate return (0); 14197c478bd9Sstevel@tonic-gate } 14207c478bd9Sstevel@tonic-gate 14217c478bd9Sstevel@tonic-gate 14227c478bd9Sstevel@tonic-gate /* 14237c478bd9Sstevel@tonic-gate * ----------------------------------------------------------- 14247c478bd9Sstevel@tonic-gate * convertbinary: 14257c478bd9Sstevel@tonic-gate * Converts a unit c of 'size' bytes long into a binary string 14267c478bd9Sstevel@tonic-gate * and returns it into the position pointed to by p 14277c478bd9Sstevel@tonic-gate * ------------------------------------------------------------ 14287c478bd9Sstevel@tonic-gate */ 14297c478bd9Sstevel@tonic-gate int 14307c478bd9Sstevel@tonic-gate convertbinary(char *p, char *c, int size) 14317c478bd9Sstevel@tonic-gate { 14327c478bd9Sstevel@tonic-gate char *s, *t, *ss; 14337c478bd9Sstevel@tonic-gate int i, j; 14347c478bd9Sstevel@tonic-gate 14357c478bd9Sstevel@tonic-gate if ((s = (char *)malloc(8 * size + 1)) == NULL) 14367c478bd9Sstevel@tonic-gate return (0); 14377c478bd9Sstevel@tonic-gate 14387c478bd9Sstevel@tonic-gate ss = s; 14397c478bd9Sstevel@tonic-gate 14407c478bd9Sstevel@tonic-gate /* first convert to binary */ 14417c478bd9Sstevel@tonic-gate t = s; 14427c478bd9Sstevel@tonic-gate for (i = 0; i < size; i++) { 14437c478bd9Sstevel@tonic-gate for (j = 0; j < 8; j++) 14447c478bd9Sstevel@tonic-gate (void) sprintf(t++, "%d", ((*c >> (7 - j)) & (0x01))); 14457c478bd9Sstevel@tonic-gate c++; 14467c478bd9Sstevel@tonic-gate } 14477c478bd9Sstevel@tonic-gate *t = '\0'; 14487c478bd9Sstevel@tonic-gate 14497c478bd9Sstevel@tonic-gate /* now string leading zero's if any */ 14507c478bd9Sstevel@tonic-gate j = strlen(s) - 1; 14517c478bd9Sstevel@tonic-gate for (i = 0; i < j; i++) { 14527c478bd9Sstevel@tonic-gate if (*s != '0') 14537c478bd9Sstevel@tonic-gate break; 14547c478bd9Sstevel@tonic-gate else 14557c478bd9Sstevel@tonic-gate s++; 14567c478bd9Sstevel@tonic-gate } 14577c478bd9Sstevel@tonic-gate 14587c478bd9Sstevel@tonic-gate /* now copy the contents of s to p */ 14597c478bd9Sstevel@tonic-gate t = p; 14607c478bd9Sstevel@tonic-gate for (i = 0; i < (8 * size + 1); i++) { 14617c478bd9Sstevel@tonic-gate if (*s == '\0') { 14627c478bd9Sstevel@tonic-gate *t = '\0'; 14637c478bd9Sstevel@tonic-gate break; 14647c478bd9Sstevel@tonic-gate } 14657c478bd9Sstevel@tonic-gate *t++ = *s++; 14667c478bd9Sstevel@tonic-gate } 14677c478bd9Sstevel@tonic-gate free(ss); 14687c478bd9Sstevel@tonic-gate 14697c478bd9Sstevel@tonic-gate return (1); 14707c478bd9Sstevel@tonic-gate } 14717c478bd9Sstevel@tonic-gate 14727c478bd9Sstevel@tonic-gate 14737c478bd9Sstevel@tonic-gate static char hex[] = "0123456789abcdef"; 14747c478bd9Sstevel@tonic-gate /* 14757c478bd9Sstevel@tonic-gate * ------------------------------------------------------------------- 14767c478bd9Sstevel@tonic-gate * hexconvert : Converts a string of (size) bytes to hexadecimal, and 14777c478bd9Sstevel@tonic-gate * returns the hexadecimal string. 14787c478bd9Sstevel@tonic-gate * returns : - NULL if memory cannot be allocated for the string, or 14797c478bd9Sstevel@tonic-gate * - pointer to the hexadecimal string if successful 14807c478bd9Sstevel@tonic-gate * ------------------------------------------------------------------- 14817c478bd9Sstevel@tonic-gate */ 14827c478bd9Sstevel@tonic-gate char * 14837c478bd9Sstevel@tonic-gate hexconvert(char *c, int size, int chunk) 14847c478bd9Sstevel@tonic-gate { 14857c478bd9Sstevel@tonic-gate register char *s, *t; 14867c478bd9Sstevel@tonic-gate register int i, j, k; 14877c478bd9Sstevel@tonic-gate int numchunks; 14887c478bd9Sstevel@tonic-gate int leftovers; 14897c478bd9Sstevel@tonic-gate 14907c478bd9Sstevel@tonic-gate if (size <= 0) 14917c478bd9Sstevel@tonic-gate return (NULL); 14927c478bd9Sstevel@tonic-gate 14937c478bd9Sstevel@tonic-gate if ((s = (char *)malloc((size * 5) + 1)) == NULL) 14947c478bd9Sstevel@tonic-gate return (NULL); 14957c478bd9Sstevel@tonic-gate 14967c478bd9Sstevel@tonic-gate if (chunk > size || chunk <= 0) 14977c478bd9Sstevel@tonic-gate chunk = size; 14987c478bd9Sstevel@tonic-gate 14997c478bd9Sstevel@tonic-gate numchunks = size / chunk; 15007c478bd9Sstevel@tonic-gate leftovers = size % chunk; 15017c478bd9Sstevel@tonic-gate 15027c478bd9Sstevel@tonic-gate t = s; 15037c478bd9Sstevel@tonic-gate for (i = j = 0; i < numchunks; i++) { 15047c478bd9Sstevel@tonic-gate if (j++) { 15057c478bd9Sstevel@tonic-gate *t++ = ' '; 15067c478bd9Sstevel@tonic-gate } 15077c478bd9Sstevel@tonic-gate *t++ = '0'; 15087c478bd9Sstevel@tonic-gate *t++ = 'x'; 15097c478bd9Sstevel@tonic-gate for (k = 0; k < chunk; k++) { 15107c478bd9Sstevel@tonic-gate *t++ = hex[(uint_t)((uchar_t)*c >> 4)]; 15117c478bd9Sstevel@tonic-gate *t++ = hex[(uint_t)((uchar_t)*c & 0xF)]; 15127c478bd9Sstevel@tonic-gate c++; 15137c478bd9Sstevel@tonic-gate } 15147c478bd9Sstevel@tonic-gate } 15157c478bd9Sstevel@tonic-gate 15167c478bd9Sstevel@tonic-gate if (leftovers) { 15177c478bd9Sstevel@tonic-gate *t++ = ' '; 15187c478bd9Sstevel@tonic-gate *t++ = '0'; 15197c478bd9Sstevel@tonic-gate *t++ = 'x'; 15207c478bd9Sstevel@tonic-gate for (i = 0; i < leftovers; i++) { 15217c478bd9Sstevel@tonic-gate *t++ = hex[(uint_t)((uchar_t)*c >> 4)]; 15227c478bd9Sstevel@tonic-gate *t++ = hex[(uint_t)((uchar_t)*c & 0xF)]; 15237c478bd9Sstevel@tonic-gate c++; 15247c478bd9Sstevel@tonic-gate } 15257c478bd9Sstevel@tonic-gate } 15267c478bd9Sstevel@tonic-gate 15277c478bd9Sstevel@tonic-gate *t = '\0'; 15287c478bd9Sstevel@tonic-gate return (s); 15297c478bd9Sstevel@tonic-gate } 15307c478bd9Sstevel@tonic-gate 15317c478bd9Sstevel@tonic-gate 15327c478bd9Sstevel@tonic-gate /* 15337c478bd9Sstevel@tonic-gate * ------------------------------------------------------------------- 15347c478bd9Sstevel@tonic-gate * htp2string: Maps a print suggestion to a string. 15357c478bd9Sstevel@tonic-gate * returns : The string mapping or "unknown print suggestion". 15367c478bd9Sstevel@tonic-gate * ------------------------------------------------------------------- 15377c478bd9Sstevel@tonic-gate */ 15387c478bd9Sstevel@tonic-gate char * 15397c478bd9Sstevel@tonic-gate htp2string(char print_sugg) 15407c478bd9Sstevel@tonic-gate { 15417c478bd9Sstevel@tonic-gate register int i; 15427c478bd9Sstevel@tonic-gate 15437c478bd9Sstevel@tonic-gate struct htp_map_ent { 15447c478bd9Sstevel@tonic-gate char print_sugg; 15457c478bd9Sstevel@tonic-gate char *print_string; 15467c478bd9Sstevel@tonic-gate }; 15477c478bd9Sstevel@tonic-gate 15487c478bd9Sstevel@tonic-gate /* 15497c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE 15507c478bd9Sstevel@tonic-gate * These names are data types when displaying the arbitrary data 15517c478bd9Sstevel@tonic-gate * token. 15527c478bd9Sstevel@tonic-gate */ 15537c478bd9Sstevel@tonic-gate 15547c478bd9Sstevel@tonic-gate static struct htp_map_ent htp_map[] = { 15557c478bd9Sstevel@tonic-gate { AUP_BINARY, "binary" }, 15567c478bd9Sstevel@tonic-gate { AUP_OCTAL, "octal" }, 15577c478bd9Sstevel@tonic-gate { AUP_DECIMAL, "decimal" }, 15587c478bd9Sstevel@tonic-gate { AUP_HEX, "hexadecimal" }, 15597c478bd9Sstevel@tonic-gate { AUP_STRING, "string" } }; 15607c478bd9Sstevel@tonic-gate 15617c478bd9Sstevel@tonic-gate for (i = 0; i < sizeof (htp_map) / sizeof (struct htp_map_ent); i++) 15627c478bd9Sstevel@tonic-gate if (print_sugg == htp_map[i].print_sugg) 15637c478bd9Sstevel@tonic-gate return (gettext(htp_map[i].print_string)); 15647c478bd9Sstevel@tonic-gate 15657c478bd9Sstevel@tonic-gate return (gettext("unknown print suggestion")); 15667c478bd9Sstevel@tonic-gate } 15677c478bd9Sstevel@tonic-gate 15687c478bd9Sstevel@tonic-gate /* 15697c478bd9Sstevel@tonic-gate * ---------------------------------------------------------------------- 15707c478bd9Sstevel@tonic-gate * pa_adr_short: Issues pr_adr_short to retrieve the next ADR item from the 15717c478bd9Sstevel@tonic-gate * input stream pointed to by audit_adr, and prints it 15727c478bd9Sstevel@tonic-gate * if status >= 0 15737c478bd9Sstevel@tonic-gate * return codes: -1 - error 15747c478bd9Sstevel@tonic-gate * : 0 - successful 15757c478bd9Sstevel@tonic-gate * ---------------------------------------------------------------------- 15767c478bd9Sstevel@tonic-gate */ 15777c478bd9Sstevel@tonic-gate int 15787c478bd9Sstevel@tonic-gate pa_adr_short(pr_context_t *context, int status, int flag) 15797c478bd9Sstevel@tonic-gate { 15807c478bd9Sstevel@tonic-gate short c; 15817c478bd9Sstevel@tonic-gate uval_t uval; 15827c478bd9Sstevel@tonic-gate 15837c478bd9Sstevel@tonic-gate if (status >= 0) { 15847c478bd9Sstevel@tonic-gate if (pr_adr_short(context, &c, 1) == 0) { 15857c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_SHORT; 15867c478bd9Sstevel@tonic-gate uval.short_val = c; 15877c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 15887c478bd9Sstevel@tonic-gate } else 15897c478bd9Sstevel@tonic-gate return (-1); 15907c478bd9Sstevel@tonic-gate } else 15917c478bd9Sstevel@tonic-gate return (status); 15927c478bd9Sstevel@tonic-gate } 15937c478bd9Sstevel@tonic-gate 15947c478bd9Sstevel@tonic-gate /* 15957c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 15967c478bd9Sstevel@tonic-gate * pa_adr_shorthex: Issues pr_adr_short to retrieve the next ADR item from the 15977c478bd9Sstevel@tonic-gate * input stream pointed to by audit_adr, and prints it 15987c478bd9Sstevel@tonic-gate * in hexadecimal if status >= 0 15997c478bd9Sstevel@tonic-gate * return codes : -1 - error 16007c478bd9Sstevel@tonic-gate * : 0 - successful 16017c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 16027c478bd9Sstevel@tonic-gate */ 16037c478bd9Sstevel@tonic-gate int 16047c478bd9Sstevel@tonic-gate pa_adr_shorthex(pr_context_t *context, int status, int flag) 16057c478bd9Sstevel@tonic-gate { 16067c478bd9Sstevel@tonic-gate short s; 16077c478bd9Sstevel@tonic-gate int returnstat; 16087c478bd9Sstevel@tonic-gate uval_t uval; 16097c478bd9Sstevel@tonic-gate 16107c478bd9Sstevel@tonic-gate if (status >= 0) { 16117c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_short(context, &s, 1)) == 0) { 16127c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 16137c478bd9Sstevel@tonic-gate uval.string_val = hexconvert((char *)&s, sizeof (s), 16147c478bd9Sstevel@tonic-gate sizeof (s)); 16157c478bd9Sstevel@tonic-gate if (uval.string_val) { 16167c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 16177c478bd9Sstevel@tonic-gate free(uval.string_val); 16187c478bd9Sstevel@tonic-gate } 16197c478bd9Sstevel@tonic-gate } 16207c478bd9Sstevel@tonic-gate return (returnstat); 16217c478bd9Sstevel@tonic-gate } else 16227c478bd9Sstevel@tonic-gate return (status); 16237c478bd9Sstevel@tonic-gate } 16247c478bd9Sstevel@tonic-gate 16257c478bd9Sstevel@tonic-gate 16267c478bd9Sstevel@tonic-gate /* 16277c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 16287c478bd9Sstevel@tonic-gate * pa_adr_string: Retrieves a string from the input stream and prints it 16297c478bd9Sstevel@tonic-gate * if status >= 0 16307c478bd9Sstevel@tonic-gate * return codes : -1 - error 16317c478bd9Sstevel@tonic-gate * : 0 - successful 16327c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 16337c478bd9Sstevel@tonic-gate */ 16347c478bd9Sstevel@tonic-gate int 16357c478bd9Sstevel@tonic-gate pa_adr_string(pr_context_t *context, int status, int flag) 16367c478bd9Sstevel@tonic-gate { 16377c478bd9Sstevel@tonic-gate char *c; 16387c478bd9Sstevel@tonic-gate short length; 16397c478bd9Sstevel@tonic-gate int returnstat; 16407c478bd9Sstevel@tonic-gate uval_t uval; 16417c478bd9Sstevel@tonic-gate 16427c478bd9Sstevel@tonic-gate /* 16437c478bd9Sstevel@tonic-gate * We need to know how much space to allocate for our string, so 16447c478bd9Sstevel@tonic-gate * read the length first, then call pr_adr_char to read those bytes. 16457c478bd9Sstevel@tonic-gate */ 16467c478bd9Sstevel@tonic-gate if (status < 0) 16477c478bd9Sstevel@tonic-gate return (status); 16487c478bd9Sstevel@tonic-gate 16497c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_short(context, &length, 1)) != 0) 16507c478bd9Sstevel@tonic-gate return (returnstat); 16517c478bd9Sstevel@tonic-gate if ((c = (char *)malloc(length + 1)) == NULL) 16527c478bd9Sstevel@tonic-gate return (-1); 16537c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, c, length)) != 0) { 16547c478bd9Sstevel@tonic-gate free(c); 16557c478bd9Sstevel@tonic-gate return (returnstat); 16567c478bd9Sstevel@tonic-gate } 165785298dc1Snakanon 16587c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 165985298dc1Snakanon uval.string_val = c; 16607c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 16617c478bd9Sstevel@tonic-gate free(c); 16627c478bd9Sstevel@tonic-gate return (returnstat); 16637c478bd9Sstevel@tonic-gate } 16647c478bd9Sstevel@tonic-gate 16657c478bd9Sstevel@tonic-gate /* 16667c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 16677c478bd9Sstevel@tonic-gate * pa_file_string: Retrieves a file string from the input stream and prints it 16687c478bd9Sstevel@tonic-gate * if status >= 0 16697c478bd9Sstevel@tonic-gate * return codes : -1 - error 16707c478bd9Sstevel@tonic-gate * : 0 - successful 16717c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 16727c478bd9Sstevel@tonic-gate */ 16737c478bd9Sstevel@tonic-gate int 16747c478bd9Sstevel@tonic-gate pa_file_string(pr_context_t *context, int status, int flag) 16757c478bd9Sstevel@tonic-gate { 16767c478bd9Sstevel@tonic-gate char *c; 16777c478bd9Sstevel@tonic-gate char *p; 16787c478bd9Sstevel@tonic-gate short length; 16797c478bd9Sstevel@tonic-gate int returnstat; 16807c478bd9Sstevel@tonic-gate uval_t uval; 16817c478bd9Sstevel@tonic-gate 16827c478bd9Sstevel@tonic-gate /* 16837c478bd9Sstevel@tonic-gate * We need to know how much space to allocate for our string, so 16847c478bd9Sstevel@tonic-gate * read the length first, then call pr_adr_char to read those bytes. 16857c478bd9Sstevel@tonic-gate */ 16867c478bd9Sstevel@tonic-gate if (status < 0) 16877c478bd9Sstevel@tonic-gate return (status); 16887c478bd9Sstevel@tonic-gate 16897c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_short(context, &length, 1)) != 0) 16907c478bd9Sstevel@tonic-gate return (returnstat); 16917c478bd9Sstevel@tonic-gate if ((c = (char *)malloc(length + 1)) == NULL) 16927c478bd9Sstevel@tonic-gate return (-1); 169385298dc1Snakanon if ((p = (char *)malloc((length * 4) + 1)) == NULL) { 16947c478bd9Sstevel@tonic-gate free(c); 16957c478bd9Sstevel@tonic-gate return (-1); 16967c478bd9Sstevel@tonic-gate } 16977c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, c, length)) != 0) { 16987c478bd9Sstevel@tonic-gate free(c); 16997c478bd9Sstevel@tonic-gate free(p); 17007c478bd9Sstevel@tonic-gate return (returnstat); 17017c478bd9Sstevel@tonic-gate } 17027c478bd9Sstevel@tonic-gate 17037c478bd9Sstevel@tonic-gate if (is_file_token(context->tokenid)) 17047c478bd9Sstevel@tonic-gate context->audit_rec_len += length; 17057c478bd9Sstevel@tonic-gate 17067c478bd9Sstevel@tonic-gate convertascii(p, c, length - 1); 17077c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 17087c478bd9Sstevel@tonic-gate uval.string_val = p; 17097c478bd9Sstevel@tonic-gate 17107c478bd9Sstevel@tonic-gate if (returnstat == 0) 17117c478bd9Sstevel@tonic-gate returnstat = finish_open_tag(context); 17127c478bd9Sstevel@tonic-gate 17137c478bd9Sstevel@tonic-gate if (returnstat == 0) 17147c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 17157c478bd9Sstevel@tonic-gate 17167c478bd9Sstevel@tonic-gate free(c); 17177c478bd9Sstevel@tonic-gate free(p); 17187c478bd9Sstevel@tonic-gate return (returnstat); 17197c478bd9Sstevel@tonic-gate } 17207c478bd9Sstevel@tonic-gate 17217c478bd9Sstevel@tonic-gate static int 17227c478bd9Sstevel@tonic-gate pa_putstr_xml(pr_context_t *context, int printable, char *str, size_t len) 17237c478bd9Sstevel@tonic-gate { 17247c478bd9Sstevel@tonic-gate int err; 17257c478bd9Sstevel@tonic-gate 17267c478bd9Sstevel@tonic-gate if (!printable) { 17277c478bd9Sstevel@tonic-gate /* 17287c478bd9Sstevel@tonic-gate * Unprintable chars should always be converted to the 17297c478bd9Sstevel@tonic-gate * visible form. If there are unprintable characters which 17307c478bd9Sstevel@tonic-gate * require special treatment in xml, those should be 17317c478bd9Sstevel@tonic-gate * handled here. 17327c478bd9Sstevel@tonic-gate */ 17337c478bd9Sstevel@tonic-gate do { 17347c478bd9Sstevel@tonic-gate err = pr_printf(context, "\\%03o", 17357c478bd9Sstevel@tonic-gate (unsigned char)*str++); 17367c478bd9Sstevel@tonic-gate } while (err == 0 && --len != 0); 17377c478bd9Sstevel@tonic-gate return (err); 17387c478bd9Sstevel@tonic-gate } 17397c478bd9Sstevel@tonic-gate /* printable characters */ 17407c478bd9Sstevel@tonic-gate if (len == 1) { 17417c478bd9Sstevel@tonic-gate /* 17427c478bd9Sstevel@tonic-gate * check for the special chars only when char size was 1 17437c478bd9Sstevel@tonic-gate * ie, ignore special chars appear in the middle of multibyte 17447c478bd9Sstevel@tonic-gate * sequence. 17457c478bd9Sstevel@tonic-gate */ 17467c478bd9Sstevel@tonic-gate 17477c478bd9Sstevel@tonic-gate /* Escape for XML */ 17487c478bd9Sstevel@tonic-gate switch (*str) { 17497c478bd9Sstevel@tonic-gate case '&': 17507c478bd9Sstevel@tonic-gate err = pr_printf(context, "%s", "&"); 17517c478bd9Sstevel@tonic-gate break; 17527c478bd9Sstevel@tonic-gate 17537c478bd9Sstevel@tonic-gate case '<': 17547c478bd9Sstevel@tonic-gate err = pr_printf(context, "%s", "<"); 17557c478bd9Sstevel@tonic-gate break; 17567c478bd9Sstevel@tonic-gate 17577c478bd9Sstevel@tonic-gate case '>': 17587c478bd9Sstevel@tonic-gate err = pr_printf(context, "%s", ">"); 17597c478bd9Sstevel@tonic-gate break; 17607c478bd9Sstevel@tonic-gate 17617c478bd9Sstevel@tonic-gate case '\"': 17627c478bd9Sstevel@tonic-gate err = pr_printf(context, "%s", """); 17637c478bd9Sstevel@tonic-gate break; 17647c478bd9Sstevel@tonic-gate 17657c478bd9Sstevel@tonic-gate case '\'': 17667c478bd9Sstevel@tonic-gate err = pr_printf(context, "%s", "'"); 17677c478bd9Sstevel@tonic-gate break; 17687c478bd9Sstevel@tonic-gate 17697c478bd9Sstevel@tonic-gate default: 17707c478bd9Sstevel@tonic-gate err = pr_putchar(context, *str); 17717c478bd9Sstevel@tonic-gate break; 17727c478bd9Sstevel@tonic-gate } 17737c478bd9Sstevel@tonic-gate return (err); 17747c478bd9Sstevel@tonic-gate } 17757c478bd9Sstevel@tonic-gate do { 17767c478bd9Sstevel@tonic-gate err = pr_putchar(context, *str++); 17777c478bd9Sstevel@tonic-gate } while (err == 0 && --len != 0); 17787c478bd9Sstevel@tonic-gate return (err); 17797c478bd9Sstevel@tonic-gate } 17807c478bd9Sstevel@tonic-gate 17817c478bd9Sstevel@tonic-gate static int 17827c478bd9Sstevel@tonic-gate pa_putstr(pr_context_t *context, int printable, char *str, size_t len) 17837c478bd9Sstevel@tonic-gate { 17847c478bd9Sstevel@tonic-gate int err; 17857c478bd9Sstevel@tonic-gate 17867c478bd9Sstevel@tonic-gate if (context->format & PRF_XMLM) 17877c478bd9Sstevel@tonic-gate return (pa_putstr_xml(context, printable, str, len)); 17887c478bd9Sstevel@tonic-gate 17897c478bd9Sstevel@tonic-gate if (!printable) { 17907c478bd9Sstevel@tonic-gate do { 17917c478bd9Sstevel@tonic-gate err = pr_printf(context, "\\%03o", 17927c478bd9Sstevel@tonic-gate (unsigned char)*str++); 17937c478bd9Sstevel@tonic-gate } while (err == 0 && --len != 0); 17947c478bd9Sstevel@tonic-gate return (err); 17957c478bd9Sstevel@tonic-gate } 17967c478bd9Sstevel@tonic-gate do { 17977c478bd9Sstevel@tonic-gate err = pr_putchar(context, *str++); 17987c478bd9Sstevel@tonic-gate } while (err == 0 && --len != 0); 17997c478bd9Sstevel@tonic-gate return (err); 18007c478bd9Sstevel@tonic-gate } 18017c478bd9Sstevel@tonic-gate 18027c478bd9Sstevel@tonic-gate int 18037c478bd9Sstevel@tonic-gate pa_string(pr_context_t *context, int status, int flag) 18047c478bd9Sstevel@tonic-gate { 18057c478bd9Sstevel@tonic-gate int rstat, wstat; 18067c478bd9Sstevel@tonic-gate int i, printable, eos; 18077c478bd9Sstevel@tonic-gate int mlen, rlen; 18087c478bd9Sstevel@tonic-gate int mbmax = MB_CUR_MAX; 18097c478bd9Sstevel@tonic-gate wchar_t wc; 18107c478bd9Sstevel@tonic-gate char mbuf[MB_LEN_MAX + 1]; 18117c478bd9Sstevel@tonic-gate char c; 18127c478bd9Sstevel@tonic-gate 18137c478bd9Sstevel@tonic-gate if (status < 0) 18147c478bd9Sstevel@tonic-gate return (status); 18157c478bd9Sstevel@tonic-gate 18167c478bd9Sstevel@tonic-gate rstat = wstat = 0; 18177c478bd9Sstevel@tonic-gate 18187c478bd9Sstevel@tonic-gate if (mbmax == 1) { 18197c478bd9Sstevel@tonic-gate while (wstat == 0) { 18207c478bd9Sstevel@tonic-gate if ((rstat = pr_adr_char(context, &c, 1)) < 0) 18217c478bd9Sstevel@tonic-gate break; 18227c478bd9Sstevel@tonic-gate if (c == '\0') 18237c478bd9Sstevel@tonic-gate break; 18247c478bd9Sstevel@tonic-gate printable = isprint((unsigned char)c); 18257c478bd9Sstevel@tonic-gate wstat = pa_putstr(context, printable, &c, 1); 18267c478bd9Sstevel@tonic-gate } 18277c478bd9Sstevel@tonic-gate goto done; 18287c478bd9Sstevel@tonic-gate } 18297c478bd9Sstevel@tonic-gate 18307c478bd9Sstevel@tonic-gate mlen = eos = 0; 18317c478bd9Sstevel@tonic-gate while (wstat == 0) { 18327c478bd9Sstevel@tonic-gate rlen = 0; 18337c478bd9Sstevel@tonic-gate do { 18347c478bd9Sstevel@tonic-gate if (!eos) { 18357c478bd9Sstevel@tonic-gate rstat = pr_adr_char(context, &c, 1); 18367c478bd9Sstevel@tonic-gate if (rstat != 0 || c == '\0') 18377c478bd9Sstevel@tonic-gate eos = 1; 18387c478bd9Sstevel@tonic-gate else 18397c478bd9Sstevel@tonic-gate mbuf[mlen++] = c; 18407c478bd9Sstevel@tonic-gate } 18417c478bd9Sstevel@tonic-gate rlen = mbtowc(&wc, mbuf, mlen); 18427c478bd9Sstevel@tonic-gate } while (!eos && mlen < mbmax && rlen <= 0); 18437c478bd9Sstevel@tonic-gate 18447c478bd9Sstevel@tonic-gate if (mlen == 0) 18457c478bd9Sstevel@tonic-gate break; /* end of string */ 18467c478bd9Sstevel@tonic-gate 18477c478bd9Sstevel@tonic-gate if (rlen <= 0) { /* no good sequence */ 18487c478bd9Sstevel@tonic-gate rlen = 1; 18497c478bd9Sstevel@tonic-gate printable = 0; 18507c478bd9Sstevel@tonic-gate } else { 18517c478bd9Sstevel@tonic-gate printable = iswprint(wc); 18527c478bd9Sstevel@tonic-gate } 18537c478bd9Sstevel@tonic-gate wstat = pa_putstr(context, printable, mbuf, rlen); 18547c478bd9Sstevel@tonic-gate mlen -= rlen; 18557c478bd9Sstevel@tonic-gate if (mlen > 0) { 18567c478bd9Sstevel@tonic-gate for (i = 0; i < mlen; i++) 18577c478bd9Sstevel@tonic-gate mbuf[i] = mbuf[rlen + i]; 18587c478bd9Sstevel@tonic-gate } 18597c478bd9Sstevel@tonic-gate } 18607c478bd9Sstevel@tonic-gate 18617c478bd9Sstevel@tonic-gate done: 18627c478bd9Sstevel@tonic-gate if (wstat == 0) 18637c478bd9Sstevel@tonic-gate wstat = do_newline(context, flag); 18647c478bd9Sstevel@tonic-gate 18657c478bd9Sstevel@tonic-gate if (wstat == 0 && context->data_mode == FILEMODE) 18667c478bd9Sstevel@tonic-gate (void) fflush(stdout); 18677c478bd9Sstevel@tonic-gate 18687c478bd9Sstevel@tonic-gate return ((rstat != 0 || wstat != 0) ? -1 : 0); 18697c478bd9Sstevel@tonic-gate } 18707c478bd9Sstevel@tonic-gate 18717c478bd9Sstevel@tonic-gate /* 18727c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 18737c478bd9Sstevel@tonic-gate * pa_adr_u_int32: Issues pr_adr_u_int32 to retrieve the next ADR item from 18747c478bd9Sstevel@tonic-gate * the input stream pointed to by audit_adr, and prints it 18757c478bd9Sstevel@tonic-gate * if status = 0 18767c478bd9Sstevel@tonic-gate * return codes : -1 - error 18777c478bd9Sstevel@tonic-gate * : 0 - successful 18787c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 18797c478bd9Sstevel@tonic-gate */ 18807c478bd9Sstevel@tonic-gate 18817c478bd9Sstevel@tonic-gate 18827c478bd9Sstevel@tonic-gate int 18837c478bd9Sstevel@tonic-gate pa_adr_u_int32(pr_context_t *context, int status, int flag) 18847c478bd9Sstevel@tonic-gate { 18857c478bd9Sstevel@tonic-gate uint32_t c; 18867c478bd9Sstevel@tonic-gate uval_t uval; 18877c478bd9Sstevel@tonic-gate 18887c478bd9Sstevel@tonic-gate if (status >= 0) { 18897c478bd9Sstevel@tonic-gate if (pr_adr_u_int32(context, &c, 1) == 0) { 18907c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT32; 18917c478bd9Sstevel@tonic-gate uval.uint32_val = c; 18927c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 18937c478bd9Sstevel@tonic-gate } else 18947c478bd9Sstevel@tonic-gate return (-1); 18957c478bd9Sstevel@tonic-gate } else 18967c478bd9Sstevel@tonic-gate return (status); 18977c478bd9Sstevel@tonic-gate } 18987c478bd9Sstevel@tonic-gate 18997c478bd9Sstevel@tonic-gate 19007c478bd9Sstevel@tonic-gate 19017c478bd9Sstevel@tonic-gate /* 19027c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 19037c478bd9Sstevel@tonic-gate * pa_adr_u_int64: Issues pr_adr_u_int64 to retrieve the next ADR item from the 19047c478bd9Sstevel@tonic-gate * input stream pointed to by audit_adr, and prints it 19057c478bd9Sstevel@tonic-gate * if status = 0 19067c478bd9Sstevel@tonic-gate * return codes : -1 - error 19077c478bd9Sstevel@tonic-gate * : 0 - successful 19087c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 19097c478bd9Sstevel@tonic-gate */ 19107c478bd9Sstevel@tonic-gate int 19117c478bd9Sstevel@tonic-gate pa_adr_u_int64(pr_context_t *context, int status, int flag) 19127c478bd9Sstevel@tonic-gate { 19137c478bd9Sstevel@tonic-gate uint64_t c; 19147c478bd9Sstevel@tonic-gate uval_t uval; 19157c478bd9Sstevel@tonic-gate 19167c478bd9Sstevel@tonic-gate if (status >= 0) { 19177c478bd9Sstevel@tonic-gate if (pr_adr_u_int64(context, &c, 1) == 0) { 19187c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT64; 19197c478bd9Sstevel@tonic-gate uval.uint64_val = c; 19207c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 19217c478bd9Sstevel@tonic-gate } else 19227c478bd9Sstevel@tonic-gate return (-1); 19237c478bd9Sstevel@tonic-gate } else 19247c478bd9Sstevel@tonic-gate return (status); 19257c478bd9Sstevel@tonic-gate } 19267c478bd9Sstevel@tonic-gate 19277c478bd9Sstevel@tonic-gate 19287c478bd9Sstevel@tonic-gate /* 19297c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 19307c478bd9Sstevel@tonic-gate * pa_adr_u_short: Issues pr_adr_u_short to retrieve the next ADR item from 19317c478bd9Sstevel@tonic-gate * the input stream pointed to by audit_adr, and prints it 19327c478bd9Sstevel@tonic-gate * if status = 0 19337c478bd9Sstevel@tonic-gate * return codes : -1 - error 19347c478bd9Sstevel@tonic-gate * : 0 - successful 19357c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 19367c478bd9Sstevel@tonic-gate */ 19377c478bd9Sstevel@tonic-gate int 19387c478bd9Sstevel@tonic-gate pa_adr_u_short(pr_context_t *context, int status, int flag) 19397c478bd9Sstevel@tonic-gate { 19407c478bd9Sstevel@tonic-gate ushort_t c; 19417c478bd9Sstevel@tonic-gate uval_t uval; 19427c478bd9Sstevel@tonic-gate 19437c478bd9Sstevel@tonic-gate if (status >= 0) { 19447c478bd9Sstevel@tonic-gate if (pr_adr_u_short(context, &c, 1) == 0) { 19457c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_USHORT; 19467c478bd9Sstevel@tonic-gate uval.ushort_val = c; 19477c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 19487c478bd9Sstevel@tonic-gate } else 19497c478bd9Sstevel@tonic-gate return (-1); 19507c478bd9Sstevel@tonic-gate } else 19517c478bd9Sstevel@tonic-gate return (status); 19527c478bd9Sstevel@tonic-gate } 19537c478bd9Sstevel@tonic-gate 19547c478bd9Sstevel@tonic-gate /* 19557c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 19567c478bd9Sstevel@tonic-gate * pa_reclen: Issues pr_adr_u_long to retrieve the length of the record 19577c478bd9Sstevel@tonic-gate * from the input stream pointed to by audit_adr, 19587c478bd9Sstevel@tonic-gate * and prints it (unless format is XML) if status = 0 19597c478bd9Sstevel@tonic-gate * return codes : -1 - error 19607c478bd9Sstevel@tonic-gate * : 0 - successful 19617c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 19627c478bd9Sstevel@tonic-gate */ 19637c478bd9Sstevel@tonic-gate int 19647c478bd9Sstevel@tonic-gate pa_reclen(pr_context_t *context, int status) 19657c478bd9Sstevel@tonic-gate { 19667c478bd9Sstevel@tonic-gate uint32_t c; 19677c478bd9Sstevel@tonic-gate uval_t uval; 19687c478bd9Sstevel@tonic-gate 19697c478bd9Sstevel@tonic-gate if (status >= 0) { 19707c478bd9Sstevel@tonic-gate if ((int)pr_adr_u_int32(context, &c, 1) == 0) { 19717c478bd9Sstevel@tonic-gate context->audit_rec_len = c; 19727c478bd9Sstevel@tonic-gate 19737c478bd9Sstevel@tonic-gate /* Don't print this for XML format */ 19747c478bd9Sstevel@tonic-gate if (context->format & PRF_XMLM) { 19757c478bd9Sstevel@tonic-gate return (0); 19767c478bd9Sstevel@tonic-gate } else { 19777c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT32; 19787c478bd9Sstevel@tonic-gate uval.uint32_val = c; 19797c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, 0)); 19807c478bd9Sstevel@tonic-gate } 19817c478bd9Sstevel@tonic-gate } else 19827c478bd9Sstevel@tonic-gate return (-1); 19837c478bd9Sstevel@tonic-gate } else 19847c478bd9Sstevel@tonic-gate return (status); 19857c478bd9Sstevel@tonic-gate } 19867c478bd9Sstevel@tonic-gate 19877c478bd9Sstevel@tonic-gate /* 19887c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 19897c478bd9Sstevel@tonic-gate * pa_mode : Issues pr_adr_u_short to retrieve the next ADR item from 19907c478bd9Sstevel@tonic-gate * the input stream pointed to by audit_adr, and prints it 19917c478bd9Sstevel@tonic-gate * in octal if status = 0 19927c478bd9Sstevel@tonic-gate * return codes : -1 - error 19937c478bd9Sstevel@tonic-gate * : 0 - successful 19947c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 19957c478bd9Sstevel@tonic-gate */ 19967c478bd9Sstevel@tonic-gate int 19977c478bd9Sstevel@tonic-gate pa_mode(pr_context_t *context, int status, int flag) 19987c478bd9Sstevel@tonic-gate { 19997c478bd9Sstevel@tonic-gate uint32_t c; 20007c478bd9Sstevel@tonic-gate uval_t uval; 20017c478bd9Sstevel@tonic-gate 20027c478bd9Sstevel@tonic-gate if (status >= 0) { 20037c478bd9Sstevel@tonic-gate if (pr_adr_u_int32(context, &c, 1) == 0) { 20047c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_LOCT; 20057c478bd9Sstevel@tonic-gate uval.uint32_val = c; 20067c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag)); 20077c478bd9Sstevel@tonic-gate } else 20087c478bd9Sstevel@tonic-gate return (-1); 20097c478bd9Sstevel@tonic-gate } else 20107c478bd9Sstevel@tonic-gate return (status); 20117c478bd9Sstevel@tonic-gate } 20127c478bd9Sstevel@tonic-gate 2013a7746f66Stz204579 static int 2014a7746f66Stz204579 pa_print_uid(pr_context_t *context, uid_t uid, int status, int flag) 20157c478bd9Sstevel@tonic-gate { 20167c478bd9Sstevel@tonic-gate int returnstat; 20177c478bd9Sstevel@tonic-gate struct passwd *pw; 20187c478bd9Sstevel@tonic-gate uval_t uval; 20197c478bd9Sstevel@tonic-gate 20207c478bd9Sstevel@tonic-gate if (status < 0) 20217c478bd9Sstevel@tonic-gate return (status); 20227c478bd9Sstevel@tonic-gate 20237c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 20247c478bd9Sstevel@tonic-gate /* get password file entry */ 20257c478bd9Sstevel@tonic-gate if ((pw = getpwuid(uid)) == NULL) { 20267c478bd9Sstevel@tonic-gate returnstat = 1; 20277c478bd9Sstevel@tonic-gate } else { 20287c478bd9Sstevel@tonic-gate /* print in ASCII form */ 20297c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 20307c478bd9Sstevel@tonic-gate uval.string_val = pw->pw_name; 20317c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 20327c478bd9Sstevel@tonic-gate } 20337c478bd9Sstevel@tonic-gate } 20347c478bd9Sstevel@tonic-gate /* print in integer form */ 20357c478bd9Sstevel@tonic-gate if ((context->format & PRF_RAWM) || (returnstat == 1)) { 20367c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_INT32; 20377c478bd9Sstevel@tonic-gate uval.int32_val = uid; 20387c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 20397c478bd9Sstevel@tonic-gate } 20407c478bd9Sstevel@tonic-gate return (returnstat); 20417c478bd9Sstevel@tonic-gate } 20427c478bd9Sstevel@tonic-gate 20437c478bd9Sstevel@tonic-gate 20447c478bd9Sstevel@tonic-gate /* 20457c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 2046a7746f66Stz204579 * pa_pw_uid() : Issues pr_adr_u_int32 to reads uid from input stream 20477c478bd9Sstevel@tonic-gate * pointed to by audit_adr, and displays it in either 20487c478bd9Sstevel@tonic-gate * raw form or its ASCII representation, if status >= 0. 20497c478bd9Sstevel@tonic-gate * return codes : -1 - error 20507c478bd9Sstevel@tonic-gate * : 1 - warning, passwd entry not found 20517c478bd9Sstevel@tonic-gate * : 0 - successful 20527c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 20537c478bd9Sstevel@tonic-gate */ 20547c478bd9Sstevel@tonic-gate int 2055a7746f66Stz204579 pa_pw_uid(pr_context_t *context, int status, int flag) 20567c478bd9Sstevel@tonic-gate { 2057a7746f66Stz204579 uint32_t uid; 20587c478bd9Sstevel@tonic-gate 20597c478bd9Sstevel@tonic-gate if (status < 0) 20607c478bd9Sstevel@tonic-gate return (status); 20617c478bd9Sstevel@tonic-gate 2062a7746f66Stz204579 if (pr_adr_u_int32(context, &uid, 1) != 0) 2063a7746f66Stz204579 /* cannot retrieve uid */ 20647c478bd9Sstevel@tonic-gate return (-1); 20657c478bd9Sstevel@tonic-gate 2066a7746f66Stz204579 return (pa_print_uid(context, uid, status, flag)); 2067a7746f66Stz204579 } 2068a7746f66Stz204579 2069a7746f66Stz204579 static int 2070a7746f66Stz204579 pa_print_gid(pr_context_t *context, gid_t gid, int status, int flag) 2071a7746f66Stz204579 { 2072a7746f66Stz204579 int returnstat; 2073a7746f66Stz204579 struct group *gr; 2074a7746f66Stz204579 uval_t uval; 2075a7746f66Stz204579 2076a7746f66Stz204579 if (status < 0) 2077a7746f66Stz204579 return (status); 2078a7746f66Stz204579 20797c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 20807c478bd9Sstevel@tonic-gate /* get group file entry */ 20817c478bd9Sstevel@tonic-gate if ((gr = getgrgid(gid)) == NULL) { 20827c478bd9Sstevel@tonic-gate returnstat = 1; 20837c478bd9Sstevel@tonic-gate } else { 20847c478bd9Sstevel@tonic-gate /* print in ASCII form */ 20857c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 20867c478bd9Sstevel@tonic-gate uval.string_val = gr->gr_name; 20877c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 20887c478bd9Sstevel@tonic-gate } 20897c478bd9Sstevel@tonic-gate } 20907c478bd9Sstevel@tonic-gate /* print in integer form */ 20917c478bd9Sstevel@tonic-gate if ((context->format & PRF_RAWM) || (returnstat == 1)) { 20927c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_INT32; 20937c478bd9Sstevel@tonic-gate uval.int32_val = gid; 20947c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 20957c478bd9Sstevel@tonic-gate } 20967c478bd9Sstevel@tonic-gate return (returnstat); 20977c478bd9Sstevel@tonic-gate } 20987c478bd9Sstevel@tonic-gate 20997c478bd9Sstevel@tonic-gate 21007c478bd9Sstevel@tonic-gate /* 21017c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 2102a7746f66Stz204579 * pa_gr_uid() : Issues pr_adr_u_int32 to reads group uid from input stream 2103a7746f66Stz204579 * pointed to by audit_adr, and displays it in either 2104a7746f66Stz204579 * raw form or its ASCII representation, if status >= 0. 2105a7746f66Stz204579 * return codes : -1 - error 2106a7746f66Stz204579 * : 1 - warning, passwd entry not found 2107a7746f66Stz204579 * : 0 - successful 2108a7746f66Stz204579 * ----------------------------------------------------------------------- 2109a7746f66Stz204579 */ 2110a7746f66Stz204579 int 2111a7746f66Stz204579 pa_gr_uid(pr_context_t *context, int status, int flag) 2112a7746f66Stz204579 { 2113a7746f66Stz204579 uint32_t gid; 2114a7746f66Stz204579 2115a7746f66Stz204579 if (status < 0) 2116a7746f66Stz204579 return (status); 2117a7746f66Stz204579 2118a7746f66Stz204579 if (pr_adr_u_int32(context, &gid, 1) != 0) 2119a7746f66Stz204579 /* cannot retrieve gid */ 2120a7746f66Stz204579 return (-1); 2121a7746f66Stz204579 2122a7746f66Stz204579 return (pa_print_gid(context, gid, status, flag)); 2123a7746f66Stz204579 } 2124a7746f66Stz204579 2125a7746f66Stz204579 2126a7746f66Stz204579 /* 2127a7746f66Stz204579 * ----------------------------------------------------------------------- 21287c478bd9Sstevel@tonic-gate * pa_pw_uid_gr_gid() : Issues pr_adr_u_int32 to reads uid or group uid 21297c478bd9Sstevel@tonic-gate * from input stream 21307c478bd9Sstevel@tonic-gate * pointed to by audit_adr, and displays it in either 21317c478bd9Sstevel@tonic-gate * raw form or its ASCII representation, if status >= 0. 21327c478bd9Sstevel@tonic-gate * return codes : -1 - error 21337c478bd9Sstevel@tonic-gate * : 1 - warning, passwd entry not found 21347c478bd9Sstevel@tonic-gate * : 0 - successful 21357c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 21367c478bd9Sstevel@tonic-gate */ 21377c478bd9Sstevel@tonic-gate int 21387c478bd9Sstevel@tonic-gate pa_pw_uid_gr_gid(pr_context_t *context, int status, int flag) 21397c478bd9Sstevel@tonic-gate { 21407c478bd9Sstevel@tonic-gate int returnstat; 21417c478bd9Sstevel@tonic-gate uint32_t value; 21427c478bd9Sstevel@tonic-gate uval_t uval; 21437c478bd9Sstevel@tonic-gate 21447c478bd9Sstevel@tonic-gate if (status < 0) 21457c478bd9Sstevel@tonic-gate return (status); 21467c478bd9Sstevel@tonic-gate 21477c478bd9Sstevel@tonic-gate /* get value of a_type */ 21487c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_int32(context, &value, 1)) != 0) 21497c478bd9Sstevel@tonic-gate return (returnstat); 21507c478bd9Sstevel@tonic-gate 21517c478bd9Sstevel@tonic-gate if ((returnstat = open_tag(context, TAG_ACLTYPE)) != 0) 21527c478bd9Sstevel@tonic-gate return (returnstat); 21537c478bd9Sstevel@tonic-gate 21547c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT32; 21557c478bd9Sstevel@tonic-gate uval.uint32_val = value; 21567c478bd9Sstevel@tonic-gate if ((returnstat = pa_print(context, &uval, flag)) != 0) 21577c478bd9Sstevel@tonic-gate return (returnstat); 21587c478bd9Sstevel@tonic-gate 21597c478bd9Sstevel@tonic-gate if ((returnstat = close_tag(context, TAG_ACLTYPE)) != 0) 21607c478bd9Sstevel@tonic-gate return (returnstat); 21617c478bd9Sstevel@tonic-gate 21627c478bd9Sstevel@tonic-gate if ((returnstat = open_tag(context, TAG_ACLVAL)) != 0) 21637c478bd9Sstevel@tonic-gate return (returnstat); 21647c478bd9Sstevel@tonic-gate /* 21657c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE 21667c478bd9Sstevel@tonic-gate * The "mask" and "other" strings refer to the class mask 21677c478bd9Sstevel@tonic-gate * and other (or world) entries in an ACL. 21687c478bd9Sstevel@tonic-gate * The "unrecognized" string refers to an unrecognized ACL 21697c478bd9Sstevel@tonic-gate * entry. 21707c478bd9Sstevel@tonic-gate */ 21717c478bd9Sstevel@tonic-gate switch (value) { 21727c478bd9Sstevel@tonic-gate case USER_OBJ: 21737c478bd9Sstevel@tonic-gate case USER: 21747c478bd9Sstevel@tonic-gate returnstat = pa_pw_uid(context, returnstat, flag); 21757c478bd9Sstevel@tonic-gate break; 21767c478bd9Sstevel@tonic-gate case GROUP_OBJ: 21777c478bd9Sstevel@tonic-gate case GROUP: 21787c478bd9Sstevel@tonic-gate returnstat = pa_gr_uid(context, returnstat, flag); 21797c478bd9Sstevel@tonic-gate break; 21807c478bd9Sstevel@tonic-gate case CLASS_OBJ: 21817c478bd9Sstevel@tonic-gate returnstat = pr_adr_u_int32(context, &value, 1); 21827c478bd9Sstevel@tonic-gate if (returnstat != 0) 21837c478bd9Sstevel@tonic-gate return (returnstat); 21847c478bd9Sstevel@tonic-gate 21857c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 21867c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 21877c478bd9Sstevel@tonic-gate uval.string_val = gettext("mask"); 21887c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 21897c478bd9Sstevel@tonic-gate } else { 21907c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT32; 21917c478bd9Sstevel@tonic-gate uval.uint32_val = value; 21928f9294f3Sgww if ((returnstat = 21938f9294f3Sgww pa_print(context, &uval, flag)) != 0) { 21947c478bd9Sstevel@tonic-gate return (returnstat); 21957c478bd9Sstevel@tonic-gate } 21968f9294f3Sgww } 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; 22108f9294f3Sgww if ((returnstat = 22118f9294f3Sgww pa_print(context, &uval, flag)) != 0) { 22127c478bd9Sstevel@tonic-gate return (returnstat); 22137c478bd9Sstevel@tonic-gate } 22148f9294f3Sgww } 22157c478bd9Sstevel@tonic-gate break; 22167c478bd9Sstevel@tonic-gate default: 22177c478bd9Sstevel@tonic-gate returnstat = pr_adr_u_int32(context, &value, 1); 22187c478bd9Sstevel@tonic-gate if (returnstat != 0) 22197c478bd9Sstevel@tonic-gate return (returnstat); 22207c478bd9Sstevel@tonic-gate 22217c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 22227c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 22237c478bd9Sstevel@tonic-gate uval.string_val = gettext("unrecognized"); 22247c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 22257c478bd9Sstevel@tonic-gate } else { 22267c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT32; 22277c478bd9Sstevel@tonic-gate uval.uint32_val = value; 22288f9294f3Sgww if ((returnstat = 22298f9294f3Sgww pa_print(context, &uval, flag)) != 0) { 22307c478bd9Sstevel@tonic-gate return (returnstat); 22317c478bd9Sstevel@tonic-gate } 22327c478bd9Sstevel@tonic-gate } 22338f9294f3Sgww } 22347c478bd9Sstevel@tonic-gate 22357c478bd9Sstevel@tonic-gate if ((returnstat = close_tag(context, TAG_ACLVAL)) != 0) 22367c478bd9Sstevel@tonic-gate return (returnstat); 22377c478bd9Sstevel@tonic-gate 22387c478bd9Sstevel@tonic-gate return (returnstat); 22397c478bd9Sstevel@tonic-gate } 22407c478bd9Sstevel@tonic-gate 22417c478bd9Sstevel@tonic-gate 22427c478bd9Sstevel@tonic-gate /* 22437c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 22447c478bd9Sstevel@tonic-gate * pa_event_modifier(): Issues pr_adr_u_short to retrieve the next ADR item from 22457c478bd9Sstevel@tonic-gate * the input stream pointed to by audit_adr. This is the 22467c478bd9Sstevel@tonic-gate * event type, and is displayed in hex; 22477c478bd9Sstevel@tonic-gate * return codes : -1 - error 22487c478bd9Sstevel@tonic-gate * : 0 - successful 22497c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 22507c478bd9Sstevel@tonic-gate */ 22517c478bd9Sstevel@tonic-gate int 22527c478bd9Sstevel@tonic-gate pa_event_modifier(pr_context_t *context, int status, int flag) 22537c478bd9Sstevel@tonic-gate { 22547c478bd9Sstevel@tonic-gate int returnstat; 2255d0fa49b7STony Nguyen au_emod_t emodifier; 22567c478bd9Sstevel@tonic-gate uval_t uval; 22577c478bd9Sstevel@tonic-gate char modstring[64]; 22587c478bd9Sstevel@tonic-gate 22597c478bd9Sstevel@tonic-gate if (status < 0) 22607c478bd9Sstevel@tonic-gate return (status); 22617c478bd9Sstevel@tonic-gate 22627c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_short(context, &emodifier, 1)) != 0) 22637c478bd9Sstevel@tonic-gate return (returnstat); 22647c478bd9Sstevel@tonic-gate 22657c478bd9Sstevel@tonic-gate /* For XML, only print when modifier is non-zero */ 22667c478bd9Sstevel@tonic-gate if (!(context->format & PRF_XMLM) || (emodifier != 0)) { 22677c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 22687c478bd9Sstevel@tonic-gate 22697c478bd9Sstevel@tonic-gate returnstat = open_tag(context, TAG_EVMOD); 22707c478bd9Sstevel@tonic-gate 22717c478bd9Sstevel@tonic-gate if (returnstat >= 0) { 22727c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 22737c478bd9Sstevel@tonic-gate eventmodifier2string(emodifier, modstring, 22747c478bd9Sstevel@tonic-gate sizeof (modstring)); 22757c478bd9Sstevel@tonic-gate uval.string_val = modstring; 22767c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 22777c478bd9Sstevel@tonic-gate } else { 22787c478bd9Sstevel@tonic-gate uval.string_val = hexconvert((char *)&emodifier, 22797c478bd9Sstevel@tonic-gate sizeof (emodifier), sizeof (emodifier)); 22807c478bd9Sstevel@tonic-gate if (uval.string_val) { 22817c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, 22827c478bd9Sstevel@tonic-gate flag); 22837c478bd9Sstevel@tonic-gate free(uval.string_val); 22847c478bd9Sstevel@tonic-gate } 22857c478bd9Sstevel@tonic-gate } 22867c478bd9Sstevel@tonic-gate } 22877c478bd9Sstevel@tonic-gate if (returnstat >= 0) 22887c478bd9Sstevel@tonic-gate returnstat = close_tag(context, TAG_EVMOD); 22897c478bd9Sstevel@tonic-gate } 22907c478bd9Sstevel@tonic-gate 22917c478bd9Sstevel@tonic-gate return (returnstat); 22927c478bd9Sstevel@tonic-gate } 22937c478bd9Sstevel@tonic-gate 22947c478bd9Sstevel@tonic-gate 22957c478bd9Sstevel@tonic-gate /* 22967c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 22977c478bd9Sstevel@tonic-gate * pa_event_type(): Issues pr_adr_u_short to retrieve the next ADR item from 22987c478bd9Sstevel@tonic-gate * the input stream pointed to by audit_adr. This is the 22997c478bd9Sstevel@tonic-gate * event type, and is displayed in either raw or 23007c478bd9Sstevel@tonic-gate * ASCII form as appropriate 23017c478bd9Sstevel@tonic-gate * return codes : -1 - error 23027c478bd9Sstevel@tonic-gate * : 0 - successful 23037c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 23047c478bd9Sstevel@tonic-gate */ 23057c478bd9Sstevel@tonic-gate int 23067c478bd9Sstevel@tonic-gate pa_event_type(pr_context_t *context, int status, int flag) 23077c478bd9Sstevel@tonic-gate { 2308d0fa49b7STony Nguyen au_event_t etype; 23097c478bd9Sstevel@tonic-gate int returnstat; 23107c478bd9Sstevel@tonic-gate au_event_ent_t *p_event = NULL; 23117c478bd9Sstevel@tonic-gate uval_t uval; 23127c478bd9Sstevel@tonic-gate 23137c478bd9Sstevel@tonic-gate if (status >= 0) { 23147c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_short(context, &etype, 1)) == 0) { 23157c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 23167c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 23177c478bd9Sstevel@tonic-gate if (context->format & PRF_NOCACHE) { 23187c478bd9Sstevel@tonic-gate p_event = getauevnum(etype); 23197c478bd9Sstevel@tonic-gate } else { 23207c478bd9Sstevel@tonic-gate (void) cacheauevent(&p_event, etype); 23217c478bd9Sstevel@tonic-gate } 23227c478bd9Sstevel@tonic-gate if (p_event != NULL) { 23237c478bd9Sstevel@tonic-gate if (context->format & PRF_SHORTM) 23247c478bd9Sstevel@tonic-gate uval.string_val = 23257c478bd9Sstevel@tonic-gate p_event->ae_name; 23267c478bd9Sstevel@tonic-gate else 23277c478bd9Sstevel@tonic-gate uval.string_val = 23287c478bd9Sstevel@tonic-gate p_event->ae_desc; 23297c478bd9Sstevel@tonic-gate } else { 23307c478bd9Sstevel@tonic-gate uval.string_val = 23317c478bd9Sstevel@tonic-gate gettext("invalid event number"); 23327c478bd9Sstevel@tonic-gate } 23337c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 23347c478bd9Sstevel@tonic-gate } else { 23357c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_USHORT; 23367c478bd9Sstevel@tonic-gate uval.ushort_val = etype; 23377c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 23387c478bd9Sstevel@tonic-gate } 23397c478bd9Sstevel@tonic-gate } 23407c478bd9Sstevel@tonic-gate return (returnstat); 23417c478bd9Sstevel@tonic-gate } else 23427c478bd9Sstevel@tonic-gate return (status); 23437c478bd9Sstevel@tonic-gate 23447c478bd9Sstevel@tonic-gate } 23457c478bd9Sstevel@tonic-gate 23467c478bd9Sstevel@tonic-gate 23477c478bd9Sstevel@tonic-gate /* 23487c478bd9Sstevel@tonic-gate * Print time from struct timeval to millisecond resolution. 23497c478bd9Sstevel@tonic-gate * 23507c478bd9Sstevel@tonic-gate * typedef long time_t; time of day in seconds 23517c478bd9Sstevel@tonic-gate * typedef long useconds_t; signed # of microseconds 23527c478bd9Sstevel@tonic-gate * 23537c478bd9Sstevel@tonic-gate * struct timeval { 23547c478bd9Sstevel@tonic-gate * time_t tv_sec; seconds 23557c478bd9Sstevel@tonic-gate * suseconds_t tv_usec; and microseconds 23567c478bd9Sstevel@tonic-gate * }; 23577c478bd9Sstevel@tonic-gate */ 23587c478bd9Sstevel@tonic-gate 23597c478bd9Sstevel@tonic-gate int 23607c478bd9Sstevel@tonic-gate pa_utime32(pr_context_t *context, int status, int flag) 23617c478bd9Sstevel@tonic-gate { 23627c478bd9Sstevel@tonic-gate uint32_t scale = 1000; /* usec to msec */ 23637c478bd9Sstevel@tonic-gate 23647c478bd9Sstevel@tonic-gate return (do_mtime32(context, status, flag, scale)); 23657c478bd9Sstevel@tonic-gate } 23667c478bd9Sstevel@tonic-gate 23677c478bd9Sstevel@tonic-gate /* 23687c478bd9Sstevel@tonic-gate * Print time from timestruc_t to millisecond resolution. 23697c478bd9Sstevel@tonic-gate * 23707c478bd9Sstevel@tonic-gate * typedef struct timespec timestruct_t; 23717c478bd9Sstevel@tonic-gate * struct timespec{ 23727c478bd9Sstevel@tonic-gate * time_t tv_sec; seconds 23737c478bd9Sstevel@tonic-gate * long tv_nsec; and nanoseconds 23747c478bd9Sstevel@tonic-gate * }; 23757c478bd9Sstevel@tonic-gate */ 23767c478bd9Sstevel@tonic-gate int 23777c478bd9Sstevel@tonic-gate pa_ntime32(pr_context_t *context, int status, int flag) 23787c478bd9Sstevel@tonic-gate { 23797c478bd9Sstevel@tonic-gate uint32_t scale = 1000000; /* nsec to msec */ 23807c478bd9Sstevel@tonic-gate 23817c478bd9Sstevel@tonic-gate return (do_mtime32(context, status, flag, scale)); 23827c478bd9Sstevel@tonic-gate } 23837c478bd9Sstevel@tonic-gate 23847c478bd9Sstevel@tonic-gate /* 23857c478bd9Sstevel@tonic-gate * Format the timezone +/- HH:MM and terminate the string 23867c478bd9Sstevel@tonic-gate * Note tm and tv_sec are the same time. 23877c478bd9Sstevel@tonic-gate * Too bad strftime won't produce an ISO 8601 time zone numeric 23887c478bd9Sstevel@tonic-gate */ 23897c478bd9Sstevel@tonic-gate 23907c478bd9Sstevel@tonic-gate #define MINS (24L * 60) 23917c478bd9Sstevel@tonic-gate static void 23927c478bd9Sstevel@tonic-gate tzone(struct tm *tm, time_t *tv_sec, char *p) 23937c478bd9Sstevel@tonic-gate { 23947c478bd9Sstevel@tonic-gate struct tm *gmt; 23957c478bd9Sstevel@tonic-gate int min_off; 23967c478bd9Sstevel@tonic-gate 23977c478bd9Sstevel@tonic-gate gmt = gmtime(tv_sec); 23987c478bd9Sstevel@tonic-gate 23997c478bd9Sstevel@tonic-gate min_off = ((tm->tm_hour - gmt->tm_hour) * 60) + 24007c478bd9Sstevel@tonic-gate (tm->tm_min - gmt->tm_min); 24017c478bd9Sstevel@tonic-gate 24027c478bd9Sstevel@tonic-gate if (tm->tm_year < gmt->tm_year) /* cross new year */ 24037c478bd9Sstevel@tonic-gate min_off -= MINS; 24047c478bd9Sstevel@tonic-gate else if (tm->tm_year > gmt->tm_year) 24057c478bd9Sstevel@tonic-gate min_off += MINS; 24067c478bd9Sstevel@tonic-gate else if (tm->tm_yday < gmt->tm_yday) /* cross dateline */ 24077c478bd9Sstevel@tonic-gate min_off -= MINS; 24087c478bd9Sstevel@tonic-gate else if (tm->tm_yday > gmt->tm_yday) 24097c478bd9Sstevel@tonic-gate min_off += MINS; 24107c478bd9Sstevel@tonic-gate 24117c478bd9Sstevel@tonic-gate if (min_off < 0) { 24127c478bd9Sstevel@tonic-gate min_off = -min_off; 24137c478bd9Sstevel@tonic-gate *p++ = '-'; 24147c478bd9Sstevel@tonic-gate } else { 24157c478bd9Sstevel@tonic-gate *p++ = '+'; 24167c478bd9Sstevel@tonic-gate } 24177c478bd9Sstevel@tonic-gate 24187c478bd9Sstevel@tonic-gate *p++ = min_off / 600 + '0'; /* 10s of hours */ 24197c478bd9Sstevel@tonic-gate min_off = min_off - min_off / 600 * 600; 24207c478bd9Sstevel@tonic-gate *p++ = min_off / 60 % 10 + '0'; /* hours */ 24217c478bd9Sstevel@tonic-gate min_off = min_off - min_off / 60 * 60; 24227c478bd9Sstevel@tonic-gate *p++ = ':'; 24237c478bd9Sstevel@tonic-gate *p++ = min_off / 10 + '0'; /* 10s of minutes */ 24247c478bd9Sstevel@tonic-gate *p++ = min_off % 10 + '0'; /* minutes */ 24257c478bd9Sstevel@tonic-gate *p = '\0'; 24267c478bd9Sstevel@tonic-gate } 24277c478bd9Sstevel@tonic-gate 24287c478bd9Sstevel@tonic-gate /* 24297c478bd9Sstevel@tonic-gate * Format the milliseconds in place in the string. 24307c478bd9Sstevel@tonic-gate * Borrowed from strftime.c:itoa() 24317c478bd9Sstevel@tonic-gate */ 24327c478bd9Sstevel@tonic-gate static void 24337c478bd9Sstevel@tonic-gate msec32(uint32_t msec, char *p) 24347c478bd9Sstevel@tonic-gate { 24357c478bd9Sstevel@tonic-gate *p++ = msec / 100 + '0'; 24367c478bd9Sstevel@tonic-gate msec = msec - msec / 100 * 100; 24377c478bd9Sstevel@tonic-gate *p++ = msec / 10 + '0'; 24387c478bd9Sstevel@tonic-gate *p++ = msec % 10 +'0'; 24397c478bd9Sstevel@tonic-gate } 24407c478bd9Sstevel@tonic-gate 24417c478bd9Sstevel@tonic-gate /* 24427c478bd9Sstevel@tonic-gate * Format time and print relative to scale factor from micro/nano seconds. 24437c478bd9Sstevel@tonic-gate */ 24447c478bd9Sstevel@tonic-gate static int 24457c478bd9Sstevel@tonic-gate do_mtime32(pr_context_t *context, int status, int flag, uint32_t scale) 24467c478bd9Sstevel@tonic-gate { 24477c478bd9Sstevel@tonic-gate uint32_t t32; 24487c478bd9Sstevel@tonic-gate time_t tv_sec; 24497c478bd9Sstevel@tonic-gate struct tm tm; 24507c478bd9Sstevel@tonic-gate char time_created[sizeof ("YYYY-MM-DD HH:MM:SS.sss -HH:MM")]; 24517c478bd9Sstevel@tonic-gate int returnstat; 24527c478bd9Sstevel@tonic-gate uval_t uval; 24537c478bd9Sstevel@tonic-gate 24547c478bd9Sstevel@tonic-gate if (status < 0) 24557c478bd9Sstevel@tonic-gate return (status); 24567c478bd9Sstevel@tonic-gate 24577c478bd9Sstevel@tonic-gate if ((returnstat = open_tag(context, TAG_ISO)) != 0) 24587c478bd9Sstevel@tonic-gate return (returnstat); 24597c478bd9Sstevel@tonic-gate 24607c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_int32(context, 24617c478bd9Sstevel@tonic-gate (uint32_t *)&tv_sec, 1)) != 0) 24627c478bd9Sstevel@tonic-gate return (returnstat); 24637c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_int32(context, &t32, 1)) == 0) { 24647c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 24657c478bd9Sstevel@tonic-gate (void) localtime_r(&tv_sec, &tm); 24667c478bd9Sstevel@tonic-gate (void) strftime(time_created, 24677c478bd9Sstevel@tonic-gate sizeof ("YYYY-MM-DD HH:MM:SS.xxx "), 24687c478bd9Sstevel@tonic-gate "%Y-%m-%d %H:%M:%S.xxx ", &tm); 24697c478bd9Sstevel@tonic-gate msec32(t32/scale, 24707c478bd9Sstevel@tonic-gate &time_created[sizeof ("YYYY-MM-DD HH:MM:SS.")-1]); 24717c478bd9Sstevel@tonic-gate tzone(&tm, &tv_sec, 24727c478bd9Sstevel@tonic-gate &time_created[ 24737c478bd9Sstevel@tonic-gate sizeof ("YYYY-MM-DD HH:MM:SS.xxx ")-1]); 24747c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 24757c478bd9Sstevel@tonic-gate uval.string_val = time_created; 24767c478bd9Sstevel@tonic-gate } else { 24777c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT32; 24787c478bd9Sstevel@tonic-gate uval.uint32_val = (uint32_t)tv_sec; 24797c478bd9Sstevel@tonic-gate (void) pa_print(context, &uval, 0); 2480*3929e195SMarek Pospisil if (context->format & PRF_XMLM) { 2481*3929e195SMarek Pospisil uval.uvaltype = PRA_CHAR; 2482*3929e195SMarek Pospisil uval.char_val = '.'; 2483*3929e195SMarek Pospisil (void) pa_print(context, &uval, 0); 2484*3929e195SMarek Pospisil } 24857c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT32; 24867c478bd9Sstevel@tonic-gate uval.uint32_val = t32; 24877c478bd9Sstevel@tonic-gate } 24887c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 24897c478bd9Sstevel@tonic-gate } 24907c478bd9Sstevel@tonic-gate 24917c478bd9Sstevel@tonic-gate if (returnstat == 0) 24927c478bd9Sstevel@tonic-gate return (close_tag(context, TAG_ISO)); 24937c478bd9Sstevel@tonic-gate else 24947c478bd9Sstevel@tonic-gate return (returnstat); 24957c478bd9Sstevel@tonic-gate } 24967c478bd9Sstevel@tonic-gate 24977c478bd9Sstevel@tonic-gate /* 24987c478bd9Sstevel@tonic-gate * Print time from struct timeval to millisecond resolution. 24997c478bd9Sstevel@tonic-gate * 25007c478bd9Sstevel@tonic-gate * typedef long time_t; time of day in seconds 25017c478bd9Sstevel@tonic-gate * typedef long useconds_t; signed # of microseconds 25027c478bd9Sstevel@tonic-gate * 25037c478bd9Sstevel@tonic-gate * struct timeval { 25047c478bd9Sstevel@tonic-gate * time_t tv_sec; seconds 25057c478bd9Sstevel@tonic-gate * suseconds_t tv_usec; and microseconds 25067c478bd9Sstevel@tonic-gate * }; 25077c478bd9Sstevel@tonic-gate */ 25087c478bd9Sstevel@tonic-gate 25097c478bd9Sstevel@tonic-gate int 25107c478bd9Sstevel@tonic-gate pa_utime64(pr_context_t *context, int status, int flag) 25117c478bd9Sstevel@tonic-gate { 25127c478bd9Sstevel@tonic-gate uint64_t scale = 1000; /* usec to msec */ 25137c478bd9Sstevel@tonic-gate 25147c478bd9Sstevel@tonic-gate return (do_mtime64(context, status, flag, scale)); 25157c478bd9Sstevel@tonic-gate } 25167c478bd9Sstevel@tonic-gate 25177c478bd9Sstevel@tonic-gate /* 25187c478bd9Sstevel@tonic-gate * Print time from timestruc_t to millisecond resolution. 25197c478bd9Sstevel@tonic-gate * 25207c478bd9Sstevel@tonic-gate * typedef struct timespec timestruct_t; 25217c478bd9Sstevel@tonic-gate * struct timespec{ 25227c478bd9Sstevel@tonic-gate * time_t tv_sec; seconds 25237c478bd9Sstevel@tonic-gate * long tv_nsec; and nanoseconds 25247c478bd9Sstevel@tonic-gate * }; 25257c478bd9Sstevel@tonic-gate */ 25267c478bd9Sstevel@tonic-gate int 25277c478bd9Sstevel@tonic-gate pa_ntime64(pr_context_t *context, int status, int flag) 25287c478bd9Sstevel@tonic-gate { 25297c478bd9Sstevel@tonic-gate uint64_t scale = 1000000; /* nsec to msec */ 25307c478bd9Sstevel@tonic-gate 25317c478bd9Sstevel@tonic-gate return (do_mtime64(context, status, flag, scale)); 25327c478bd9Sstevel@tonic-gate } 25337c478bd9Sstevel@tonic-gate 25347c478bd9Sstevel@tonic-gate /* 25357c478bd9Sstevel@tonic-gate * Format the milliseconds in place in the string. 25367c478bd9Sstevel@tonic-gate * Borrowed from strftime.c:itoa() 25377c478bd9Sstevel@tonic-gate */ 25387c478bd9Sstevel@tonic-gate static void 25397c478bd9Sstevel@tonic-gate msec64(uint64_t msec, char *p) 25407c478bd9Sstevel@tonic-gate { 25417c478bd9Sstevel@tonic-gate *p++ = msec / 100 + '0'; 25427c478bd9Sstevel@tonic-gate msec = msec - msec / 100 * 100; 25437c478bd9Sstevel@tonic-gate *p++ = msec / 10 + '0'; 25447c478bd9Sstevel@tonic-gate *p++ = msec % 10 +'0'; 25457c478bd9Sstevel@tonic-gate } 25467c478bd9Sstevel@tonic-gate 25477c478bd9Sstevel@tonic-gate /* 25487c478bd9Sstevel@tonic-gate * Format time and print relative to scale factor from micro/nano seconds. 25497c478bd9Sstevel@tonic-gate */ 25507c478bd9Sstevel@tonic-gate static int 25517c478bd9Sstevel@tonic-gate do_mtime64(pr_context_t *context, int status, int flag, uint64_t scale) 25527c478bd9Sstevel@tonic-gate { 25537c478bd9Sstevel@tonic-gate uint64_t t64_sec; 25547c478bd9Sstevel@tonic-gate uint64_t t64_msec; 25557c478bd9Sstevel@tonic-gate time_t tv_sec; 25567c478bd9Sstevel@tonic-gate struct tm tm; 25577c478bd9Sstevel@tonic-gate char time_created[sizeof ("YYYY-MM-DD HH:MM:SS.sss -HH:MM")]; 25587c478bd9Sstevel@tonic-gate int returnstat; 25597c478bd9Sstevel@tonic-gate uval_t uval; 25607c478bd9Sstevel@tonic-gate 25617c478bd9Sstevel@tonic-gate if (status < 0) 25627c478bd9Sstevel@tonic-gate return (status); 25637c478bd9Sstevel@tonic-gate 25647c478bd9Sstevel@tonic-gate if ((returnstat = open_tag(context, TAG_ISO)) != 0) 25657c478bd9Sstevel@tonic-gate return (returnstat); 25667c478bd9Sstevel@tonic-gate 25677c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_int64(context, &t64_sec, 1)) != 0) 25687c478bd9Sstevel@tonic-gate return (returnstat); 25697c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_int64(context, &t64_msec, 1)) == 0) { 25707c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 25717c478bd9Sstevel@tonic-gate #ifndef _LP64 25727c478bd9Sstevel@tonic-gate /* 25737c478bd9Sstevel@tonic-gate * N.B. 25747c478bd9Sstevel@tonic-gate * This fails for years from 2038 25757c478bd9Sstevel@tonic-gate * The Y2K+38 problem 25767c478bd9Sstevel@tonic-gate */ 25777c478bd9Sstevel@tonic-gate #endif /* !_LP64 */ 25787c478bd9Sstevel@tonic-gate tv_sec = (time_t)t64_sec; 25797c478bd9Sstevel@tonic-gate (void) localtime_r(&tv_sec, &tm); 25807c478bd9Sstevel@tonic-gate (void) strftime(time_created, 25817c478bd9Sstevel@tonic-gate sizeof ("YYYY-MM-DD HH:MM:SS.xxx "), 25827c478bd9Sstevel@tonic-gate "%Y-%m-%d %H:%M:%S.xxx ", &tm); 25837c478bd9Sstevel@tonic-gate msec64(t64_msec/scale, 25847c478bd9Sstevel@tonic-gate &time_created[sizeof ("YYYY-MM-DD HH:MM:SS.")-1]); 25857c478bd9Sstevel@tonic-gate tzone(&tm, &tv_sec, 25867c478bd9Sstevel@tonic-gate &time_created[ 25877c478bd9Sstevel@tonic-gate sizeof ("YYYY-MM-DD HH:MM:SS.xxx ")-1]); 25887c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 25897c478bd9Sstevel@tonic-gate uval.string_val = time_created; 25907c478bd9Sstevel@tonic-gate } else { 25917c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT64; 25927c478bd9Sstevel@tonic-gate uval.uint64_val = t64_sec; 25937c478bd9Sstevel@tonic-gate (void) pa_print(context, &uval, 0); 2594*3929e195SMarek Pospisil if (context->format & PRF_XMLM) { 2595*3929e195SMarek Pospisil uval.uvaltype = PRA_CHAR; 2596*3929e195SMarek Pospisil uval.char_val = '.'; 2597*3929e195SMarek Pospisil (void) pa_print(context, &uval, 0); 2598*3929e195SMarek Pospisil } 25997c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT64; 26007c478bd9Sstevel@tonic-gate uval.uint64_val = t64_msec; 26017c478bd9Sstevel@tonic-gate } 26027c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 26037c478bd9Sstevel@tonic-gate } 26047c478bd9Sstevel@tonic-gate 26057c478bd9Sstevel@tonic-gate if (returnstat < 0) 26067c478bd9Sstevel@tonic-gate return (returnstat); 26077c478bd9Sstevel@tonic-gate 26087c478bd9Sstevel@tonic-gate return (close_tag(context, TAG_ISO)); 26097c478bd9Sstevel@tonic-gate } 26107c478bd9Sstevel@tonic-gate 26117c478bd9Sstevel@tonic-gate /* 26127c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 26137c478bd9Sstevel@tonic-gate * pa_error() : convert the return token error code. 26147c478bd9Sstevel@tonic-gate * 26157c478bd9Sstevel@tonic-gate * output : buf string representing return token error code. 26167c478bd9Sstevel@tonic-gate * 26177c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 26187c478bd9Sstevel@tonic-gate */ 26197c478bd9Sstevel@tonic-gate void 26207c478bd9Sstevel@tonic-gate pa_error(const uchar_t err, char *buf, size_t buflen) 26217c478bd9Sstevel@tonic-gate { 2622f72effdeSgww if (err == ADT_SUCCESS) { 26237c478bd9Sstevel@tonic-gate (void) strlcpy(buf, gettext("success"), buflen); 2624f72effdeSgww } else if ((char)err == ADT_FAILURE) { 26257c478bd9Sstevel@tonic-gate (void) strlcpy(buf, gettext("failure"), buflen); 26267c478bd9Sstevel@tonic-gate } else { 26277c478bd9Sstevel@tonic-gate char *emsg = strerror(err); 26287c478bd9Sstevel@tonic-gate 26297c478bd9Sstevel@tonic-gate if (emsg != NULL) { 26307c478bd9Sstevel@tonic-gate (void) strlcpy(buf, gettext("failure: "), buflen); 26317c478bd9Sstevel@tonic-gate (void) strlcat(buf, emsg, buflen); 26327c478bd9Sstevel@tonic-gate } else { 26337c478bd9Sstevel@tonic-gate (void) snprintf(buf, buflen, "%s%d", 26347c478bd9Sstevel@tonic-gate gettext("failure: "), err); 26357c478bd9Sstevel@tonic-gate } 26367c478bd9Sstevel@tonic-gate } 26377c478bd9Sstevel@tonic-gate } 26387c478bd9Sstevel@tonic-gate 26397c478bd9Sstevel@tonic-gate /* 26407c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 26417c478bd9Sstevel@tonic-gate * pa_retval() : convert the return token return value code. 26427c478bd9Sstevel@tonic-gate * 2643a9729242Sgww * input : err, for kernel success 0, or 2644a9729242Sgww * failure errno: 0 > & < sys_nerr. 2645a9729242Sgww * for userland success ADT_SUCCESS (0) or 2646a9729242Sgww * failure ADT_FAILURE (-1). 2647a9729242Sgww * pa_error() above has already converted err. 2648a9729242Sgww * 2649a9729242Sgww * : retval, for kernel arbitrary return value for success, or 2650a9729242Sgww * failure: -1. 2651a9729242Sgww * for userland, 2652a9729242Sgww * >= ADT_FAIL_VALUE < ADT_FAIL_PAM, an adt message code; 2653a9729242Sgww * >= ADT_FAIL_PAM, a pam_strerror value; 2654a9729242Sgww * < ADT_FAIL_VALUE, supposed to be an errno. 2655a9729242Sgww * 26567c478bd9Sstevel@tonic-gate * output : buf string representing return token error code. 26577c478bd9Sstevel@tonic-gate * 26587c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 26597c478bd9Sstevel@tonic-gate */ 26607c478bd9Sstevel@tonic-gate void 2661f72effdeSgww pa_retval(const uchar_t err, const int32_t retval, char *buf, size_t buflen) 26627c478bd9Sstevel@tonic-gate { 2663a9729242Sgww struct msg_text *msglist; 2664a9729242Sgww char *emsg; 2665a9729242Sgww 2666a9729242Sgww /* success or kernel failure */ 2667a9729242Sgww if (((char)err == ADT_SUCCESS) || 2668a9729242Sgww (retval < 0)) { 2669a9729242Sgww 2670a9729242Sgww (void) snprintf(buf, buflen, "%d", retval); 2671a9729242Sgww return; 2672a9729242Sgww } 2673a9729242Sgww 2674a9729242Sgww /* userland failure */ 2675a9729242Sgww msglist = &adt_msg_text[ADT_LIST_FAIL_VALUE]; 26767c478bd9Sstevel@tonic-gate 26777c478bd9Sstevel@tonic-gate if ((retval + msglist->ml_offset >= msglist->ml_min_index) && 26787c478bd9Sstevel@tonic-gate (retval + msglist->ml_offset <= msglist->ml_max_index)) { 26797c478bd9Sstevel@tonic-gate 26807c478bd9Sstevel@tonic-gate (void) strlcpy(buf, 26817c478bd9Sstevel@tonic-gate gettext(msglist->ml_msg_list[retval + msglist->ml_offset]), 26827c478bd9Sstevel@tonic-gate buflen); 26837c478bd9Sstevel@tonic-gate } else if ((retval >= ADT_FAIL_PAM) && 2684f72effdeSgww (retval < ADT_FAIL_PAM + PAM_TOTAL_ERRNUM)) { 2685a9729242Sgww 26867c478bd9Sstevel@tonic-gate (void) strlcpy(buf, pam_strerror(NULL, retval - ADT_FAIL_PAM), 26877c478bd9Sstevel@tonic-gate buflen); 2688a9729242Sgww } else if ((emsg = strerror(retval)) != NULL) { 2689f72effdeSgww 2690f72effdeSgww (void) strlcpy(buf, emsg, buflen); 2691f72effdeSgww } else { 26927c478bd9Sstevel@tonic-gate 2693a9729242Sgww (void) snprintf(buf, buflen, "%d", retval); 2694a9729242Sgww } 2695a9729242Sgww } 26967c478bd9Sstevel@tonic-gate 26977c478bd9Sstevel@tonic-gate /* 26987c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 26997c478bd9Sstevel@tonic-gate * pa_printstr() : print a given string, translating unprintables 27007c478bd9Sstevel@tonic-gate * : as needed. 27017c478bd9Sstevel@tonic-gate */ 27027c478bd9Sstevel@tonic-gate static int 27037c478bd9Sstevel@tonic-gate pa_printstr(pr_context_t *context, char *str) 27047c478bd9Sstevel@tonic-gate { 27057c478bd9Sstevel@tonic-gate int err = 0; 27067c478bd9Sstevel@tonic-gate int len, printable; 27077c478bd9Sstevel@tonic-gate int mbmax = MB_CUR_MAX; 27087c478bd9Sstevel@tonic-gate wchar_t wc; 27097c478bd9Sstevel@tonic-gate char c; 27107c478bd9Sstevel@tonic-gate 27117c478bd9Sstevel@tonic-gate if (mbmax == 1) { 27127c478bd9Sstevel@tonic-gate /* fast path */ 27137c478bd9Sstevel@tonic-gate while (err == 0 && *str != '\0') { 27147c478bd9Sstevel@tonic-gate c = *str++; 27157c478bd9Sstevel@tonic-gate printable = isprint((unsigned char)c); 27167c478bd9Sstevel@tonic-gate err = pa_putstr(context, printable, &c, 1); 27177c478bd9Sstevel@tonic-gate } 27187c478bd9Sstevel@tonic-gate return (err); 27197c478bd9Sstevel@tonic-gate } 27207c478bd9Sstevel@tonic-gate while (err == 0 && *str != '\0') { 27217c478bd9Sstevel@tonic-gate len = mbtowc(&wc, str, mbmax); 27227c478bd9Sstevel@tonic-gate if (len <= 0) { 27237c478bd9Sstevel@tonic-gate len = 1; 27247c478bd9Sstevel@tonic-gate printable = 0; 27257c478bd9Sstevel@tonic-gate } else { 27267c478bd9Sstevel@tonic-gate printable = iswprint(wc); 27277c478bd9Sstevel@tonic-gate } 27287c478bd9Sstevel@tonic-gate err = pa_putstr(context, printable, str, len); 27297c478bd9Sstevel@tonic-gate str += len; 27307c478bd9Sstevel@tonic-gate } 27317c478bd9Sstevel@tonic-gate return (err); 27327c478bd9Sstevel@tonic-gate } 27337c478bd9Sstevel@tonic-gate 27347c478bd9Sstevel@tonic-gate /* 27357c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 27367c478bd9Sstevel@tonic-gate * pa_print() : print as one str or formatted for easy reading. 27377c478bd9Sstevel@tonic-gate * : flag - indicates whether to output a new line for 27387c478bd9Sstevel@tonic-gate * : multi-line output. 27397c478bd9Sstevel@tonic-gate * : = 0; no new line 27407c478bd9Sstevel@tonic-gate * : = 1; new line if regular output 27417c478bd9Sstevel@tonic-gate * output : The audit record information is displayed in the 27427c478bd9Sstevel@tonic-gate * type specified by uvaltype and value specified in 27437c478bd9Sstevel@tonic-gate * uval. The printing of the delimiter or newline is 27447c478bd9Sstevel@tonic-gate * determined by PRF_ONELINE, and the flag value, 27457c478bd9Sstevel@tonic-gate * as follows: 27467c478bd9Sstevel@tonic-gate * +--------+------+------+-----------------+ 27477c478bd9Sstevel@tonic-gate * |ONELINE | flag | last | Action | 27487c478bd9Sstevel@tonic-gate * +--------+------+------+-----------------+ 27497c478bd9Sstevel@tonic-gate * | Y | Y | T | print new line | 27507c478bd9Sstevel@tonic-gate * | Y | Y | F | print delimiter | 27517c478bd9Sstevel@tonic-gate * | Y | N | T | print new line | 27527c478bd9Sstevel@tonic-gate * | Y | N | F | print delimiter | 27537c478bd9Sstevel@tonic-gate * | N | Y | T | print new line | 27547c478bd9Sstevel@tonic-gate * | N | Y | F | print new line | 27557c478bd9Sstevel@tonic-gate * | N | N | T | print new line | 27567c478bd9Sstevel@tonic-gate * | N | N | F | print delimiter | 27577c478bd9Sstevel@tonic-gate * +--------+------+------+-----------------+ 27587c478bd9Sstevel@tonic-gate * 27597c478bd9Sstevel@tonic-gate * return codes : -1 - error 27607c478bd9Sstevel@tonic-gate * 0 - successful 27617c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 27627c478bd9Sstevel@tonic-gate */ 27637c478bd9Sstevel@tonic-gate int 27647c478bd9Sstevel@tonic-gate pa_print(pr_context_t *context, uval_t *uval, int flag) 27657c478bd9Sstevel@tonic-gate { 27667c478bd9Sstevel@tonic-gate int returnstat = 0; 27677c478bd9Sstevel@tonic-gate int last; 27687c478bd9Sstevel@tonic-gate 27697c478bd9Sstevel@tonic-gate switch (uval->uvaltype) { 27707c478bd9Sstevel@tonic-gate case PRA_INT32: 27717c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%d", uval->int32_val); 27727c478bd9Sstevel@tonic-gate break; 27737c478bd9Sstevel@tonic-gate case PRA_UINT32: 27747c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%u", uval->uint32_val); 27757c478bd9Sstevel@tonic-gate break; 27767c478bd9Sstevel@tonic-gate case PRA_INT64: 27777c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%"PRId64, uval->int64_val); 27787c478bd9Sstevel@tonic-gate break; 27797c478bd9Sstevel@tonic-gate case PRA_UINT64: 27807c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%"PRIu64, uval->uint64_val); 27817c478bd9Sstevel@tonic-gate break; 27827c478bd9Sstevel@tonic-gate case PRA_SHORT: 27837c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%hd", uval->short_val); 27847c478bd9Sstevel@tonic-gate break; 27857c478bd9Sstevel@tonic-gate case PRA_USHORT: 27867c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%hu", uval->ushort_val); 27877c478bd9Sstevel@tonic-gate break; 27887c478bd9Sstevel@tonic-gate case PRA_CHAR: 27897c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%c", uval->char_val); 27907c478bd9Sstevel@tonic-gate break; 27917c478bd9Sstevel@tonic-gate case PRA_BYTE: 27927c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%d", uval->char_val); 27937c478bd9Sstevel@tonic-gate break; 27947c478bd9Sstevel@tonic-gate case PRA_STRING: 27957c478bd9Sstevel@tonic-gate returnstat = pa_printstr(context, uval->string_val); 27967c478bd9Sstevel@tonic-gate break; 27977c478bd9Sstevel@tonic-gate case PRA_HEX32: 27987c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "0x%x", uval->int32_val); 27997c478bd9Sstevel@tonic-gate break; 28007c478bd9Sstevel@tonic-gate case PRA_HEX64: 28017c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "0x%"PRIx64, uval->int64_val); 28027c478bd9Sstevel@tonic-gate break; 28037c478bd9Sstevel@tonic-gate case PRA_SHEX: 28047c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "0x%hx", uval->short_val); 28057c478bd9Sstevel@tonic-gate break; 28067c478bd9Sstevel@tonic-gate case PRA_OCT: 28077c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%ho", uval->ushort_val); 28087c478bd9Sstevel@tonic-gate break; 28097c478bd9Sstevel@tonic-gate case PRA_LOCT: 28107c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%o", (int)uval->uint32_val); 28117c478bd9Sstevel@tonic-gate break; 28127c478bd9Sstevel@tonic-gate default: 28137c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("praudit: Unknown type.\n")); 28147c478bd9Sstevel@tonic-gate returnstat = -1; 28157c478bd9Sstevel@tonic-gate break; 28167c478bd9Sstevel@tonic-gate } 28177c478bd9Sstevel@tonic-gate if (returnstat < 0) 28187c478bd9Sstevel@tonic-gate return (returnstat); 28197c478bd9Sstevel@tonic-gate 28207c478bd9Sstevel@tonic-gate last = (context->audit_adr->adr_now == 28217c478bd9Sstevel@tonic-gate (context->audit_rec_start + context->audit_rec_len)); 28227c478bd9Sstevel@tonic-gate 28237c478bd9Sstevel@tonic-gate if (!(context->format & PRF_XMLM)) { 28247c478bd9Sstevel@tonic-gate if (!(context->format & PRF_ONELINE)) { 28257c478bd9Sstevel@tonic-gate if ((flag == 1) || last) 28267c478bd9Sstevel@tonic-gate returnstat = pr_putchar(context, '\n'); 28277c478bd9Sstevel@tonic-gate else 28287c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%s", 28297c478bd9Sstevel@tonic-gate context->SEPARATOR); 28307c478bd9Sstevel@tonic-gate } else { 28317c478bd9Sstevel@tonic-gate if (!last) 28327c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%s", 28337c478bd9Sstevel@tonic-gate context->SEPARATOR); 28347c478bd9Sstevel@tonic-gate else 28357c478bd9Sstevel@tonic-gate returnstat = pr_putchar(context, '\n'); 28367c478bd9Sstevel@tonic-gate } 28377c478bd9Sstevel@tonic-gate } 28387c478bd9Sstevel@tonic-gate if ((returnstat == 0) && (context->data_mode == FILEMODE)) 28397c478bd9Sstevel@tonic-gate (void) fflush(stdout); 28407c478bd9Sstevel@tonic-gate 28417c478bd9Sstevel@tonic-gate return (returnstat); 28427c478bd9Sstevel@tonic-gate } 28437c478bd9Sstevel@tonic-gate 28448dc347dbStz204579 static struct cntrl_mapping { 28458dc347dbStz204579 char from; 28468dc347dbStz204579 char to; 28478dc347dbStz204579 } cntrl_map[] = { 28488dc347dbStz204579 '\0', '0', 28498dc347dbStz204579 '\a', 'a', 28508dc347dbStz204579 '\b', 'b', 28518dc347dbStz204579 '\t', 't', 28528dc347dbStz204579 '\f', 'f', 28538dc347dbStz204579 '\n', 'n', 28548dc347dbStz204579 '\r', 'r', 28558dc347dbStz204579 '\v', 'v' 28568dc347dbStz204579 }; 28578dc347dbStz204579 28588dc347dbStz204579 static int cntrl_map_entries = sizeof (cntrl_map) 28598dc347dbStz204579 / sizeof (struct cntrl_mapping); 28608dc347dbStz204579 28617c478bd9Sstevel@tonic-gate /* 28627c478bd9Sstevel@tonic-gate * Convert binary data to ASCII for printing. 28637c478bd9Sstevel@tonic-gate */ 28647c478bd9Sstevel@tonic-gate void 28657c478bd9Sstevel@tonic-gate convertascii(char *p, char *c, int size) 28667c478bd9Sstevel@tonic-gate { 286785298dc1Snakanon int i, j, uc; 28687c478bd9Sstevel@tonic-gate 28697c478bd9Sstevel@tonic-gate for (i = 0; i < size; i++) { 287085298dc1Snakanon uc = (unsigned char)*(c + i); 287185298dc1Snakanon if (isascii(uc)) { 287285298dc1Snakanon if (iscntrl(uc)) { 287385298dc1Snakanon for (j = 0; j < cntrl_map_entries; j++) { 287485298dc1Snakanon if (cntrl_map[j].from == uc) { 28758dc347dbStz204579 *p++ = '\\'; 28768dc347dbStz204579 *p++ = cntrl_map[j].to; 287785298dc1Snakanon break; 28788dc347dbStz204579 } 287985298dc1Snakanon } 288085298dc1Snakanon if (j == cntrl_map_entries) { 28817c478bd9Sstevel@tonic-gate *p++ = '^'; 288285298dc1Snakanon *p++ = (char)(uc ^ 0100); 28838dc347dbStz204579 } 288485298dc1Snakanon } else { 288585298dc1Snakanon *p++ = (char)uc; 28867c478bd9Sstevel@tonic-gate } 288785298dc1Snakanon } else { 288885298dc1Snakanon p += sprintf(p, "\\%03o", uc); 288985298dc1Snakanon } 289085298dc1Snakanon } 28917c478bd9Sstevel@tonic-gate *p = '\0'; 28927c478bd9Sstevel@tonic-gate } 28937c478bd9Sstevel@tonic-gate 28947c478bd9Sstevel@tonic-gate /* 28957c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 28967c478bd9Sstevel@tonic-gate * pa_xgeneric: Process Xobject token and display contents 28977c478bd9Sstevel@tonic-gate * This routine will handle many of the attribute 28987c478bd9Sstevel@tonic-gate * types introduced in TS 2.x, such as: 28997c478bd9Sstevel@tonic-gate * 29007c478bd9Sstevel@tonic-gate * AUT_XCOLORMAP, AUT_XCURSOR, AUT_XFONT, 29017c478bd9Sstevel@tonic-gate * AUT_XGC, AUT_XPIXMAP, AUT_XWINDOW 29027c478bd9Sstevel@tonic-gate * 29037c478bd9Sstevel@tonic-gate * NOTE: At the time of call, the token id has been retrieved 29047c478bd9Sstevel@tonic-gate * 29057c478bd9Sstevel@tonic-gate * return codes : -1 - error 29067c478bd9Sstevel@tonic-gate * : 0 - successful 29077c478bd9Sstevel@tonic-gate * NOTE: At the time of call, the xatom token id has been retrieved 29087c478bd9Sstevel@tonic-gate * 29097c478bd9Sstevel@tonic-gate * Format of xobj 29107c478bd9Sstevel@tonic-gate * text token id adr_char 29117c478bd9Sstevel@tonic-gate * XID adr_u_int32 29127c478bd9Sstevel@tonic-gate * creator uid adr_pw_uid 29137c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 29147c478bd9Sstevel@tonic-gate */ 29157c478bd9Sstevel@tonic-gate int 29167c478bd9Sstevel@tonic-gate pa_xgeneric(pr_context_t *context) 29177c478bd9Sstevel@tonic-gate { 29187c478bd9Sstevel@tonic-gate int returnstat; 29197c478bd9Sstevel@tonic-gate 29207c478bd9Sstevel@tonic-gate returnstat = process_tag(context, TAG_XID, 0, 0); 29217c478bd9Sstevel@tonic-gate return (process_tag(context, TAG_XCUID, returnstat, 1)); 29227c478bd9Sstevel@tonic-gate } 29237c478bd9Sstevel@tonic-gate 29247c478bd9Sstevel@tonic-gate 29257c478bd9Sstevel@tonic-gate /* 29267c478bd9Sstevel@tonic-gate * ------------------------------------------------------------------------ 29277c478bd9Sstevel@tonic-gate * pa_liaison : Issues pr_adr_char to retrieve the next ADR item from the 29287c478bd9Sstevel@tonic-gate * input stream pointed to by audit_adr, and prints it 29297c478bd9Sstevel@tonic-gate * if status >= 0 either in ASCII or raw form 29307c478bd9Sstevel@tonic-gate * return codes : -1 - error 29317c478bd9Sstevel@tonic-gate * : 0 - successful 29327c478bd9Sstevel@tonic-gate * : 1 - warning, unknown label type 29337c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------- 29347c478bd9Sstevel@tonic-gate */ 29357c478bd9Sstevel@tonic-gate int 29367c478bd9Sstevel@tonic-gate pa_liaison(pr_context_t *context, int status, int flag) 29377c478bd9Sstevel@tonic-gate { 29387c478bd9Sstevel@tonic-gate int returnstat; 29397c478bd9Sstevel@tonic-gate int32_t li; 29407c478bd9Sstevel@tonic-gate uval_t uval; 29417c478bd9Sstevel@tonic-gate 29427c478bd9Sstevel@tonic-gate if (status >= 0) { 29437c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_int32(context, &li, 1)) != 0) { 29447c478bd9Sstevel@tonic-gate return (returnstat); 29457c478bd9Sstevel@tonic-gate } 29467c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 29477c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT32; 29487c478bd9Sstevel@tonic-gate uval.uint32_val = li; 29497c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 29507c478bd9Sstevel@tonic-gate } 29517c478bd9Sstevel@tonic-gate /* print in hexadecimal form */ 29527c478bd9Sstevel@tonic-gate if ((context->format & PRF_RAWM) || (returnstat == 1)) { 29537c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_HEX32; 29547c478bd9Sstevel@tonic-gate uval.uint32_val = li; 29557c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 29567c478bd9Sstevel@tonic-gate } 29577c478bd9Sstevel@tonic-gate return (returnstat); 29587c478bd9Sstevel@tonic-gate } else 29597c478bd9Sstevel@tonic-gate return (status); 29607c478bd9Sstevel@tonic-gate } 29617c478bd9Sstevel@tonic-gate 29627c478bd9Sstevel@tonic-gate /* 29637c478bd9Sstevel@tonic-gate * ------------------------------------------------------------------------ 29647c478bd9Sstevel@tonic-gate * pa_xid : Issues pr_adr_int32 to retrieve the XID from the input 29657c478bd9Sstevel@tonic-gate * stream pointed to by audit_adr, and prints it if 29667c478bd9Sstevel@tonic-gate * status >= 0 either in ASCII or raw form 29677c478bd9Sstevel@tonic-gate * return codes : -1 - error 29687c478bd9Sstevel@tonic-gate * : 0 - successful 29697c478bd9Sstevel@tonic-gate * : 1 - warning, unknown label type 29707c478bd9Sstevel@tonic-gate * ------------------------------------------------------------------------ 29717c478bd9Sstevel@tonic-gate */ 29727c478bd9Sstevel@tonic-gate 29737c478bd9Sstevel@tonic-gate int 29747c478bd9Sstevel@tonic-gate pa_xid(pr_context_t *context, int status, int flag) 29757c478bd9Sstevel@tonic-gate { 29767c478bd9Sstevel@tonic-gate int returnstat; 29777c478bd9Sstevel@tonic-gate int32_t xid; 29787c478bd9Sstevel@tonic-gate uval_t uval; 29797c478bd9Sstevel@tonic-gate 29807c478bd9Sstevel@tonic-gate if (status < 0) 29817c478bd9Sstevel@tonic-gate return (status); 29827c478bd9Sstevel@tonic-gate 29837c478bd9Sstevel@tonic-gate /* get XID from stream */ 29847c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_int32(context, (int32_t *)&xid, 1)) != 0) 29857c478bd9Sstevel@tonic-gate return (returnstat); 29867c478bd9Sstevel@tonic-gate 29877c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) { 29887c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING; 29897c478bd9Sstevel@tonic-gate uval.string_val = hexconvert((char *)&xid, sizeof (xid), 29907c478bd9Sstevel@tonic-gate sizeof (xid)); 29917c478bd9Sstevel@tonic-gate if (uval.string_val) { 29927c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 29937c478bd9Sstevel@tonic-gate free(uval.string_val); 29947c478bd9Sstevel@tonic-gate } 29957c478bd9Sstevel@tonic-gate } else { 29967c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_INT32; 29977c478bd9Sstevel@tonic-gate uval.int32_val = xid; 29987c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag); 29997c478bd9Sstevel@tonic-gate } 30007c478bd9Sstevel@tonic-gate 30017c478bd9Sstevel@tonic-gate return (returnstat); 30027c478bd9Sstevel@tonic-gate } 3003a7746f66Stz204579 3004a7746f66Stz204579 static int 3005a7746f66Stz204579 pa_ace_flags(pr_context_t *context, ace_t *ace, int status, int flag) 3006a7746f66Stz204579 { 3007a7746f66Stz204579 int returnstat; 3008a7746f66Stz204579 uval_t uval; 3009a7746f66Stz204579 3010a7746f66Stz204579 if (status < 0) 3011a7746f66Stz204579 return (status); 3012a7746f66Stz204579 3013a7746f66Stz204579 /* 3014a7746f66Stz204579 * TRANSLATION_NOTE 3015a7746f66Stz204579 * ace->a_flags refers to access flags of ZFS/NFSv4 ACL entry. 3016a7746f66Stz204579 */ 3017a7746f66Stz204579 if ((returnstat = open_tag(context, TAG_ACEFLAGS)) != 0) 3018a7746f66Stz204579 return (returnstat); 3019a7746f66Stz204579 if (!(context->format & PRF_RAWM)) { 3020a7746f66Stz204579 uval.uvaltype = PRA_STRING; 3021a7746f66Stz204579 switch (ace->a_flags & ACE_TYPE_FLAGS) { 3022a7746f66Stz204579 case ACE_OWNER: 3023a7746f66Stz204579 uval.string_val = gettext(OWNERAT_TXT); 3024a7746f66Stz204579 break; 3025a7746f66Stz204579 case ACE_GROUP | ACE_IDENTIFIER_GROUP: 3026a7746f66Stz204579 uval.string_val = gettext(GROUPAT_TXT); 3027a7746f66Stz204579 break; 3028a7746f66Stz204579 case ACE_IDENTIFIER_GROUP: 3029a7746f66Stz204579 uval.string_val = gettext(GROUP_TXT); 3030a7746f66Stz204579 break; 3031a7746f66Stz204579 case ACE_EVERYONE: 3032a7746f66Stz204579 uval.string_val = gettext(EVERYONEAT_TXT); 3033a7746f66Stz204579 break; 3034a7746f66Stz204579 case 0: 3035a7746f66Stz204579 uval.string_val = gettext(USER_TXT); 3036a7746f66Stz204579 break; 3037a7746f66Stz204579 default: 3038a7746f66Stz204579 uval.uvaltype = PRA_USHORT; 3039a7746f66Stz204579 uval.uint32_val = ace->a_flags; 3040a7746f66Stz204579 } 3041a7746f66Stz204579 } else { 3042a7746f66Stz204579 uval.uvaltype = PRA_USHORT; 3043a7746f66Stz204579 uval.uint32_val = ace->a_flags; 3044a7746f66Stz204579 } 3045a7746f66Stz204579 if ((returnstat = pa_print(context, &uval, flag)) != 0) 3046a7746f66Stz204579 return (returnstat); 3047a7746f66Stz204579 return (close_tag(context, TAG_ACEFLAGS)); 3048a7746f66Stz204579 } 3049a7746f66Stz204579 3050a7746f66Stz204579 static int 3051a7746f66Stz204579 pa_ace_who(pr_context_t *context, ace_t *ace, int status, int flag) 3052a7746f66Stz204579 { 3053a7746f66Stz204579 int returnstat; 3054a7746f66Stz204579 3055a7746f66Stz204579 if (status < 0) 3056a7746f66Stz204579 return (status); 3057a7746f66Stz204579 3058a7746f66Stz204579 /* 3059a7746f66Stz204579 * TRANSLATION_NOTE 3060a7746f66Stz204579 * ace->a_who refers to user id or group id of ZFS/NFSv4 ACL entry. 3061a7746f66Stz204579 */ 3062a7746f66Stz204579 if ((returnstat = open_tag(context, TAG_ACEID)) != 0) 3063a7746f66Stz204579 return (returnstat); 3064a7746f66Stz204579 switch (ace->a_flags & ACE_TYPE_FLAGS) { 3065a7746f66Stz204579 case ACE_IDENTIFIER_GROUP: /* group id */ 3066a7746f66Stz204579 returnstat = pa_print_gid(context, ace->a_who, returnstat, 3067a7746f66Stz204579 flag); 3068a7746f66Stz204579 break; 3069a7746f66Stz204579 default: /* user id */ 3070a7746f66Stz204579 returnstat = pa_print_uid(context, ace->a_who, returnstat, 3071a7746f66Stz204579 flag); 3072a7746f66Stz204579 break; 3073a7746f66Stz204579 } 3074a7746f66Stz204579 if (returnstat < 0) 3075a7746f66Stz204579 return (returnstat); 3076a7746f66Stz204579 return (close_tag(context, TAG_ACEID)); 3077a7746f66Stz204579 } 3078a7746f66Stz204579 3079a7746f66Stz204579 /* 3080a7746f66Stz204579 * Appends what to str, (re)allocating str if necessary. 3081a7746f66Stz204579 */ 3082a7746f66Stz204579 #define INITIAL_ALLOC 256 3083a7746f66Stz204579 static int 3084a7746f66Stz204579 strappend(char **str, char *what, size_t *alloc) 3085a7746f66Stz204579 { 3086a7746f66Stz204579 char *s, *newstr; 3087a7746f66Stz204579 size_t needed; 3088a7746f66Stz204579 3089a7746f66Stz204579 s = *str; 3090a7746f66Stz204579 3091a7746f66Stz204579 if (s == NULL) { 3092a7746f66Stz204579 s = malloc(INITIAL_ALLOC); 3093a7746f66Stz204579 if (s == NULL) { 3094a7746f66Stz204579 *alloc = 0; 3095a7746f66Stz204579 return (-1); 3096a7746f66Stz204579 } 3097a7746f66Stz204579 *alloc = INITIAL_ALLOC; 3098a7746f66Stz204579 s[0] = '\0'; 3099a7746f66Stz204579 *str = s; 3100a7746f66Stz204579 } 3101a7746f66Stz204579 3102a7746f66Stz204579 needed = strlen(s) + strlen(what) + 1; 3103a7746f66Stz204579 if (*alloc < needed) { 3104a7746f66Stz204579 newstr = realloc(s, needed); 3105a7746f66Stz204579 if (newstr == NULL) 3106a7746f66Stz204579 return (-1); 3107a7746f66Stz204579 s = newstr; 3108a7746f66Stz204579 *alloc = needed; 3109a7746f66Stz204579 *str = s; 3110a7746f66Stz204579 } 3111a7746f66Stz204579 (void) strlcat(s, what, *alloc); 3112a7746f66Stz204579 3113a7746f66Stz204579 return (0); 3114a7746f66Stz204579 } 3115a7746f66Stz204579 3116a7746f66Stz204579 static int 3117a7746f66Stz204579 pa_ace_access_mask(pr_context_t *context, ace_t *ace, int status, int flag) 3118a7746f66Stz204579 { 3119a7746f66Stz204579 int returnstat, i; 3120a7746f66Stz204579 uval_t uval; 3121a7746f66Stz204579 char *permstr = NULL; 3122a7746f66Stz204579 size_t permstr_alloc = 0; 3123a7746f66Stz204579 3124a7746f66Stz204579 if (status < 0) 3125a7746f66Stz204579 return (status); 3126a7746f66Stz204579 3127a7746f66Stz204579 /* 3128a7746f66Stz204579 * TRANSLATION_NOTE 3129a7746f66Stz204579 * ace->a_access_mask refers to access mask of ZFS/NFSv4 ACL entry. 3130a7746f66Stz204579 */ 3131a7746f66Stz204579 if ((returnstat = open_tag(context, TAG_ACEMASK)) != 0) 3132a7746f66Stz204579 return (returnstat); 3133a7746f66Stz204579 if (context->format & PRF_SHORTM && 3134a7746f66Stz204579 ((permstr = malloc(15)) != NULL)) { 3135a7746f66Stz204579 for (i = 0; i < 14; i++) 3136a7746f66Stz204579 permstr[i] = '-'; 3137a7746f66Stz204579 3138a7746f66Stz204579 if (ace->a_access_mask & ACE_READ_DATA) 3139a7746f66Stz204579 permstr[0] = 'r'; 3140a7746f66Stz204579 if (ace->a_access_mask & ACE_WRITE_DATA) 3141a7746f66Stz204579 permstr[1] = 'w'; 3142a7746f66Stz204579 if (ace->a_access_mask & ACE_EXECUTE) 3143a7746f66Stz204579 permstr[2] = 'x'; 3144a7746f66Stz204579 if (ace->a_access_mask & ACE_APPEND_DATA) 3145a7746f66Stz204579 permstr[3] = 'p'; 3146a7746f66Stz204579 if (ace->a_access_mask & ACE_DELETE) 3147a7746f66Stz204579 permstr[4] = 'd'; 3148a7746f66Stz204579 if (ace->a_access_mask & ACE_DELETE_CHILD) 3149a7746f66Stz204579 permstr[5] = 'D'; 3150a7746f66Stz204579 if (ace->a_access_mask & ACE_READ_ATTRIBUTES) 3151a7746f66Stz204579 permstr[6] = 'a'; 3152a7746f66Stz204579 if (ace->a_access_mask & ACE_WRITE_ATTRIBUTES) 3153a7746f66Stz204579 permstr[7] = 'A'; 3154a7746f66Stz204579 if (ace->a_access_mask & ACE_READ_NAMED_ATTRS) 3155a7746f66Stz204579 permstr[8] = 'R'; 3156a7746f66Stz204579 if (ace->a_access_mask & ACE_WRITE_NAMED_ATTRS) 3157a7746f66Stz204579 permstr[9] = 'W'; 3158a7746f66Stz204579 if (ace->a_access_mask & ACE_READ_ACL) 3159a7746f66Stz204579 permstr[10] = 'c'; 3160a7746f66Stz204579 if (ace->a_access_mask & ACE_WRITE_ACL) 3161a7746f66Stz204579 permstr[11] = 'C'; 3162a7746f66Stz204579 if (ace->a_access_mask & ACE_WRITE_OWNER) 3163a7746f66Stz204579 permstr[12] = 'o'; 3164a7746f66Stz204579 if (ace->a_access_mask & ACE_SYNCHRONIZE) 3165a7746f66Stz204579 permstr[13] = 's'; 3166a7746f66Stz204579 permstr[14] = '\0'; 3167a7746f66Stz204579 uval.uvaltype = PRA_STRING; 3168a7746f66Stz204579 uval.string_val = permstr; 3169a7746f66Stz204579 } else if (!(context->format & PRF_RAWM)) { 3170a7746f66Stz204579 3171a7746f66Stz204579 /* 3172a7746f66Stz204579 * Note this differs from acltext.c:ace_perm_txt() 3173a7746f66Stz204579 * because we don't know if the acl belongs to a file 3174a7746f66Stz204579 * or directory. ace mask value are the same 3175a7746f66Stz204579 * nonetheless, see sys/acl.h 3176a7746f66Stz204579 */ 3177a7746f66Stz204579 if (ace->a_access_mask & ACE_LIST_DIRECTORY) { 3178a7746f66Stz204579 returnstat = strappend(&permstr, gettext(READ_DIR_TXT), 3179a7746f66Stz204579 &permstr_alloc); 3180a7746f66Stz204579 } 3181a7746f66Stz204579 if (ace->a_access_mask & ACE_ADD_FILE) { 3182a7746f66Stz204579 returnstat = strappend(&permstr, gettext(ADD_FILE_TXT), 3183a7746f66Stz204579 &permstr_alloc); 3184a7746f66Stz204579 } 3185a7746f66Stz204579 if (ace->a_access_mask & ACE_ADD_SUBDIRECTORY) { 3186a7746f66Stz204579 returnstat = strappend(&permstr, gettext(ADD_DIR_TXT), 3187a7746f66Stz204579 &permstr_alloc); 3188a7746f66Stz204579 } 3189a7746f66Stz204579 if (ace->a_access_mask & ACE_READ_NAMED_ATTRS) { 3190a7746f66Stz204579 returnstat = strappend(&permstr, 3191a7746f66Stz204579 gettext(READ_XATTR_TXT), &permstr_alloc); 3192a7746f66Stz204579 } 3193a7746f66Stz204579 if (ace->a_access_mask & ACE_WRITE_NAMED_ATTRS) { 3194a7746f66Stz204579 returnstat = strappend(&permstr, 3195a7746f66Stz204579 gettext(WRITE_XATTR_TXT), &permstr_alloc); 3196a7746f66Stz204579 } 3197a7746f66Stz204579 if (ace->a_access_mask & ACE_EXECUTE) { 3198a7746f66Stz204579 returnstat = strappend(&permstr, 3199a7746f66Stz204579 gettext(EXECUTE_TXT), &permstr_alloc); 3200a7746f66Stz204579 } 3201a7746f66Stz204579 if (ace->a_access_mask & ACE_DELETE_CHILD) { 3202a7746f66Stz204579 returnstat = strappend(&permstr, 3203a7746f66Stz204579 gettext(DELETE_CHILD_TXT), &permstr_alloc); 3204a7746f66Stz204579 } 3205a7746f66Stz204579 if (ace->a_access_mask & ACE_READ_ATTRIBUTES) { 3206a7746f66Stz204579 returnstat = strappend(&permstr, 3207a7746f66Stz204579 gettext(READ_ATTRIBUTES_TXT), &permstr_alloc); 3208a7746f66Stz204579 } 3209a7746f66Stz204579 if (ace->a_access_mask & ACE_WRITE_ATTRIBUTES) { 3210a7746f66Stz204579 returnstat = strappend(&permstr, 3211a7746f66Stz204579 gettext(WRITE_ATTRIBUTES_TXT), &permstr_alloc); 3212a7746f66Stz204579 } 3213a7746f66Stz204579 if (ace->a_access_mask & ACE_DELETE) { 3214a7746f66Stz204579 returnstat = strappend(&permstr, gettext(DELETE_TXT), 3215a7746f66Stz204579 &permstr_alloc); 3216a7746f66Stz204579 } 3217a7746f66Stz204579 if (ace->a_access_mask & ACE_READ_ACL) { 3218a7746f66Stz204579 returnstat = strappend(&permstr, gettext(READ_ACL_TXT), 3219a7746f66Stz204579 &permstr_alloc); 3220a7746f66Stz204579 } 3221a7746f66Stz204579 if (ace->a_access_mask & ACE_WRITE_ACL) { 3222a7746f66Stz204579 returnstat = strappend(&permstr, gettext(WRITE_ACL_TXT), 3223a7746f66Stz204579 &permstr_alloc); 3224a7746f66Stz204579 } 3225a7746f66Stz204579 if (ace->a_access_mask & ACE_WRITE_OWNER) { 3226a7746f66Stz204579 returnstat = strappend(&permstr, 3227a7746f66Stz204579 gettext(WRITE_OWNER_TXT), &permstr_alloc); 3228a7746f66Stz204579 } 3229a7746f66Stz204579 if (ace->a_access_mask & ACE_SYNCHRONIZE) { 3230a7746f66Stz204579 returnstat = strappend(&permstr, 3231a7746f66Stz204579 gettext(SYNCHRONIZE_TXT), &permstr_alloc); 3232a7746f66Stz204579 } 3233a7746f66Stz204579 if (permstr[strlen(permstr) - 1] == '/') 3234a7746f66Stz204579 permstr[strlen(permstr) - 1] = '\0'; 3235a7746f66Stz204579 uval.uvaltype = PRA_STRING; 3236a7746f66Stz204579 uval.string_val = permstr; 3237a7746f66Stz204579 } 3238a7746f66Stz204579 if ((permstr == NULL) || (returnstat != 0) || 3239a7746f66Stz204579 (context->format & PRF_RAWM)) { 3240a7746f66Stz204579 uval.uvaltype = PRA_UINT32; 3241a7746f66Stz204579 uval.uint32_val = ace->a_access_mask; 3242a7746f66Stz204579 } 3243a7746f66Stz204579 returnstat = pa_print(context, &uval, flag); 3244a7746f66Stz204579 3245a7746f66Stz204579 if (permstr != NULL) 3246a7746f66Stz204579 free(permstr); 3247a7746f66Stz204579 if (returnstat != 0) 3248a7746f66Stz204579 return (returnstat); 3249a7746f66Stz204579 return (close_tag(context, TAG_ACEMASK)); 3250a7746f66Stz204579 } 3251a7746f66Stz204579 3252a7746f66Stz204579 static int 3253a7746f66Stz204579 pa_ace_type(pr_context_t *context, ace_t *ace, int status, int flag) 3254a7746f66Stz204579 { 3255a7746f66Stz204579 int returnstat; 3256a7746f66Stz204579 uval_t uval; 3257a7746f66Stz204579 3258a7746f66Stz204579 if (status < 0) 3259a7746f66Stz204579 return (status); 3260a7746f66Stz204579 3261a7746f66Stz204579 /* 3262a7746f66Stz204579 * TRANSLATION_NOTE 3263a7746f66Stz204579 * ace->a_type refers to access type of ZFS/NFSv4 ACL entry. 3264a7746f66Stz204579 */ 3265a7746f66Stz204579 if ((returnstat = open_tag(context, TAG_ACETYPE)) != 0) 3266a7746f66Stz204579 return (returnstat); 3267a7746f66Stz204579 if (!(context->format & PRF_RAWM)) { 3268a7746f66Stz204579 uval.uvaltype = PRA_STRING; 3269a7746f66Stz204579 switch (ace->a_type) { 3270a7746f66Stz204579 case ACE_ACCESS_ALLOWED_ACE_TYPE: 3271a7746f66Stz204579 uval.string_val = gettext(ALLOW_TXT); 3272a7746f66Stz204579 break; 3273a7746f66Stz204579 case ACE_ACCESS_DENIED_ACE_TYPE: 3274a7746f66Stz204579 uval.string_val = gettext(DENY_TXT); 3275a7746f66Stz204579 break; 3276a7746f66Stz204579 case ACE_SYSTEM_AUDIT_ACE_TYPE: 3277a7746f66Stz204579 uval.string_val = gettext(AUDIT_TXT); 3278a7746f66Stz204579 break; 3279a7746f66Stz204579 case ACE_SYSTEM_ALARM_ACE_TYPE: 3280a7746f66Stz204579 uval.string_val = gettext(ALARM_TXT); 3281a7746f66Stz204579 break; 3282a7746f66Stz204579 default: 3283a7746f66Stz204579 uval.string_val = gettext(UNKNOWN_TXT); 3284a7746f66Stz204579 } 3285a7746f66Stz204579 } else { 3286a7746f66Stz204579 uval.uvaltype = PRA_USHORT; 3287a7746f66Stz204579 uval.uint32_val = ace->a_type; 3288a7746f66Stz204579 } 3289a7746f66Stz204579 if ((returnstat = pa_print(context, &uval, flag)) != 0) 3290a7746f66Stz204579 return (returnstat); 3291a7746f66Stz204579 return (close_tag(context, TAG_ACETYPE)); 3292a7746f66Stz204579 } 3293a7746f66Stz204579 3294a7746f66Stz204579 int 3295a7746f66Stz204579 pa_ace(pr_context_t *context, int status, int flag) 3296a7746f66Stz204579 { 3297a7746f66Stz204579 int returnstat; 3298a7746f66Stz204579 ace_t ace; 3299a7746f66Stz204579 3300a7746f66Stz204579 if (status < 0) 3301a7746f66Stz204579 return (status); 3302a7746f66Stz204579 3303a7746f66Stz204579 if ((returnstat = pr_adr_u_int32(context, &ace.a_who, 1)) != 0) 3304a7746f66Stz204579 return (returnstat); 3305a7746f66Stz204579 if ((returnstat = pr_adr_u_int32(context, &ace.a_access_mask, 1)) != 0) 3306a7746f66Stz204579 return (returnstat); 3307a7746f66Stz204579 if ((returnstat = pr_adr_u_short(context, &ace.a_flags, 1)) != 0) 3308a7746f66Stz204579 return (returnstat); 3309a7746f66Stz204579 if ((returnstat = pr_adr_u_short(context, &ace.a_type, 1)) != 0) 3310a7746f66Stz204579 return (returnstat); 3311a7746f66Stz204579 3312a7746f66Stz204579 if ((returnstat = pa_ace_flags(context, &ace, returnstat, 0)) != 0) 3313a7746f66Stz204579 return (returnstat); 3314a7746f66Stz204579 /* pa_ace_who can returns 1 if uid/gid is not found */ 3315a7746f66Stz204579 if ((returnstat = pa_ace_who(context, &ace, returnstat, 0)) < 0) 3316a7746f66Stz204579 return (returnstat); 3317a7746f66Stz204579 if ((returnstat = pa_ace_access_mask(context, &ace, 3318a7746f66Stz204579 returnstat, 0)) != 0) 3319a7746f66Stz204579 return (returnstat); 3320a7746f66Stz204579 return (pa_ace_type(context, &ace, returnstat, flag)); 3321a7746f66Stz204579 } 3322