2 static char sfs_rpc_prot_id[] = "@(#)rpc_prot.c 2.1 97/10/23";
4 /* @(#)rpc_prot.c 2.3 88/08/07 4.0 RPCSRC */
6 * Copyright (c) 1992-1997,2001 by Standard Performance Evaluation Corporation
8 * Standard Performance Evaluation Corporation (SPEC)
9 * 6585 Merchant Place, Suite 100
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.
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.
20 * The source code is provided to the user or company under the license
21 * agreement for the SPEC Benchmark Suite for this product.
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.
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.
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.
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.
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.
47 * Sun Microsystems, Inc.
49 * Mountain View, California 94043
51 #if !defined(lint) && defined(SCCSIDS)
52 static char sccsid[] = "@(#)rpc_prot.c 1.36 87/08/11 Copyr 1984 Sun Micro";
58 * Copyright (C) 1984, Sun Microsystems, Inc.
60 * This set of routines implements the rpc message definition,
61 * its serializer and some common rpc utility routines.
62 * The routines are meant for various implementations of rpc -
63 * they are NOT for the rpc client or rpc service implementations!
64 * Because authentication stuff is easy and is part of rpc, the opaque
65 * routines are also in this program.
70 /* * * * * * * * * * * * * * XDR Authentication * * * * * * * * * * * */
72 struct opaque_auth _null_auth;
75 * XDR an opaque authentication struct
81 struct opaque_auth *ap)
84 if (xdr_enum(xdrs, &(ap->oa_flavor)))
85 return (xdr_bytes(xdrs, (void *)&ap->oa_base,
86 &ap->oa_length, MAX_AUTH_BYTES));
98 return (xdr_opaque(xdrs, (void *)blkp, sizeof(des_block)));
101 /* * * * * * * * * * * * * * XDR RPC MESSAGE * * * * * * * * * * * * * * * */
104 * XDR the MSG_ACCEPTED part of a reply message union
109 struct accepted_reply *ar)
112 /* personalized union, rather than calling xdr_union */
113 if (! xdr_opaque_auth(xdrs, &(ar->ar_verf)))
115 if (! xdr_enum(xdrs, (enum_t *)&(ar->ar_stat)))
117 switch (ar->ar_stat) {
120 return ((*(ar->ar_results.proc))(xdrs, ar->ar_results.where));
123 if (! xdr_uint32_t(xdrs, &(ar->ar_vers.low)))
125 return (xdr_uint32_t(xdrs, &(ar->ar_vers.high)));
127 return (TRUE); /* TRUE => open ended set of problems */
131 * XDR the MSG_DENIED part of a reply message union
136 struct rejected_reply *rr)
139 /* personalized union, rather than calling xdr_union */
140 if (! xdr_enum(xdrs, (enum_t *)&(rr->rj_stat)))
142 switch (rr->rj_stat) {
145 if (! xdr_uint32_t(xdrs, &(rr->rj_vers.low)))
147 return (xdr_uint32_t(xdrs, &(rr->rj_vers.high)));
150 return (xdr_enum(xdrs, (enum_t *)&(rr->rj_why)));
155 static struct xdr_discrim reply_dscrm[3] = {
156 { (int)MSG_ACCEPTED, xdr_accepted_reply },
157 { (int)MSG_DENIED, xdr_rejected_reply },
158 { __dontcare__, NULL_xdrproc_t } };
161 * XDR a reply message
166 struct rpc_msg *rmsg)
169 xdr_uint32_t(xdrs, &(rmsg->rm_xid)) &&
170 xdr_enum(xdrs, (enum_t *)&(rmsg->rm_direction)) &&
171 (rmsg->rm_direction == REPLY) )
172 return (xdr_union(xdrs, (enum_t *)&(rmsg->rm_reply.rp_stat),
173 (void *)&(rmsg->rm_reply.ru), reply_dscrm, NULL_xdrproc_t));
179 * Serializes the "static part" of a call message header.
180 * The fields include: rm_xid, rm_direction, rpcvers, prog, and vers.
181 * The rm_xid is not really static, but the user can easily munge on the fly.
186 struct rpc_msg *cmsg)
189 cmsg->rm_direction = CALL;
190 cmsg->rm_call.cb_rpcvers = RPC_MSG_VERSION;
192 (xdrs->x_op == XDR_ENCODE) &&
193 xdr_uint32_t(xdrs, &(cmsg->rm_xid)) &&
194 xdr_enum(xdrs, (enum_t *)&(cmsg->rm_direction)) &&
195 xdr_uint32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
196 xdr_uint32_t(xdrs, &(cmsg->rm_call.cb_prog)) )
197 return (xdr_uint32_t(xdrs, &(cmsg->rm_call.cb_vers)));
201 /* ************************** Client utility routine ************* */
205 enum accept_stat acpt_stat,
206 struct rpc_err *error)
212 error->re_status = RPC_PROGUNAVAIL;
216 error->re_status = RPC_PROGVERSMISMATCH;
220 error->re_status = RPC_PROCUNAVAIL;
224 error->re_status = RPC_CANTDECODEARGS;
228 error->re_status = RPC_SYSTEMERROR;
232 error->re_status = RPC_SUCCESS;
235 /* something's wrong, but we don't know what ... */
236 error->re_status = RPC_FAILED;
237 error->re_lb.s1 = (int32_t)MSG_ACCEPTED;
238 error->re_lb.s2 = (int32_t)acpt_stat;
243 enum reject_stat rjct_stat,
244 struct rpc_err *error)
247 if ((int)rjct_stat == (int)RPC_VERSMISMATCH) {
248 error->re_status = RPC_VERSMISMATCH;
251 if (rjct_stat == AUTH_ERROR) {
252 error->re_status = RPC_AUTHERROR;
256 /* something's wrong, but we don't know what ... */
257 error->re_status = RPC_FAILED;
258 error->re_lb.s1 = (int32_t)MSG_DENIED;
259 error->re_lb.s2 = (int32_t)rjct_stat;
263 * given a reply message, fills in the error
268 struct rpc_err *error)
271 /* optimized for normal, SUCCESSful case */
272 switch (msg->rm_reply.rp_stat) {
275 if (msg->acpted_rply.ar_stat == SUCCESS) {
276 error->re_status = RPC_SUCCESS;
279 accepted(msg->acpted_rply.ar_stat, error);
283 rejected(msg->rjcted_rply.rj_stat, error);
287 error->re_status = RPC_FAILED;
288 error->re_lb.s1 = (int32_t)(msg->rm_reply.rp_stat);
291 switch (error->re_status) {
293 case RPC_VERSMISMATCH:
294 error->re_vers.low = msg->rjcted_rply.rj_vers.low;
295 error->re_vers.high = msg->rjcted_rply.rj_vers.high;
299 error->re_why = msg->rjcted_rply.rj_why;
302 case RPC_PROGVERSMISMATCH:
303 error->re_vers.low = msg->acpted_rply.ar_vers.low;
304 error->re_vers.high = msg->acpted_rply.ar_vers.high;