]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurityd/lib/sec_xdr_reference.c
2 * Copyright (c) 2006,2011,2013-2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 /* $NetBSD: xdr_reference.c,v 1.13 2000/01/22 22:19:18 mycroft Exp $ */
27 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
28 * unrestricted use provided that this legend is included on all tape
29 * media and as a part of the software program in whole or part. Users
30 * may copy or modify Sun RPC without charge, but are not authorized
31 * to license or distribute it to anyone else except as part of a product or
32 * program developed by the user.
34 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
35 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
36 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
38 * Sun RPC is provided with no support and without any obligation on the
39 * part of Sun Microsystems, Inc. to assist in its use, correction,
40 * modification or enhancement.
42 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
43 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
44 * OR ANY PART THEREOF.
46 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
47 * or profits or other special, indirect and consequential damages, even if
48 * Sun has been advised of the possibility of such damages.
50 * Sun Microsystems, Inc.
52 * Mountain View, California 94043
55 #include <sys/cdefs.h>
56 #if defined(LIBC_SCCS) && !defined(lint)
57 static char *sccsid
= "@(#)xdr_reference.c 1.11 87/08/11 SMI";
58 static char *sccsid
= "@(#)xdr_reference.c 2.1 88/07/29 4.0 RPCSRC";
59 static char *rcsid
= "$FreeBSD: src/lib/libc/xdr/xdr_reference.c,v 1.11 2002/03/22 21:53:26 obrien Exp $";
61 #include <sys/cdefs.h>
64 * xdr_reference.c, Generic XDR routines impelmentation.
66 * Copyright (C) 1987, Sun Microsystems, Inc.
68 * These are the "non-trivial" xdr primitives used to serialize and de-serialize
69 * "pointers". See xdr.h for more info on the interface to xdr.
80 * XDR an indirect pointer
81 * xdr_reference is for recursively translating a structure that is
82 * referenced by a pointer inside the structure that is currently being
83 * translated. pp references a pointer to storage. If *pp is null
84 * the necessary storage is allocated.
85 * size is the sizeof the referneced structure.
86 * proc is the routine to handle the referenced structure.
89 sec_xdr_reference(XDR
*xdrs
, uint8_t **pp
, u_int size
, xdrproc_t proc
)
91 uint8_t *loc
= pp
? *pp
: NULL
;
95 // Structure suspiciously large: 1024 is arbitrary upper bound
96 // for struct sizes (non-nested size)
102 bool_t sizeof_alloc
= sec_xdr_arena_size_allocator(xdrs
);
105 switch (xdrs
->x_op
) {
110 if (!sec_mem_alloc(xdrs
, size
, &loc
))
113 memset(obj
, 0, size
);
116 if (!sizeof_alloc
&& pp
!= NULL
)
124 stat
= (*proc
)(xdrs
, loc
, 0);
126 if (xdrs
->x_op
== XDR_FREE
) {
127 sec_mem_free(xdrs
, loc
, size
);
137 sec_xdr_pointer(XDR
*xdrs
, uint8_t **objpp
, u_int obj_size
, xdrproc_t xdr_obj
)
141 more_data
= (objpp
? (*objpp
!= NULL
) : FALSE
);
142 if (! xdr_bool(xdrs
,&more_data
))
145 bool_t sizeof_alloc
= sec_xdr_arena_size_allocator(xdrs
);
148 if ((xdrs
->x_op
== XDR_DECODE
) && !sizeof_alloc
&& objpp
!= NULL
)
152 return (sec_xdr_reference(xdrs
,objpp
,obj_size
,xdr_obj
));
156 * This is almost a straight copy of the standard implementation, except
157 * that all calls made that allocate memory can defer to an alternate
158 * mechanism, with the purpose to allocate from one block of memory on