Correct data for isw* functions.
[glibc/history.git] / sunrpc / rpc_prot.c
blob8da20c61c8a18ef691be7366a63ce4d27db2e297
1 /* @(#)rpc_prot.c 2.3 88/08/07 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.
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.
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.
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.
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.
26 * Sun Microsystems, Inc.
27 * 2550 Garcia Avenue
28 * Mountain View, California 94043
30 #if !defined(lint) && defined(SCCSIDS)
31 static char sccsid[] = "@(#)rpc_prot.c 1.36 87/08/11 Copyr 1984 Sun Micro";
32 #endif
35 * rpc_prot.c
37 * Copyright (C) 1984, Sun Microsystems, Inc.
39 * This set of routines implements the rpc message definition,
40 * its serializer and some common rpc utility routines.
41 * The routines are meant for various implementations of rpc -
42 * they are NOT for the rpc client or rpc service implementations!
43 * Because authentication stuff is easy and is part of rpc, the opaque
44 * routines are also in this program.
47 #include <sys/param.h>
49 #include <rpc/rpc.h>
51 /* * * * * * * * * * * * * * XDR Authentication * * * * * * * * * * * */
54 * XDR an opaque authentication struct
55 * (see auth.h)
57 bool_t
58 xdr_opaque_auth(xdrs, ap)
59 register XDR *xdrs;
60 register struct opaque_auth *ap;
63 if (xdr_enum(xdrs, &(ap->oa_flavor)))
64 return (xdr_bytes(xdrs, &ap->oa_base,
65 &ap->oa_length, MAX_AUTH_BYTES));
66 return (FALSE);
70 * XDR a DES block
72 bool_t
73 xdr_des_block(xdrs, blkp)
74 register XDR *xdrs;
75 register des_block *blkp;
77 return (xdr_opaque(xdrs, (caddr_t)blkp, sizeof(des_block)));
80 /* * * * * * * * * * * * * * XDR RPC MESSAGE * * * * * * * * * * * * * * * */
83 * XDR the MSG_ACCEPTED part of a reply message union
85 bool_t
86 xdr_accepted_reply(xdrs, ar)
87 register XDR *xdrs;
88 register struct accepted_reply *ar;
91 /* personalized union, rather than calling xdr_union */
92 if (! xdr_opaque_auth(xdrs, &(ar->ar_verf)))
93 return (FALSE);
94 if (! xdr_enum(xdrs, (enum_t *)&(ar->ar_stat)))
95 return (FALSE);
96 switch (ar->ar_stat) {
98 case SUCCESS:
99 return ((*(ar->ar_results.proc))(xdrs, ar->ar_results.where));
101 case PROG_MISMATCH:
102 if (! xdr_u_long(xdrs, &(ar->ar_vers.low)))
103 return (FALSE);
104 return (xdr_u_long(xdrs, &(ar->ar_vers.high)));
106 return (TRUE); /* TRUE => open ended set of problems */
110 * XDR the MSG_DENIED part of a reply message union
112 bool_t
113 xdr_rejected_reply(xdrs, rr)
114 register XDR *xdrs;
115 register struct rejected_reply *rr;
118 /* personalized union, rather than calling xdr_union */
119 if (! xdr_enum(xdrs, (enum_t *)&(rr->rj_stat)))
120 return (FALSE);
121 switch (rr->rj_stat) {
123 case RPC_MISMATCH:
124 if (! xdr_u_long(xdrs, &(rr->rj_vers.low)))
125 return (FALSE);
126 return (xdr_u_long(xdrs, &(rr->rj_vers.high)));
128 case AUTH_ERROR:
129 return (xdr_enum(xdrs, (enum_t *)&(rr->rj_why)));
131 return (FALSE);
134 static struct xdr_discrim reply_dscrm[3] = {
135 { (int)MSG_ACCEPTED, xdr_accepted_reply },
136 { (int)MSG_DENIED, xdr_rejected_reply },
137 { __dontcare__, NULL_xdrproc_t } };
140 * XDR a reply message
142 bool_t
143 xdr_replymsg(xdrs, rmsg)
144 register XDR *xdrs;
145 register struct rpc_msg *rmsg;
147 if (
148 xdr_u_long(xdrs, &(rmsg->rm_xid)) &&
149 xdr_enum(xdrs, (enum_t *)&(rmsg->rm_direction)) &&
150 (rmsg->rm_direction == REPLY) )
151 return (xdr_union(xdrs, (enum_t *)&(rmsg->rm_reply.rp_stat),
152 (caddr_t)&(rmsg->rm_reply.ru), reply_dscrm, NULL_xdrproc_t));
153 return (FALSE);
158 * Serializes the "static part" of a call message header.
159 * The fields include: rm_xid, rm_direction, rpcvers, prog, and vers.
160 * The rm_xid is not really static, but the user can easily munge on the fly.
162 bool_t
163 xdr_callhdr(xdrs, cmsg)
164 register XDR *xdrs;
165 register struct rpc_msg *cmsg;
168 cmsg->rm_direction = CALL;
169 cmsg->rm_call.cb_rpcvers = RPC_MSG_VERSION;
170 if (
171 (xdrs->x_op == XDR_ENCODE) &&
172 xdr_u_long(xdrs, &(cmsg->rm_xid)) &&
173 xdr_enum(xdrs, (enum_t *)&(cmsg->rm_direction)) &&
174 xdr_u_long(xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
175 xdr_u_long(xdrs, &(cmsg->rm_call.cb_prog)) )
176 return (xdr_u_long(xdrs, &(cmsg->rm_call.cb_vers)));
177 return (FALSE);
180 /* ************************** Client utility routine ************* */
182 static void
183 accepted(acpt_stat, error)
184 register enum accept_stat acpt_stat;
185 register struct rpc_err *error;
188 switch (acpt_stat) {
190 case PROG_UNAVAIL:
191 error->re_status = RPC_PROGUNAVAIL;
192 return;
194 case PROG_MISMATCH:
195 error->re_status = RPC_PROGVERSMISMATCH;
196 return;
198 case PROC_UNAVAIL:
199 error->re_status = RPC_PROCUNAVAIL;
200 return;
202 case GARBAGE_ARGS:
203 error->re_status = RPC_CANTDECODEARGS;
204 return;
206 case SYSTEM_ERR:
207 error->re_status = RPC_SYSTEMERROR;
208 return;
210 case SUCCESS:
211 error->re_status = RPC_SUCCESS;
212 return;
214 /* something's wrong, but we don't know what ... */
215 error->re_status = RPC_FAILED;
216 error->re_lb.s1 = (long)MSG_ACCEPTED;
217 error->re_lb.s2 = (long)acpt_stat;
220 static void
221 rejected(rjct_stat, error)
222 register enum reject_stat rjct_stat;
223 register struct rpc_err *error;
226 switch (rjct_stat) {
228 case RPC_VERSMISMATCH:
229 error->re_status = RPC_VERSMISMATCH;
230 return;
232 case AUTH_ERROR:
233 error->re_status = RPC_AUTHERROR;
234 return;
236 /* something's wrong, but we don't know what ... */
237 error->re_status = RPC_FAILED;
238 error->re_lb.s1 = (long)MSG_DENIED;
239 error->re_lb.s2 = (long)rjct_stat;
243 * given a reply message, fills in the error
245 void
246 _seterr_reply(msg, error)
247 register struct rpc_msg *msg;
248 register struct rpc_err *error;
251 /* optimized for normal, SUCCESSful case */
252 switch (msg->rm_reply.rp_stat) {
254 case MSG_ACCEPTED:
255 if (msg->acpted_rply.ar_stat == SUCCESS) {
256 error->re_status = RPC_SUCCESS;
257 return;
259 accepted(msg->acpted_rply.ar_stat, error);
260 break;
262 case MSG_DENIED:
263 rejected(msg->rjcted_rply.rj_stat, error);
264 break;
266 default:
267 error->re_status = RPC_FAILED;
268 error->re_lb.s1 = (long)(msg->rm_reply.rp_stat);
269 break;
271 switch (error->re_status) {
273 case RPC_VERSMISMATCH:
274 error->re_vers.low = msg->rjcted_rply.rj_vers.low;
275 error->re_vers.high = msg->rjcted_rply.rj_vers.high;
276 break;
278 case RPC_AUTHERROR:
279 error->re_why = msg->rjcted_rply.rj_why;
280 break;
282 case RPC_PROGVERSMISMATCH:
283 error->re_vers.low = msg->acpted_rply.ar_vers.low;
284 error->re_vers.high = msg->acpted_rply.ar_vers.high;
285 break;