Back to index

glibc  2.9
rpc_cmsg.c
Go to the documentation of this file.
00001 /* @(#)rpc_callmsg.c 2.1 88/07/29 4.0 RPCSRC */
00002 /*
00003  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
00004  * unrestricted use provided that this legend is included on all tape
00005  * media and as a part of the software program in whole or part.  Users
00006  * may copy or modify Sun RPC without charge, but are not authorized
00007  * to license or distribute it to anyone else except as part of a product or
00008  * program developed by the user.
00009  *
00010  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
00011  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
00012  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
00013  *
00014  * Sun RPC is provided with no support and without any obligation on the
00015  * part of Sun Microsystems, Inc. to assist in its use, correction,
00016  * modification or enhancement.
00017  *
00018  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
00019  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
00020  * OR ANY PART THEREOF.
00021  *
00022  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
00023  * or profits or other special, indirect and consequential damages, even if
00024  * Sun has been advised of the possibility of such damages.
00025  *
00026  * Sun Microsystems, Inc.
00027  * 2550 Garcia Avenue
00028  * Mountain View, California  94043
00029  */
00030 #if !defined(lint) && defined(SCCSIDS)
00031 static char sccsid[] = "@(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro";
00032 #endif
00033 
00034 /*
00035  * rpc_callmsg.c
00036  *
00037  * Copyright (C) 1984, Sun Microsystems, Inc.
00038  *
00039  */
00040 
00041 #include <string.h>
00042 #include <sys/param.h>
00043 #include <rpc/rpc.h>
00044 
00045 /*
00046  * XDR a call message
00047  */
00048 bool_t
00049 xdr_callmsg (XDR *xdrs, struct rpc_msg *cmsg)
00050 {
00051   int32_t *buf;
00052   struct opaque_auth *oa;
00053 
00054   if (xdrs->x_op == XDR_ENCODE)
00055     {
00056       if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES)
00057        {
00058          return (FALSE);
00059        }
00060       if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES)
00061        {
00062          return (FALSE);
00063        }
00064       buf = XDR_INLINE (xdrs, 8 * BYTES_PER_XDR_UNIT
00065                      + RNDUP (cmsg->rm_call.cb_cred.oa_length)
00066                      + 2 * BYTES_PER_XDR_UNIT
00067                      + RNDUP (cmsg->rm_call.cb_verf.oa_length));
00068       if (buf != NULL)
00069        {
00070          (void) IXDR_PUT_LONG (buf, cmsg->rm_xid);
00071          (void) IXDR_PUT_ENUM (buf, cmsg->rm_direction);
00072          if (cmsg->rm_direction != CALL)
00073            return FALSE;
00074          (void) IXDR_PUT_LONG (buf, cmsg->rm_call.cb_rpcvers);
00075          if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION)
00076            return FALSE;
00077          (void) IXDR_PUT_LONG (buf, cmsg->rm_call.cb_prog);
00078          (void) IXDR_PUT_LONG (buf, cmsg->rm_call.cb_vers);
00079          (void) IXDR_PUT_LONG (buf, cmsg->rm_call.cb_proc);
00080          oa = &cmsg->rm_call.cb_cred;
00081          (void) IXDR_PUT_ENUM (buf, oa->oa_flavor);
00082          (void) IXDR_PUT_INT32 (buf, oa->oa_length);
00083          if (oa->oa_length)
00084            {
00085              memcpy ((caddr_t) buf, oa->oa_base, oa->oa_length);
00086              buf = (int32_t *) ((char *) buf + RNDUP (oa->oa_length));
00087            }
00088          oa = &cmsg->rm_call.cb_verf;
00089          (void) IXDR_PUT_ENUM (buf, oa->oa_flavor);
00090          (void) IXDR_PUT_INT32 (buf, oa->oa_length);
00091          if (oa->oa_length)
00092            {
00093              memcpy ((caddr_t) buf, oa->oa_base, oa->oa_length);
00094              /* no real need....
00095                 buf = (long *) ((char *) buf + RNDUP(oa->oa_length));
00096               */
00097            }
00098          return TRUE;
00099        }
00100     }
00101   if (xdrs->x_op == XDR_DECODE)
00102     {
00103       buf = XDR_INLINE (xdrs, 8 * BYTES_PER_XDR_UNIT);
00104       if (buf != NULL)
00105        {
00106          cmsg->rm_xid = IXDR_GET_LONG (buf);
00107          cmsg->rm_direction = IXDR_GET_ENUM (buf, enum msg_type);
00108          if (cmsg->rm_direction != CALL)
00109            {
00110              return FALSE;
00111            }
00112          cmsg->rm_call.cb_rpcvers = IXDR_GET_LONG (buf);
00113          if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION)
00114            {
00115              return FALSE;
00116            }
00117          cmsg->rm_call.cb_prog = IXDR_GET_LONG (buf);
00118          cmsg->rm_call.cb_vers = IXDR_GET_LONG (buf);
00119          cmsg->rm_call.cb_proc = IXDR_GET_LONG (buf);
00120          oa = &cmsg->rm_call.cb_cred;
00121          oa->oa_flavor = IXDR_GET_ENUM (buf, enum_t);
00122          oa->oa_length = IXDR_GET_INT32 (buf);
00123          if (oa->oa_length)
00124            {
00125              if (oa->oa_length > MAX_AUTH_BYTES)
00126               return FALSE;
00127              if (oa->oa_base == NULL)
00128               {
00129                 oa->oa_base = (caddr_t)
00130                   mem_alloc (oa->oa_length);
00131               }
00132              buf = XDR_INLINE (xdrs, RNDUP (oa->oa_length));
00133              if (buf == NULL)
00134               {
00135                 if (INTUSE(xdr_opaque) (xdrs, oa->oa_base,
00136                                      oa->oa_length) == FALSE)
00137                   return FALSE;
00138               }
00139              else
00140               {
00141                 memcpy (oa->oa_base, (caddr_t) buf, oa->oa_length);
00142                 /* no real need....
00143                    buf = (long *) ((char *) buf
00144                    + RNDUP(oa->oa_length));
00145                  */
00146               }
00147            }
00148          oa = &cmsg->rm_call.cb_verf;
00149          buf = XDR_INLINE (xdrs, 2 * BYTES_PER_XDR_UNIT);
00150          if (buf == NULL)
00151            {
00152              if (INTUSE(xdr_enum) (xdrs, &oa->oa_flavor) == FALSE ||
00153                 INTUSE(xdr_u_int) (xdrs, &oa->oa_length) == FALSE)
00154               {
00155                 return FALSE;
00156               }
00157            }
00158          else
00159            {
00160              oa->oa_flavor = IXDR_GET_ENUM (buf, enum_t);
00161              oa->oa_length = IXDR_GET_INT32 (buf);
00162            }
00163          if (oa->oa_length)
00164            {
00165              if (oa->oa_length > MAX_AUTH_BYTES)
00166               return FALSE;
00167              if (oa->oa_base == NULL)
00168               {
00169                 oa->oa_base = (caddr_t)
00170                   mem_alloc (oa->oa_length);
00171               }
00172              buf = XDR_INLINE (xdrs, RNDUP (oa->oa_length));
00173              if (buf == NULL)
00174               {
00175                 if (INTUSE(xdr_opaque) (xdrs, oa->oa_base,
00176                                      oa->oa_length) == FALSE)
00177                   return FALSE;
00178               }
00179              else
00180               {
00181                 memcpy (oa->oa_base, (caddr_t) buf, oa->oa_length);
00182                 /* no real need...
00183                    buf = (long *) ((char *) buf
00184                    + RNDUP(oa->oa_length));
00185                  */
00186               }
00187            }
00188          return TRUE;
00189        }
00190     }
00191   if (
00192        INTUSE(xdr_u_long) (xdrs, &(cmsg->rm_xid)) &&
00193        INTUSE(xdr_enum) (xdrs, (enum_t *) & (cmsg->rm_direction)) &&
00194        (cmsg->rm_direction == CALL) &&
00195        INTUSE(xdr_u_long) (xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
00196        (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) &&
00197        INTUSE(xdr_u_long) (xdrs, &(cmsg->rm_call.cb_prog)) &&
00198        INTUSE(xdr_u_long) (xdrs, &(cmsg->rm_call.cb_vers)) &&
00199        INTUSE(xdr_u_long) (xdrs, &(cmsg->rm_call.cb_proc)) &&
00200        INTUSE(xdr_opaque_auth) (xdrs, &(cmsg->rm_call.cb_cred)))
00201     return INTUSE(xdr_opaque_auth) (xdrs, &(cmsg->rm_call.cb_verf));
00202   return FALSE;
00203 }
00204 INTDEF(xdr_callmsg)