diff options
Diffstat (limited to 'usr/src/lib/libnsl/rpc/rpc_callmsg.c')
-rw-r--r-- | usr/src/lib/libnsl/rpc/rpc_callmsg.c | 240 |
1 files changed, 240 insertions, 0 deletions
diff --git a/usr/src/lib/libnsl/rpc/rpc_callmsg.c b/usr/src/lib/libnsl/rpc/rpc_callmsg.c new file mode 100644 index 0000000000..f5cf825ba4 --- /dev/null +++ b/usr/src/lib/libnsl/rpc/rpc_callmsg.c @@ -0,0 +1,240 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + * + * Copyright 1999 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ +/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ +/* All Rights Reserved */ +/* + * Portions of this source code were derived from Berkeley + * 4.3 BSD under license from the Regents of the University of + * California. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * rpc_callmsg.c + * + */ + +#include <sys/param.h> +#include <rpc/trace.h> + +#ifdef KERNEL +#include <rpc/types.h> /* spell 'em out for make depend */ +#include <rpc/xdr.h> +#include <rpc/auth.h> +#include <rpc/clnt.h> +#include <rpc/rpc_msg.h> +#else +#include <rpc/rpc.h> +#endif +#include <syslog.h> +#include <sys/byteorder.h> + +extern bool_t xdr_opaque_auth(); +extern char *malloc(); + +/* + * XDR a call message + */ +bool_t +xdr_callmsg(xdrs, cmsg) + register XDR *xdrs; + register struct rpc_msg *cmsg; +{ + register rpc_inline_t *buf; + register struct opaque_auth *oa; + bool_t dummy; + + trace1(TR_xdr_callmsg, 0); + if (xdrs->x_op == XDR_ENCODE) { + if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) { + trace1(TR_xdr_callmsg, 1); + return (FALSE); + } + if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) { + trace1(TR_xdr_callmsg, 1); + return (FALSE); + } + buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT + + RNDUP(cmsg->rm_call.cb_cred.oa_length) + + 2 * BYTES_PER_XDR_UNIT + + RNDUP(cmsg->rm_call.cb_verf.oa_length)); + if (buf != NULL) { + IXDR_PUT_INT32(buf, cmsg->rm_xid); + IXDR_PUT_ENUM(buf, cmsg->rm_direction); + if (cmsg->rm_direction != CALL) { + trace1(TR_xdr_callmsg, 1); + return (FALSE); + } + IXDR_PUT_INT32(buf, cmsg->rm_call.cb_rpcvers); + if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) { + trace1(TR_xdr_callmsg, 1); + return (FALSE); + } + IXDR_PUT_INT32(buf, cmsg->rm_call.cb_prog); + IXDR_PUT_INT32(buf, cmsg->rm_call.cb_vers); + IXDR_PUT_INT32(buf, cmsg->rm_call.cb_proc); + oa = &cmsg->rm_call.cb_cred; + IXDR_PUT_ENUM(buf, oa->oa_flavor); + IXDR_PUT_INT32(buf, oa->oa_length); + if (oa->oa_length) { + (void) memcpy((caddr_t)buf, oa->oa_base, + oa->oa_length); + buf += RNDUP(oa->oa_length) / sizeof (int32_t); + } + oa = &cmsg->rm_call.cb_verf; + IXDR_PUT_ENUM(buf, oa->oa_flavor); + IXDR_PUT_INT32(buf, oa->oa_length); + if (oa->oa_length) { + (void) memcpy((caddr_t)buf, oa->oa_base, + oa->oa_length); + /* + * no real need.... + * buf += RNDUP(oa->oa_length) / sizeof + * (int32_t); + */ + } + trace1(TR_xdr_callmsg, 1); + return (TRUE); + } + } + if (xdrs->x_op == XDR_DECODE) { + buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT); + if (buf != NULL) { + cmsg->rm_xid = IXDR_GET_INT32(buf); + cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type); + if (cmsg->rm_direction != CALL) { + trace1(TR_xdr_callmsg, 1); + return (FALSE); + } + cmsg->rm_call.cb_rpcvers = IXDR_GET_INT32(buf); + if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) { + trace1(TR_xdr_callmsg, 1); + return (FALSE); + } + cmsg->rm_call.cb_prog = IXDR_GET_INT32(buf); + cmsg->rm_call.cb_vers = IXDR_GET_INT32(buf); + cmsg->rm_call.cb_proc = IXDR_GET_INT32(buf); + oa = &cmsg->rm_call.cb_cred; + oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t); + oa->oa_length = IXDR_GET_INT32(buf); + if (oa->oa_length) { + if (oa->oa_length > MAX_AUTH_BYTES) { + trace1(TR_xdr_callmsg, 1); + return (FALSE); + } + if (oa->oa_base == NULL) { + oa->oa_base = (caddr_t) + mem_alloc(oa->oa_length); + if (oa->oa_base == NULL) { + syslog(LOG_ERR, + "xdr_callmsg : " + "out of memory."); + trace1(TR_xdr_callmsg, 1); + return (FALSE); + } + } + buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length)); + if (buf == NULL) { + if (xdr_opaque(xdrs, oa->oa_base, + oa->oa_length) == FALSE) { + trace1(TR_xdr_callmsg, 1); + return (FALSE); + } + } else { + (void) memcpy(oa->oa_base, + (caddr_t)buf, (int)oa->oa_length); + /* + * no real need.... + * buf += RNDUP(oa->oa_length) / + * (int) sizeof (int32_t); + */ + } + } + oa = &cmsg->rm_call.cb_verf; + buf = XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT); + if (buf == NULL) { + if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE || + xdr_u_int(xdrs, &oa->oa_length) == FALSE) { + trace1(TR_xdr_callmsg, 1); + return (FALSE); + } + } else { + oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t); + oa->oa_length = IXDR_GET_INT32(buf); + } + if (oa->oa_length) { + if (oa->oa_length > MAX_AUTH_BYTES) { + trace1(TR_xdr_callmsg, 1); + return (FALSE); + } + if (oa->oa_base == NULL) { + oa->oa_base = (caddr_t) + mem_alloc(oa->oa_length); + if (oa->oa_base == NULL) { + syslog(LOG_ERR, + "xdr_callmsg : " + "out of memory."); + trace1(TR_xdr_callmsg, 1); + return (FALSE); + } + } + buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length)); + if (buf == NULL) { + if (xdr_opaque(xdrs, oa->oa_base, + oa->oa_length) == FALSE) { + trace1(TR_xdr_callmsg, 1); + return (FALSE); + } + } else { + (void) memcpy(oa->oa_base, + (caddr_t)buf, (int)oa->oa_length); + /* + * no real need... + * buf += RNDUP(oa->oa_length) / + * (int) sizeof (int32_t); + */ + } + } + trace1(TR_xdr_callmsg, 1); + return (TRUE); + } + } + if (xdr_u_int(xdrs, &(cmsg->rm_xid)) && + xdr_enum(xdrs, (enum_t *)&(cmsg->rm_direction)) && + (cmsg->rm_direction == CALL) && + xdr_u_int(xdrs, (u_int *)&(cmsg->rm_call.cb_rpcvers)) && + (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) && + xdr_u_int(xdrs, (u_int *)&(cmsg->rm_call.cb_prog)) && + xdr_u_int(xdrs, (u_int *)&(cmsg->rm_call.cb_vers)) && + xdr_u_int(xdrs, (u_int *)&(cmsg->rm_call.cb_proc)) && + xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred))) { + dummy = xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf)); + trace1(TR_xdr_callmsg, 1); + return (dummy); + } + trace1(TR_xdr_callmsg, 1); + return (FALSE); +} |