rpc_cmsg.c 6.0 KB

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