Path: blob/main/crypto/krb5/src/lib/rpc/rpc_callmsg.c
39536 views
/* @(#)rpc_callmsg.c 2.1 88/07/29 4.0 RPCSRC */1/*2* Copyright (c) 2010, Oracle America, Inc.3*4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions are met:8*9* * Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11*12* * Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in14* the documentation and/or other materials provided with the15* distribution.16*17* * Neither the name of the "Oracle America, Inc." nor the names of18* its contributors may be used to endorse or promote products19* derived from this software without specific prior written permission.20*21* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS22* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED23* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A24* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT25* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,26* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED27* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR28* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF29* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING30* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS31* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.32*/33#if !defined(lint) && defined(SCCSIDS)34static char sccsid[] = "@(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro";35#endif3637/*38* rpc_callmsg.c39*/4041#include <sys/param.h>42#include <string.h>43#include <gssrpc/rpc.h>4445/*46* XDR a call message47*/48bool_t49xdr_callmsg(XDR *xdrs, struct rpc_msg *cmsg)50{51rpc_inline_t *buf;52struct opaque_auth *oa;5354if (xdrs->x_op == XDR_ENCODE) {55if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) {56return (FALSE);57}58if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) {59return (FALSE);60}61buf = (rpc_inline_t *) XDR_INLINE(xdrs, (int) (628 * BYTES_PER_XDR_UNIT63+ RNDUP(cmsg->rm_call.cb_cred.oa_length)64+ 2 * BYTES_PER_XDR_UNIT65+ RNDUP(cmsg->rm_call.cb_verf.oa_length)));66if (buf != NULL) {67IXDR_PUT_LONG(buf, cmsg->rm_xid);68IXDR_PUT_ENUM(buf, cmsg->rm_direction);69if (cmsg->rm_direction != CALL) {70return (FALSE);71}72IXDR_PUT_LONG(buf, cmsg->rm_call.cb_rpcvers);73if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {74return (FALSE);75}76IXDR_PUT_LONG(buf, cmsg->rm_call.cb_prog);77IXDR_PUT_LONG(buf, cmsg->rm_call.cb_vers);78IXDR_PUT_LONG(buf, cmsg->rm_call.cb_proc);79oa = &cmsg->rm_call.cb_cred;80IXDR_PUT_ENUM(buf, oa->oa_flavor);81IXDR_PUT_LONG(buf, oa->oa_length);82if (oa->oa_length) {83memmove((caddr_t)buf, oa->oa_base,84oa->oa_length);85buf += RNDUP(oa->oa_length) / BYTES_PER_XDR_UNIT;86}87oa = &cmsg->rm_call.cb_verf;88IXDR_PUT_ENUM(buf, oa->oa_flavor);89IXDR_PUT_LONG(buf, oa->oa_length);90if (oa->oa_length) {91memmove((caddr_t)buf, oa->oa_base,92oa->oa_length);93/* no real need....94buf += RNDUP(oa->oa_length) / BYTES_PER_XDR_UNIT;95*/96}97return (TRUE);98}99}100if (xdrs->x_op == XDR_DECODE) {101buf = (rpc_inline_t *) XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT);102if (buf != NULL) {103cmsg->rm_xid = IXDR_GET_LONG(buf);104cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type);105if (cmsg->rm_direction != CALL) {106return (FALSE);107}108cmsg->rm_call.cb_rpcvers = IXDR_GET_LONG(buf);109if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {110return (FALSE);111}112cmsg->rm_call.cb_prog = IXDR_GET_LONG(buf);113cmsg->rm_call.cb_vers = IXDR_GET_LONG(buf);114cmsg->rm_call.cb_proc = IXDR_GET_LONG(buf);115oa = &cmsg->rm_call.cb_cred;116oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);117oa->oa_length = IXDR_GET_LONG(buf);118if (oa->oa_length) {119if (oa->oa_length > MAX_AUTH_BYTES) {120return (FALSE);121}122if (oa->oa_base == NULL) {123oa->oa_base = (caddr_t)124mem_alloc(oa->oa_length);125}126buf = (rpc_inline_t *)127XDR_INLINE(xdrs, (int)RNDUP(oa->oa_length));128if (buf == NULL) {129if (xdr_opaque(xdrs, oa->oa_base,130oa->oa_length) == FALSE) {131return (FALSE);132}133} else {134memmove(oa->oa_base, (caddr_t)buf,135oa->oa_length);136/* no real need....137buf += RNDUP(oa->oa_length) /138BYTES_PER_XDR_UNIT;139*/140}141}142oa = &cmsg->rm_call.cb_verf;143buf = (rpc_inline_t *)144XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT);145if (buf == NULL) {146if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE ||147xdr_u_int(xdrs, &oa->oa_length) == FALSE) {148return (FALSE);149}150} else {151oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);152oa->oa_length = IXDR_GET_LONG(buf);153}154if (oa->oa_length) {155if (oa->oa_length > MAX_AUTH_BYTES) {156return (FALSE);157}158if (oa->oa_base == NULL) {159oa->oa_base = (caddr_t)160mem_alloc(oa->oa_length);161}162buf = (rpc_inline_t *)163XDR_INLINE(xdrs, (int)RNDUP(oa->oa_length));164if (buf == NULL) {165if (xdr_opaque(xdrs, oa->oa_base,166oa->oa_length) == FALSE) {167return (FALSE);168}169} else {170memmove(oa->oa_base, (caddr_t) buf,171oa->oa_length);172/* no real need...173buf += RNDUP(oa->oa_length) /174BYTES_PER_XDR_UNIT;175*/176}177}178return (TRUE);179}180}181if (182xdr_u_int32(xdrs, &(cmsg->rm_xid)) &&183xdr_enum(xdrs, (enum_t *)&(cmsg->rm_direction)) &&184(cmsg->rm_direction == CALL) &&185xdr_u_int32(xdrs, &(cmsg->rm_call.cb_rpcvers)) &&186(cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) &&187xdr_u_int32(xdrs, &(cmsg->rm_call.cb_prog)) &&188xdr_u_int32(xdrs, &(cmsg->rm_call.cb_vers)) &&189xdr_u_int32(xdrs, &(cmsg->rm_call.cb_proc)) &&190xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred)) )191return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf)));192return (FALSE);193}194195196