xref: /onnv-gate/usr/src/lib/libbsm/common/adrm.c (revision 5344:2d3435ff5f3d)
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
53500Stz204579  * Common Development and Distribution License (the "License").
63500Stz204579  * 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 /*
223500Stz204579  * 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 /*
290Sstevel@tonic-gate  * Adr memory based translations
300Sstevel@tonic-gate  */
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <stdio.h>
330Sstevel@tonic-gate #include <sys/types.h>
340Sstevel@tonic-gate #include <bsm/audit.h>
350Sstevel@tonic-gate #include <bsm/audit_record.h>
360Sstevel@tonic-gate 
370Sstevel@tonic-gate void
adrm_start(adr_t * adr,char * p)380Sstevel@tonic-gate adrm_start(adr_t *adr, char *p)
390Sstevel@tonic-gate {
400Sstevel@tonic-gate 	adr->adr_stream = p;
410Sstevel@tonic-gate 	adr->adr_now = p;
420Sstevel@tonic-gate }
430Sstevel@tonic-gate 
440Sstevel@tonic-gate /*
450Sstevel@tonic-gate  * adrm_char - pull out characters
460Sstevel@tonic-gate  */
470Sstevel@tonic-gate void
adrm_char(adr_t * adr,char * cp,int count)480Sstevel@tonic-gate adrm_char(adr_t *adr, char *cp, int count)
490Sstevel@tonic-gate {
503500Stz204579 	while (count-- > 0)
510Sstevel@tonic-gate 		*cp++ = *adr->adr_now++;
520Sstevel@tonic-gate }
530Sstevel@tonic-gate 
540Sstevel@tonic-gate /*
550Sstevel@tonic-gate  * adrm_short - pull out shorts
560Sstevel@tonic-gate  */
570Sstevel@tonic-gate void
adrm_short(adr_t * adr,short * sp,int count)580Sstevel@tonic-gate adrm_short(adr_t *adr, short *sp, int count)
590Sstevel@tonic-gate {
603500Stz204579 	while (count-- > 0) {
610Sstevel@tonic-gate 		*sp = *adr->adr_now++ << 8;
620Sstevel@tonic-gate 		*sp++ += ((short)*adr->adr_now++) & 0x00ff;
630Sstevel@tonic-gate 	}
640Sstevel@tonic-gate }
650Sstevel@tonic-gate 
660Sstevel@tonic-gate /*
670Sstevel@tonic-gate  * adrm_int32 - pull out int
680Sstevel@tonic-gate  */
690Sstevel@tonic-gate void adrm_int(adr_t *adr, int32_t *lp, int count);
700Sstevel@tonic-gate void adrm_long(adr_t *adr, int32_t *lp, int count);
710Sstevel@tonic-gate #pragma weak adrm_int = adrm_int32
720Sstevel@tonic-gate #pragma weak adrm_long = adrm_int32
730Sstevel@tonic-gate 
740Sstevel@tonic-gate void
adrm_int32(adr_t * adr,int32_t * lp,int count)750Sstevel@tonic-gate adrm_int32(adr_t *adr, int32_t *lp, int count)
760Sstevel@tonic-gate {
770Sstevel@tonic-gate 	int i;
780Sstevel@tonic-gate 
793500Stz204579 	for (; count-- > 0; lp++) {
800Sstevel@tonic-gate 		*lp = 0;
810Sstevel@tonic-gate 		for (i = 0; i < 4; i++) {
820Sstevel@tonic-gate 			*lp <<= 8;
830Sstevel@tonic-gate 			*lp += ((int32_t)*adr->adr_now++) & 0x000000ff;
840Sstevel@tonic-gate 		}
850Sstevel@tonic-gate 	}
860Sstevel@tonic-gate }
870Sstevel@tonic-gate 
880Sstevel@tonic-gate void
adrm_uid(adr_t * adr,uid_t * up,int count)89*5344Stz204579 adrm_uid(adr_t *adr, uid_t *up, int count)
90*5344Stz204579 {
91*5344Stz204579 	int i;
92*5344Stz204579 
93*5344Stz204579 	for (; count-- > 0; up++) {
94*5344Stz204579 		*up = 0;
95*5344Stz204579 		for (i = 0; i < 4; i++) {
96*5344Stz204579 			*up <<= 8;
97*5344Stz204579 			*up += ((uid_t)*adr->adr_now++) & 0x000000ff;
98*5344Stz204579 		}
99*5344Stz204579 	}
100*5344Stz204579 }
101*5344Stz204579 
102*5344Stz204579 void
adrm_int64(adr_t * adr,int64_t * lp,int count)1030Sstevel@tonic-gate adrm_int64(adr_t *adr, int64_t *lp, int count)
1040Sstevel@tonic-gate {
1050Sstevel@tonic-gate 	int i;
1060Sstevel@tonic-gate 
1073500Stz204579 	for (; count-- > 0; lp++) {
1080Sstevel@tonic-gate 		*lp = 0;
1090Sstevel@tonic-gate 		for (i = 0; i < 8; i++) {
1100Sstevel@tonic-gate 			*lp <<= 8;
1110Sstevel@tonic-gate 			*lp += ((int64_t)*adr->adr_now++) & 0x00000000000000ff;
1120Sstevel@tonic-gate 		}
1130Sstevel@tonic-gate 	}
1140Sstevel@tonic-gate }
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate void adrm_u_int(adr_t *adr, uint32_t *cp, int count);
1170Sstevel@tonic-gate void adrm_u_long(adr_t *adr, uint32_t *cp, int count);
1180Sstevel@tonic-gate #pragma weak adrm_u_int = adrm_u_int32
1190Sstevel@tonic-gate #pragma weak adrm_u_long = adrm_u_int32
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate void
adrm_u_int32(adr_t * adr,uint32_t * cp,int count)1220Sstevel@tonic-gate adrm_u_int32(adr_t *adr, uint32_t *cp, int count)
1230Sstevel@tonic-gate {
1240Sstevel@tonic-gate 	adrm_int32(adr, (int32_t *)cp, count);
1250Sstevel@tonic-gate }
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate void
adrm_u_char(adr_t * adr,uchar_t * cp,int count)1280Sstevel@tonic-gate adrm_u_char(adr_t *adr, uchar_t *cp, int count)
1290Sstevel@tonic-gate {
1300Sstevel@tonic-gate 	adrm_char(adr, (char *)cp, count);
1310Sstevel@tonic-gate }
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate void
adrm_u_int64(adr_t * adr,uint64_t * lp,int count)1340Sstevel@tonic-gate adrm_u_int64(adr_t *adr, uint64_t *lp, int count)
1350Sstevel@tonic-gate {
1360Sstevel@tonic-gate 	adrm_int64(adr, (int64_t *)lp, count);
1370Sstevel@tonic-gate }
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate void
adrm_u_short(adr_t * adr,ushort_t * sp,int count)1400Sstevel@tonic-gate adrm_u_short(adr_t *adr, ushort_t *sp, int count)
1410Sstevel@tonic-gate {
1420Sstevel@tonic-gate 	adrm_short(adr, (short *)sp, count);
1430Sstevel@tonic-gate }
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate /*
1460Sstevel@tonic-gate  * adrm_putint32 - pack in int32
1470Sstevel@tonic-gate  */
1480Sstevel@tonic-gate #pragma weak adrm_putint = adrm_putint32
1490Sstevel@tonic-gate #pragma weak adrm_putlong = adrm_putint32
1500Sstevel@tonic-gate void
adrm_putint32(adr_t * adr,int32_t * lp,int count)1510Sstevel@tonic-gate adrm_putint32(adr_t *adr, int32_t *lp, int count)
1520Sstevel@tonic-gate {
1530Sstevel@tonic-gate 	int i;		/* index for counting */
1540Sstevel@tonic-gate 	int32_t l;	/* value for shifting */
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate 	for (; count-- > 0; lp++) {
1570Sstevel@tonic-gate 		for (i = 0, l = *lp; i < 4; i++) {
1580Sstevel@tonic-gate 			*adr->adr_now++ = (char)((l & (int32_t)0xff000000) >>
159*5344Stz204579 			    (int)24);
1600Sstevel@tonic-gate 			l <<= (int)8;
1610Sstevel@tonic-gate 		}
1620Sstevel@tonic-gate 	}
1630Sstevel@tonic-gate }
164