10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
70Sstevel@tonic-gate * with the License.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate * See the License for the specific language governing permissions
120Sstevel@tonic-gate * and limitations under the License.
130Sstevel@tonic-gate *
140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * CDDL HEADER END
21132Srobinson */
22132Srobinson
23132Srobinson /*
24*1219Sraf * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
250Sstevel@tonic-gate * Use is subject to license terms.
260Sstevel@tonic-gate */
27*1219Sraf
280Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
290Sstevel@tonic-gate /* All Rights Reserved */
300Sstevel@tonic-gate /*
310Sstevel@tonic-gate * Portions of this source code were derived from Berkeley
320Sstevel@tonic-gate * 4.3 BSD under license from the Regents of the University of
330Sstevel@tonic-gate * California.
340Sstevel@tonic-gate */
350Sstevel@tonic-gate
360Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
370Sstevel@tonic-gate
38*1219Sraf #include "mt.h"
39132Srobinson #include <stdlib.h>
400Sstevel@tonic-gate #include <sys/param.h>
410Sstevel@tonic-gate #include <rpc/rpc.h>
420Sstevel@tonic-gate #include <syslog.h>
430Sstevel@tonic-gate #include <sys/byteorder.h>
440Sstevel@tonic-gate
45132Srobinson extern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *);
460Sstevel@tonic-gate
470Sstevel@tonic-gate /*
480Sstevel@tonic-gate * XDR a call message
490Sstevel@tonic-gate */
500Sstevel@tonic-gate bool_t
xdr_callmsg(XDR * xdrs,struct rpc_msg * cmsg)51132Srobinson xdr_callmsg(XDR *xdrs, struct rpc_msg *cmsg)
520Sstevel@tonic-gate {
53132Srobinson rpc_inline_t *buf;
54132Srobinson struct opaque_auth *oa;
550Sstevel@tonic-gate
560Sstevel@tonic-gate if (xdrs->x_op == XDR_ENCODE) {
57132Srobinson if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES)
580Sstevel@tonic-gate return (FALSE);
59132Srobinson if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES)
600Sstevel@tonic-gate return (FALSE);
610Sstevel@tonic-gate buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT
620Sstevel@tonic-gate + RNDUP(cmsg->rm_call.cb_cred.oa_length)
630Sstevel@tonic-gate + 2 * BYTES_PER_XDR_UNIT
640Sstevel@tonic-gate + RNDUP(cmsg->rm_call.cb_verf.oa_length));
650Sstevel@tonic-gate if (buf != NULL) {
660Sstevel@tonic-gate IXDR_PUT_INT32(buf, cmsg->rm_xid);
670Sstevel@tonic-gate IXDR_PUT_ENUM(buf, cmsg->rm_direction);
68132Srobinson if (cmsg->rm_direction != CALL)
690Sstevel@tonic-gate return (FALSE);
700Sstevel@tonic-gate IXDR_PUT_INT32(buf, cmsg->rm_call.cb_rpcvers);
71132Srobinson if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION)
720Sstevel@tonic-gate return (FALSE);
730Sstevel@tonic-gate IXDR_PUT_INT32(buf, cmsg->rm_call.cb_prog);
740Sstevel@tonic-gate IXDR_PUT_INT32(buf, cmsg->rm_call.cb_vers);
750Sstevel@tonic-gate IXDR_PUT_INT32(buf, cmsg->rm_call.cb_proc);
760Sstevel@tonic-gate oa = &cmsg->rm_call.cb_cred;
770Sstevel@tonic-gate IXDR_PUT_ENUM(buf, oa->oa_flavor);
780Sstevel@tonic-gate IXDR_PUT_INT32(buf, oa->oa_length);
790Sstevel@tonic-gate if (oa->oa_length) {
80132Srobinson (void) memcpy(buf, oa->oa_base, oa->oa_length);
810Sstevel@tonic-gate buf += RNDUP(oa->oa_length) / sizeof (int32_t);
820Sstevel@tonic-gate }
830Sstevel@tonic-gate oa = &cmsg->rm_call.cb_verf;
840Sstevel@tonic-gate IXDR_PUT_ENUM(buf, oa->oa_flavor);
850Sstevel@tonic-gate IXDR_PUT_INT32(buf, oa->oa_length);
860Sstevel@tonic-gate if (oa->oa_length) {
87132Srobinson (void) memcpy(buf, oa->oa_base, oa->oa_length);
880Sstevel@tonic-gate /*
890Sstevel@tonic-gate * no real need....
900Sstevel@tonic-gate * buf += RNDUP(oa->oa_length) / sizeof
910Sstevel@tonic-gate * (int32_t);
920Sstevel@tonic-gate */
930Sstevel@tonic-gate }
940Sstevel@tonic-gate return (TRUE);
950Sstevel@tonic-gate }
960Sstevel@tonic-gate }
970Sstevel@tonic-gate if (xdrs->x_op == XDR_DECODE) {
980Sstevel@tonic-gate buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT);
990Sstevel@tonic-gate if (buf != NULL) {
1000Sstevel@tonic-gate cmsg->rm_xid = IXDR_GET_INT32(buf);
1010Sstevel@tonic-gate cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type);
102132Srobinson if (cmsg->rm_direction != CALL)
1030Sstevel@tonic-gate return (FALSE);
1040Sstevel@tonic-gate cmsg->rm_call.cb_rpcvers = IXDR_GET_INT32(buf);
105132Srobinson if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION)
1060Sstevel@tonic-gate return (FALSE);
1070Sstevel@tonic-gate cmsg->rm_call.cb_prog = IXDR_GET_INT32(buf);
1080Sstevel@tonic-gate cmsg->rm_call.cb_vers = IXDR_GET_INT32(buf);
1090Sstevel@tonic-gate cmsg->rm_call.cb_proc = IXDR_GET_INT32(buf);
1100Sstevel@tonic-gate oa = &cmsg->rm_call.cb_cred;
1110Sstevel@tonic-gate oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
1120Sstevel@tonic-gate oa->oa_length = IXDR_GET_INT32(buf);
1130Sstevel@tonic-gate if (oa->oa_length) {
114132Srobinson if (oa->oa_length > MAX_AUTH_BYTES)
1150Sstevel@tonic-gate return (FALSE);
1160Sstevel@tonic-gate if (oa->oa_base == NULL) {
117132Srobinson oa->oa_base = malloc(oa->oa_length);
1180Sstevel@tonic-gate if (oa->oa_base == NULL) {
1190Sstevel@tonic-gate syslog(LOG_ERR,
1200Sstevel@tonic-gate "xdr_callmsg : "
1210Sstevel@tonic-gate "out of memory.");
1220Sstevel@tonic-gate return (FALSE);
1230Sstevel@tonic-gate }
1240Sstevel@tonic-gate }
1250Sstevel@tonic-gate buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
1260Sstevel@tonic-gate if (buf == NULL) {
1270Sstevel@tonic-gate if (xdr_opaque(xdrs, oa->oa_base,
128132Srobinson oa->oa_length) == FALSE)
1290Sstevel@tonic-gate return (FALSE);
1300Sstevel@tonic-gate } else {
1310Sstevel@tonic-gate (void) memcpy(oa->oa_base,
132132Srobinson buf, (size_t)oa->oa_length);
1330Sstevel@tonic-gate /*
1340Sstevel@tonic-gate * no real need....
1350Sstevel@tonic-gate * buf += RNDUP(oa->oa_length) /
136132Srobinson * (int)sizeof (int32_t);
1370Sstevel@tonic-gate */
1380Sstevel@tonic-gate }
1390Sstevel@tonic-gate }
1400Sstevel@tonic-gate oa = &cmsg->rm_call.cb_verf;
1410Sstevel@tonic-gate buf = XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT);
1420Sstevel@tonic-gate if (buf == NULL) {
1430Sstevel@tonic-gate if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE ||
144132Srobinson xdr_u_int(xdrs, &oa->oa_length) == FALSE)
1450Sstevel@tonic-gate return (FALSE);
1460Sstevel@tonic-gate } else {
1470Sstevel@tonic-gate oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
1480Sstevel@tonic-gate oa->oa_length = IXDR_GET_INT32(buf);
1490Sstevel@tonic-gate }
1500Sstevel@tonic-gate if (oa->oa_length) {
151132Srobinson if (oa->oa_length > MAX_AUTH_BYTES)
1520Sstevel@tonic-gate return (FALSE);
1530Sstevel@tonic-gate if (oa->oa_base == NULL) {
154132Srobinson oa->oa_base = malloc(oa->oa_length);
1550Sstevel@tonic-gate if (oa->oa_base == NULL) {
1560Sstevel@tonic-gate syslog(LOG_ERR,
1570Sstevel@tonic-gate "xdr_callmsg : "
1580Sstevel@tonic-gate "out of memory.");
1590Sstevel@tonic-gate return (FALSE);
1600Sstevel@tonic-gate }
1610Sstevel@tonic-gate }
1620Sstevel@tonic-gate buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
1630Sstevel@tonic-gate if (buf == NULL) {
1640Sstevel@tonic-gate if (xdr_opaque(xdrs, oa->oa_base,
165132Srobinson oa->oa_length) == FALSE)
1660Sstevel@tonic-gate return (FALSE);
1670Sstevel@tonic-gate } else {
1680Sstevel@tonic-gate (void) memcpy(oa->oa_base,
169132Srobinson buf, (size_t)oa->oa_length);
1700Sstevel@tonic-gate /*
1710Sstevel@tonic-gate * no real need...
1720Sstevel@tonic-gate * buf += RNDUP(oa->oa_length) /
173132Srobinson * (int)sizeof (int32_t);
1740Sstevel@tonic-gate */
1750Sstevel@tonic-gate }
1760Sstevel@tonic-gate }
1770Sstevel@tonic-gate return (TRUE);
1780Sstevel@tonic-gate }
1790Sstevel@tonic-gate }
1800Sstevel@tonic-gate if (xdr_u_int(xdrs, &(cmsg->rm_xid)) &&
1810Sstevel@tonic-gate xdr_enum(xdrs, (enum_t *)&(cmsg->rm_direction)) &&
1820Sstevel@tonic-gate (cmsg->rm_direction == CALL) &&
183132Srobinson xdr_u_int(xdrs, (uint_t *)&(cmsg->rm_call.cb_rpcvers)) &&
1840Sstevel@tonic-gate (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) &&
185132Srobinson xdr_u_int(xdrs, (uint_t *)&(cmsg->rm_call.cb_prog)) &&
186132Srobinson xdr_u_int(xdrs, (uint_t *)&(cmsg->rm_call.cb_vers)) &&
187132Srobinson xdr_u_int(xdrs, (uint_t *)&(cmsg->rm_call.cb_proc)) &&
1880Sstevel@tonic-gate xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred))) {
189132Srobinson return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf)));
1900Sstevel@tonic-gate }
1910Sstevel@tonic-gate return (FALSE);
1920Sstevel@tonic-gate }
193