2 * Copyright (c) 2009, Sun Microsystems, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * - Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * - Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * - Neither the name of Sun Microsystems, Inc. nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
28 * @(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro
29 * @(#)rpc_callmsg.c 2.1 88/07/29 4.0 RPCSRC
30 * $NetBSD: rpc_callmsg.c,v 1.16 2000/07/14 08:40:42 fvdl Exp $
31 * $FreeBSD: src/lib/libc/rpc/rpc_callmsg.c,v 1.13 2007/11/20 01:51:20 jb Exp $
37 * Copyright (C) 1984, Sun Microsystems, Inc.
41 #include "namespace.h"
47 #include "un-namespace.h"
53 xdr_callmsg(XDR
*xdrs
, struct rpc_msg
*cmsg
)
55 enum msg_type
*prm_direction
;
57 struct opaque_auth
*oa
;
62 if (xdrs
->x_op
== XDR_ENCODE
) {
63 if (cmsg
->rm_call
.cb_cred
.oa_length
> MAX_AUTH_BYTES
) {
66 if (cmsg
->rm_call
.cb_verf
.oa_length
> MAX_AUTH_BYTES
) {
69 buf
= XDR_INLINE(xdrs
, 8 * BYTES_PER_XDR_UNIT
70 + RNDUP(cmsg
->rm_call
.cb_cred
.oa_length
)
71 + 2 * BYTES_PER_XDR_UNIT
72 + RNDUP(cmsg
->rm_call
.cb_verf
.oa_length
));
74 IXDR_PUT_INT32(buf
, cmsg
->rm_xid
);
75 IXDR_PUT_ENUM(buf
, cmsg
->rm_direction
);
76 if (cmsg
->rm_direction
!= CALL
) {
79 IXDR_PUT_INT32(buf
, cmsg
->rm_call
.cb_rpcvers
);
80 if (cmsg
->rm_call
.cb_rpcvers
!= RPC_MSG_VERSION
) {
83 IXDR_PUT_INT32(buf
, cmsg
->rm_call
.cb_prog
);
84 IXDR_PUT_INT32(buf
, cmsg
->rm_call
.cb_vers
);
85 IXDR_PUT_INT32(buf
, cmsg
->rm_call
.cb_proc
);
86 oa
= &cmsg
->rm_call
.cb_cred
;
87 IXDR_PUT_ENUM(buf
, oa
->oa_flavor
);
88 IXDR_PUT_INT32(buf
, oa
->oa_length
);
90 memmove(buf
, oa
->oa_base
, oa
->oa_length
);
91 buf
+= RNDUP(oa
->oa_length
) / sizeof (int32_t);
93 oa
= &cmsg
->rm_call
.cb_verf
;
94 IXDR_PUT_ENUM(buf
, oa
->oa_flavor
);
95 IXDR_PUT_INT32(buf
, oa
->oa_length
);
97 memmove(buf
, oa
->oa_base
, oa
->oa_length
);
99 buf += RNDUP(oa->oa_length) / sizeof (int32_t);
105 if (xdrs
->x_op
== XDR_DECODE
) {
106 buf
= XDR_INLINE(xdrs
, 8 * BYTES_PER_XDR_UNIT
);
108 cmsg
->rm_xid
= IXDR_GET_U_INT32(buf
);
109 cmsg
->rm_direction
= IXDR_GET_ENUM(buf
, enum msg_type
);
110 if (cmsg
->rm_direction
!= CALL
) {
113 cmsg
->rm_call
.cb_rpcvers
= IXDR_GET_U_INT32(buf
);
114 if (cmsg
->rm_call
.cb_rpcvers
!= RPC_MSG_VERSION
) {
117 cmsg
->rm_call
.cb_prog
= IXDR_GET_U_INT32(buf
);
118 cmsg
->rm_call
.cb_vers
= IXDR_GET_U_INT32(buf
);
119 cmsg
->rm_call
.cb_proc
= IXDR_GET_U_INT32(buf
);
120 oa
= &cmsg
->rm_call
.cb_cred
;
121 oa
->oa_flavor
= IXDR_GET_ENUM(buf
, enum_t
);
122 oa
->oa_length
= (u_int
)IXDR_GET_U_INT32(buf
);
124 if (oa
->oa_length
> MAX_AUTH_BYTES
) {
127 if (oa
->oa_base
== NULL
) {
128 oa
->oa_base
= (caddr_t
)
129 mem_alloc(oa
->oa_length
);
130 if (oa
->oa_base
== NULL
)
133 buf
= XDR_INLINE(xdrs
, RNDUP(oa
->oa_length
));
135 if (xdr_opaque(xdrs
, oa
->oa_base
,
136 oa
->oa_length
) == FALSE
) {
140 memmove(oa
->oa_base
, buf
,
143 buf += RNDUP(oa->oa_length) /
148 oa
= &cmsg
->rm_call
.cb_verf
;
149 buf
= XDR_INLINE(xdrs
, 2 * BYTES_PER_XDR_UNIT
);
151 if (xdr_enum(xdrs
, &oa
->oa_flavor
) == FALSE
||
152 xdr_u_int(xdrs
, &oa
->oa_length
) == FALSE
) {
156 oa
->oa_flavor
= IXDR_GET_ENUM(buf
, enum_t
);
157 oa
->oa_length
= (u_int
)IXDR_GET_U_INT32(buf
);
160 if (oa
->oa_length
> MAX_AUTH_BYTES
) {
163 if (oa
->oa_base
== NULL
) {
164 oa
->oa_base
= (caddr_t
)
165 mem_alloc(oa
->oa_length
);
166 if (oa
->oa_base
== NULL
)
169 buf
= XDR_INLINE(xdrs
, RNDUP(oa
->oa_length
));
171 if (xdr_opaque(xdrs
, oa
->oa_base
,
172 oa
->oa_length
) == FALSE
) {
176 memmove(oa
->oa_base
, buf
,
179 buf += RNDUP(oa->oa_length) /
187 prm_direction
= &cmsg
->rm_direction
;
189 xdr_u_int32_t(xdrs
, &(cmsg
->rm_xid
)) &&
190 xdr_enum(xdrs
, (enum_t
*) prm_direction
) &&
191 (cmsg
->rm_direction
== CALL
) &&
192 xdr_rpcvers(xdrs
, &(cmsg
->rm_call
.cb_rpcvers
)) &&
193 (cmsg
->rm_call
.cb_rpcvers
== RPC_MSG_VERSION
) &&
194 xdr_rpcprog(xdrs
, &(cmsg
->rm_call
.cb_prog
)) &&
195 xdr_rpcvers(xdrs
, &(cmsg
->rm_call
.cb_vers
)) &&
196 xdr_rpcproc(xdrs
, &(cmsg
->rm_call
.cb_proc
)) &&
197 xdr_opaque_auth(xdrs
, &(cmsg
->rm_call
.cb_cred
)) )
198 return (xdr_opaque_auth(xdrs
, &(cmsg
->rm_call
.cb_verf
)));