2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
12 #include "afs/param.h"
14 #include <afs/param.h>
21 #include "afs/sysincludes.h"
22 #include "afsincludes.h"
24 #else /* defined(UKERNEL) */
25 #if defined(AFS_ALPHA_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
26 #include "afs/sysincludes.h"
27 #include "afsincludes.h"
30 #include "rpc/types.h"
33 #if !defined(AFS_ALPHA_ENV)
35 #define XDR_GETINT32 XDR_GETLONG
38 #define XDR_PUTINT32 XDR_PUTLONG
41 #endif /* defined(UKERNEL) */
49 #define NVALLOC(a) osi_Alloc(a)
50 #define NVFREE(a,b) osi_Free(a,b)
52 #define MAXBS 2048 /* try to avoid horrible allocs */
53 static afs_int32 bslosers = 0;
54 #define NVALLOC(a) malloc(a)
55 #define NVFREE(a,b) free(a)
58 /* these things are defined in R (but not RX's) library. For now, we add them
59 only for the kernel system. Later, when R is expunged, we'll remove the ifdef */
61 #ifndef AFS_USR_DARWIN_ENV
65 #if (defined(AFS_AIX_ENV) && !defined(AUTH_DES)) || (!defined(AFS_SUN_ENV)) && !defined(AFS_SGI_ENV) && !defined(AFS_ALPHA_ENV) && !defined(AFS_SUN5_ENV)
67 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
69 * XDR chars; from user mode xdr package.
71 bool_t xdr_char(register XDR *xdrs, char *sp)
79 return (XDR_PUTINT32(xdrs, &l));
82 if (!XDR_GETINT32(xdrs, &l)) {
93 #endif /* AFS_HPUX110_ENV && AFS_LINUX20_ENV */
95 #endif /* defined(AFS_AIX_ENV) && !defined(AUTH_DES) */
99 * Wrapper for xdr_string that can be called directly from
100 * routines like clnt_call; from user-mode xdr package.
103 #ifndef AFS_HPUX110_ENV
104 bool_t xdr_wrapstring(XDR *xdrs, char **cpp)
106 if (xdr_string(xdrs, cpp, 1024)) {
111 #endif /* AFS_HPUX110_ENV */
112 #endif /* AFS_SUN5_ENV */
117 * XDR a fixed length array. Unlike variable-length arrays,
118 * the storage of fixed length arrays is static and unfreeable.
119 * > basep: base of the array
120 * > size: size of the array
121 * > elemsize: size of each element
122 * > xdr_elem: routine to XDR each element
124 bool_t xdr_vector(register XDR *xdrs, register char *basep,
125 register u_int nelem, register u_int elemsize, register xdrproc_t xdr_elem)
128 register char *elptr;
131 for (i = 0; i < nelem; i++) {
132 if (! (*xdr_elem)(xdrs, elptr, (u_int) (~0))) {
143 bool_t xdr_CBS(XDR *x, struct CBS *abbs)
146 if (x->x_op == XDR_FREE) {
147 NVFREE(abbs->SeqBody,abbs->SeqLen);
151 if (x->x_op == XDR_ENCODE) {
152 xdr_afs_int32(x, &abbs->SeqLen);
153 xdr_opaque(x, abbs->SeqBody, abbs->SeqLen);
157 xdr_afs_int32(x, &len);
158 if (len < 0 || len > MAXBS) {bslosers++; return FALSE;}
159 if (!abbs->SeqBody) abbs->SeqBody = (char *) NVALLOC(len);
161 xdr_opaque(x, abbs->SeqBody, len);
166 bool_t xdr_BBS(XDR *x, struct BBS *abbs)
168 afs_int32 maxLen, len;
169 if (x->x_op == XDR_FREE) {
170 NVFREE(abbs->SeqBody, abbs->MaxSeqLen);
174 if (x->x_op == XDR_ENCODE) {
175 xdr_afs_int32(x, &abbs->MaxSeqLen);
176 xdr_afs_int32(x, &abbs->SeqLen);
177 xdr_opaque(x, abbs->SeqBody, abbs->SeqLen);
181 xdr_afs_int32(x, &maxLen);
182 xdr_afs_int32(x, &len);
183 if (len < 0 || len > MAXBS || len > maxLen) {bslosers++; return FALSE;}
184 if (!abbs->SeqBody) abbs->SeqBody = (char *) NVALLOC(maxLen);
185 abbs->MaxSeqLen = maxLen;
187 xdr_opaque(x, abbs->SeqBody, len);
192 bool_t xdr_AFSAccessList(XDR *x, AFSAccessList *abbs)
194 afs_int32 maxLen, len;
195 if (x->x_op == XDR_FREE) {
196 NVFREE(abbs->SeqBody, abbs->MaxSeqLen);
200 if (x->x_op == XDR_ENCODE) {
201 xdr_afs_int32(x, &abbs->MaxSeqLen);
202 xdr_afs_int32(x, &abbs->SeqLen);
203 xdr_opaque(x, abbs->SeqBody, abbs->SeqLen);
207 xdr_afs_int32(x, &maxLen);
208 xdr_afs_int32(x, &len);
209 if (len < 0 || len > MAXBS || len > maxLen) {bslosers++; return FALSE;}
210 if (!abbs->SeqBody) abbs->SeqBody = (char *) NVALLOC(maxLen);
211 abbs->MaxSeqLen = maxLen;
213 xdr_opaque(x, abbs->SeqBody, len);