1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #include <stdio.h>
30*0Sstevel@tonic-gate #include <sys/types.h>
31*0Sstevel@tonic-gate #include <bsm/audit.h>
32*0Sstevel@tonic-gate #include <bsm/libbsm.h>
33*0Sstevel@tonic-gate #include <bsm/audit_record.h>
34*0Sstevel@tonic-gate 
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate /*
37*0Sstevel@tonic-gate  * adr_struct.now is used to calculate the record length so
38*0Sstevel@tonic-gate  * end of record will be recognized.
39*0Sstevel@tonic-gate  */
40*0Sstevel@tonic-gate 
41*0Sstevel@tonic-gate 
42*0Sstevel@tonic-gate void
43*0Sstevel@tonic-gate adrf_start(adrf_t *adrf, adr_t *adr, FILE *fp)
44*0Sstevel@tonic-gate {
45*0Sstevel@tonic-gate 	adrf->adrf_fp = fp;
46*0Sstevel@tonic-gate 	adrf->adrf_adr = adr;
47*0Sstevel@tonic-gate 	adrf->adrf_adr->adr_now = NULL;
48*0Sstevel@tonic-gate }
49*0Sstevel@tonic-gate 
50*0Sstevel@tonic-gate /*
51*0Sstevel@tonic-gate  * adrf_char - pull out characters
52*0Sstevel@tonic-gate  */
53*0Sstevel@tonic-gate int
54*0Sstevel@tonic-gate adrf_char(adrf_t *adrf, char *cp, int count)
55*0Sstevel@tonic-gate {
56*0Sstevel@tonic-gate 	int c;	/* read character in here */
57*0Sstevel@tonic-gate 
58*0Sstevel@tonic-gate 	while (count--) {
59*0Sstevel@tonic-gate 		if ((c = fgetc(adrf->adrf_fp)) == EOF)
60*0Sstevel@tonic-gate 			return (-1);
61*0Sstevel@tonic-gate 		*cp++ = c;
62*0Sstevel@tonic-gate 		adrf->adrf_adr->adr_now += sizeof (char);
63*0Sstevel@tonic-gate 	}
64*0Sstevel@tonic-gate 	return (0);
65*0Sstevel@tonic-gate }
66*0Sstevel@tonic-gate 
67*0Sstevel@tonic-gate /*
68*0Sstevel@tonic-gate  * adrf_short - pull out shorts
69*0Sstevel@tonic-gate  */
70*0Sstevel@tonic-gate int
71*0Sstevel@tonic-gate adrf_short(adrf_t *adrf, short *sp, int count)
72*0Sstevel@tonic-gate {
73*0Sstevel@tonic-gate 	int c;	/* read character in here */
74*0Sstevel@tonic-gate 
75*0Sstevel@tonic-gate 	while (count--) {
76*0Sstevel@tonic-gate 		if ((c = fgetc(adrf->adrf_fp)) == EOF)
77*0Sstevel@tonic-gate 			return (-1);
78*0Sstevel@tonic-gate 		*sp = c << 8;
79*0Sstevel@tonic-gate 		if ((c = fgetc(adrf->adrf_fp)) == EOF)
80*0Sstevel@tonic-gate 			return (-1);
81*0Sstevel@tonic-gate 		*sp++ |= c & 0x00ff;
82*0Sstevel@tonic-gate 		adrf->adrf_adr->adr_now += sizeof (short);
83*0Sstevel@tonic-gate 	}
84*0Sstevel@tonic-gate 	return (0);
85*0Sstevel@tonic-gate }
86*0Sstevel@tonic-gate 
87*0Sstevel@tonic-gate /*
88*0Sstevel@tonic-gate  * adrf_int32 - pull out int32
89*0Sstevel@tonic-gate  */
90*0Sstevel@tonic-gate int adrf_int(adrf_t *adrf, int32_t *lp, int count);
91*0Sstevel@tonic-gate int adrf_long(adrf_t *adrf, int32_t *lp, int count);
92*0Sstevel@tonic-gate 
93*0Sstevel@tonic-gate #pragma weak adrf_int = adrf_int32
94*0Sstevel@tonic-gate #pragma weak adrf_long = adrf_int32
95*0Sstevel@tonic-gate 
96*0Sstevel@tonic-gate int
97*0Sstevel@tonic-gate adrf_int32(adrf_t *adrf, int32_t *lp, int count)
98*0Sstevel@tonic-gate {
99*0Sstevel@tonic-gate 	int i;
100*0Sstevel@tonic-gate 	int c;	/* read character in here */
101*0Sstevel@tonic-gate 
102*0Sstevel@tonic-gate 	for (; count--; lp++) {
103*0Sstevel@tonic-gate 		*lp = 0;
104*0Sstevel@tonic-gate 		for (i = 0; i < 4; i++) {
105*0Sstevel@tonic-gate 			if ((c = fgetc(adrf->adrf_fp)) == EOF)
106*0Sstevel@tonic-gate 				return (-1);
107*0Sstevel@tonic-gate 			*lp <<= 8;
108*0Sstevel@tonic-gate 			*lp |= c & 0x000000ff;
109*0Sstevel@tonic-gate 		}
110*0Sstevel@tonic-gate 		adrf->adrf_adr->adr_now += sizeof (int32_t);
111*0Sstevel@tonic-gate 	}
112*0Sstevel@tonic-gate 	return (0);
113*0Sstevel@tonic-gate }
114*0Sstevel@tonic-gate 
115*0Sstevel@tonic-gate int
116*0Sstevel@tonic-gate adrf_int64(adrf_t *adrf, int64_t *lp, int count)
117*0Sstevel@tonic-gate {
118*0Sstevel@tonic-gate 	int i;
119*0Sstevel@tonic-gate 	int c;	/* read character in here */
120*0Sstevel@tonic-gate 
121*0Sstevel@tonic-gate 	for (; count--; lp++) {
122*0Sstevel@tonic-gate 		*lp = 0;
123*0Sstevel@tonic-gate 		for (i = 0; i < 8; i++) {
124*0Sstevel@tonic-gate 			if ((c = fgetc(adrf->adrf_fp)) == EOF)
125*0Sstevel@tonic-gate 				return (-1);
126*0Sstevel@tonic-gate 			*lp <<= 8;
127*0Sstevel@tonic-gate 			*lp |= c & 0x00000000000000ff;
128*0Sstevel@tonic-gate 		}
129*0Sstevel@tonic-gate 		adrf->adrf_adr->adr_now += sizeof (int64_t);
130*0Sstevel@tonic-gate 	}
131*0Sstevel@tonic-gate 	return (0);
132*0Sstevel@tonic-gate }
133*0Sstevel@tonic-gate 
134*0Sstevel@tonic-gate int adrf_u_int(adrf_t *adrf, uint32_t *cp, int count);
135*0Sstevel@tonic-gate int adrf_u_long(adrf_t *adrf, uint32_t *cp, int count);
136*0Sstevel@tonic-gate 
137*0Sstevel@tonic-gate #pragma weak adrf_u_int = adrf_u_int32
138*0Sstevel@tonic-gate #pragma weak adrf_u_long = adrf_u_int32
139*0Sstevel@tonic-gate 
140*0Sstevel@tonic-gate int
141*0Sstevel@tonic-gate adrf_u_int32(adrf_t *adrf, uint32_t *cp, int count)
142*0Sstevel@tonic-gate {
143*0Sstevel@tonic-gate 	return (adrf_int32(adrf, (int32_t *)cp, count));
144*0Sstevel@tonic-gate }
145*0Sstevel@tonic-gate 
146*0Sstevel@tonic-gate int
147*0Sstevel@tonic-gate adrf_u_char(adrf_t *adrf, uchar_t *cp, int count)
148*0Sstevel@tonic-gate {
149*0Sstevel@tonic-gate 	return (adrf_char(adrf, (char *)cp, count));
150*0Sstevel@tonic-gate }
151*0Sstevel@tonic-gate 
152*0Sstevel@tonic-gate int
153*0Sstevel@tonic-gate adrf_u_int64(adrf_t *adrf, uint64_t *lp, int count)
154*0Sstevel@tonic-gate {
155*0Sstevel@tonic-gate 	return (adrf_int64(adrf, (int64_t *)lp, count));
156*0Sstevel@tonic-gate }
157*0Sstevel@tonic-gate 
158*0Sstevel@tonic-gate int
159*0Sstevel@tonic-gate adrf_u_short(adrf_t *adrf, ushort_t *sp, int count)
160*0Sstevel@tonic-gate {
161*0Sstevel@tonic-gate 	return (adrf_short(adrf, (short *)sp, count));
162*0Sstevel@tonic-gate }
163*0Sstevel@tonic-gate 
164*0Sstevel@tonic-gate int
165*0Sstevel@tonic-gate adrf_peek(adrf_t *adrf)
166*0Sstevel@tonic-gate {
167*0Sstevel@tonic-gate 	return (ungetc(fgetc(adrf->adrf_fp), adrf->adrf_fp));
168*0Sstevel@tonic-gate }
169