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) */
48 #define MAXBS 2048 /* try to avoid horrible allocs */
49 static afs_int32 bslosers = 0;
52 #define NVALLOC(a) osi_Alloc(a)
53 #define NVFREE(a,b) osi_Free(a,b)
55 #define NVALLOC(a) malloc(a)
56 #define NVFREE(a,b) free(a)
59 /* these things are defined in R (but not RX's) library. For now, we add them
60 only for the kernel system. Later, when R is expunged, we'll remove the ifdef */
62 #ifndef AFS_USR_DARWIN_ENV
66 #if (defined(AFS_AIX_ENV) && !defined(AUTH_DES)) || (!defined(AFS_SUN_ENV)) && !defined(AFS_SGI_ENV) && !defined(AFS_ALPHA_ENV) && !defined(AFS_SUN5_ENV)
68 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
70 * XDR chars; from user mode xdr package.
72 bool_t xdr_char(register XDR *xdrs, char *sp)
80 return (XDR_PUTINT32(xdrs, &l));
83 if (!XDR_GETINT32(xdrs, &l)) {
94 #endif /* AFS_HPUX110_ENV && AFS_LINUX20_ENV */
96 #endif /* defined(AFS_AIX_ENV) && !defined(AUTH_DES) */
100 * Wrapper for xdr_string that can be called directly from
101 * routines like clnt_call; from user-mode xdr package.
104 #ifndef AFS_HPUX110_ENV
105 bool_t xdr_wrapstring(XDR *xdrs, char **cpp)
107 if (xdr_string(xdrs, cpp, 1024)) {
112 #endif /* AFS_HPUX110_ENV */
113 #endif /* AFS_SUN5_ENV */
118 * XDR a fixed length array. Unlike variable-length arrays,
119 * the storage of fixed length arrays is static and unfreeable.
120 * > basep: base of the array
121 * > size: size of the array
122 * > elemsize: size of each element
123 * > xdr_elem: routine to XDR each element
125 bool_t xdr_vector(register XDR *xdrs, register char *basep,
126 register u_int nelem, register u_int elemsize, register xdrproc_t xdr_elem)
129 register char *elptr;
132 for (i = 0; i < nelem; i++) {
133 if (! (*xdr_elem)(xdrs, elptr, (u_int) (~0))) {
144 bool_t xdr_CBS(XDR *x, struct CBS *abbs)
147 if (x->x_op == XDR_FREE) {
148 NVFREE(abbs->SeqBody,abbs->SeqLen);
152 if (x->x_op == XDR_ENCODE) {
153 xdr_afs_int32(x, &abbs->SeqLen);
154 xdr_opaque(x, abbs->SeqBody, abbs->SeqLen);
158 xdr_afs_int32(x, &len);
159 if (len < 0 || len > MAXBS) {bslosers++; return FALSE;}
160 if (!abbs->SeqBody) abbs->SeqBody = (char *) NVALLOC(len);
162 xdr_opaque(x, abbs->SeqBody, len);
167 bool_t xdr_BBS(XDR *x, struct BBS *abbs)
169 afs_int32 maxLen, len;
170 if (x->x_op == XDR_FREE) {
171 NVFREE(abbs->SeqBody, abbs->MaxSeqLen);
175 if (x->x_op == XDR_ENCODE) {
176 xdr_afs_int32(x, &abbs->MaxSeqLen);
177 xdr_afs_int32(x, &abbs->SeqLen);
178 xdr_opaque(x, abbs->SeqBody, abbs->SeqLen);
182 xdr_afs_int32(x, &maxLen);
183 xdr_afs_int32(x, &len);
184 if (len < 0 || len > MAXBS || len > maxLen) {bslosers++; return FALSE;}
185 if (!abbs->SeqBody) abbs->SeqBody = (char *) NVALLOC(maxLen);
186 abbs->MaxSeqLen = maxLen;
188 xdr_opaque(x, abbs->SeqBody, len);
193 bool_t xdr_AFSAccessList(XDR *x, AFSAccessList *abbs)
195 afs_int32 maxLen, len;
196 if (x->x_op == XDR_FREE) {
197 NVFREE(abbs->SeqBody, abbs->MaxSeqLen);
201 if (x->x_op == XDR_ENCODE) {
202 xdr_afs_int32(x, &abbs->MaxSeqLen);
203 xdr_afs_int32(x, &abbs->SeqLen);
204 xdr_opaque(x, abbs->SeqBody, abbs->SeqLen);
208 xdr_afs_int32(x, &maxLen);
209 xdr_afs_int32(x, &len);
210 if (len < 0 || len > MAXBS || len > maxLen) {bslosers++; return FALSE;}
211 if (!abbs->SeqBody) abbs->SeqBody = (char *) NVALLOC(maxLen);
212 abbs->MaxSeqLen = maxLen;
214 xdr_opaque(x, abbs->SeqBody, len);