1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate /* 31*7c478bd9Sstevel@tonic-gate * Portions of this source code were derived from Berkeley 4.3 BSD 32*7c478bd9Sstevel@tonic-gate * under license from the Regents of the University of California. 33*7c478bd9Sstevel@tonic-gate */ 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate /* 38*7c478bd9Sstevel@tonic-gate * rpc_calmsg.c 39*7c478bd9Sstevel@tonic-gate */ 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate #include <sys/param.h> 42*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 43*7c478bd9Sstevel@tonic-gate #include <sys/t_lock.h> 44*7c478bd9Sstevel@tonic-gate #include <sys/systm.h> 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate #include <rpc/types.h> 47*7c478bd9Sstevel@tonic-gate #include <rpc/xdr.h> 48*7c478bd9Sstevel@tonic-gate #include <rpc/auth.h> 49*7c478bd9Sstevel@tonic-gate #include <rpc/clnt.h> 50*7c478bd9Sstevel@tonic-gate #include <rpc/rpc_msg.h> 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate /* 53*7c478bd9Sstevel@tonic-gate * XDR a call message 54*7c478bd9Sstevel@tonic-gate */ 55*7c478bd9Sstevel@tonic-gate bool_t 56*7c478bd9Sstevel@tonic-gate xdr_callmsg(XDR *xdrs, struct rpc_msg *cmsg) 57*7c478bd9Sstevel@tonic-gate { 58*7c478bd9Sstevel@tonic-gate int32_t *buf; 59*7c478bd9Sstevel@tonic-gate struct opaque_auth *oa; 60*7c478bd9Sstevel@tonic-gate 61*7c478bd9Sstevel@tonic-gate if (xdrs->x_op == XDR_ENCODE) { 62*7c478bd9Sstevel@tonic-gate if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) 63*7c478bd9Sstevel@tonic-gate return (FALSE); 64*7c478bd9Sstevel@tonic-gate if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) 65*7c478bd9Sstevel@tonic-gate return (FALSE); 66*7c478bd9Sstevel@tonic-gate buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT + 67*7c478bd9Sstevel@tonic-gate RNDUP(cmsg->rm_call.cb_cred.oa_length) + 68*7c478bd9Sstevel@tonic-gate 2 * BYTES_PER_XDR_UNIT + 69*7c478bd9Sstevel@tonic-gate RNDUP(cmsg->rm_call.cb_verf.oa_length)); 70*7c478bd9Sstevel@tonic-gate if (buf != NULL) { 71*7c478bd9Sstevel@tonic-gate IXDR_PUT_INT32(buf, cmsg->rm_xid); 72*7c478bd9Sstevel@tonic-gate IXDR_PUT_ENUM(buf, cmsg->rm_direction); 73*7c478bd9Sstevel@tonic-gate if (cmsg->rm_direction != CALL) 74*7c478bd9Sstevel@tonic-gate return (FALSE); 75*7c478bd9Sstevel@tonic-gate IXDR_PUT_INT32(buf, cmsg->rm_call.cb_rpcvers); 76*7c478bd9Sstevel@tonic-gate if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) 77*7c478bd9Sstevel@tonic-gate return (FALSE); 78*7c478bd9Sstevel@tonic-gate IXDR_PUT_INT32(buf, cmsg->rm_call.cb_prog); 79*7c478bd9Sstevel@tonic-gate IXDR_PUT_INT32(buf, cmsg->rm_call.cb_vers); 80*7c478bd9Sstevel@tonic-gate IXDR_PUT_INT32(buf, cmsg->rm_call.cb_proc); 81*7c478bd9Sstevel@tonic-gate oa = &cmsg->rm_call.cb_cred; 82*7c478bd9Sstevel@tonic-gate IXDR_PUT_ENUM(buf, oa->oa_flavor); 83*7c478bd9Sstevel@tonic-gate IXDR_PUT_INT32(buf, oa->oa_length); 84*7c478bd9Sstevel@tonic-gate if (oa->oa_length) { 85*7c478bd9Sstevel@tonic-gate bcopy(oa->oa_base, buf, oa->oa_length); 86*7c478bd9Sstevel@tonic-gate buf += RNDUP(oa->oa_length) / sizeof (int32_t); 87*7c478bd9Sstevel@tonic-gate } 88*7c478bd9Sstevel@tonic-gate oa = &cmsg->rm_call.cb_verf; 89*7c478bd9Sstevel@tonic-gate IXDR_PUT_ENUM(buf, oa->oa_flavor); 90*7c478bd9Sstevel@tonic-gate IXDR_PUT_INT32(buf, oa->oa_length); 91*7c478bd9Sstevel@tonic-gate if (oa->oa_length) 92*7c478bd9Sstevel@tonic-gate bcopy(oa->oa_base, buf, oa->oa_length); 93*7c478bd9Sstevel@tonic-gate return (TRUE); 94*7c478bd9Sstevel@tonic-gate } 95*7c478bd9Sstevel@tonic-gate } 96*7c478bd9Sstevel@tonic-gate if (xdrs->x_op == XDR_DECODE) { 97*7c478bd9Sstevel@tonic-gate buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT); 98*7c478bd9Sstevel@tonic-gate if (buf != NULL) { 99*7c478bd9Sstevel@tonic-gate cmsg->rm_xid = IXDR_GET_INT32(buf); 100*7c478bd9Sstevel@tonic-gate cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type); 101*7c478bd9Sstevel@tonic-gate if (cmsg->rm_direction != CALL) 102*7c478bd9Sstevel@tonic-gate return (FALSE); 103*7c478bd9Sstevel@tonic-gate cmsg->rm_call.cb_rpcvers = IXDR_GET_INT32(buf); 104*7c478bd9Sstevel@tonic-gate if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) 105*7c478bd9Sstevel@tonic-gate return (FALSE); 106*7c478bd9Sstevel@tonic-gate cmsg->rm_call.cb_prog = IXDR_GET_INT32(buf); 107*7c478bd9Sstevel@tonic-gate cmsg->rm_call.cb_vers = IXDR_GET_INT32(buf); 108*7c478bd9Sstevel@tonic-gate cmsg->rm_call.cb_proc = IXDR_GET_INT32(buf); 109*7c478bd9Sstevel@tonic-gate oa = &cmsg->rm_call.cb_cred; 110*7c478bd9Sstevel@tonic-gate oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t); 111*7c478bd9Sstevel@tonic-gate oa->oa_length = IXDR_GET_INT32(buf); 112*7c478bd9Sstevel@tonic-gate if (oa->oa_length) { 113*7c478bd9Sstevel@tonic-gate if (oa->oa_length > MAX_AUTH_BYTES) 114*7c478bd9Sstevel@tonic-gate return (FALSE); 115*7c478bd9Sstevel@tonic-gate if (oa->oa_base == NULL) 116*7c478bd9Sstevel@tonic-gate oa->oa_base = (caddr_t) 117*7c478bd9Sstevel@tonic-gate mem_alloc(oa->oa_length); 118*7c478bd9Sstevel@tonic-gate buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length)); 119*7c478bd9Sstevel@tonic-gate if (buf == NULL) { 120*7c478bd9Sstevel@tonic-gate if (xdr_opaque(xdrs, oa->oa_base, 121*7c478bd9Sstevel@tonic-gate oa->oa_length) == FALSE) 122*7c478bd9Sstevel@tonic-gate return (FALSE); 123*7c478bd9Sstevel@tonic-gate } else { 124*7c478bd9Sstevel@tonic-gate bcopy(buf, oa->oa_base, oa->oa_length); 125*7c478bd9Sstevel@tonic-gate } 126*7c478bd9Sstevel@tonic-gate } 127*7c478bd9Sstevel@tonic-gate oa = &cmsg->rm_call.cb_verf; 128*7c478bd9Sstevel@tonic-gate buf = XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT); 129*7c478bd9Sstevel@tonic-gate if (buf == NULL) { 130*7c478bd9Sstevel@tonic-gate if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE || 131*7c478bd9Sstevel@tonic-gate xdr_u_int(xdrs, &oa->oa_length) == FALSE) 132*7c478bd9Sstevel@tonic-gate return (FALSE); 133*7c478bd9Sstevel@tonic-gate } else { 134*7c478bd9Sstevel@tonic-gate oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t); 135*7c478bd9Sstevel@tonic-gate oa->oa_length = IXDR_GET_INT32(buf); 136*7c478bd9Sstevel@tonic-gate } 137*7c478bd9Sstevel@tonic-gate if (oa->oa_length) { 138*7c478bd9Sstevel@tonic-gate if (oa->oa_length > MAX_AUTH_BYTES) 139*7c478bd9Sstevel@tonic-gate return (FALSE); 140*7c478bd9Sstevel@tonic-gate if (oa->oa_base == NULL) 141*7c478bd9Sstevel@tonic-gate oa->oa_base = (caddr_t) 142*7c478bd9Sstevel@tonic-gate mem_alloc(oa->oa_length); 143*7c478bd9Sstevel@tonic-gate buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length)); 144*7c478bd9Sstevel@tonic-gate if (buf == NULL) { 145*7c478bd9Sstevel@tonic-gate if (xdr_opaque(xdrs, oa->oa_base, 146*7c478bd9Sstevel@tonic-gate oa->oa_length) == FALSE) 147*7c478bd9Sstevel@tonic-gate return (FALSE); 148*7c478bd9Sstevel@tonic-gate } else { 149*7c478bd9Sstevel@tonic-gate bcopy(buf, oa->oa_base, oa->oa_length); 150*7c478bd9Sstevel@tonic-gate } 151*7c478bd9Sstevel@tonic-gate } 152*7c478bd9Sstevel@tonic-gate return (TRUE); 153*7c478bd9Sstevel@tonic-gate } 154*7c478bd9Sstevel@tonic-gate } 155*7c478bd9Sstevel@tonic-gate 156*7c478bd9Sstevel@tonic-gate if (xdr_u_int(xdrs, &(cmsg->rm_xid)) && 157*7c478bd9Sstevel@tonic-gate xdr_enum(xdrs, (enum_t *)&(cmsg->rm_direction)) && 158*7c478bd9Sstevel@tonic-gate cmsg->rm_direction == CALL && 159*7c478bd9Sstevel@tonic-gate xdr_rpcvers(xdrs, &(cmsg->rm_call.cb_rpcvers)) && 160*7c478bd9Sstevel@tonic-gate cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION && 161*7c478bd9Sstevel@tonic-gate xdr_rpcprog(xdrs, &(cmsg->rm_call.cb_prog)) && 162*7c478bd9Sstevel@tonic-gate xdr_rpcvers(xdrs, &(cmsg->rm_call.cb_vers)) && 163*7c478bd9Sstevel@tonic-gate xdr_rpcproc(xdrs, &(cmsg->rm_call.cb_proc)) && 164*7c478bd9Sstevel@tonic-gate xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred))) 165*7c478bd9Sstevel@tonic-gate return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf))); 166*7c478bd9Sstevel@tonic-gate 167*7c478bd9Sstevel@tonic-gate return (FALSE); 168*7c478bd9Sstevel@tonic-gate } 169