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