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