Blame sunrpc/rpc_cmsg.c

Packit 6c4009
/*
Packit 6c4009
 * rpc_callmsg.c
Packit 6c4009
 *
Packit 6c4009
 * Copyright (c) 2010, Oracle America, Inc.
Packit 6c4009
 *
Packit 6c4009
 * Redistribution and use in source and binary forms, with or without
Packit 6c4009
 * modification, are permitted provided that the following conditions are
Packit 6c4009
 * met:
Packit 6c4009
 *
Packit 6c4009
 *     * Redistributions of source code must retain the above copyright
Packit 6c4009
 *       notice, this list of conditions and the following disclaimer.
Packit 6c4009
 *     * Redistributions in binary form must reproduce the above
Packit 6c4009
 *       copyright notice, this list of conditions and the following
Packit 6c4009
 *       disclaimer in the documentation and/or other materials
Packit 6c4009
 *       provided with the distribution.
Packit 6c4009
 *     * Neither the name of the "Oracle America, Inc." nor the names of its
Packit 6c4009
 *       contributors may be used to endorse or promote products derived
Packit 6c4009
 *       from this software without specific prior written permission.
Packit 6c4009
 *
Packit 6c4009
 *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit 6c4009
 *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit 6c4009
 *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
Packit 6c4009
 *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
Packit 6c4009
 *   COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
Packit 6c4009
 *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit 6c4009
 *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
Packit 6c4009
 *   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Packit 6c4009
 *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
Packit 6c4009
 *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
Packit 6c4009
 *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit 6c4009
 *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
#include <string.h>
Packit 6c4009
#include <sys/param.h>
Packit 6c4009
#include <rpc/rpc.h>
Packit 6c4009
#include <shlib-compat.h>
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 * XDR a call message
Packit 6c4009
 */
Packit 6c4009
bool_t
Packit 6c4009
xdr_callmsg (XDR *xdrs, struct rpc_msg *cmsg)
Packit 6c4009
{
Packit 6c4009
  int32_t *buf;
Packit 6c4009
  struct opaque_auth *oa;
Packit 6c4009
Packit 6c4009
  if (xdrs->x_op == XDR_ENCODE)
Packit 6c4009
    {
Packit 6c4009
      if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES)
Packit 6c4009
	{
Packit 6c4009
	  return (FALSE);
Packit 6c4009
	}
Packit 6c4009
      if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES)
Packit 6c4009
	{
Packit 6c4009
	  return (FALSE);
Packit 6c4009
	}
Packit 6c4009
      buf = XDR_INLINE (xdrs, 8 * BYTES_PER_XDR_UNIT
Packit 6c4009
			+ RNDUP (cmsg->rm_call.cb_cred.oa_length)
Packit 6c4009
			+ 2 * BYTES_PER_XDR_UNIT
Packit 6c4009
			+ RNDUP (cmsg->rm_call.cb_verf.oa_length));
Packit 6c4009
      if (buf != NULL)
Packit 6c4009
	{
Packit 6c4009
	  (void) IXDR_PUT_LONG (buf, cmsg->rm_xid);
Packit 6c4009
	  (void) IXDR_PUT_ENUM (buf, cmsg->rm_direction);
Packit 6c4009
	  if (cmsg->rm_direction != CALL)
Packit 6c4009
	    return FALSE;
Packit 6c4009
	  (void) IXDR_PUT_LONG (buf, cmsg->rm_call.cb_rpcvers);
Packit 6c4009
	  if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION)
Packit 6c4009
	    return FALSE;
Packit 6c4009
	  (void) IXDR_PUT_LONG (buf, cmsg->rm_call.cb_prog);
Packit 6c4009
	  (void) IXDR_PUT_LONG (buf, cmsg->rm_call.cb_vers);
Packit 6c4009
	  (void) IXDR_PUT_LONG (buf, cmsg->rm_call.cb_proc);
Packit 6c4009
	  oa = &cmsg->rm_call.cb_cred;
Packit 6c4009
	  (void) IXDR_PUT_ENUM (buf, oa->oa_flavor);
Packit 6c4009
	  (void) IXDR_PUT_INT32 (buf, oa->oa_length);
Packit 6c4009
	  if (oa->oa_length)
Packit 6c4009
	    {
Packit 6c4009
	      memcpy ((caddr_t) buf, oa->oa_base, oa->oa_length);
Packit 6c4009
	      buf = (int32_t *) ((char *) buf + RNDUP (oa->oa_length));
Packit 6c4009
	    }
Packit 6c4009
	  oa = &cmsg->rm_call.cb_verf;
Packit 6c4009
	  (void) IXDR_PUT_ENUM (buf, oa->oa_flavor);
Packit 6c4009
	  (void) IXDR_PUT_INT32 (buf, oa->oa_length);
Packit 6c4009
	  if (oa->oa_length)
Packit 6c4009
	    {
Packit 6c4009
	      memcpy ((caddr_t) buf, oa->oa_base, oa->oa_length);
Packit 6c4009
	      /* no real need....
Packit 6c4009
		 buf = (long *) ((char *) buf + RNDUP(oa->oa_length));
Packit 6c4009
	       */
Packit 6c4009
	    }
Packit 6c4009
	  return TRUE;
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
  if (xdrs->x_op == XDR_DECODE)
Packit 6c4009
    {
Packit 6c4009
      buf = XDR_INLINE (xdrs, 8 * BYTES_PER_XDR_UNIT);
Packit 6c4009
      if (buf != NULL)
Packit 6c4009
	{
Packit 6c4009
	  cmsg->rm_xid = IXDR_GET_LONG (buf);
Packit 6c4009
	  cmsg->rm_direction = IXDR_GET_ENUM (buf, enum msg_type);
Packit 6c4009
	  if (cmsg->rm_direction != CALL)
Packit 6c4009
	    {
Packit 6c4009
	      return FALSE;
Packit 6c4009
	    }
Packit 6c4009
	  cmsg->rm_call.cb_rpcvers = IXDR_GET_LONG (buf);
Packit 6c4009
	  if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION)
Packit 6c4009
	    {
Packit 6c4009
	      return FALSE;
Packit 6c4009
	    }
Packit 6c4009
	  cmsg->rm_call.cb_prog = IXDR_GET_LONG (buf);
Packit 6c4009
	  cmsg->rm_call.cb_vers = IXDR_GET_LONG (buf);
Packit 6c4009
	  cmsg->rm_call.cb_proc = IXDR_GET_LONG (buf);
Packit 6c4009
	  oa = &cmsg->rm_call.cb_cred;
Packit 6c4009
	  oa->oa_flavor = IXDR_GET_ENUM (buf, enum_t);
Packit 6c4009
	  oa->oa_length = IXDR_GET_INT32 (buf);
Packit 6c4009
	  if (oa->oa_length)
Packit 6c4009
	    {
Packit 6c4009
	      if (oa->oa_length > MAX_AUTH_BYTES)
Packit 6c4009
		return FALSE;
Packit 6c4009
	      if (oa->oa_base == NULL)
Packit 6c4009
		{
Packit 6c4009
		  oa->oa_base = (caddr_t)
Packit 6c4009
		    mem_alloc (oa->oa_length);
Packit 6c4009
		}
Packit 6c4009
	      buf = XDR_INLINE (xdrs, RNDUP (oa->oa_length));
Packit 6c4009
	      if (buf == NULL)
Packit 6c4009
		{
Packit 6c4009
		  if (xdr_opaque (xdrs, oa->oa_base,
Packit 6c4009
				  oa->oa_length) == FALSE)
Packit 6c4009
		    return FALSE;
Packit 6c4009
		}
Packit 6c4009
	      else
Packit 6c4009
		{
Packit 6c4009
		  memcpy (oa->oa_base, (caddr_t) buf, oa->oa_length);
Packit 6c4009
		  /* no real need....
Packit 6c4009
		     buf = (long *) ((char *) buf
Packit 6c4009
		     + RNDUP(oa->oa_length));
Packit 6c4009
		   */
Packit 6c4009
		}
Packit 6c4009
	    }
Packit 6c4009
	  oa = &cmsg->rm_call.cb_verf;
Packit 6c4009
	  buf = XDR_INLINE (xdrs, 2 * BYTES_PER_XDR_UNIT);
Packit 6c4009
	  if (buf == NULL)
Packit 6c4009
	    {
Packit 6c4009
	      if (xdr_enum (xdrs, &oa->oa_flavor) == FALSE ||
Packit 6c4009
		  xdr_u_int (xdrs, &oa->oa_length) == FALSE)
Packit 6c4009
		{
Packit 6c4009
		  return FALSE;
Packit 6c4009
		}
Packit 6c4009
	    }
Packit 6c4009
	  else
Packit 6c4009
	    {
Packit 6c4009
	      oa->oa_flavor = IXDR_GET_ENUM (buf, enum_t);
Packit 6c4009
	      oa->oa_length = IXDR_GET_INT32 (buf);
Packit 6c4009
	    }
Packit 6c4009
	  if (oa->oa_length)
Packit 6c4009
	    {
Packit 6c4009
	      if (oa->oa_length > MAX_AUTH_BYTES)
Packit 6c4009
		return FALSE;
Packit 6c4009
	      if (oa->oa_base == NULL)
Packit 6c4009
		{
Packit 6c4009
		  oa->oa_base = (caddr_t)
Packit 6c4009
		    mem_alloc (oa->oa_length);
Packit 6c4009
		}
Packit 6c4009
	      buf = XDR_INLINE (xdrs, RNDUP (oa->oa_length));
Packit 6c4009
	      if (buf == NULL)
Packit 6c4009
		{
Packit 6c4009
		  if (xdr_opaque (xdrs, oa->oa_base,
Packit 6c4009
				  oa->oa_length) == FALSE)
Packit 6c4009
		    return FALSE;
Packit 6c4009
		}
Packit 6c4009
	      else
Packit 6c4009
		{
Packit 6c4009
		  memcpy (oa->oa_base, (caddr_t) buf, oa->oa_length);
Packit 6c4009
		  /* no real need...
Packit 6c4009
		     buf = (long *) ((char *) buf
Packit 6c4009
		     + RNDUP(oa->oa_length));
Packit 6c4009
		   */
Packit 6c4009
		}
Packit 6c4009
	    }
Packit 6c4009
	  return TRUE;
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
  if (
Packit 6c4009
       xdr_u_long (xdrs, &(cmsg->rm_xid)) &&
Packit 6c4009
       xdr_enum (xdrs, (enum_t *) & (cmsg->rm_direction)) &&
Packit 6c4009
       (cmsg->rm_direction == CALL) &&
Packit 6c4009
       xdr_u_long (xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
Packit 6c4009
       (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) &&
Packit 6c4009
       xdr_u_long (xdrs, &(cmsg->rm_call.cb_prog)) &&
Packit 6c4009
       xdr_u_long (xdrs, &(cmsg->rm_call.cb_vers)) &&
Packit 6c4009
       xdr_u_long (xdrs, &(cmsg->rm_call.cb_proc)) &&
Packit 6c4009
       xdr_opaque_auth (xdrs, &(cmsg->rm_call.cb_cred)))
Packit 6c4009
    return xdr_opaque_auth (xdrs, &(cmsg->rm_call.cb_verf));
Packit 6c4009
  return FALSE;
Packit 6c4009
}
Packit 6c4009
libc_hidden_nolink_sunrpc (xdr_callmsg, GLIBC_2_0)