18360efbdSAlfred Perlstein /* $NetBSD: rpc_callmsg.c,v 1.16 2000/07/14 08:40:42 fvdl Exp $ */ 28360efbdSAlfred Perlstein 32e322d37SHiroki Sato /*- 42e322d37SHiroki Sato * Copyright (c) 2009, Sun Microsystems, Inc. 52e322d37SHiroki Sato * All rights reserved. 699064799SGarrett Wollman * 72e322d37SHiroki Sato * Redistribution and use in source and binary forms, with or without 82e322d37SHiroki Sato * modification, are permitted provided that the following conditions are met: 92e322d37SHiroki Sato * - Redistributions of source code must retain the above copyright notice, 102e322d37SHiroki Sato * this list of conditions and the following disclaimer. 112e322d37SHiroki Sato * - Redistributions in binary form must reproduce the above copyright notice, 122e322d37SHiroki Sato * this list of conditions and the following disclaimer in the documentation 132e322d37SHiroki Sato * and/or other materials provided with the distribution. 142e322d37SHiroki Sato * - Neither the name of Sun Microsystems, Inc. nor the names of its 152e322d37SHiroki Sato * contributors may be used to endorse or promote products derived 162e322d37SHiroki Sato * from this software without specific prior written permission. 1799064799SGarrett Wollman * 182e322d37SHiroki Sato * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 192e322d37SHiroki Sato * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 202e322d37SHiroki Sato * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 212e322d37SHiroki Sato * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 222e322d37SHiroki Sato * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 232e322d37SHiroki Sato * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 242e322d37SHiroki Sato * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 252e322d37SHiroki Sato * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 262e322d37SHiroki Sato * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 272e322d37SHiroki Sato * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 282e322d37SHiroki Sato * POSSIBILITY OF SUCH DAMAGE. 2999064799SGarrett Wollman */ 3099064799SGarrett Wollman 3199064799SGarrett Wollman #if defined(LIBC_SCCS) && !defined(lint) 32a986ef57SDavid E. O'Brien static char *sccsid2 = "@(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro"; 338360efbdSAlfred Perlstein static char *sccsid = "@(#)rpc_callmsg.c 2.1 88/07/29 4.0 RPCSRC"; 3499064799SGarrett Wollman #endif 35d3d20c82SDavid E. O'Brien #include <sys/cdefs.h> 36d3d20c82SDavid E. O'Brien __FBSDID("$FreeBSD$"); 3799064799SGarrett Wollman 3899064799SGarrett Wollman /* 3999064799SGarrett Wollman * rpc_callmsg.c 4099064799SGarrett Wollman * 4199064799SGarrett Wollman * Copyright (C) 1984, Sun Microsystems, Inc. 4299064799SGarrett Wollman * 4399064799SGarrett Wollman */ 4499064799SGarrett Wollman 458360efbdSAlfred Perlstein #include "namespace.h" 468360efbdSAlfred Perlstein #include <assert.h> 474c3af266SPoul-Henning Kamp #include <stdlib.h> 484c3af266SPoul-Henning Kamp #include <string.h> 498360efbdSAlfred Perlstein 5099064799SGarrett Wollman #include <rpc/rpc.h> 518360efbdSAlfred Perlstein #include "un-namespace.h" 5299064799SGarrett Wollman 5399064799SGarrett Wollman /* 5499064799SGarrett Wollman * XDR a call message 5599064799SGarrett Wollman */ 5699064799SGarrett Wollman bool_t 57*587cf682SCraig Rodrigues xdr_callmsg(XDR *xdrs, struct rpc_msg *cmsg) 5899064799SGarrett Wollman { 59102c7c92SJohn Birrell enum msg_type *prm_direction; 608360efbdSAlfred Perlstein int32_t *buf; 618360efbdSAlfred Perlstein struct opaque_auth *oa; 628360efbdSAlfred Perlstein 638360efbdSAlfred Perlstein assert(xdrs != NULL); 648360efbdSAlfred Perlstein assert(cmsg != NULL); 6599064799SGarrett Wollman 6699064799SGarrett Wollman if (xdrs->x_op == XDR_ENCODE) { 6799064799SGarrett Wollman if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) { 6899064799SGarrett Wollman return (FALSE); 6999064799SGarrett Wollman } 7099064799SGarrett Wollman if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) { 7199064799SGarrett Wollman return (FALSE); 7299064799SGarrett Wollman } 7399064799SGarrett Wollman buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT 7499064799SGarrett Wollman + RNDUP(cmsg->rm_call.cb_cred.oa_length) 7599064799SGarrett Wollman + 2 * BYTES_PER_XDR_UNIT 7699064799SGarrett Wollman + RNDUP(cmsg->rm_call.cb_verf.oa_length)); 7799064799SGarrett Wollman if (buf != NULL) { 788360efbdSAlfred Perlstein IXDR_PUT_INT32(buf, cmsg->rm_xid); 7999064799SGarrett Wollman IXDR_PUT_ENUM(buf, cmsg->rm_direction); 8099064799SGarrett Wollman if (cmsg->rm_direction != CALL) { 8199064799SGarrett Wollman return (FALSE); 8299064799SGarrett Wollman } 838360efbdSAlfred Perlstein IXDR_PUT_INT32(buf, cmsg->rm_call.cb_rpcvers); 8499064799SGarrett Wollman if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) { 8599064799SGarrett Wollman return (FALSE); 8699064799SGarrett Wollman } 878360efbdSAlfred Perlstein IXDR_PUT_INT32(buf, cmsg->rm_call.cb_prog); 888360efbdSAlfred Perlstein IXDR_PUT_INT32(buf, cmsg->rm_call.cb_vers); 898360efbdSAlfred Perlstein IXDR_PUT_INT32(buf, cmsg->rm_call.cb_proc); 9099064799SGarrett Wollman oa = &cmsg->rm_call.cb_cred; 9199064799SGarrett Wollman IXDR_PUT_ENUM(buf, oa->oa_flavor); 928360efbdSAlfred Perlstein IXDR_PUT_INT32(buf, oa->oa_length); 9399064799SGarrett Wollman if (oa->oa_length) { 948360efbdSAlfred Perlstein memmove(buf, oa->oa_base, oa->oa_length); 95ec3ca1a2SPeter Wemm buf += RNDUP(oa->oa_length) / sizeof (int32_t); 9699064799SGarrett Wollman } 9799064799SGarrett Wollman oa = &cmsg->rm_call.cb_verf; 9899064799SGarrett Wollman IXDR_PUT_ENUM(buf, oa->oa_flavor); 998360efbdSAlfred Perlstein IXDR_PUT_INT32(buf, oa->oa_length); 10099064799SGarrett Wollman if (oa->oa_length) { 1018360efbdSAlfred Perlstein memmove(buf, oa->oa_base, oa->oa_length); 10299064799SGarrett Wollman /* no real need.... 103ec3ca1a2SPeter Wemm buf += RNDUP(oa->oa_length) / sizeof (int32_t); 10499064799SGarrett Wollman */ 10599064799SGarrett Wollman } 10699064799SGarrett Wollman return (TRUE); 10799064799SGarrett Wollman } 10899064799SGarrett Wollman } 10999064799SGarrett Wollman if (xdrs->x_op == XDR_DECODE) { 11099064799SGarrett Wollman buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT); 11199064799SGarrett Wollman if (buf != NULL) { 1128360efbdSAlfred Perlstein cmsg->rm_xid = IXDR_GET_U_INT32(buf); 11399064799SGarrett Wollman cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type); 11499064799SGarrett Wollman if (cmsg->rm_direction != CALL) { 11599064799SGarrett Wollman return (FALSE); 11699064799SGarrett Wollman } 1178360efbdSAlfred Perlstein cmsg->rm_call.cb_rpcvers = IXDR_GET_U_INT32(buf); 11899064799SGarrett Wollman if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) { 11999064799SGarrett Wollman return (FALSE); 12099064799SGarrett Wollman } 1218360efbdSAlfred Perlstein cmsg->rm_call.cb_prog = IXDR_GET_U_INT32(buf); 1228360efbdSAlfred Perlstein cmsg->rm_call.cb_vers = IXDR_GET_U_INT32(buf); 1238360efbdSAlfred Perlstein cmsg->rm_call.cb_proc = IXDR_GET_U_INT32(buf); 12499064799SGarrett Wollman oa = &cmsg->rm_call.cb_cred; 12599064799SGarrett Wollman oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t); 1268360efbdSAlfred Perlstein oa->oa_length = (u_int)IXDR_GET_U_INT32(buf); 12799064799SGarrett Wollman if (oa->oa_length) { 12899064799SGarrett Wollman if (oa->oa_length > MAX_AUTH_BYTES) { 12999064799SGarrett Wollman return (FALSE); 13099064799SGarrett Wollman } 13199064799SGarrett Wollman if (oa->oa_base == NULL) { 13299064799SGarrett Wollman oa->oa_base = (caddr_t) 13399064799SGarrett Wollman mem_alloc(oa->oa_length); 1348360efbdSAlfred Perlstein if (oa->oa_base == NULL) 1358360efbdSAlfred Perlstein return (FALSE); 13699064799SGarrett Wollman } 13799064799SGarrett Wollman buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length)); 13899064799SGarrett Wollman if (buf == NULL) { 13999064799SGarrett Wollman if (xdr_opaque(xdrs, oa->oa_base, 14099064799SGarrett Wollman oa->oa_length) == FALSE) { 14199064799SGarrett Wollman return (FALSE); 14299064799SGarrett Wollman } 14399064799SGarrett Wollman } else { 1448360efbdSAlfred Perlstein memmove(oa->oa_base, buf, 14599064799SGarrett Wollman oa->oa_length); 14699064799SGarrett Wollman /* no real need.... 14799064799SGarrett Wollman buf += RNDUP(oa->oa_length) / 148ec3ca1a2SPeter Wemm sizeof (int32_t); 14999064799SGarrett Wollman */ 15099064799SGarrett Wollman } 15199064799SGarrett Wollman } 15299064799SGarrett Wollman oa = &cmsg->rm_call.cb_verf; 15399064799SGarrett Wollman buf = XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT); 15499064799SGarrett Wollman if (buf == NULL) { 15599064799SGarrett Wollman if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE || 15699064799SGarrett Wollman xdr_u_int(xdrs, &oa->oa_length) == FALSE) { 15799064799SGarrett Wollman return (FALSE); 15899064799SGarrett Wollman } 15999064799SGarrett Wollman } else { 16099064799SGarrett Wollman oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t); 1618360efbdSAlfred Perlstein oa->oa_length = (u_int)IXDR_GET_U_INT32(buf); 16299064799SGarrett Wollman } 16399064799SGarrett Wollman if (oa->oa_length) { 16499064799SGarrett Wollman if (oa->oa_length > MAX_AUTH_BYTES) { 16599064799SGarrett Wollman return (FALSE); 16699064799SGarrett Wollman } 16799064799SGarrett Wollman if (oa->oa_base == NULL) { 16899064799SGarrett Wollman oa->oa_base = (caddr_t) 16999064799SGarrett Wollman mem_alloc(oa->oa_length); 1708360efbdSAlfred Perlstein if (oa->oa_base == NULL) 1718360efbdSAlfred Perlstein return (FALSE); 17299064799SGarrett Wollman } 17399064799SGarrett Wollman buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length)); 17499064799SGarrett Wollman if (buf == NULL) { 17599064799SGarrett Wollman if (xdr_opaque(xdrs, oa->oa_base, 17699064799SGarrett Wollman oa->oa_length) == FALSE) { 17799064799SGarrett Wollman return (FALSE); 17899064799SGarrett Wollman } 17999064799SGarrett Wollman } else { 1808360efbdSAlfred Perlstein memmove(oa->oa_base, buf, 18199064799SGarrett Wollman oa->oa_length); 18299064799SGarrett Wollman /* no real need... 18399064799SGarrett Wollman buf += RNDUP(oa->oa_length) / 184ec3ca1a2SPeter Wemm sizeof (int32_t); 18599064799SGarrett Wollman */ 18699064799SGarrett Wollman } 18799064799SGarrett Wollman } 18899064799SGarrett Wollman return (TRUE); 18999064799SGarrett Wollman } 19099064799SGarrett Wollman } 191102c7c92SJohn Birrell prm_direction = &cmsg->rm_direction; 19299064799SGarrett Wollman if ( 193ec3ca1a2SPeter Wemm xdr_u_int32_t(xdrs, &(cmsg->rm_xid)) && 194102c7c92SJohn Birrell xdr_enum(xdrs, (enum_t *) prm_direction) && 19599064799SGarrett Wollman (cmsg->rm_direction == CALL) && 196ec3ca1a2SPeter Wemm xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) && 19799064799SGarrett Wollman (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) && 198ec3ca1a2SPeter Wemm xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_prog)) && 199ec3ca1a2SPeter Wemm xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers)) && 200ec3ca1a2SPeter Wemm xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_proc)) && 20199064799SGarrett Wollman xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred)) ) 20299064799SGarrett Wollman return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf))); 20399064799SGarrett Wollman return (FALSE); 20499064799SGarrett Wollman } 205