xref: /freebsd/lib/libc/rpc/rpc_callmsg.c (revision 990647991e51c0f93ad5d9985587a60f322f543a)
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";*/
3399064799SGarrett Wollman static char *rcsid = "$Id: rpc_callmsg.c,v 1.1 1993/10/27 05:40:46 paul 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>
4499064799SGarrett Wollman 
4599064799SGarrett Wollman #include <rpc/rpc.h>
4699064799SGarrett Wollman 
4799064799SGarrett Wollman /*
4899064799SGarrett Wollman  * XDR a call message
4999064799SGarrett Wollman  */
5099064799SGarrett Wollman bool_t
5199064799SGarrett Wollman xdr_callmsg(xdrs, cmsg)
5299064799SGarrett Wollman 	register XDR *xdrs;
5399064799SGarrett Wollman 	register struct rpc_msg *cmsg;
5499064799SGarrett Wollman {
5599064799SGarrett Wollman 	register long *buf;
5699064799SGarrett Wollman 	register struct opaque_auth *oa;
5799064799SGarrett Wollman 
5899064799SGarrett Wollman 	if (xdrs->x_op == XDR_ENCODE) {
5999064799SGarrett Wollman 		if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) {
6099064799SGarrett Wollman 			return (FALSE);
6199064799SGarrett Wollman 		}
6299064799SGarrett Wollman 		if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) {
6399064799SGarrett Wollman 			return (FALSE);
6499064799SGarrett Wollman 		}
6599064799SGarrett Wollman 		buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT
6699064799SGarrett Wollman 			+ RNDUP(cmsg->rm_call.cb_cred.oa_length)
6799064799SGarrett Wollman 			+ 2 * BYTES_PER_XDR_UNIT
6899064799SGarrett Wollman 			+ RNDUP(cmsg->rm_call.cb_verf.oa_length));
6999064799SGarrett Wollman 		if (buf != NULL) {
7099064799SGarrett Wollman 			IXDR_PUT_LONG(buf, cmsg->rm_xid);
7199064799SGarrett Wollman 			IXDR_PUT_ENUM(buf, cmsg->rm_direction);
7299064799SGarrett Wollman 			if (cmsg->rm_direction != CALL) {
7399064799SGarrett Wollman 				return (FALSE);
7499064799SGarrett Wollman 			}
7599064799SGarrett Wollman 			IXDR_PUT_LONG(buf, cmsg->rm_call.cb_rpcvers);
7699064799SGarrett Wollman 			if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
7799064799SGarrett Wollman 				return (FALSE);
7899064799SGarrett Wollman 			}
7999064799SGarrett Wollman 			IXDR_PUT_LONG(buf, cmsg->rm_call.cb_prog);
8099064799SGarrett Wollman 			IXDR_PUT_LONG(buf, cmsg->rm_call.cb_vers);
8199064799SGarrett Wollman 			IXDR_PUT_LONG(buf, cmsg->rm_call.cb_proc);
8299064799SGarrett Wollman 			oa = &cmsg->rm_call.cb_cred;
8399064799SGarrett Wollman 			IXDR_PUT_ENUM(buf, oa->oa_flavor);
8499064799SGarrett Wollman 			IXDR_PUT_LONG(buf, oa->oa_length);
8599064799SGarrett Wollman 			if (oa->oa_length) {
8699064799SGarrett Wollman 				bcopy(oa->oa_base, (caddr_t)buf, oa->oa_length);
8799064799SGarrett Wollman 				buf += RNDUP(oa->oa_length) / sizeof (long);
8899064799SGarrett Wollman 			}
8999064799SGarrett Wollman 			oa = &cmsg->rm_call.cb_verf;
9099064799SGarrett Wollman 			IXDR_PUT_ENUM(buf, oa->oa_flavor);
9199064799SGarrett Wollman 			IXDR_PUT_LONG(buf, oa->oa_length);
9299064799SGarrett Wollman 			if (oa->oa_length) {
9399064799SGarrett Wollman 				bcopy(oa->oa_base, (caddr_t)buf, oa->oa_length);
9499064799SGarrett Wollman 				/* no real need....
9599064799SGarrett Wollman 				buf += RNDUP(oa->oa_length) / sizeof (long);
9699064799SGarrett Wollman 				*/
9799064799SGarrett Wollman 			}
9899064799SGarrett Wollman 			return (TRUE);
9999064799SGarrett Wollman 		}
10099064799SGarrett Wollman 	}
10199064799SGarrett Wollman 	if (xdrs->x_op == XDR_DECODE) {
10299064799SGarrett Wollman 		buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT);
10399064799SGarrett Wollman 		if (buf != NULL) {
10499064799SGarrett Wollman 			cmsg->rm_xid = IXDR_GET_LONG(buf);
10599064799SGarrett Wollman 			cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type);
10699064799SGarrett Wollman 			if (cmsg->rm_direction != CALL) {
10799064799SGarrett Wollman 				return (FALSE);
10899064799SGarrett Wollman 			}
10999064799SGarrett Wollman 			cmsg->rm_call.cb_rpcvers = IXDR_GET_LONG(buf);
11099064799SGarrett Wollman 			if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
11199064799SGarrett Wollman 				return (FALSE);
11299064799SGarrett Wollman 			}
11399064799SGarrett Wollman 			cmsg->rm_call.cb_prog = IXDR_GET_LONG(buf);
11499064799SGarrett Wollman 			cmsg->rm_call.cb_vers = IXDR_GET_LONG(buf);
11599064799SGarrett Wollman 			cmsg->rm_call.cb_proc = IXDR_GET_LONG(buf);
11699064799SGarrett Wollman 			oa = &cmsg->rm_call.cb_cred;
11799064799SGarrett Wollman 			oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
11899064799SGarrett Wollman 			oa->oa_length = IXDR_GET_LONG(buf);
11999064799SGarrett Wollman 			if (oa->oa_length) {
12099064799SGarrett Wollman 				if (oa->oa_length > MAX_AUTH_BYTES) {
12199064799SGarrett Wollman 					return (FALSE);
12299064799SGarrett Wollman 				}
12399064799SGarrett Wollman 				if (oa->oa_base == NULL) {
12499064799SGarrett Wollman 					oa->oa_base = (caddr_t)
12599064799SGarrett Wollman 						mem_alloc(oa->oa_length);
12699064799SGarrett Wollman 				}
12799064799SGarrett Wollman 				buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
12899064799SGarrett Wollman 				if (buf == NULL) {
12999064799SGarrett Wollman 					if (xdr_opaque(xdrs, oa->oa_base,
13099064799SGarrett Wollman 					    oa->oa_length) == FALSE) {
13199064799SGarrett Wollman 						return (FALSE);
13299064799SGarrett Wollman 					}
13399064799SGarrett Wollman 				} else {
13499064799SGarrett Wollman 					bcopy((caddr_t)buf, oa->oa_base,
13599064799SGarrett Wollman 					    oa->oa_length);
13699064799SGarrett Wollman 					/* no real need....
13799064799SGarrett Wollman 					buf += RNDUP(oa->oa_length) /
13899064799SGarrett Wollman 						sizeof (long);
13999064799SGarrett Wollman 					*/
14099064799SGarrett Wollman 				}
14199064799SGarrett Wollman 			}
14299064799SGarrett Wollman 			oa = &cmsg->rm_call.cb_verf;
14399064799SGarrett Wollman 			buf = XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT);
14499064799SGarrett Wollman 			if (buf == NULL) {
14599064799SGarrett Wollman 				if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE ||
14699064799SGarrett Wollman 				    xdr_u_int(xdrs, &oa->oa_length) == FALSE) {
14799064799SGarrett Wollman 					return (FALSE);
14899064799SGarrett Wollman 				}
14999064799SGarrett Wollman 			} else {
15099064799SGarrett Wollman 				oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
15199064799SGarrett Wollman 				oa->oa_length = IXDR_GET_LONG(buf);
15299064799SGarrett Wollman 			}
15399064799SGarrett Wollman 			if (oa->oa_length) {
15499064799SGarrett Wollman 				if (oa->oa_length > MAX_AUTH_BYTES) {
15599064799SGarrett Wollman 					return (FALSE);
15699064799SGarrett Wollman 				}
15799064799SGarrett Wollman 				if (oa->oa_base == NULL) {
15899064799SGarrett Wollman 					oa->oa_base = (caddr_t)
15999064799SGarrett Wollman 						mem_alloc(oa->oa_length);
16099064799SGarrett Wollman 				}
16199064799SGarrett Wollman 				buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
16299064799SGarrett Wollman 				if (buf == NULL) {
16399064799SGarrett Wollman 					if (xdr_opaque(xdrs, oa->oa_base,
16499064799SGarrett Wollman 					    oa->oa_length) == FALSE) {
16599064799SGarrett Wollman 						return (FALSE);
16699064799SGarrett Wollman 					}
16799064799SGarrett Wollman 				} else {
16899064799SGarrett Wollman 					bcopy((caddr_t)buf, oa->oa_base,
16999064799SGarrett Wollman 					    oa->oa_length);
17099064799SGarrett Wollman 					/* no real need...
17199064799SGarrett Wollman 					buf += RNDUP(oa->oa_length) /
17299064799SGarrett Wollman 						sizeof (long);
17399064799SGarrett Wollman 					*/
17499064799SGarrett Wollman 				}
17599064799SGarrett Wollman 			}
17699064799SGarrett Wollman 			return (TRUE);
17799064799SGarrett Wollman 		}
17899064799SGarrett Wollman 	}
17999064799SGarrett Wollman 	if (
18099064799SGarrett Wollman 	    xdr_u_long(xdrs, &(cmsg->rm_xid)) &&
18199064799SGarrett Wollman 	    xdr_enum(xdrs, (enum_t *)&(cmsg->rm_direction)) &&
18299064799SGarrett Wollman 	    (cmsg->rm_direction == CALL) &&
18399064799SGarrett Wollman 	    xdr_u_long(xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
18499064799SGarrett Wollman 	    (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) &&
18599064799SGarrett Wollman 	    xdr_u_long(xdrs, &(cmsg->rm_call.cb_prog)) &&
18699064799SGarrett Wollman 	    xdr_u_long(xdrs, &(cmsg->rm_call.cb_vers)) &&
18799064799SGarrett Wollman 	    xdr_u_long(xdrs, &(cmsg->rm_call.cb_proc)) &&
18899064799SGarrett Wollman 	    xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred)) )
18999064799SGarrett Wollman 	    return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf)));
19099064799SGarrett Wollman 	return (FALSE);
19199064799SGarrett Wollman }
19299064799SGarrett Wollman 
193