1 /* $NetBSD: rpc_callmsg.c,v 1.5 1996/12/20 20:47:59 cgd 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 #if defined(LIBC_SCCS) && !defined(lint) 33 /*static char *sccsid = "from: @(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro";*/ 34 /*static char *sccsid = "from: @(#)rpc_callmsg.c 2.1 88/07/29 4.0 RPCSRC";*/ 35 static char *rcsid = "$NetBSD: rpc_callmsg.c,v 1.5 1996/12/20 20:47:59 cgd Exp $"; 36 #endif 37 38 /* 39 * rpc_callmsg.c 40 * 41 * Copyright (C) 1984, Sun Microsystems, Inc. 42 * 43 */ 44 45 #include <stdlib.h> 46 #include <string.h> 47 #include <sys/param.h> 48 49 #include <rpc/rpc.h> 50 51 /* 52 * XDR a call message 53 */ 54 bool_t 55 xdr_callmsg(xdrs, cmsg) 56 register XDR *xdrs; 57 register struct rpc_msg *cmsg; 58 { 59 register int32_t *buf; 60 register struct opaque_auth *oa; 61 62 if (xdrs->x_op == XDR_ENCODE) { 63 if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) { 64 return (FALSE); 65 } 66 if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) { 67 return (FALSE); 68 } 69 buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT 70 + RNDUP(cmsg->rm_call.cb_cred.oa_length) 71 + 2 * BYTES_PER_XDR_UNIT 72 + RNDUP(cmsg->rm_call.cb_verf.oa_length)); 73 if (buf != NULL) { 74 IXDR_PUT_LONG(buf, cmsg->rm_xid); 75 IXDR_PUT_ENUM(buf, cmsg->rm_direction); 76 if (cmsg->rm_direction != CALL) { 77 return (FALSE); 78 } 79 IXDR_PUT_LONG(buf, cmsg->rm_call.cb_rpcvers); 80 if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) { 81 return (FALSE); 82 } 83 IXDR_PUT_LONG(buf, cmsg->rm_call.cb_prog); 84 IXDR_PUT_LONG(buf, cmsg->rm_call.cb_vers); 85 IXDR_PUT_LONG(buf, cmsg->rm_call.cb_proc); 86 oa = &cmsg->rm_call.cb_cred; 87 IXDR_PUT_ENUM(buf, oa->oa_flavor); 88 IXDR_PUT_LONG(buf, oa->oa_length); 89 if (oa->oa_length) { 90 bcopy(oa->oa_base, (caddr_t)buf, oa->oa_length); 91 buf += RNDUP(oa->oa_length) / sizeof (int32_t); 92 } 93 oa = &cmsg->rm_call.cb_verf; 94 IXDR_PUT_ENUM(buf, oa->oa_flavor); 95 IXDR_PUT_LONG(buf, oa->oa_length); 96 if (oa->oa_length) { 97 bcopy(oa->oa_base, (caddr_t)buf, oa->oa_length); 98 /* no real need.... 99 buf += RNDUP(oa->oa_length) / sizeof (int32_t); 100 */ 101 } 102 return (TRUE); 103 } 104 } 105 if (xdrs->x_op == XDR_DECODE) { 106 buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT); 107 if (buf != NULL) { 108 cmsg->rm_xid = IXDR_GET_LONG(buf); 109 cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type); 110 if (cmsg->rm_direction != CALL) { 111 return (FALSE); 112 } 113 cmsg->rm_call.cb_rpcvers = IXDR_GET_LONG(buf); 114 if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) { 115 return (FALSE); 116 } 117 cmsg->rm_call.cb_prog = IXDR_GET_LONG(buf); 118 cmsg->rm_call.cb_vers = IXDR_GET_LONG(buf); 119 cmsg->rm_call.cb_proc = IXDR_GET_LONG(buf); 120 oa = &cmsg->rm_call.cb_cred; 121 oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t); 122 oa->oa_length = IXDR_GET_LONG(buf); 123 if (oa->oa_length) { 124 if (oa->oa_length > MAX_AUTH_BYTES) { 125 return (FALSE); 126 } 127 if (oa->oa_base == NULL) { 128 oa->oa_base = (caddr_t) 129 mem_alloc(oa->oa_length); 130 } 131 buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length)); 132 if (buf == NULL) { 133 if (xdr_opaque(xdrs, oa->oa_base, 134 oa->oa_length) == FALSE) { 135 return (FALSE); 136 } 137 } else { 138 bcopy((caddr_t)buf, oa->oa_base, 139 oa->oa_length); 140 /* no real need.... 141 buf += RNDUP(oa->oa_length) / 142 sizeof (int32_t); 143 */ 144 } 145 } 146 oa = &cmsg->rm_call.cb_verf; 147 buf = XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT); 148 if (buf == NULL) { 149 if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE || 150 xdr_u_int(xdrs, &oa->oa_length) == FALSE) { 151 return (FALSE); 152 } 153 } else { 154 oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t); 155 oa->oa_length = IXDR_GET_LONG(buf); 156 } 157 if (oa->oa_length) { 158 if (oa->oa_length > MAX_AUTH_BYTES) { 159 return (FALSE); 160 } 161 if (oa->oa_base == NULL) { 162 oa->oa_base = (caddr_t) 163 mem_alloc(oa->oa_length); 164 } 165 buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length)); 166 if (buf == NULL) { 167 if (xdr_opaque(xdrs, oa->oa_base, 168 oa->oa_length) == FALSE) { 169 return (FALSE); 170 } 171 } else { 172 bcopy((caddr_t)buf, oa->oa_base, 173 oa->oa_length); 174 /* no real need... 175 buf += RNDUP(oa->oa_length) / 176 sizeof (int32_t); 177 */ 178 } 179 } 180 return (TRUE); 181 } 182 } 183 if ( 184 xdr_u_int32_t(xdrs, &(cmsg->rm_xid)) && 185 xdr_enum(xdrs, (enum_t *)&(cmsg->rm_direction)) && 186 (cmsg->rm_direction == CALL) && 187 xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) && 188 (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) && 189 xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_prog)) && 190 xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers)) && 191 xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_proc)) && 192 xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred)) ) 193 return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf))); 194 return (FALSE); 195 } 196 197