rpc_callmsg.c 5.6 KB

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