1 /* $NetBSD: rpc_callmsg.c,v 1.20 2013/03/11 20:19:29 tron Exp $ */
4 * Copyright (c) 2010, Oracle America, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
16 * * Neither the name of the "Oracle America, Inc." nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/cdefs.h>
35 #if defined(LIBC_SCCS) && !defined(lint)
37 static char *sccsid
= "@(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro";
38 static char *sccsid
= "@(#)rpc_callmsg.c 2.1 88/07/29 4.0 RPCSRC";
40 __RCSID("$NetBSD: rpc_callmsg.c,v 1.20 2013/03/11 20:19:29 tron Exp $");
47 * Copyright (C) 1984, Sun Microsystems, Inc.
51 #include "namespace.h"
53 #include <sys/param.h>
62 __weak_alias(xdr_callmsg
,_xdr_callmsg
)
69 xdr_callmsg(XDR
*xdrs
, struct rpc_msg
*cmsg
)
72 struct opaque_auth
*oa
;
74 _DIAGASSERT(xdrs
!= NULL
);
75 _DIAGASSERT(cmsg
!= NULL
);
77 if (xdrs
->x_op
== XDR_ENCODE
) {
78 if (cmsg
->rm_call
.cb_cred
.oa_length
> MAX_AUTH_BYTES
) {
81 if (cmsg
->rm_call
.cb_verf
.oa_length
> MAX_AUTH_BYTES
) {
84 buf
= XDR_INLINE(xdrs
, 8 * BYTES_PER_XDR_UNIT
85 + RNDUP(cmsg
->rm_call
.cb_cred
.oa_length
)
86 + 2 * BYTES_PER_XDR_UNIT
87 + RNDUP(cmsg
->rm_call
.cb_verf
.oa_length
));
89 IXDR_PUT_INT32(buf
, cmsg
->rm_xid
);
90 IXDR_PUT_ENUM(buf
, cmsg
->rm_direction
);
91 if (cmsg
->rm_direction
!= CALL
) {
94 IXDR_PUT_INT32(buf
, cmsg
->rm_call
.cb_rpcvers
);
95 if (cmsg
->rm_call
.cb_rpcvers
!= RPC_MSG_VERSION
) {
98 IXDR_PUT_INT32(buf
, cmsg
->rm_call
.cb_prog
);
99 IXDR_PUT_INT32(buf
, cmsg
->rm_call
.cb_vers
);
100 IXDR_PUT_INT32(buf
, cmsg
->rm_call
.cb_proc
);
101 oa
= &cmsg
->rm_call
.cb_cred
;
102 IXDR_PUT_ENUM(buf
, oa
->oa_flavor
);
103 IXDR_PUT_INT32(buf
, oa
->oa_length
);
105 memmove(buf
, oa
->oa_base
, oa
->oa_length
);
106 buf
+= RNDUP(oa
->oa_length
) / sizeof (int32_t);
108 oa
= &cmsg
->rm_call
.cb_verf
;
109 IXDR_PUT_ENUM(buf
, oa
->oa_flavor
);
110 IXDR_PUT_INT32(buf
, oa
->oa_length
);
112 memmove(buf
, oa
->oa_base
, oa
->oa_length
);
114 buf += RNDUP(oa->oa_length) / sizeof (int32_t);
120 if (xdrs
->x_op
== XDR_DECODE
) {
121 buf
= XDR_INLINE(xdrs
, 8 * BYTES_PER_XDR_UNIT
);
123 cmsg
->rm_xid
= IXDR_GET_U_INT32(buf
);
124 cmsg
->rm_direction
= IXDR_GET_ENUM(buf
, enum msg_type
);
125 if (cmsg
->rm_direction
!= CALL
) {
128 cmsg
->rm_call
.cb_rpcvers
= IXDR_GET_U_INT32(buf
);
129 if (cmsg
->rm_call
.cb_rpcvers
!= RPC_MSG_VERSION
) {
132 cmsg
->rm_call
.cb_prog
= IXDR_GET_U_INT32(buf
);
133 cmsg
->rm_call
.cb_vers
= IXDR_GET_U_INT32(buf
);
134 cmsg
->rm_call
.cb_proc
= IXDR_GET_U_INT32(buf
);
135 oa
= &cmsg
->rm_call
.cb_cred
;
136 oa
->oa_flavor
= IXDR_GET_ENUM(buf
, enum_t
);
137 oa
->oa_length
= (u_int
)IXDR_GET_U_INT32(buf
);
139 if (oa
->oa_length
> MAX_AUTH_BYTES
) {
142 if (oa
->oa_base
== NULL
) {
143 oa
->oa_base
= mem_alloc(oa
->oa_length
);
144 if (oa
->oa_base
== NULL
)
147 buf
= XDR_INLINE(xdrs
, RNDUP(oa
->oa_length
));
149 if (xdr_opaque(xdrs
, oa
->oa_base
,
150 oa
->oa_length
) == FALSE
) {
154 memmove(oa
->oa_base
, buf
,
157 buf += RNDUP(oa->oa_length) /
162 oa
= &cmsg
->rm_call
.cb_verf
;
163 buf
= XDR_INLINE(xdrs
, 2 * BYTES_PER_XDR_UNIT
);
165 if (xdr_enum(xdrs
, &oa
->oa_flavor
) == FALSE
||
166 xdr_u_int(xdrs
, &oa
->oa_length
) == FALSE
) {
170 oa
->oa_flavor
= IXDR_GET_ENUM(buf
, enum_t
);
171 oa
->oa_length
= (u_int
)IXDR_GET_U_INT32(buf
);
174 if (oa
->oa_length
> MAX_AUTH_BYTES
) {
177 if (oa
->oa_base
== NULL
) {
178 oa
->oa_base
= mem_alloc(oa
->oa_length
);
179 if (oa
->oa_base
== NULL
)
182 buf
= XDR_INLINE(xdrs
, RNDUP(oa
->oa_length
));
184 if (xdr_opaque(xdrs
, oa
->oa_base
,
185 oa
->oa_length
) == FALSE
) {
189 memmove(oa
->oa_base
, buf
,
192 buf += RNDUP(oa->oa_length) /
201 xdr_u_int32_t(xdrs
, &(cmsg
->rm_xid
)) &&
202 xdr_enum(xdrs
, (enum_t
*)(void *)&(cmsg
->rm_direction
)) &&
203 (cmsg
->rm_direction
== CALL
) &&
204 xdr_u_int32_t(xdrs
, &(cmsg
->rm_call
.cb_rpcvers
)) &&
205 (cmsg
->rm_call
.cb_rpcvers
== RPC_MSG_VERSION
) &&
206 xdr_u_int32_t(xdrs
, &(cmsg
->rm_call
.cb_prog
)) &&
207 xdr_u_int32_t(xdrs
, &(cmsg
->rm_call
.cb_vers
)) &&
208 xdr_u_int32_t(xdrs
, &(cmsg
->rm_call
.cb_proc
)) &&
209 xdr_opaque_auth(xdrs
, &(cmsg
->rm_call
.cb_cred
)) )
210 return (xdr_opaque_auth(xdrs
, &(cmsg
->rm_call
.cb_verf
)));