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 */
21*8bb3e7e3SPeter Tribble /*
22*8bb3e7e3SPeter Tribble * Copyright (c) 2019 Peter Tribble.
23*8bb3e7e3SPeter Tribble */
247c478bd9Sstevel@tonic-gate /*
253929e195SMarek Pospisil * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
267c478bd9Sstevel@tonic-gate * Use is subject to license terms.
277c478bd9Sstevel@tonic-gate */
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate #define _REENTRANT
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate #include <ctype.h>
337c478bd9Sstevel@tonic-gate #include <errno.h>
347c478bd9Sstevel@tonic-gate #include <grp.h>
357c478bd9Sstevel@tonic-gate #include <libintl.h>
367c478bd9Sstevel@tonic-gate #include <netdb.h>
377c478bd9Sstevel@tonic-gate #include <time.h>
387c478bd9Sstevel@tonic-gate #include <pwd.h>
397c478bd9Sstevel@tonic-gate #include <stdio.h>
407c478bd9Sstevel@tonic-gate #include <stdlib.h>
417c478bd9Sstevel@tonic-gate #include <string.h>
427c478bd9Sstevel@tonic-gate #include <wchar.h>
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate #include <arpa/inet.h>
457c478bd9Sstevel@tonic-gate
467c478bd9Sstevel@tonic-gate #include <bsm/audit.h>
477c478bd9Sstevel@tonic-gate #include <bsm/audit_record.h>
487c478bd9Sstevel@tonic-gate #include <bsm/libbsm.h>
497c478bd9Sstevel@tonic-gate #include <security/pam_appl.h>
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate #include <sys/inttypes.h>
527c478bd9Sstevel@tonic-gate #include <sys/mkdev.h>
537c478bd9Sstevel@tonic-gate #include <sys/types.h>
54a7746f66Stz #include <aclutils.h>
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate #include "praudit.h"
577c478bd9Sstevel@tonic-gate #include "toktable.h"
587c478bd9Sstevel@tonic-gate #include "adt_xlate.h"
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate static void convertascii(char *p, char *c, int size);
617c478bd9Sstevel@tonic-gate static int convertbinary(char *p, char *c, int size);
62d0fa49b7STony Nguyen static void eventmodifier2string(au_emod_t emodifier, char *modstring,
637c478bd9Sstevel@tonic-gate size_t modlen);
647c478bd9Sstevel@tonic-gate static int do_mtime32(pr_context_t *context, int status, int flag,
657c478bd9Sstevel@tonic-gate uint32_t scale);
667c478bd9Sstevel@tonic-gate static int do_mtime64(pr_context_t *context, int status, int flag,
677c478bd9Sstevel@tonic-gate uint64_t scale);
687c478bd9Sstevel@tonic-gate
6999591362SPeter Tribble /*
7099591362SPeter Tribble * for uid/gid caches
7199591362SPeter Tribble */
7299591362SPeter Tribble static uid_t lastuid = (uid_t)-1;
7399591362SPeter Tribble static gid_t lastgid = (gid_t)-1;
7499591362SPeter Tribble static char *lastuname = NULL;
7599591362SPeter Tribble static char *lastgname = NULL;
7699591362SPeter Tribble static char *getname(uid_t);
7799591362SPeter Tribble static char *getgroup(gid_t);
7899591362SPeter Tribble static struct cachenode *findincache(struct cachenode **, long);
7999591362SPeter Tribble #include <utmpx.h>
8099591362SPeter Tribble
8199591362SPeter Tribble struct utmpx utmp;
8299591362SPeter Tribble
8399591362SPeter Tribble #define NMAX (sizeof (utmp.ut_name))
8499591362SPeter Tribble #define SCPYN(a, b) (void) strncpy(a, b, NMAX)
8599591362SPeter Tribble
8699591362SPeter Tribble struct cachenode { /* this struct must be zeroed before using */
8799591362SPeter Tribble struct cachenode *lesschild; /* subtree whose entries < val */
8899591362SPeter Tribble struct cachenode *grtrchild; /* subtree whose entries > val */
8999591362SPeter Tribble long val; /* the uid or gid of this entry */
9099591362SPeter Tribble int initted; /* name has been filled in */
9199591362SPeter Tribble char name[NMAX+1]; /* the string that val maps to */
9299591362SPeter Tribble };
9399591362SPeter Tribble static struct cachenode *names, *groups;
9499591362SPeter Tribble
9599591362SPeter Tribble static struct cachenode *
findincache(struct cachenode ** head,long val)9699591362SPeter Tribble findincache(struct cachenode **head, long val)
9799591362SPeter Tribble {
9899591362SPeter Tribble struct cachenode **parent = head;
9999591362SPeter Tribble struct cachenode *c = *parent;
10099591362SPeter Tribble
10199591362SPeter Tribble while (c != NULL) {
10299591362SPeter Tribble if (val == c->val) {
10399591362SPeter Tribble /* found it */
10499591362SPeter Tribble return (c);
10599591362SPeter Tribble } else if (val < c->val) {
10699591362SPeter Tribble parent = &c->lesschild;
10799591362SPeter Tribble c = c->lesschild;
10899591362SPeter Tribble } else {
10999591362SPeter Tribble parent = &c->grtrchild;
11099591362SPeter Tribble c = c->grtrchild;
11199591362SPeter Tribble }
11299591362SPeter Tribble }
11399591362SPeter Tribble
11499591362SPeter Tribble /* not in the cache, make a new entry for it */
11599591362SPeter Tribble c = calloc(1, sizeof (struct cachenode));
11699591362SPeter Tribble if (c == NULL) {
11799591362SPeter Tribble perror("praudit");
11899591362SPeter Tribble exit(2);
11999591362SPeter Tribble }
12099591362SPeter Tribble *parent = c;
12199591362SPeter Tribble c->val = val;
12299591362SPeter Tribble return (c);
12399591362SPeter Tribble }
12499591362SPeter Tribble
12599591362SPeter Tribble /*
12699591362SPeter Tribble * get name from cache, or passwd file for a given uid;
12799591362SPeter Tribble * lastuid is set to uid.
12899591362SPeter Tribble */
12999591362SPeter Tribble static char *
getname(uid_t uid)13099591362SPeter Tribble getname(uid_t uid)
13199591362SPeter Tribble {
13299591362SPeter Tribble struct passwd *pwent;
13399591362SPeter Tribble struct cachenode *c;
13499591362SPeter Tribble
13599591362SPeter Tribble if ((uid == lastuid) && lastuname)
13699591362SPeter Tribble return (lastuname);
13799591362SPeter Tribble
13899591362SPeter Tribble c = findincache(&names, uid);
13999591362SPeter Tribble if (c->initted == 0) {
14099591362SPeter Tribble if ((pwent = getpwuid(uid)) != NULL) {
14199591362SPeter Tribble SCPYN(&c->name[0], pwent->pw_name);
14299591362SPeter Tribble } else {
14399591362SPeter Tribble (void) sprintf(&c->name[0], "%u", (int)uid);
14499591362SPeter Tribble }
14599591362SPeter Tribble c->initted = 1;
14699591362SPeter Tribble }
14799591362SPeter Tribble lastuid = uid;
14899591362SPeter Tribble lastuname = &c->name[0];
14999591362SPeter Tribble return (lastuname);
15099591362SPeter Tribble }
15199591362SPeter Tribble
15299591362SPeter Tribble /*
15399591362SPeter Tribble * get name from cache, or group file for a given gid;
15499591362SPeter Tribble * lastgid is set to gid.
15599591362SPeter Tribble */
15699591362SPeter Tribble static char *
getgroup(gid_t gid)15799591362SPeter Tribble getgroup(gid_t gid)
15899591362SPeter Tribble {
15999591362SPeter Tribble struct group *grent;
16099591362SPeter Tribble struct cachenode *c;
16199591362SPeter Tribble
16299591362SPeter Tribble if ((gid == lastgid) && lastgname)
16399591362SPeter Tribble return (lastgname);
16499591362SPeter Tribble
16599591362SPeter Tribble c = findincache(&groups, gid);
16699591362SPeter Tribble if (c->initted == 0) {
16799591362SPeter Tribble if ((grent = getgrgid(gid)) != NULL) {
16899591362SPeter Tribble SCPYN(&c->name[0], grent->gr_name);
16999591362SPeter Tribble } else {
17099591362SPeter Tribble (void) sprintf(&c->name[0], "%u", (int)gid);
17199591362SPeter Tribble }
17299591362SPeter Tribble c->initted = 1;
17399591362SPeter Tribble }
17499591362SPeter Tribble lastgid = gid;
17599591362SPeter Tribble lastgname = &c->name[0];
17699591362SPeter Tribble return (lastgname);
17799591362SPeter Tribble }
17899591362SPeter Tribble
179*8bb3e7e3SPeter Tribble /*
180*8bb3e7e3SPeter Tribble * populate name cache from given file
181*8bb3e7e3SPeter Tribble * caller is responsible for opening and closing the file
182*8bb3e7e3SPeter Tribble */
183*8bb3e7e3SPeter Tribble void
loadnames(FILE * pf)184*8bb3e7e3SPeter Tribble loadnames(FILE *pf)
185*8bb3e7e3SPeter Tribble {
186*8bb3e7e3SPeter Tribble struct passwd *pwent;
187*8bb3e7e3SPeter Tribble struct cachenode *c;
188*8bb3e7e3SPeter Tribble
189*8bb3e7e3SPeter Tribble while ((pwent = fgetpwent(pf)) != NULL) {
190*8bb3e7e3SPeter Tribble c = findincache(&names, pwent->pw_uid);
191*8bb3e7e3SPeter Tribble if (c->initted == 0) {
192*8bb3e7e3SPeter Tribble SCPYN(&c->name[0], pwent->pw_name);
193*8bb3e7e3SPeter Tribble c->initted = 1;
194*8bb3e7e3SPeter Tribble }
195*8bb3e7e3SPeter Tribble }
196*8bb3e7e3SPeter Tribble }
197*8bb3e7e3SPeter Tribble
198*8bb3e7e3SPeter Tribble /*
199*8bb3e7e3SPeter Tribble * populate group cache from given file
200*8bb3e7e3SPeter Tribble * caller is responsible for opening and closing the file
201*8bb3e7e3SPeter Tribble */
202*8bb3e7e3SPeter Tribble void
loadgroups(FILE * gf)203*8bb3e7e3SPeter Tribble loadgroups(FILE *gf)
204*8bb3e7e3SPeter Tribble {
205*8bb3e7e3SPeter Tribble struct group *grent;
206*8bb3e7e3SPeter Tribble struct cachenode *c;
207*8bb3e7e3SPeter Tribble
208*8bb3e7e3SPeter Tribble while ((grent = fgetgrent(gf)) != NULL) {
209*8bb3e7e3SPeter Tribble c = findincache(&groups, grent->gr_gid);
210*8bb3e7e3SPeter Tribble if (c->initted == 0) {
211*8bb3e7e3SPeter Tribble SCPYN(&c->name[0], grent->gr_name);
212*8bb3e7e3SPeter Tribble c->initted = 1;
213*8bb3e7e3SPeter Tribble }
214*8bb3e7e3SPeter Tribble }
215*8bb3e7e3SPeter Tribble }
216*8bb3e7e3SPeter Tribble
2177c478bd9Sstevel@tonic-gate /*
2187c478bd9Sstevel@tonic-gate * ------------------------------------------------------
2197c478bd9Sstevel@tonic-gate * field widths for arbitrary data token type
2207c478bd9Sstevel@tonic-gate * ------------------------------------------------------
2217c478bd9Sstevel@tonic-gate */
2227c478bd9Sstevel@tonic-gate static struct fw {
2237c478bd9Sstevel@tonic-gate char basic_unit;
2247c478bd9Sstevel@tonic-gate struct {
2257c478bd9Sstevel@tonic-gate char print_base;
2267c478bd9Sstevel@tonic-gate int field_width;
2277c478bd9Sstevel@tonic-gate } pwidth[5];
2287c478bd9Sstevel@tonic-gate } fwidth[] = {
2297c478bd9Sstevel@tonic-gate /* character data type, 8 bits */
2307c478bd9Sstevel@tonic-gate AUR_CHAR, AUP_BINARY, 12,
2317c478bd9Sstevel@tonic-gate AUP_OCTAL, 6,
2327c478bd9Sstevel@tonic-gate AUP_DECIMAL, 6,
2337c478bd9Sstevel@tonic-gate AUP_HEX, 6,
2348dc347dbStz AUP_STRING, 1,
2357c478bd9Sstevel@tonic-gate AUR_BYTE, AUP_BINARY, 12,
2367c478bd9Sstevel@tonic-gate AUP_OCTAL, 6,
2377c478bd9Sstevel@tonic-gate AUP_DECIMAL, 6,
2387c478bd9Sstevel@tonic-gate AUP_HEX, 6,
2398dc347dbStz AUP_STRING, 1,
2407c478bd9Sstevel@tonic-gate AUR_SHORT, AUP_BINARY, 20,
2417c478bd9Sstevel@tonic-gate AUP_OCTAL, 10,
2427c478bd9Sstevel@tonic-gate AUP_DECIMAL, 10,
2437c478bd9Sstevel@tonic-gate AUP_HEX, 8,
2447c478bd9Sstevel@tonic-gate AUP_STRING, 6,
2457c478bd9Sstevel@tonic-gate AUR_INT32, AUP_BINARY, 36,
2467c478bd9Sstevel@tonic-gate AUP_OCTAL, 18,
2477c478bd9Sstevel@tonic-gate AUP_DECIMAL, 18,
2487c478bd9Sstevel@tonic-gate AUP_HEX, 12,
2497c478bd9Sstevel@tonic-gate AUP_STRING, 10,
2507c478bd9Sstevel@tonic-gate AUR_INT64, AUP_BINARY, 68,
2517c478bd9Sstevel@tonic-gate AUP_OCTAL, 34,
2527c478bd9Sstevel@tonic-gate AUP_DECIMAL, 34,
2537c478bd9Sstevel@tonic-gate AUP_HEX, 20,
2547c478bd9Sstevel@tonic-gate AUP_STRING, 20};
2557c478bd9Sstevel@tonic-gate
2567c478bd9Sstevel@tonic-gate
2577c478bd9Sstevel@tonic-gate static int numwidthentries = sizeof (fwidth)
2587c478bd9Sstevel@tonic-gate / sizeof (struct fw);
2597c478bd9Sstevel@tonic-gate
2607c478bd9Sstevel@tonic-gate
2617c478bd9Sstevel@tonic-gate /*
2627c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
2637c478bd9Sstevel@tonic-gate * do_newline:
2647c478bd9Sstevel@tonic-gate * Print a newline, if needed according to various formatting
2657c478bd9Sstevel@tonic-gate * rules.
2667c478bd9Sstevel@tonic-gate * return codes : 0 - success
2677c478bd9Sstevel@tonic-gate * : -1 - error
2687c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
2697c478bd9Sstevel@tonic-gate */
2707c478bd9Sstevel@tonic-gate int
do_newline(pr_context_t * context,int flag)2717c478bd9Sstevel@tonic-gate do_newline(pr_context_t *context, int flag)
2727c478bd9Sstevel@tonic-gate {
2737c478bd9Sstevel@tonic-gate int retstat = 0;
2747c478bd9Sstevel@tonic-gate
2757c478bd9Sstevel@tonic-gate if (!(context->format & PRF_ONELINE) && (flag == 1))
2767c478bd9Sstevel@tonic-gate retstat = pr_putchar(context, '\n');
2777c478bd9Sstevel@tonic-gate else if (!(context->format & PRF_XMLM))
2787c478bd9Sstevel@tonic-gate retstat = pr_printf(context, "%s", context->SEPARATOR);
2797c478bd9Sstevel@tonic-gate
2807c478bd9Sstevel@tonic-gate return (retstat);
2817c478bd9Sstevel@tonic-gate }
2827c478bd9Sstevel@tonic-gate
2837c478bd9Sstevel@tonic-gate int
open_tag(pr_context_t * context,int tagnum)2847c478bd9Sstevel@tonic-gate open_tag(pr_context_t *context, int tagnum)
2857c478bd9Sstevel@tonic-gate {
2867c478bd9Sstevel@tonic-gate int err = 0;
2877c478bd9Sstevel@tonic-gate token_desc_t *tag;
2887c478bd9Sstevel@tonic-gate
2897c478bd9Sstevel@tonic-gate /* no-op if not doing XML format */
2907c478bd9Sstevel@tonic-gate if (!(context->format & PRF_XMLM))
2917c478bd9Sstevel@tonic-gate return (0);
2927c478bd9Sstevel@tonic-gate
2937c478bd9Sstevel@tonic-gate tag = &tokentable[tagnum];
2947c478bd9Sstevel@tonic-gate
2957c478bd9Sstevel@tonic-gate /*
2967c478bd9Sstevel@tonic-gate * First if needed do an implicit finish of a pending open for an
2977c478bd9Sstevel@tonic-gate * extended tag. I.e., for the extended tag xxx:
2987c478bd9Sstevel@tonic-gate * <xxx a=".." b=".."> ... </xxx>
2997c478bd9Sstevel@tonic-gate * -- insert a close bracket after the last attribute
3007c478bd9Sstevel@tonic-gate * (in other words, when the 1st non-attribute is opened while
3017c478bd9Sstevel@tonic-gate * this is pending). Note that only one tag could be pending at
3027c478bd9Sstevel@tonic-gate * a given time -- it couldn't be nested.
3037c478bd9Sstevel@tonic-gate */
3047c478bd9Sstevel@tonic-gate if (context->pending_flag && (tag->t_type != T_ATTRIBUTE)) {
3057c478bd9Sstevel@tonic-gate /* complete pending extended open */
3067c478bd9Sstevel@tonic-gate err = pr_putchar(context, '>');
3077c478bd9Sstevel@tonic-gate if (err != 0)
3087c478bd9Sstevel@tonic-gate return (err);
3097c478bd9Sstevel@tonic-gate context->pending_flag = 0;
3107c478bd9Sstevel@tonic-gate }
3117c478bd9Sstevel@tonic-gate
3127c478bd9Sstevel@tonic-gate if (is_header_token(tagnum) || is_file_token(tagnum)) {
3137c478bd9Sstevel@tonic-gate /* File token or new record on new line */
3147c478bd9Sstevel@tonic-gate err = pr_putchar(context, '\n');
3157c478bd9Sstevel@tonic-gate } else if (is_token(tagnum)) {
3167c478bd9Sstevel@tonic-gate /* Each token on new line if possible */
3177c478bd9Sstevel@tonic-gate err = do_newline(context, 1);
3187c478bd9Sstevel@tonic-gate }
3197c478bd9Sstevel@tonic-gate if (err != 0)
3207c478bd9Sstevel@tonic-gate return (err);
3217c478bd9Sstevel@tonic-gate
3227c478bd9Sstevel@tonic-gate switch (tag->t_type) {
3237c478bd9Sstevel@tonic-gate case T_ATTRIBUTE:
3247c478bd9Sstevel@tonic-gate err = pr_printf(context, " %s=\"", tag->t_tagname);
3257c478bd9Sstevel@tonic-gate break;
3267c478bd9Sstevel@tonic-gate case T_ELEMENT:
3277c478bd9Sstevel@tonic-gate err = pr_printf(context, "<%s>", tag->t_tagname);
3287c478bd9Sstevel@tonic-gate break;
3297c478bd9Sstevel@tonic-gate case T_ENCLOSED:
3307c478bd9Sstevel@tonic-gate err = pr_printf(context, "<%s", tag->t_tagname);
3317c478bd9Sstevel@tonic-gate break;
3327c478bd9Sstevel@tonic-gate case T_EXTENDED:
3337c478bd9Sstevel@tonic-gate err = pr_printf(context, "<%s", tag->t_tagname);
3347c478bd9Sstevel@tonic-gate if (err == 0)
3357c478bd9Sstevel@tonic-gate context->pending_flag = tagnum;
3367c478bd9Sstevel@tonic-gate break;
3377c478bd9Sstevel@tonic-gate default:
3387c478bd9Sstevel@tonic-gate break;
3397c478bd9Sstevel@tonic-gate }
3407c478bd9Sstevel@tonic-gate
3417c478bd9Sstevel@tonic-gate if (is_header_token(tagnum) && (err == 0))
3427c478bd9Sstevel@tonic-gate context->current_rec = tagnum; /* set start of new record */
3437c478bd9Sstevel@tonic-gate
3447c478bd9Sstevel@tonic-gate return (err);
3457c478bd9Sstevel@tonic-gate }
3467c478bd9Sstevel@tonic-gate
3477c478bd9Sstevel@tonic-gate /*
3487c478bd9Sstevel@tonic-gate * Do an implicit close of a record when needed.
3497c478bd9Sstevel@tonic-gate */
3507c478bd9Sstevel@tonic-gate int
check_close_rec(pr_context_t * context,int tagnum)3517c478bd9Sstevel@tonic-gate check_close_rec(pr_context_t *context, int tagnum)
3527c478bd9Sstevel@tonic-gate {
3537c478bd9Sstevel@tonic-gate int err = 0;
3547c478bd9Sstevel@tonic-gate
3557c478bd9Sstevel@tonic-gate /* no-op if not doing XML format */
3567c478bd9Sstevel@tonic-gate if (!(context->format & PRF_XMLM))
3577c478bd9Sstevel@tonic-gate return (0);
3587c478bd9Sstevel@tonic-gate
3597c478bd9Sstevel@tonic-gate /*
3607c478bd9Sstevel@tonic-gate * If we're opening a header or the file token (i.e., starting a new
3617c478bd9Sstevel@tonic-gate * record), if there's a current record in progress do an implicit
3627c478bd9Sstevel@tonic-gate * close of it.
3637c478bd9Sstevel@tonic-gate */
3647c478bd9Sstevel@tonic-gate if ((is_header_token(tagnum) || is_file_token(tagnum)) &&
3657c478bd9Sstevel@tonic-gate context->current_rec) {
3667c478bd9Sstevel@tonic-gate err = do_newline(context, 1);
3677c478bd9Sstevel@tonic-gate if (err == 0)
3687c478bd9Sstevel@tonic-gate err = close_tag(context, context->current_rec);
3697c478bd9Sstevel@tonic-gate }
3707c478bd9Sstevel@tonic-gate
3717c478bd9Sstevel@tonic-gate return (err);
3727c478bd9Sstevel@tonic-gate }
3737c478bd9Sstevel@tonic-gate
3747c478bd9Sstevel@tonic-gate /*
3757c478bd9Sstevel@tonic-gate * explicit finish of a pending open for an extended tag.
3767c478bd9Sstevel@tonic-gate */
3777c478bd9Sstevel@tonic-gate int
finish_open_tag(pr_context_t * context)3787c478bd9Sstevel@tonic-gate finish_open_tag(pr_context_t *context)
3797c478bd9Sstevel@tonic-gate {
3807c478bd9Sstevel@tonic-gate int err = 0;
3817c478bd9Sstevel@tonic-gate
3827c478bd9Sstevel@tonic-gate /* no-op if not doing XML format */
3837c478bd9Sstevel@tonic-gate if (!(context->format & PRF_XMLM))
3847c478bd9Sstevel@tonic-gate return (0);
3857c478bd9Sstevel@tonic-gate
3867c478bd9Sstevel@tonic-gate if (context->pending_flag) {
3877c478bd9Sstevel@tonic-gate /* complete pending extended open */
3887c478bd9Sstevel@tonic-gate err = pr_putchar(context, '>');
3897c478bd9Sstevel@tonic-gate if (err == 0)
3907c478bd9Sstevel@tonic-gate context->pending_flag = 0;
3917c478bd9Sstevel@tonic-gate }
3927c478bd9Sstevel@tonic-gate return (err);
3937c478bd9Sstevel@tonic-gate }
3947c478bd9Sstevel@tonic-gate
3957c478bd9Sstevel@tonic-gate int
close_tag(pr_context_t * context,int tagnum)3967c478bd9Sstevel@tonic-gate close_tag(pr_context_t *context, int tagnum)
3977c478bd9Sstevel@tonic-gate {
3987c478bd9Sstevel@tonic-gate int err = 0;
3997c478bd9Sstevel@tonic-gate token_desc_t *tag;
4007c478bd9Sstevel@tonic-gate
4017c478bd9Sstevel@tonic-gate /* no-op if not doing XML format */
4027c478bd9Sstevel@tonic-gate if (!(context->format & PRF_XMLM))
4037c478bd9Sstevel@tonic-gate return (0);
4047c478bd9Sstevel@tonic-gate
4057c478bd9Sstevel@tonic-gate tag = &tokentable[tagnum];
4067c478bd9Sstevel@tonic-gate
4077c478bd9Sstevel@tonic-gate switch (tag->t_type) {
4087c478bd9Sstevel@tonic-gate case T_ATTRIBUTE:
4097c478bd9Sstevel@tonic-gate err = pr_putchar(context, '\"');
4107c478bd9Sstevel@tonic-gate break;
4117c478bd9Sstevel@tonic-gate case T_ELEMENT:
4127c478bd9Sstevel@tonic-gate err = pr_printf(context, "</%s>", tag->t_tagname);
4137c478bd9Sstevel@tonic-gate break;
4147c478bd9Sstevel@tonic-gate case T_ENCLOSED:
4157c478bd9Sstevel@tonic-gate err = pr_printf(context, "/>");
4167c478bd9Sstevel@tonic-gate break;
4177c478bd9Sstevel@tonic-gate case T_EXTENDED:
4187c478bd9Sstevel@tonic-gate err = pr_printf(context, "</%s>", tag->t_tagname);
4197c478bd9Sstevel@tonic-gate break;
4207c478bd9Sstevel@tonic-gate default:
4217c478bd9Sstevel@tonic-gate break;
4227c478bd9Sstevel@tonic-gate }
4237c478bd9Sstevel@tonic-gate
4247c478bd9Sstevel@tonic-gate if (is_header_token(tagnum) && (err == 0))
4257c478bd9Sstevel@tonic-gate context->current_rec = 0; /* closing rec; none current */
4267c478bd9Sstevel@tonic-gate
4277c478bd9Sstevel@tonic-gate return (err);
4287c478bd9Sstevel@tonic-gate }
4297c478bd9Sstevel@tonic-gate
4307c478bd9Sstevel@tonic-gate /*
4317c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
4327c478bd9Sstevel@tonic-gate * process_tag:
4337c478bd9Sstevel@tonic-gate * Calls the routine corresponding to the tag
4347c478bd9Sstevel@tonic-gate * Note that to use this mechanism, all such routines must
4357c478bd9Sstevel@tonic-gate * take 2 ints for their parameters; the first of these is
4367c478bd9Sstevel@tonic-gate * the current status.
4377c478bd9Sstevel@tonic-gate *
4387c478bd9Sstevel@tonic-gate * flag = 1 for newline / delimiter, else 0
4397c478bd9Sstevel@tonic-gate * return codes : -1 - error
4407c478bd9Sstevel@tonic-gate * : 0 - successful
4417c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
4427c478bd9Sstevel@tonic-gate */
4437c478bd9Sstevel@tonic-gate int
process_tag(pr_context_t * context,int tagnum,int status,int flag)4447c478bd9Sstevel@tonic-gate process_tag(pr_context_t *context, int tagnum, int status, int flag)
4457c478bd9Sstevel@tonic-gate {
4467c478bd9Sstevel@tonic-gate int retstat;
4477c478bd9Sstevel@tonic-gate
4487c478bd9Sstevel@tonic-gate retstat = status;
4497c478bd9Sstevel@tonic-gate
4507c478bd9Sstevel@tonic-gate if (retstat)
4517c478bd9Sstevel@tonic-gate return (retstat);
4527c478bd9Sstevel@tonic-gate
4537c478bd9Sstevel@tonic-gate if ((tagnum > 0) && (tagnum <= MAXTAG) &&
4547c478bd9Sstevel@tonic-gate (tokentable[tagnum].func != NOFUNC)) {
4557c478bd9Sstevel@tonic-gate retstat = open_tag(context, tagnum);
4567c478bd9Sstevel@tonic-gate if (!retstat)
4577c478bd9Sstevel@tonic-gate retstat = (*tokentable[tagnum].func)(context, status,
4587c478bd9Sstevel@tonic-gate flag);
4597c478bd9Sstevel@tonic-gate if (!retstat)
4607c478bd9Sstevel@tonic-gate retstat = close_tag(context, tagnum);
4617c478bd9Sstevel@tonic-gate return (retstat);
4627c478bd9Sstevel@tonic-gate }
4637c478bd9Sstevel@tonic-gate /* here if token id is not in table */
4647c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("praudit: No code associated with "
4657c478bd9Sstevel@tonic-gate "tag id %d\n"), tagnum);
4667c478bd9Sstevel@tonic-gate return (0);
4677c478bd9Sstevel@tonic-gate }
4687c478bd9Sstevel@tonic-gate
4697c478bd9Sstevel@tonic-gate void
get_Hname(uint32_t addr,char * buf,size_t buflen)4707c478bd9Sstevel@tonic-gate get_Hname(uint32_t addr, char *buf, size_t buflen)
4717c478bd9Sstevel@tonic-gate {
4727c478bd9Sstevel@tonic-gate extern char *inet_ntoa(const struct in_addr);
4737c478bd9Sstevel@tonic-gate struct hostent *phe;
4747c478bd9Sstevel@tonic-gate struct in_addr ia;
4757c478bd9Sstevel@tonic-gate
4767c478bd9Sstevel@tonic-gate phe = gethostbyaddr((const char *)&addr, 4, AF_INET);
4777c478bd9Sstevel@tonic-gate if (phe == (struct hostent *)0) {
4787c478bd9Sstevel@tonic-gate ia.s_addr = addr;
4797c478bd9Sstevel@tonic-gate (void) snprintf(buf, buflen, "%s", inet_ntoa(ia));
4807c478bd9Sstevel@tonic-gate return;
4817c478bd9Sstevel@tonic-gate }
4827c478bd9Sstevel@tonic-gate ia.s_addr = addr;
4837c478bd9Sstevel@tonic-gate (void) snprintf(buf, buflen, "%s", phe->h_name);
4847c478bd9Sstevel@tonic-gate }
4857c478bd9Sstevel@tonic-gate
4867c478bd9Sstevel@tonic-gate void
get_Hname_ex(uint32_t * addr,char * buf,size_t buflen)4877c478bd9Sstevel@tonic-gate get_Hname_ex(uint32_t *addr, char *buf, size_t buflen)
4887c478bd9Sstevel@tonic-gate {
4897c478bd9Sstevel@tonic-gate struct hostent *phe;
4907c478bd9Sstevel@tonic-gate int err;
4917c478bd9Sstevel@tonic-gate
4927c478bd9Sstevel@tonic-gate phe = getipnodebyaddr((const void *)addr, 16, AF_INET6, &err);
4937c478bd9Sstevel@tonic-gate
4947c478bd9Sstevel@tonic-gate if (phe == (struct hostent *)0) {
4957c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET6, (void *)addr, buf, buflen);
4967c478bd9Sstevel@tonic-gate } else
4977c478bd9Sstevel@tonic-gate (void) snprintf(buf, buflen, "%s", phe->h_name);
4987c478bd9Sstevel@tonic-gate
4997c478bd9Sstevel@tonic-gate if (phe)
5007c478bd9Sstevel@tonic-gate freehostent(phe);
5017c478bd9Sstevel@tonic-gate }
5027c478bd9Sstevel@tonic-gate
5037c478bd9Sstevel@tonic-gate int
pa_hostname(pr_context_t * context,int status,int flag)5047c478bd9Sstevel@tonic-gate pa_hostname(pr_context_t *context, int status, int flag)
5057c478bd9Sstevel@tonic-gate {
5067c478bd9Sstevel@tonic-gate int returnstat;
5077c478bd9Sstevel@tonic-gate uint32_t ip_addr;
5087c478bd9Sstevel@tonic-gate struct in_addr ia;
5097c478bd9Sstevel@tonic-gate uval_t uval;
5107c478bd9Sstevel@tonic-gate char buf[256];
5117c478bd9Sstevel@tonic-gate
5127c478bd9Sstevel@tonic-gate if (status < 0)
5137c478bd9Sstevel@tonic-gate return (status);
5147c478bd9Sstevel@tonic-gate
5157c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, (char *)&ip_addr, 4)) != 0)
5167c478bd9Sstevel@tonic-gate return (returnstat);
5177c478bd9Sstevel@tonic-gate
5187c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING;
5197c478bd9Sstevel@tonic-gate
5207c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) {
5217c478bd9Sstevel@tonic-gate uval.string_val = buf;
5227c478bd9Sstevel@tonic-gate get_Hname(ip_addr, buf, sizeof (buf));
5237c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag);
5247c478bd9Sstevel@tonic-gate } else {
5257c478bd9Sstevel@tonic-gate ia.s_addr = ip_addr;
5267c478bd9Sstevel@tonic-gate if ((uval.string_val = inet_ntoa(ia)) == NULL)
5277c478bd9Sstevel@tonic-gate return (-1);
5287c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag);
5297c478bd9Sstevel@tonic-gate }
5307c478bd9Sstevel@tonic-gate return (returnstat);
5317c478bd9Sstevel@tonic-gate }
5327c478bd9Sstevel@tonic-gate
5337c478bd9Sstevel@tonic-gate int
pa_hostname_ex(pr_context_t * context,int status,int flag)5347c478bd9Sstevel@tonic-gate pa_hostname_ex(pr_context_t *context, int status, int flag)
5357c478bd9Sstevel@tonic-gate {
5367c478bd9Sstevel@tonic-gate int returnstat;
5377c478bd9Sstevel@tonic-gate uint32_t ip_type;
5387c478bd9Sstevel@tonic-gate uint32_t ip_addr[4];
5397c478bd9Sstevel@tonic-gate struct in_addr ia;
5407c478bd9Sstevel@tonic-gate char buf[256];
5417c478bd9Sstevel@tonic-gate uval_t uval;
5427c478bd9Sstevel@tonic-gate
5437c478bd9Sstevel@tonic-gate if (status < 0)
5447c478bd9Sstevel@tonic-gate return (status);
5457c478bd9Sstevel@tonic-gate
5467c478bd9Sstevel@tonic-gate /* get ip type */
5477c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_int32(context, (int32_t *)&ip_type, 1)) != 0)
5487c478bd9Sstevel@tonic-gate return (returnstat);
5497c478bd9Sstevel@tonic-gate
5507c478bd9Sstevel@tonic-gate /* only IPv4 and IPv6 addresses are legal */
5517c478bd9Sstevel@tonic-gate if ((ip_type != AU_IPv4) && (ip_type != AU_IPv6))
5527c478bd9Sstevel@tonic-gate return (-1);
5537c478bd9Sstevel@tonic-gate
5547c478bd9Sstevel@tonic-gate /* get ip address */
5557c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, (char *)ip_addr, ip_type)) != 0)
5567c478bd9Sstevel@tonic-gate return (returnstat);
5577c478bd9Sstevel@tonic-gate
5587c478bd9Sstevel@tonic-gate if ((returnstat = open_tag(context, TAG_HOSTID)) != 0)
5597c478bd9Sstevel@tonic-gate return (returnstat);
5607c478bd9Sstevel@tonic-gate
5617c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING;
5627c478bd9Sstevel@tonic-gate if (ip_type == AU_IPv4) { /* ipv4 address */
5637c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) {
5647c478bd9Sstevel@tonic-gate uval.string_val = buf;
5657c478bd9Sstevel@tonic-gate get_Hname(ip_addr[0], buf, sizeof (buf));
5667c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag);
5677c478bd9Sstevel@tonic-gate } else {
5687c478bd9Sstevel@tonic-gate ia.s_addr = ip_addr[0];
5697c478bd9Sstevel@tonic-gate if ((uval.string_val = inet_ntoa(ia)) == NULL)
5707c478bd9Sstevel@tonic-gate return (-1);
5717c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag);
5727c478bd9Sstevel@tonic-gate }
5737c478bd9Sstevel@tonic-gate } else if (ip_type == AU_IPv6) { /* IPv6 addresss (128 bits) */
5747c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) {
5757c478bd9Sstevel@tonic-gate uval.string_val = buf;
5767c478bd9Sstevel@tonic-gate get_Hname_ex(ip_addr, buf, sizeof (buf));
5777c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag);
5787c478bd9Sstevel@tonic-gate } else {
5797c478bd9Sstevel@tonic-gate uval.string_val = (char *)buf;
5807c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET6, (void *)ip_addr, buf,
5817c478bd9Sstevel@tonic-gate sizeof (buf));
5827c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag);
5837c478bd9Sstevel@tonic-gate }
5847c478bd9Sstevel@tonic-gate }
5857c478bd9Sstevel@tonic-gate
5867c478bd9Sstevel@tonic-gate if (returnstat != 0)
5877c478bd9Sstevel@tonic-gate return (returnstat);
5887c478bd9Sstevel@tonic-gate return (close_tag(context, TAG_HOSTID));
5897c478bd9Sstevel@tonic-gate }
5907c478bd9Sstevel@tonic-gate
5917c478bd9Sstevel@tonic-gate int
pa_hostname_so(pr_context_t * context,int status,int flag)5927c478bd9Sstevel@tonic-gate pa_hostname_so(pr_context_t *context, int status, int flag)
5937c478bd9Sstevel@tonic-gate {
5947c478bd9Sstevel@tonic-gate int returnstat;
5957c478bd9Sstevel@tonic-gate short ip_type;
5967c478bd9Sstevel@tonic-gate ushort_t ip_port;
5977c478bd9Sstevel@tonic-gate uint32_t ip_addr[4];
5987c478bd9Sstevel@tonic-gate struct in_addr ia;
5997c478bd9Sstevel@tonic-gate char buf[256];
6007c478bd9Sstevel@tonic-gate uval_t uval;
6017c478bd9Sstevel@tonic-gate
6027c478bd9Sstevel@tonic-gate if (status < 0)
6037c478bd9Sstevel@tonic-gate return (status);
6047c478bd9Sstevel@tonic-gate
6057c478bd9Sstevel@tonic-gate /* get ip type */
6067c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_short(context, &ip_type, 1)) != 0)
6077c478bd9Sstevel@tonic-gate return (returnstat);
6087c478bd9Sstevel@tonic-gate
6097c478bd9Sstevel@tonic-gate /* only IPv4 and IPv6 addresses are legal */
6107c478bd9Sstevel@tonic-gate if ((ip_type != AU_IPv4) && (ip_type != AU_IPv6))
6117c478bd9Sstevel@tonic-gate return (-1);
6127c478bd9Sstevel@tonic-gate
6137c478bd9Sstevel@tonic-gate /* get local ip port */
6147c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_short(context, &ip_port, 1)) != 0)
6157c478bd9Sstevel@tonic-gate return (returnstat);
6167c478bd9Sstevel@tonic-gate
6177c478bd9Sstevel@tonic-gate if ((returnstat = open_tag(context, TAG_SOCKEXLPORT)) != 0)
6187c478bd9Sstevel@tonic-gate return (returnstat);
6197c478bd9Sstevel@tonic-gate
6207c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING;
6217c478bd9Sstevel@tonic-gate uval.string_val = hexconvert((char *)&ip_port, sizeof (ip_port),
6227c478bd9Sstevel@tonic-gate sizeof (ip_port));
6237c478bd9Sstevel@tonic-gate if (uval.string_val) {
6247c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, 0);
6257c478bd9Sstevel@tonic-gate free(uval.string_val);
6267c478bd9Sstevel@tonic-gate } else
6277c478bd9Sstevel@tonic-gate returnstat = -1;
6287c478bd9Sstevel@tonic-gate if (returnstat)
6297c478bd9Sstevel@tonic-gate return (returnstat);
6307c478bd9Sstevel@tonic-gate
6317c478bd9Sstevel@tonic-gate if ((returnstat = close_tag(context, TAG_SOCKEXLPORT)) != 0)
6327c478bd9Sstevel@tonic-gate return (returnstat);
6337c478bd9Sstevel@tonic-gate
6347c478bd9Sstevel@tonic-gate /* get local ip address */
6357c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, (char *)ip_addr, ip_type)) != 0)
6367c478bd9Sstevel@tonic-gate return (returnstat);
6377c478bd9Sstevel@tonic-gate
6387c478bd9Sstevel@tonic-gate if ((returnstat = open_tag(context, TAG_SOCKEXLADDR)) != 0)
6397c478bd9Sstevel@tonic-gate return (returnstat);
6407c478bd9Sstevel@tonic-gate
6417c478bd9Sstevel@tonic-gate if (ip_type == AU_IPv4) { /* ipv4 address */
6427c478bd9Sstevel@tonic-gate
6437c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) {
6447c478bd9Sstevel@tonic-gate uval.string_val = buf;
6457c478bd9Sstevel@tonic-gate get_Hname(ip_addr[0], buf, sizeof (buf));
6467c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, 0);
6477c478bd9Sstevel@tonic-gate } else {
6487c478bd9Sstevel@tonic-gate ia.s_addr = ip_addr[0];
6497c478bd9Sstevel@tonic-gate if ((uval.string_val = inet_ntoa(ia)) == NULL)
6507c478bd9Sstevel@tonic-gate return (-1);
6517c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, 0);
6527c478bd9Sstevel@tonic-gate }
6537c478bd9Sstevel@tonic-gate
6547c478bd9Sstevel@tonic-gate } else if (ip_type == AU_IPv6) { /* IPv6 addresss (128 bits) */
6557c478bd9Sstevel@tonic-gate
6567c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) {
6577c478bd9Sstevel@tonic-gate uval.string_val = buf;
6587c478bd9Sstevel@tonic-gate get_Hname_ex(ip_addr, buf, sizeof (buf));
6597c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, 0);
6607c478bd9Sstevel@tonic-gate } else {
6617c478bd9Sstevel@tonic-gate uval.string_val = (char *)buf;
6627c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET6, (void *)ip_addr, buf,
6637c478bd9Sstevel@tonic-gate sizeof (buf));
6647c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, 0);
6657c478bd9Sstevel@tonic-gate }
6667c478bd9Sstevel@tonic-gate } else
6677c478bd9Sstevel@tonic-gate returnstat = -1;
6687c478bd9Sstevel@tonic-gate
6697c478bd9Sstevel@tonic-gate if (returnstat)
6707c478bd9Sstevel@tonic-gate return (returnstat);
6717c478bd9Sstevel@tonic-gate
6727c478bd9Sstevel@tonic-gate if ((returnstat = close_tag(context, TAG_SOCKEXLADDR)) != 0)
6737c478bd9Sstevel@tonic-gate return (returnstat);
6747c478bd9Sstevel@tonic-gate
6757c478bd9Sstevel@tonic-gate /* get foreign ip port */
6767c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_short(context, &ip_port, 1)) != 0)
6777c478bd9Sstevel@tonic-gate return (returnstat);
6787c478bd9Sstevel@tonic-gate
6797c478bd9Sstevel@tonic-gate if ((returnstat = open_tag(context, TAG_SOCKEXFPORT)) != 0)
6807c478bd9Sstevel@tonic-gate return (returnstat);
6817c478bd9Sstevel@tonic-gate
6827c478bd9Sstevel@tonic-gate uval.string_val = hexconvert((char *)&ip_port, sizeof (ip_port),
6837c478bd9Sstevel@tonic-gate sizeof (ip_port));
6847c478bd9Sstevel@tonic-gate if (uval.string_val) {
6857c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, 0);
6867c478bd9Sstevel@tonic-gate free(uval.string_val);
6877c478bd9Sstevel@tonic-gate } else
6887c478bd9Sstevel@tonic-gate returnstat = -1;
6897c478bd9Sstevel@tonic-gate
6907c478bd9Sstevel@tonic-gate if (returnstat)
6917c478bd9Sstevel@tonic-gate return (returnstat);
6927c478bd9Sstevel@tonic-gate
6937c478bd9Sstevel@tonic-gate if ((returnstat = close_tag(context, TAG_SOCKEXFPORT)) != 0)
6947c478bd9Sstevel@tonic-gate return (returnstat);
6957c478bd9Sstevel@tonic-gate
6967c478bd9Sstevel@tonic-gate /* get foreign ip address */
6977c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, (char *)ip_addr, ip_type)) != 0)
6987c478bd9Sstevel@tonic-gate return (returnstat);
6997c478bd9Sstevel@tonic-gate
7007c478bd9Sstevel@tonic-gate if ((returnstat = open_tag(context, TAG_SOCKEXFADDR)) != 0)
7017c478bd9Sstevel@tonic-gate return (returnstat);
7027c478bd9Sstevel@tonic-gate
7037c478bd9Sstevel@tonic-gate if (ip_type == AU_IPv4) { /* ipv4 address */
7047c478bd9Sstevel@tonic-gate
7057c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) {
7067c478bd9Sstevel@tonic-gate uval.string_val = buf;
7077c478bd9Sstevel@tonic-gate get_Hname(ip_addr[0], buf, sizeof (buf));
7087c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag);
7097c478bd9Sstevel@tonic-gate } else {
7107c478bd9Sstevel@tonic-gate ia.s_addr = ip_addr[0];
7117c478bd9Sstevel@tonic-gate if ((uval.string_val = inet_ntoa(ia)) == NULL)
7127c478bd9Sstevel@tonic-gate return (-1);
7137c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag);
7147c478bd9Sstevel@tonic-gate }
7157c478bd9Sstevel@tonic-gate
7167c478bd9Sstevel@tonic-gate } else if (ip_type == AU_IPv6) { /* IPv6 addresss (128 bits) */
7177c478bd9Sstevel@tonic-gate
7187c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) {
7197c478bd9Sstevel@tonic-gate uval.string_val = buf;
7207c478bd9Sstevel@tonic-gate get_Hname_ex(ip_addr, buf, sizeof (buf));
7217c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag);
7227c478bd9Sstevel@tonic-gate } else {
7237c478bd9Sstevel@tonic-gate uval.string_val = (char *)buf;
7247c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET6, (void *)ip_addr, buf,
7257c478bd9Sstevel@tonic-gate sizeof (buf));
7267c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag);
7277c478bd9Sstevel@tonic-gate }
7287c478bd9Sstevel@tonic-gate } else
7297c478bd9Sstevel@tonic-gate returnstat = -1;
7307c478bd9Sstevel@tonic-gate
7317c478bd9Sstevel@tonic-gate if (returnstat)
7327c478bd9Sstevel@tonic-gate return (returnstat);
7337c478bd9Sstevel@tonic-gate
7347c478bd9Sstevel@tonic-gate if ((returnstat = close_tag(context, TAG_SOCKEXFADDR)) != 0)
7357c478bd9Sstevel@tonic-gate return (returnstat);
7367c478bd9Sstevel@tonic-gate
7377c478bd9Sstevel@tonic-gate return (returnstat);
7387c478bd9Sstevel@tonic-gate }
7397c478bd9Sstevel@tonic-gate
7407c478bd9Sstevel@tonic-gate
7417c478bd9Sstevel@tonic-gate #define NBITSMAJOR64 32 /* # of major device bits in 64-bit Solaris */
7427c478bd9Sstevel@tonic-gate #define NBITSMINOR64 32 /* # of minor device bits in 64-bit Solaris */
7437c478bd9Sstevel@tonic-gate #define MAXMAJ64 0xfffffffful /* max major value */
7447c478bd9Sstevel@tonic-gate #define MAXMIN64 0xfffffffful /* max minor value */
7457c478bd9Sstevel@tonic-gate
7467c478bd9Sstevel@tonic-gate #define NBITSMAJOR32 14 /* # of SVR4 major device bits */
7477c478bd9Sstevel@tonic-gate #define NBITSMINOR32 18 /* # of SVR4 minor device bits */
7487c478bd9Sstevel@tonic-gate #define NMAXMAJ32 0x3fff /* SVR4 max major value */
7497c478bd9Sstevel@tonic-gate #define NMAXMIN32 0x3ffff /* MAX minor for 3b2 software drivers. */
7507c478bd9Sstevel@tonic-gate
7517c478bd9Sstevel@tonic-gate
7527c478bd9Sstevel@tonic-gate static int32_t
minor_64(uint64_t dev)7537c478bd9Sstevel@tonic-gate minor_64(uint64_t dev)
7547c478bd9Sstevel@tonic-gate {
7557c478bd9Sstevel@tonic-gate if (dev == NODEV) {
7567c478bd9Sstevel@tonic-gate errno = EINVAL;
7577c478bd9Sstevel@tonic-gate return (NODEV);
7587c478bd9Sstevel@tonic-gate }
7597c478bd9Sstevel@tonic-gate return (int32_t)(dev & MAXMIN64);
7607c478bd9Sstevel@tonic-gate }
7617c478bd9Sstevel@tonic-gate
7627c478bd9Sstevel@tonic-gate static int32_t
major_64(uint64_t dev)7637c478bd9Sstevel@tonic-gate major_64(uint64_t dev)
7647c478bd9Sstevel@tonic-gate {
7657c478bd9Sstevel@tonic-gate uint32_t maj;
7667c478bd9Sstevel@tonic-gate
7677c478bd9Sstevel@tonic-gate maj = (uint32_t)(dev >> NBITSMINOR64);
7687c478bd9Sstevel@tonic-gate
7697c478bd9Sstevel@tonic-gate if (dev == NODEV || maj > MAXMAJ64) {
7707c478bd9Sstevel@tonic-gate errno = EINVAL;
7717c478bd9Sstevel@tonic-gate return (NODEV);
7727c478bd9Sstevel@tonic-gate }
7737c478bd9Sstevel@tonic-gate return (int32_t)(maj);
7747c478bd9Sstevel@tonic-gate }
7757c478bd9Sstevel@tonic-gate
7767c478bd9Sstevel@tonic-gate static int32_t
minor_32(uint32_t dev)7777c478bd9Sstevel@tonic-gate minor_32(uint32_t dev)
7787c478bd9Sstevel@tonic-gate {
7797c478bd9Sstevel@tonic-gate if (dev == NODEV) {
7807c478bd9Sstevel@tonic-gate errno = EINVAL;
7817c478bd9Sstevel@tonic-gate return (NODEV);
7827c478bd9Sstevel@tonic-gate }
7837c478bd9Sstevel@tonic-gate return (int32_t)(dev & MAXMIN32);
7847c478bd9Sstevel@tonic-gate }
7857c478bd9Sstevel@tonic-gate
7867c478bd9Sstevel@tonic-gate static int32_t
major_32(uint32_t dev)7877c478bd9Sstevel@tonic-gate major_32(uint32_t dev)
7887c478bd9Sstevel@tonic-gate {
7897c478bd9Sstevel@tonic-gate uint32_t maj;
7907c478bd9Sstevel@tonic-gate
7917c478bd9Sstevel@tonic-gate maj = (uint32_t)(dev >> NBITSMINOR32);
7927c478bd9Sstevel@tonic-gate
7937c478bd9Sstevel@tonic-gate if (dev == NODEV || maj > MAXMAJ32) {
7947c478bd9Sstevel@tonic-gate errno = EINVAL;
7957c478bd9Sstevel@tonic-gate return (NODEV);
7967c478bd9Sstevel@tonic-gate }
7977c478bd9Sstevel@tonic-gate return (int32_t)(maj);
7987c478bd9Sstevel@tonic-gate }
7997c478bd9Sstevel@tonic-gate
8007c478bd9Sstevel@tonic-gate
8017c478bd9Sstevel@tonic-gate /*
8027c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
803*8bb3e7e3SPeter Tribble * pa_tid() : Process terminal id and display contents
8047c478bd9Sstevel@tonic-gate * return codes : -1 - error
8057c478bd9Sstevel@tonic-gate * : 0 - successful
8067c478bd9Sstevel@tonic-gate *
8077c478bd9Sstevel@tonic-gate * terminal id port adr_int32
8087c478bd9Sstevel@tonic-gate * terminal id machine adr_int32
8097c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
8107c478bd9Sstevel@tonic-gate */
8117c478bd9Sstevel@tonic-gate int
pa_tid32(pr_context_t * context,int status,int flag)8127c478bd9Sstevel@tonic-gate pa_tid32(pr_context_t *context, int status, int flag)
8137c478bd9Sstevel@tonic-gate {
8147c478bd9Sstevel@tonic-gate int returnstat;
8157c478bd9Sstevel@tonic-gate int32_t dev_maj_min;
8167c478bd9Sstevel@tonic-gate uint32_t ip_addr;
8177c478bd9Sstevel@tonic-gate struct in_addr ia;
8187c478bd9Sstevel@tonic-gate char *ipstring;
8197c478bd9Sstevel@tonic-gate char buf[256];
8207c478bd9Sstevel@tonic-gate uval_t uval;
8217c478bd9Sstevel@tonic-gate
8227c478bd9Sstevel@tonic-gate if (status < 0)
8237c478bd9Sstevel@tonic-gate return (status);
8247c478bd9Sstevel@tonic-gate
8257c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_int32(context, &dev_maj_min, 1)) != 0)
8267c478bd9Sstevel@tonic-gate return (returnstat);
8277c478bd9Sstevel@tonic-gate
8287c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, (char *)&ip_addr, 4)) != 0)
8297c478bd9Sstevel@tonic-gate return (returnstat);
8307c478bd9Sstevel@tonic-gate
8317c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING;
8327c478bd9Sstevel@tonic-gate uval.string_val = buf;
8337c478bd9Sstevel@tonic-gate
8347c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) {
8357c478bd9Sstevel@tonic-gate char hostname[256];
8367c478bd9Sstevel@tonic-gate
8377c478bd9Sstevel@tonic-gate get_Hname(ip_addr, hostname, sizeof (hostname));
8387c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s",
8398f9294f3Sgww major_32(dev_maj_min),
8408f9294f3Sgww minor_32(dev_maj_min),
8418f9294f3Sgww hostname);
8427c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag));
8437c478bd9Sstevel@tonic-gate }
8447c478bd9Sstevel@tonic-gate
8457c478bd9Sstevel@tonic-gate ia.s_addr = ip_addr;
8467c478bd9Sstevel@tonic-gate if ((ipstring = inet_ntoa(ia)) == NULL)
8477c478bd9Sstevel@tonic-gate return (-1);
8487c478bd9Sstevel@tonic-gate
8498f9294f3Sgww (void) snprintf(buf, sizeof (buf), "%d %d %s", major_32(dev_maj_min),
8508f9294f3Sgww minor_32(dev_maj_min),
8518f9294f3Sgww ipstring);
8527c478bd9Sstevel@tonic-gate
8537c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag));
8547c478bd9Sstevel@tonic-gate }
8557c478bd9Sstevel@tonic-gate
8567c478bd9Sstevel@tonic-gate int
pa_tid32_ex(pr_context_t * context,int status,int flag)8577c478bd9Sstevel@tonic-gate pa_tid32_ex(pr_context_t *context, int status, int flag)
8587c478bd9Sstevel@tonic-gate {
8597c478bd9Sstevel@tonic-gate int returnstat;
8607c478bd9Sstevel@tonic-gate int32_t dev_maj_min;
8617c478bd9Sstevel@tonic-gate uint32_t ip_addr[16];
8627c478bd9Sstevel@tonic-gate uint32_t ip_type;
8637c478bd9Sstevel@tonic-gate struct in_addr ia;
8647c478bd9Sstevel@tonic-gate char *ipstring;
8657c478bd9Sstevel@tonic-gate char hostname[256];
8667c478bd9Sstevel@tonic-gate char buf[256];
8677c478bd9Sstevel@tonic-gate char tbuf[256];
8687c478bd9Sstevel@tonic-gate uval_t uval;
8697c478bd9Sstevel@tonic-gate
8707c478bd9Sstevel@tonic-gate if (status < 0)
8717c478bd9Sstevel@tonic-gate return (status);
8727c478bd9Sstevel@tonic-gate
8737c478bd9Sstevel@tonic-gate /* get port info */
8747c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_int32(context, &dev_maj_min, 1)) != 0)
8757c478bd9Sstevel@tonic-gate return (returnstat);
8767c478bd9Sstevel@tonic-gate
8777c478bd9Sstevel@tonic-gate /* get address type */
8787c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_int32(context, &ip_type, 1)) != 0)
8797c478bd9Sstevel@tonic-gate return (returnstat);
8807c478bd9Sstevel@tonic-gate
8817c478bd9Sstevel@tonic-gate /* legal address types are either AU_IPv4 or AU_IPv6 only */
8827c478bd9Sstevel@tonic-gate if ((ip_type != AU_IPv4) && (ip_type != AU_IPv6))
8837c478bd9Sstevel@tonic-gate return (-1);
8847c478bd9Sstevel@tonic-gate
8857c478bd9Sstevel@tonic-gate /* get address (4/16) */
8867c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, (char *)ip_addr, ip_type)) != 0)
8877c478bd9Sstevel@tonic-gate return (returnstat);
8887c478bd9Sstevel@tonic-gate
8897c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING;
8907c478bd9Sstevel@tonic-gate if (ip_type == AU_IPv4) {
8917c478bd9Sstevel@tonic-gate uval.string_val = buf;
8927c478bd9Sstevel@tonic-gate
8937c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) {
8947c478bd9Sstevel@tonic-gate get_Hname(ip_addr[0], hostname, sizeof (hostname));
8957c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s",
8968f9294f3Sgww major_32(dev_maj_min), minor_32(dev_maj_min),
8978f9294f3Sgww hostname);
8987c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag));
8997c478bd9Sstevel@tonic-gate }
9007c478bd9Sstevel@tonic-gate
9017c478bd9Sstevel@tonic-gate ia.s_addr = ip_addr[0];
9027c478bd9Sstevel@tonic-gate if ((ipstring = inet_ntoa(ia)) == NULL)
9037c478bd9Sstevel@tonic-gate return (-1);
9047c478bd9Sstevel@tonic-gate
9057c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s",
9068f9294f3Sgww major_32(dev_maj_min), minor_32(dev_maj_min), ipstring);
9077c478bd9Sstevel@tonic-gate
9087c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag));
9097c478bd9Sstevel@tonic-gate } else {
9107c478bd9Sstevel@tonic-gate uval.string_val = buf;
9117c478bd9Sstevel@tonic-gate
9127c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) {
9137c478bd9Sstevel@tonic-gate get_Hname_ex(ip_addr, hostname, sizeof (hostname));
9147c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s",
9158f9294f3Sgww major_32(dev_maj_min), minor_32(dev_maj_min),
9168f9294f3Sgww hostname);
9177c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag));
9187c478bd9Sstevel@tonic-gate }
9197c478bd9Sstevel@tonic-gate
9207c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET6, (void *) ip_addr, tbuf,
9217c478bd9Sstevel@tonic-gate sizeof (tbuf));
9227c478bd9Sstevel@tonic-gate
9237c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s",
9248f9294f3Sgww major_32(dev_maj_min), minor_32(dev_maj_min), tbuf);
9257c478bd9Sstevel@tonic-gate
9267c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag));
9277c478bd9Sstevel@tonic-gate }
9287c478bd9Sstevel@tonic-gate }
9297c478bd9Sstevel@tonic-gate
9307c478bd9Sstevel@tonic-gate int
pa_ip_addr(pr_context_t * context,int status,int flag)9317c478bd9Sstevel@tonic-gate pa_ip_addr(pr_context_t *context, int status, int flag)
9327c478bd9Sstevel@tonic-gate {
9337c478bd9Sstevel@tonic-gate int returnstat;
9347c478bd9Sstevel@tonic-gate uval_t uval;
9357c478bd9Sstevel@tonic-gate uint32_t ip_addr[4];
9367c478bd9Sstevel@tonic-gate uint32_t ip_type;
9377c478bd9Sstevel@tonic-gate struct in_addr ia;
9387c478bd9Sstevel@tonic-gate char *ipstring;
9397c478bd9Sstevel@tonic-gate char hostname[256];
9407c478bd9Sstevel@tonic-gate char buf[256];
9417c478bd9Sstevel@tonic-gate char tbuf[256];
9427c478bd9Sstevel@tonic-gate
9437c478bd9Sstevel@tonic-gate if (status < 0)
9447c478bd9Sstevel@tonic-gate return (status);
9457c478bd9Sstevel@tonic-gate
9467c478bd9Sstevel@tonic-gate /* get address type */
9477c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_int32(context, &ip_type, 1)) != 0)
9487c478bd9Sstevel@tonic-gate return (returnstat);
9497c478bd9Sstevel@tonic-gate
9507c478bd9Sstevel@tonic-gate /* legal address type is AU_IPv4 or AU_IPv6 */
9517c478bd9Sstevel@tonic-gate if ((ip_type != AU_IPv4) && (ip_type != AU_IPv6))
9527c478bd9Sstevel@tonic-gate return (-1);
9537c478bd9Sstevel@tonic-gate
9547c478bd9Sstevel@tonic-gate /* get address (4/16) */
9557c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, (char *)ip_addr, ip_type)) != 0)
9567c478bd9Sstevel@tonic-gate return (returnstat);
9577c478bd9Sstevel@tonic-gate
9587c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING;
9597c478bd9Sstevel@tonic-gate if (ip_type == AU_IPv4) {
9607c478bd9Sstevel@tonic-gate uval.string_val = buf;
9617c478bd9Sstevel@tonic-gate
9627c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) {
9637c478bd9Sstevel@tonic-gate get_Hname(ip_addr[0], hostname, sizeof (hostname));
9648f9294f3Sgww (void) snprintf(buf, sizeof (buf), "%s", hostname);
9657c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag));
9667c478bd9Sstevel@tonic-gate }
9677c478bd9Sstevel@tonic-gate
9687c478bd9Sstevel@tonic-gate ia.s_addr = ip_addr[0];
9697c478bd9Sstevel@tonic-gate if ((ipstring = inet_ntoa(ia)) == NULL)
9707c478bd9Sstevel@tonic-gate return (-1);
9717c478bd9Sstevel@tonic-gate
9728f9294f3Sgww (void) snprintf(buf, sizeof (buf), "%s", ipstring);
9737c478bd9Sstevel@tonic-gate
9747c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag));
9757c478bd9Sstevel@tonic-gate } else {
9767c478bd9Sstevel@tonic-gate uval.string_val = buf;
9777c478bd9Sstevel@tonic-gate
9787c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) {
9797c478bd9Sstevel@tonic-gate get_Hname_ex(ip_addr, hostname, sizeof (hostname));
9807c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%s",
9817c478bd9Sstevel@tonic-gate hostname);
9827c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag));
9837c478bd9Sstevel@tonic-gate }
9847c478bd9Sstevel@tonic-gate
9857c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET6, (void *) ip_addr, tbuf,
9867c478bd9Sstevel@tonic-gate sizeof (tbuf));
9877c478bd9Sstevel@tonic-gate
9887c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%s", tbuf);
9897c478bd9Sstevel@tonic-gate
9907c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag));
9917c478bd9Sstevel@tonic-gate }
9927c478bd9Sstevel@tonic-gate
9937c478bd9Sstevel@tonic-gate }
9947c478bd9Sstevel@tonic-gate
9957c478bd9Sstevel@tonic-gate int
pa_tid64(pr_context_t * context,int status,int flag)9967c478bd9Sstevel@tonic-gate pa_tid64(pr_context_t *context, int status, int flag)
9977c478bd9Sstevel@tonic-gate {
9987c478bd9Sstevel@tonic-gate int returnstat;
9997c478bd9Sstevel@tonic-gate int64_t dev_maj_min;
10007c478bd9Sstevel@tonic-gate uint32_t ip_addr;
10017c478bd9Sstevel@tonic-gate struct in_addr ia;
10027c478bd9Sstevel@tonic-gate char *ipstring;
10037c478bd9Sstevel@tonic-gate char buf[256];
10047c478bd9Sstevel@tonic-gate uval_t uval;
10057c478bd9Sstevel@tonic-gate
10067c478bd9Sstevel@tonic-gate if (status < 0)
10077c478bd9Sstevel@tonic-gate return (status);
10087c478bd9Sstevel@tonic-gate
10097c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_int64(context, &dev_maj_min, 1)) != 0)
10107c478bd9Sstevel@tonic-gate return (returnstat);
10117c478bd9Sstevel@tonic-gate
10127c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, (char *)&ip_addr, 4)) != 0)
10137c478bd9Sstevel@tonic-gate return (returnstat);
10147c478bd9Sstevel@tonic-gate
10157c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING;
10167c478bd9Sstevel@tonic-gate uval.string_val = buf;
10177c478bd9Sstevel@tonic-gate
10187c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) {
10197c478bd9Sstevel@tonic-gate char hostname[256];
10207c478bd9Sstevel@tonic-gate
10217c478bd9Sstevel@tonic-gate get_Hname(ip_addr, hostname, sizeof (hostname));
10227c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s",
10238f9294f3Sgww major_64(dev_maj_min), minor_64(dev_maj_min), hostname);
10247c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag));
10257c478bd9Sstevel@tonic-gate }
10267c478bd9Sstevel@tonic-gate
10277c478bd9Sstevel@tonic-gate ia.s_addr = ip_addr;
10287c478bd9Sstevel@tonic-gate if ((ipstring = inet_ntoa(ia)) == NULL)
10297c478bd9Sstevel@tonic-gate return (-1);
10307c478bd9Sstevel@tonic-gate
10317c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s",
10328f9294f3Sgww major_64(dev_maj_min), minor_64(dev_maj_min), ipstring);
10337c478bd9Sstevel@tonic-gate
10347c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag));
10357c478bd9Sstevel@tonic-gate }
10367c478bd9Sstevel@tonic-gate
10377c478bd9Sstevel@tonic-gate int
pa_tid64_ex(pr_context_t * context,int status,int flag)10387c478bd9Sstevel@tonic-gate pa_tid64_ex(pr_context_t *context, int status, int flag)
10397c478bd9Sstevel@tonic-gate {
10407c478bd9Sstevel@tonic-gate int returnstat;
10417c478bd9Sstevel@tonic-gate int64_t dev_maj_min;
10427c478bd9Sstevel@tonic-gate uint32_t ip_addr[4];
10437c478bd9Sstevel@tonic-gate uint32_t ip_type;
10447c478bd9Sstevel@tonic-gate struct in_addr ia;
10457c478bd9Sstevel@tonic-gate char *ipstring;
10467c478bd9Sstevel@tonic-gate char hostname[256];
10477c478bd9Sstevel@tonic-gate char buf[256];
10487c478bd9Sstevel@tonic-gate char tbuf[256];
10497c478bd9Sstevel@tonic-gate uval_t uval;
10507c478bd9Sstevel@tonic-gate
10517c478bd9Sstevel@tonic-gate if (status < 0)
10527c478bd9Sstevel@tonic-gate return (status);
10537c478bd9Sstevel@tonic-gate
10547c478bd9Sstevel@tonic-gate /* get port info */
10557c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_int64(context, &dev_maj_min, 1)) != 0)
10567c478bd9Sstevel@tonic-gate return (returnstat);
10577c478bd9Sstevel@tonic-gate
10587c478bd9Sstevel@tonic-gate /* get address type */
10597c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_int32(context, &ip_type, 1)) != 0)
10607c478bd9Sstevel@tonic-gate return (returnstat);
10617c478bd9Sstevel@tonic-gate
10627c478bd9Sstevel@tonic-gate /* legal address types are either AU_IPv4 or AU_IPv6 only */
10637c478bd9Sstevel@tonic-gate if ((ip_type != AU_IPv4) && (ip_type != AU_IPv6))
10647c478bd9Sstevel@tonic-gate return (-1);
10657c478bd9Sstevel@tonic-gate
10667c478bd9Sstevel@tonic-gate /* get address (4/16) */
10677c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, (char *)&ip_addr, ip_type)) != 0)
10687c478bd9Sstevel@tonic-gate return (returnstat);
10697c478bd9Sstevel@tonic-gate
10707c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING;
10717c478bd9Sstevel@tonic-gate if (ip_type == AU_IPv4) {
10727c478bd9Sstevel@tonic-gate uval.string_val = buf;
10737c478bd9Sstevel@tonic-gate
10747c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) {
10757c478bd9Sstevel@tonic-gate get_Hname(ip_addr[0], hostname, sizeof (hostname));
10767c478bd9Sstevel@tonic-gate uval.string_val = buf;
10777c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s",
10788f9294f3Sgww major_64(dev_maj_min), minor_64(dev_maj_min),
10798f9294f3Sgww hostname);
10807c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag));
10817c478bd9Sstevel@tonic-gate }
10827c478bd9Sstevel@tonic-gate
10837c478bd9Sstevel@tonic-gate ia.s_addr = ip_addr[0];
10847c478bd9Sstevel@tonic-gate if ((ipstring = inet_ntoa(ia)) == NULL)
10857c478bd9Sstevel@tonic-gate return (-1);
10867c478bd9Sstevel@tonic-gate
10877c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s",
10888f9294f3Sgww major_64(dev_maj_min), minor_64(dev_maj_min), ipstring);
10897c478bd9Sstevel@tonic-gate
10907c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag));
10917c478bd9Sstevel@tonic-gate } else {
10927c478bd9Sstevel@tonic-gate uval.string_val = buf;
10937c478bd9Sstevel@tonic-gate
10947c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) {
10957c478bd9Sstevel@tonic-gate get_Hname_ex(ip_addr, hostname, sizeof (hostname));
10967c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s",
10978f9294f3Sgww major_64(dev_maj_min), minor_64(dev_maj_min),
10988f9294f3Sgww hostname);
10997c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag));
11007c478bd9Sstevel@tonic-gate }
11017c478bd9Sstevel@tonic-gate
11027c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET6, (void *)ip_addr, tbuf,
11037c478bd9Sstevel@tonic-gate sizeof (tbuf));
11047c478bd9Sstevel@tonic-gate
11057c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%d %d %s",
11068f9294f3Sgww major_64(dev_maj_min), minor_64(dev_maj_min), tbuf);
11077c478bd9Sstevel@tonic-gate
11087c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag));
11097c478bd9Sstevel@tonic-gate }
11107c478bd9Sstevel@tonic-gate }
11117c478bd9Sstevel@tonic-gate
11127c478bd9Sstevel@tonic-gate
11137c478bd9Sstevel@tonic-gate /*
11147c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------
11157c478bd9Sstevel@tonic-gate * findfieldwidth:
11167c478bd9Sstevel@tonic-gate * Returns the field width based on the basic unit and print mode.
11177c478bd9Sstevel@tonic-gate * This routine is called to determine the field width for the
11187c478bd9Sstevel@tonic-gate * data items in the arbitrary data token where the tokens are
11197c478bd9Sstevel@tonic-gate * to be printed in more than one line. The field width can be
11207c478bd9Sstevel@tonic-gate * found in the fwidth structure.
11217c478bd9Sstevel@tonic-gate *
11227c478bd9Sstevel@tonic-gate * Input parameters:
11237c478bd9Sstevel@tonic-gate * basicunit Can be one of AUR_CHAR, AUR_BYTE, AUR_SHORT,
11247c478bd9Sstevel@tonic-gate * AUR_INT32, or AUR_INT64
11257c478bd9Sstevel@tonic-gate * howtoprint Print mode. Can be one of AUP_BINARY, AUP_OCTAL,
11267c478bd9Sstevel@tonic-gate * AUP_DECIMAL, or AUP_HEX.
11277c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------
11287c478bd9Sstevel@tonic-gate */
11297c478bd9Sstevel@tonic-gate int
findfieldwidth(char basicunit,char howtoprint)11307c478bd9Sstevel@tonic-gate findfieldwidth(char basicunit, char howtoprint)
11317c478bd9Sstevel@tonic-gate {
11327c478bd9Sstevel@tonic-gate int i, j;
11337c478bd9Sstevel@tonic-gate
11347c478bd9Sstevel@tonic-gate for (i = 0; i < numwidthentries; i++) {
11357c478bd9Sstevel@tonic-gate if (fwidth[i].basic_unit == basicunit) {
11367c478bd9Sstevel@tonic-gate for (j = 0; j <= 4; j++) {
11377c478bd9Sstevel@tonic-gate if (fwidth[i].pwidth[j].print_base ==
11388f9294f3Sgww howtoprint) {
11398f9294f3Sgww return (
11408f9294f3Sgww fwidth[i].pwidth[j].field_width);
11418f9294f3Sgww }
11427c478bd9Sstevel@tonic-gate }
11437c478bd9Sstevel@tonic-gate /*
11447c478bd9Sstevel@tonic-gate * if we got here, then we didn't get what we were after
11457c478bd9Sstevel@tonic-gate */
11467c478bd9Sstevel@tonic-gate return (0);
11477c478bd9Sstevel@tonic-gate }
11487c478bd9Sstevel@tonic-gate }
11497c478bd9Sstevel@tonic-gate /* if we got here, we didn't get what we wanted either */
11507c478bd9Sstevel@tonic-gate return (0);
11517c478bd9Sstevel@tonic-gate }
11527c478bd9Sstevel@tonic-gate
11537c478bd9Sstevel@tonic-gate
11547c478bd9Sstevel@tonic-gate /*
11557c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
11567c478bd9Sstevel@tonic-gate * pa_cmd: Retrieves the cmd item from the input stream.
11577c478bd9Sstevel@tonic-gate * return codes : -1 - error
11587c478bd9Sstevel@tonic-gate * : 0 - successful
11597c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
11607c478bd9Sstevel@tonic-gate */
11617c478bd9Sstevel@tonic-gate int
pa_cmd(pr_context_t * context,int status,int flag)11627c478bd9Sstevel@tonic-gate pa_cmd(pr_context_t *context, int status, int flag)
11637c478bd9Sstevel@tonic-gate {
11647c478bd9Sstevel@tonic-gate char *cmd; /* cmd */
11657c478bd9Sstevel@tonic-gate short length;
11667c478bd9Sstevel@tonic-gate int returnstat;
11677c478bd9Sstevel@tonic-gate uval_t uval;
11687c478bd9Sstevel@tonic-gate
11697c478bd9Sstevel@tonic-gate /*
11707c478bd9Sstevel@tonic-gate * We need to know how much space to allocate for our string, so
11717c478bd9Sstevel@tonic-gate * read the length first, then call pr_adr_char to read those bytes.
11727c478bd9Sstevel@tonic-gate */
11737c478bd9Sstevel@tonic-gate if (status >= 0) {
11747c478bd9Sstevel@tonic-gate if (pr_adr_short(context, &length, 1) == 0) {
11757c478bd9Sstevel@tonic-gate if ((cmd = (char *)malloc(length + 1)) == NULL)
11767c478bd9Sstevel@tonic-gate return (-1);
11777c478bd9Sstevel@tonic-gate if (pr_adr_char(context, cmd, length) == 0) {
11787c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING;
11797c478bd9Sstevel@tonic-gate uval.string_val = cmd;
11807c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag);
11817c478bd9Sstevel@tonic-gate } else {
11827c478bd9Sstevel@tonic-gate returnstat = -1;
11837c478bd9Sstevel@tonic-gate }
11847c478bd9Sstevel@tonic-gate free(cmd);
11857c478bd9Sstevel@tonic-gate return (returnstat);
11867c478bd9Sstevel@tonic-gate } else
11877c478bd9Sstevel@tonic-gate return (-1);
11887c478bd9Sstevel@tonic-gate } else
11897c478bd9Sstevel@tonic-gate return (status);
11907c478bd9Sstevel@tonic-gate }
11917c478bd9Sstevel@tonic-gate
11927c478bd9Sstevel@tonic-gate
11937c478bd9Sstevel@tonic-gate
11947c478bd9Sstevel@tonic-gate /*
11957c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
11967c478bd9Sstevel@tonic-gate * pa_adr_byte : Issues pr_adr_char to retrieve the next ADR item from
11977c478bd9Sstevel@tonic-gate * the input stream pointed to by audit_adr, and prints it
11987c478bd9Sstevel@tonic-gate * as an integer if status >= 0
11997c478bd9Sstevel@tonic-gate * return codes : -1 - error
12007c478bd9Sstevel@tonic-gate * : 0 - successful
12017c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
12027c478bd9Sstevel@tonic-gate */
12037c478bd9Sstevel@tonic-gate int
pa_adr_byte(pr_context_t * context,int status,int flag)12047c478bd9Sstevel@tonic-gate pa_adr_byte(pr_context_t *context, int status, int flag)
12057c478bd9Sstevel@tonic-gate {
12067c478bd9Sstevel@tonic-gate char c;
12077c478bd9Sstevel@tonic-gate uval_t uval;
12087c478bd9Sstevel@tonic-gate
12097c478bd9Sstevel@tonic-gate if (status >= 0) {
12107c478bd9Sstevel@tonic-gate if (pr_adr_char(context, &c, 1) == 0) {
12117c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_BYTE;
12127c478bd9Sstevel@tonic-gate uval.char_val = c;
12137c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag));
12147c478bd9Sstevel@tonic-gate } else
12157c478bd9Sstevel@tonic-gate return (-1);
12167c478bd9Sstevel@tonic-gate } else
12177c478bd9Sstevel@tonic-gate return (status);
12187c478bd9Sstevel@tonic-gate }
12197c478bd9Sstevel@tonic-gate
12207c478bd9Sstevel@tonic-gate /*
12217c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
12227c478bd9Sstevel@tonic-gate * pa_adr_charhex: Issues pr_adr_char to retrieve the next ADR item from
12237c478bd9Sstevel@tonic-gate * the input stream pointed to by audit_adr, and prints it
12247c478bd9Sstevel@tonic-gate * in hexadecimal if status >= 0
12257c478bd9Sstevel@tonic-gate * return codes : -1 - error
12267c478bd9Sstevel@tonic-gate * : 0 - successful
12277c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
12287c478bd9Sstevel@tonic-gate */
12297c478bd9Sstevel@tonic-gate int
pa_adr_charhex(pr_context_t * context,int status,int flag)12307c478bd9Sstevel@tonic-gate pa_adr_charhex(pr_context_t *context, int status, int flag)
12317c478bd9Sstevel@tonic-gate {
12327c478bd9Sstevel@tonic-gate char p[2];
12337c478bd9Sstevel@tonic-gate int returnstat;
12347c478bd9Sstevel@tonic-gate uval_t uval;
12357c478bd9Sstevel@tonic-gate
12367c478bd9Sstevel@tonic-gate if (status >= 0) {
12377c478bd9Sstevel@tonic-gate p[0] = p[1] = 0;
12387c478bd9Sstevel@tonic-gate
12397c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, p, 1)) == 0) {
12407c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING;
12417c478bd9Sstevel@tonic-gate uval.string_val = hexconvert(p, sizeof (char),
12427c478bd9Sstevel@tonic-gate sizeof (char));
12437c478bd9Sstevel@tonic-gate if (uval.string_val) {
12447c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag);
12457c478bd9Sstevel@tonic-gate free(uval.string_val);
12467c478bd9Sstevel@tonic-gate }
12477c478bd9Sstevel@tonic-gate }
12487c478bd9Sstevel@tonic-gate return (returnstat);
12497c478bd9Sstevel@tonic-gate } else
12507c478bd9Sstevel@tonic-gate return (status);
12517c478bd9Sstevel@tonic-gate }
12527c478bd9Sstevel@tonic-gate
12537c478bd9Sstevel@tonic-gate /*
12547c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
12557c478bd9Sstevel@tonic-gate * pa_adr_int32 : Issues pr_adr_int32 to retrieve the next ADR item from the
12567c478bd9Sstevel@tonic-gate * input stream pointed to by audit_adr, and prints it
12577c478bd9Sstevel@tonic-gate * if status >= 0
12587c478bd9Sstevel@tonic-gate * return codes : -1 - error
12597c478bd9Sstevel@tonic-gate * : 0 - successful
12607c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
12617c478bd9Sstevel@tonic-gate */
12627c478bd9Sstevel@tonic-gate int
pa_adr_int32(pr_context_t * context,int status,int flag)12637c478bd9Sstevel@tonic-gate pa_adr_int32(pr_context_t *context, int status, int flag)
12647c478bd9Sstevel@tonic-gate {
12657c478bd9Sstevel@tonic-gate int32_t c;
12667c478bd9Sstevel@tonic-gate uval_t uval;
12677c478bd9Sstevel@tonic-gate
12687c478bd9Sstevel@tonic-gate if (status >= 0) {
12697c478bd9Sstevel@tonic-gate if (pr_adr_int32(context, &c, 1) == 0) {
12707c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_INT32;
12717c478bd9Sstevel@tonic-gate uval.int32_val = c;
12727c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag));
12737c478bd9Sstevel@tonic-gate } else
12747c478bd9Sstevel@tonic-gate return (-1);
12757c478bd9Sstevel@tonic-gate } else
12767c478bd9Sstevel@tonic-gate return (status);
12777c478bd9Sstevel@tonic-gate }
12787c478bd9Sstevel@tonic-gate
12797c478bd9Sstevel@tonic-gate
12807c478bd9Sstevel@tonic-gate
12817c478bd9Sstevel@tonic-gate
12827c478bd9Sstevel@tonic-gate /*
12837c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
12847c478bd9Sstevel@tonic-gate * pa_adr_int64 : Issues pr_adr_int64 to retrieve the next ADR item from the
12857c478bd9Sstevel@tonic-gate * input stream pointed to by audit_adr, and prints it
12867c478bd9Sstevel@tonic-gate * if status >= 0
12877c478bd9Sstevel@tonic-gate * return codes : -1 - error
12887c478bd9Sstevel@tonic-gate * : 0 - successful
12897c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
12907c478bd9Sstevel@tonic-gate */
12917c478bd9Sstevel@tonic-gate int
pa_adr_int64(pr_context_t * context,int status,int flag)12927c478bd9Sstevel@tonic-gate pa_adr_int64(pr_context_t *context, int status, int flag)
12937c478bd9Sstevel@tonic-gate {
12947c478bd9Sstevel@tonic-gate int64_t c;
12957c478bd9Sstevel@tonic-gate uval_t uval;
12967c478bd9Sstevel@tonic-gate
12977c478bd9Sstevel@tonic-gate if (status >= 0) {
12987c478bd9Sstevel@tonic-gate if (pr_adr_int64(context, &c, 1) == 0) {
12997c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_INT64;
13007c478bd9Sstevel@tonic-gate uval.int64_val = c;
13017c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag));
13027c478bd9Sstevel@tonic-gate } else
13037c478bd9Sstevel@tonic-gate return (-1);
13047c478bd9Sstevel@tonic-gate } else
13057c478bd9Sstevel@tonic-gate return (status);
13067c478bd9Sstevel@tonic-gate }
13077c478bd9Sstevel@tonic-gate
13087c478bd9Sstevel@tonic-gate /*
13097c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
13107c478bd9Sstevel@tonic-gate * pa_adr_int64hex: Issues pr_adr_int64 to retrieve the next ADR item from the
13117c478bd9Sstevel@tonic-gate * input stream pointed to by audit_adr, and prints it
13127c478bd9Sstevel@tonic-gate * in hexadecimal if status >= 0
13137c478bd9Sstevel@tonic-gate * return codes : -1 - error
13147c478bd9Sstevel@tonic-gate * : 0 - successful
13157c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
13167c478bd9Sstevel@tonic-gate */
13177c478bd9Sstevel@tonic-gate int
pa_adr_int32hex(pr_context_t * context,int status,int flag)13187c478bd9Sstevel@tonic-gate pa_adr_int32hex(pr_context_t *context, int status, int flag)
13197c478bd9Sstevel@tonic-gate {
13207c478bd9Sstevel@tonic-gate int32_t l;
13217c478bd9Sstevel@tonic-gate int returnstat;
13227c478bd9Sstevel@tonic-gate uval_t uval;
13237c478bd9Sstevel@tonic-gate
13247c478bd9Sstevel@tonic-gate if (status >= 0) {
13257c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_int32(context, &l, 1)) == 0) {
13267c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_HEX32;
13277c478bd9Sstevel@tonic-gate uval.int32_val = l;
13287c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag);
13297c478bd9Sstevel@tonic-gate }
13307c478bd9Sstevel@tonic-gate return (returnstat);
13317c478bd9Sstevel@tonic-gate } else
13327c478bd9Sstevel@tonic-gate return (status);
13337c478bd9Sstevel@tonic-gate }
13347c478bd9Sstevel@tonic-gate
13357c478bd9Sstevel@tonic-gate /*
13367c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
13377c478bd9Sstevel@tonic-gate * pa_adr_int64hex: Issues pr_adr_int64 to retrieve the next ADR item from the
13387c478bd9Sstevel@tonic-gate * input stream pointed to by audit_adr, and prints it
13397c478bd9Sstevel@tonic-gate * in hexadecimal if status >= 0
13407c478bd9Sstevel@tonic-gate * return codes : -1 - error
13417c478bd9Sstevel@tonic-gate * : 0 - successful
13427c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
13437c478bd9Sstevel@tonic-gate */
13447c478bd9Sstevel@tonic-gate int
pa_adr_int64hex(pr_context_t * context,int status,int flag)13457c478bd9Sstevel@tonic-gate pa_adr_int64hex(pr_context_t *context, int status, int flag)
13467c478bd9Sstevel@tonic-gate {
13477c478bd9Sstevel@tonic-gate int64_t l;
13487c478bd9Sstevel@tonic-gate int returnstat;
13497c478bd9Sstevel@tonic-gate uval_t uval;
13507c478bd9Sstevel@tonic-gate
13517c478bd9Sstevel@tonic-gate if (status >= 0) {
13527c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_int64(context, &l, 1)) == 0) {
13537c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_HEX64;
13547c478bd9Sstevel@tonic-gate uval.int64_val = l;
13557c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag);
13567c478bd9Sstevel@tonic-gate }
13577c478bd9Sstevel@tonic-gate return (returnstat);
13587c478bd9Sstevel@tonic-gate } else
13597c478bd9Sstevel@tonic-gate return (status);
13607c478bd9Sstevel@tonic-gate }
13617c478bd9Sstevel@tonic-gate
13627c478bd9Sstevel@tonic-gate
13637c478bd9Sstevel@tonic-gate /*
13647c478bd9Sstevel@tonic-gate * -------------------------------------------------------------------
13657c478bd9Sstevel@tonic-gate * bu2string: Maps a print basic unit type to a string.
13667c478bd9Sstevel@tonic-gate * returns : The string mapping or "unknown basic unit type".
13677c478bd9Sstevel@tonic-gate * -------------------------------------------------------------------
13687c478bd9Sstevel@tonic-gate */
13697c478bd9Sstevel@tonic-gate char *
bu2string(char basic_unit)13707c478bd9Sstevel@tonic-gate bu2string(char basic_unit)
13717c478bd9Sstevel@tonic-gate {
13727c478bd9Sstevel@tonic-gate register int i;
13737c478bd9Sstevel@tonic-gate
13747c478bd9Sstevel@tonic-gate struct bu_map_ent {
13757c478bd9Sstevel@tonic-gate char basic_unit;
13767c478bd9Sstevel@tonic-gate char *string;
13777c478bd9Sstevel@tonic-gate };
13787c478bd9Sstevel@tonic-gate
13797c478bd9Sstevel@tonic-gate /*
13807c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE
13817c478bd9Sstevel@tonic-gate * These names are data units when displaying the arbitrary data
13827c478bd9Sstevel@tonic-gate * token.
13837c478bd9Sstevel@tonic-gate */
13847c478bd9Sstevel@tonic-gate
13857c478bd9Sstevel@tonic-gate static struct bu_map_ent bu_map[] = {
13867c478bd9Sstevel@tonic-gate { AUR_BYTE, "byte" },
13877c478bd9Sstevel@tonic-gate { AUR_CHAR, "char" },
13887c478bd9Sstevel@tonic-gate { AUR_SHORT, "short" },
13897c478bd9Sstevel@tonic-gate { AUR_INT32, "int32" },
1390*8bb3e7e3SPeter Tribble { AUR_INT64, "int64" } };
13917c478bd9Sstevel@tonic-gate
13927c478bd9Sstevel@tonic-gate for (i = 0; i < sizeof (bu_map) / sizeof (struct bu_map_ent); i++)
13937c478bd9Sstevel@tonic-gate if (basic_unit == bu_map[i].basic_unit)
13947c478bd9Sstevel@tonic-gate return (gettext(bu_map[i].string));
13957c478bd9Sstevel@tonic-gate
13967c478bd9Sstevel@tonic-gate return (gettext("unknown basic unit type"));
13977c478bd9Sstevel@tonic-gate }
13987c478bd9Sstevel@tonic-gate
13997c478bd9Sstevel@tonic-gate
14007c478bd9Sstevel@tonic-gate /*
14017c478bd9Sstevel@tonic-gate * -------------------------------------------------------------------
14027c478bd9Sstevel@tonic-gate * eventmodifier2string: Maps event modifier flags to a readable string.
14037c478bd9Sstevel@tonic-gate * returns: The string mapping or "none".
14047c478bd9Sstevel@tonic-gate * -------------------------------------------------------------------
14057c478bd9Sstevel@tonic-gate */
14067c478bd9Sstevel@tonic-gate static void
eventmodifier2string(au_emod_t emodifier,char * modstring,size_t modlen)1407d0fa49b7STony Nguyen eventmodifier2string(au_emod_t emodifier, char *modstring, size_t modlen)
14087c478bd9Sstevel@tonic-gate {
14097c478bd9Sstevel@tonic-gate register int i, j;
14107c478bd9Sstevel@tonic-gate
14117c478bd9Sstevel@tonic-gate struct em_map_ent {
14127c478bd9Sstevel@tonic-gate int mask;
14137c478bd9Sstevel@tonic-gate char *string;
14147c478bd9Sstevel@tonic-gate };
14157c478bd9Sstevel@tonic-gate
14167c478bd9Sstevel@tonic-gate /*
14177c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE
14187c478bd9Sstevel@tonic-gate * These abbreviations represent the event modifier field of the
14197c478bd9Sstevel@tonic-gate * header token. To gain a better understanding of each modifier,
14208f9294f3Sgww * read
14218f9294f3Sgww * System Administration Guide: Security Services >> Solaris Auditing
14228f9294f3Sgww * at http://docs.sun.com.
14237c478bd9Sstevel@tonic-gate */
14247c478bd9Sstevel@tonic-gate
14257c478bd9Sstevel@tonic-gate static struct em_map_ent em_map[] = {
14267c478bd9Sstevel@tonic-gate { (int)PAD_READ, "rd" }, /* data read from object */
14277c478bd9Sstevel@tonic-gate { (int)PAD_WRITE, "wr" }, /* data written to object */
14287c478bd9Sstevel@tonic-gate { (int)PAD_SPRIVUSE, "sp" }, /* successfully used priv */
14297c478bd9Sstevel@tonic-gate { (int)PAD_FPRIVUSE, "fp" }, /* failed use of priv */
14307c478bd9Sstevel@tonic-gate { (int)PAD_NONATTR, "na" }, /* non-attributable event */
14317c478bd9Sstevel@tonic-gate { (int)PAD_FAILURE, "fe" } /* fail audit event */
14327c478bd9Sstevel@tonic-gate };
14337c478bd9Sstevel@tonic-gate
14347c478bd9Sstevel@tonic-gate modstring[0] = '\0';
14357c478bd9Sstevel@tonic-gate
14367c478bd9Sstevel@tonic-gate for (i = 0, j = 0; i < sizeof (em_map) / sizeof (struct em_map_ent);
14377c478bd9Sstevel@tonic-gate i++) {
14387c478bd9Sstevel@tonic-gate if ((int)emodifier & em_map[i].mask) {
14397c478bd9Sstevel@tonic-gate if (j++)
14407c478bd9Sstevel@tonic-gate (void) strlcat(modstring, ":", modlen);
14417c478bd9Sstevel@tonic-gate (void) strlcat(modstring, em_map[i].string, modlen);
14427c478bd9Sstevel@tonic-gate }
14437c478bd9Sstevel@tonic-gate }
14447c478bd9Sstevel@tonic-gate }
14457c478bd9Sstevel@tonic-gate
14467c478bd9Sstevel@tonic-gate
14477c478bd9Sstevel@tonic-gate /*
14487c478bd9Sstevel@tonic-gate * ---------------------------------------------------------
14497c478bd9Sstevel@tonic-gate * convert_char_to_string:
14507c478bd9Sstevel@tonic-gate * Converts a byte to string depending on the print mode
14517c478bd9Sstevel@tonic-gate * input : printmode, which may be one of AUP_BINARY,
14527c478bd9Sstevel@tonic-gate * AUP_OCTAL, AUP_DECIMAL, and AUP_HEX
14537c478bd9Sstevel@tonic-gate * c, which is the byte to convert
14547c478bd9Sstevel@tonic-gate * output : p, which is a pointer to the location where
14557c478bd9Sstevel@tonic-gate * the resulting string is to be stored
14567c478bd9Sstevel@tonic-gate * ----------------------------------------------------------
14577c478bd9Sstevel@tonic-gate */
14587c478bd9Sstevel@tonic-gate
14597c478bd9Sstevel@tonic-gate int
convert_char_to_string(char printmode,char c,char * p)14607c478bd9Sstevel@tonic-gate convert_char_to_string(char printmode, char c, char *p)
14617c478bd9Sstevel@tonic-gate {
14627c478bd9Sstevel@tonic-gate union {
14637c478bd9Sstevel@tonic-gate char c1[4];
14647c478bd9Sstevel@tonic-gate int c2;
14657c478bd9Sstevel@tonic-gate } dat;
14667c478bd9Sstevel@tonic-gate
14677c478bd9Sstevel@tonic-gate dat.c2 = 0;
14687c478bd9Sstevel@tonic-gate dat.c1[3] = c;
14697c478bd9Sstevel@tonic-gate
14707c478bd9Sstevel@tonic-gate if (printmode == AUP_BINARY)
14717c478bd9Sstevel@tonic-gate (void) convertbinary(p, &c, sizeof (char));
14727c478bd9Sstevel@tonic-gate else if (printmode == AUP_OCTAL)
14737c478bd9Sstevel@tonic-gate (void) sprintf(p, "%o", (int)dat.c2);
14747c478bd9Sstevel@tonic-gate else if (printmode == AUP_DECIMAL)
14757c478bd9Sstevel@tonic-gate (void) sprintf(p, "%d", c);
14767c478bd9Sstevel@tonic-gate else if (printmode == AUP_HEX)
14777c478bd9Sstevel@tonic-gate (void) sprintf(p, "0x%x", (int)dat.c2);
14787c478bd9Sstevel@tonic-gate else if (printmode == AUP_STRING)
14797c478bd9Sstevel@tonic-gate convertascii(p, &c, sizeof (char));
14807c478bd9Sstevel@tonic-gate return (0);
14817c478bd9Sstevel@tonic-gate }
14827c478bd9Sstevel@tonic-gate
14837c478bd9Sstevel@tonic-gate /*
14847c478bd9Sstevel@tonic-gate * --------------------------------------------------------------
14857c478bd9Sstevel@tonic-gate * convert_short_to_string:
14867c478bd9Sstevel@tonic-gate * Converts a short integer to string depending on the print mode
14877c478bd9Sstevel@tonic-gate * input : printmode, which may be one of AUP_BINARY,
14887c478bd9Sstevel@tonic-gate * AUP_OCTAL, AUP_DECIMAL, and AUP_HEX
14897c478bd9Sstevel@tonic-gate * c, which is the short integer to convert
14907c478bd9Sstevel@tonic-gate * output : p, which is a pointer to the location where
14917c478bd9Sstevel@tonic-gate * the resulting string is to be stored
14927c478bd9Sstevel@tonic-gate * ---------------------------------------------------------------
14937c478bd9Sstevel@tonic-gate */
14947c478bd9Sstevel@tonic-gate int
convert_short_to_string(char printmode,short c,char * p)14957c478bd9Sstevel@tonic-gate convert_short_to_string(char printmode, short c, char *p)
14967c478bd9Sstevel@tonic-gate {
14977c478bd9Sstevel@tonic-gate union {
14987c478bd9Sstevel@tonic-gate short c1[2];
14997c478bd9Sstevel@tonic-gate int c2;
15007c478bd9Sstevel@tonic-gate } dat;
15017c478bd9Sstevel@tonic-gate
15027c478bd9Sstevel@tonic-gate dat.c2 = 0;
15037c478bd9Sstevel@tonic-gate dat.c1[1] = c;
15047c478bd9Sstevel@tonic-gate
15057c478bd9Sstevel@tonic-gate if (printmode == AUP_BINARY)
15067c478bd9Sstevel@tonic-gate (void) convertbinary(p, (char *)&c, sizeof (short));
15077c478bd9Sstevel@tonic-gate else if (printmode == AUP_OCTAL)
15087c478bd9Sstevel@tonic-gate (void) sprintf(p, "%o", (int)dat.c2);
15097c478bd9Sstevel@tonic-gate else if (printmode == AUP_DECIMAL)
15107c478bd9Sstevel@tonic-gate (void) sprintf(p, "%hd", c);
15117c478bd9Sstevel@tonic-gate else if (printmode == AUP_HEX)
15127c478bd9Sstevel@tonic-gate (void) sprintf(p, "0x%x", (int)dat.c2);
15137c478bd9Sstevel@tonic-gate else if (printmode == AUP_STRING)
15147c478bd9Sstevel@tonic-gate convertascii(p, (char *)&c, sizeof (short));
15157c478bd9Sstevel@tonic-gate return (0);
15167c478bd9Sstevel@tonic-gate }
15177c478bd9Sstevel@tonic-gate
15187c478bd9Sstevel@tonic-gate /*
15197c478bd9Sstevel@tonic-gate * ---------------------------------------------------------
15207c478bd9Sstevel@tonic-gate * convert_int32_to_string:
15217c478bd9Sstevel@tonic-gate * Converts a integer to string depending on the print mode
15227c478bd9Sstevel@tonic-gate * input : printmode, which may be one of AUP_BINARY,
15237c478bd9Sstevel@tonic-gate * AUP_OCTAL, AUP_DECIMAL, and AUP_HEX
15247c478bd9Sstevel@tonic-gate * c, which is the integer to convert
15257c478bd9Sstevel@tonic-gate * output : p, which is a pointer to the location where
15267c478bd9Sstevel@tonic-gate * the resulting string is to be stored
15277c478bd9Sstevel@tonic-gate * ----------------------------------------------------------
15287c478bd9Sstevel@tonic-gate */
15297c478bd9Sstevel@tonic-gate int
convert_int32_to_string(char printmode,int32_t c,char * p)15307c478bd9Sstevel@tonic-gate convert_int32_to_string(char printmode, int32_t c, char *p)
15317c478bd9Sstevel@tonic-gate {
15327c478bd9Sstevel@tonic-gate if (printmode == AUP_BINARY)
15337c478bd9Sstevel@tonic-gate (void) convertbinary(p, (char *)&c, sizeof (int32_t));
15347c478bd9Sstevel@tonic-gate else if (printmode == AUP_OCTAL)
15357c478bd9Sstevel@tonic-gate (void) sprintf(p, "%o", c);
15367c478bd9Sstevel@tonic-gate else if (printmode == AUP_DECIMAL)
15377c478bd9Sstevel@tonic-gate (void) sprintf(p, "%d", c);
15387c478bd9Sstevel@tonic-gate else if (printmode == AUP_HEX)
15397c478bd9Sstevel@tonic-gate (void) sprintf(p, "0x%x", c);
15407c478bd9Sstevel@tonic-gate else if (printmode == AUP_STRING)
15417c478bd9Sstevel@tonic-gate convertascii(p, (char *)&c, sizeof (int));
15427c478bd9Sstevel@tonic-gate return (0);
15437c478bd9Sstevel@tonic-gate }
15447c478bd9Sstevel@tonic-gate
15457c478bd9Sstevel@tonic-gate /*
15467c478bd9Sstevel@tonic-gate * ---------------------------------------------------------
15477c478bd9Sstevel@tonic-gate * convert_int64_to_string:
15487c478bd9Sstevel@tonic-gate * Converts a integer to string depending on the print mode
15497c478bd9Sstevel@tonic-gate * input : printmode, which may be one of AUP_BINARY,
15507c478bd9Sstevel@tonic-gate * AUP_OCTAL, AUP_DECIMAL, and AUP_HEX
15517c478bd9Sstevel@tonic-gate * c, which is the integer to convert
15527c478bd9Sstevel@tonic-gate * output : p, which is a pointer to the location where
15537c478bd9Sstevel@tonic-gate * the resulting string is to be stored
15547c478bd9Sstevel@tonic-gate * ----------------------------------------------------------
15557c478bd9Sstevel@tonic-gate */
15567c478bd9Sstevel@tonic-gate int
convert_int64_to_string(char printmode,int64_t c,char * p)15577c478bd9Sstevel@tonic-gate convert_int64_to_string(char printmode, int64_t c, char *p)
15587c478bd9Sstevel@tonic-gate {
15597c478bd9Sstevel@tonic-gate if (printmode == AUP_BINARY)
15607c478bd9Sstevel@tonic-gate (void) convertbinary(p, (char *)&c, sizeof (int64_t));
15617c478bd9Sstevel@tonic-gate else if (printmode == AUP_OCTAL)
15627c478bd9Sstevel@tonic-gate (void) sprintf(p, "%"PRIo64, c);
15637c478bd9Sstevel@tonic-gate else if (printmode == AUP_DECIMAL)
15647c478bd9Sstevel@tonic-gate (void) sprintf(p, "%"PRId64, c);
15657c478bd9Sstevel@tonic-gate else if (printmode == AUP_HEX)
15667c478bd9Sstevel@tonic-gate (void) sprintf(p, "0x%"PRIx64, c);
15677c478bd9Sstevel@tonic-gate else if (printmode == AUP_STRING)
15687c478bd9Sstevel@tonic-gate convertascii(p, (char *)&c, sizeof (int64_t));
15697c478bd9Sstevel@tonic-gate return (0);
15707c478bd9Sstevel@tonic-gate }
15717c478bd9Sstevel@tonic-gate
15727c478bd9Sstevel@tonic-gate
15737c478bd9Sstevel@tonic-gate /*
15747c478bd9Sstevel@tonic-gate * -----------------------------------------------------------
15757c478bd9Sstevel@tonic-gate * convertbinary:
15767c478bd9Sstevel@tonic-gate * Converts a unit c of 'size' bytes long into a binary string
15777c478bd9Sstevel@tonic-gate * and returns it into the position pointed to by p
15787c478bd9Sstevel@tonic-gate * ------------------------------------------------------------
15797c478bd9Sstevel@tonic-gate */
15807c478bd9Sstevel@tonic-gate int
convertbinary(char * p,char * c,int size)15817c478bd9Sstevel@tonic-gate convertbinary(char *p, char *c, int size)
15827c478bd9Sstevel@tonic-gate {
15837c478bd9Sstevel@tonic-gate char *s, *t, *ss;
15847c478bd9Sstevel@tonic-gate int i, j;
15857c478bd9Sstevel@tonic-gate
15867c478bd9Sstevel@tonic-gate if ((s = (char *)malloc(8 * size + 1)) == NULL)
15877c478bd9Sstevel@tonic-gate return (0);
15887c478bd9Sstevel@tonic-gate
15897c478bd9Sstevel@tonic-gate ss = s;
15907c478bd9Sstevel@tonic-gate
15917c478bd9Sstevel@tonic-gate /* first convert to binary */
15927c478bd9Sstevel@tonic-gate t = s;
15937c478bd9Sstevel@tonic-gate for (i = 0; i < size; i++) {
15947c478bd9Sstevel@tonic-gate for (j = 0; j < 8; j++)
15957c478bd9Sstevel@tonic-gate (void) sprintf(t++, "%d", ((*c >> (7 - j)) & (0x01)));
15967c478bd9Sstevel@tonic-gate c++;
15977c478bd9Sstevel@tonic-gate }
15987c478bd9Sstevel@tonic-gate *t = '\0';
15997c478bd9Sstevel@tonic-gate
16007c478bd9Sstevel@tonic-gate /* now string leading zero's if any */
16017c478bd9Sstevel@tonic-gate j = strlen(s) - 1;
16027c478bd9Sstevel@tonic-gate for (i = 0; i < j; i++) {
16037c478bd9Sstevel@tonic-gate if (*s != '0')
16047c478bd9Sstevel@tonic-gate break;
16057c478bd9Sstevel@tonic-gate else
16067c478bd9Sstevel@tonic-gate s++;
16077c478bd9Sstevel@tonic-gate }
16087c478bd9Sstevel@tonic-gate
16097c478bd9Sstevel@tonic-gate /* now copy the contents of s to p */
16107c478bd9Sstevel@tonic-gate t = p;
16117c478bd9Sstevel@tonic-gate for (i = 0; i < (8 * size + 1); i++) {
16127c478bd9Sstevel@tonic-gate if (*s == '\0') {
16137c478bd9Sstevel@tonic-gate *t = '\0';
16147c478bd9Sstevel@tonic-gate break;
16157c478bd9Sstevel@tonic-gate }
16167c478bd9Sstevel@tonic-gate *t++ = *s++;
16177c478bd9Sstevel@tonic-gate }
16187c478bd9Sstevel@tonic-gate free(ss);
16197c478bd9Sstevel@tonic-gate
16207c478bd9Sstevel@tonic-gate return (1);
16217c478bd9Sstevel@tonic-gate }
16227c478bd9Sstevel@tonic-gate
16237c478bd9Sstevel@tonic-gate
16247c478bd9Sstevel@tonic-gate static char hex[] = "0123456789abcdef";
16257c478bd9Sstevel@tonic-gate /*
16267c478bd9Sstevel@tonic-gate * -------------------------------------------------------------------
16277c478bd9Sstevel@tonic-gate * hexconvert : Converts a string of (size) bytes to hexadecimal, and
16287c478bd9Sstevel@tonic-gate * returns the hexadecimal string.
16297c478bd9Sstevel@tonic-gate * returns : - NULL if memory cannot be allocated for the string, or
16307c478bd9Sstevel@tonic-gate * - pointer to the hexadecimal string if successful
16317c478bd9Sstevel@tonic-gate * -------------------------------------------------------------------
16327c478bd9Sstevel@tonic-gate */
16337c478bd9Sstevel@tonic-gate char *
hexconvert(char * c,int size,int chunk)16347c478bd9Sstevel@tonic-gate hexconvert(char *c, int size, int chunk)
16357c478bd9Sstevel@tonic-gate {
16367c478bd9Sstevel@tonic-gate register char *s, *t;
16377c478bd9Sstevel@tonic-gate register int i, j, k;
16387c478bd9Sstevel@tonic-gate int numchunks;
16397c478bd9Sstevel@tonic-gate int leftovers;
16407c478bd9Sstevel@tonic-gate
16417c478bd9Sstevel@tonic-gate if (size <= 0)
16427c478bd9Sstevel@tonic-gate return (NULL);
16437c478bd9Sstevel@tonic-gate
16447c478bd9Sstevel@tonic-gate if ((s = (char *)malloc((size * 5) + 1)) == NULL)
16457c478bd9Sstevel@tonic-gate return (NULL);
16467c478bd9Sstevel@tonic-gate
16477c478bd9Sstevel@tonic-gate if (chunk > size || chunk <= 0)
16487c478bd9Sstevel@tonic-gate chunk = size;
16497c478bd9Sstevel@tonic-gate
16507c478bd9Sstevel@tonic-gate numchunks = size / chunk;
16517c478bd9Sstevel@tonic-gate leftovers = size % chunk;
16527c478bd9Sstevel@tonic-gate
16537c478bd9Sstevel@tonic-gate t = s;
16547c478bd9Sstevel@tonic-gate for (i = j = 0; i < numchunks; i++) {
16557c478bd9Sstevel@tonic-gate if (j++) {
16567c478bd9Sstevel@tonic-gate *t++ = ' ';
16577c478bd9Sstevel@tonic-gate }
16587c478bd9Sstevel@tonic-gate *t++ = '0';
16597c478bd9Sstevel@tonic-gate *t++ = 'x';
16607c478bd9Sstevel@tonic-gate for (k = 0; k < chunk; k++) {
16617c478bd9Sstevel@tonic-gate *t++ = hex[(uint_t)((uchar_t)*c >> 4)];
16627c478bd9Sstevel@tonic-gate *t++ = hex[(uint_t)((uchar_t)*c & 0xF)];
16637c478bd9Sstevel@tonic-gate c++;
16647c478bd9Sstevel@tonic-gate }
16657c478bd9Sstevel@tonic-gate }
16667c478bd9Sstevel@tonic-gate
16677c478bd9Sstevel@tonic-gate if (leftovers) {
16687c478bd9Sstevel@tonic-gate *t++ = ' ';
16697c478bd9Sstevel@tonic-gate *t++ = '0';
16707c478bd9Sstevel@tonic-gate *t++ = 'x';
16717c478bd9Sstevel@tonic-gate for (i = 0; i < leftovers; i++) {
16727c478bd9Sstevel@tonic-gate *t++ = hex[(uint_t)((uchar_t)*c >> 4)];
16737c478bd9Sstevel@tonic-gate *t++ = hex[(uint_t)((uchar_t)*c & 0xF)];
16747c478bd9Sstevel@tonic-gate c++;
16757c478bd9Sstevel@tonic-gate }
16767c478bd9Sstevel@tonic-gate }
16777c478bd9Sstevel@tonic-gate
16787c478bd9Sstevel@tonic-gate *t = '\0';
16797c478bd9Sstevel@tonic-gate return (s);
16807c478bd9Sstevel@tonic-gate }
16817c478bd9Sstevel@tonic-gate
16827c478bd9Sstevel@tonic-gate
16837c478bd9Sstevel@tonic-gate /*
16847c478bd9Sstevel@tonic-gate * -------------------------------------------------------------------
16857c478bd9Sstevel@tonic-gate * htp2string: Maps a print suggestion to a string.
16867c478bd9Sstevel@tonic-gate * returns : The string mapping or "unknown print suggestion".
16877c478bd9Sstevel@tonic-gate * -------------------------------------------------------------------
16887c478bd9Sstevel@tonic-gate */
16897c478bd9Sstevel@tonic-gate char *
htp2string(char print_sugg)16907c478bd9Sstevel@tonic-gate htp2string(char print_sugg)
16917c478bd9Sstevel@tonic-gate {
16927c478bd9Sstevel@tonic-gate register int i;
16937c478bd9Sstevel@tonic-gate
16947c478bd9Sstevel@tonic-gate struct htp_map_ent {
16957c478bd9Sstevel@tonic-gate char print_sugg;
16967c478bd9Sstevel@tonic-gate char *print_string;
16977c478bd9Sstevel@tonic-gate };
16987c478bd9Sstevel@tonic-gate
16997c478bd9Sstevel@tonic-gate /*
17007c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE
17017c478bd9Sstevel@tonic-gate * These names are data types when displaying the arbitrary data
17027c478bd9Sstevel@tonic-gate * token.
17037c478bd9Sstevel@tonic-gate */
17047c478bd9Sstevel@tonic-gate
17057c478bd9Sstevel@tonic-gate static struct htp_map_ent htp_map[] = {
17067c478bd9Sstevel@tonic-gate { AUP_BINARY, "binary" },
17077c478bd9Sstevel@tonic-gate { AUP_OCTAL, "octal" },
17087c478bd9Sstevel@tonic-gate { AUP_DECIMAL, "decimal" },
17097c478bd9Sstevel@tonic-gate { AUP_HEX, "hexadecimal" },
1710*8bb3e7e3SPeter Tribble { AUP_STRING, "string" } };
17117c478bd9Sstevel@tonic-gate
17127c478bd9Sstevel@tonic-gate for (i = 0; i < sizeof (htp_map) / sizeof (struct htp_map_ent); i++)
17137c478bd9Sstevel@tonic-gate if (print_sugg == htp_map[i].print_sugg)
17147c478bd9Sstevel@tonic-gate return (gettext(htp_map[i].print_string));
17157c478bd9Sstevel@tonic-gate
17167c478bd9Sstevel@tonic-gate return (gettext("unknown print suggestion"));
17177c478bd9Sstevel@tonic-gate }
17187c478bd9Sstevel@tonic-gate
17197c478bd9Sstevel@tonic-gate /*
17207c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------
17217c478bd9Sstevel@tonic-gate * pa_adr_short: Issues pr_adr_short to retrieve the next ADR item from the
17227c478bd9Sstevel@tonic-gate * input stream pointed to by audit_adr, and prints it
17237c478bd9Sstevel@tonic-gate * if status >= 0
17247c478bd9Sstevel@tonic-gate * return codes: -1 - error
17257c478bd9Sstevel@tonic-gate * : 0 - successful
17267c478bd9Sstevel@tonic-gate * ----------------------------------------------------------------------
17277c478bd9Sstevel@tonic-gate */
17287c478bd9Sstevel@tonic-gate int
pa_adr_short(pr_context_t * context,int status,int flag)17297c478bd9Sstevel@tonic-gate pa_adr_short(pr_context_t *context, int status, int flag)
17307c478bd9Sstevel@tonic-gate {
17317c478bd9Sstevel@tonic-gate short c;
17327c478bd9Sstevel@tonic-gate uval_t uval;
17337c478bd9Sstevel@tonic-gate
17347c478bd9Sstevel@tonic-gate if (status >= 0) {
17357c478bd9Sstevel@tonic-gate if (pr_adr_short(context, &c, 1) == 0) {
17367c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_SHORT;
17377c478bd9Sstevel@tonic-gate uval.short_val = c;
17387c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag));
17397c478bd9Sstevel@tonic-gate } else
17407c478bd9Sstevel@tonic-gate return (-1);
17417c478bd9Sstevel@tonic-gate } else
17427c478bd9Sstevel@tonic-gate return (status);
17437c478bd9Sstevel@tonic-gate }
17447c478bd9Sstevel@tonic-gate
17457c478bd9Sstevel@tonic-gate /*
17467c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
17477c478bd9Sstevel@tonic-gate * pa_adr_shorthex: Issues pr_adr_short to retrieve the next ADR item from the
17487c478bd9Sstevel@tonic-gate * input stream pointed to by audit_adr, and prints it
17497c478bd9Sstevel@tonic-gate * in hexadecimal if status >= 0
17507c478bd9Sstevel@tonic-gate * return codes : -1 - error
17517c478bd9Sstevel@tonic-gate * : 0 - successful
17527c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
17537c478bd9Sstevel@tonic-gate */
17547c478bd9Sstevel@tonic-gate int
pa_adr_shorthex(pr_context_t * context,int status,int flag)17557c478bd9Sstevel@tonic-gate pa_adr_shorthex(pr_context_t *context, int status, int flag)
17567c478bd9Sstevel@tonic-gate {
17577c478bd9Sstevel@tonic-gate short s;
17587c478bd9Sstevel@tonic-gate int returnstat;
17597c478bd9Sstevel@tonic-gate uval_t uval;
17607c478bd9Sstevel@tonic-gate
17617c478bd9Sstevel@tonic-gate if (status >= 0) {
17627c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_short(context, &s, 1)) == 0) {
17637c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING;
17647c478bd9Sstevel@tonic-gate uval.string_val = hexconvert((char *)&s, sizeof (s),
17657c478bd9Sstevel@tonic-gate sizeof (s));
17667c478bd9Sstevel@tonic-gate if (uval.string_val) {
17677c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag);
17687c478bd9Sstevel@tonic-gate free(uval.string_val);
17697c478bd9Sstevel@tonic-gate }
17707c478bd9Sstevel@tonic-gate }
17717c478bd9Sstevel@tonic-gate return (returnstat);
17727c478bd9Sstevel@tonic-gate } else
17737c478bd9Sstevel@tonic-gate return (status);
17747c478bd9Sstevel@tonic-gate }
17757c478bd9Sstevel@tonic-gate
17767c478bd9Sstevel@tonic-gate
17777c478bd9Sstevel@tonic-gate /*
17787c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
17797c478bd9Sstevel@tonic-gate * pa_adr_string: Retrieves a string from the input stream and prints it
17807c478bd9Sstevel@tonic-gate * if status >= 0
17817c478bd9Sstevel@tonic-gate * return codes : -1 - error
17827c478bd9Sstevel@tonic-gate * : 0 - successful
17837c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
17847c478bd9Sstevel@tonic-gate */
17857c478bd9Sstevel@tonic-gate int
pa_adr_string(pr_context_t * context,int status,int flag)17867c478bd9Sstevel@tonic-gate pa_adr_string(pr_context_t *context, int status, int flag)
17877c478bd9Sstevel@tonic-gate {
17887c478bd9Sstevel@tonic-gate char *c;
17897c478bd9Sstevel@tonic-gate short length;
17907c478bd9Sstevel@tonic-gate int returnstat;
17917c478bd9Sstevel@tonic-gate uval_t uval;
17927c478bd9Sstevel@tonic-gate
17937c478bd9Sstevel@tonic-gate /*
17947c478bd9Sstevel@tonic-gate * We need to know how much space to allocate for our string, so
17957c478bd9Sstevel@tonic-gate * read the length first, then call pr_adr_char to read those bytes.
17967c478bd9Sstevel@tonic-gate */
17977c478bd9Sstevel@tonic-gate if (status < 0)
17987c478bd9Sstevel@tonic-gate return (status);
17997c478bd9Sstevel@tonic-gate
18007c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_short(context, &length, 1)) != 0)
18017c478bd9Sstevel@tonic-gate return (returnstat);
18027c478bd9Sstevel@tonic-gate if ((c = (char *)malloc(length + 1)) == NULL)
18037c478bd9Sstevel@tonic-gate return (-1);
18047c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, c, length)) != 0) {
18057c478bd9Sstevel@tonic-gate free(c);
18067c478bd9Sstevel@tonic-gate return (returnstat);
18077c478bd9Sstevel@tonic-gate }
180885298dc1Snakanon
18097c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING;
181085298dc1Snakanon uval.string_val = c;
18117c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag);
18127c478bd9Sstevel@tonic-gate free(c);
18137c478bd9Sstevel@tonic-gate return (returnstat);
18147c478bd9Sstevel@tonic-gate }
18157c478bd9Sstevel@tonic-gate
18167c478bd9Sstevel@tonic-gate /*
18177c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
18187c478bd9Sstevel@tonic-gate * pa_file_string: Retrieves a file string from the input stream and prints it
18197c478bd9Sstevel@tonic-gate * if status >= 0
18207c478bd9Sstevel@tonic-gate * return codes : -1 - error
18217c478bd9Sstevel@tonic-gate * : 0 - successful
18227c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
18237c478bd9Sstevel@tonic-gate */
18247c478bd9Sstevel@tonic-gate int
pa_file_string(pr_context_t * context,int status,int flag)18257c478bd9Sstevel@tonic-gate pa_file_string(pr_context_t *context, int status, int flag)
18267c478bd9Sstevel@tonic-gate {
18277c478bd9Sstevel@tonic-gate char *c;
18287c478bd9Sstevel@tonic-gate char *p;
18297c478bd9Sstevel@tonic-gate short length;
18307c478bd9Sstevel@tonic-gate int returnstat;
18317c478bd9Sstevel@tonic-gate uval_t uval;
18327c478bd9Sstevel@tonic-gate
18337c478bd9Sstevel@tonic-gate /*
18347c478bd9Sstevel@tonic-gate * We need to know how much space to allocate for our string, so
18357c478bd9Sstevel@tonic-gate * read the length first, then call pr_adr_char to read those bytes.
18367c478bd9Sstevel@tonic-gate */
18377c478bd9Sstevel@tonic-gate if (status < 0)
18387c478bd9Sstevel@tonic-gate return (status);
18397c478bd9Sstevel@tonic-gate
18407c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_short(context, &length, 1)) != 0)
18417c478bd9Sstevel@tonic-gate return (returnstat);
18427c478bd9Sstevel@tonic-gate if ((c = (char *)malloc(length + 1)) == NULL)
18437c478bd9Sstevel@tonic-gate return (-1);
184485298dc1Snakanon if ((p = (char *)malloc((length * 4) + 1)) == NULL) {
18457c478bd9Sstevel@tonic-gate free(c);
18467c478bd9Sstevel@tonic-gate return (-1);
18477c478bd9Sstevel@tonic-gate }
18487c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_char(context, c, length)) != 0) {
18497c478bd9Sstevel@tonic-gate free(c);
18507c478bd9Sstevel@tonic-gate free(p);
18517c478bd9Sstevel@tonic-gate return (returnstat);
18527c478bd9Sstevel@tonic-gate }
18537c478bd9Sstevel@tonic-gate
18547c478bd9Sstevel@tonic-gate if (is_file_token(context->tokenid))
18557c478bd9Sstevel@tonic-gate context->audit_rec_len += length;
18567c478bd9Sstevel@tonic-gate
18577c478bd9Sstevel@tonic-gate convertascii(p, c, length - 1);
18587c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING;
18597c478bd9Sstevel@tonic-gate uval.string_val = p;
18607c478bd9Sstevel@tonic-gate
18617c478bd9Sstevel@tonic-gate if (returnstat == 0)
18627c478bd9Sstevel@tonic-gate returnstat = finish_open_tag(context);
18637c478bd9Sstevel@tonic-gate
18647c478bd9Sstevel@tonic-gate if (returnstat == 0)
18657c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag);
18667c478bd9Sstevel@tonic-gate
18677c478bd9Sstevel@tonic-gate free(c);
18687c478bd9Sstevel@tonic-gate free(p);
18697c478bd9Sstevel@tonic-gate return (returnstat);
18707c478bd9Sstevel@tonic-gate }
18717c478bd9Sstevel@tonic-gate
18727c478bd9Sstevel@tonic-gate static int
pa_putstr_xml(pr_context_t * context,int printable,char * str,size_t len)18737c478bd9Sstevel@tonic-gate pa_putstr_xml(pr_context_t *context, int printable, char *str, size_t len)
18747c478bd9Sstevel@tonic-gate {
18757c478bd9Sstevel@tonic-gate int err;
18767c478bd9Sstevel@tonic-gate
18777c478bd9Sstevel@tonic-gate if (!printable) {
18787c478bd9Sstevel@tonic-gate /*
18797c478bd9Sstevel@tonic-gate * Unprintable chars should always be converted to the
18807c478bd9Sstevel@tonic-gate * visible form. If there are unprintable characters which
18817c478bd9Sstevel@tonic-gate * require special treatment in xml, those should be
18827c478bd9Sstevel@tonic-gate * handled here.
18837c478bd9Sstevel@tonic-gate */
18847c478bd9Sstevel@tonic-gate do {
18857c478bd9Sstevel@tonic-gate err = pr_printf(context, "\\%03o",
18868f9294f3Sgww (unsigned char)*str++);
18877c478bd9Sstevel@tonic-gate } while (err == 0 && --len != 0);
18887c478bd9Sstevel@tonic-gate return (err);
18897c478bd9Sstevel@tonic-gate }
18907c478bd9Sstevel@tonic-gate /* printable characters */
18917c478bd9Sstevel@tonic-gate if (len == 1) {
18927c478bd9Sstevel@tonic-gate /*
18937c478bd9Sstevel@tonic-gate * check for the special chars only when char size was 1
18947c478bd9Sstevel@tonic-gate * ie, ignore special chars appear in the middle of multibyte
18957c478bd9Sstevel@tonic-gate * sequence.
18967c478bd9Sstevel@tonic-gate */
18977c478bd9Sstevel@tonic-gate
18987c478bd9Sstevel@tonic-gate /* Escape for XML */
18997c478bd9Sstevel@tonic-gate switch (*str) {
19007c478bd9Sstevel@tonic-gate case '&':
19017c478bd9Sstevel@tonic-gate err = pr_printf(context, "%s", "&");
19027c478bd9Sstevel@tonic-gate break;
19037c478bd9Sstevel@tonic-gate
19047c478bd9Sstevel@tonic-gate case '<':
19057c478bd9Sstevel@tonic-gate err = pr_printf(context, "%s", "<");
19067c478bd9Sstevel@tonic-gate break;
19077c478bd9Sstevel@tonic-gate
19087c478bd9Sstevel@tonic-gate case '>':
19097c478bd9Sstevel@tonic-gate err = pr_printf(context, "%s", ">");
19107c478bd9Sstevel@tonic-gate break;
19117c478bd9Sstevel@tonic-gate
19127c478bd9Sstevel@tonic-gate case '\"':
19137c478bd9Sstevel@tonic-gate err = pr_printf(context, "%s", """);
19147c478bd9Sstevel@tonic-gate break;
19157c478bd9Sstevel@tonic-gate
19167c478bd9Sstevel@tonic-gate case '\'':
19177c478bd9Sstevel@tonic-gate err = pr_printf(context, "%s", "'");
19187c478bd9Sstevel@tonic-gate break;
19197c478bd9Sstevel@tonic-gate
19207c478bd9Sstevel@tonic-gate default:
19217c478bd9Sstevel@tonic-gate err = pr_putchar(context, *str);
19227c478bd9Sstevel@tonic-gate break;
19237c478bd9Sstevel@tonic-gate }
19247c478bd9Sstevel@tonic-gate return (err);
19257c478bd9Sstevel@tonic-gate }
19267c478bd9Sstevel@tonic-gate do {
19277c478bd9Sstevel@tonic-gate err = pr_putchar(context, *str++);
19287c478bd9Sstevel@tonic-gate } while (err == 0 && --len != 0);
19297c478bd9Sstevel@tonic-gate return (err);
19307c478bd9Sstevel@tonic-gate }
19317c478bd9Sstevel@tonic-gate
19327c478bd9Sstevel@tonic-gate static int
pa_putstr(pr_context_t * context,int printable,char * str,size_t len)19337c478bd9Sstevel@tonic-gate pa_putstr(pr_context_t *context, int printable, char *str, size_t len)
19347c478bd9Sstevel@tonic-gate {
19357c478bd9Sstevel@tonic-gate int err;
19367c478bd9Sstevel@tonic-gate
19377c478bd9Sstevel@tonic-gate if (context->format & PRF_XMLM)
19387c478bd9Sstevel@tonic-gate return (pa_putstr_xml(context, printable, str, len));
19397c478bd9Sstevel@tonic-gate
19407c478bd9Sstevel@tonic-gate if (!printable) {
19417c478bd9Sstevel@tonic-gate do {
19427c478bd9Sstevel@tonic-gate err = pr_printf(context, "\\%03o",
19438f9294f3Sgww (unsigned char)*str++);
19447c478bd9Sstevel@tonic-gate } while (err == 0 && --len != 0);
19457c478bd9Sstevel@tonic-gate return (err);
19467c478bd9Sstevel@tonic-gate }
19477c478bd9Sstevel@tonic-gate do {
19487c478bd9Sstevel@tonic-gate err = pr_putchar(context, *str++);
19497c478bd9Sstevel@tonic-gate } while (err == 0 && --len != 0);
19507c478bd9Sstevel@tonic-gate return (err);
19517c478bd9Sstevel@tonic-gate }
19527c478bd9Sstevel@tonic-gate
19537c478bd9Sstevel@tonic-gate int
pa_string(pr_context_t * context,int status,int flag)19547c478bd9Sstevel@tonic-gate pa_string(pr_context_t *context, int status, int flag)
19557c478bd9Sstevel@tonic-gate {
19567c478bd9Sstevel@tonic-gate int rstat, wstat;
19577c478bd9Sstevel@tonic-gate int i, printable, eos;
19587c478bd9Sstevel@tonic-gate int mlen, rlen;
19597c478bd9Sstevel@tonic-gate int mbmax = MB_CUR_MAX;
19607c478bd9Sstevel@tonic-gate wchar_t wc;
19617c478bd9Sstevel@tonic-gate char mbuf[MB_LEN_MAX + 1];
19627c478bd9Sstevel@tonic-gate char c;
19637c478bd9Sstevel@tonic-gate
19647c478bd9Sstevel@tonic-gate if (status < 0)
19657c478bd9Sstevel@tonic-gate return (status);
19667c478bd9Sstevel@tonic-gate
19677c478bd9Sstevel@tonic-gate rstat = wstat = 0;
19687c478bd9Sstevel@tonic-gate
19697c478bd9Sstevel@tonic-gate if (mbmax == 1) {
19707c478bd9Sstevel@tonic-gate while (wstat == 0) {
19717c478bd9Sstevel@tonic-gate if ((rstat = pr_adr_char(context, &c, 1)) < 0)
19727c478bd9Sstevel@tonic-gate break;
19737c478bd9Sstevel@tonic-gate if (c == '\0')
19747c478bd9Sstevel@tonic-gate break;
19757c478bd9Sstevel@tonic-gate printable = isprint((unsigned char)c);
19767c478bd9Sstevel@tonic-gate wstat = pa_putstr(context, printable, &c, 1);
19777c478bd9Sstevel@tonic-gate }
19787c478bd9Sstevel@tonic-gate goto done;
19797c478bd9Sstevel@tonic-gate }
19807c478bd9Sstevel@tonic-gate
19817c478bd9Sstevel@tonic-gate mlen = eos = 0;
19827c478bd9Sstevel@tonic-gate while (wstat == 0) {
19837c478bd9Sstevel@tonic-gate rlen = 0;
19847c478bd9Sstevel@tonic-gate do {
19857c478bd9Sstevel@tonic-gate if (!eos) {
19867c478bd9Sstevel@tonic-gate rstat = pr_adr_char(context, &c, 1);
19877c478bd9Sstevel@tonic-gate if (rstat != 0 || c == '\0')
19887c478bd9Sstevel@tonic-gate eos = 1;
19897c478bd9Sstevel@tonic-gate else
19907c478bd9Sstevel@tonic-gate mbuf[mlen++] = c;
19917c478bd9Sstevel@tonic-gate }
19927c478bd9Sstevel@tonic-gate rlen = mbtowc(&wc, mbuf, mlen);
19937c478bd9Sstevel@tonic-gate } while (!eos && mlen < mbmax && rlen <= 0);
19947c478bd9Sstevel@tonic-gate
19957c478bd9Sstevel@tonic-gate if (mlen == 0)
19967c478bd9Sstevel@tonic-gate break; /* end of string */
19977c478bd9Sstevel@tonic-gate
19987c478bd9Sstevel@tonic-gate if (rlen <= 0) { /* no good sequence */
19997c478bd9Sstevel@tonic-gate rlen = 1;
20007c478bd9Sstevel@tonic-gate printable = 0;
20017c478bd9Sstevel@tonic-gate } else {
20027c478bd9Sstevel@tonic-gate printable = iswprint(wc);
20037c478bd9Sstevel@tonic-gate }
20047c478bd9Sstevel@tonic-gate wstat = pa_putstr(context, printable, mbuf, rlen);
20057c478bd9Sstevel@tonic-gate mlen -= rlen;
20067c478bd9Sstevel@tonic-gate if (mlen > 0) {
20077c478bd9Sstevel@tonic-gate for (i = 0; i < mlen; i++)
20087c478bd9Sstevel@tonic-gate mbuf[i] = mbuf[rlen + i];
20097c478bd9Sstevel@tonic-gate }
20107c478bd9Sstevel@tonic-gate }
20117c478bd9Sstevel@tonic-gate
20127c478bd9Sstevel@tonic-gate done:
20137c478bd9Sstevel@tonic-gate if (wstat == 0)
20147c478bd9Sstevel@tonic-gate wstat = do_newline(context, flag);
20157c478bd9Sstevel@tonic-gate
20167c478bd9Sstevel@tonic-gate return ((rstat != 0 || wstat != 0) ? -1 : 0);
20177c478bd9Sstevel@tonic-gate }
20187c478bd9Sstevel@tonic-gate
20197c478bd9Sstevel@tonic-gate /*
20207c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
20217c478bd9Sstevel@tonic-gate * pa_adr_u_int32: Issues pr_adr_u_int32 to retrieve the next ADR item from
20227c478bd9Sstevel@tonic-gate * the input stream pointed to by audit_adr, and prints it
20237c478bd9Sstevel@tonic-gate * if status = 0
20247c478bd9Sstevel@tonic-gate * return codes : -1 - error
20257c478bd9Sstevel@tonic-gate * : 0 - successful
20267c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
20277c478bd9Sstevel@tonic-gate */
20287c478bd9Sstevel@tonic-gate
20297c478bd9Sstevel@tonic-gate
20307c478bd9Sstevel@tonic-gate int
pa_adr_u_int32(pr_context_t * context,int status,int flag)20317c478bd9Sstevel@tonic-gate pa_adr_u_int32(pr_context_t *context, int status, int flag)
20327c478bd9Sstevel@tonic-gate {
20337c478bd9Sstevel@tonic-gate uint32_t c;
20347c478bd9Sstevel@tonic-gate uval_t uval;
20357c478bd9Sstevel@tonic-gate
20367c478bd9Sstevel@tonic-gate if (status >= 0) {
20377c478bd9Sstevel@tonic-gate if (pr_adr_u_int32(context, &c, 1) == 0) {
20387c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT32;
20397c478bd9Sstevel@tonic-gate uval.uint32_val = c;
20407c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag));
20417c478bd9Sstevel@tonic-gate } else
20427c478bd9Sstevel@tonic-gate return (-1);
20437c478bd9Sstevel@tonic-gate } else
20447c478bd9Sstevel@tonic-gate return (status);
20457c478bd9Sstevel@tonic-gate }
20467c478bd9Sstevel@tonic-gate
20477c478bd9Sstevel@tonic-gate
20487c478bd9Sstevel@tonic-gate
20497c478bd9Sstevel@tonic-gate /*
20507c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
20517c478bd9Sstevel@tonic-gate * pa_adr_u_int64: Issues pr_adr_u_int64 to retrieve the next ADR item from the
20527c478bd9Sstevel@tonic-gate * input stream pointed to by audit_adr, and prints it
20537c478bd9Sstevel@tonic-gate * if status = 0
20547c478bd9Sstevel@tonic-gate * return codes : -1 - error
20557c478bd9Sstevel@tonic-gate * : 0 - successful
20567c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
20577c478bd9Sstevel@tonic-gate */
20587c478bd9Sstevel@tonic-gate int
pa_adr_u_int64(pr_context_t * context,int status,int flag)20597c478bd9Sstevel@tonic-gate pa_adr_u_int64(pr_context_t *context, int status, int flag)
20607c478bd9Sstevel@tonic-gate {
20617c478bd9Sstevel@tonic-gate uint64_t c;
20627c478bd9Sstevel@tonic-gate uval_t uval;
20637c478bd9Sstevel@tonic-gate
20647c478bd9Sstevel@tonic-gate if (status >= 0) {
20657c478bd9Sstevel@tonic-gate if (pr_adr_u_int64(context, &c, 1) == 0) {
20667c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT64;
20677c478bd9Sstevel@tonic-gate uval.uint64_val = c;
20687c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag));
20697c478bd9Sstevel@tonic-gate } else
20707c478bd9Sstevel@tonic-gate return (-1);
20717c478bd9Sstevel@tonic-gate } else
20727c478bd9Sstevel@tonic-gate return (status);
20737c478bd9Sstevel@tonic-gate }
20747c478bd9Sstevel@tonic-gate
20757c478bd9Sstevel@tonic-gate
20767c478bd9Sstevel@tonic-gate /*
20777c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
20787c478bd9Sstevel@tonic-gate * pa_adr_u_short: Issues pr_adr_u_short to retrieve the next ADR item from
20797c478bd9Sstevel@tonic-gate * the input stream pointed to by audit_adr, and prints it
20807c478bd9Sstevel@tonic-gate * if status = 0
20817c478bd9Sstevel@tonic-gate * return codes : -1 - error
20827c478bd9Sstevel@tonic-gate * : 0 - successful
20837c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
20847c478bd9Sstevel@tonic-gate */
20857c478bd9Sstevel@tonic-gate int
pa_adr_u_short(pr_context_t * context,int status,int flag)20867c478bd9Sstevel@tonic-gate pa_adr_u_short(pr_context_t *context, int status, int flag)
20877c478bd9Sstevel@tonic-gate {
20887c478bd9Sstevel@tonic-gate ushort_t c;
20897c478bd9Sstevel@tonic-gate uval_t uval;
20907c478bd9Sstevel@tonic-gate
20917c478bd9Sstevel@tonic-gate if (status >= 0) {
20927c478bd9Sstevel@tonic-gate if (pr_adr_u_short(context, &c, 1) == 0) {
20937c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_USHORT;
20947c478bd9Sstevel@tonic-gate uval.ushort_val = c;
20957c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag));
20967c478bd9Sstevel@tonic-gate } else
20977c478bd9Sstevel@tonic-gate return (-1);
20987c478bd9Sstevel@tonic-gate } else
20997c478bd9Sstevel@tonic-gate return (status);
21007c478bd9Sstevel@tonic-gate }
21017c478bd9Sstevel@tonic-gate
21027c478bd9Sstevel@tonic-gate /*
21037c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
21047c478bd9Sstevel@tonic-gate * pa_reclen: Issues pr_adr_u_long to retrieve the length of the record
21057c478bd9Sstevel@tonic-gate * from the input stream pointed to by audit_adr,
21067c478bd9Sstevel@tonic-gate * and prints it (unless format is XML) if status = 0
21077c478bd9Sstevel@tonic-gate * return codes : -1 - error
21087c478bd9Sstevel@tonic-gate * : 0 - successful
21097c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
21107c478bd9Sstevel@tonic-gate */
21117c478bd9Sstevel@tonic-gate int
pa_reclen(pr_context_t * context,int status)21127c478bd9Sstevel@tonic-gate pa_reclen(pr_context_t *context, int status)
21137c478bd9Sstevel@tonic-gate {
21147c478bd9Sstevel@tonic-gate uint32_t c;
21157c478bd9Sstevel@tonic-gate uval_t uval;
21167c478bd9Sstevel@tonic-gate
21177c478bd9Sstevel@tonic-gate if (status >= 0) {
21187c478bd9Sstevel@tonic-gate if ((int)pr_adr_u_int32(context, &c, 1) == 0) {
21197c478bd9Sstevel@tonic-gate context->audit_rec_len = c;
21207c478bd9Sstevel@tonic-gate
21217c478bd9Sstevel@tonic-gate /* Don't print this for XML format */
21227c478bd9Sstevel@tonic-gate if (context->format & PRF_XMLM) {
21237c478bd9Sstevel@tonic-gate return (0);
21247c478bd9Sstevel@tonic-gate } else {
21257c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT32;
21267c478bd9Sstevel@tonic-gate uval.uint32_val = c;
21277c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, 0));
21287c478bd9Sstevel@tonic-gate }
21297c478bd9Sstevel@tonic-gate } else
21307c478bd9Sstevel@tonic-gate return (-1);
21317c478bd9Sstevel@tonic-gate } else
21327c478bd9Sstevel@tonic-gate return (status);
21337c478bd9Sstevel@tonic-gate }
21347c478bd9Sstevel@tonic-gate
21357c478bd9Sstevel@tonic-gate /*
21367c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
21377c478bd9Sstevel@tonic-gate * pa_mode : Issues pr_adr_u_short to retrieve the next ADR item from
21387c478bd9Sstevel@tonic-gate * the input stream pointed to by audit_adr, and prints it
21397c478bd9Sstevel@tonic-gate * in octal if status = 0
21407c478bd9Sstevel@tonic-gate * return codes : -1 - error
21417c478bd9Sstevel@tonic-gate * : 0 - successful
21427c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
21437c478bd9Sstevel@tonic-gate */
21447c478bd9Sstevel@tonic-gate int
pa_mode(pr_context_t * context,int status,int flag)21457c478bd9Sstevel@tonic-gate pa_mode(pr_context_t *context, int status, int flag)
21467c478bd9Sstevel@tonic-gate {
21477c478bd9Sstevel@tonic-gate uint32_t c;
21487c478bd9Sstevel@tonic-gate uval_t uval;
21497c478bd9Sstevel@tonic-gate
21507c478bd9Sstevel@tonic-gate if (status >= 0) {
21517c478bd9Sstevel@tonic-gate if (pr_adr_u_int32(context, &c, 1) == 0) {
21527c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_LOCT;
21537c478bd9Sstevel@tonic-gate uval.uint32_val = c;
21547c478bd9Sstevel@tonic-gate return (pa_print(context, &uval, flag));
21557c478bd9Sstevel@tonic-gate } else
21567c478bd9Sstevel@tonic-gate return (-1);
21577c478bd9Sstevel@tonic-gate } else
21587c478bd9Sstevel@tonic-gate return (status);
21597c478bd9Sstevel@tonic-gate }
21607c478bd9Sstevel@tonic-gate
2161a7746f66Stz static int
pa_print_uid(pr_context_t * context,uid_t uid,int status,int flag)2162a7746f66Stz pa_print_uid(pr_context_t *context, uid_t uid, int status, int flag)
21637c478bd9Sstevel@tonic-gate {
21647c478bd9Sstevel@tonic-gate int returnstat;
21657c478bd9Sstevel@tonic-gate uval_t uval;
21667c478bd9Sstevel@tonic-gate
21677c478bd9Sstevel@tonic-gate if (status < 0)
21687c478bd9Sstevel@tonic-gate return (status);
21697c478bd9Sstevel@tonic-gate
217099591362SPeter Tribble if (context->format & PRF_RAWM) {
217199591362SPeter Tribble /* print in integer form */
21727c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_INT32;
21737c478bd9Sstevel@tonic-gate uval.int32_val = uid;
21747c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag);
217599591362SPeter Tribble } else {
217699591362SPeter Tribble /* print in ASCII form */
217799591362SPeter Tribble uval.uvaltype = PRA_STRING;
217899591362SPeter Tribble uval.string_val = getname(uid);
217999591362SPeter Tribble returnstat = pa_print(context, &uval, flag);
21807c478bd9Sstevel@tonic-gate }
21817c478bd9Sstevel@tonic-gate return (returnstat);
21827c478bd9Sstevel@tonic-gate }
21837c478bd9Sstevel@tonic-gate
21847c478bd9Sstevel@tonic-gate
21857c478bd9Sstevel@tonic-gate /*
21867c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
2187a7746f66Stz * pa_pw_uid() : Issues pr_adr_u_int32 to reads uid from input stream
2188a7746f66Stz * pointed to by audit_adr, and displays it in either
2189a7746f66Stz * raw form or its ASCII representation, if status >= 0.
21907c478bd9Sstevel@tonic-gate * return codes : -1 - error
2191*8bb3e7e3SPeter Tribble * : 1 - warning, passwd entry not found
21927c478bd9Sstevel@tonic-gate * : 0 - successful
21937c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
21947c478bd9Sstevel@tonic-gate */
21957c478bd9Sstevel@tonic-gate int
pa_pw_uid(pr_context_t * context,int status,int flag)2196a7746f66Stz pa_pw_uid(pr_context_t *context, int status, int flag)
2197a7746f66Stz {
2198a7746f66Stz uint32_t uid;
2199a7746f66Stz
2200a7746f66Stz if (status < 0)
2201a7746f66Stz return (status);
2202a7746f66Stz
2203a7746f66Stz if (pr_adr_u_int32(context, &uid, 1) != 0)
2204a7746f66Stz /* cannot retrieve uid */
2205a7746f66Stz return (-1);
2206a7746f66Stz
2207a7746f66Stz return (pa_print_uid(context, uid, status, flag));
2208a7746f66Stz }
2209a7746f66Stz
2210a7746f66Stz static int
pa_print_gid(pr_context_t * context,gid_t gid,int status,int flag)2211a7746f66Stz pa_print_gid(pr_context_t *context, gid_t gid, int status, int flag)
22127c478bd9Sstevel@tonic-gate {
22137c478bd9Sstevel@tonic-gate int returnstat;
22147c478bd9Sstevel@tonic-gate uval_t uval;
22157c478bd9Sstevel@tonic-gate
22167c478bd9Sstevel@tonic-gate if (status < 0)
22177c478bd9Sstevel@tonic-gate return (status);
22187c478bd9Sstevel@tonic-gate
221999591362SPeter Tribble if (context->format & PRF_RAWM) {
222099591362SPeter Tribble /* print in integer form */
22217c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_INT32;
22227c478bd9Sstevel@tonic-gate uval.int32_val = gid;
22237c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag);
222499591362SPeter Tribble } else {
222599591362SPeter Tribble /* print in ASCII form */
222699591362SPeter Tribble uval.uvaltype = PRA_STRING;
222799591362SPeter Tribble uval.string_val = getgroup(gid);
222899591362SPeter Tribble returnstat = pa_print(context, &uval, flag);
22297c478bd9Sstevel@tonic-gate }
22307c478bd9Sstevel@tonic-gate return (returnstat);
22317c478bd9Sstevel@tonic-gate }
22327c478bd9Sstevel@tonic-gate
22337c478bd9Sstevel@tonic-gate
2234a7746f66Stz /*
2235a7746f66Stz * -----------------------------------------------------------------------
2236a7746f66Stz * pa_gr_uid() : Issues pr_adr_u_int32 to reads group uid from input stream
2237a7746f66Stz * pointed to by audit_adr, and displays it in either
2238a7746f66Stz * raw form or its ASCII representation, if status >= 0.
2239a7746f66Stz * return codes : -1 - error
2240*8bb3e7e3SPeter Tribble * : 1 - warning, passwd entry not found
2241a7746f66Stz * : 0 - successful
2242a7746f66Stz * -----------------------------------------------------------------------
2243a7746f66Stz */
2244a7746f66Stz int
pa_gr_uid(pr_context_t * context,int status,int flag)2245a7746f66Stz pa_gr_uid(pr_context_t *context, int status, int flag)
2246a7746f66Stz {
2247a7746f66Stz uint32_t gid;
2248a7746f66Stz
2249a7746f66Stz if (status < 0)
2250a7746f66Stz return (status);
2251a7746f66Stz
2252a7746f66Stz if (pr_adr_u_int32(context, &gid, 1) != 0)
2253a7746f66Stz /* cannot retrieve gid */
2254a7746f66Stz return (-1);
2255a7746f66Stz
2256a7746f66Stz return (pa_print_gid(context, gid, status, flag));
2257a7746f66Stz }
2258a7746f66Stz
2259a7746f66Stz
22607c478bd9Sstevel@tonic-gate /*
22617c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
22627c478bd9Sstevel@tonic-gate * pa_pw_uid_gr_gid() : Issues pr_adr_u_int32 to reads uid or group uid
22637c478bd9Sstevel@tonic-gate * from input stream
22647c478bd9Sstevel@tonic-gate * pointed to by audit_adr, and displays it in either
22657c478bd9Sstevel@tonic-gate * raw form or its ASCII representation, if status >= 0.
22667c478bd9Sstevel@tonic-gate * return codes : -1 - error
2267*8bb3e7e3SPeter Tribble * : 1 - warning, passwd entry not found
22687c478bd9Sstevel@tonic-gate * : 0 - successful
22697c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
22707c478bd9Sstevel@tonic-gate */
22717c478bd9Sstevel@tonic-gate int
pa_pw_uid_gr_gid(pr_context_t * context,int status,int flag)22727c478bd9Sstevel@tonic-gate pa_pw_uid_gr_gid(pr_context_t *context, int status, int flag)
22737c478bd9Sstevel@tonic-gate {
22747c478bd9Sstevel@tonic-gate int returnstat;
22757c478bd9Sstevel@tonic-gate uint32_t value;
22767c478bd9Sstevel@tonic-gate uval_t uval;
22777c478bd9Sstevel@tonic-gate
22787c478bd9Sstevel@tonic-gate if (status < 0)
22797c478bd9Sstevel@tonic-gate return (status);
22807c478bd9Sstevel@tonic-gate
22817c478bd9Sstevel@tonic-gate /* get value of a_type */
22827c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_int32(context, &value, 1)) != 0)
22837c478bd9Sstevel@tonic-gate return (returnstat);
22847c478bd9Sstevel@tonic-gate
22857c478bd9Sstevel@tonic-gate if ((returnstat = open_tag(context, TAG_ACLTYPE)) != 0)
22867c478bd9Sstevel@tonic-gate return (returnstat);
22877c478bd9Sstevel@tonic-gate
22887c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT32;
22897c478bd9Sstevel@tonic-gate uval.uint32_val = value;
22907c478bd9Sstevel@tonic-gate if ((returnstat = pa_print(context, &uval, flag)) != 0)
22917c478bd9Sstevel@tonic-gate return (returnstat);
22927c478bd9Sstevel@tonic-gate
22937c478bd9Sstevel@tonic-gate if ((returnstat = close_tag(context, TAG_ACLTYPE)) != 0)
22947c478bd9Sstevel@tonic-gate return (returnstat);
22957c478bd9Sstevel@tonic-gate
22967c478bd9Sstevel@tonic-gate if ((returnstat = open_tag(context, TAG_ACLVAL)) != 0)
22977c478bd9Sstevel@tonic-gate return (returnstat);
22987c478bd9Sstevel@tonic-gate /*
22997c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE
23007c478bd9Sstevel@tonic-gate * The "mask" and "other" strings refer to the class mask
23017c478bd9Sstevel@tonic-gate * and other (or world) entries in an ACL.
23027c478bd9Sstevel@tonic-gate * The "unrecognized" string refers to an unrecognized ACL
23037c478bd9Sstevel@tonic-gate * entry.
23047c478bd9Sstevel@tonic-gate */
23057c478bd9Sstevel@tonic-gate switch (value) {
23067c478bd9Sstevel@tonic-gate case USER_OBJ:
23077c478bd9Sstevel@tonic-gate case USER:
23087c478bd9Sstevel@tonic-gate returnstat = pa_pw_uid(context, returnstat, flag);
23097c478bd9Sstevel@tonic-gate break;
23107c478bd9Sstevel@tonic-gate case GROUP_OBJ:
23117c478bd9Sstevel@tonic-gate case GROUP:
23127c478bd9Sstevel@tonic-gate returnstat = pa_gr_uid(context, returnstat, flag);
23137c478bd9Sstevel@tonic-gate break;
23147c478bd9Sstevel@tonic-gate case CLASS_OBJ:
23158f9294f3Sgww returnstat = pr_adr_u_int32(context, &value, 1);
23168f9294f3Sgww if (returnstat != 0)
23177c478bd9Sstevel@tonic-gate return (returnstat);
23187c478bd9Sstevel@tonic-gate
23198f9294f3Sgww if (!(context->format & PRF_RAWM)) {
23208f9294f3Sgww uval.uvaltype = PRA_STRING;
23218f9294f3Sgww uval.string_val = gettext("mask");
23228f9294f3Sgww returnstat = pa_print(context, &uval, flag);
23238f9294f3Sgww } else {
23248f9294f3Sgww uval.uvaltype = PRA_UINT32;
23258f9294f3Sgww uval.uint32_val = value;
23268f9294f3Sgww if ((returnstat =
23278f9294f3Sgww pa_print(context, &uval, flag)) != 0) {
23288f9294f3Sgww return (returnstat);
23298f9294f3Sgww }
23308f9294f3Sgww }
23318f9294f3Sgww break;
23328f9294f3Sgww case OTHER_OBJ:
23338f9294f3Sgww returnstat = pr_adr_u_int32(context, &value, 1);
23348f9294f3Sgww if (returnstat != 0)
23357c478bd9Sstevel@tonic-gate return (returnstat);
23367c478bd9Sstevel@tonic-gate
23378f9294f3Sgww if (!(context->format & PRF_RAWM)) {
23388f9294f3Sgww uval.uvaltype = PRA_STRING;
23398f9294f3Sgww uval.string_val = gettext("other");
23408f9294f3Sgww returnstat = pa_print(context, &uval, flag);
23418f9294f3Sgww } else {
23428f9294f3Sgww uval.uvaltype = PRA_UINT32;
23438f9294f3Sgww uval.uint32_val = value;
23448f9294f3Sgww if ((returnstat =
23458f9294f3Sgww pa_print(context, &uval, flag)) != 0) {
23468f9294f3Sgww return (returnstat);
23478f9294f3Sgww }
23488f9294f3Sgww }
23498f9294f3Sgww break;
23508f9294f3Sgww default:
23518f9294f3Sgww returnstat = pr_adr_u_int32(context, &value, 1);
23528f9294f3Sgww if (returnstat != 0)
23537c478bd9Sstevel@tonic-gate return (returnstat);
23548f9294f3Sgww
23558f9294f3Sgww if (!(context->format & PRF_RAWM)) {
23568f9294f3Sgww uval.uvaltype = PRA_STRING;
23578f9294f3Sgww uval.string_val = gettext("unrecognized");
23588f9294f3Sgww returnstat = pa_print(context, &uval, flag);
23598f9294f3Sgww } else {
23608f9294f3Sgww uval.uvaltype = PRA_UINT32;
23618f9294f3Sgww uval.uint32_val = value;
23628f9294f3Sgww if ((returnstat =
23638f9294f3Sgww pa_print(context, &uval, flag)) != 0) {
23648f9294f3Sgww return (returnstat);
23658f9294f3Sgww }
23668f9294f3Sgww }
23677c478bd9Sstevel@tonic-gate }
23687c478bd9Sstevel@tonic-gate
23697c478bd9Sstevel@tonic-gate if ((returnstat = close_tag(context, TAG_ACLVAL)) != 0)
23707c478bd9Sstevel@tonic-gate return (returnstat);
23717c478bd9Sstevel@tonic-gate
23727c478bd9Sstevel@tonic-gate return (returnstat);
23737c478bd9Sstevel@tonic-gate }
23747c478bd9Sstevel@tonic-gate
23757c478bd9Sstevel@tonic-gate
23767c478bd9Sstevel@tonic-gate /*
23777c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
23787c478bd9Sstevel@tonic-gate * pa_event_modifier(): Issues pr_adr_u_short to retrieve the next ADR item from
23797c478bd9Sstevel@tonic-gate * the input stream pointed to by audit_adr. This is the
23807c478bd9Sstevel@tonic-gate * event type, and is displayed in hex;
23817c478bd9Sstevel@tonic-gate * return codes : -1 - error
23827c478bd9Sstevel@tonic-gate * : 0 - successful
23837c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
23847c478bd9Sstevel@tonic-gate */
23857c478bd9Sstevel@tonic-gate int
pa_event_modifier(pr_context_t * context,int status,int flag)23867c478bd9Sstevel@tonic-gate pa_event_modifier(pr_context_t *context, int status, int flag)
23877c478bd9Sstevel@tonic-gate {
23887c478bd9Sstevel@tonic-gate int returnstat;
2389d0fa49b7STony Nguyen au_emod_t emodifier;
23907c478bd9Sstevel@tonic-gate uval_t uval;
23917c478bd9Sstevel@tonic-gate char modstring[64];
23927c478bd9Sstevel@tonic-gate
23937c478bd9Sstevel@tonic-gate if (status < 0)
23947c478bd9Sstevel@tonic-gate return (status);
23957c478bd9Sstevel@tonic-gate
23967c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_short(context, &emodifier, 1)) != 0)
23977c478bd9Sstevel@tonic-gate return (returnstat);
23987c478bd9Sstevel@tonic-gate
23997c478bd9Sstevel@tonic-gate /* For XML, only print when modifier is non-zero */
24007c478bd9Sstevel@tonic-gate if (!(context->format & PRF_XMLM) || (emodifier != 0)) {
24017c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING;
24027c478bd9Sstevel@tonic-gate
24037c478bd9Sstevel@tonic-gate returnstat = open_tag(context, TAG_EVMOD);
24047c478bd9Sstevel@tonic-gate
24057c478bd9Sstevel@tonic-gate if (returnstat >= 0) {
24067c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) {
24077c478bd9Sstevel@tonic-gate eventmodifier2string(emodifier, modstring,
24087c478bd9Sstevel@tonic-gate sizeof (modstring));
24097c478bd9Sstevel@tonic-gate uval.string_val = modstring;
24107c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag);
24117c478bd9Sstevel@tonic-gate } else {
24127c478bd9Sstevel@tonic-gate uval.string_val = hexconvert((char *)&emodifier,
24137c478bd9Sstevel@tonic-gate sizeof (emodifier), sizeof (emodifier));
24147c478bd9Sstevel@tonic-gate if (uval.string_val) {
24157c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval,
24167c478bd9Sstevel@tonic-gate flag);
24177c478bd9Sstevel@tonic-gate free(uval.string_val);
24187c478bd9Sstevel@tonic-gate }
24197c478bd9Sstevel@tonic-gate }
24207c478bd9Sstevel@tonic-gate }
24217c478bd9Sstevel@tonic-gate if (returnstat >= 0)
24227c478bd9Sstevel@tonic-gate returnstat = close_tag(context, TAG_EVMOD);
24237c478bd9Sstevel@tonic-gate }
24247c478bd9Sstevel@tonic-gate
24257c478bd9Sstevel@tonic-gate return (returnstat);
24267c478bd9Sstevel@tonic-gate }
24277c478bd9Sstevel@tonic-gate
24287c478bd9Sstevel@tonic-gate
24297c478bd9Sstevel@tonic-gate /*
24307c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
24317c478bd9Sstevel@tonic-gate * pa_event_type(): Issues pr_adr_u_short to retrieve the next ADR item from
24327c478bd9Sstevel@tonic-gate * the input stream pointed to by audit_adr. This is the
24337c478bd9Sstevel@tonic-gate * event type, and is displayed in either raw or
24347c478bd9Sstevel@tonic-gate * ASCII form as appropriate
24357c478bd9Sstevel@tonic-gate * return codes : -1 - error
24367c478bd9Sstevel@tonic-gate * : 0 - successful
24377c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
24387c478bd9Sstevel@tonic-gate */
24397c478bd9Sstevel@tonic-gate int
pa_event_type(pr_context_t * context,int status,int flag)24407c478bd9Sstevel@tonic-gate pa_event_type(pr_context_t *context, int status, int flag)
24417c478bd9Sstevel@tonic-gate {
2442d0fa49b7STony Nguyen au_event_t etype;
24437c478bd9Sstevel@tonic-gate int returnstat;
24447c478bd9Sstevel@tonic-gate au_event_ent_t *p_event = NULL;
24457c478bd9Sstevel@tonic-gate uval_t uval;
24467c478bd9Sstevel@tonic-gate
24477c478bd9Sstevel@tonic-gate if (status >= 0) {
24487c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_short(context, &etype, 1)) == 0) {
24497c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) {
24507c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING;
24517c478bd9Sstevel@tonic-gate if (context->format & PRF_NOCACHE) {
24527c478bd9Sstevel@tonic-gate p_event = getauevnum(etype);
24537c478bd9Sstevel@tonic-gate } else {
24547c478bd9Sstevel@tonic-gate (void) cacheauevent(&p_event, etype);
24557c478bd9Sstevel@tonic-gate }
24567c478bd9Sstevel@tonic-gate if (p_event != NULL) {
24577c478bd9Sstevel@tonic-gate if (context->format & PRF_SHORTM)
24587c478bd9Sstevel@tonic-gate uval.string_val =
24597c478bd9Sstevel@tonic-gate p_event->ae_name;
24607c478bd9Sstevel@tonic-gate else
24617c478bd9Sstevel@tonic-gate uval.string_val =
24627c478bd9Sstevel@tonic-gate p_event->ae_desc;
24637c478bd9Sstevel@tonic-gate } else {
24647c478bd9Sstevel@tonic-gate uval.string_val =
24657c478bd9Sstevel@tonic-gate gettext("invalid event number");
24667c478bd9Sstevel@tonic-gate }
24677c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag);
24687c478bd9Sstevel@tonic-gate } else {
24697c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_USHORT;
24707c478bd9Sstevel@tonic-gate uval.ushort_val = etype;
24717c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag);
24727c478bd9Sstevel@tonic-gate }
24737c478bd9Sstevel@tonic-gate }
24747c478bd9Sstevel@tonic-gate return (returnstat);
24757c478bd9Sstevel@tonic-gate } else
24767c478bd9Sstevel@tonic-gate return (status);
24777c478bd9Sstevel@tonic-gate
24787c478bd9Sstevel@tonic-gate }
24797c478bd9Sstevel@tonic-gate
24807c478bd9Sstevel@tonic-gate
24817c478bd9Sstevel@tonic-gate /*
24827c478bd9Sstevel@tonic-gate * Print time from struct timeval to millisecond resolution.
24837c478bd9Sstevel@tonic-gate *
24847c478bd9Sstevel@tonic-gate * typedef long time_t; time of day in seconds
24857c478bd9Sstevel@tonic-gate * typedef long useconds_t; signed # of microseconds
24867c478bd9Sstevel@tonic-gate *
24877c478bd9Sstevel@tonic-gate * struct timeval {
24887c478bd9Sstevel@tonic-gate * time_t tv_sec; seconds
24897c478bd9Sstevel@tonic-gate * suseconds_t tv_usec; and microseconds
24907c478bd9Sstevel@tonic-gate * };
24917c478bd9Sstevel@tonic-gate */
24927c478bd9Sstevel@tonic-gate
24937c478bd9Sstevel@tonic-gate int
pa_utime32(pr_context_t * context,int status,int flag)24947c478bd9Sstevel@tonic-gate pa_utime32(pr_context_t *context, int status, int flag)
24957c478bd9Sstevel@tonic-gate {
24967c478bd9Sstevel@tonic-gate uint32_t scale = 1000; /* usec to msec */
24977c478bd9Sstevel@tonic-gate
24987c478bd9Sstevel@tonic-gate return (do_mtime32(context, status, flag, scale));
24997c478bd9Sstevel@tonic-gate }
25007c478bd9Sstevel@tonic-gate
25017c478bd9Sstevel@tonic-gate /*
25027c478bd9Sstevel@tonic-gate * Print time from timestruc_t to millisecond resolution.
25037c478bd9Sstevel@tonic-gate *
25047c478bd9Sstevel@tonic-gate * typedef struct timespec timestruct_t;
25057c478bd9Sstevel@tonic-gate * struct timespec{
25067c478bd9Sstevel@tonic-gate * time_t tv_sec; seconds
25077c478bd9Sstevel@tonic-gate * long tv_nsec; and nanoseconds
25087c478bd9Sstevel@tonic-gate * };
25097c478bd9Sstevel@tonic-gate */
25107c478bd9Sstevel@tonic-gate int
pa_ntime32(pr_context_t * context,int status,int flag)25117c478bd9Sstevel@tonic-gate pa_ntime32(pr_context_t *context, int status, int flag)
25127c478bd9Sstevel@tonic-gate {
25137c478bd9Sstevel@tonic-gate uint32_t scale = 1000000; /* nsec to msec */
25147c478bd9Sstevel@tonic-gate
25157c478bd9Sstevel@tonic-gate return (do_mtime32(context, status, flag, scale));
25167c478bd9Sstevel@tonic-gate }
25177c478bd9Sstevel@tonic-gate
25187c478bd9Sstevel@tonic-gate /*
25197c478bd9Sstevel@tonic-gate * Format the timezone +/- HH:MM and terminate the string
25207c478bd9Sstevel@tonic-gate * Note tm and tv_sec are the same time.
25217c478bd9Sstevel@tonic-gate * Too bad strftime won't produce an ISO 8601 time zone numeric
25227c478bd9Sstevel@tonic-gate */
25237c478bd9Sstevel@tonic-gate
25247c478bd9Sstevel@tonic-gate #define MINS (24L * 60)
25257c478bd9Sstevel@tonic-gate static void
tzone(struct tm * tm,time_t * tv_sec,char * p)25267c478bd9Sstevel@tonic-gate tzone(struct tm *tm, time_t *tv_sec, char *p)
25277c478bd9Sstevel@tonic-gate {
25287c478bd9Sstevel@tonic-gate struct tm *gmt;
25297c478bd9Sstevel@tonic-gate int min_off;
25307c478bd9Sstevel@tonic-gate
25317c478bd9Sstevel@tonic-gate gmt = gmtime(tv_sec);
25327c478bd9Sstevel@tonic-gate
25337c478bd9Sstevel@tonic-gate min_off = ((tm->tm_hour - gmt->tm_hour) * 60) +
25347c478bd9Sstevel@tonic-gate (tm->tm_min - gmt->tm_min);
25357c478bd9Sstevel@tonic-gate
25367c478bd9Sstevel@tonic-gate if (tm->tm_year < gmt->tm_year) /* cross new year */
25377c478bd9Sstevel@tonic-gate min_off -= MINS;
25387c478bd9Sstevel@tonic-gate else if (tm->tm_year > gmt->tm_year)
25397c478bd9Sstevel@tonic-gate min_off += MINS;
25407c478bd9Sstevel@tonic-gate else if (tm->tm_yday < gmt->tm_yday) /* cross dateline */
25417c478bd9Sstevel@tonic-gate min_off -= MINS;
25427c478bd9Sstevel@tonic-gate else if (tm->tm_yday > gmt->tm_yday)
25437c478bd9Sstevel@tonic-gate min_off += MINS;
25447c478bd9Sstevel@tonic-gate
25457c478bd9Sstevel@tonic-gate if (min_off < 0) {
25467c478bd9Sstevel@tonic-gate min_off = -min_off;
25477c478bd9Sstevel@tonic-gate *p++ = '-';
25487c478bd9Sstevel@tonic-gate } else {
25497c478bd9Sstevel@tonic-gate *p++ = '+';
25507c478bd9Sstevel@tonic-gate }
25517c478bd9Sstevel@tonic-gate
25527c478bd9Sstevel@tonic-gate *p++ = min_off / 600 + '0'; /* 10s of hours */
25537c478bd9Sstevel@tonic-gate min_off = min_off - min_off / 600 * 600;
25547c478bd9Sstevel@tonic-gate *p++ = min_off / 60 % 10 + '0'; /* hours */
25557c478bd9Sstevel@tonic-gate min_off = min_off - min_off / 60 * 60;
25567c478bd9Sstevel@tonic-gate *p++ = ':';
25577c478bd9Sstevel@tonic-gate *p++ = min_off / 10 + '0'; /* 10s of minutes */
25587c478bd9Sstevel@tonic-gate *p++ = min_off % 10 + '0'; /* minutes */
25597c478bd9Sstevel@tonic-gate *p = '\0';
25607c478bd9Sstevel@tonic-gate }
25617c478bd9Sstevel@tonic-gate
25627c478bd9Sstevel@tonic-gate /*
25637c478bd9Sstevel@tonic-gate * Format the milliseconds in place in the string.
25647c478bd9Sstevel@tonic-gate * Borrowed from strftime.c:itoa()
25657c478bd9Sstevel@tonic-gate */
25667c478bd9Sstevel@tonic-gate static void
msec32(uint32_t msec,char * p)25677c478bd9Sstevel@tonic-gate msec32(uint32_t msec, char *p)
25687c478bd9Sstevel@tonic-gate {
25697c478bd9Sstevel@tonic-gate *p++ = msec / 100 + '0';
25707c478bd9Sstevel@tonic-gate msec = msec - msec / 100 * 100;
25717c478bd9Sstevel@tonic-gate *p++ = msec / 10 + '0';
25727c478bd9Sstevel@tonic-gate *p++ = msec % 10 +'0';
25737c478bd9Sstevel@tonic-gate }
25747c478bd9Sstevel@tonic-gate
25757c478bd9Sstevel@tonic-gate /*
25767c478bd9Sstevel@tonic-gate * Format time and print relative to scale factor from micro/nano seconds.
25777c478bd9Sstevel@tonic-gate */
25787c478bd9Sstevel@tonic-gate static int
do_mtime32(pr_context_t * context,int status,int flag,uint32_t scale)25797c478bd9Sstevel@tonic-gate do_mtime32(pr_context_t *context, int status, int flag, uint32_t scale)
25807c478bd9Sstevel@tonic-gate {
25817c478bd9Sstevel@tonic-gate uint32_t t32;
25827c478bd9Sstevel@tonic-gate time_t tv_sec;
25837c478bd9Sstevel@tonic-gate struct tm tm;
25847c478bd9Sstevel@tonic-gate char time_created[sizeof ("YYYY-MM-DD HH:MM:SS.sss -HH:MM")];
25857c478bd9Sstevel@tonic-gate int returnstat;
25867c478bd9Sstevel@tonic-gate uval_t uval;
25877c478bd9Sstevel@tonic-gate
25887c478bd9Sstevel@tonic-gate if (status < 0)
25897c478bd9Sstevel@tonic-gate return (status);
25907c478bd9Sstevel@tonic-gate
25917c478bd9Sstevel@tonic-gate if ((returnstat = open_tag(context, TAG_ISO)) != 0)
25927c478bd9Sstevel@tonic-gate return (returnstat);
25937c478bd9Sstevel@tonic-gate
25947c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_int32(context,
25957c478bd9Sstevel@tonic-gate (uint32_t *)&tv_sec, 1)) != 0)
25967c478bd9Sstevel@tonic-gate return (returnstat);
25977c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_int32(context, &t32, 1)) == 0) {
25987c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) {
25997c478bd9Sstevel@tonic-gate (void) localtime_r(&tv_sec, &tm);
26007c478bd9Sstevel@tonic-gate (void) strftime(time_created,
26017c478bd9Sstevel@tonic-gate sizeof ("YYYY-MM-DD HH:MM:SS.xxx "),
26027c478bd9Sstevel@tonic-gate "%Y-%m-%d %H:%M:%S.xxx ", &tm);
26037c478bd9Sstevel@tonic-gate msec32(t32/scale,
26047c478bd9Sstevel@tonic-gate &time_created[sizeof ("YYYY-MM-DD HH:MM:SS.")-1]);
26057c478bd9Sstevel@tonic-gate tzone(&tm, &tv_sec,
26067c478bd9Sstevel@tonic-gate &time_created[
26077c478bd9Sstevel@tonic-gate sizeof ("YYYY-MM-DD HH:MM:SS.xxx ")-1]);
26087c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING;
26097c478bd9Sstevel@tonic-gate uval.string_val = time_created;
26107c478bd9Sstevel@tonic-gate } else {
26117c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT32;
26127c478bd9Sstevel@tonic-gate uval.uint32_val = (uint32_t)tv_sec;
26137c478bd9Sstevel@tonic-gate (void) pa_print(context, &uval, 0);
26143929e195SMarek Pospisil if (context->format & PRF_XMLM) {
26153929e195SMarek Pospisil uval.uvaltype = PRA_CHAR;
26163929e195SMarek Pospisil uval.char_val = '.';
26173929e195SMarek Pospisil (void) pa_print(context, &uval, 0);
26183929e195SMarek Pospisil }
26197c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT32;
26207c478bd9Sstevel@tonic-gate uval.uint32_val = t32;
26217c478bd9Sstevel@tonic-gate }
26227c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag);
26237c478bd9Sstevel@tonic-gate }
26247c478bd9Sstevel@tonic-gate
26257c478bd9Sstevel@tonic-gate if (returnstat == 0)
26267c478bd9Sstevel@tonic-gate return (close_tag(context, TAG_ISO));
26277c478bd9Sstevel@tonic-gate else
26287c478bd9Sstevel@tonic-gate return (returnstat);
26297c478bd9Sstevel@tonic-gate }
26307c478bd9Sstevel@tonic-gate
26317c478bd9Sstevel@tonic-gate /*
26327c478bd9Sstevel@tonic-gate * Print time from struct timeval to millisecond resolution.
26337c478bd9Sstevel@tonic-gate *
26347c478bd9Sstevel@tonic-gate * typedef long time_t; time of day in seconds
26357c478bd9Sstevel@tonic-gate * typedef long useconds_t; signed # of microseconds
26367c478bd9Sstevel@tonic-gate *
26377c478bd9Sstevel@tonic-gate * struct timeval {
26387c478bd9Sstevel@tonic-gate * time_t tv_sec; seconds
26397c478bd9Sstevel@tonic-gate * suseconds_t tv_usec; and microseconds
26407c478bd9Sstevel@tonic-gate * };
26417c478bd9Sstevel@tonic-gate */
26427c478bd9Sstevel@tonic-gate
26437c478bd9Sstevel@tonic-gate int
pa_utime64(pr_context_t * context,int status,int flag)26447c478bd9Sstevel@tonic-gate pa_utime64(pr_context_t *context, int status, int flag)
26457c478bd9Sstevel@tonic-gate {
26467c478bd9Sstevel@tonic-gate uint64_t scale = 1000; /* usec to msec */
26477c478bd9Sstevel@tonic-gate
26487c478bd9Sstevel@tonic-gate return (do_mtime64(context, status, flag, scale));
26497c478bd9Sstevel@tonic-gate }
26507c478bd9Sstevel@tonic-gate
26517c478bd9Sstevel@tonic-gate /*
26527c478bd9Sstevel@tonic-gate * Print time from timestruc_t to millisecond resolution.
26537c478bd9Sstevel@tonic-gate *
26547c478bd9Sstevel@tonic-gate * typedef struct timespec timestruct_t;
26557c478bd9Sstevel@tonic-gate * struct timespec{
26567c478bd9Sstevel@tonic-gate * time_t tv_sec; seconds
26577c478bd9Sstevel@tonic-gate * long tv_nsec; and nanoseconds
26587c478bd9Sstevel@tonic-gate * };
26597c478bd9Sstevel@tonic-gate */
26607c478bd9Sstevel@tonic-gate int
pa_ntime64(pr_context_t * context,int status,int flag)26617c478bd9Sstevel@tonic-gate pa_ntime64(pr_context_t *context, int status, int flag)
26627c478bd9Sstevel@tonic-gate {
26637c478bd9Sstevel@tonic-gate uint64_t scale = 1000000; /* nsec to msec */
26647c478bd9Sstevel@tonic-gate
26657c478bd9Sstevel@tonic-gate return (do_mtime64(context, status, flag, scale));
26667c478bd9Sstevel@tonic-gate }
26677c478bd9Sstevel@tonic-gate
26687c478bd9Sstevel@tonic-gate /*
26697c478bd9Sstevel@tonic-gate * Format the milliseconds in place in the string.
26707c478bd9Sstevel@tonic-gate * Borrowed from strftime.c:itoa()
26717c478bd9Sstevel@tonic-gate */
26727c478bd9Sstevel@tonic-gate static void
msec64(uint64_t msec,char * p)26737c478bd9Sstevel@tonic-gate msec64(uint64_t msec, char *p)
26747c478bd9Sstevel@tonic-gate {
26757c478bd9Sstevel@tonic-gate *p++ = msec / 100 + '0';
26767c478bd9Sstevel@tonic-gate msec = msec - msec / 100 * 100;
26777c478bd9Sstevel@tonic-gate *p++ = msec / 10 + '0';
26787c478bd9Sstevel@tonic-gate *p++ = msec % 10 +'0';
26797c478bd9Sstevel@tonic-gate }
26807c478bd9Sstevel@tonic-gate
26817c478bd9Sstevel@tonic-gate /*
26827c478bd9Sstevel@tonic-gate * Format time and print relative to scale factor from micro/nano seconds.
26837c478bd9Sstevel@tonic-gate */
26847c478bd9Sstevel@tonic-gate static int
do_mtime64(pr_context_t * context,int status,int flag,uint64_t scale)26857c478bd9Sstevel@tonic-gate do_mtime64(pr_context_t *context, int status, int flag, uint64_t scale)
26867c478bd9Sstevel@tonic-gate {
26877c478bd9Sstevel@tonic-gate uint64_t t64_sec;
26887c478bd9Sstevel@tonic-gate uint64_t t64_msec;
26897c478bd9Sstevel@tonic-gate time_t tv_sec;
26907c478bd9Sstevel@tonic-gate struct tm tm;
26917c478bd9Sstevel@tonic-gate char time_created[sizeof ("YYYY-MM-DD HH:MM:SS.sss -HH:MM")];
26927c478bd9Sstevel@tonic-gate int returnstat;
26937c478bd9Sstevel@tonic-gate uval_t uval;
26947c478bd9Sstevel@tonic-gate
26957c478bd9Sstevel@tonic-gate if (status < 0)
26967c478bd9Sstevel@tonic-gate return (status);
26977c478bd9Sstevel@tonic-gate
26987c478bd9Sstevel@tonic-gate if ((returnstat = open_tag(context, TAG_ISO)) != 0)
26997c478bd9Sstevel@tonic-gate return (returnstat);
27007c478bd9Sstevel@tonic-gate
27017c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_int64(context, &t64_sec, 1)) != 0)
27027c478bd9Sstevel@tonic-gate return (returnstat);
27037c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_u_int64(context, &t64_msec, 1)) == 0) {
27047c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) {
27057c478bd9Sstevel@tonic-gate #ifndef _LP64
27067c478bd9Sstevel@tonic-gate /*
27077c478bd9Sstevel@tonic-gate * N.B.
27087c478bd9Sstevel@tonic-gate * This fails for years from 2038
27097c478bd9Sstevel@tonic-gate * The Y2K+38 problem
27107c478bd9Sstevel@tonic-gate */
27117c478bd9Sstevel@tonic-gate #endif /* !_LP64 */
27127c478bd9Sstevel@tonic-gate tv_sec = (time_t)t64_sec;
27137c478bd9Sstevel@tonic-gate (void) localtime_r(&tv_sec, &tm);
27147c478bd9Sstevel@tonic-gate (void) strftime(time_created,
27157c478bd9Sstevel@tonic-gate sizeof ("YYYY-MM-DD HH:MM:SS.xxx "),
27167c478bd9Sstevel@tonic-gate "%Y-%m-%d %H:%M:%S.xxx ", &tm);
27177c478bd9Sstevel@tonic-gate msec64(t64_msec/scale,
27187c478bd9Sstevel@tonic-gate &time_created[sizeof ("YYYY-MM-DD HH:MM:SS.")-1]);
27197c478bd9Sstevel@tonic-gate tzone(&tm, &tv_sec,
27207c478bd9Sstevel@tonic-gate &time_created[
27217c478bd9Sstevel@tonic-gate sizeof ("YYYY-MM-DD HH:MM:SS.xxx ")-1]);
27227c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING;
27237c478bd9Sstevel@tonic-gate uval.string_val = time_created;
27247c478bd9Sstevel@tonic-gate } else {
27257c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT64;
27267c478bd9Sstevel@tonic-gate uval.uint64_val = t64_sec;
27277c478bd9Sstevel@tonic-gate (void) pa_print(context, &uval, 0);
27283929e195SMarek Pospisil if (context->format & PRF_XMLM) {
27293929e195SMarek Pospisil uval.uvaltype = PRA_CHAR;
27303929e195SMarek Pospisil uval.char_val = '.';
27313929e195SMarek Pospisil (void) pa_print(context, &uval, 0);
27323929e195SMarek Pospisil }
27337c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT64;
27347c478bd9Sstevel@tonic-gate uval.uint64_val = t64_msec;
27357c478bd9Sstevel@tonic-gate }
27367c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag);
27377c478bd9Sstevel@tonic-gate }
27387c478bd9Sstevel@tonic-gate
27397c478bd9Sstevel@tonic-gate if (returnstat < 0)
27407c478bd9Sstevel@tonic-gate return (returnstat);
27417c478bd9Sstevel@tonic-gate
27427c478bd9Sstevel@tonic-gate return (close_tag(context, TAG_ISO));
27437c478bd9Sstevel@tonic-gate }
27447c478bd9Sstevel@tonic-gate
27457c478bd9Sstevel@tonic-gate /*
27467c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
27477c478bd9Sstevel@tonic-gate * pa_error() : convert the return token error code.
27487c478bd9Sstevel@tonic-gate *
27497c478bd9Sstevel@tonic-gate * output : buf string representing return token error code.
27507c478bd9Sstevel@tonic-gate *
27517c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
27527c478bd9Sstevel@tonic-gate */
27537c478bd9Sstevel@tonic-gate void
pa_error(const uchar_t err,char * buf,size_t buflen)27547c478bd9Sstevel@tonic-gate pa_error(const uchar_t err, char *buf, size_t buflen)
27557c478bd9Sstevel@tonic-gate {
2756f72effdeSgww if (err == ADT_SUCCESS) {
27577c478bd9Sstevel@tonic-gate (void) strlcpy(buf, gettext("success"), buflen);
2758f72effdeSgww } else if ((char)err == ADT_FAILURE) {
27597c478bd9Sstevel@tonic-gate (void) strlcpy(buf, gettext("failure"), buflen);
27607c478bd9Sstevel@tonic-gate } else {
27617c478bd9Sstevel@tonic-gate char *emsg = strerror(err);
27627c478bd9Sstevel@tonic-gate
27637c478bd9Sstevel@tonic-gate if (emsg != NULL) {
27647c478bd9Sstevel@tonic-gate (void) strlcpy(buf, gettext("failure: "), buflen);
27657c478bd9Sstevel@tonic-gate (void) strlcat(buf, emsg, buflen);
27667c478bd9Sstevel@tonic-gate } else {
27677c478bd9Sstevel@tonic-gate (void) snprintf(buf, buflen, "%s%d",
27687c478bd9Sstevel@tonic-gate gettext("failure: "), err);
27697c478bd9Sstevel@tonic-gate }
27707c478bd9Sstevel@tonic-gate }
27717c478bd9Sstevel@tonic-gate }
27727c478bd9Sstevel@tonic-gate
27737c478bd9Sstevel@tonic-gate /*
27747c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
2775a9729242Sgww * pa_retval() : convert the return token return value code.
2776a9729242Sgww *
2777a9729242Sgww * input : err, for kernel success 0, or
2778a9729242Sgww * failure errno: 0 > & < sys_nerr.
2779a9729242Sgww * for userland success ADT_SUCCESS (0) or
2780a9729242Sgww * failure ADT_FAILURE (-1).
2781a9729242Sgww * pa_error() above has already converted err.
2782a9729242Sgww *
2783a9729242Sgww * : retval, for kernel arbitrary return value for success, or
2784a9729242Sgww * failure: -1.
2785a9729242Sgww * for userland,
2786a9729242Sgww * >= ADT_FAIL_VALUE < ADT_FAIL_PAM, an adt message code;
2787a9729242Sgww * >= ADT_FAIL_PAM, a pam_strerror value;
2788a9729242Sgww * < ADT_FAIL_VALUE, supposed to be an errno.
27897c478bd9Sstevel@tonic-gate *
27907c478bd9Sstevel@tonic-gate * output : buf string representing return token error code.
27917c478bd9Sstevel@tonic-gate *
27927c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
27937c478bd9Sstevel@tonic-gate */
27947c478bd9Sstevel@tonic-gate void
pa_retval(const uchar_t err,const int32_t retval,char * buf,size_t buflen)2795f72effdeSgww pa_retval(const uchar_t err, const int32_t retval, char *buf, size_t buflen)
27967c478bd9Sstevel@tonic-gate {
2797a9729242Sgww struct msg_text *msglist;
2798a9729242Sgww char *emsg;
2799a9729242Sgww
2800a9729242Sgww /* success or kernel failure */
2801a9729242Sgww if (((char)err == ADT_SUCCESS) ||
2802a9729242Sgww (retval < 0)) {
2803a9729242Sgww
2804a9729242Sgww (void) snprintf(buf, buflen, "%d", retval);
2805a9729242Sgww return;
2806a9729242Sgww }
2807a9729242Sgww
2808a9729242Sgww /* userland failure */
2809a9729242Sgww msglist = &adt_msg_text[ADT_LIST_FAIL_VALUE];
28107c478bd9Sstevel@tonic-gate
28117c478bd9Sstevel@tonic-gate if ((retval + msglist->ml_offset >= msglist->ml_min_index) &&
28127c478bd9Sstevel@tonic-gate (retval + msglist->ml_offset <= msglist->ml_max_index)) {
28137c478bd9Sstevel@tonic-gate
28147c478bd9Sstevel@tonic-gate (void) strlcpy(buf,
28157c478bd9Sstevel@tonic-gate gettext(msglist->ml_msg_list[retval + msglist->ml_offset]),
28167c478bd9Sstevel@tonic-gate buflen);
28177c478bd9Sstevel@tonic-gate } else if ((retval >= ADT_FAIL_PAM) &&
2818f72effdeSgww (retval < ADT_FAIL_PAM + PAM_TOTAL_ERRNUM)) {
2819a9729242Sgww
28207c478bd9Sstevel@tonic-gate (void) strlcpy(buf, pam_strerror(NULL, retval - ADT_FAIL_PAM),
28217c478bd9Sstevel@tonic-gate buflen);
2822a9729242Sgww } else if ((emsg = strerror(retval)) != NULL) {
2823f72effdeSgww
2824a9729242Sgww (void) strlcpy(buf, emsg, buflen);
2825f72effdeSgww } else {
2826a9729242Sgww
28277c478bd9Sstevel@tonic-gate (void) snprintf(buf, buflen, "%d", retval);
2828f72effdeSgww }
28297c478bd9Sstevel@tonic-gate }
28307c478bd9Sstevel@tonic-gate
28317c478bd9Sstevel@tonic-gate /*
28327c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
28337c478bd9Sstevel@tonic-gate * pa_printstr() : print a given string, translating unprintables
28347c478bd9Sstevel@tonic-gate * : as needed.
28357c478bd9Sstevel@tonic-gate */
28367c478bd9Sstevel@tonic-gate static int
pa_printstr(pr_context_t * context,char * str)28377c478bd9Sstevel@tonic-gate pa_printstr(pr_context_t *context, char *str)
28387c478bd9Sstevel@tonic-gate {
28397c478bd9Sstevel@tonic-gate int err = 0;
28407c478bd9Sstevel@tonic-gate int len, printable;
28417c478bd9Sstevel@tonic-gate int mbmax = MB_CUR_MAX;
28427c478bd9Sstevel@tonic-gate wchar_t wc;
28437c478bd9Sstevel@tonic-gate char c;
28447c478bd9Sstevel@tonic-gate
28457c478bd9Sstevel@tonic-gate if (mbmax == 1) {
28467c478bd9Sstevel@tonic-gate /* fast path */
28477c478bd9Sstevel@tonic-gate while (err == 0 && *str != '\0') {
28487c478bd9Sstevel@tonic-gate c = *str++;
28497c478bd9Sstevel@tonic-gate printable = isprint((unsigned char)c);
28507c478bd9Sstevel@tonic-gate err = pa_putstr(context, printable, &c, 1);
28517c478bd9Sstevel@tonic-gate }
28527c478bd9Sstevel@tonic-gate return (err);
28537c478bd9Sstevel@tonic-gate }
28547c478bd9Sstevel@tonic-gate while (err == 0 && *str != '\0') {
28557c478bd9Sstevel@tonic-gate len = mbtowc(&wc, str, mbmax);
28567c478bd9Sstevel@tonic-gate if (len <= 0) {
28577c478bd9Sstevel@tonic-gate len = 1;
28587c478bd9Sstevel@tonic-gate printable = 0;
28597c478bd9Sstevel@tonic-gate } else {
28607c478bd9Sstevel@tonic-gate printable = iswprint(wc);
28617c478bd9Sstevel@tonic-gate }
28627c478bd9Sstevel@tonic-gate err = pa_putstr(context, printable, str, len);
28637c478bd9Sstevel@tonic-gate str += len;
28647c478bd9Sstevel@tonic-gate }
28657c478bd9Sstevel@tonic-gate return (err);
28667c478bd9Sstevel@tonic-gate }
28677c478bd9Sstevel@tonic-gate
28687c478bd9Sstevel@tonic-gate /*
28697c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
28707c478bd9Sstevel@tonic-gate * pa_print() : print as one str or formatted for easy reading.
2871*8bb3e7e3SPeter Tribble * : flag - indicates whether to output a new line for
28727c478bd9Sstevel@tonic-gate * : multi-line output.
2873*8bb3e7e3SPeter Tribble * : = 0; no new line
28747c478bd9Sstevel@tonic-gate * : = 1; new line if regular output
28757c478bd9Sstevel@tonic-gate * output : The audit record information is displayed in the
28767c478bd9Sstevel@tonic-gate * type specified by uvaltype and value specified in
28777c478bd9Sstevel@tonic-gate * uval. The printing of the delimiter or newline is
28787c478bd9Sstevel@tonic-gate * determined by PRF_ONELINE, and the flag value,
28797c478bd9Sstevel@tonic-gate * as follows:
28807c478bd9Sstevel@tonic-gate * +--------+------+------+-----------------+
28817c478bd9Sstevel@tonic-gate * |ONELINE | flag | last | Action |
28827c478bd9Sstevel@tonic-gate * +--------+------+------+-----------------+
28837c478bd9Sstevel@tonic-gate * | Y | Y | T | print new line |
28847c478bd9Sstevel@tonic-gate * | Y | Y | F | print delimiter |
28857c478bd9Sstevel@tonic-gate * | Y | N | T | print new line |
28867c478bd9Sstevel@tonic-gate * | Y | N | F | print delimiter |
28877c478bd9Sstevel@tonic-gate * | N | Y | T | print new line |
28887c478bd9Sstevel@tonic-gate * | N | Y | F | print new line |
28897c478bd9Sstevel@tonic-gate * | N | N | T | print new line |
28907c478bd9Sstevel@tonic-gate * | N | N | F | print delimiter |
28917c478bd9Sstevel@tonic-gate * +--------+------+------+-----------------+
28927c478bd9Sstevel@tonic-gate *
28937c478bd9Sstevel@tonic-gate * return codes : -1 - error
28947c478bd9Sstevel@tonic-gate * 0 - successful
28957c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
28967c478bd9Sstevel@tonic-gate */
28977c478bd9Sstevel@tonic-gate int
pa_print(pr_context_t * context,uval_t * uval,int flag)28987c478bd9Sstevel@tonic-gate pa_print(pr_context_t *context, uval_t *uval, int flag)
28997c478bd9Sstevel@tonic-gate {
29007c478bd9Sstevel@tonic-gate int returnstat = 0;
29017c478bd9Sstevel@tonic-gate int last;
29027c478bd9Sstevel@tonic-gate
29037c478bd9Sstevel@tonic-gate switch (uval->uvaltype) {
29047c478bd9Sstevel@tonic-gate case PRA_INT32:
29057c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%d", uval->int32_val);
29067c478bd9Sstevel@tonic-gate break;
29077c478bd9Sstevel@tonic-gate case PRA_UINT32:
29087c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%u", uval->uint32_val);
29097c478bd9Sstevel@tonic-gate break;
29107c478bd9Sstevel@tonic-gate case PRA_INT64:
29117c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%"PRId64, uval->int64_val);
29127c478bd9Sstevel@tonic-gate break;
29137c478bd9Sstevel@tonic-gate case PRA_UINT64:
29147c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%"PRIu64, uval->uint64_val);
29157c478bd9Sstevel@tonic-gate break;
29167c478bd9Sstevel@tonic-gate case PRA_SHORT:
29177c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%hd", uval->short_val);
29187c478bd9Sstevel@tonic-gate break;
29197c478bd9Sstevel@tonic-gate case PRA_USHORT:
29207c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%hu", uval->ushort_val);
29217c478bd9Sstevel@tonic-gate break;
29227c478bd9Sstevel@tonic-gate case PRA_CHAR:
29237c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%c", uval->char_val);
29247c478bd9Sstevel@tonic-gate break;
29257c478bd9Sstevel@tonic-gate case PRA_BYTE:
29267c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%d", uval->char_val);
29277c478bd9Sstevel@tonic-gate break;
29287c478bd9Sstevel@tonic-gate case PRA_STRING:
29297c478bd9Sstevel@tonic-gate returnstat = pa_printstr(context, uval->string_val);
29307c478bd9Sstevel@tonic-gate break;
29317c478bd9Sstevel@tonic-gate case PRA_HEX32:
29327c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "0x%x", uval->int32_val);
29337c478bd9Sstevel@tonic-gate break;
29347c478bd9Sstevel@tonic-gate case PRA_HEX64:
29357c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "0x%"PRIx64, uval->int64_val);
29367c478bd9Sstevel@tonic-gate break;
29377c478bd9Sstevel@tonic-gate case PRA_SHEX:
29387c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "0x%hx", uval->short_val);
29397c478bd9Sstevel@tonic-gate break;
29407c478bd9Sstevel@tonic-gate case PRA_OCT:
29417c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%ho", uval->ushort_val);
29427c478bd9Sstevel@tonic-gate break;
29437c478bd9Sstevel@tonic-gate case PRA_LOCT:
29447c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%o", (int)uval->uint32_val);
29457c478bd9Sstevel@tonic-gate break;
29467c478bd9Sstevel@tonic-gate default:
29477c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("praudit: Unknown type.\n"));
29487c478bd9Sstevel@tonic-gate returnstat = -1;
29497c478bd9Sstevel@tonic-gate break;
29507c478bd9Sstevel@tonic-gate }
29517c478bd9Sstevel@tonic-gate if (returnstat < 0)
29527c478bd9Sstevel@tonic-gate return (returnstat);
29537c478bd9Sstevel@tonic-gate
29547c478bd9Sstevel@tonic-gate last = (context->audit_adr->adr_now ==
29557c478bd9Sstevel@tonic-gate (context->audit_rec_start + context->audit_rec_len));
29567c478bd9Sstevel@tonic-gate
29577c478bd9Sstevel@tonic-gate if (!(context->format & PRF_XMLM)) {
29587c478bd9Sstevel@tonic-gate if (!(context->format & PRF_ONELINE)) {
29597c478bd9Sstevel@tonic-gate if ((flag == 1) || last)
29607c478bd9Sstevel@tonic-gate returnstat = pr_putchar(context, '\n');
29617c478bd9Sstevel@tonic-gate else
29627c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%s",
29637c478bd9Sstevel@tonic-gate context->SEPARATOR);
29647c478bd9Sstevel@tonic-gate } else {
29657c478bd9Sstevel@tonic-gate if (!last)
29667c478bd9Sstevel@tonic-gate returnstat = pr_printf(context, "%s",
29677c478bd9Sstevel@tonic-gate context->SEPARATOR);
29687c478bd9Sstevel@tonic-gate else
29697c478bd9Sstevel@tonic-gate returnstat = pr_putchar(context, '\n');
29707c478bd9Sstevel@tonic-gate }
29717c478bd9Sstevel@tonic-gate }
29727c478bd9Sstevel@tonic-gate return (returnstat);
29737c478bd9Sstevel@tonic-gate }
29747c478bd9Sstevel@tonic-gate
29758dc347dbStz static struct cntrl_mapping {
29768dc347dbStz char from;
29778dc347dbStz char to;
29788dc347dbStz } cntrl_map[] = {
29798dc347dbStz '\0', '0',
29808dc347dbStz '\a', 'a',
29818dc347dbStz '\b', 'b',
29828dc347dbStz '\t', 't',
29838dc347dbStz '\f', 'f',
29848dc347dbStz '\n', 'n',
29858dc347dbStz '\r', 'r',
29868dc347dbStz '\v', 'v'
29878dc347dbStz };
29888dc347dbStz
29898dc347dbStz static int cntrl_map_entries = sizeof (cntrl_map)
29908dc347dbStz / sizeof (struct cntrl_mapping);
29918dc347dbStz
29927c478bd9Sstevel@tonic-gate /*
29937c478bd9Sstevel@tonic-gate * Convert binary data to ASCII for printing.
29947c478bd9Sstevel@tonic-gate */
29957c478bd9Sstevel@tonic-gate void
convertascii(char * p,char * c,int size)29967c478bd9Sstevel@tonic-gate convertascii(char *p, char *c, int size)
29977c478bd9Sstevel@tonic-gate {
299885298dc1Snakanon int i, j, uc;
29997c478bd9Sstevel@tonic-gate
30007c478bd9Sstevel@tonic-gate for (i = 0; i < size; i++) {
300185298dc1Snakanon uc = (unsigned char)*(c + i);
300285298dc1Snakanon if (isascii(uc)) {
300385298dc1Snakanon if (iscntrl(uc)) {
300485298dc1Snakanon for (j = 0; j < cntrl_map_entries; j++) {
300585298dc1Snakanon if (cntrl_map[j].from == uc) {
300685298dc1Snakanon *p++ = '\\';
300785298dc1Snakanon *p++ = cntrl_map[j].to;
300885298dc1Snakanon break;
300985298dc1Snakanon }
301085298dc1Snakanon }
301185298dc1Snakanon if (j == cntrl_map_entries) {
301285298dc1Snakanon *p++ = '^';
301385298dc1Snakanon *p++ = (char)(uc ^ 0100);
30148dc347dbStz }
301585298dc1Snakanon } else {
301685298dc1Snakanon *p++ = (char)uc;
30178dc347dbStz }
301885298dc1Snakanon } else {
301985298dc1Snakanon p += sprintf(p, "\\%03o", uc);
302085298dc1Snakanon }
30217c478bd9Sstevel@tonic-gate }
30227c478bd9Sstevel@tonic-gate *p = '\0';
30237c478bd9Sstevel@tonic-gate }
30247c478bd9Sstevel@tonic-gate
30257c478bd9Sstevel@tonic-gate /*
30267c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
30277c478bd9Sstevel@tonic-gate * pa_xgeneric: Process Xobject token and display contents
30287c478bd9Sstevel@tonic-gate * This routine will handle many of the attribute
30297c478bd9Sstevel@tonic-gate * types introduced in TS 2.x, such as:
30307c478bd9Sstevel@tonic-gate *
30317c478bd9Sstevel@tonic-gate * AUT_XCOLORMAP, AUT_XCURSOR, AUT_XFONT,
30327c478bd9Sstevel@tonic-gate * AUT_XGC, AUT_XPIXMAP, AUT_XWINDOW
30337c478bd9Sstevel@tonic-gate *
30347c478bd9Sstevel@tonic-gate * NOTE: At the time of call, the token id has been retrieved
30357c478bd9Sstevel@tonic-gate *
30367c478bd9Sstevel@tonic-gate * return codes : -1 - error
30377c478bd9Sstevel@tonic-gate * : 0 - successful
30387c478bd9Sstevel@tonic-gate * NOTE: At the time of call, the xatom token id has been retrieved
30397c478bd9Sstevel@tonic-gate *
30407c478bd9Sstevel@tonic-gate * Format of xobj
30417c478bd9Sstevel@tonic-gate * text token id adr_char
3042*8bb3e7e3SPeter Tribble * XID adr_u_int32
3043*8bb3e7e3SPeter Tribble * creator uid adr_pw_uid
30447c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
30457c478bd9Sstevel@tonic-gate */
30467c478bd9Sstevel@tonic-gate int
pa_xgeneric(pr_context_t * context)30477c478bd9Sstevel@tonic-gate pa_xgeneric(pr_context_t *context)
30487c478bd9Sstevel@tonic-gate {
30497c478bd9Sstevel@tonic-gate int returnstat;
30507c478bd9Sstevel@tonic-gate
30517c478bd9Sstevel@tonic-gate returnstat = process_tag(context, TAG_XID, 0, 0);
30527c478bd9Sstevel@tonic-gate return (process_tag(context, TAG_XCUID, returnstat, 1));
30537c478bd9Sstevel@tonic-gate }
30547c478bd9Sstevel@tonic-gate
30557c478bd9Sstevel@tonic-gate
30567c478bd9Sstevel@tonic-gate /*
30577c478bd9Sstevel@tonic-gate * ------------------------------------------------------------------------
30587c478bd9Sstevel@tonic-gate * pa_liaison : Issues pr_adr_char to retrieve the next ADR item from the
30597c478bd9Sstevel@tonic-gate * input stream pointed to by audit_adr, and prints it
30607c478bd9Sstevel@tonic-gate * if status >= 0 either in ASCII or raw form
30617c478bd9Sstevel@tonic-gate * return codes : -1 - error
30627c478bd9Sstevel@tonic-gate * : 0 - successful
30637c478bd9Sstevel@tonic-gate * : 1 - warning, unknown label type
30647c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------------
30657c478bd9Sstevel@tonic-gate */
30667c478bd9Sstevel@tonic-gate int
pa_liaison(pr_context_t * context,int status,int flag)30677c478bd9Sstevel@tonic-gate pa_liaison(pr_context_t *context, int status, int flag)
30687c478bd9Sstevel@tonic-gate {
30697c478bd9Sstevel@tonic-gate int returnstat;
30707c478bd9Sstevel@tonic-gate int32_t li;
30717c478bd9Sstevel@tonic-gate uval_t uval;
30727c478bd9Sstevel@tonic-gate
30737c478bd9Sstevel@tonic-gate if (status >= 0) {
30747c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_int32(context, &li, 1)) != 0) {
30757c478bd9Sstevel@tonic-gate return (returnstat);
30767c478bd9Sstevel@tonic-gate }
30777c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) {
30787c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_UINT32;
30797c478bd9Sstevel@tonic-gate uval.uint32_val = li;
30807c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag);
30817c478bd9Sstevel@tonic-gate }
30827c478bd9Sstevel@tonic-gate /* print in hexadecimal form */
30837c478bd9Sstevel@tonic-gate if ((context->format & PRF_RAWM) || (returnstat == 1)) {
30847c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_HEX32;
30857c478bd9Sstevel@tonic-gate uval.uint32_val = li;
30867c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag);
30877c478bd9Sstevel@tonic-gate }
30887c478bd9Sstevel@tonic-gate return (returnstat);
30897c478bd9Sstevel@tonic-gate } else
30907c478bd9Sstevel@tonic-gate return (status);
30917c478bd9Sstevel@tonic-gate }
30927c478bd9Sstevel@tonic-gate
30937c478bd9Sstevel@tonic-gate /*
30947c478bd9Sstevel@tonic-gate * ------------------------------------------------------------------------
30957c478bd9Sstevel@tonic-gate * pa_xid : Issues pr_adr_int32 to retrieve the XID from the input
30967c478bd9Sstevel@tonic-gate * stream pointed to by audit_adr, and prints it if
30977c478bd9Sstevel@tonic-gate * status >= 0 either in ASCII or raw form
30987c478bd9Sstevel@tonic-gate * return codes : -1 - error
30997c478bd9Sstevel@tonic-gate * : 0 - successful
31007c478bd9Sstevel@tonic-gate * : 1 - warning, unknown label type
31017c478bd9Sstevel@tonic-gate * ------------------------------------------------------------------------
31027c478bd9Sstevel@tonic-gate */
31037c478bd9Sstevel@tonic-gate
31047c478bd9Sstevel@tonic-gate int
pa_xid(pr_context_t * context,int status,int flag)31057c478bd9Sstevel@tonic-gate pa_xid(pr_context_t *context, int status, int flag)
31067c478bd9Sstevel@tonic-gate {
31077c478bd9Sstevel@tonic-gate int returnstat;
31087c478bd9Sstevel@tonic-gate int32_t xid;
31097c478bd9Sstevel@tonic-gate uval_t uval;
31107c478bd9Sstevel@tonic-gate
31117c478bd9Sstevel@tonic-gate if (status < 0)
31127c478bd9Sstevel@tonic-gate return (status);
31137c478bd9Sstevel@tonic-gate
31147c478bd9Sstevel@tonic-gate /* get XID from stream */
31157c478bd9Sstevel@tonic-gate if ((returnstat = pr_adr_int32(context, (int32_t *)&xid, 1)) != 0)
31167c478bd9Sstevel@tonic-gate return (returnstat);
31177c478bd9Sstevel@tonic-gate
31187c478bd9Sstevel@tonic-gate if (!(context->format & PRF_RAWM)) {
31197c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_STRING;
31207c478bd9Sstevel@tonic-gate uval.string_val = hexconvert((char *)&xid, sizeof (xid),
31217c478bd9Sstevel@tonic-gate sizeof (xid));
31227c478bd9Sstevel@tonic-gate if (uval.string_val) {
31237c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag);
31247c478bd9Sstevel@tonic-gate free(uval.string_val);
31257c478bd9Sstevel@tonic-gate }
31267c478bd9Sstevel@tonic-gate } else {
31277c478bd9Sstevel@tonic-gate uval.uvaltype = PRA_INT32;
31287c478bd9Sstevel@tonic-gate uval.int32_val = xid;
31297c478bd9Sstevel@tonic-gate returnstat = pa_print(context, &uval, flag);
31307c478bd9Sstevel@tonic-gate }
31317c478bd9Sstevel@tonic-gate
31327c478bd9Sstevel@tonic-gate return (returnstat);
31337c478bd9Sstevel@tonic-gate }
3134a7746f66Stz
3135a7746f66Stz static int
pa_ace_flags(pr_context_t * context,ace_t * ace,int status,int flag)3136a7746f66Stz pa_ace_flags(pr_context_t *context, ace_t *ace, int status, int flag)
3137a7746f66Stz {
3138a7746f66Stz int returnstat;
3139a7746f66Stz uval_t uval;
3140a7746f66Stz
3141a7746f66Stz if (status < 0)
3142a7746f66Stz return (status);
3143a7746f66Stz
3144a7746f66Stz /*
3145a7746f66Stz * TRANSLATION_NOTE
3146a7746f66Stz * ace->a_flags refers to access flags of ZFS/NFSv4 ACL entry.
3147a7746f66Stz */
3148a7746f66Stz if ((returnstat = open_tag(context, TAG_ACEFLAGS)) != 0)
3149a7746f66Stz return (returnstat);
3150a7746f66Stz if (!(context->format & PRF_RAWM)) {
3151a7746f66Stz uval.uvaltype = PRA_STRING;
3152a7746f66Stz switch (ace->a_flags & ACE_TYPE_FLAGS) {
3153a7746f66Stz case ACE_OWNER:
3154a7746f66Stz uval.string_val = gettext(OWNERAT_TXT);
3155a7746f66Stz break;
3156a7746f66Stz case ACE_GROUP | ACE_IDENTIFIER_GROUP:
3157a7746f66Stz uval.string_val = gettext(GROUPAT_TXT);
3158a7746f66Stz break;
3159a7746f66Stz case ACE_IDENTIFIER_GROUP:
3160a7746f66Stz uval.string_val = gettext(GROUP_TXT);
3161a7746f66Stz break;
3162a7746f66Stz case ACE_EVERYONE:
3163a7746f66Stz uval.string_val = gettext(EVERYONEAT_TXT);
3164a7746f66Stz break;
3165a7746f66Stz case 0:
3166a7746f66Stz uval.string_val = gettext(USER_TXT);
3167a7746f66Stz break;
3168a7746f66Stz default:
3169a7746f66Stz uval.uvaltype = PRA_USHORT;
3170a7746f66Stz uval.uint32_val = ace->a_flags;
3171a7746f66Stz }
3172a7746f66Stz } else {
3173a7746f66Stz uval.uvaltype = PRA_USHORT;
3174a7746f66Stz uval.uint32_val = ace->a_flags;
3175a7746f66Stz }
3176a7746f66Stz if ((returnstat = pa_print(context, &uval, flag)) != 0)
3177a7746f66Stz return (returnstat);
3178a7746f66Stz return (close_tag(context, TAG_ACEFLAGS));
3179a7746f66Stz }
3180a7746f66Stz
3181a7746f66Stz static int
pa_ace_who(pr_context_t * context,ace_t * ace,int status,int flag)3182a7746f66Stz pa_ace_who(pr_context_t *context, ace_t *ace, int status, int flag)
3183a7746f66Stz {
3184a7746f66Stz int returnstat;
3185a7746f66Stz
3186a7746f66Stz if (status < 0)
3187a7746f66Stz return (status);
3188a7746f66Stz
3189a7746f66Stz /*
3190a7746f66Stz * TRANSLATION_NOTE
3191a7746f66Stz * ace->a_who refers to user id or group id of ZFS/NFSv4 ACL entry.
3192a7746f66Stz */
3193a7746f66Stz if ((returnstat = open_tag(context, TAG_ACEID)) != 0)
3194a7746f66Stz return (returnstat);
3195a7746f66Stz switch (ace->a_flags & ACE_TYPE_FLAGS) {
3196a7746f66Stz case ACE_IDENTIFIER_GROUP: /* group id */
3197a7746f66Stz returnstat = pa_print_gid(context, ace->a_who, returnstat,
3198a7746f66Stz flag);
3199a7746f66Stz break;
3200a7746f66Stz default: /* user id */
3201a7746f66Stz returnstat = pa_print_uid(context, ace->a_who, returnstat,
3202a7746f66Stz flag);
3203a7746f66Stz break;
3204a7746f66Stz }
3205a7746f66Stz if (returnstat < 0)
3206a7746f66Stz return (returnstat);
3207a7746f66Stz return (close_tag(context, TAG_ACEID));
3208a7746f66Stz }
3209a7746f66Stz
3210a7746f66Stz /*
3211a7746f66Stz * Appends what to str, (re)allocating str if necessary.
3212a7746f66Stz */
3213a7746f66Stz #define INITIAL_ALLOC 256
3214a7746f66Stz static int
strappend(char ** str,char * what,size_t * alloc)3215a7746f66Stz strappend(char **str, char *what, size_t *alloc)
3216a7746f66Stz {
3217a7746f66Stz char *s, *newstr;
3218a7746f66Stz size_t needed;
3219a7746f66Stz
3220a7746f66Stz s = *str;
3221a7746f66Stz
3222a7746f66Stz if (s == NULL) {
3223a7746f66Stz s = malloc(INITIAL_ALLOC);
3224a7746f66Stz if (s == NULL) {
3225a7746f66Stz *alloc = 0;
3226a7746f66Stz return (-1);
3227a7746f66Stz }
3228a7746f66Stz *alloc = INITIAL_ALLOC;
3229a7746f66Stz s[0] = '\0';
3230a7746f66Stz *str = s;
3231a7746f66Stz }
3232a7746f66Stz
3233a7746f66Stz needed = strlen(s) + strlen(what) + 1;
3234a7746f66Stz if (*alloc < needed) {
3235a7746f66Stz newstr = realloc(s, needed);
3236a7746f66Stz if (newstr == NULL)
3237a7746f66Stz return (-1);
3238a7746f66Stz s = newstr;
3239a7746f66Stz *alloc = needed;
3240a7746f66Stz *str = s;
3241a7746f66Stz }
3242a7746f66Stz (void) strlcat(s, what, *alloc);
3243a7746f66Stz
3244a7746f66Stz return (0);
3245a7746f66Stz }
3246a7746f66Stz
3247a7746f66Stz static int
pa_ace_access_mask(pr_context_t * context,ace_t * ace,int status,int flag)3248a7746f66Stz pa_ace_access_mask(pr_context_t *context, ace_t *ace, int status, int flag)
3249a7746f66Stz {
3250a7746f66Stz int returnstat, i;
3251a7746f66Stz uval_t uval;
3252a7746f66Stz char *permstr = NULL;
3253a7746f66Stz size_t permstr_alloc = 0;
3254a7746f66Stz
3255a7746f66Stz if (status < 0)
3256a7746f66Stz return (status);
3257a7746f66Stz
3258a7746f66Stz /*
3259a7746f66Stz * TRANSLATION_NOTE
3260a7746f66Stz * ace->a_access_mask refers to access mask of ZFS/NFSv4 ACL entry.
3261a7746f66Stz */
3262a7746f66Stz if ((returnstat = open_tag(context, TAG_ACEMASK)) != 0)
3263a7746f66Stz return (returnstat);
3264a7746f66Stz if (context->format & PRF_SHORTM &&
3265a7746f66Stz ((permstr = malloc(15)) != NULL)) {
3266a7746f66Stz for (i = 0; i < 14; i++)
3267a7746f66Stz permstr[i] = '-';
3268a7746f66Stz
3269a7746f66Stz if (ace->a_access_mask & ACE_READ_DATA)
3270a7746f66Stz permstr[0] = 'r';
3271a7746f66Stz if (ace->a_access_mask & ACE_WRITE_DATA)
3272a7746f66Stz permstr[1] = 'w';
3273a7746f66Stz if (ace->a_access_mask & ACE_EXECUTE)
3274a7746f66Stz permstr[2] = 'x';
3275a7746f66Stz if (ace->a_access_mask & ACE_APPEND_DATA)
3276a7746f66Stz permstr[3] = 'p';
3277a7746f66Stz if (ace->a_access_mask & ACE_DELETE)
3278a7746f66Stz permstr[4] = 'd';
3279a7746f66Stz if (ace->a_access_mask & ACE_DELETE_CHILD)
3280a7746f66Stz permstr[5] = 'D';
3281a7746f66Stz if (ace->a_access_mask & ACE_READ_ATTRIBUTES)
3282a7746f66Stz permstr[6] = 'a';
3283a7746f66Stz if (ace->a_access_mask & ACE_WRITE_ATTRIBUTES)
3284a7746f66Stz permstr[7] = 'A';
3285a7746f66Stz if (ace->a_access_mask & ACE_READ_NAMED_ATTRS)
3286a7746f66Stz permstr[8] = 'R';
3287a7746f66Stz if (ace->a_access_mask & ACE_WRITE_NAMED_ATTRS)
3288a7746f66Stz permstr[9] = 'W';
3289a7746f66Stz if (ace->a_access_mask & ACE_READ_ACL)
3290a7746f66Stz permstr[10] = 'c';
3291a7746f66Stz if (ace->a_access_mask & ACE_WRITE_ACL)
3292a7746f66Stz permstr[11] = 'C';
3293a7746f66Stz if (ace->a_access_mask & ACE_WRITE_OWNER)
3294a7746f66Stz permstr[12] = 'o';
3295a7746f66Stz if (ace->a_access_mask & ACE_SYNCHRONIZE)
3296a7746f66Stz permstr[13] = 's';
3297a7746f66Stz permstr[14] = '\0';
3298a7746f66Stz uval.uvaltype = PRA_STRING;
3299a7746f66Stz uval.string_val = permstr;
3300a7746f66Stz } else if (!(context->format & PRF_RAWM)) {
3301a7746f66Stz
3302a7746f66Stz /*
3303a7746f66Stz * Note this differs from acltext.c:ace_perm_txt()
3304a7746f66Stz * because we don't know if the acl belongs to a file
3305a7746f66Stz * or directory. ace mask value are the same
3306a7746f66Stz * nonetheless, see sys/acl.h
3307a7746f66Stz */
3308a7746f66Stz if (ace->a_access_mask & ACE_LIST_DIRECTORY) {
3309a7746f66Stz returnstat = strappend(&permstr, gettext(READ_DIR_TXT),
3310a7746f66Stz &permstr_alloc);
3311a7746f66Stz }
3312a7746f66Stz if (ace->a_access_mask & ACE_ADD_FILE) {
3313a7746f66Stz returnstat = strappend(&permstr, gettext(ADD_FILE_TXT),
3314a7746f66Stz &permstr_alloc);
3315a7746f66Stz }
3316a7746f66Stz if (ace->a_access_mask & ACE_ADD_SUBDIRECTORY) {
3317a7746f66Stz returnstat = strappend(&permstr, gettext(ADD_DIR_TXT),
3318a7746f66Stz &permstr_alloc);
3319a7746f66Stz }
3320a7746f66Stz if (ace->a_access_mask & ACE_READ_NAMED_ATTRS) {
3321a7746f66Stz returnstat = strappend(&permstr,
3322a7746f66Stz gettext(READ_XATTR_TXT), &permstr_alloc);
3323a7746f66Stz }
3324a7746f66Stz if (ace->a_access_mask & ACE_WRITE_NAMED_ATTRS) {
3325a7746f66Stz returnstat = strappend(&permstr,
3326a7746f66Stz gettext(WRITE_XATTR_TXT), &permstr_alloc);
3327a7746f66Stz }
3328a7746f66Stz if (ace->a_access_mask & ACE_EXECUTE) {
3329a7746f66Stz returnstat = strappend(&permstr,
3330a7746f66Stz gettext(EXECUTE_TXT), &permstr_alloc);
3331a7746f66Stz }
3332a7746f66Stz if (ace->a_access_mask & ACE_DELETE_CHILD) {
3333a7746f66Stz returnstat = strappend(&permstr,
3334a7746f66Stz gettext(DELETE_CHILD_TXT), &permstr_alloc);
3335a7746f66Stz }
3336a7746f66Stz if (ace->a_access_mask & ACE_READ_ATTRIBUTES) {
3337a7746f66Stz returnstat = strappend(&permstr,
3338a7746f66Stz gettext(READ_ATTRIBUTES_TXT), &permstr_alloc);
3339a7746f66Stz }
3340a7746f66Stz if (ace->a_access_mask & ACE_WRITE_ATTRIBUTES) {
3341a7746f66Stz returnstat = strappend(&permstr,
3342a7746f66Stz gettext(WRITE_ATTRIBUTES_TXT), &permstr_alloc);
3343a7746f66Stz }
3344a7746f66Stz if (ace->a_access_mask & ACE_DELETE) {
3345a7746f66Stz returnstat = strappend(&permstr, gettext(DELETE_TXT),
3346a7746f66Stz &permstr_alloc);
3347a7746f66Stz }
3348a7746f66Stz if (ace->a_access_mask & ACE_READ_ACL) {
3349a7746f66Stz returnstat = strappend(&permstr, gettext(READ_ACL_TXT),
3350a7746f66Stz &permstr_alloc);
3351a7746f66Stz }
3352a7746f66Stz if (ace->a_access_mask & ACE_WRITE_ACL) {
3353a7746f66Stz returnstat = strappend(&permstr, gettext(WRITE_ACL_TXT),
3354a7746f66Stz &permstr_alloc);
3355a7746f66Stz }
3356a7746f66Stz if (ace->a_access_mask & ACE_WRITE_OWNER) {
3357a7746f66Stz returnstat = strappend(&permstr,
3358a7746f66Stz gettext(WRITE_OWNER_TXT), &permstr_alloc);
3359a7746f66Stz }
3360a7746f66Stz if (ace->a_access_mask & ACE_SYNCHRONIZE) {
3361a7746f66Stz returnstat = strappend(&permstr,
3362a7746f66Stz gettext(SYNCHRONIZE_TXT), &permstr_alloc);
3363a7746f66Stz }
3364a7746f66Stz if (permstr[strlen(permstr) - 1] == '/')
3365a7746f66Stz permstr[strlen(permstr) - 1] = '\0';
3366a7746f66Stz uval.uvaltype = PRA_STRING;
3367a7746f66Stz uval.string_val = permstr;
3368a7746f66Stz }
3369a7746f66Stz if ((permstr == NULL) || (returnstat != 0) ||
3370a7746f66Stz (context->format & PRF_RAWM)) {
3371a7746f66Stz uval.uvaltype = PRA_UINT32;
3372a7746f66Stz uval.uint32_val = ace->a_access_mask;
3373a7746f66Stz }
3374a7746f66Stz returnstat = pa_print(context, &uval, flag);
3375a7746f66Stz
3376a7746f66Stz if (permstr != NULL)
3377a7746f66Stz free(permstr);
3378a7746f66Stz if (returnstat != 0)
3379a7746f66Stz return (returnstat);
3380a7746f66Stz return (close_tag(context, TAG_ACEMASK));
3381a7746f66Stz }
3382a7746f66Stz
3383a7746f66Stz static int
pa_ace_type(pr_context_t * context,ace_t * ace,int status,int flag)3384a7746f66Stz pa_ace_type(pr_context_t *context, ace_t *ace, int status, int flag)
3385a7746f66Stz {
3386a7746f66Stz int returnstat;
3387a7746f66Stz uval_t uval;
3388a7746f66Stz
3389a7746f66Stz if (status < 0)
3390a7746f66Stz return (status);
3391a7746f66Stz
3392a7746f66Stz /*
3393a7746f66Stz * TRANSLATION_NOTE
3394a7746f66Stz * ace->a_type refers to access type of ZFS/NFSv4 ACL entry.
3395a7746f66Stz */
3396a7746f66Stz if ((returnstat = open_tag(context, TAG_ACETYPE)) != 0)
3397a7746f66Stz return (returnstat);
3398a7746f66Stz if (!(context->format & PRF_RAWM)) {
3399a7746f66Stz uval.uvaltype = PRA_STRING;
3400a7746f66Stz switch (ace->a_type) {
3401a7746f66Stz case ACE_ACCESS_ALLOWED_ACE_TYPE:
3402a7746f66Stz uval.string_val = gettext(ALLOW_TXT);
3403a7746f66Stz break;
3404a7746f66Stz case ACE_ACCESS_DENIED_ACE_TYPE:
3405a7746f66Stz uval.string_val = gettext(DENY_TXT);
3406a7746f66Stz break;
3407a7746f66Stz case ACE_SYSTEM_AUDIT_ACE_TYPE:
3408a7746f66Stz uval.string_val = gettext(AUDIT_TXT);
3409a7746f66Stz break;
3410a7746f66Stz case ACE_SYSTEM_ALARM_ACE_TYPE:
3411a7746f66Stz uval.string_val = gettext(ALARM_TXT);
3412a7746f66Stz break;
3413a7746f66Stz default:
3414a7746f66Stz uval.string_val = gettext(UNKNOWN_TXT);
3415a7746f66Stz }
3416a7746f66Stz } else {
3417a7746f66Stz uval.uvaltype = PRA_USHORT;
3418a7746f66Stz uval.uint32_val = ace->a_type;
3419a7746f66Stz }
3420a7746f66Stz if ((returnstat = pa_print(context, &uval, flag)) != 0)
3421a7746f66Stz return (returnstat);
3422a7746f66Stz return (close_tag(context, TAG_ACETYPE));
3423a7746f66Stz }
3424a7746f66Stz
3425a7746f66Stz int
pa_ace(pr_context_t * context,int status,int flag)3426a7746f66Stz pa_ace(pr_context_t *context, int status, int flag)
3427a7746f66Stz {
3428a7746f66Stz int returnstat;
3429a7746f66Stz ace_t ace;
3430a7746f66Stz
3431a7746f66Stz if (status < 0)
3432a7746f66Stz return (status);
3433a7746f66Stz
3434a7746f66Stz if ((returnstat = pr_adr_u_int32(context, &ace.a_who, 1)) != 0)
3435a7746f66Stz return (returnstat);
3436a7746f66Stz if ((returnstat = pr_adr_u_int32(context, &ace.a_access_mask, 1)) != 0)
3437a7746f66Stz return (returnstat);
3438a7746f66Stz if ((returnstat = pr_adr_u_short(context, &ace.a_flags, 1)) != 0)
3439a7746f66Stz return (returnstat);
3440a7746f66Stz if ((returnstat = pr_adr_u_short(context, &ace.a_type, 1)) != 0)
3441a7746f66Stz return (returnstat);
3442a7746f66Stz
3443a7746f66Stz if ((returnstat = pa_ace_flags(context, &ace, returnstat, 0)) != 0)
3444a7746f66Stz return (returnstat);
3445a7746f66Stz /* pa_ace_who can returns 1 if uid/gid is not found */
3446a7746f66Stz if ((returnstat = pa_ace_who(context, &ace, returnstat, 0)) < 0)
3447a7746f66Stz return (returnstat);
3448a7746f66Stz if ((returnstat = pa_ace_access_mask(context, &ace,
3449a7746f66Stz returnstat, 0)) != 0)
3450a7746f66Stz return (returnstat);
3451a7746f66Stz return (pa_ace_type(context, &ace, returnstat, flag));
3452a7746f66Stz }
3453