Home | History | Annotate | Line # | Download | only in rpc
rpc_callmsg.c revision 1.6
      1 /*	$NetBSD: rpc_callmsg.c,v 1.6 1997/07/13 20:13:17 christos Exp $	*/
      2 
      3 /*
      4  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
      5  * unrestricted use provided that this legend is included on all tape
      6  * media and as a part of the software program in whole or part.  Users
      7  * may copy or modify Sun RPC without charge, but are not authorized
      8  * to license or distribute it to anyone else except as part of a product or
      9  * program developed by the user.
     10  *
     11  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
     12  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
     13  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
     14  *
     15  * Sun RPC is provided with no support and without any obligation on the
     16  * part of Sun Microsystems, Inc. to assist in its use, correction,
     17  * modification or enhancement.
     18  *
     19  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
     20  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
     21  * OR ANY PART THEREOF.
     22  *
     23  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
     24  * or profits or other special, indirect and consequential damages, even if
     25  * Sun has been advised of the possibility of such damages.
     26  *
     27  * Sun Microsystems, Inc.
     28  * 2550 Garcia Avenue
     29  * Mountain View, California  94043
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 #if defined(LIBC_SCCS) && !defined(lint)
     34 #if 0
     35 static char *sccsid = "@(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro";
     36 static char *sccsid = "@(#)rpc_callmsg.c	2.1 88/07/29 4.0 RPCSRC";
     37 #else
     38 __RCSID("$NetBSD: rpc_callmsg.c,v 1.6 1997/07/13 20:13:17 christos Exp $");
     39 #endif
     40 #endif
     41 
     42 /*
     43  * rpc_callmsg.c
     44  *
     45  * Copyright (C) 1984, Sun Microsystems, Inc.
     46  *
     47  */
     48 
     49 #include <stdlib.h>
     50 #include <string.h>
     51 #include <sys/param.h>
     52 
     53 #include <rpc/rpc.h>
     54 
     55 /*
     56  * XDR a call message
     57  */
     58 bool_t
     59 xdr_callmsg(xdrs, cmsg)
     60 	register XDR *xdrs;
     61 	register struct rpc_msg *cmsg;
     62 {
     63 	register int32_t *buf;
     64 	register struct opaque_auth *oa;
     65 
     66 	if (xdrs->x_op == XDR_ENCODE) {
     67 		if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) {
     68 			return (FALSE);
     69 		}
     70 		if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) {
     71 			return (FALSE);
     72 		}
     73 		buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT
     74 			+ RNDUP(cmsg->rm_call.cb_cred.oa_length)
     75 			+ 2 * BYTES_PER_XDR_UNIT
     76 			+ RNDUP(cmsg->rm_call.cb_verf.oa_length));
     77 		if (buf != NULL) {
     78 			IXDR_PUT_LONG(buf, cmsg->rm_xid);
     79 			IXDR_PUT_ENUM(buf, cmsg->rm_direction);
     80 			if (cmsg->rm_direction != CALL) {
     81 				return (FALSE);
     82 			}
     83 			IXDR_PUT_LONG(buf, cmsg->rm_call.cb_rpcvers);
     84 			if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
     85 				return (FALSE);
     86 			}
     87 			IXDR_PUT_LONG(buf, cmsg->rm_call.cb_prog);
     88 			IXDR_PUT_LONG(buf, cmsg->rm_call.cb_vers);
     89 			IXDR_PUT_LONG(buf, cmsg->rm_call.cb_proc);
     90 			oa = &cmsg->rm_call.cb_cred;
     91 			IXDR_PUT_ENUM(buf, oa->oa_flavor);
     92 			IXDR_PUT_LONG(buf, oa->oa_length);
     93 			if (oa->oa_length) {
     94 				bcopy(oa->oa_base, (caddr_t)buf, oa->oa_length);
     95 				buf += RNDUP(oa->oa_length) / sizeof (int32_t);
     96 			}
     97 			oa = &cmsg->rm_call.cb_verf;
     98 			IXDR_PUT_ENUM(buf, oa->oa_flavor);
     99 			IXDR_PUT_LONG(buf, oa->oa_length);
    100 			if (oa->oa_length) {
    101 				bcopy(oa->oa_base, (caddr_t)buf, oa->oa_length);
    102 				/* no real need....
    103 				buf += RNDUP(oa->oa_length) / sizeof (int32_t);
    104 				*/
    105 			}
    106 			return (TRUE);
    107 		}
    108 	}
    109 	if (xdrs->x_op == XDR_DECODE) {
    110 		buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT);
    111 		if (buf != NULL) {
    112 			cmsg->rm_xid = IXDR_GET_LONG(buf);
    113 			cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type);
    114 			if (cmsg->rm_direction != CALL) {
    115 				return (FALSE);
    116 			}
    117 			cmsg->rm_call.cb_rpcvers = IXDR_GET_LONG(buf);
    118 			if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
    119 				return (FALSE);
    120 			}
    121 			cmsg->rm_call.cb_prog = IXDR_GET_LONG(buf);
    122 			cmsg->rm_call.cb_vers = IXDR_GET_LONG(buf);
    123 			cmsg->rm_call.cb_proc = IXDR_GET_LONG(buf);
    124 			oa = &cmsg->rm_call.cb_cred;
    125 			oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
    126 			oa->oa_length = IXDR_GET_LONG(buf);
    127 			if (oa->oa_length) {
    128 				if (oa->oa_length > MAX_AUTH_BYTES) {
    129 					return (FALSE);
    130 				}
    131 				if (oa->oa_base == NULL) {
    132 					oa->oa_base = (caddr_t)
    133 						mem_alloc(oa->oa_length);
    134 				}
    135 				buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
    136 				if (buf == NULL) {
    137 					if (xdr_opaque(xdrs, oa->oa_base,
    138 					    oa->oa_length) == FALSE) {
    139 						return (FALSE);
    140 					}
    141 				} else {
    142 					bcopy((caddr_t)buf, oa->oa_base,
    143 					    oa->oa_length);
    144 					/* no real need....
    145 					buf += RNDUP(oa->oa_length) /
    146 						sizeof (int32_t);
    147 					*/
    148 				}
    149 			}
    150 			oa = &cmsg->rm_call.cb_verf;
    151 			buf = XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT);
    152 			if (buf == NULL) {
    153 				if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE ||
    154 				    xdr_u_int(xdrs, &oa->oa_length) == FALSE) {
    155 					return (FALSE);
    156 				}
    157 			} else {
    158 				oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
    159 				oa->oa_length = IXDR_GET_LONG(buf);
    160 			}
    161 			if (oa->oa_length) {
    162 				if (oa->oa_length > MAX_AUTH_BYTES) {
    163 					return (FALSE);
    164 				}
    165 				if (oa->oa_base == NULL) {
    166 					oa->oa_base = (caddr_t)
    167 						mem_alloc(oa->oa_length);
    168 				}
    169 				buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
    170 				if (buf == NULL) {
    171 					if (xdr_opaque(xdrs, oa->oa_base,
    172 					    oa->oa_length) == FALSE) {
    173 						return (FALSE);
    174 					}
    175 				} else {
    176 					bcopy((caddr_t)buf, oa->oa_base,
    177 					    oa->oa_length);
    178 					/* no real need...
    179 					buf += RNDUP(oa->oa_length) /
    180 						sizeof (int32_t);
    181 					*/
    182 				}
    183 			}
    184 			return (TRUE);
    185 		}
    186 	}
    187 	if (
    188 	    xdr_u_int32_t(xdrs, &(cmsg->rm_xid)) &&
    189 	    xdr_enum(xdrs, (enum_t *)&(cmsg->rm_direction)) &&
    190 	    (cmsg->rm_direction == CALL) &&
    191 	    xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
    192 	    (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) &&
    193 	    xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_prog)) &&
    194 	    xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers)) &&
    195 	    xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_proc)) &&
    196 	    xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred)) )
    197 	    return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf)));
    198 	return (FALSE);
    199 }
    200 
    201