174462Salfred/* $NetBSD: rpc_callmsg.c,v 1.16 2000/07/14 08:40:42 fvdl Exp $ */ 274462Salfred 3261057Smav/*- 4261057Smav * Copyright (c) 2009, Sun Microsystems, Inc. 5261057Smav * All rights reserved. 68870Srgrimes * 7261057Smav * Redistribution and use in source and binary forms, with or without 8261057Smav * modification, are permitted provided that the following conditions are met: 9261057Smav * - Redistributions of source code must retain the above copyright notice, 10261057Smav * this list of conditions and the following disclaimer. 11261057Smav * - Redistributions in binary form must reproduce the above copyright notice, 12261057Smav * this list of conditions and the following disclaimer in the documentation 13261057Smav * and/or other materials provided with the distribution. 14261057Smav * - Neither the name of Sun Microsystems, Inc. nor the names of its 15261057Smav * contributors may be used to endorse or promote products derived 16261057Smav * from this software without specific prior written permission. 17261057Smav * 18261057Smav * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19261057Smav * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20261057Smav * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21261057Smav * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22261057Smav * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23261057Smav * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24261057Smav * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25261057Smav * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26261057Smav * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27261057Smav * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28261057Smav * POSSIBILITY OF SUCH DAMAGE. 291901Swollman */ 301901Swollman 311901Swollman#if defined(LIBC_SCCS) && !defined(lint) 32136581Sobrienstatic char *sccsid2 = "@(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro"; 3374462Salfredstatic char *sccsid = "@(#)rpc_callmsg.c 2.1 88/07/29 4.0 RPCSRC"; 341901Swollman#endif 3592990Sobrien#include <sys/cdefs.h> 3692990Sobrien__FBSDID("$FreeBSD$"); 371901Swollman 381901Swollman/* 391901Swollman * rpc_callmsg.c 401901Swollman * 411901Swollman * Copyright (C) 1984, Sun Microsystems, Inc. 421901Swollman * 431901Swollman */ 441901Swollman 4574462Salfred#include "namespace.h" 4674462Salfred#include <assert.h> 4711666Sphk#include <stdlib.h> 4811666Sphk#include <string.h> 4974462Salfred 501901Swollman#include <rpc/rpc.h> 5174462Salfred#include "un-namespace.h" 521901Swollman 531901Swollman/* 541901Swollman * XDR a call message 551901Swollman */ 561901Swollmanbool_t 571901Swollmanxdr_callmsg(xdrs, cmsg) 5874462Salfred XDR *xdrs; 5974462Salfred struct rpc_msg *cmsg; 601901Swollman{ 61173763Sjb enum msg_type *prm_direction; 6274462Salfred int32_t *buf; 6374462Salfred struct opaque_auth *oa; 641901Swollman 6574462Salfred assert(xdrs != NULL); 6674462Salfred assert(cmsg != NULL); 6774462Salfred 681901Swollman if (xdrs->x_op == XDR_ENCODE) { 691901Swollman if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) { 701901Swollman return (FALSE); 711901Swollman } 721901Swollman if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) { 731901Swollman return (FALSE); 741901Swollman } 751901Swollman buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT 761901Swollman + RNDUP(cmsg->rm_call.cb_cred.oa_length) 771901Swollman + 2 * BYTES_PER_XDR_UNIT 781901Swollman + RNDUP(cmsg->rm_call.cb_verf.oa_length)); 791901Swollman if (buf != NULL) { 8074462Salfred IXDR_PUT_INT32(buf, cmsg->rm_xid); 811901Swollman IXDR_PUT_ENUM(buf, cmsg->rm_direction); 821901Swollman if (cmsg->rm_direction != CALL) { 831901Swollman return (FALSE); 841901Swollman } 8574462Salfred IXDR_PUT_INT32(buf, cmsg->rm_call.cb_rpcvers); 861901Swollman if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) { 871901Swollman return (FALSE); 881901Swollman } 8974462Salfred IXDR_PUT_INT32(buf, cmsg->rm_call.cb_prog); 9074462Salfred IXDR_PUT_INT32(buf, cmsg->rm_call.cb_vers); 9174462Salfred IXDR_PUT_INT32(buf, cmsg->rm_call.cb_proc); 921901Swollman oa = &cmsg->rm_call.cb_cred; 931901Swollman IXDR_PUT_ENUM(buf, oa->oa_flavor); 9474462Salfred IXDR_PUT_INT32(buf, oa->oa_length); 951901Swollman if (oa->oa_length) { 9674462Salfred memmove(buf, oa->oa_base, oa->oa_length); 9721082Speter buf += RNDUP(oa->oa_length) / sizeof (int32_t); 981901Swollman } 991901Swollman oa = &cmsg->rm_call.cb_verf; 1001901Swollman IXDR_PUT_ENUM(buf, oa->oa_flavor); 10174462Salfred IXDR_PUT_INT32(buf, oa->oa_length); 1021901Swollman if (oa->oa_length) { 10374462Salfred memmove(buf, oa->oa_base, oa->oa_length); 1041901Swollman /* no real need.... 10521082Speter buf += RNDUP(oa->oa_length) / sizeof (int32_t); 1061901Swollman */ 1071901Swollman } 1081901Swollman return (TRUE); 1091901Swollman } 1101901Swollman } 1111901Swollman if (xdrs->x_op == XDR_DECODE) { 1121901Swollman buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT); 1131901Swollman if (buf != NULL) { 11474462Salfred cmsg->rm_xid = IXDR_GET_U_INT32(buf); 1151901Swollman cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type); 1161901Swollman if (cmsg->rm_direction != CALL) { 1171901Swollman return (FALSE); 1181901Swollman } 11974462Salfred cmsg->rm_call.cb_rpcvers = IXDR_GET_U_INT32(buf); 1201901Swollman if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) { 1211901Swollman return (FALSE); 1221901Swollman } 12374462Salfred cmsg->rm_call.cb_prog = IXDR_GET_U_INT32(buf); 12474462Salfred cmsg->rm_call.cb_vers = IXDR_GET_U_INT32(buf); 12574462Salfred cmsg->rm_call.cb_proc = IXDR_GET_U_INT32(buf); 1261901Swollman oa = &cmsg->rm_call.cb_cred; 1271901Swollman oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t); 12874462Salfred oa->oa_length = (u_int)IXDR_GET_U_INT32(buf); 1291901Swollman if (oa->oa_length) { 1301901Swollman if (oa->oa_length > MAX_AUTH_BYTES) { 1311901Swollman return (FALSE); 1321901Swollman } 1331901Swollman if (oa->oa_base == NULL) { 1341901Swollman oa->oa_base = (caddr_t) 13574462Salfred mem_alloc(oa->oa_length); 13674462Salfred if (oa->oa_base == NULL) 13774462Salfred return (FALSE); 1381901Swollman } 1391901Swollman buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length)); 1401901Swollman if (buf == NULL) { 1411901Swollman if (xdr_opaque(xdrs, oa->oa_base, 1421901Swollman oa->oa_length) == FALSE) { 1431901Swollman return (FALSE); 1441901Swollman } 1451901Swollman } else { 14674462Salfred memmove(oa->oa_base, buf, 1471901Swollman oa->oa_length); 1481901Swollman /* no real need.... 1491901Swollman buf += RNDUP(oa->oa_length) / 15021082Speter sizeof (int32_t); 1511901Swollman */ 1521901Swollman } 1531901Swollman } 1541901Swollman oa = &cmsg->rm_call.cb_verf; 1551901Swollman buf = XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT); 1561901Swollman if (buf == NULL) { 1571901Swollman if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE || 1581901Swollman xdr_u_int(xdrs, &oa->oa_length) == FALSE) { 1591901Swollman return (FALSE); 1601901Swollman } 1611901Swollman } else { 1621901Swollman oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t); 16374462Salfred oa->oa_length = (u_int)IXDR_GET_U_INT32(buf); 1641901Swollman } 1651901Swollman if (oa->oa_length) { 1661901Swollman if (oa->oa_length > MAX_AUTH_BYTES) { 1671901Swollman return (FALSE); 1681901Swollman } 1691901Swollman if (oa->oa_base == NULL) { 1701901Swollman oa->oa_base = (caddr_t) 17174462Salfred mem_alloc(oa->oa_length); 17274462Salfred if (oa->oa_base == NULL) 17374462Salfred return (FALSE); 1741901Swollman } 1751901Swollman buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length)); 1761901Swollman if (buf == NULL) { 1771901Swollman if (xdr_opaque(xdrs, oa->oa_base, 1781901Swollman oa->oa_length) == FALSE) { 1791901Swollman return (FALSE); 1801901Swollman } 1811901Swollman } else { 18274462Salfred memmove(oa->oa_base, buf, 1831901Swollman oa->oa_length); 1841901Swollman /* no real need... 1851901Swollman buf += RNDUP(oa->oa_length) / 18621082Speter sizeof (int32_t); 1871901Swollman */ 1881901Swollman } 1891901Swollman } 1901901Swollman return (TRUE); 1911901Swollman } 1921901Swollman } 193173763Sjb prm_direction = &cmsg->rm_direction; 1941901Swollman if ( 19521082Speter xdr_u_int32_t(xdrs, &(cmsg->rm_xid)) && 196173763Sjb xdr_enum(xdrs, (enum_t *) prm_direction) && 1971901Swollman (cmsg->rm_direction == CALL) && 19821082Speter xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) && 1991901Swollman (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) && 20021082Speter xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_prog)) && 20121082Speter xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers)) && 20221082Speter xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_proc)) && 2031901Swollman xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred)) ) 20474462Salfred return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf))); 2051901Swollman return (FALSE); 2061901Swollman} 207