10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*3500Stz204579 * Common Development and Distribution License (the "License").
6*3500Stz204579 * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*3500Stz204579 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
270Sstevel@tonic-gate
280Sstevel@tonic-gate #include <stdio.h>
290Sstevel@tonic-gate #include <sys/types.h>
300Sstevel@tonic-gate #include <bsm/audit.h>
310Sstevel@tonic-gate #include <bsm/libbsm.h>
320Sstevel@tonic-gate #include <bsm/audit_record.h>
330Sstevel@tonic-gate
340Sstevel@tonic-gate
350Sstevel@tonic-gate /*
360Sstevel@tonic-gate * adr_struct.now is used to calculate the record length so
370Sstevel@tonic-gate * end of record will be recognized.
380Sstevel@tonic-gate */
390Sstevel@tonic-gate
400Sstevel@tonic-gate
410Sstevel@tonic-gate void
adrf_start(adrf_t * adrf,adr_t * adr,FILE * fp)420Sstevel@tonic-gate adrf_start(adrf_t *adrf, adr_t *adr, FILE *fp)
430Sstevel@tonic-gate {
440Sstevel@tonic-gate adrf->adrf_fp = fp;
450Sstevel@tonic-gate adrf->adrf_adr = adr;
460Sstevel@tonic-gate adrf->adrf_adr->adr_now = NULL;
470Sstevel@tonic-gate }
480Sstevel@tonic-gate
490Sstevel@tonic-gate /*
500Sstevel@tonic-gate * adrf_char - pull out characters
510Sstevel@tonic-gate */
520Sstevel@tonic-gate int
adrf_char(adrf_t * adrf,char * cp,int count)530Sstevel@tonic-gate adrf_char(adrf_t *adrf, char *cp, int count)
540Sstevel@tonic-gate {
550Sstevel@tonic-gate int c; /* read character in here */
560Sstevel@tonic-gate
57*3500Stz204579 if (count < 0)
58*3500Stz204579 return (-1);
590Sstevel@tonic-gate while (count--) {
600Sstevel@tonic-gate if ((c = fgetc(adrf->adrf_fp)) == EOF)
610Sstevel@tonic-gate return (-1);
620Sstevel@tonic-gate *cp++ = c;
630Sstevel@tonic-gate adrf->adrf_adr->adr_now += sizeof (char);
640Sstevel@tonic-gate }
650Sstevel@tonic-gate return (0);
660Sstevel@tonic-gate }
670Sstevel@tonic-gate
680Sstevel@tonic-gate /*
690Sstevel@tonic-gate * adrf_short - pull out shorts
700Sstevel@tonic-gate */
710Sstevel@tonic-gate int
adrf_short(adrf_t * adrf,short * sp,int count)720Sstevel@tonic-gate adrf_short(adrf_t *adrf, short *sp, int count)
730Sstevel@tonic-gate {
740Sstevel@tonic-gate int c; /* read character in here */
750Sstevel@tonic-gate
76*3500Stz204579 if (count < 0)
77*3500Stz204579 return (-1);
780Sstevel@tonic-gate while (count--) {
790Sstevel@tonic-gate if ((c = fgetc(adrf->adrf_fp)) == EOF)
800Sstevel@tonic-gate return (-1);
810Sstevel@tonic-gate *sp = c << 8;
820Sstevel@tonic-gate if ((c = fgetc(adrf->adrf_fp)) == EOF)
830Sstevel@tonic-gate return (-1);
840Sstevel@tonic-gate *sp++ |= c & 0x00ff;
850Sstevel@tonic-gate adrf->adrf_adr->adr_now += sizeof (short);
860Sstevel@tonic-gate }
870Sstevel@tonic-gate return (0);
880Sstevel@tonic-gate }
890Sstevel@tonic-gate
900Sstevel@tonic-gate /*
910Sstevel@tonic-gate * adrf_int32 - pull out int32
920Sstevel@tonic-gate */
930Sstevel@tonic-gate int adrf_int(adrf_t *adrf, int32_t *lp, int count);
940Sstevel@tonic-gate int adrf_long(adrf_t *adrf, int32_t *lp, int count);
950Sstevel@tonic-gate
960Sstevel@tonic-gate #pragma weak adrf_int = adrf_int32
970Sstevel@tonic-gate #pragma weak adrf_long = adrf_int32
980Sstevel@tonic-gate
990Sstevel@tonic-gate int
adrf_int32(adrf_t * adrf,int32_t * lp,int count)1000Sstevel@tonic-gate adrf_int32(adrf_t *adrf, int32_t *lp, int count)
1010Sstevel@tonic-gate {
1020Sstevel@tonic-gate int i;
1030Sstevel@tonic-gate int c; /* read character in here */
1040Sstevel@tonic-gate
105*3500Stz204579 if (count < 0)
106*3500Stz204579 return (-1);
1070Sstevel@tonic-gate for (; count--; lp++) {
1080Sstevel@tonic-gate *lp = 0;
1090Sstevel@tonic-gate for (i = 0; i < 4; i++) {
1100Sstevel@tonic-gate if ((c = fgetc(adrf->adrf_fp)) == EOF)
1110Sstevel@tonic-gate return (-1);
1120Sstevel@tonic-gate *lp <<= 8;
1130Sstevel@tonic-gate *lp |= c & 0x000000ff;
1140Sstevel@tonic-gate }
1150Sstevel@tonic-gate adrf->adrf_adr->adr_now += sizeof (int32_t);
1160Sstevel@tonic-gate }
1170Sstevel@tonic-gate return (0);
1180Sstevel@tonic-gate }
1190Sstevel@tonic-gate
1200Sstevel@tonic-gate int
adrf_int64(adrf_t * adrf,int64_t * lp,int count)1210Sstevel@tonic-gate adrf_int64(adrf_t *adrf, int64_t *lp, int count)
1220Sstevel@tonic-gate {
1230Sstevel@tonic-gate int i;
1240Sstevel@tonic-gate int c; /* read character in here */
1250Sstevel@tonic-gate
126*3500Stz204579 if (count < 0)
127*3500Stz204579 return (-1);
1280Sstevel@tonic-gate for (; count--; lp++) {
1290Sstevel@tonic-gate *lp = 0;
1300Sstevel@tonic-gate for (i = 0; i < 8; i++) {
1310Sstevel@tonic-gate if ((c = fgetc(adrf->adrf_fp)) == EOF)
1320Sstevel@tonic-gate return (-1);
1330Sstevel@tonic-gate *lp <<= 8;
1340Sstevel@tonic-gate *lp |= c & 0x00000000000000ff;
1350Sstevel@tonic-gate }
1360Sstevel@tonic-gate adrf->adrf_adr->adr_now += sizeof (int64_t);
1370Sstevel@tonic-gate }
1380Sstevel@tonic-gate return (0);
1390Sstevel@tonic-gate }
1400Sstevel@tonic-gate
1410Sstevel@tonic-gate int adrf_u_int(adrf_t *adrf, uint32_t *cp, int count);
1420Sstevel@tonic-gate int adrf_u_long(adrf_t *adrf, uint32_t *cp, int count);
1430Sstevel@tonic-gate
1440Sstevel@tonic-gate #pragma weak adrf_u_int = adrf_u_int32
1450Sstevel@tonic-gate #pragma weak adrf_u_long = adrf_u_int32
1460Sstevel@tonic-gate
1470Sstevel@tonic-gate int
adrf_u_int32(adrf_t * adrf,uint32_t * cp,int count)1480Sstevel@tonic-gate adrf_u_int32(adrf_t *adrf, uint32_t *cp, int count)
1490Sstevel@tonic-gate {
1500Sstevel@tonic-gate return (adrf_int32(adrf, (int32_t *)cp, count));
1510Sstevel@tonic-gate }
1520Sstevel@tonic-gate
1530Sstevel@tonic-gate int
adrf_u_char(adrf_t * adrf,uchar_t * cp,int count)1540Sstevel@tonic-gate adrf_u_char(adrf_t *adrf, uchar_t *cp, int count)
1550Sstevel@tonic-gate {
1560Sstevel@tonic-gate return (adrf_char(adrf, (char *)cp, count));
1570Sstevel@tonic-gate }
1580Sstevel@tonic-gate
1590Sstevel@tonic-gate int
adrf_u_int64(adrf_t * adrf,uint64_t * lp,int count)1600Sstevel@tonic-gate adrf_u_int64(adrf_t *adrf, uint64_t *lp, int count)
1610Sstevel@tonic-gate {
1620Sstevel@tonic-gate return (adrf_int64(adrf, (int64_t *)lp, count));
1630Sstevel@tonic-gate }
1640Sstevel@tonic-gate
1650Sstevel@tonic-gate int
adrf_u_short(adrf_t * adrf,ushort_t * sp,int count)1660Sstevel@tonic-gate adrf_u_short(adrf_t *adrf, ushort_t *sp, int count)
1670Sstevel@tonic-gate {
1680Sstevel@tonic-gate return (adrf_short(adrf, (short *)sp, count));
1690Sstevel@tonic-gate }
1700Sstevel@tonic-gate
1710Sstevel@tonic-gate int
adrf_peek(adrf_t * adrf)1720Sstevel@tonic-gate adrf_peek(adrf_t *adrf)
1730Sstevel@tonic-gate {
1740Sstevel@tonic-gate return (ungetc(fgetc(adrf->adrf_fp), adrf->adrf_fp));
1750Sstevel@tonic-gate }
176