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.
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.
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.
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.
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.
25 * Sun Microsystems, Inc.
27 * Mountain View, California 94043
29 * @(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro
30 * @(#)rpc_callmsg.c 2.1 88/07/29 4.0 RPCSRC
31 * $NetBSD: rpc_callmsg.c,v 1.16 2000/07/14 08:40:42 fvdl Exp $
32 * $FreeBSD: src/lib/libc/rpc/rpc_callmsg.c,v 1.13 2007/11/20 01:51:20 jb Exp $
33 * $DragonFly: src/lib/libc/rpc/rpc_callmsg.c,v 1.4 2005/11/13 12:27:04 swildner Exp $
39 * Copyright (C) 1984, Sun Microsystems, Inc.
43 #include "namespace.h"
49 #include "un-namespace.h"
55 xdr_callmsg(XDR
*xdrs
, struct rpc_msg
*cmsg
)
57 enum msg_type
*prm_direction
;
59 struct opaque_auth
*oa
;
64 if (xdrs
->x_op
== XDR_ENCODE
) {
65 if (cmsg
->rm_call
.cb_cred
.oa_length
> MAX_AUTH_BYTES
) {
68 if (cmsg
->rm_call
.cb_verf
.oa_length
> MAX_AUTH_BYTES
) {
71 buf
= XDR_INLINE(xdrs
, 8 * BYTES_PER_XDR_UNIT
72 + RNDUP(cmsg
->rm_call
.cb_cred
.oa_length
)
73 + 2 * BYTES_PER_XDR_UNIT
74 + RNDUP(cmsg
->rm_call
.cb_verf
.oa_length
));
76 IXDR_PUT_INT32(buf
, cmsg
->rm_xid
);
77 IXDR_PUT_ENUM(buf
, cmsg
->rm_direction
);
78 if (cmsg
->rm_direction
!= CALL
) {
81 IXDR_PUT_INT32(buf
, cmsg
->rm_call
.cb_rpcvers
);
82 if (cmsg
->rm_call
.cb_rpcvers
!= RPC_MSG_VERSION
) {
85 IXDR_PUT_INT32(buf
, cmsg
->rm_call
.cb_prog
);
86 IXDR_PUT_INT32(buf
, cmsg
->rm_call
.cb_vers
);
87 IXDR_PUT_INT32(buf
, cmsg
->rm_call
.cb_proc
);
88 oa
= &cmsg
->rm_call
.cb_cred
;
89 IXDR_PUT_ENUM(buf
, oa
->oa_flavor
);
90 IXDR_PUT_INT32(buf
, oa
->oa_length
);
92 memmove(buf
, oa
->oa_base
, oa
->oa_length
);
93 buf
+= RNDUP(oa
->oa_length
) / sizeof (int32_t);
95 oa
= &cmsg
->rm_call
.cb_verf
;
96 IXDR_PUT_ENUM(buf
, oa
->oa_flavor
);
97 IXDR_PUT_INT32(buf
, oa
->oa_length
);
99 memmove(buf
, oa
->oa_base
, oa
->oa_length
);
101 buf += RNDUP(oa->oa_length) / sizeof (int32_t);
107 if (xdrs
->x_op
== XDR_DECODE
) {
108 buf
= XDR_INLINE(xdrs
, 8 * BYTES_PER_XDR_UNIT
);
110 cmsg
->rm_xid
= IXDR_GET_U_INT32(buf
);
111 cmsg
->rm_direction
= IXDR_GET_ENUM(buf
, enum msg_type
);
112 if (cmsg
->rm_direction
!= CALL
) {
115 cmsg
->rm_call
.cb_rpcvers
= IXDR_GET_U_INT32(buf
);
116 if (cmsg
->rm_call
.cb_rpcvers
!= RPC_MSG_VERSION
) {
119 cmsg
->rm_call
.cb_prog
= IXDR_GET_U_INT32(buf
);
120 cmsg
->rm_call
.cb_vers
= IXDR_GET_U_INT32(buf
);
121 cmsg
->rm_call
.cb_proc
= IXDR_GET_U_INT32(buf
);
122 oa
= &cmsg
->rm_call
.cb_cred
;
123 oa
->oa_flavor
= IXDR_GET_ENUM(buf
, enum_t
);
124 oa
->oa_length
= (u_int
)IXDR_GET_U_INT32(buf
);
126 if (oa
->oa_length
> MAX_AUTH_BYTES
) {
129 if (oa
->oa_base
== NULL
) {
130 oa
->oa_base
= (caddr_t
)
131 mem_alloc(oa
->oa_length
);
132 if (oa
->oa_base
== NULL
)
135 buf
= XDR_INLINE(xdrs
, RNDUP(oa
->oa_length
));
137 if (xdr_opaque(xdrs
, oa
->oa_base
,
138 oa
->oa_length
) == FALSE
) {
142 memmove(oa
->oa_base
, buf
,
145 buf += RNDUP(oa->oa_length) /
150 oa
= &cmsg
->rm_call
.cb_verf
;
151 buf
= XDR_INLINE(xdrs
, 2 * BYTES_PER_XDR_UNIT
);
153 if (xdr_enum(xdrs
, &oa
->oa_flavor
) == FALSE
||
154 xdr_u_int(xdrs
, &oa
->oa_length
) == FALSE
) {
158 oa
->oa_flavor
= IXDR_GET_ENUM(buf
, enum_t
);
159 oa
->oa_length
= (u_int
)IXDR_GET_U_INT32(buf
);
162 if (oa
->oa_length
> MAX_AUTH_BYTES
) {
165 if (oa
->oa_base
== NULL
) {
166 oa
->oa_base
= (caddr_t
)
167 mem_alloc(oa
->oa_length
);
168 if (oa
->oa_base
== NULL
)
171 buf
= XDR_INLINE(xdrs
, RNDUP(oa
->oa_length
));
173 if (xdr_opaque(xdrs
, oa
->oa_base
,
174 oa
->oa_length
) == FALSE
) {
178 memmove(oa
->oa_base
, buf
,
181 buf += RNDUP(oa->oa_length) /
189 prm_direction
= &cmsg
->rm_direction
;
191 xdr_u_int32_t(xdrs
, &(cmsg
->rm_xid
)) &&
192 xdr_enum(xdrs
, (enum_t
*) prm_direction
) &&
193 (cmsg
->rm_direction
== CALL
) &&
194 xdr_u_int32_t(xdrs
, &(cmsg
->rm_call
.cb_rpcvers
)) &&
195 (cmsg
->rm_call
.cb_rpcvers
== RPC_MSG_VERSION
) &&
196 xdr_u_int32_t(xdrs
, &(cmsg
->rm_call
.cb_prog
)) &&
197 xdr_u_int32_t(xdrs
, &(cmsg
->rm_call
.cb_vers
)) &&
198 xdr_u_int32_t(xdrs
, &(cmsg
->rm_call
.cb_proc
)) &&
199 xdr_opaque_auth(xdrs
, &(cmsg
->rm_call
.cb_cred
)) )
200 return (xdr_opaque_auth(xdrs
, &(cmsg
->rm_call
.cb_verf
)));