* sysdeps/unix/sysv/linux/sparc/sparc32/sysdep.h
[glibc.git] / sunrpc / rpc_prot.c
blob69b0b6cd9d69eba87fc4ce2bbc18edd17fccc2a9
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 (XDR *xdrs, struct opaque_auth *ap)
61 if (INTUSE(xdr_enum) (xdrs, &(ap->oa_flavor)))
62 return INTUSE(xdr_bytes) (xdrs, &ap->oa_base,
63 &ap->oa_length, MAX_AUTH_BYTES);
64 return FALSE;
66 INTDEF(xdr_opaque_auth)
69 * XDR a DES block
71 bool_t
72 xdr_des_block (XDR *xdrs, des_block *blkp)
74 return INTUSE(xdr_opaque) (xdrs, (caddr_t) blkp, sizeof (des_block));
76 INTDEF(xdr_des_block)
78 /* * * * * * * * * * * * * * XDR RPC MESSAGE * * * * * * * * * * * * * * * */
81 * XDR the MSG_ACCEPTED part of a reply message union
83 bool_t
84 xdr_accepted_reply (XDR *xdrs, struct accepted_reply *ar)
86 /* personalized union, rather than calling xdr_union */
87 if (!INTUSE(xdr_opaque_auth) (xdrs, &(ar->ar_verf)))
88 return FALSE;
89 if (!INTUSE(xdr_enum) (xdrs, (enum_t *) & (ar->ar_stat)))
90 return FALSE;
91 switch (ar->ar_stat)
93 case SUCCESS:
94 return ((*(ar->ar_results.proc)) (xdrs, ar->ar_results.where));
95 case PROG_MISMATCH:
96 if (!INTUSE(xdr_u_long) (xdrs, &(ar->ar_vers.low)))
97 return FALSE;
98 return (INTUSE(xdr_u_long) (xdrs, &(ar->ar_vers.high)));
99 default:
100 return TRUE;
102 return TRUE; /* TRUE => open ended set of problems */
104 INTDEF(xdr_accepted_reply)
107 * XDR the MSG_DENIED part of a reply message union
109 bool_t
110 xdr_rejected_reply (XDR *xdrs, struct rejected_reply *rr)
112 /* personalized union, rather than calling xdr_union */
113 if (!INTUSE(xdr_enum) (xdrs, (enum_t *) & (rr->rj_stat)))
114 return FALSE;
115 switch (rr->rj_stat)
117 case RPC_MISMATCH:
118 if (!INTUSE(xdr_u_long) (xdrs, &(rr->rj_vers.low)))
119 return FALSE;
120 return INTUSE(xdr_u_long) (xdrs, &(rr->rj_vers.high));
122 case AUTH_ERROR:
123 return INTUSE(xdr_enum) (xdrs, (enum_t *) & (rr->rj_why));
125 return FALSE;
127 INTDEF(xdr_rejected_reply)
129 static const struct xdr_discrim reply_dscrm[3] =
131 {(int) MSG_ACCEPTED, (xdrproc_t) INTUSE(xdr_accepted_reply)},
132 {(int) MSG_DENIED, (xdrproc_t) INTUSE(xdr_rejected_reply)},
133 {__dontcare__, NULL_xdrproc_t}};
136 * XDR a reply message
138 bool_t
139 xdr_replymsg (xdrs, rmsg)
140 XDR *xdrs;
141 struct rpc_msg *rmsg;
143 if (INTUSE(xdr_u_long) (xdrs, &(rmsg->rm_xid)) &&
144 INTUSE(xdr_enum) (xdrs, (enum_t *) & (rmsg->rm_direction)) &&
145 (rmsg->rm_direction == REPLY))
146 return INTUSE(xdr_union) (xdrs, (enum_t *) & (rmsg->rm_reply.rp_stat),
147 (caddr_t) & (rmsg->rm_reply.ru), reply_dscrm,
148 NULL_xdrproc_t);
149 return FALSE;
151 INTDEF(xdr_replymsg)
155 * Serializes the "static part" of a call message header.
156 * The fields include: rm_xid, rm_direction, rpcvers, prog, and vers.
157 * The rm_xid is not really static, but the user can easily munge on the fly.
159 bool_t
160 xdr_callhdr (xdrs, cmsg)
161 XDR *xdrs;
162 struct rpc_msg *cmsg;
165 cmsg->rm_direction = CALL;
166 cmsg->rm_call.cb_rpcvers = RPC_MSG_VERSION;
167 if (
168 (xdrs->x_op == XDR_ENCODE) &&
169 INTUSE(xdr_u_long) (xdrs, &(cmsg->rm_xid)) &&
170 INTUSE(xdr_enum) (xdrs, (enum_t *) & (cmsg->rm_direction)) &&
171 INTUSE(xdr_u_long) (xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
172 INTUSE(xdr_u_long) (xdrs, &(cmsg->rm_call.cb_prog)))
173 return INTUSE(xdr_u_long) (xdrs, &(cmsg->rm_call.cb_vers));
174 return FALSE;
176 INTDEF(xdr_callhdr)
178 /* ************************** Client utility routine ************* */
180 static void
181 accepted (enum accept_stat acpt_stat,
182 struct rpc_err *error)
184 switch (acpt_stat)
187 case PROG_UNAVAIL:
188 error->re_status = RPC_PROGUNAVAIL;
189 return;
191 case PROG_MISMATCH:
192 error->re_status = RPC_PROGVERSMISMATCH;
193 return;
195 case PROC_UNAVAIL:
196 error->re_status = RPC_PROCUNAVAIL;
197 return;
199 case GARBAGE_ARGS:
200 error->re_status = RPC_CANTDECODEARGS;
201 return;
203 case SYSTEM_ERR:
204 error->re_status = RPC_SYSTEMERROR;
205 return;
207 case SUCCESS:
208 error->re_status = RPC_SUCCESS;
209 return;
211 /* something's wrong, but we don't know what ... */
212 error->re_status = RPC_FAILED;
213 error->re_lb.s1 = (long) MSG_ACCEPTED;
214 error->re_lb.s2 = (long) acpt_stat;
217 static void
218 rejected (enum reject_stat rjct_stat,
219 struct rpc_err *error)
221 switch (rjct_stat)
223 case RPC_VERSMISMATCH:
224 error->re_status = RPC_VERSMISMATCH;
225 return;
226 case AUTH_ERROR:
227 error->re_status = RPC_AUTHERROR;
228 return;
229 default:
230 /* something's wrong, but we don't know what ... */
231 error->re_status = RPC_FAILED;
232 error->re_lb.s1 = (long) MSG_DENIED;
233 error->re_lb.s2 = (long) rjct_stat;
234 return;
239 * given a reply message, fills in the error
241 void
242 _seterr_reply (struct rpc_msg *msg,
243 struct rpc_err *error)
245 /* optimized for normal, SUCCESSful case */
246 switch (msg->rm_reply.rp_stat)
248 case MSG_ACCEPTED:
249 if (msg->acpted_rply.ar_stat == SUCCESS)
251 error->re_status = RPC_SUCCESS;
252 return;
254 accepted (msg->acpted_rply.ar_stat, error);
255 break;
257 case MSG_DENIED:
258 rejected (msg->rjcted_rply.rj_stat, error);
259 break;
261 default:
262 error->re_status = RPC_FAILED;
263 error->re_lb.s1 = (long) (msg->rm_reply.rp_stat);
264 break;
266 switch (error->re_status)
269 case RPC_VERSMISMATCH:
270 error->re_vers.low = msg->rjcted_rply.rj_vers.low;
271 error->re_vers.high = msg->rjcted_rply.rj_vers.high;
272 break;
274 case RPC_AUTHERROR:
275 error->re_why = msg->rjcted_rply.rj_why;
276 break;
278 case RPC_PROGVERSMISMATCH:
279 error->re_vers.low = msg->acpted_rply.ar_vers.low;
280 error->re_vers.high = msg->acpted_rply.ar_vers.high;
281 break;
282 default:
283 break;
286 libc_hidden_def (_seterr_reply)