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 3299064799SGarrett Wollman #if defined(LIBC_SCCS) && !defined(lint) 33a986ef57SDavid E. O'Brien static char *sccsid2 = "@(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro"; 348360efbdSAlfred Perlstein static char *sccsid = "@(#)rpc_callmsg.c 2.1 88/07/29 4.0 RPCSRC"; 3599064799SGarrett Wollman #endif 36d3d20c82SDavid E. O'Brien #include <sys/cdefs.h> 37d3d20c82SDavid E. O'Brien __FBSDID("$FreeBSD$"); 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 { 62102c7c92SJohn Birrell enum msg_type *prm_direction; 638360efbdSAlfred Perlstein int32_t *buf; 648360efbdSAlfred Perlstein struct opaque_auth *oa; 658360efbdSAlfred Perlstein 668360efbdSAlfred Perlstein assert(xdrs != NULL); 678360efbdSAlfred Perlstein assert(cmsg != NULL); 6899064799SGarrett Wollman 6999064799SGarrett Wollman if (xdrs->x_op == XDR_ENCODE) { 7099064799SGarrett Wollman if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) { 7199064799SGarrett Wollman return (FALSE); 7299064799SGarrett Wollman } 7399064799SGarrett Wollman if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) { 7499064799SGarrett Wollman return (FALSE); 7599064799SGarrett Wollman } 7699064799SGarrett Wollman buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT 7799064799SGarrett Wollman + RNDUP(cmsg->rm_call.cb_cred.oa_length) 7899064799SGarrett Wollman + 2 * BYTES_PER_XDR_UNIT 7999064799SGarrett Wollman + RNDUP(cmsg->rm_call.cb_verf.oa_length)); 8099064799SGarrett Wollman if (buf != NULL) { 818360efbdSAlfred Perlstein IXDR_PUT_INT32(buf, cmsg->rm_xid); 8299064799SGarrett Wollman IXDR_PUT_ENUM(buf, cmsg->rm_direction); 8399064799SGarrett Wollman if (cmsg->rm_direction != CALL) { 8499064799SGarrett Wollman return (FALSE); 8599064799SGarrett Wollman } 868360efbdSAlfred Perlstein IXDR_PUT_INT32(buf, cmsg->rm_call.cb_rpcvers); 8799064799SGarrett Wollman if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) { 8899064799SGarrett Wollman return (FALSE); 8999064799SGarrett Wollman } 908360efbdSAlfred Perlstein IXDR_PUT_INT32(buf, cmsg->rm_call.cb_prog); 918360efbdSAlfred Perlstein IXDR_PUT_INT32(buf, cmsg->rm_call.cb_vers); 928360efbdSAlfred Perlstein IXDR_PUT_INT32(buf, cmsg->rm_call.cb_proc); 9399064799SGarrett Wollman oa = &cmsg->rm_call.cb_cred; 9499064799SGarrett Wollman IXDR_PUT_ENUM(buf, oa->oa_flavor); 958360efbdSAlfred Perlstein IXDR_PUT_INT32(buf, oa->oa_length); 9699064799SGarrett Wollman if (oa->oa_length) { 978360efbdSAlfred Perlstein memmove(buf, oa->oa_base, oa->oa_length); 98ec3ca1a2SPeter Wemm buf += RNDUP(oa->oa_length) / sizeof (int32_t); 9999064799SGarrett Wollman } 10099064799SGarrett Wollman oa = &cmsg->rm_call.cb_verf; 10199064799SGarrett Wollman IXDR_PUT_ENUM(buf, oa->oa_flavor); 1028360efbdSAlfred Perlstein IXDR_PUT_INT32(buf, oa->oa_length); 10399064799SGarrett Wollman if (oa->oa_length) { 1048360efbdSAlfred Perlstein memmove(buf, oa->oa_base, oa->oa_length); 10599064799SGarrett Wollman /* no real need.... 106ec3ca1a2SPeter Wemm buf += RNDUP(oa->oa_length) / sizeof (int32_t); 10799064799SGarrett Wollman */ 10899064799SGarrett Wollman } 10999064799SGarrett Wollman return (TRUE); 11099064799SGarrett Wollman } 11199064799SGarrett Wollman } 11299064799SGarrett Wollman if (xdrs->x_op == XDR_DECODE) { 11399064799SGarrett Wollman buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT); 11499064799SGarrett Wollman if (buf != NULL) { 1158360efbdSAlfred Perlstein cmsg->rm_xid = IXDR_GET_U_INT32(buf); 11699064799SGarrett Wollman cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type); 11799064799SGarrett Wollman if (cmsg->rm_direction != CALL) { 11899064799SGarrett Wollman return (FALSE); 11999064799SGarrett Wollman } 1208360efbdSAlfred Perlstein cmsg->rm_call.cb_rpcvers = IXDR_GET_U_INT32(buf); 12199064799SGarrett Wollman if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) { 12299064799SGarrett Wollman return (FALSE); 12399064799SGarrett Wollman } 1248360efbdSAlfred Perlstein cmsg->rm_call.cb_prog = IXDR_GET_U_INT32(buf); 1258360efbdSAlfred Perlstein cmsg->rm_call.cb_vers = IXDR_GET_U_INT32(buf); 1268360efbdSAlfred Perlstein cmsg->rm_call.cb_proc = IXDR_GET_U_INT32(buf); 12799064799SGarrett Wollman oa = &cmsg->rm_call.cb_cred; 12899064799SGarrett Wollman oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t); 1298360efbdSAlfred Perlstein oa->oa_length = (u_int)IXDR_GET_U_INT32(buf); 13099064799SGarrett Wollman if (oa->oa_length) { 13199064799SGarrett Wollman if (oa->oa_length > MAX_AUTH_BYTES) { 13299064799SGarrett Wollman return (FALSE); 13399064799SGarrett Wollman } 13499064799SGarrett Wollman if (oa->oa_base == NULL) { 13599064799SGarrett Wollman oa->oa_base = (caddr_t) 13699064799SGarrett Wollman mem_alloc(oa->oa_length); 1378360efbdSAlfred Perlstein if (oa->oa_base == NULL) 1388360efbdSAlfred Perlstein return (FALSE); 13999064799SGarrett Wollman } 14099064799SGarrett Wollman buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length)); 14199064799SGarrett Wollman if (buf == NULL) { 14299064799SGarrett Wollman if (xdr_opaque(xdrs, oa->oa_base, 14399064799SGarrett Wollman oa->oa_length) == FALSE) { 14499064799SGarrett Wollman return (FALSE); 14599064799SGarrett Wollman } 14699064799SGarrett Wollman } else { 1478360efbdSAlfred Perlstein memmove(oa->oa_base, buf, 14899064799SGarrett Wollman oa->oa_length); 14999064799SGarrett Wollman /* no real need.... 15099064799SGarrett Wollman buf += RNDUP(oa->oa_length) / 151ec3ca1a2SPeter Wemm sizeof (int32_t); 15299064799SGarrett Wollman */ 15399064799SGarrett Wollman } 15499064799SGarrett Wollman } 15599064799SGarrett Wollman oa = &cmsg->rm_call.cb_verf; 15699064799SGarrett Wollman buf = XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT); 15799064799SGarrett Wollman if (buf == NULL) { 15899064799SGarrett Wollman if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE || 15999064799SGarrett Wollman xdr_u_int(xdrs, &oa->oa_length) == FALSE) { 16099064799SGarrett Wollman return (FALSE); 16199064799SGarrett Wollman } 16299064799SGarrett Wollman } else { 16399064799SGarrett Wollman oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t); 1648360efbdSAlfred Perlstein oa->oa_length = (u_int)IXDR_GET_U_INT32(buf); 16599064799SGarrett Wollman } 16699064799SGarrett Wollman if (oa->oa_length) { 16799064799SGarrett Wollman if (oa->oa_length > MAX_AUTH_BYTES) { 16899064799SGarrett Wollman return (FALSE); 16999064799SGarrett Wollman } 17099064799SGarrett Wollman if (oa->oa_base == NULL) { 17199064799SGarrett Wollman oa->oa_base = (caddr_t) 17299064799SGarrett Wollman mem_alloc(oa->oa_length); 1738360efbdSAlfred Perlstein if (oa->oa_base == NULL) 1748360efbdSAlfred Perlstein return (FALSE); 17599064799SGarrett Wollman } 17699064799SGarrett Wollman buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length)); 17799064799SGarrett Wollman if (buf == NULL) { 17899064799SGarrett Wollman if (xdr_opaque(xdrs, oa->oa_base, 17999064799SGarrett Wollman oa->oa_length) == FALSE) { 18099064799SGarrett Wollman return (FALSE); 18199064799SGarrett Wollman } 18299064799SGarrett Wollman } else { 1838360efbdSAlfred Perlstein memmove(oa->oa_base, buf, 18499064799SGarrett Wollman oa->oa_length); 18599064799SGarrett Wollman /* no real need... 18699064799SGarrett Wollman buf += RNDUP(oa->oa_length) / 187ec3ca1a2SPeter Wemm sizeof (int32_t); 18899064799SGarrett Wollman */ 18999064799SGarrett Wollman } 19099064799SGarrett Wollman } 19199064799SGarrett Wollman return (TRUE); 19299064799SGarrett Wollman } 19399064799SGarrett Wollman } 194102c7c92SJohn Birrell prm_direction = &cmsg->rm_direction; 19599064799SGarrett Wollman if ( 196ec3ca1a2SPeter Wemm xdr_u_int32_t(xdrs, &(cmsg->rm_xid)) && 197102c7c92SJohn Birrell xdr_enum(xdrs, (enum_t *) prm_direction) && 19899064799SGarrett Wollman (cmsg->rm_direction == CALL) && 199ec3ca1a2SPeter Wemm xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) && 20099064799SGarrett Wollman (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) && 201ec3ca1a2SPeter Wemm xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_prog)) && 202ec3ca1a2SPeter Wemm xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers)) && 203ec3ca1a2SPeter Wemm xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_proc)) && 20499064799SGarrett Wollman xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred)) ) 20599064799SGarrett Wollman return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf))); 20699064799SGarrett Wollman return (FALSE); 20799064799SGarrett Wollman } 208