svc_authux.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  3. * unrestricted use provided that this legend is included on all tape
  4. * media and as a part of the software program in whole or part. Users
  5. * may copy or modify Sun RPC without charge, but are not authorized
  6. * to license or distribute it to anyone else except as part of a product or
  7. * program developed by the user.
  8. *
  9. * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  10. * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  11. * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  12. *
  13. * Sun RPC is provided with no support and without any obligation on the
  14. * part of Sun Microsystems, Inc. to assist in its use, correction,
  15. * modification or enhancement.
  16. *
  17. * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  18. * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  19. * OR ANY PART THEREOF.
  20. *
  21. * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  22. * or profits or other special, indirect and consequential damages, even if
  23. * Sun has been advised of the possibility of such damages.
  24. *
  25. * Sun Microsystems, Inc.
  26. * 2550 Garcia Avenue
  27. * Mountain View, California 94043
  28. */
  29. /*
  30. * svc_auth_unix.c
  31. * Handles UNIX flavor authentication parameters on the service side of rpc.
  32. * There are two svc auth implementations here: AUTH_UNIX and AUTH_SHORT.
  33. * _svcauth_unix does full blown unix style uid,gid+gids auth,
  34. * _svcauth_short uses a shorthand auth to index into a cache of longhand auths.
  35. * Note: the shorthand has been gutted for efficiency.
  36. *
  37. * Copyright (C) 1984, Sun Microsystems, Inc.
  38. */
  39. #include <stdio.h>
  40. #include <string.h>
  41. #include <rpc/rpc.h>
  42. #include <rpc/svc.h>
  43. /*
  44. * Unix longhand authenticator
  45. */
  46. enum auth_stat
  47. _svcauth_unix (struct svc_req *rqst, struct rpc_msg *msg) attribute_hidden;
  48. enum auth_stat
  49. _svcauth_unix (struct svc_req *rqst, struct rpc_msg *msg)
  50. {
  51. enum auth_stat stat;
  52. XDR xdrs;
  53. struct authunix_parms *aup;
  54. int32_t *buf;
  55. struct area
  56. {
  57. struct authunix_parms area_aup;
  58. char area_machname[MAX_MACHINE_NAME + 1];
  59. gid_t area_gids[NGRPS];
  60. }
  61. *area;
  62. u_int auth_len;
  63. u_int str_len, gid_len;
  64. u_int i;
  65. area = (struct area *) rqst->rq_clntcred;
  66. aup = &area->area_aup;
  67. aup->aup_machname = area->area_machname;
  68. aup->aup_gids = area->area_gids;
  69. auth_len = (u_int) msg->rm_call.cb_cred.oa_length;
  70. xdrmem_create (&xdrs, msg->rm_call.cb_cred.oa_base, auth_len, XDR_DECODE);
  71. buf = XDR_INLINE (&xdrs, auth_len);
  72. if (buf != NULL)
  73. {
  74. aup->aup_time = IXDR_GET_LONG (buf);
  75. str_len = IXDR_GET_U_INT32 (buf);
  76. if (str_len > MAX_MACHINE_NAME)
  77. {
  78. stat = AUTH_BADCRED;
  79. goto done;
  80. }
  81. memcpy (aup->aup_machname, (caddr_t) buf, (u_int) str_len);
  82. aup->aup_machname[str_len] = 0;
  83. str_len = RNDUP (str_len);
  84. buf = (int32_t *) ((char *) buf + str_len);
  85. aup->aup_uid = IXDR_GET_LONG (buf);
  86. aup->aup_gid = IXDR_GET_LONG (buf);
  87. gid_len = IXDR_GET_U_INT32 (buf);
  88. if (gid_len > NGRPS)
  89. {
  90. stat = AUTH_BADCRED;
  91. goto done;
  92. }
  93. aup->aup_len = gid_len;
  94. for (i = 0; i < gid_len; i++)
  95. {
  96. aup->aup_gids[i] = IXDR_GET_LONG (buf);
  97. }
  98. /*
  99. * five is the smallest unix credentials structure -
  100. * timestamp, hostname len (0), uid, gid, and gids len (0).
  101. */
  102. if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len)
  103. {
  104. (void) printf ("bad auth_len gid %d str %d auth %d\n",
  105. gid_len, str_len, auth_len);
  106. stat = AUTH_BADCRED;
  107. goto done;
  108. }
  109. }
  110. else if (!xdr_authunix_parms (&xdrs, aup))
  111. {
  112. xdrs.x_op = XDR_FREE;
  113. (void) xdr_authunix_parms (&xdrs, aup);
  114. stat = AUTH_BADCRED;
  115. goto done;
  116. }
  117. /* get the verifier */
  118. if ((u_int)msg->rm_call.cb_verf.oa_length)
  119. {
  120. rqst->rq_xprt->xp_verf.oa_flavor =
  121. msg->rm_call.cb_verf.oa_flavor;
  122. rqst->rq_xprt->xp_verf.oa_base =
  123. msg->rm_call.cb_verf.oa_base;
  124. rqst->rq_xprt->xp_verf.oa_length =
  125. msg->rm_call.cb_verf.oa_length;
  126. }
  127. else
  128. {
  129. rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL;
  130. rqst->rq_xprt->xp_verf.oa_length = 0;
  131. }
  132. stat = AUTH_OK;
  133. done:
  134. XDR_DESTROY (&xdrs);
  135. return stat;
  136. }
  137. /*
  138. * Shorthand unix authenticator
  139. * Looks up longhand in a cache.
  140. */
  141. /*ARGSUSED */
  142. enum auth_stat
  143. _svcauth_short (struct svc_req *rqst attribute_unused, struct rpc_msg *msg attribute_unused) attribute_hidden;
  144. enum auth_stat
  145. _svcauth_short (struct svc_req *rqst attribute_unused, struct rpc_msg *msg attribute_unused)
  146. {
  147. return AUTH_REJECTEDCRED;
  148. }