rpc_cmsg.c 5.7 KB

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