svc_auth_unix.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* @(#)svc_auth_unix.c 2.3 88/08/01 4.0 RPCSRC; from 1.28 88/02/08 SMI */
  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 !defined(lint) && defined(SCCSIDS)
  31. static char sccsid[] =
  32. "@(#)svc_auth_unix.c 1.28 88/02/08 Copyr 1984 Sun Micro";
  33. #endif
  34. /*
  35. * svc_auth_unix.c
  36. * Handles UNIX flavor authentication parameters on the service side of rpc.
  37. * There are two svc auth implementations here: AUTH_UNIX and AUTH_SHORT.
  38. * _svcauth_unix does full blown unix style uid,gid+gids auth,
  39. * _svcauth_short uses a shorthand auth to index into a cache of longhand auths.
  40. * Note: the shorthand has been gutted for efficiency.
  41. *
  42. * Copyright (C) 1984, Sun Microsystems, Inc.
  43. */
  44. #include <stdio.h>
  45. #include <rpc/rpc.h>
  46. /*
  47. * Unix longhand authenticator
  48. */
  49. enum auth_stat _svcauth_unix(rqst, msg)
  50. register struct svc_req *rqst;
  51. register struct rpc_msg *msg;
  52. {
  53. register enum auth_stat stat;
  54. XDR xdrs;
  55. register struct authunix_parms *aup;
  56. register long *buf;
  57. struct area {
  58. struct authunix_parms area_aup;
  59. char area_machname[MAX_MACHINE_NAME + 1];
  60. int area_gids[NGRPS];
  61. } *area;
  62. u_int auth_len;
  63. int str_len, gid_len;
  64. register 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,
  71. XDR_DECODE);
  72. buf = XDR_INLINE(&xdrs, auth_len);
  73. if (buf != NULL) {
  74. aup->aup_time = IXDR_GET_LONG(buf);
  75. str_len = IXDR_GET_U_LONG(buf);
  76. if (str_len > MAX_MACHINE_NAME) {
  77. stat = AUTH_BADCRED;
  78. goto done;
  79. }
  80. bcopy((caddr_t) buf, aup->aup_machname, (u_int) str_len);
  81. aup->aup_machname[str_len] = 0;
  82. str_len = RNDUP(str_len);
  83. buf += str_len / sizeof(long);
  84. aup->aup_uid = IXDR_GET_LONG(buf);
  85. aup->aup_gid = IXDR_GET_LONG(buf);
  86. gid_len = IXDR_GET_U_LONG(buf);
  87. if (gid_len > NGRPS) {
  88. stat = AUTH_BADCRED;
  89. goto done;
  90. }
  91. aup->aup_len = gid_len;
  92. for (i = 0; i < gid_len; i++) {
  93. aup->aup_gids[i] = IXDR_GET_LONG(buf);
  94. }
  95. /*
  96. * five is the smallest unix credentials structure -
  97. * timestamp, hostname len (0), uid, gid, and gids len (0).
  98. */
  99. if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len) {
  100. (void) printf("bad auth_len gid %d str %d auth %d\n",
  101. gid_len, str_len, auth_len);
  102. stat = AUTH_BADCRED;
  103. goto done;
  104. }
  105. } else if (!xdr_authunix_parms(&xdrs, aup)) {
  106. xdrs.x_op = XDR_FREE;
  107. (void) xdr_authunix_parms(&xdrs, aup);
  108. stat = AUTH_BADCRED;
  109. goto done;
  110. }
  111. rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL;
  112. rqst->rq_xprt->xp_verf.oa_length = 0;
  113. stat = AUTH_OK;
  114. done:
  115. XDR_DESTROY(&xdrs);
  116. return (stat);
  117. }
  118. /*
  119. * Shorthand unix authenticator
  120. * Looks up longhand in a cache.
  121. */
  122. /*ARGSUSED*/ enum auth_stat _svcauth_short(rqst, msg)
  123. struct svc_req *rqst;
  124. struct rpc_msg *msg;
  125. {
  126. return (AUTH_REJECTEDCRED);
  127. }