svc_auth.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* @(#)svc_auth.c 2.4 88/08/15 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[] = "@(#)svc_auth.c 1.19 87/08/11 Copyr 1984 Sun Micro";
  32. #endif
  33. /*
  34. * svc_auth.c, Server-side rpc authenticator interface.
  35. *
  36. * Copyright (C) 1984, Sun Microsystems, Inc.
  37. */
  38. #include <rpc/rpc.h>
  39. #include <rpc/svc.h>
  40. #include <rpc/svc_auth.h>
  41. /*
  42. * svcauthsw is the bdevsw of server side authentication.
  43. *
  44. * Server side authenticators are called from authenticate by
  45. * using the client auth struct flavor field to index into svcauthsw.
  46. * The server auth flavors must implement a routine that looks
  47. * like:
  48. *
  49. * enum auth_stat
  50. * flavorx_auth(rqst, msg)
  51. * register struct svc_req *rqst;
  52. * register struct rpc_msg *msg;
  53. *
  54. */
  55. static enum auth_stat _svcauth_null (struct svc_req *, struct rpc_msg *);
  56. /* no authentication */
  57. extern enum auth_stat _svcauth_unix (struct svc_req *, struct rpc_msg *);
  58. /* unix style (uid, gids) */
  59. extern enum auth_stat _svcauth_short (struct svc_req *, struct rpc_msg *);
  60. /* short hand unix style */
  61. #ifdef CONFIG_AUTH_DES
  62. extern enum auth_stat _svcauth_des (struct svc_req *, struct rpc_msg *);
  63. /* des style */
  64. #endif
  65. static const struct
  66. {
  67. enum auth_stat (*authenticator) (struct svc_req *, struct rpc_msg *);
  68. }
  69. svcauthsw[] =
  70. {
  71. { _svcauth_null }, /* AUTH_NULL */
  72. { _svcauth_unix }, /* AUTH_UNIX */
  73. { _svcauth_short }, /* AUTH_SHORT */
  74. #ifdef CONFIG_AUTH_DES
  75. { _svcauth_des } /* AUTH_DES */
  76. #endif
  77. };
  78. #define AUTH_MAX 3 /* HIGHEST AUTH NUMBER */
  79. /*
  80. * The call rpc message, msg has been obtained from the wire. The msg contains
  81. * the raw form of credentials and verifiers. authenticate returns AUTH_OK
  82. * if the msg is successfully authenticated. If AUTH_OK then the routine also
  83. * does the following things:
  84. * set rqst->rq_xprt->verf to the appropriate response verifier;
  85. * sets rqst->rq_client_cred to the "cooked" form of the credentials.
  86. *
  87. * NB: rqst->rq_cxprt->verf must be pre-allocated;
  88. * its length is set appropriately.
  89. *
  90. * The caller still owns and is responsible for msg->u.cmb.cred and
  91. * msg->u.cmb.verf. The authentication system retains ownership of
  92. * rqst->rq_client_cred, the cooked credentials.
  93. *
  94. * There is an assumption that any flavour less than AUTH_NULL is
  95. * invalid.
  96. */
  97. enum auth_stat
  98. _authenticate (register struct svc_req *rqst, struct rpc_msg *msg)
  99. {
  100. register int cred_flavor;
  101. rqst->rq_cred = msg->rm_call.cb_cred;
  102. rqst->rq_xprt->xp_verf.oa_flavor = _null_auth.oa_flavor;
  103. rqst->rq_xprt->xp_verf.oa_length = 0;
  104. cred_flavor = rqst->rq_cred.oa_flavor;
  105. if ((cred_flavor <= AUTH_MAX) && (cred_flavor >= AUTH_NULL))
  106. return (*(svcauthsw[cred_flavor].authenticator)) (rqst, msg);
  107. return AUTH_REJECTEDCRED;
  108. }
  109. static enum auth_stat
  110. _svcauth_null (struct svc_req *rqst, struct rpc_msg *msg)
  111. {
  112. return AUTH_OK;
  113. }