4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 #include <sys/types.h>
31 #include <sys/varargs.h>
32 #include <bsm/audit.h>
33 #include <bsm/libbsm.h>
34 #include <bsm/audit_record.h>
40 * pr_adr_char - pull out characters
43 pr_adr_char(pr_context_t
*context
, char *cp
, int count
)
46 adr_t
*adr
= context
->audit_adr
;
47 adrf_t
*adrf
= context
->audit_adrf
;
49 if (context
->data_mode
== FILEMODE
) {
50 err
= adrf_char(adrf
, cp
, count
);
58 /* adrm routines don't return error, so check before calling */
59 if (!pr_input_remaining(context
, (sizeof (char) * count
))) {
64 adrm_char(adr
, cp
, count
);
69 * pr_adr_short - pull out shorts
72 pr_adr_short(pr_context_t
*context
, short *sp
, int count
)
75 adr_t
*adr
= context
->audit_adr
;
76 adrf_t
*adrf
= context
->audit_adrf
;
78 if (context
->data_mode
== FILEMODE
) {
79 err
= adrf_short(adrf
, sp
, count
);
87 /* adrm routines don't return error, so check before calling */
88 if (!pr_input_remaining(context
, (sizeof (short) * count
))) {
93 adrm_short(adr
, sp
, count
);
98 * pr_adr_int32 - pull out int32
101 pr_adr_int32(pr_context_t
*context
, int32_t *lp
, int count
)
104 adr_t
*adr
= context
->audit_adr
;
105 adrf_t
*adrf
= context
->audit_adrf
;
107 if (context
->data_mode
== FILEMODE
) {
108 err
= adrf_int32(adrf
, lp
, count
);
116 /* adrm routines don't return error, so check before calling */
117 if (!pr_input_remaining(context
, (sizeof (int32_t) * count
))) {
122 adrm_int32(adr
, lp
, count
);
127 pr_adr_int64(pr_context_t
*context
, int64_t *lp
, int count
)
130 adr_t
*adr
= context
->audit_adr
;
131 adrf_t
*adrf
= context
->audit_adrf
;
133 if (context
->data_mode
== FILEMODE
) {
134 err
= adrf_int64(adrf
, lp
, count
);
142 /* adrm routines don't return error, so check before calling */
143 if (!pr_input_remaining(context
, (sizeof (int64_t) * count
))) {
148 adrm_int64(adr
, lp
, count
);
153 pr_adr_u_int32(pr_context_t
*context
, uint32_t *cp
, int count
)
155 return (pr_adr_int32(context
, (int32_t *)cp
, count
));
159 pr_adr_u_char(pr_context_t
*context
, uchar_t
*cp
, int count
)
161 return (pr_adr_char(context
, (char *)cp
, count
));
165 pr_adr_u_int64(pr_context_t
*context
, uint64_t *lp
, int count
)
167 return (pr_adr_int64(context
, (int64_t *)lp
, count
));
171 pr_adr_u_short(pr_context_t
*context
, ushort_t
*sp
, int count
)
173 return (pr_adr_short(context
, (short *)sp
, count
));
177 pr_putchar(pr_context_t
*context
, char c
)
179 if (context
->data_mode
== FILEMODE
) {
183 /* Buffer-based output processing otherwise... */
185 /* Need at least room for char + null-byte */
186 if (context
->outbuf_remain_len
< 2) {
192 *(context
->outbuf_p
) = c
;
193 context
->outbuf_p
+= 1;
194 context
->outbuf_remain_len
-= 1;
200 pr_printf(pr_context_t
*context
, const char *fmt
, ...)
207 if (context
->data_mode
== FILEMODE
) {
208 (void) vprintf(fmt
, ap
);
212 /* Buffer-based output processing otherwise... */
214 if (context
->outbuf_remain_len
< 2) {
215 /* no space at all left */
221 /* Attempt to tack on this string */
222 addlen
= vsnprintf(context
->outbuf_p
, context
->outbuf_remain_len
- 1,
230 if (addlen
>= context
->outbuf_remain_len
- 1) {
231 /* not enough space; bail out */
237 * vsnprintf was successful; update pointers and counters
238 * as needed. If no bytes were written, treat it as a no-op
239 * and don't need to update anything.
242 context
->outbuf_remain_len
-= addlen
;
243 context
->outbuf_p
+= addlen
;
251 * pr_input_remaining - Check whether size bytes (or more) are remaining in
253 * returns 1 - there are enough bytes remaining
254 * 0 - not enough bytes left
257 pr_input_remaining(pr_context_t
*context
, size_t size
)
259 adr_t
*adr
= context
->audit_adr
;
261 /* no-op if not doing buf mode */
262 if (context
->data_mode
!= BUFMODE
)
265 if ((adr_count(adr
) + size
) > context
->inbuf_totalsize
)