xref: /onnv-gate/usr/src/lib/libbsm/common/adr.c (revision 7753:ebbac916a413)
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
54893Stz204579  * Common Development and Distribution License (the "License").
64893Stz204579  * 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*7753STon.Nguyen@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate 
270Sstevel@tonic-gate /*
280Sstevel@tonic-gate  * Adr memory based encoding
290Sstevel@tonic-gate  */
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #include <sys/types.h>
320Sstevel@tonic-gate #include <bsm/audit.h>
330Sstevel@tonic-gate #include <bsm/libbsm.h>
340Sstevel@tonic-gate #include <bsm/audit_record.h>
350Sstevel@tonic-gate 
360Sstevel@tonic-gate void
adr_start(adr_t * adr,char * p)370Sstevel@tonic-gate adr_start(adr_t *adr, char *p)
380Sstevel@tonic-gate {
390Sstevel@tonic-gate 	adr->adr_stream = p;
400Sstevel@tonic-gate 	adr->adr_now = p;
410Sstevel@tonic-gate }
420Sstevel@tonic-gate 
430Sstevel@tonic-gate int
adr_count(adr_t * adr)440Sstevel@tonic-gate adr_count(adr_t *adr)
450Sstevel@tonic-gate {
460Sstevel@tonic-gate 	return (((intptr_t)adr->adr_now) - ((intptr_t)adr->adr_stream));
470Sstevel@tonic-gate }
480Sstevel@tonic-gate 
490Sstevel@tonic-gate 
500Sstevel@tonic-gate /*
510Sstevel@tonic-gate  * adr_char - pull out characters
520Sstevel@tonic-gate  */
530Sstevel@tonic-gate void
adr_char(adr_t * adr,char * cp,int count)540Sstevel@tonic-gate adr_char(adr_t *adr, char *cp, int count)
550Sstevel@tonic-gate {
560Sstevel@tonic-gate 	while (count-- > 0)
570Sstevel@tonic-gate 		*adr->adr_now++ = *cp++;
580Sstevel@tonic-gate }
590Sstevel@tonic-gate 
600Sstevel@tonic-gate /*
610Sstevel@tonic-gate  * adr_short - pull out shorts
620Sstevel@tonic-gate  */
630Sstevel@tonic-gate void
adr_short(adr_t * adr,short * sp,int count)640Sstevel@tonic-gate adr_short(adr_t *adr, short *sp, int count)
650Sstevel@tonic-gate {
660Sstevel@tonic-gate 
670Sstevel@tonic-gate 	for (; count-- > 0; sp++) {
680Sstevel@tonic-gate 		*adr->adr_now++ = (char)((*sp >> 8) & 0x00ff);
690Sstevel@tonic-gate 		*adr->adr_now++ = (char)(*sp & 0x00ff);
700Sstevel@tonic-gate 	}
710Sstevel@tonic-gate }
720Sstevel@tonic-gate 
730Sstevel@tonic-gate /*
74*7753STon.Nguyen@Sun.COM  * adr_ushort - pull out ushorts
75*7753STon.Nguyen@Sun.COM  */
76*7753STon.Nguyen@Sun.COM void
adr_ushort(adr_t * adr,ushort_t * sp,int count)77*7753STon.Nguyen@Sun.COM adr_ushort(adr_t *adr, ushort_t *sp, int count)
78*7753STon.Nguyen@Sun.COM {
79*7753STon.Nguyen@Sun.COM 
80*7753STon.Nguyen@Sun.COM 	for (; count-- > 0; sp++) {
81*7753STon.Nguyen@Sun.COM 		*adr->adr_now++ = (char)((*sp >> 8) & 0x00ff);
82*7753STon.Nguyen@Sun.COM 		*adr->adr_now++ = (char)(*sp & 0x00ff);
83*7753STon.Nguyen@Sun.COM 	}
84*7753STon.Nguyen@Sun.COM }
85*7753STon.Nguyen@Sun.COM 
86*7753STon.Nguyen@Sun.COM /*
870Sstevel@tonic-gate  * adr_int32 - pull out uint32
880Sstevel@tonic-gate  */
890Sstevel@tonic-gate #pragma weak adr_long = adr_int32
905012Sgww void
915012Sgww adr_long(adr_t *adr, int32_t *lp, int count);
920Sstevel@tonic-gate void
adr_int32(adr_t * adr,int32_t * lp,int count)930Sstevel@tonic-gate adr_int32(adr_t *adr, int32_t *lp, int count)
940Sstevel@tonic-gate {
950Sstevel@tonic-gate 	int i;		/* index for counting */
965012Sgww 	uint32_t l;	/* value for shifting */
970Sstevel@tonic-gate 
980Sstevel@tonic-gate 	for (; count-- > 0; lp++) {
990Sstevel@tonic-gate 		for (i = 0, l = *(uint32_t *)lp; i < 4; i++) {
1000Sstevel@tonic-gate 			*adr->adr_now++ =
1015012Sgww 			    (char)((uint32_t)(l & 0xff000000) >> 24);
1025012Sgww 			l <<= 8;
1035012Sgww 		}
1045012Sgww 	}
1055012Sgww }
1065012Sgww 
1075012Sgww /*
1085012Sgww  * adr_uid
1095012Sgww  */
1105012Sgww 
1115012Sgww void
adr_uid(adr_t * adr,uid_t * up,int count)1125012Sgww adr_uid(adr_t *adr, uid_t *up, int count)
1135012Sgww {
1145012Sgww 	int i;		/* index for counting */
1155012Sgww 	uid_t l;	/* value for shifting */
1165012Sgww 
1175012Sgww 	for (; count-- > 0; up++) {
1185012Sgww 		for (i = 0, l = *(uint32_t *)up; i < 4; i++) {
1195012Sgww 			*adr->adr_now++ =
1205012Sgww 			    (char)((uint32_t)(l & 0xff000000) >> 24);
1210Sstevel@tonic-gate 			l <<= 8;
1220Sstevel@tonic-gate 		}
1230Sstevel@tonic-gate 	}
1240Sstevel@tonic-gate }
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate /*
1270Sstevel@tonic-gate  * adr_int64 - pull out uint64_t
1280Sstevel@tonic-gate  */
1290Sstevel@tonic-gate void
adr_int64(adr_t * adr,int64_t * lp,int count)1300Sstevel@tonic-gate adr_int64(adr_t *adr, int64_t *lp, int count)
1310Sstevel@tonic-gate {
1320Sstevel@tonic-gate 	int i;		/* index for counting */
1330Sstevel@tonic-gate 	uint64_t l;	/* value for shifting */
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate 	for (; count-- > 0; lp++) {
1360Sstevel@tonic-gate 		for (i = 0, l = *(uint64_t *)lp; i < 8; i++) {
1370Sstevel@tonic-gate 			*adr->adr_now++ = (char)
1385012Sgww 			    ((uint64_t)(l & 0xff00000000000000ULL) >> 56);
1390Sstevel@tonic-gate 			l <<= 8;
1400Sstevel@tonic-gate 		}
1410Sstevel@tonic-gate 	}
1420Sstevel@tonic-gate }
143