rpc_callmsg.c revision 1.18.24.1 1 1.18.24.1 riz /* $NetBSD: rpc_callmsg.c,v 1.18.24.1 2013/03/14 22:03:13 riz Exp $ */
2 1.3 cgd
3 1.1 cgd /*
4 1.18.24.1 riz * Copyright (c) 2010, Oracle America, Inc.
5 1.18.24.1 riz *
6 1.18.24.1 riz * Redistribution and use in source and binary forms, with or without
7 1.18.24.1 riz * modification, are permitted provided that the following conditions are
8 1.18.24.1 riz * met:
9 1.18.24.1 riz *
10 1.18.24.1 riz * * Redistributions of source code must retain the above copyright
11 1.18.24.1 riz * notice, this list of conditions and the following disclaimer.
12 1.18.24.1 riz * * Redistributions in binary form must reproduce the above
13 1.18.24.1 riz * copyright notice, this list of conditions and the following
14 1.18.24.1 riz * disclaimer in the documentation and/or other materials
15 1.18.24.1 riz * provided with the distribution.
16 1.18.24.1 riz * * Neither the name of the "Oracle America, Inc." nor the names of its
17 1.18.24.1 riz * contributors may be used to endorse or promote products derived
18 1.18.24.1 riz * from this software without specific prior written permission.
19 1.18.24.1 riz *
20 1.18.24.1 riz * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 1.18.24.1 riz * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 1.18.24.1 riz * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 1.18.24.1 riz * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 1.18.24.1 riz * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 1.18.24.1 riz * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.18.24.1 riz * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27 1.18.24.1 riz * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 1.18.24.1 riz * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 1.18.24.1 riz * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 1.18.24.1 riz * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 1.18.24.1 riz * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 cgd */
33 1.1 cgd
34 1.6 christos #include <sys/cdefs.h>
35 1.1 cgd #if defined(LIBC_SCCS) && !defined(lint)
36 1.6 christos #if 0
37 1.6 christos static char *sccsid = "@(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro";
38 1.6 christos static char *sccsid = "@(#)rpc_callmsg.c 2.1 88/07/29 4.0 RPCSRC";
39 1.6 christos #else
40 1.18.24.1 riz __RCSID("$NetBSD: rpc_callmsg.c,v 1.18.24.1 2013/03/14 22:03:13 riz Exp $");
41 1.6 christos #endif
42 1.1 cgd #endif
43 1.1 cgd
44 1.1 cgd /*
45 1.1 cgd * rpc_callmsg.c
46 1.1 cgd *
47 1.1 cgd * Copyright (C) 1984, Sun Microsystems, Inc.
48 1.1 cgd *
49 1.1 cgd */
50 1.1 cgd
51 1.7 jtc #include "namespace.h"
52 1.10 lukem
53 1.10 lukem #include <sys/param.h>
54 1.10 lukem
55 1.13 lukem #include <assert.h>
56 1.2 cgd #include <stdlib.h>
57 1.5 cgd #include <string.h>
58 1.10 lukem
59 1.7 jtc #include <rpc/rpc.h>
60 1.1 cgd
61 1.7 jtc #ifdef __weak_alias
62 1.15 mycroft __weak_alias(xdr_callmsg,_xdr_callmsg)
63 1.7 jtc #endif
64 1.1 cgd
65 1.1 cgd /*
66 1.1 cgd * XDR a call message
67 1.1 cgd */
68 1.1 cgd bool_t
69 1.1 cgd xdr_callmsg(xdrs, cmsg)
70 1.10 lukem XDR *xdrs;
71 1.10 lukem struct rpc_msg *cmsg;
72 1.1 cgd {
73 1.10 lukem int32_t *buf;
74 1.10 lukem struct opaque_auth *oa;
75 1.13 lukem
76 1.13 lukem _DIAGASSERT(xdrs != NULL);
77 1.13 lukem _DIAGASSERT(cmsg != NULL);
78 1.1 cgd
79 1.1 cgd if (xdrs->x_op == XDR_ENCODE) {
80 1.1 cgd if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) {
81 1.1 cgd return (FALSE);
82 1.1 cgd }
83 1.1 cgd if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) {
84 1.1 cgd return (FALSE);
85 1.1 cgd }
86 1.1 cgd buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT
87 1.1 cgd + RNDUP(cmsg->rm_call.cb_cred.oa_length)
88 1.1 cgd + 2 * BYTES_PER_XDR_UNIT
89 1.1 cgd + RNDUP(cmsg->rm_call.cb_verf.oa_length));
90 1.1 cgd if (buf != NULL) {
91 1.16 fvdl IXDR_PUT_INT32(buf, cmsg->rm_xid);
92 1.1 cgd IXDR_PUT_ENUM(buf, cmsg->rm_direction);
93 1.1 cgd if (cmsg->rm_direction != CALL) {
94 1.1 cgd return (FALSE);
95 1.1 cgd }
96 1.16 fvdl IXDR_PUT_INT32(buf, cmsg->rm_call.cb_rpcvers);
97 1.1 cgd if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
98 1.1 cgd return (FALSE);
99 1.1 cgd }
100 1.16 fvdl IXDR_PUT_INT32(buf, cmsg->rm_call.cb_prog);
101 1.16 fvdl IXDR_PUT_INT32(buf, cmsg->rm_call.cb_vers);
102 1.16 fvdl IXDR_PUT_INT32(buf, cmsg->rm_call.cb_proc);
103 1.1 cgd oa = &cmsg->rm_call.cb_cred;
104 1.1 cgd IXDR_PUT_ENUM(buf, oa->oa_flavor);
105 1.16 fvdl IXDR_PUT_INT32(buf, oa->oa_length);
106 1.1 cgd if (oa->oa_length) {
107 1.11 christos memmove(buf, oa->oa_base, oa->oa_length);
108 1.2 cgd buf += RNDUP(oa->oa_length) / sizeof (int32_t);
109 1.1 cgd }
110 1.1 cgd oa = &cmsg->rm_call.cb_verf;
111 1.1 cgd IXDR_PUT_ENUM(buf, oa->oa_flavor);
112 1.16 fvdl IXDR_PUT_INT32(buf, oa->oa_length);
113 1.1 cgd if (oa->oa_length) {
114 1.11 christos memmove(buf, oa->oa_base, oa->oa_length);
115 1.1 cgd /* no real need....
116 1.2 cgd buf += RNDUP(oa->oa_length) / sizeof (int32_t);
117 1.1 cgd */
118 1.1 cgd }
119 1.1 cgd return (TRUE);
120 1.1 cgd }
121 1.1 cgd }
122 1.1 cgd if (xdrs->x_op == XDR_DECODE) {
123 1.1 cgd buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT);
124 1.1 cgd if (buf != NULL) {
125 1.16 fvdl cmsg->rm_xid = IXDR_GET_U_INT32(buf);
126 1.1 cgd cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type);
127 1.1 cgd if (cmsg->rm_direction != CALL) {
128 1.1 cgd return (FALSE);
129 1.1 cgd }
130 1.16 fvdl cmsg->rm_call.cb_rpcvers = IXDR_GET_U_INT32(buf);
131 1.1 cgd if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
132 1.1 cgd return (FALSE);
133 1.1 cgd }
134 1.16 fvdl cmsg->rm_call.cb_prog = IXDR_GET_U_INT32(buf);
135 1.16 fvdl cmsg->rm_call.cb_vers = IXDR_GET_U_INT32(buf);
136 1.16 fvdl cmsg->rm_call.cb_proc = IXDR_GET_U_INT32(buf);
137 1.1 cgd oa = &cmsg->rm_call.cb_cred;
138 1.1 cgd oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
139 1.16 fvdl oa->oa_length = (u_int)IXDR_GET_U_INT32(buf);
140 1.1 cgd if (oa->oa_length) {
141 1.1 cgd if (oa->oa_length > MAX_AUTH_BYTES) {
142 1.1 cgd return (FALSE);
143 1.1 cgd }
144 1.1 cgd if (oa->oa_base == NULL) {
145 1.18 christos oa->oa_base = mem_alloc(oa->oa_length);
146 1.12 lukem if (oa->oa_base == NULL)
147 1.12 lukem return (FALSE);
148 1.1 cgd }
149 1.1 cgd buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
150 1.1 cgd if (buf == NULL) {
151 1.1 cgd if (xdr_opaque(xdrs, oa->oa_base,
152 1.1 cgd oa->oa_length) == FALSE) {
153 1.1 cgd return (FALSE);
154 1.1 cgd }
155 1.1 cgd } else {
156 1.11 christos memmove(oa->oa_base, buf,
157 1.1 cgd oa->oa_length);
158 1.1 cgd /* no real need....
159 1.1 cgd buf += RNDUP(oa->oa_length) /
160 1.2 cgd sizeof (int32_t);
161 1.1 cgd */
162 1.1 cgd }
163 1.1 cgd }
164 1.1 cgd oa = &cmsg->rm_call.cb_verf;
165 1.1 cgd buf = XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT);
166 1.1 cgd if (buf == NULL) {
167 1.1 cgd if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE ||
168 1.1 cgd xdr_u_int(xdrs, &oa->oa_length) == FALSE) {
169 1.1 cgd return (FALSE);
170 1.1 cgd }
171 1.1 cgd } else {
172 1.1 cgd oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
173 1.16 fvdl oa->oa_length = (u_int)IXDR_GET_U_INT32(buf);
174 1.1 cgd }
175 1.1 cgd if (oa->oa_length) {
176 1.1 cgd if (oa->oa_length > MAX_AUTH_BYTES) {
177 1.1 cgd return (FALSE);
178 1.1 cgd }
179 1.1 cgd if (oa->oa_base == NULL) {
180 1.18 christos oa->oa_base = mem_alloc(oa->oa_length);
181 1.12 lukem if (oa->oa_base == NULL)
182 1.12 lukem return (FALSE);
183 1.1 cgd }
184 1.1 cgd buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
185 1.1 cgd if (buf == NULL) {
186 1.1 cgd if (xdr_opaque(xdrs, oa->oa_base,
187 1.1 cgd oa->oa_length) == FALSE) {
188 1.1 cgd return (FALSE);
189 1.1 cgd }
190 1.1 cgd } else {
191 1.11 christos memmove(oa->oa_base, buf,
192 1.1 cgd oa->oa_length);
193 1.1 cgd /* no real need...
194 1.1 cgd buf += RNDUP(oa->oa_length) /
195 1.2 cgd sizeof (int32_t);
196 1.1 cgd */
197 1.1 cgd }
198 1.1 cgd }
199 1.1 cgd return (TRUE);
200 1.1 cgd }
201 1.1 cgd }
202 1.1 cgd if (
203 1.4 cgd xdr_u_int32_t(xdrs, &(cmsg->rm_xid)) &&
204 1.17 christos xdr_enum(xdrs, (enum_t *)(void *)&(cmsg->rm_direction)) &&
205 1.1 cgd (cmsg->rm_direction == CALL) &&
206 1.4 cgd xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
207 1.1 cgd (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) &&
208 1.4 cgd xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_prog)) &&
209 1.4 cgd xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers)) &&
210 1.4 cgd xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_proc)) &&
211 1.1 cgd xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred)) )
212 1.12 lukem return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf)));
213 1.1 cgd return (FALSE);
214 1.1 cgd }
215