OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libc/] [inet/] [rpc/] [rpc_prot.c] - Blame information for rev 1325

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/* @(#)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.
9
 *
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.
13
 *
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.
17
 *
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.
21
 *
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.
25
 *
26
 * Sun Microsystems, Inc.
27
 * 2550 Garcia Avenue
28
 * Mountain View, California  94043
29
 */
30
#if 0
31
static char sccsid[] = "@(#)rpc_prot.c 1.36 87/08/11 Copyr 1984 Sun Micro";
32
#endif
33
 
34
/*
35
 * rpc_prot.c
36
 *
37
 * Copyright (C) 1984, Sun Microsystems, Inc.
38
 *
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.
45
 */
46
 
47
#define __FORCE_GLIBC
48
#include <features.h>
49
 
50
#include <sys/param.h>
51
 
52
#include <rpc/rpc.h>
53
 
54
/* * * * * * * * * * * * * * XDR Authentication * * * * * * * * * * * */
55
 
56
/*
57
 * XDR an opaque authentication struct
58
 * (see auth.h)
59
 */
60
bool_t
61
xdr_opaque_auth (XDR *xdrs, struct opaque_auth *ap)
62
{
63
 
64
  if (xdr_enum (xdrs, &(ap->oa_flavor)))
65
    return xdr_bytes (xdrs, &ap->oa_base,
66
                      &ap->oa_length, MAX_AUTH_BYTES);
67
  return FALSE;
68
}
69
 
70
/*
71
 * XDR a DES block
72
 */
73
bool_t
74
xdr_des_block (XDR *xdrs, des_block *blkp)
75
{
76
  return xdr_opaque (xdrs, (caddr_t) blkp, sizeof (des_block));
77
}
78
 
79
/* * * * * * * * * * * * * * XDR RPC MESSAGE * * * * * * * * * * * * * * * */
80
 
81
/*
82
 * XDR the MSG_ACCEPTED part of a reply message union
83
 */
84
bool_t
85
xdr_accepted_reply (XDR *xdrs, struct accepted_reply *ar)
86
{
87
  /* personalized union, rather than calling xdr_union */
88
  if (!xdr_opaque_auth (xdrs, &(ar->ar_verf)))
89
    return FALSE;
90
  if (!xdr_enum (xdrs, (enum_t *) & (ar->ar_stat)))
91
    return FALSE;
92
  switch (ar->ar_stat)
93
    {
94
    case SUCCESS:
95
      return ((*(ar->ar_results.proc)) (xdrs, ar->ar_results.where));
96
    case PROG_MISMATCH:
97
      if (!xdr_u_long (xdrs, &(ar->ar_vers.low)))
98
        return FALSE;
99
      return (xdr_u_long (xdrs, &(ar->ar_vers.high)));
100
    default:
101
      return TRUE;
102
    }
103
  return TRUE;          /* TRUE => open ended set of problems */
104
}
105
 
106
/*
107
 * XDR the MSG_DENIED part of a reply message union
108
 */
109
bool_t
110
xdr_rejected_reply (XDR *xdrs, struct rejected_reply *rr)
111
{
112
  /* personalized union, rather than calling xdr_union */
113
  if (!xdr_enum (xdrs, (enum_t *) & (rr->rj_stat)))
114
    return FALSE;
115
  switch (rr->rj_stat)
116
    {
117
    case RPC_MISMATCH:
118
      if (!xdr_u_long (xdrs, &(rr->rj_vers.low)))
119
        return FALSE;
120
      return xdr_u_long (xdrs, &(rr->rj_vers.high));
121
 
122
    case AUTH_ERROR:
123
      return xdr_enum (xdrs, (enum_t *) & (rr->rj_why));
124
    }
125
  return FALSE;
126
}
127
 
128
static const struct xdr_discrim reply_dscrm[3] =
129
{
130
  {(int) MSG_ACCEPTED, (xdrproc_t) xdr_accepted_reply},
131
  {(int) MSG_DENIED, (xdrproc_t) xdr_rejected_reply},
132
  {__dontcare__, NULL_xdrproc_t}};
133
 
134
/*
135
 * XDR a reply message
136
 */
137
bool_t
138
xdr_replymsg (xdrs, rmsg)
139
     XDR *xdrs;
140
     struct rpc_msg *rmsg;
141
{
142
  if (xdr_u_long (xdrs, &(rmsg->rm_xid)) &&
143
      xdr_enum (xdrs, (enum_t *) & (rmsg->rm_direction)) &&
144
      (rmsg->rm_direction == REPLY))
145
    return xdr_union (xdrs, (enum_t *) & (rmsg->rm_reply.rp_stat),
146
                      (caddr_t) & (rmsg->rm_reply.ru), reply_dscrm,
147
                      NULL_xdrproc_t);
148
  return FALSE;
149
}
150
 
151
 
152
/*
153
 * Serializes the "static part" of a call message header.
154
 * The fields include: rm_xid, rm_direction, rpcvers, prog, and vers.
155
 * The rm_xid is not really static, but the user can easily munge on the fly.
156
 */
157
bool_t
158
xdr_callhdr (xdrs, cmsg)
159
     XDR *xdrs;
160
     struct rpc_msg *cmsg;
161
{
162
 
163
  cmsg->rm_direction = CALL;
164
  cmsg->rm_call.cb_rpcvers = RPC_MSG_VERSION;
165
  if (
166
       (xdrs->x_op == XDR_ENCODE) &&
167
       xdr_u_long (xdrs, &(cmsg->rm_xid)) &&
168
       xdr_enum (xdrs, (enum_t *) & (cmsg->rm_direction)) &&
169
       xdr_u_long (xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
170
       xdr_u_long (xdrs, &(cmsg->rm_call.cb_prog)))
171
    return xdr_u_long (xdrs, &(cmsg->rm_call.cb_vers));
172
  return FALSE;
173
}
174
 
175
/* ************************** Client utility routine ************* */
176
 
177
static void
178
accepted (enum accept_stat acpt_stat,
179
          struct rpc_err *error)
180
{
181
  switch (acpt_stat)
182
    {
183
 
184
    case PROG_UNAVAIL:
185
      error->re_status = RPC_PROGUNAVAIL;
186
      return;
187
 
188
    case PROG_MISMATCH:
189
      error->re_status = RPC_PROGVERSMISMATCH;
190
      return;
191
 
192
    case PROC_UNAVAIL:
193
      error->re_status = RPC_PROCUNAVAIL;
194
      return;
195
 
196
    case GARBAGE_ARGS:
197
      error->re_status = RPC_CANTDECODEARGS;
198
      return;
199
 
200
    case SYSTEM_ERR:
201
      error->re_status = RPC_SYSTEMERROR;
202
      return;
203
 
204
    case SUCCESS:
205
      error->re_status = RPC_SUCCESS;
206
      return;
207
    }
208
  /* something's wrong, but we don't know what ... */
209
  error->re_status = RPC_FAILED;
210
  error->re_lb.s1 = (long) MSG_ACCEPTED;
211
  error->re_lb.s2 = (long) acpt_stat;
212
}
213
 
214
static void
215
rejected (enum reject_stat rjct_stat,
216
          struct rpc_err *error)
217
{
218
  switch (rjct_stat)
219
    {
220
    case RPC_VERSMISMATCH:
221
      error->re_status = RPC_VERSMISMATCH;
222
      return;
223
    case AUTH_ERROR:
224
      error->re_status = RPC_AUTHERROR;
225
      return;
226
    default:
227
      /* something's wrong, but we don't know what ... */
228
      error->re_status = RPC_FAILED;
229
      error->re_lb.s1 = (long) MSG_DENIED;
230
      error->re_lb.s2 = (long) rjct_stat;
231
      return;
232
    }
233
}
234
 
235
/*
236
 * given a reply message, fills in the error
237
 */
238
void
239
_seterr_reply (struct rpc_msg *msg,
240
               struct rpc_err *error)
241
{
242
  /* optimized for normal, SUCCESSful case */
243
  switch (msg->rm_reply.rp_stat)
244
    {
245
    case MSG_ACCEPTED:
246
      if (msg->acpted_rply.ar_stat == SUCCESS)
247
        {
248
          error->re_status = RPC_SUCCESS;
249
          return;
250
        };
251
      accepted (msg->acpted_rply.ar_stat, error);
252
      break;
253
 
254
    case MSG_DENIED:
255
      rejected (msg->rjcted_rply.rj_stat, error);
256
      break;
257
 
258
    default:
259
      error->re_status = RPC_FAILED;
260
      error->re_lb.s1 = (long) (msg->rm_reply.rp_stat);
261
      break;
262
    }
263
  switch (error->re_status)
264
    {
265
 
266
    case RPC_VERSMISMATCH:
267
      error->re_vers.low = msg->rjcted_rply.rj_vers.low;
268
      error->re_vers.high = msg->rjcted_rply.rj_vers.high;
269
      break;
270
 
271
    case RPC_AUTHERROR:
272
      error->re_why = msg->rjcted_rply.rj_why;
273
      break;
274
 
275
    case RPC_PROGVERSMISMATCH:
276
      error->re_vers.low = msg->acpted_rply.ar_vers.low;
277
      error->re_vers.high = msg->acpted_rply.ar_vers.high;
278
      break;
279
    default:
280
      break;
281
    }
282
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.