1 /* $NetBSD: rpc_callmsg.c,v 1.13 1999/09/16 11:45:24 lukem 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.13 1999/09/16 11:45:24 lukem Exp $"); 39 #endif 40 #endif 41 42 /* 43 * rpc_callmsg.c 44 * 45 * Copyright (C) 1984, Sun Microsystems, Inc. 46 * 47 */ 48 49 #include "namespace.h" 50 51 #include <sys/param.h> 52 53 #include <assert.h> 54 #include <stdlib.h> 55 #include <string.h> 56 57 #include <rpc/rpc.h> 58 59 #ifdef __weak_alias 60 __weak_alias(xdr_callmsg,_xdr_callmsg); 61 #endif 62 63 /* 64 * XDR a call message 65 */ 66 bool_t 67 xdr_callmsg(xdrs, cmsg) 68 XDR *xdrs; 69 struct rpc_msg *cmsg; 70 { 71 int32_t *buf; 72 struct opaque_auth *oa; 73 74 _DIAGASSERT(xdrs != NULL); 75 _DIAGASSERT(cmsg != NULL); 76 #ifdef _DIAGNOSTIC 77 if (xdrs == NULL || cmsg == NULL) 78 return (FALSE); 79 #endif 80 81 if (xdrs->x_op == XDR_ENCODE) { 82 if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) { 83 return (FALSE); 84 } 85 if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) { 86 return (FALSE); 87 } 88 buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT 89 + RNDUP(cmsg->rm_call.cb_cred.oa_length) 90 + 2 * BYTES_PER_XDR_UNIT 91 + RNDUP(cmsg->rm_call.cb_verf.oa_length)); 92 if (buf != NULL) { 93 IXDR_PUT_LONG(buf, cmsg->rm_xid); 94 IXDR_PUT_ENUM(buf, cmsg->rm_direction); 95 if (cmsg->rm_direction != CALL) { 96 return (FALSE); 97 } 98 IXDR_PUT_LONG(buf, cmsg->rm_call.cb_rpcvers); 99 if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) { 100 return (FALSE); 101 } 102 IXDR_PUT_LONG(buf, cmsg->rm_call.cb_prog); 103 IXDR_PUT_LONG(buf, cmsg->rm_call.cb_vers); 104 IXDR_PUT_LONG(buf, cmsg->rm_call.cb_proc); 105 oa = &cmsg->rm_call.cb_cred; 106 IXDR_PUT_ENUM(buf, oa->oa_flavor); 107 IXDR_PUT_LONG(buf, oa->oa_length); 108 if (oa->oa_length) { 109 memmove(buf, oa->oa_base, oa->oa_length); 110 buf += RNDUP(oa->oa_length) / sizeof (int32_t); 111 } 112 oa = &cmsg->rm_call.cb_verf; 113 IXDR_PUT_ENUM(buf, oa->oa_flavor); 114 IXDR_PUT_LONG(buf, oa->oa_length); 115 if (oa->oa_length) { 116 memmove(buf, oa->oa_base, oa->oa_length); 117 /* no real need.... 118 buf += RNDUP(oa->oa_length) / sizeof (int32_t); 119 */ 120 } 121 return (TRUE); 122 } 123 } 124 if (xdrs->x_op == XDR_DECODE) { 125 buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT); 126 if (buf != NULL) { 127 cmsg->rm_xid = (u_int32_t)IXDR_GET_LONG(buf); 128 cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type); 129 if (cmsg->rm_direction != CALL) { 130 return (FALSE); 131 } 132 cmsg->rm_call.cb_rpcvers = 133 (u_int32_t)IXDR_GET_LONG(buf); 134 if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) { 135 return (FALSE); 136 } 137 cmsg->rm_call.cb_prog = 138 (u_int32_t)IXDR_GET_LONG(buf); 139 cmsg->rm_call.cb_vers = 140 (u_int32_t)IXDR_GET_LONG(buf); 141 cmsg->rm_call.cb_proc = 142 (u_int32_t)IXDR_GET_LONG(buf); 143 oa = &cmsg->rm_call.cb_cred; 144 oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t); 145 oa->oa_length = (u_int)IXDR_GET_LONG(buf); 146 if (oa->oa_length) { 147 if (oa->oa_length > MAX_AUTH_BYTES) { 148 return (FALSE); 149 } 150 if (oa->oa_base == NULL) { 151 oa->oa_base = (caddr_t) 152 mem_alloc(oa->oa_length); 153 if (oa->oa_base == NULL) 154 return (FALSE); 155 } 156 buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length)); 157 if (buf == NULL) { 158 if (xdr_opaque(xdrs, oa->oa_base, 159 oa->oa_length) == FALSE) { 160 return (FALSE); 161 } 162 } else { 163 memmove(oa->oa_base, buf, 164 oa->oa_length); 165 /* no real need.... 166 buf += RNDUP(oa->oa_length) / 167 sizeof (int32_t); 168 */ 169 } 170 } 171 oa = &cmsg->rm_call.cb_verf; 172 buf = XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT); 173 if (buf == NULL) { 174 if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE || 175 xdr_u_int(xdrs, &oa->oa_length) == FALSE) { 176 return (FALSE); 177 } 178 } else { 179 oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t); 180 oa->oa_length = (u_int)IXDR_GET_LONG(buf); 181 } 182 if (oa->oa_length) { 183 if (oa->oa_length > MAX_AUTH_BYTES) { 184 return (FALSE); 185 } 186 if (oa->oa_base == NULL) { 187 oa->oa_base = (caddr_t) 188 mem_alloc(oa->oa_length); 189 if (oa->oa_base == NULL) 190 return (FALSE); 191 } 192 buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length)); 193 if (buf == NULL) { 194 if (xdr_opaque(xdrs, oa->oa_base, 195 oa->oa_length) == FALSE) { 196 return (FALSE); 197 } 198 } else { 199 memmove(oa->oa_base, buf, 200 oa->oa_length); 201 /* no real need... 202 buf += RNDUP(oa->oa_length) / 203 sizeof (int32_t); 204 */ 205 } 206 } 207 return (TRUE); 208 } 209 } 210 if ( 211 xdr_u_int32_t(xdrs, &(cmsg->rm_xid)) && 212 xdr_enum(xdrs, (enum_t *)&(cmsg->rm_direction)) && 213 (cmsg->rm_direction == CALL) && 214 xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) && 215 (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) && 216 xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_prog)) && 217 xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers)) && 218 xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_proc)) && 219 xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred)) ) 220 return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf))); 221 return (FALSE); 222 } 223