aboutsummaryrefslogtreecommitdiff
path: root/src/lib/rpc
diff options
context:
space:
mode:
authorKen Raeburn <raeburn@mit.edu>2008-06-25 18:00:39 +0000
committerKen Raeburn <raeburn@mit.edu>2008-06-25 18:00:39 +0000
commit2eba3c5425102cf63d465d7ac57ef982110c8385 (patch)
treefb4683a4710a3cff163b6677fc660ab89c3aa4d6 /src/lib/rpc
parent2b272e104d992ce923ae1156823f9b2446845723 (diff)
downloadkrb5-2eba3c5425102cf63d465d7ac57ef982110c8385.zip
krb5-2eba3c5425102cf63d465d7ac57ef982110c8385.tar.gz
krb5-2eba3c5425102cf63d465d7ac57ef982110c8385.tar.bz2
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
Diffstat (limited to 'src/lib/rpc')
-rw-r--r--src/lib/rpc/Makefile.in3
-rw-r--r--src/lib/rpc/libgssrpc.exports1
-rw-r--r--src/lib/rpc/xdr_sizeof.c163
3 files changed, 167 insertions, 0 deletions
diff --git a/src/lib/rpc/Makefile.in b/src/lib/rpc/Makefile.in
index 286b65d..8eaa7d5 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 1437b96..e6509d9 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 0000000..0d9774f
--- /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 <gssrpc/types.h>
+#include <gssrpc/xdr.h>
+#include <sys/types.h>
+
+/* 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);
+}