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