source: rtems-libbsd/services/librpc/src/rpc/rpc_prot.c @ e599318

4.115-freebsd-12freebsd-9.3
Last change on this file since e599318 was e599318, checked in by Sebastian Huber <sebastian.huber@…>, on Oct 9, 2013 at 8:52:54 PM

Update files to match FreeBSD layout

Add compatibility with Newlib header files. Some FreeBSD header files
are mapped by the translation script:

o rtems/bsd/sys/_types.h
o rtems/bsd/sys/errno.h
o rtems/bsd/sys/lock.h
o rtems/bsd/sys/param.h
o rtems/bsd/sys/resource.h
o rtems/bsd/sys/time.h
o rtems/bsd/sys/timespec.h
o rtems/bsd/sys/types.h
o rtems/bsd/sys/unistd.h

It is now possible to include <sys/socket.h> directly for example.

Generate one Makefile which builds everything including tests.

  • Property mode set to 100644
File size: 7.8 KB
Line 
1/*
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.
8 *
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.
12 *
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.
16 *
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.
20 *
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.
24 *
25 * Sun Microsystems, Inc.
26 * 2550 Garcia Avenue
27 * Mountain View, California  94043
28 */
29
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";*/
33static char *rcsid = "$FreeBSD: src/lib/libc/rpc/rpc_prot.c,v 1.8 1999/08/28 00:00:46 peter Exp $";
34#endif
35
36/*
37 * rpc_prot.c
38 *
39 * Copyright (C) 1984, Sun Microsystems, Inc.
40 *
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.
47 */
48
49#ifdef HAVE_CONFIG_H
50#include "config.h"
51#endif
52
53#include <assert.h>
54#include <sys/param.h>
55
56#include <rpc/rpc.h>
57
58static void accepted(enum accept_stat, struct rpc_err *);
59static void rejected(enum reject_stat, struct rpc_err *);
60
61/* * * * * * * * * * * * * * XDR Authentication * * * * * * * * * * * */
62
63extern struct opaque_auth _null_auth;
64
65/*
66 * XDR an opaque authentication struct
67 * (see auth.h)
68 */
69bool_t
70xdr_opaque_auth(
71        XDR *xdrs,
72        struct opaque_auth *ap)
73{
74
75        assert(xdrs != NULL);
76        assert(ap != NULL);
77
78        if (xdr_enum(xdrs, &(ap->oa_flavor)))
79                return (xdr_bytes(xdrs, &ap->oa_base,
80                        &ap->oa_length, MAX_AUTH_BYTES));
81        return (FALSE);
82}
83
84/*
85 * XDR a DES block
86 */
87bool_t
88xdr_des_block(
89        XDR *xdrs,
90        des_block *blkp)
91{
92
93        assert(xdrs != NULL);
94        assert(blkp != NULL);
95
96        return (xdr_opaque(xdrs, (caddr_t)blkp, sizeof(des_block)));
97}
98
99/* * * * * * * * * * * * * * XDR RPC MESSAGE * * * * * * * * * * * * * * * */
100
101/*
102 * XDR the MSG_ACCEPTED part of a reply message union
103 */
104bool_t
105xdr_accepted_reply(
106        XDR *xdrs,
107        struct accepted_reply *ar)
108{
109
110        /* personalized union, rather than calling xdr_union */
111        if (! xdr_opaque_auth(xdrs, &(ar->ar_verf)))
112                return (FALSE);
113        if (! xdr_enum(xdrs, (enum_t *)(void *)&(ar->ar_stat)))
114                return (FALSE);
115        switch (ar->ar_stat) {
116
117        case SUCCESS:
118                return ((*(ar->ar_results.proc))(xdrs, ar->ar_results.where));
119
120        case PROG_MISMATCH:
121                if (! xdr_u_int32_t(xdrs, &(ar->ar_vers.low)))
122                        return (FALSE);
123                return (xdr_u_int32_t(xdrs, &(ar->ar_vers.high)));
124
125        case GARBAGE_ARGS:
126        case SYSTEM_ERR:
127        case PROC_UNAVAIL:
128        case PROG_UNAVAIL:
129                break;
130        }
131        return (TRUE);  /* TRUE => open ended set of problems */
132}
133
134/*
135 * XDR the MSG_DENIED part of a reply message union
136 */
137bool_t
138xdr_rejected_reply(
139        XDR *xdrs,
140        struct rejected_reply *rr )
141{
142
143        /* personalized union, rather than calling xdr_union */
144        if (! xdr_enum(xdrs, (enum_t *)(void *)&(rr->rj_stat)))
145                return (FALSE);
146        switch (rr->rj_stat) {
147
148        case RPC_MISMATCH:
149                if (! xdr_u_int32_t(xdrs, &(rr->rj_vers.low)))
150                        return (FALSE);
151                return (xdr_u_int32_t(xdrs, &(rr->rj_vers.high)));
152
153        case AUTH_ERROR:
154                return (xdr_enum(xdrs, (enum_t *)(void *)&(rr->rj_why)));
155        }
156        return (FALSE);
157}
158
159static const struct xdr_discrim reply_dscrm[3] = {
160        { (int)MSG_ACCEPTED, (xdrproc_t)xdr_accepted_reply },
161        { (int)MSG_DENIED, (xdrproc_t)xdr_rejected_reply },
162        { __dontcare__, NULL_xdrproc_t } };
163
164/*
165 * XDR a reply message
166 */
167bool_t
168xdr_replymsg(
169        XDR *xdrs,
170        struct rpc_msg *rmsg)
171{
172        if (
173            xdr_u_int32_t(xdrs, &(rmsg->rm_xid)) &&
174            xdr_enum(xdrs, (enum_t *)(void *)&(rmsg->rm_direction)) &&
175            (rmsg->rm_direction == REPLY) )
176                return (xdr_union(xdrs, (enum_t *)(void *)&(rmsg->rm_reply.rp_stat),
177                   (caddr_t)&(rmsg->rm_reply.ru), reply_dscrm, NULL_xdrproc_t));
178        return (FALSE);
179}
180
181
182/*
183 * Serializes the "static part" of a call message header.
184 * The fields include: rm_xid, rm_direction, rpcvers, prog, and vers.
185 * The rm_xid is not really static, but the user can easily munge on the fly.
186 */
187bool_t
188xdr_callhdr(
189        XDR *xdrs,
190        struct rpc_msg *cmsg)
191{
192
193        cmsg->rm_direction = CALL;
194        cmsg->rm_call.cb_rpcvers = RPC_MSG_VERSION;
195        if (
196            (xdrs->x_op == XDR_ENCODE) &&
197            xdr_u_int32_t(xdrs, &(cmsg->rm_xid)) &&
198            xdr_enum(xdrs, (enum_t *)(void *)&(cmsg->rm_direction)) &&
199            xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
200            xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_prog)) )
201            return (xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers)));
202        return (FALSE);
203}
204
205/* ************************** Client utility routine ************* */
206
207static void
208accepted(
209        enum accept_stat acpt_stat,
210        struct rpc_err *error)
211{
212
213        assert(error != NULL);
214
215        switch (acpt_stat) {
216
217        case PROG_UNAVAIL:
218                error->re_status = RPC_PROGUNAVAIL;
219                return;
220
221        case PROG_MISMATCH:
222                error->re_status = RPC_PROGVERSMISMATCH;
223                return;
224
225        case PROC_UNAVAIL:
226                error->re_status = RPC_PROCUNAVAIL;
227                return;
228
229        case GARBAGE_ARGS:
230                error->re_status = RPC_CANTDECODEARGS;
231                return;
232
233        case SYSTEM_ERR:
234                error->re_status = RPC_SYSTEMERROR;
235                return;
236
237        case SUCCESS:
238                error->re_status = RPC_SUCCESS;
239                return;
240        }
241        /* something's wrong, but we don't know what ... */
242        error->re_status = RPC_FAILED;
243        error->re_lb.s1 = (int32_t)MSG_ACCEPTED;
244        error->re_lb.s2 = (int32_t)acpt_stat;
245}
246
247static void
248rejected(
249        enum reject_stat rjct_stat,
250        struct rpc_err *error)
251{
252
253        assert(error != NULL);
254
255        switch (rjct_stat) {
256        case RPC_MISMATCH:
257                error->re_status = RPC_VERSMISMATCH;
258                return;
259
260        case AUTH_ERROR:
261                error->re_status = RPC_AUTHERROR;
262                return;
263        }
264        /* something's wrong, but we don't know what ... */
265        error->re_status = RPC_FAILED;
266        error->re_lb.s1 = (int32_t)MSG_DENIED;
267        error->re_lb.s2 = (int32_t)rjct_stat;
268}
269
270/*
271 * given a reply message, fills in the error
272 */
273void
274_seterr_reply(
275        struct rpc_msg *msg,
276        struct rpc_err *error)
277{
278
279        assert(msg != NULL);
280        assert(error != NULL);
281
282        /* optimized for normal, SUCCESSful case */
283        switch (msg->rm_reply.rp_stat) {
284
285        case MSG_ACCEPTED:
286                if (msg->acpted_rply.ar_stat == SUCCESS) {
287                        error->re_status = RPC_SUCCESS;
288                        return;
289                }
290                accepted(msg->acpted_rply.ar_stat, error);
291                break;
292
293        case MSG_DENIED:
294                rejected(msg->rjcted_rply.rj_stat, error);
295                break;
296
297        default:
298                error->re_status = RPC_FAILED;
299                error->re_lb.s1 = (int32_t)(msg->rm_reply.rp_stat);
300                break;
301        }
302        switch (error->re_status) {
303
304        case RPC_VERSMISMATCH:
305                error->re_vers.low = msg->rjcted_rply.rj_vers.low;
306                error->re_vers.high = msg->rjcted_rply.rj_vers.high;
307                break;
308
309        case RPC_AUTHERROR:
310                error->re_why = msg->rjcted_rply.rj_why;
311                break;
312
313        case RPC_PROGVERSMISMATCH:
314                error->re_vers.low = msg->acpted_rply.ar_vers.low;
315                error->re_vers.high = msg->acpted_rply.ar_vers.high;
316                break;
317
318        case RPC_FAILED:
319        case RPC_SUCCESS:
320        case RPC_PROGNOTREGISTERED:
321        case RPC_PMAPFAILURE:
322        case RPC_UNKNOWNPROTO:
323        case RPC_UNKNOWNHOST:
324        case RPC_SYSTEMERROR:
325        case RPC_CANTDECODEARGS:
326        case RPC_PROCUNAVAIL:
327        case RPC_PROGUNAVAIL:
328        case RPC_TIMEDOUT:
329        case RPC_CANTRECV:
330        case RPC_CANTSEND:
331        case RPC_CANTDECODERES:
332        case RPC_CANTENCODEARGS:
333        default:
334                break;
335        }
336}
Note: See TracBrowser for help on using the repository browser.