rpc_callmsg.c 6.0 KB

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