xref: /titanic_44/usr/src/lib/krb5/kadm5/srv/xdr_alloc.c (revision 71269a2275bf5a143dad6461eee2710a344e7261)
1 
2 /*
3  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
4  *
5  *	Openvision retains the copyright to derivative works of
6  *	this source code.  Do *NOT* create a derivative of this
7  *	source code before consulting with your legal department.
8  *	Do *NOT* integrate *ANY* of this source code into another
9  *	product before consulting with your legal department.
10  *
11  *	For further information, read the top-level Openvision
12  *	copyright which is contained in the top-level MIT Kerberos
13  *	copyright.
14  *
15  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
16  *
17  */
18 
19 
20 /* @(#)xdr_mem.c	2.1 88/07/29 4.0 RPCSRC */
21 /*
22  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
23  * unrestricted use provided that this legend is included on all tape
24  * media and as a part of the software program in whole or part.  Users
25  * may copy or modify Sun RPC without charge, but are not authorized
26  * to license or distribute it to anyone else except as part of a product or
27  * program developed by the user.
28  *
29  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
30  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
31  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
32  *
33  * Sun RPC is provided with no support and without any obligation on the
34  * part of Sun Microsystems, Inc. to assist in its use, correction,
35  * modification or enhancement.
36  *
37  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
38  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
39  * OR ANY PART THEREOF.
40  *
41  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
42  * or profits or other special, indirect and consequential damages, even if
43  * Sun has been advised of the possibility of such damages.
44  *
45  * Sun Microsystems, Inc.
46  * 2550 Garcia Avenue
47  * Mountain View, California  94043
48  */
49 #if !defined(lint) && defined(SCCSIDS)
50 static char sccsid[] = "@(#)xdr_mem.c 1.19 87/08/11 Copyr 1984 Sun Micro";
51 #endif
52 
53 /*
54  * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved.
55  *
56  */
57 
58 #include "admin.h"
59 #include <rpc/types.h>
60 #include <rpc/xdr.h>
61 #include <dyn/dyn.h>
62 
63 /* Solaris Kerberos - 116 resync */
64 static bool_t	xdralloc_putlong();
65 static bool_t	xdralloc_putbytes();
66 static unsigned int	xdralloc_getpos();
67 static rpc_inline_t *	xdralloc_inline();
68 static void	xdralloc_destroy();
69 static bool_t	xdralloc_notsup_getlong();
70 static bool_t	xdralloc_notsup_getbytes();
71 static bool_t	xdralloc_notsup_setpos();
72 static struct	xdr_ops xdralloc_ops = {
73      xdralloc_notsup_getlong,
74      xdralloc_putlong,
75      xdralloc_notsup_getbytes,
76      xdralloc_putbytes,
77      xdralloc_getpos,
78      xdralloc_notsup_setpos,
79      xdralloc_inline,
80      xdralloc_destroy,
81 };
82 
83 /*
84  * The procedure xdralloc_create initializes a stream descriptor for a
85  * memory buffer.
86  */
87 void xdralloc_create(XDR *xdrs, enum xdr_op op)
88 {
89      xdrs->x_op = op;
90      xdrs->x_ops = &xdralloc_ops;
91      xdrs->x_private = (caddr_t) DynCreate(sizeof(char), -4);
92      /* not allowed to fail */
93 }
94 
95 caddr_t xdralloc_getdata(XDR *xdrs)
96 {
97      return (caddr_t) DynGet((DynObject) xdrs->x_private, 0);
98 }
99 
100 void xdralloc_release(XDR *xdrs)
101 {
102      DynRelease((DynObject) xdrs->x_private);
103 }
104 
105 static void xdralloc_destroy(XDR *xdrs)
106 {
107      DynDestroy((DynObject) xdrs->x_private);
108 }
109 
110 static bool_t xdralloc_notsup_getlong(
111      register XDR *xdrs,
112      long *lp)
113 {
114      return FALSE;
115 }
116 
117 static bool_t xdralloc_putlong(
118      register XDR *xdrs,
119      long *lp)
120 {
121      int l = htonl((uint32_t) *lp); /* XXX need bounds checking */
122 
123      /* XXX assumes sizeof(int)==4 */
124      if (DynInsert((DynObject) xdrs->x_private,
125 		   DynSize((DynObject) xdrs->x_private), &l,
126 		   sizeof(int)) != DYN_OK)
127 	  return FALSE;
128      return (TRUE);
129 }
130 
131 
132 static bool_t xdralloc_notsup_getbytes(
133      register XDR *xdrs,
134      caddr_t addr,
135      register unsigned int len)
136 {
137      return FALSE;
138 }
139 
140 
141 static bool_t xdralloc_putbytes(
142      register XDR *xdrs,
143      caddr_t addr,
144      register unsigned int len)
145 {
146      if (DynInsert((DynObject) xdrs->x_private,
147 		   DynSize((DynObject) xdrs->x_private),
148 		   addr, (int) len) != DYN_OK)
149 	  return FALSE;
150      return TRUE;
151 }
152 
153 static unsigned int xdralloc_getpos(XDR *xdrs)
154 {
155      return DynSize((DynObject) xdrs->x_private);
156 }
157 
158 static bool_t xdralloc_notsup_setpos(
159      register XDR *xdrs,
160      unsigned int lp)
161 {
162      return FALSE;
163 }
164 
165 
166 
167 static rpc_inline_t *xdralloc_inline(
168      register XDR *xdrs,
169      int len)
170 {
171      return (rpc_inline_t *) 0;
172 }
173