| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
#include <assert.h> |
| 37 |
#include <stdlib.h> |
| 38 |
#include <string.h> |
| 39 |
|
| 40 |
#include <rpc/rpc.h> |
| 41 |
#include <rpc/xdr.h> |
| 42 |
|
| 43 |
#include <sys/select.h> |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
bool_t |
| 49 |
xdr_callmsg(xdrs, cmsg) |
| 50 |
XDR *xdrs; |
| 51 |
struct rpc_msg *cmsg; |
| 52 |
{ |
| 53 |
int32_t *buf; |
| 54 |
struct opaque_auth *oa; |
| 55 |
|
| 56 |
assert(xdrs != NULL); |
| 57 |
assert(cmsg != NULL); |
| 58 |
|
| 59 |
if (xdrs->x_op == XDR_ENCODE) { |
| 60 |
if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) { |
| 61 |
return (FALSE); |
| 62 |
} |
| 63 |
if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) { |
| 64 |
return (FALSE); |
| 65 |
} |
| 66 |
buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT |
| 67 |
+ RNDUP(cmsg->rm_call.cb_cred.oa_length) |
| 68 |
+ 2 * BYTES_PER_XDR_UNIT |
| 69 |
+ RNDUP(cmsg->rm_call.cb_verf.oa_length)); |
| 70 |
if (buf != NULL) { |
| 71 |
IXDR_PUT_INT32(buf, cmsg->rm_xid); |
| 72 |
IXDR_PUT_ENUM(buf, cmsg->rm_direction); |
| 73 |
if (cmsg->rm_direction != CALL) { |
| 74 |
return (FALSE); |
| 75 |
} |
| 76 |
IXDR_PUT_INT32(buf, cmsg->rm_call.cb_rpcvers); |
| 77 |
if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) { |
| 78 |
return (FALSE); |
| 79 |
} |
| 80 |
IXDR_PUT_INT32(buf, cmsg->rm_call.cb_prog); |
| 81 |
IXDR_PUT_INT32(buf, cmsg->rm_call.cb_vers); |
| 82 |
IXDR_PUT_INT32(buf, cmsg->rm_call.cb_proc); |
| 83 |
oa = &cmsg->rm_call.cb_cred; |
| 84 |
IXDR_PUT_ENUM(buf, oa->oa_flavor); |
| 85 |
IXDR_PUT_INT32(buf, oa->oa_length); |
| 86 |
if (oa->oa_length) { |
| 87 |
memmove(buf, oa->oa_base, oa->oa_length); |
| 88 |
buf += RNDUP(oa->oa_length) / sizeof (int32_t); |
| 89 |
} |
| 90 |
oa = &cmsg->rm_call.cb_verf; |
| 91 |
IXDR_PUT_ENUM(buf, oa->oa_flavor); |
| 92 |
IXDR_PUT_INT32(buf, oa->oa_length); |
| 93 |
if (oa->oa_length) { |
| 94 |
memmove(buf, oa->oa_base, oa->oa_length); |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
} |
| 99 |
return (TRUE); |
| 100 |
} |
| 101 |
} |
| 102 |
if (xdrs->x_op == XDR_DECODE) { |
| 103 |
buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT); |
| 104 |
if (buf != NULL) { |
| 105 |
cmsg->rm_xid = IXDR_GET_U_INT32(buf); |
| 106 |
cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type); |
| 107 |
if (cmsg->rm_direction != CALL) { |
| 108 |
return (FALSE); |
| 109 |
} |
| 110 |
cmsg->rm_call.cb_rpcvers = IXDR_GET_U_INT32(buf); |
| 111 |
if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) { |
| 112 |
return (FALSE); |
| 113 |
} |
| 114 |
cmsg->rm_call.cb_prog = IXDR_GET_U_INT32(buf); |
| 115 |
cmsg->rm_call.cb_vers = IXDR_GET_U_INT32(buf); |
| 116 |
cmsg->rm_call.cb_proc = IXDR_GET_U_INT32(buf); |
| 117 |
oa = &cmsg->rm_call.cb_cred; |
| 118 |
oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t); |
| 119 |
oa->oa_length = (u_int)IXDR_GET_U_INT32(buf); |
| 120 |
if (oa->oa_length) { |
| 121 |
if (oa->oa_length > MAX_AUTH_BYTES) { |
| 122 |
return (FALSE); |
| 123 |
} |
| 124 |
if (oa->oa_base == NULL) { |
| 125 |
oa->oa_base = (caddr_t) |
| 126 |
mem_alloc(oa->oa_length); |
| 127 |
if (oa->oa_base == NULL) |
| 128 |
return (FALSE); |
| 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 |
memmove(oa->oa_base, buf, |
| 138 |
oa->oa_length); |
| 139 |
|
| 140 |
|
| 141 |
|
| 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 = (u_int)IXDR_GET_U_INT32(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 |
if (oa->oa_base == NULL) |
| 164 |
return (FALSE); |
| 165 |
} |
| 166 |
buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length)); |
| 167 |
if (buf == NULL) { |
| 168 |
if (xdr_opaque(xdrs, oa->oa_base, |
| 169 |
oa->oa_length) == FALSE) { |
| 170 |
return (FALSE); |
| 171 |
} |
| 172 |
} else { |
| 173 |
memmove(oa->oa_base, buf, |
| 174 |
oa->oa_length); |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
} |
| 180 |
} |
| 181 |
return (TRUE); |
| 182 |
} |
| 183 |
} |
| 184 |
if ( |
| 185 |
xdr_u_int32_t(xdrs, &(cmsg->rm_xid)) && |
| 186 |
xdr_enum(xdrs, (enum_t *)&(cmsg->rm_direction)) && |
| 187 |
(cmsg->rm_direction == CALL) && |
| 188 |
xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) && |
| 189 |
(cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) && |
| 190 |
xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_prog)) && |
| 191 |
xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers)) && |
| 192 |
xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_proc)) && |
| 193 |
xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred)) ) |
| 194 |
return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf))); |
| 195 |
return (FALSE); |
| 196 |
} |