2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
25 * Sun Microsystems, Inc.
27 * Mountain View, California 94043
30 #if defined(LIBC_SCCS) && !defined(lint)
31 /*static char *sccsid = "from: @(#)rpc_prot.c 1.36 87/08/11 Copyr 1984 Sun Micro";*/
32 /*static char *sccsid = "from: @(#)rpc_prot.c 2.3 88/08/07 4.0 RPCSRC";*/
33 static char *rcsid = "$FreeBSD: src/lib/libc/rpc/rpc_prot.c,v 1.8 1999/08/28 00:00:46 peter Exp $";
39 * Copyright (C) 1984, Sun Microsystems, Inc.
41 * This set of routines implements the rpc message definition,
42 * its serializer and some common rpc utility routines.
43 * The routines are meant for various implementations of rpc -
44 * they are NOT for the rpc client or rpc service implementations!
45 * Because authentication stuff is easy and is part of rpc, the opaque
46 * routines are also in this program.
49 #include <sys/param.h>
53 /* * * * * * * * * * * * * * XDR Authentication * * * * * * * * * * * */
55 struct opaque_auth _null_auth;
58 * XDR an opaque authentication struct
62 xdr_opaque_auth(xdrs, ap)
64 register struct opaque_auth *ap;
67 if (xdr_enum(xdrs, &(ap->oa_flavor)))
68 return (xdr_bytes(xdrs, &ap->oa_base,
69 &ap->oa_length, MAX_AUTH_BYTES));
77 xdr_des_block(xdrs, blkp)
79 register des_block *blkp;
81 return (xdr_opaque(xdrs, (caddr_t)blkp, sizeof(des_block)));
84 /* * * * * * * * * * * * * * XDR RPC MESSAGE * * * * * * * * * * * * * * * */
87 * XDR the MSG_ACCEPTED part of a reply message union
90 xdr_accepted_reply(xdrs, ar)
92 register struct accepted_reply *ar;
95 /* personalized union, rather than calling xdr_union */
96 if (! xdr_opaque_auth(xdrs, &(ar->ar_verf)))
98 if (! xdr_enum(xdrs, (enum_t *)&(ar->ar_stat)))
100 switch (ar->ar_stat) {
103 return ((*(ar->ar_results.proc))(xdrs, ar->ar_results.where));
106 if (! xdr_u_int32_t(xdrs, &(ar->ar_vers.low)))
108 return (xdr_u_int32_t(xdrs, &(ar->ar_vers.high)));
112 return (TRUE); /* TRUE => open ended set of problems */
116 * XDR the MSG_DENIED part of a reply message union
119 xdr_rejected_reply(xdrs, rr)
121 register struct rejected_reply *rr;
124 /* personalized union, rather than calling xdr_union */
125 if (! xdr_enum(xdrs, (enum_t *)&(rr->rj_stat)))
127 switch (rr->rj_stat) {
130 if (! xdr_u_int32_t(xdrs, &(rr->rj_vers.low)))
132 return (xdr_u_int32_t(xdrs, &(rr->rj_vers.high)));
135 return (xdr_enum(xdrs, (enum_t *)&(rr->rj_why)));
140 static struct xdr_discrim reply_dscrm[3] = {
141 { (int)MSG_ACCEPTED, xdr_accepted_reply },
142 { (int)MSG_DENIED, xdr_rejected_reply },
143 { __dontcare__, NULL_xdrproc_t } };
146 * XDR a reply message
149 xdr_replymsg(xdrs, rmsg)
151 register struct rpc_msg *rmsg;
154 xdr_u_int32_t(xdrs, &(rmsg->rm_xid)) &&
155 xdr_enum(xdrs, (enum_t *)&(rmsg->rm_direction)) &&
156 (rmsg->rm_direction == REPLY) )
157 return (xdr_union(xdrs, (enum_t *)&(rmsg->rm_reply.rp_stat),
158 (caddr_t)&(rmsg->rm_reply.ru), reply_dscrm, NULL_xdrproc_t));
164 * Serializes the "static part" of a call message header.
165 * The fields include: rm_xid, rm_direction, rpcvers, prog, and vers.
166 * The rm_xid is not really static, but the user can easily munge on the fly.
169 xdr_callhdr(xdrs, cmsg)
171 register struct rpc_msg *cmsg;
174 cmsg->rm_direction = CALL;
175 cmsg->rm_call.cb_rpcvers = RPC_MSG_VERSION;
177 (xdrs->x_op == XDR_ENCODE) &&
178 xdr_u_int32_t(xdrs, &(cmsg->rm_xid)) &&
179 xdr_enum(xdrs, (enum_t *)&(cmsg->rm_direction)) &&
180 xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
181 xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_prog)) )
182 return (xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers)));
186 /* ************************** Client utility routine ************* */
189 accepted(acpt_stat, error)
190 register enum accept_stat acpt_stat;
191 register struct rpc_err *error;
197 error->re_status = RPC_PROGUNAVAIL;
201 error->re_status = RPC_PROGVERSMISMATCH;
205 error->re_status = RPC_PROCUNAVAIL;
209 error->re_status = RPC_CANTDECODEARGS;
213 error->re_status = RPC_SYSTEMERROR;
217 error->re_status = RPC_SUCCESS;
220 /* something's wrong, but we don't know what ... */
221 error->re_status = RPC_FAILED;
222 error->re_lb.s1 = (long)MSG_ACCEPTED;
223 error->re_lb.s2 = (long)acpt_stat;
227 rejected(rjct_stat, error)
228 register enum reject_stat rjct_stat;
229 register struct rpc_err *error;
234 case RPC_VERSMISMATCH:
235 error->re_status = RPC_VERSMISMATCH;
239 error->re_status = RPC_AUTHERROR;
244 /* something's wrong, but we don't know what ... */
245 error->re_status = RPC_FAILED;
246 error->re_lb.s1 = (long)MSG_DENIED;
247 error->re_lb.s2 = (long)rjct_stat;
251 * given a reply message, fills in the error
254 _seterr_reply(msg, error)
255 register struct rpc_msg *msg;
256 register struct rpc_err *error;
259 /* optimized for normal, SUCCESSful case */
260 switch (msg->rm_reply.rp_stat) {
263 if (msg->acpted_rply.ar_stat == SUCCESS) {
264 error->re_status = RPC_SUCCESS;
267 accepted(msg->acpted_rply.ar_stat, error);
271 rejected(msg->rjcted_rply.rj_stat, error);
275 error->re_status = RPC_FAILED;
276 error->re_lb.s1 = (long)(msg->rm_reply.rp_stat);
279 switch (error->re_status) {
281 case RPC_VERSMISMATCH:
282 error->re_vers.low = msg->rjcted_rply.rj_vers.low;
283 error->re_vers.high = msg->rjcted_rply.rj_vers.high;
287 error->re_why = msg->rjcted_rply.rj_why;
290 case RPC_PROGVERSMISMATCH:
291 error->re_vers.low = msg->acpted_rply.ar_vers.low;
292 error->re_vers.high = msg->acpted_rply.ar_vers.high;