1 |
30 |
unneback |
/*
|
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_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro";*/
|
32 |
|
|
/*static char *sccsid = "from: @(#)rpc_callmsg.c 2.1 88/07/29 4.0 RPCSRC";*/
|
33 |
|
|
static char *rcsid = "$FreeBSD: src/lib/libc/rpc/rpc_callmsg.c,v 1.9 1999/08/28 00:00:45 peter Exp $";
|
34 |
|
|
#endif
|
35 |
|
|
|
36 |
|
|
/*
|
37 |
|
|
* rpc_callmsg.c
|
38 |
|
|
*
|
39 |
|
|
* Copyright (C) 1984, Sun Microsystems, Inc.
|
40 |
|
|
*
|
41 |
|
|
*/
|
42 |
|
|
|
43 |
|
|
#include <sys/param.h>
|
44 |
|
|
#include <stdlib.h>
|
45 |
|
|
#include <string.h>
|
46 |
|
|
#include <rpc/rpc.h>
|
47 |
|
|
|
48 |
|
|
/*
|
49 |
|
|
* XDR a call message
|
50 |
|
|
*/
|
51 |
|
|
bool_t
|
52 |
|
|
xdr_callmsg(xdrs, cmsg)
|
53 |
|
|
register XDR *xdrs;
|
54 |
|
|
register struct rpc_msg *cmsg;
|
55 |
|
|
{
|
56 |
|
|
register int32_t *buf;
|
57 |
|
|
register struct opaque_auth *oa;
|
58 |
|
|
|
59 |
|
|
if (xdrs->x_op == XDR_ENCODE) {
|
60 |
|
|
if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) {
|
61 |
|
|
return (FALSE);
|
62 |
|
|
}
|
63 |
|
|
if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) {
|
64 |
|
|
return (FALSE);
|
65 |
|
|
}
|
66 |
|
|
buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT
|
67 |
|
|
+ RNDUP(cmsg->rm_call.cb_cred.oa_length)
|
68 |
|
|
+ 2 * BYTES_PER_XDR_UNIT
|
69 |
|
|
+ RNDUP(cmsg->rm_call.cb_verf.oa_length));
|
70 |
|
|
if (buf != NULL) {
|
71 |
|
|
IXDR_PUT_LONG(buf, cmsg->rm_xid);
|
72 |
|
|
IXDR_PUT_ENUM(buf, cmsg->rm_direction);
|
73 |
|
|
if (cmsg->rm_direction != CALL) {
|
74 |
|
|
return (FALSE);
|
75 |
|
|
}
|
76 |
|
|
IXDR_PUT_LONG(buf, cmsg->rm_call.cb_rpcvers);
|
77 |
|
|
if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
|
78 |
|
|
return (FALSE);
|
79 |
|
|
}
|
80 |
|
|
IXDR_PUT_LONG(buf, cmsg->rm_call.cb_prog);
|
81 |
|
|
IXDR_PUT_LONG(buf, cmsg->rm_call.cb_vers);
|
82 |
|
|
IXDR_PUT_LONG(buf, cmsg->rm_call.cb_proc);
|
83 |
|
|
oa = &cmsg->rm_call.cb_cred;
|
84 |
|
|
IXDR_PUT_ENUM(buf, oa->oa_flavor);
|
85 |
|
|
IXDR_PUT_LONG(buf, oa->oa_length);
|
86 |
|
|
if (oa->oa_length) {
|
87 |
|
|
memcpy((caddr_t)buf, oa->oa_base, oa->oa_length);
|
88 |
|
|
buf += RNDUP(oa->oa_length) / sizeof (int32_t);
|
89 |
|
|
}
|
90 |
|
|
oa = &cmsg->rm_call.cb_verf;
|
91 |
|
|
IXDR_PUT_ENUM(buf, oa->oa_flavor);
|
92 |
|
|
IXDR_PUT_LONG(buf, oa->oa_length);
|
93 |
|
|
if (oa->oa_length) {
|
94 |
|
|
memcpy((caddr_t)buf, oa->oa_base, oa->oa_length);
|
95 |
|
|
/* no real need....
|
96 |
|
|
buf += RNDUP(oa->oa_length) / sizeof (int32_t);
|
97 |
|
|
*/
|
98 |
|
|
}
|
99 |
|
|
return (TRUE);
|
100 |
|
|
}
|
101 |
|
|
}
|
102 |
|
|
if (xdrs->x_op == XDR_DECODE) {
|
103 |
|
|
buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT);
|
104 |
|
|
if (buf != NULL) {
|
105 |
|
|
cmsg->rm_xid = IXDR_GET_LONG(buf);
|
106 |
|
|
cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type);
|
107 |
|
|
if (cmsg->rm_direction != CALL) {
|
108 |
|
|
return (FALSE);
|
109 |
|
|
}
|
110 |
|
|
cmsg->rm_call.cb_rpcvers = IXDR_GET_LONG(buf);
|
111 |
|
|
if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
|
112 |
|
|
return (FALSE);
|
113 |
|
|
}
|
114 |
|
|
cmsg->rm_call.cb_prog = IXDR_GET_LONG(buf);
|
115 |
|
|
cmsg->rm_call.cb_vers = IXDR_GET_LONG(buf);
|
116 |
|
|
cmsg->rm_call.cb_proc = IXDR_GET_LONG(buf);
|
117 |
|
|
oa = &cmsg->rm_call.cb_cred;
|
118 |
|
|
oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
|
119 |
|
|
oa->oa_length = IXDR_GET_LONG(buf);
|
120 |
|
|
if (oa->oa_length) {
|
121 |
|
|
if (oa->oa_length > MAX_AUTH_BYTES) {
|
122 |
|
|
return (FALSE);
|
123 |
|
|
}
|
124 |
|
|
if (oa->oa_base == NULL) {
|
125 |
|
|
oa->oa_base = (caddr_t)
|
126 |
|
|
mem_alloc(oa->oa_length);
|
127 |
|
|
}
|
128 |
|
|
buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
|
129 |
|
|
if (buf == NULL) {
|
130 |
|
|
if (xdr_opaque(xdrs, oa->oa_base,
|
131 |
|
|
oa->oa_length) == FALSE) {
|
132 |
|
|
return (FALSE);
|
133 |
|
|
}
|
134 |
|
|
} else {
|
135 |
|
|
memcpy(oa->oa_base, (caddr_t)buf,
|
136 |
|
|
oa->oa_length);
|
137 |
|
|
/* no real need....
|
138 |
|
|
buf += RNDUP(oa->oa_length) /
|
139 |
|
|
sizeof (int32_t);
|
140 |
|
|
*/
|
141 |
|
|
}
|
142 |
|
|
}
|
143 |
|
|
oa = &cmsg->rm_call.cb_verf;
|
144 |
|
|
buf = XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT);
|
145 |
|
|
if (buf == NULL) {
|
146 |
|
|
if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE ||
|
147 |
|
|
xdr_u_int(xdrs, &oa->oa_length) == FALSE) {
|
148 |
|
|
return (FALSE);
|
149 |
|
|
}
|
150 |
|
|
} else {
|
151 |
|
|
oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
|
152 |
|
|
oa->oa_length = IXDR_GET_LONG(buf);
|
153 |
|
|
}
|
154 |
|
|
if (oa->oa_length) {
|
155 |
|
|
if (oa->oa_length > MAX_AUTH_BYTES) {
|
156 |
|
|
return (FALSE);
|
157 |
|
|
}
|
158 |
|
|
if (oa->oa_base == NULL) {
|
159 |
|
|
oa->oa_base = (caddr_t)
|
160 |
|
|
mem_alloc(oa->oa_length);
|
161 |
|
|
}
|
162 |
|
|
buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
|
163 |
|
|
if (buf == NULL) {
|
164 |
|
|
if (xdr_opaque(xdrs, oa->oa_base,
|
165 |
|
|
oa->oa_length) == FALSE) {
|
166 |
|
|
return (FALSE);
|
167 |
|
|
}
|
168 |
|
|
} else {
|
169 |
|
|
memcpy(oa->oa_base, (caddr_t)buf,
|
170 |
|
|
oa->oa_length);
|
171 |
|
|
/* no real need...
|
172 |
|
|
buf += RNDUP(oa->oa_length) /
|
173 |
|
|
sizeof (int32_t);
|
174 |
|
|
*/
|
175 |
|
|
}
|
176 |
|
|
}
|
177 |
|
|
return (TRUE);
|
178 |
|
|
}
|
179 |
|
|
}
|
180 |
|
|
if (
|
181 |
|
|
xdr_u_int32_t(xdrs, &(cmsg->rm_xid)) &&
|
182 |
|
|
xdr_enum(xdrs, (enum_t *)&(cmsg->rm_direction)) &&
|
183 |
|
|
(cmsg->rm_direction == CALL) &&
|
184 |
|
|
xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
|
185 |
|
|
(cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) &&
|
186 |
|
|
xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_prog)) &&
|
187 |
|
|
xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers)) &&
|
188 |
|
|
xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_proc)) &&
|
189 |
|
|
xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred)) )
|
190 |
|
|
return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf)));
|
191 |
|
|
return (FALSE);
|
192 |
|
|
}
|
193 |
|
|
|