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