From: Ken Raeburn Date: Wed, 25 Jun 2008 18:00:39 +0000 (+0000) Subject: Pull in xdr_sizeof from tirpc2.3 (which has the same license as our current rpc code) X-Git-Tag: krb5-1.7-alpha1~640 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=2eba3c5425102cf63d465d7ac57ef982110c8385;p=krb5.git Pull in xdr_sizeof from tirpc2.3 (which has the same license as our current rpc code) git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20468 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/include/gssrpc/rename.h b/src/include/gssrpc/rename.h index b28ae9145..6e472e617 100644 --- a/src/include/gssrpc/rename.h +++ b/src/include/gssrpc/rename.h @@ -289,6 +289,8 @@ #define xdr_wrapstring gssrpc_xdr_wrapstring #define xdr_free gssrpc_xdr_free +#define xdr_sizeof gssrpc_xdr_sizeof + #define xdr_netobj gssrpc_xdr_netobj #define xdr_int32 gssrpc_xdr_int32 #define xdr_u_int32 gssrpc_xdr_u_int32 diff --git a/src/include/gssrpc/xdr.h b/src/include/gssrpc/xdr.h index 943e39e2a..b7c2843a4 100644 --- a/src/include/gssrpc/xdr.h +++ b/src/include/gssrpc/xdr.h @@ -271,6 +271,8 @@ extern bool_t xdr_reference(XDR *, caddr_t *, u_int, xdrproc_t); extern bool_t xdr_pointer(XDR *, char **, u_int, xdrproc_t); extern bool_t xdr_wrapstring(XDR *, char **); +extern unsigned long xdr_sizeof(xdrproc_t, void *); + #define xdr_rpcprog xdr_u_int32 #define xdr_rpcvers xdr_u_int32 #define xdr_rpcprot xdr_u_int32 diff --git a/src/lib/rpc/Makefile.in b/src/lib/rpc/Makefile.in index 286b65d5e..8eaa7d5f8 100644 --- a/src/lib/rpc/Makefile.in +++ b/src/lib/rpc/Makefile.in @@ -69,6 +69,7 @@ SRCS = $(srcdir)/auth_none.c \ $(srcdir)/xdr_rec.c \ $(srcdir)/xdr_reference.c \ $(srcdir)/xdr_stdio.c \ + $(srcdir)/xdr_sizeof.c \ $(srcdir)/xdr_alloc.c OBJS = auth_none.$(OBJEXT) \ @@ -116,6 +117,7 @@ OBJS = auth_none.$(OBJEXT) \ xdr_rec.$(OBJEXT) \ xdr_reference.$(OBJEXT) \ xdr_stdio.$(OBJEXT) \ + xdr_sizeof.$(OBJEXT) \ xdr_alloc.$(OBJEXT) STLIBOBJS = \ @@ -164,6 +166,7 @@ STLIBOBJS = \ xdr_rec.o \ xdr_reference.o \ xdr_stdio.o \ + xdr_sizeof.o \ xdr_alloc.o HDRDIR=$(BUILDTOP)/include/gssrpc diff --git a/src/lib/rpc/libgssrpc.exports b/src/lib/rpc/libgssrpc.exports index 1437b9661..e6509d90c 100644 --- a/src/lib/rpc/libgssrpc.exports +++ b/src/lib/rpc/libgssrpc.exports @@ -118,6 +118,7 @@ gssrpc_xdr_rpc_gss_init_res gssrpc_xdr_rpc_gss_unwrap_data gssrpc_xdr_rpc_gss_wrap_data gssrpc_xdr_short +gssrpc_xdr_sizeof gssrpc_xdr_string gssrpc_xdr_u_char gssrpc_xdr_u_int diff --git a/src/lib/rpc/xdr_sizeof.c b/src/lib/rpc/xdr_sizeof.c new file mode 100644 index 000000000..0d9774f11 --- /dev/null +++ b/src/lib/rpc/xdr_sizeof.c @@ -0,0 +1,163 @@ +/* + * Sun RPC is a product of Sun Microsystems, Inc. and is provided for + * unrestricted use provided that this legend is included on all tape + * media and as a part of the software program in whole or part. Users + * may copy or modify Sun RPC without charge, but are not authorized + * to license or distribute it to anyone else except as part of a product or + * program developed by the user. + * + * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE + * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR + * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. + * + * Sun RPC is provided with no support and without any obligation on the + * part of Sun Microsystems, Inc. to assist in its use, correction, + * modification or enhancement. + * + * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE + * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC + * OR ANY PART THEREOF. + * + * In no event will Sun Microsystems, Inc. be liable for any lost revenue + * or profits or other special, indirect and consequential damages, even if + * Sun has been advised of the possibility of such damages. + * + * Sun Microsystems, Inc. + * 2550 Garcia Avenue + * Mountain View, California 94043 + */ +/* + * xdr_sizeof.c + * + * Copyright 1990 Sun Microsystems, Inc. + * + * General purpose routine to see how much space something will use + * when serialized using XDR. + */ + +#include +#include +#include + +/* ARGSUSED */ +static bool_t +x_putlong(xdrs, longp) + XDR *xdrs; + long *longp; +{ + xdrs->x_handy += BYTES_PER_XDR_UNIT; + return (TRUE); +} + +/* ARGSUSED */ +static bool_t +x_putbytes(xdrs, bp, len) + XDR *xdrs; + char *bp; + int len; +{ + xdrs->x_handy += len; + + return (TRUE); +} + +static u_int +x_getpostn(xdrs) + XDR *xdrs; +{ + return (xdrs->x_handy); +} + +/* ARGSUSED */ +static bool_t +x_setpostn(xdrs, pos) + XDR *xdrs; + u_int pos; +{ + /* This is not allowed */ + return (FALSE); +} + +static long * +x_inline(xdrs, len) + XDR *xdrs; + int len; +{ + if (len == 0) { + return (NULL); + } + if (xdrs->x_op != XDR_ENCODE) { + return (NULL); + } + if (len < (int) xdrs->x_base) { + /* x_private was already allocated */ + xdrs->x_handy += len; + return ((long *) xdrs->x_private); + } else { + /* Free the earlier space and allocate new area */ + if (xdrs->x_private) + free(xdrs->x_private); + if ((xdrs->x_private = (caddr_t) malloc(len)) == NULL) { + xdrs->x_base = 0; + return (NULL); + } + xdrs->x_base = (caddr_t) len; + xdrs->x_handy += len; + return ((long *) xdrs->x_private); + } +} + +static +harmless() +{ + /* Always return FALSE/NULL, as the case may be */ + return (0); +} + +static void +x_destroy(xdrs) + XDR *xdrs; +{ + xdrs->x_handy = 0; + xdrs->x_base = 0; + if (xdrs->x_private) { + free(xdrs->x_private); + xdrs->x_private = NULL; + } + return; +} + +unsigned long +xdr_sizeof(func, data) + xdrproc_t func; + void *data; +{ + XDR x; + struct xdr_ops ops; + bool_t stat; + /* to stop ANSI-C compiler from complaining */ + typedef bool_t (* dummyfunc1)(XDR *, long *); + typedef bool_t (* dummyfunc2)(XDR *, caddr_t, int); + + ops.x_putlong = x_putlong; + ops.x_putbytes = x_putbytes; + ops.x_inline = x_inline; + ops.x_getpostn = x_getpostn; + ops.x_setpostn = x_setpostn; + ops.x_destroy = x_destroy; + + /* the other harmless ones */ + ops.x_getlong = (dummyfunc1) harmless; + ops.x_getbytes = (dummyfunc2) harmless; + + x.x_op = XDR_ENCODE; + x.x_ops = &ops; + x.x_handy = 0; + x.x_private = (caddr_t) NULL; + x.x_base = (caddr_t) 0; + + stat = func(&x, data); + if (x.x_private) + free(x.x_private); + return (stat == TRUE ? (unsigned) x.x_handy: 0); +}