199064799SGarrett Wollman /* 299064799SGarrett Wollman * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 399064799SGarrett Wollman * unrestricted use provided that this legend is included on all tape 499064799SGarrett Wollman * media and as a part of the software program in whole or part. Users 599064799SGarrett Wollman * may copy or modify Sun RPC without charge, but are not authorized 699064799SGarrett Wollman * to license or distribute it to anyone else except as part of a product or 799064799SGarrett Wollman * program developed by the user. 899064799SGarrett Wollman * 999064799SGarrett Wollman * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 1099064799SGarrett Wollman * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 1199064799SGarrett Wollman * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 1299064799SGarrett Wollman * 1399064799SGarrett Wollman * Sun RPC is provided with no support and without any obligation on the 1499064799SGarrett Wollman * part of Sun Microsystems, Inc. to assist in its use, correction, 1599064799SGarrett Wollman * modification or enhancement. 1699064799SGarrett Wollman * 1799064799SGarrett Wollman * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 1899064799SGarrett Wollman * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 1999064799SGarrett Wollman * OR ANY PART THEREOF. 2099064799SGarrett Wollman * 2199064799SGarrett Wollman * In no event will Sun Microsystems, Inc. be liable for any lost revenue 2299064799SGarrett Wollman * or profits or other special, indirect and consequential damages, even if 2399064799SGarrett Wollman * Sun has been advised of the possibility of such damages. 2499064799SGarrett Wollman * 2599064799SGarrett Wollman * Sun Microsystems, Inc. 2699064799SGarrett Wollman * 2550 Garcia Avenue 2799064799SGarrett Wollman * Mountain View, California 94043 2899064799SGarrett Wollman */ 2999064799SGarrett Wollman 3099064799SGarrett Wollman #if defined(LIBC_SCCS) && !defined(lint) 3199064799SGarrett Wollman /*static char *sccsid = "from: @(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro";*/ 3299064799SGarrett Wollman /*static char *sccsid = "from: @(#)rpc_callmsg.c 2.1 88/07/29 4.0 RPCSRC";*/ 334c3af266SPoul-Henning Kamp static char *rcsid = "$Id: rpc_callmsg.c,v 1.2 1995/05/30 05:41:28 rgrimes Exp $"; 3499064799SGarrett Wollman #endif 3599064799SGarrett Wollman 3699064799SGarrett Wollman /* 3799064799SGarrett Wollman * rpc_callmsg.c 3899064799SGarrett Wollman * 3999064799SGarrett Wollman * Copyright (C) 1984, Sun Microsystems, Inc. 4099064799SGarrett Wollman * 4199064799SGarrett Wollman */ 4299064799SGarrett Wollman 4399064799SGarrett Wollman #include <sys/param.h> 444c3af266SPoul-Henning Kamp #include <stdlib.h> 454c3af266SPoul-Henning Kamp #include <string.h> 4699064799SGarrett Wollman #include <rpc/rpc.h> 4799064799SGarrett Wollman 4899064799SGarrett Wollman /* 4999064799SGarrett Wollman * XDR a call message 5099064799SGarrett Wollman */ 5199064799SGarrett Wollman bool_t 5299064799SGarrett Wollman xdr_callmsg(xdrs, cmsg) 5399064799SGarrett Wollman register XDR *xdrs; 5499064799SGarrett Wollman register struct rpc_msg *cmsg; 5599064799SGarrett Wollman { 5699064799SGarrett Wollman register long *buf; 5799064799SGarrett Wollman register struct opaque_auth *oa; 5899064799SGarrett Wollman 5999064799SGarrett Wollman if (xdrs->x_op == XDR_ENCODE) { 6099064799SGarrett Wollman if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) { 6199064799SGarrett Wollman return (FALSE); 6299064799SGarrett Wollman } 6399064799SGarrett Wollman if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) { 6499064799SGarrett Wollman return (FALSE); 6599064799SGarrett Wollman } 6699064799SGarrett Wollman buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT 6799064799SGarrett Wollman + RNDUP(cmsg->rm_call.cb_cred.oa_length) 6899064799SGarrett Wollman + 2 * BYTES_PER_XDR_UNIT 6999064799SGarrett Wollman + RNDUP(cmsg->rm_call.cb_verf.oa_length)); 7099064799SGarrett Wollman if (buf != NULL) { 7199064799SGarrett Wollman IXDR_PUT_LONG(buf, cmsg->rm_xid); 7299064799SGarrett Wollman IXDR_PUT_ENUM(buf, cmsg->rm_direction); 7399064799SGarrett Wollman if (cmsg->rm_direction != CALL) { 7499064799SGarrett Wollman return (FALSE); 7599064799SGarrett Wollman } 7699064799SGarrett Wollman IXDR_PUT_LONG(buf, cmsg->rm_call.cb_rpcvers); 7799064799SGarrett Wollman if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) { 7899064799SGarrett Wollman return (FALSE); 7999064799SGarrett Wollman } 8099064799SGarrett Wollman IXDR_PUT_LONG(buf, cmsg->rm_call.cb_prog); 8199064799SGarrett Wollman IXDR_PUT_LONG(buf, cmsg->rm_call.cb_vers); 8299064799SGarrett Wollman IXDR_PUT_LONG(buf, cmsg->rm_call.cb_proc); 8399064799SGarrett Wollman oa = &cmsg->rm_call.cb_cred; 8499064799SGarrett Wollman IXDR_PUT_ENUM(buf, oa->oa_flavor); 8599064799SGarrett Wollman IXDR_PUT_LONG(buf, oa->oa_length); 8699064799SGarrett Wollman if (oa->oa_length) { 8799064799SGarrett Wollman bcopy(oa->oa_base, (caddr_t)buf, oa->oa_length); 8899064799SGarrett Wollman buf += RNDUP(oa->oa_length) / sizeof (long); 8999064799SGarrett Wollman } 9099064799SGarrett Wollman oa = &cmsg->rm_call.cb_verf; 9199064799SGarrett Wollman IXDR_PUT_ENUM(buf, oa->oa_flavor); 9299064799SGarrett Wollman IXDR_PUT_LONG(buf, oa->oa_length); 9399064799SGarrett Wollman if (oa->oa_length) { 9499064799SGarrett Wollman bcopy(oa->oa_base, (caddr_t)buf, oa->oa_length); 9599064799SGarrett Wollman /* no real need.... 9699064799SGarrett Wollman buf += RNDUP(oa->oa_length) / sizeof (long); 9799064799SGarrett Wollman */ 9899064799SGarrett Wollman } 9999064799SGarrett Wollman return (TRUE); 10099064799SGarrett Wollman } 10199064799SGarrett Wollman } 10299064799SGarrett Wollman if (xdrs->x_op == XDR_DECODE) { 10399064799SGarrett Wollman buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT); 10499064799SGarrett Wollman if (buf != NULL) { 10599064799SGarrett Wollman cmsg->rm_xid = IXDR_GET_LONG(buf); 10699064799SGarrett Wollman cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type); 10799064799SGarrett Wollman if (cmsg->rm_direction != CALL) { 10899064799SGarrett Wollman return (FALSE); 10999064799SGarrett Wollman } 11099064799SGarrett Wollman cmsg->rm_call.cb_rpcvers = IXDR_GET_LONG(buf); 11199064799SGarrett Wollman if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) { 11299064799SGarrett Wollman return (FALSE); 11399064799SGarrett Wollman } 11499064799SGarrett Wollman cmsg->rm_call.cb_prog = IXDR_GET_LONG(buf); 11599064799SGarrett Wollman cmsg->rm_call.cb_vers = IXDR_GET_LONG(buf); 11699064799SGarrett Wollman cmsg->rm_call.cb_proc = IXDR_GET_LONG(buf); 11799064799SGarrett Wollman oa = &cmsg->rm_call.cb_cred; 11899064799SGarrett Wollman oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t); 11999064799SGarrett Wollman oa->oa_length = IXDR_GET_LONG(buf); 12099064799SGarrett Wollman if (oa->oa_length) { 12199064799SGarrett Wollman if (oa->oa_length > MAX_AUTH_BYTES) { 12299064799SGarrett Wollman return (FALSE); 12399064799SGarrett Wollman } 12499064799SGarrett Wollman if (oa->oa_base == NULL) { 12599064799SGarrett Wollman oa->oa_base = (caddr_t) 12699064799SGarrett Wollman mem_alloc(oa->oa_length); 12799064799SGarrett Wollman } 12899064799SGarrett Wollman buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length)); 12999064799SGarrett Wollman if (buf == NULL) { 13099064799SGarrett Wollman if (xdr_opaque(xdrs, oa->oa_base, 13199064799SGarrett Wollman oa->oa_length) == FALSE) { 13299064799SGarrett Wollman return (FALSE); 13399064799SGarrett Wollman } 13499064799SGarrett Wollman } else { 13599064799SGarrett Wollman bcopy((caddr_t)buf, oa->oa_base, 13699064799SGarrett Wollman oa->oa_length); 13799064799SGarrett Wollman /* no real need.... 13899064799SGarrett Wollman buf += RNDUP(oa->oa_length) / 13999064799SGarrett Wollman sizeof (long); 14099064799SGarrett Wollman */ 14199064799SGarrett Wollman } 14299064799SGarrett Wollman } 14399064799SGarrett Wollman oa = &cmsg->rm_call.cb_verf; 14499064799SGarrett Wollman buf = XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT); 14599064799SGarrett Wollman if (buf == NULL) { 14699064799SGarrett Wollman if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE || 14799064799SGarrett Wollman xdr_u_int(xdrs, &oa->oa_length) == FALSE) { 14899064799SGarrett Wollman return (FALSE); 14999064799SGarrett Wollman } 15099064799SGarrett Wollman } else { 15199064799SGarrett Wollman oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t); 15299064799SGarrett Wollman oa->oa_length = IXDR_GET_LONG(buf); 15399064799SGarrett Wollman } 15499064799SGarrett Wollman if (oa->oa_length) { 15599064799SGarrett Wollman if (oa->oa_length > MAX_AUTH_BYTES) { 15699064799SGarrett Wollman return (FALSE); 15799064799SGarrett Wollman } 15899064799SGarrett Wollman if (oa->oa_base == NULL) { 15999064799SGarrett Wollman oa->oa_base = (caddr_t) 16099064799SGarrett Wollman mem_alloc(oa->oa_length); 16199064799SGarrett Wollman } 16299064799SGarrett Wollman buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length)); 16399064799SGarrett Wollman if (buf == NULL) { 16499064799SGarrett Wollman if (xdr_opaque(xdrs, oa->oa_base, 16599064799SGarrett Wollman oa->oa_length) == FALSE) { 16699064799SGarrett Wollman return (FALSE); 16799064799SGarrett Wollman } 16899064799SGarrett Wollman } else { 16999064799SGarrett Wollman bcopy((caddr_t)buf, oa->oa_base, 17099064799SGarrett Wollman oa->oa_length); 17199064799SGarrett Wollman /* no real need... 17299064799SGarrett Wollman buf += RNDUP(oa->oa_length) / 17399064799SGarrett Wollman sizeof (long); 17499064799SGarrett Wollman */ 17599064799SGarrett Wollman } 17699064799SGarrett Wollman } 17799064799SGarrett Wollman return (TRUE); 17899064799SGarrett Wollman } 17999064799SGarrett Wollman } 18099064799SGarrett Wollman if ( 18199064799SGarrett Wollman xdr_u_long(xdrs, &(cmsg->rm_xid)) && 18299064799SGarrett Wollman xdr_enum(xdrs, (enum_t *)&(cmsg->rm_direction)) && 18399064799SGarrett Wollman (cmsg->rm_direction == CALL) && 18499064799SGarrett Wollman xdr_u_long(xdrs, &(cmsg->rm_call.cb_rpcvers)) && 18599064799SGarrett Wollman (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) && 18699064799SGarrett Wollman xdr_u_long(xdrs, &(cmsg->rm_call.cb_prog)) && 18799064799SGarrett Wollman xdr_u_long(xdrs, &(cmsg->rm_call.cb_vers)) && 18899064799SGarrett Wollman xdr_u_long(xdrs, &(cmsg->rm_call.cb_proc)) && 18999064799SGarrett Wollman xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred)) ) 19099064799SGarrett Wollman return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf))); 19199064799SGarrett Wollman return (FALSE); 19299064799SGarrett Wollman } 19399064799SGarrett Wollman 194