rpc_callmsg.c 5.5 KB

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