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