rpc_callmsg.c 5.7 KB

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