]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - lib/libc/rpc/rpc_callmsg.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / lib / libc / rpc / rpc_callmsg.c
1 /*      $NetBSD: rpc_callmsg.c,v 1.16 2000/07/14 08:40:42 fvdl Exp $    */
2
3 /*
4  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
5  * unrestricted use provided that this legend is included on all tape
6  * media and as a part of the software program in whole or part.  Users
7  * may copy or modify Sun RPC without charge, but are not authorized
8  * to license or distribute it to anyone else except as part of a product or
9  * program developed by the user.
10  *
11  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
12  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
13  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14  *
15  * Sun RPC is provided with no support and without any obligation on the
16  * part of Sun Microsystems, Inc. to assist in its use, correction,
17  * modification or enhancement.
18  *
19  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
20  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
21  * OR ANY PART THEREOF.
22  *
23  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
24  * or profits or other special, indirect and consequential damages, even if
25  * Sun has been advised of the possibility of such damages.
26  *
27  * Sun Microsystems, Inc.
28  * 2550 Garcia Avenue
29  * Mountain View, California  94043
30  */
31
32 #if defined(LIBC_SCCS) && !defined(lint)
33 static char *sccsid2 = "@(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro";
34 static char *sccsid = "@(#)rpc_callmsg.c        2.1 88/07/29 4.0 RPCSRC";
35 #endif
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
38
39 /*
40  * rpc_callmsg.c
41  *
42  * Copyright (C) 1984, Sun Microsystems, Inc.
43  *
44  */
45
46 #include "namespace.h"
47 #include <assert.h>
48 #include <stdlib.h>
49 #include <string.h>
50
51 #include <rpc/rpc.h>
52 #include "un-namespace.h"
53
54 /*
55  * XDR a call message
56  */
57 bool_t
58 xdr_callmsg(xdrs, cmsg)
59         XDR *xdrs;
60         struct rpc_msg *cmsg;
61 {
62         enum msg_type *prm_direction;
63         int32_t *buf;
64         struct opaque_auth *oa;
65
66         assert(xdrs != NULL);
67         assert(cmsg != NULL);
68
69         if (xdrs->x_op == XDR_ENCODE) {
70                 if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) {
71                         return (FALSE);
72                 }
73                 if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) {
74                         return (FALSE);
75                 }
76                 buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT
77                         + RNDUP(cmsg->rm_call.cb_cred.oa_length)
78                         + 2 * BYTES_PER_XDR_UNIT
79                         + RNDUP(cmsg->rm_call.cb_verf.oa_length));
80                 if (buf != NULL) {
81                         IXDR_PUT_INT32(buf, cmsg->rm_xid);
82                         IXDR_PUT_ENUM(buf, cmsg->rm_direction);
83                         if (cmsg->rm_direction != CALL) {
84                                 return (FALSE);
85                         }
86                         IXDR_PUT_INT32(buf, cmsg->rm_call.cb_rpcvers);
87                         if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
88                                 return (FALSE);
89                         }
90                         IXDR_PUT_INT32(buf, cmsg->rm_call.cb_prog);
91                         IXDR_PUT_INT32(buf, cmsg->rm_call.cb_vers);
92                         IXDR_PUT_INT32(buf, cmsg->rm_call.cb_proc);
93                         oa = &cmsg->rm_call.cb_cred;
94                         IXDR_PUT_ENUM(buf, oa->oa_flavor);
95                         IXDR_PUT_INT32(buf, oa->oa_length);
96                         if (oa->oa_length) {
97                                 memmove(buf, oa->oa_base, oa->oa_length);
98                                 buf += RNDUP(oa->oa_length) / sizeof (int32_t);
99                         }
100                         oa = &cmsg->rm_call.cb_verf;
101                         IXDR_PUT_ENUM(buf, oa->oa_flavor);
102                         IXDR_PUT_INT32(buf, oa->oa_length);
103                         if (oa->oa_length) {
104                                 memmove(buf, oa->oa_base, oa->oa_length);
105                                 /* no real need....
106                                 buf += RNDUP(oa->oa_length) / sizeof (int32_t);
107                                 */
108                         }
109                         return (TRUE);
110                 }
111         }
112         if (xdrs->x_op == XDR_DECODE) {
113                 buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT);
114                 if (buf != NULL) {
115                         cmsg->rm_xid = IXDR_GET_U_INT32(buf);
116                         cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type);
117                         if (cmsg->rm_direction != CALL) {
118                                 return (FALSE);
119                         }
120                         cmsg->rm_call.cb_rpcvers = IXDR_GET_U_INT32(buf);
121                         if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
122                                 return (FALSE);
123                         }
124                         cmsg->rm_call.cb_prog = IXDR_GET_U_INT32(buf);
125                         cmsg->rm_call.cb_vers = IXDR_GET_U_INT32(buf);
126                         cmsg->rm_call.cb_proc = IXDR_GET_U_INT32(buf);
127                         oa = &cmsg->rm_call.cb_cred;
128                         oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
129                         oa->oa_length = (u_int)IXDR_GET_U_INT32(buf);
130                         if (oa->oa_length) {
131                                 if (oa->oa_length > MAX_AUTH_BYTES) {
132                                         return (FALSE);
133                                 }
134                                 if (oa->oa_base == NULL) {
135                                         oa->oa_base = (caddr_t)
136                                             mem_alloc(oa->oa_length);
137                                         if (oa->oa_base == NULL)
138                                                 return (FALSE);
139                                 }
140                                 buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
141                                 if (buf == NULL) {
142                                         if (xdr_opaque(xdrs, oa->oa_base,
143                                             oa->oa_length) == FALSE) {
144                                                 return (FALSE);
145                                         }
146                                 } else {
147                                         memmove(oa->oa_base, buf,
148                                             oa->oa_length);
149                                         /* no real need....
150                                         buf += RNDUP(oa->oa_length) /
151                                                 sizeof (int32_t);
152                                         */
153                                 }
154                         }
155                         oa = &cmsg->rm_call.cb_verf;
156                         buf = XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT);
157                         if (buf == NULL) {
158                                 if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE ||
159                                     xdr_u_int(xdrs, &oa->oa_length) == FALSE) {
160                                         return (FALSE);
161                                 }
162                         } else {
163                                 oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
164                                 oa->oa_length = (u_int)IXDR_GET_U_INT32(buf);
165                         }
166                         if (oa->oa_length) {
167                                 if (oa->oa_length > MAX_AUTH_BYTES) {
168                                         return (FALSE);
169                                 }
170                                 if (oa->oa_base == NULL) {
171                                         oa->oa_base = (caddr_t)
172                                             mem_alloc(oa->oa_length);
173                                         if (oa->oa_base == NULL)
174                                                 return (FALSE);
175                                 }
176                                 buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
177                                 if (buf == NULL) {
178                                         if (xdr_opaque(xdrs, oa->oa_base,
179                                             oa->oa_length) == FALSE) {
180                                                 return (FALSE);
181                                         }
182                                 } else {
183                                         memmove(oa->oa_base, buf,
184                                             oa->oa_length);
185                                         /* no real need...
186                                         buf += RNDUP(oa->oa_length) /
187                                                 sizeof (int32_t);
188                                         */
189                                 }
190                         }
191                         return (TRUE);
192                 }
193         }
194         prm_direction = &cmsg->rm_direction;
195         if (
196             xdr_u_int32_t(xdrs, &(cmsg->rm_xid)) &&
197             xdr_enum(xdrs, (enum_t *) prm_direction) &&
198             (cmsg->rm_direction == CALL) &&
199             xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
200             (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) &&
201             xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_prog)) &&
202             xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers)) &&
203             xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_proc)) &&
204             xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred)) )
205                 return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf)));
206         return (FALSE);
207 }