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