18360efbdSAlfred Perlstein /* $NetBSD: rpc_callmsg.c,v 1.16 2000/07/14 08:40:42 fvdl Exp $ */ 28360efbdSAlfred Perlstein 399064799SGarrett Wollman /* 499064799SGarrett Wollman * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 599064799SGarrett Wollman * unrestricted use provided that this legend is included on all tape 699064799SGarrett Wollman * media and as a part of the software program in whole or part. Users 799064799SGarrett Wollman * may copy or modify Sun RPC without charge, but are not authorized 899064799SGarrett Wollman * to license or distribute it to anyone else except as part of a product or 999064799SGarrett Wollman * program developed by the user. 1099064799SGarrett Wollman * 1199064799SGarrett Wollman * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 1299064799SGarrett Wollman * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 1399064799SGarrett Wollman * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 1499064799SGarrett Wollman * 1599064799SGarrett Wollman * Sun RPC is provided with no support and without any obligation on the 1699064799SGarrett Wollman * part of Sun Microsystems, Inc. to assist in its use, correction, 1799064799SGarrett Wollman * modification or enhancement. 1899064799SGarrett Wollman * 1999064799SGarrett Wollman * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 2099064799SGarrett Wollman * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 2199064799SGarrett Wollman * OR ANY PART THEREOF. 2299064799SGarrett Wollman * 2399064799SGarrett Wollman * In no event will Sun Microsystems, Inc. be liable for any lost revenue 2499064799SGarrett Wollman * or profits or other special, indirect and consequential damages, even if 2599064799SGarrett Wollman * Sun has been advised of the possibility of such damages. 2699064799SGarrett Wollman * 2799064799SGarrett Wollman * Sun Microsystems, Inc. 2899064799SGarrett Wollman * 2550 Garcia Avenue 2999064799SGarrett Wollman * Mountain View, California 94043 3099064799SGarrett Wollman */ 3199064799SGarrett Wollman 328360efbdSAlfred Perlstein #include <sys/cdefs.h> 3399064799SGarrett Wollman #if defined(LIBC_SCCS) && !defined(lint) 348360efbdSAlfred Perlstein static char *sccsid = "@(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro"; 358360efbdSAlfred Perlstein static char *sccsid = "@(#)rpc_callmsg.c 2.1 88/07/29 4.0 RPCSRC"; 367f3dea24SPeter Wemm static char *rcsid = "$FreeBSD$"; 3799064799SGarrett Wollman #endif 3899064799SGarrett Wollman 3999064799SGarrett Wollman /* 4099064799SGarrett Wollman * rpc_callmsg.c 4199064799SGarrett Wollman * 4299064799SGarrett Wollman * Copyright (C) 1984, Sun Microsystems, Inc. 4399064799SGarrett Wollman * 4499064799SGarrett Wollman */ 4599064799SGarrett Wollman 468360efbdSAlfred Perlstein #include "namespace.h" 478360efbdSAlfred Perlstein #include <assert.h> 484c3af266SPoul-Henning Kamp #include <stdlib.h> 494c3af266SPoul-Henning Kamp #include <string.h> 508360efbdSAlfred Perlstein 5199064799SGarrett Wollman #include <rpc/rpc.h> 528360efbdSAlfred Perlstein #include "un-namespace.h" 5399064799SGarrett Wollman 5499064799SGarrett Wollman /* 5599064799SGarrett Wollman * XDR a call message 5699064799SGarrett Wollman */ 5799064799SGarrett Wollman bool_t 5899064799SGarrett Wollman xdr_callmsg(xdrs, cmsg) 598360efbdSAlfred Perlstein XDR *xdrs; 608360efbdSAlfred Perlstein struct rpc_msg *cmsg; 6199064799SGarrett Wollman { 628360efbdSAlfred Perlstein int32_t *buf; 638360efbdSAlfred Perlstein struct opaque_auth *oa; 648360efbdSAlfred Perlstein 658360efbdSAlfred Perlstein assert(xdrs != NULL); 668360efbdSAlfred Perlstein assert(cmsg != NULL); 6799064799SGarrett Wollman 6899064799SGarrett Wollman if (xdrs->x_op == XDR_ENCODE) { 6999064799SGarrett Wollman if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) { 7099064799SGarrett Wollman return (FALSE); 7199064799SGarrett Wollman } 7299064799SGarrett Wollman if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) { 7399064799SGarrett Wollman return (FALSE); 7499064799SGarrett Wollman } 7599064799SGarrett Wollman buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT 7699064799SGarrett Wollman + RNDUP(cmsg->rm_call.cb_cred.oa_length) 7799064799SGarrett Wollman + 2 * BYTES_PER_XDR_UNIT 7899064799SGarrett Wollman + RNDUP(cmsg->rm_call.cb_verf.oa_length)); 7999064799SGarrett Wollman if (buf != NULL) { 808360efbdSAlfred Perlstein IXDR_PUT_INT32(buf, cmsg->rm_xid); 8199064799SGarrett Wollman IXDR_PUT_ENUM(buf, cmsg->rm_direction); 8299064799SGarrett Wollman if (cmsg->rm_direction != CALL) { 8399064799SGarrett Wollman return (FALSE); 8499064799SGarrett Wollman } 858360efbdSAlfred Perlstein IXDR_PUT_INT32(buf, cmsg->rm_call.cb_rpcvers); 8699064799SGarrett Wollman if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) { 8799064799SGarrett Wollman return (FALSE); 8899064799SGarrett Wollman } 898360efbdSAlfred Perlstein IXDR_PUT_INT32(buf, cmsg->rm_call.cb_prog); 908360efbdSAlfred Perlstein IXDR_PUT_INT32(buf, cmsg->rm_call.cb_vers); 918360efbdSAlfred Perlstein IXDR_PUT_INT32(buf, cmsg->rm_call.cb_proc); 9299064799SGarrett Wollman oa = &cmsg->rm_call.cb_cred; 9399064799SGarrett Wollman IXDR_PUT_ENUM(buf, oa->oa_flavor); 948360efbdSAlfred Perlstein IXDR_PUT_INT32(buf, oa->oa_length); 9599064799SGarrett Wollman if (oa->oa_length) { 968360efbdSAlfred Perlstein memmove(buf, oa->oa_base, oa->oa_length); 97ec3ca1a2SPeter Wemm buf += RNDUP(oa->oa_length) / sizeof (int32_t); 9899064799SGarrett Wollman } 9999064799SGarrett Wollman oa = &cmsg->rm_call.cb_verf; 10099064799SGarrett Wollman IXDR_PUT_ENUM(buf, oa->oa_flavor); 1018360efbdSAlfred Perlstein IXDR_PUT_INT32(buf, oa->oa_length); 10299064799SGarrett Wollman if (oa->oa_length) { 1038360efbdSAlfred Perlstein memmove(buf, oa->oa_base, oa->oa_length); 10499064799SGarrett Wollman /* no real need.... 105ec3ca1a2SPeter Wemm buf += RNDUP(oa->oa_length) / sizeof (int32_t); 10699064799SGarrett Wollman */ 10799064799SGarrett Wollman } 10899064799SGarrett Wollman return (TRUE); 10999064799SGarrett Wollman } 11099064799SGarrett Wollman } 11199064799SGarrett Wollman if (xdrs->x_op == XDR_DECODE) { 11299064799SGarrett Wollman buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT); 11399064799SGarrett Wollman if (buf != NULL) { 1148360efbdSAlfred Perlstein cmsg->rm_xid = IXDR_GET_U_INT32(buf); 11599064799SGarrett Wollman cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type); 11699064799SGarrett Wollman if (cmsg->rm_direction != CALL) { 11799064799SGarrett Wollman return (FALSE); 11899064799SGarrett Wollman } 1198360efbdSAlfred Perlstein cmsg->rm_call.cb_rpcvers = IXDR_GET_U_INT32(buf); 12099064799SGarrett Wollman if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) { 12199064799SGarrett Wollman return (FALSE); 12299064799SGarrett Wollman } 1238360efbdSAlfred Perlstein cmsg->rm_call.cb_prog = IXDR_GET_U_INT32(buf); 1248360efbdSAlfred Perlstein cmsg->rm_call.cb_vers = IXDR_GET_U_INT32(buf); 1258360efbdSAlfred Perlstein cmsg->rm_call.cb_proc = IXDR_GET_U_INT32(buf); 12699064799SGarrett Wollman oa = &cmsg->rm_call.cb_cred; 12799064799SGarrett Wollman oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t); 1288360efbdSAlfred Perlstein oa->oa_length = (u_int)IXDR_GET_U_INT32(buf); 12999064799SGarrett Wollman if (oa->oa_length) { 13099064799SGarrett Wollman if (oa->oa_length > MAX_AUTH_BYTES) { 13199064799SGarrett Wollman return (FALSE); 13299064799SGarrett Wollman } 13399064799SGarrett Wollman if (oa->oa_base == NULL) { 13499064799SGarrett Wollman oa->oa_base = (caddr_t) 13599064799SGarrett Wollman mem_alloc(oa->oa_length); 1368360efbdSAlfred Perlstein if (oa->oa_base == NULL) 1378360efbdSAlfred Perlstein return (FALSE); 13899064799SGarrett Wollman } 13999064799SGarrett Wollman buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length)); 14099064799SGarrett Wollman if (buf == NULL) { 14199064799SGarrett Wollman if (xdr_opaque(xdrs, oa->oa_base, 14299064799SGarrett Wollman oa->oa_length) == FALSE) { 14399064799SGarrett Wollman return (FALSE); 14499064799SGarrett Wollman } 14599064799SGarrett Wollman } else { 1468360efbdSAlfred Perlstein memmove(oa->oa_base, buf, 14799064799SGarrett Wollman oa->oa_length); 14899064799SGarrett Wollman /* no real need.... 14999064799SGarrett Wollman buf += RNDUP(oa->oa_length) / 150ec3ca1a2SPeter Wemm sizeof (int32_t); 15199064799SGarrett Wollman */ 15299064799SGarrett Wollman } 15399064799SGarrett Wollman } 15499064799SGarrett Wollman oa = &cmsg->rm_call.cb_verf; 15599064799SGarrett Wollman buf = XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT); 15699064799SGarrett Wollman if (buf == NULL) { 15799064799SGarrett Wollman if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE || 15899064799SGarrett Wollman xdr_u_int(xdrs, &oa->oa_length) == FALSE) { 15999064799SGarrett Wollman return (FALSE); 16099064799SGarrett Wollman } 16199064799SGarrett Wollman } else { 16299064799SGarrett Wollman oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t); 1638360efbdSAlfred Perlstein oa->oa_length = (u_int)IXDR_GET_U_INT32(buf); 16499064799SGarrett Wollman } 16599064799SGarrett Wollman if (oa->oa_length) { 16699064799SGarrett Wollman if (oa->oa_length > MAX_AUTH_BYTES) { 16799064799SGarrett Wollman return (FALSE); 16899064799SGarrett Wollman } 16999064799SGarrett Wollman if (oa->oa_base == NULL) { 17099064799SGarrett Wollman oa->oa_base = (caddr_t) 17199064799SGarrett Wollman mem_alloc(oa->oa_length); 1728360efbdSAlfred Perlstein if (oa->oa_base == NULL) 1738360efbdSAlfred Perlstein return (FALSE); 17499064799SGarrett Wollman } 17599064799SGarrett Wollman buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length)); 17699064799SGarrett Wollman if (buf == NULL) { 17799064799SGarrett Wollman if (xdr_opaque(xdrs, oa->oa_base, 17899064799SGarrett Wollman oa->oa_length) == FALSE) { 17999064799SGarrett Wollman return (FALSE); 18099064799SGarrett Wollman } 18199064799SGarrett Wollman } else { 1828360efbdSAlfred Perlstein memmove(oa->oa_base, buf, 18399064799SGarrett Wollman oa->oa_length); 18499064799SGarrett Wollman /* no real need... 18599064799SGarrett Wollman buf += RNDUP(oa->oa_length) / 186ec3ca1a2SPeter Wemm sizeof (int32_t); 18799064799SGarrett Wollman */ 18899064799SGarrett Wollman } 18999064799SGarrett Wollman } 19099064799SGarrett Wollman return (TRUE); 19199064799SGarrett Wollman } 19299064799SGarrett Wollman } 19399064799SGarrett Wollman if ( 194ec3ca1a2SPeter Wemm xdr_u_int32_t(xdrs, &(cmsg->rm_xid)) && 19599064799SGarrett Wollman xdr_enum(xdrs, (enum_t *)&(cmsg->rm_direction)) && 19699064799SGarrett Wollman (cmsg->rm_direction == CALL) && 197ec3ca1a2SPeter Wemm xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) && 19899064799SGarrett Wollman (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) && 199ec3ca1a2SPeter Wemm xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_prog)) && 200ec3ca1a2SPeter Wemm xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers)) && 201ec3ca1a2SPeter Wemm xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_proc)) && 20299064799SGarrett Wollman xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred)) ) 20399064799SGarrett Wollman return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf))); 20499064799SGarrett Wollman return (FALSE); 20599064799SGarrett Wollman } 206