Path: blob/main/crypto/krb5/src/lib/rpc/xdr_alloc.c
39536 views
/* lib/rpc/xdr_alloc.c */1/*2* Copyright (c) 2010, Oracle America, Inc.3*4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions are met:8*9* * Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11*12* * Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in14* the documentation and/or other materials provided with the15* distribution.16*17* * Neither the name of the "Oracle America, Inc." nor the names of18* its contributors may be used to endorse or promote products19* derived from this software without specific prior written permission.20*21* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS22* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED23* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A24* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT25* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,26* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED27* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR28* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF29* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING30* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS31* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.32*/33/*34* Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved.35*/3637#include <gssrpc/types.h>38#include <gssrpc/xdr.h>39#include "dyn.h"4041static bool_t xdralloc_putlong(XDR *, long *);42static bool_t xdralloc_putbytes(XDR *, caddr_t, unsigned int);43static unsigned int xdralloc_getpos(XDR *);44static rpc_inline_t * xdralloc_inline(XDR *, int);45static void xdralloc_destroy(XDR *);46static bool_t xdralloc_notsup_getlong(XDR *, long *);47static bool_t xdralloc_notsup_getbytes(XDR *, caddr_t, unsigned int);48static bool_t xdralloc_notsup_setpos(XDR *, unsigned int);49static struct xdr_ops xdralloc_ops = {50xdralloc_notsup_getlong,51xdralloc_putlong,52xdralloc_notsup_getbytes,53xdralloc_putbytes,54xdralloc_getpos,55xdralloc_notsup_setpos,56xdralloc_inline,57xdralloc_destroy,58};5960/*61* The procedure xdralloc_create initializes a stream descriptor for a62* memory buffer.63*/64void xdralloc_create(XDR *xdrs, enum xdr_op op)65{66xdrs->x_op = op;67xdrs->x_ops = &xdralloc_ops;68xdrs->x_private = (caddr_t) DynCreate(sizeof(char), -4);69/* not allowed to fail */70}7172caddr_t xdralloc_getdata(XDR *xdrs)73{74return (caddr_t) DynGet((DynObject) xdrs->x_private, 0);75}7677void xdralloc_release(XDR *xdrs)78{79DynRelease((DynObject) xdrs->x_private);80}8182static void xdralloc_destroy(XDR *xdrs)83{84DynDestroy((DynObject) xdrs->x_private);85}8687static bool_t xdralloc_notsup_getlong(88XDR *xdrs,89long *lp)90{91return FALSE;92}9394static bool_t xdralloc_putlong(95XDR *xdrs,96long *lp)97{98int l = htonl((uint32_t) *lp); /* XXX need bounds checking */99100/* XXX assumes sizeof(int)==4 */101if (DynInsert((DynObject) xdrs->x_private,102DynSize((DynObject) xdrs->x_private), &l,103sizeof(int)) != DYN_OK)104return FALSE;105return (TRUE);106}107108109static bool_t xdralloc_notsup_getbytes(110XDR *xdrs,111caddr_t addr,112unsigned int len)113{114return FALSE;115}116117118static bool_t xdralloc_putbytes(119XDR *xdrs,120caddr_t addr,121unsigned int len)122{123if (DynInsert((DynObject) xdrs->x_private,124DynSize((DynObject) xdrs->x_private),125addr, (int) len) != DYN_OK)126return FALSE;127return TRUE;128}129130static unsigned int xdralloc_getpos(XDR *xdrs)131{132return DynSize((DynObject) xdrs->x_private);133}134135static bool_t xdralloc_notsup_setpos(136XDR *xdrs,137unsigned int lp)138{139return FALSE;140}141142143144static rpc_inline_t *xdralloc_inline(145XDR *xdrs,146int len)147{148return (rpc_inline_t *) 0;149}150151152