1 /* @(#)rpc_callmsg.c 2.1 88/07/29 4.0 RPCSRC */
3 * Copyright (c) 2010, Oracle America, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
18 * * Neither the name of the "Oracle America, Inc." nor the names of
19 * its contributors may be used to endorse or promote products
20 * derived from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
23 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
28 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #if !defined(lint) && defined(SCCSIDS)
35 static char sccsid[] = "@(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro";
42 #include <sys/param.h>
44 #include <gssrpc/rpc.h>
50 xdr_callmsg(register XDR *xdrs, register struct rpc_msg *cmsg)
52 register rpc_inline_t *buf;
53 register struct opaque_auth *oa;
55 if (xdrs->x_op == XDR_ENCODE) {
56 if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) {
59 if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) {
62 buf = (rpc_inline_t *) XDR_INLINE(xdrs, (int) (
63 8 * BYTES_PER_XDR_UNIT
64 + RNDUP(cmsg->rm_call.cb_cred.oa_length)
65 + 2 * BYTES_PER_XDR_UNIT
66 + RNDUP(cmsg->rm_call.cb_verf.oa_length)));
68 IXDR_PUT_LONG(buf, cmsg->rm_xid);
69 IXDR_PUT_ENUM(buf, cmsg->rm_direction);
70 if (cmsg->rm_direction != CALL) {
73 IXDR_PUT_LONG(buf, cmsg->rm_call.cb_rpcvers);
74 if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
77 IXDR_PUT_LONG(buf, cmsg->rm_call.cb_prog);
78 IXDR_PUT_LONG(buf, cmsg->rm_call.cb_vers);
79 IXDR_PUT_LONG(buf, cmsg->rm_call.cb_proc);
80 oa = &cmsg->rm_call.cb_cred;
81 IXDR_PUT_ENUM(buf, oa->oa_flavor);
82 IXDR_PUT_LONG(buf, oa->oa_length);
84 memmove((caddr_t)buf, oa->oa_base,
86 buf += RNDUP(oa->oa_length) / BYTES_PER_XDR_UNIT;
88 oa = &cmsg->rm_call.cb_verf;
89 IXDR_PUT_ENUM(buf, oa->oa_flavor);
90 IXDR_PUT_LONG(buf, oa->oa_length);
92 memmove((caddr_t)buf, oa->oa_base,
95 buf += RNDUP(oa->oa_length) / BYTES_PER_XDR_UNIT;
101 if (xdrs->x_op == XDR_DECODE) {
102 buf = (rpc_inline_t *) XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT);
104 cmsg->rm_xid = IXDR_GET_LONG(buf);
105 cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type);
106 if (cmsg->rm_direction != CALL) {
109 cmsg->rm_call.cb_rpcvers = IXDR_GET_LONG(buf);
110 if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
113 cmsg->rm_call.cb_prog = IXDR_GET_LONG(buf);
114 cmsg->rm_call.cb_vers = IXDR_GET_LONG(buf);
115 cmsg->rm_call.cb_proc = IXDR_GET_LONG(buf);
116 oa = &cmsg->rm_call.cb_cred;
117 oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
118 oa->oa_length = IXDR_GET_LONG(buf);
120 if (oa->oa_length > MAX_AUTH_BYTES) {
123 if (oa->oa_base == NULL) {
124 oa->oa_base = (caddr_t)
125 mem_alloc(oa->oa_length);
127 buf = (rpc_inline_t *)
128 XDR_INLINE(xdrs, (int)RNDUP(oa->oa_length));
130 if (xdr_opaque(xdrs, oa->oa_base,
131 oa->oa_length) == FALSE) {
135 memmove(oa->oa_base, (caddr_t)buf,
138 buf += RNDUP(oa->oa_length) /
143 oa = &cmsg->rm_call.cb_verf;
144 buf = (rpc_inline_t *)
145 XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT);
147 if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE ||
148 xdr_u_int(xdrs, &oa->oa_length) == FALSE) {
152 oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
153 oa->oa_length = IXDR_GET_LONG(buf);
156 if (oa->oa_length > MAX_AUTH_BYTES) {
159 if (oa->oa_base == NULL) {
160 oa->oa_base = (caddr_t)
161 mem_alloc(oa->oa_length);
163 buf = (rpc_inline_t *)
164 XDR_INLINE(xdrs, (int)RNDUP(oa->oa_length));
166 if (xdr_opaque(xdrs, oa->oa_base,
167 oa->oa_length) == FALSE) {
171 memmove(oa->oa_base, (caddr_t) buf,
174 buf += RNDUP(oa->oa_length) /
183 xdr_u_int32(xdrs, &(cmsg->rm_xid)) &&
184 xdr_enum(xdrs, (enum_t *)&(cmsg->rm_direction)) &&
185 (cmsg->rm_direction == CALL) &&
186 xdr_u_int32(xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
187 (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) &&
188 xdr_u_int32(xdrs, &(cmsg->rm_call.cb_prog)) &&
189 xdr_u_int32(xdrs, &(cmsg->rm_call.cb_vers)) &&
190 xdr_u_int32(xdrs, &(cmsg->rm_call.cb_proc)) &&
191 xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred)) )
192 return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf)));