1 /* @(#)rpc_callmsg.c	2.1 88/07/29 4.0 RPCSRC */
2 /*
3  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
4  * unrestricted use provided that this legend is included on all tape
5  * media and as a part of the software program in whole or part.  Users
6  * may copy or modify Sun RPC without charge, but are not authorized
7  * to license or distribute it to anyone else except as part of a product or
8  * program developed by the user.
9  *
10  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
11  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
12  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
13  *
14  * Sun RPC is provided with no support and without any obligation on the
15  * part of Sun Microsystems, Inc. to assist in its use, correction,
16  * modification or enhancement.
17  *
18  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
19  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
20  * OR ANY PART THEREOF.
21  *
22  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
23  * or profits or other special, indirect and consequential damages, even if
24  * Sun has been advised of the possibility of such damages.
25  *
26  * Sun Microsystems, Inc.
27  * 2550 Garcia Avenue
28  * Mountain View, California  94043
29  */
30 #if 0
31 static char sccsid[] = "@(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro";
32 #endif
33 
34 /*
35  * rpc_callmsg.c
36  *
37  * Copyright (C) 1984, Sun Microsystems, Inc.
38  *
39  */
40 
41 #include <string.h>
42 #include <sys/param.h>
43 #include <rpc/rpc.h>
44 
45 
46 /*
47  * XDR a call message
48  */
49 bool_t
xdr_callmsg(XDR * xdrs,struct rpc_msg * cmsg)50 xdr_callmsg (XDR *xdrs, struct rpc_msg *cmsg)
51 {
52   int32_t *buf;
53   struct opaque_auth *oa;
54 
55   if (xdrs->x_op == XDR_ENCODE)
56     {
57       if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES)
58 	{
59 	  return (FALSE);
60 	}
61       if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES)
62 	{
63 	  return (FALSE);
64 	}
65       buf = XDR_INLINE (xdrs, 8 * BYTES_PER_XDR_UNIT
66 			+ RNDUP (cmsg->rm_call.cb_cred.oa_length)
67 			+ 2 * BYTES_PER_XDR_UNIT
68 			+ RNDUP (cmsg->rm_call.cb_verf.oa_length));
69       if (buf != NULL)
70 	{
71 	  IXDR_PUT_LONG (buf, cmsg->rm_xid);
72 	  IXDR_PUT_ENUM (buf, cmsg->rm_direction);
73 	  if (cmsg->rm_direction != CALL)
74 	    return FALSE;
75 	  IXDR_PUT_LONG (buf, cmsg->rm_call.cb_rpcvers);
76 	  if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION)
77 	    return FALSE;
78 	  IXDR_PUT_LONG (buf, cmsg->rm_call.cb_prog);
79 	  IXDR_PUT_LONG (buf, cmsg->rm_call.cb_vers);
80 	  IXDR_PUT_LONG (buf, cmsg->rm_call.cb_proc);
81 	  oa = &cmsg->rm_call.cb_cred;
82 	  IXDR_PUT_ENUM (buf, oa->oa_flavor);
83 	  IXDR_PUT_INT32 (buf, oa->oa_length);
84 	  if (oa->oa_length)
85 	    {
86 	      memcpy ((caddr_t) buf, oa->oa_base, oa->oa_length);
87 	      buf = (int32_t *) ((char *) buf + RNDUP (oa->oa_length));
88 	    }
89 	  oa = &cmsg->rm_call.cb_verf;
90 	  IXDR_PUT_ENUM (buf, oa->oa_flavor);
91 	  IXDR_PUT_INT32 (buf, oa->oa_length);
92 	  if (oa->oa_length)
93 	    {
94 	      memcpy ((caddr_t) buf, oa->oa_base, oa->oa_length);
95 	      /* no real need....
96 	         buf = (long *) ((char *) buf + RNDUP(oa->oa_length));
97 	       */
98 	    }
99 	  return TRUE;
100 	}
101     }
102   if (xdrs->x_op == XDR_DECODE)
103     {
104       buf = XDR_INLINE (xdrs, 8 * BYTES_PER_XDR_UNIT);
105       if (buf != NULL)
106 	{
107 	  cmsg->rm_xid = IXDR_GET_LONG (buf);
108 	  cmsg->rm_direction = IXDR_GET_ENUM (buf, enum msg_type);
109 	  if (cmsg->rm_direction != CALL)
110 	    {
111 	      return FALSE;
112 	    }
113 	  cmsg->rm_call.cb_rpcvers = IXDR_GET_LONG (buf);
114 	  if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION)
115 	    {
116 	      return FALSE;
117 	    }
118 	  cmsg->rm_call.cb_prog = IXDR_GET_LONG (buf);
119 	  cmsg->rm_call.cb_vers = IXDR_GET_LONG (buf);
120 	  cmsg->rm_call.cb_proc = IXDR_GET_LONG (buf);
121 	  oa = &cmsg->rm_call.cb_cred;
122 	  oa->oa_flavor = IXDR_GET_ENUM (buf, enum_t);
123 	  oa->oa_length = IXDR_GET_INT32 (buf);
124 	  if (oa->oa_length)
125 	    {
126 	      if (oa->oa_length > MAX_AUTH_BYTES)
127 		return FALSE;
128 	      if (oa->oa_base == NULL)
129 		{
130 		  oa->oa_base = (caddr_t)
131 		    mem_alloc (oa->oa_length);
132 		}
133 	      buf = XDR_INLINE (xdrs, RNDUP (oa->oa_length));
134 	      if (buf == NULL)
135 		{
136 		  if (xdr_opaque (xdrs, oa->oa_base,
137 				  oa->oa_length) == FALSE)
138 		    return FALSE;
139 		}
140 	      else
141 		{
142 		  memcpy (oa->oa_base, (caddr_t) buf, oa->oa_length);
143 		  /* no real need....
144 		     buf = (long *) ((char *) buf
145 		     + RNDUP(oa->oa_length));
146 		   */
147 		}
148 	    }
149 	  oa = &cmsg->rm_call.cb_verf;
150 	  buf = XDR_INLINE (xdrs, 2 * BYTES_PER_XDR_UNIT);
151 	  if (buf == NULL)
152 	    {
153 	      if (xdr_enum (xdrs, &oa->oa_flavor) == FALSE ||
154 		  xdr_u_int (xdrs, &oa->oa_length) == FALSE)
155 		{
156 		  return FALSE;
157 		}
158 	    }
159 	  else
160 	    {
161 	      oa->oa_flavor = IXDR_GET_ENUM (buf, enum_t);
162 	      oa->oa_length = IXDR_GET_INT32 (buf);
163 	    }
164 	  if (oa->oa_length)
165 	    {
166 	      if (oa->oa_length > MAX_AUTH_BYTES)
167 		return FALSE;
168 	      if (oa->oa_base == NULL)
169 		{
170 		  oa->oa_base = (caddr_t)
171 		    mem_alloc (oa->oa_length);
172 		}
173 	      buf = XDR_INLINE (xdrs, RNDUP (oa->oa_length));
174 	      if (buf == NULL)
175 		{
176 		  if (xdr_opaque (xdrs, oa->oa_base,
177 				  oa->oa_length) == FALSE)
178 		    return FALSE;
179 		}
180 	      else
181 		{
182 		  memcpy (oa->oa_base, (caddr_t) buf, oa->oa_length);
183 		  /* no real need...
184 		     buf = (long *) ((char *) buf
185 		     + RNDUP(oa->oa_length));
186 		   */
187 		}
188 	    }
189 	  return TRUE;
190 	}
191     }
192   if (
193        xdr_u_long (xdrs, &(cmsg->rm_xid)) &&
194        xdr_enum (xdrs, (enum_t *) & (cmsg->rm_direction)) &&
195        (cmsg->rm_direction == CALL) &&
196        xdr_u_long (xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
197        (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) &&
198        xdr_u_long (xdrs, &(cmsg->rm_call.cb_prog)) &&
199        xdr_u_long (xdrs, &(cmsg->rm_call.cb_vers)) &&
200        xdr_u_long (xdrs, &(cmsg->rm_call.cb_proc)) &&
201        xdr_opaque_auth (xdrs, &(cmsg->rm_call.cb_cred)))
202     return xdr_opaque_auth (xdrs, &(cmsg->rm_call.cb_verf));
203   return FALSE;
204 }
205 libc_hidden_def(xdr_callmsg)
206