svc_auth.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #if !defined(lint) && defined(SCCSIDS)
  2. static char sccsid[] = "@(#)svc_auth.c 2.1 88/08/07 4.0 RPCSRC; from 1.19 87/08/11 Copyr 1984 Sun Micro";
  3. #endif
  4. /*
  5. * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  6. * unrestricted use provided that this legend is included on all tape
  7. * media and as a part of the software program in whole or part. Users
  8. * may copy or modify Sun RPC without charge, but are not authorized
  9. * to license or distribute it to anyone else except as part of a product or
  10. * program developed by the user.
  11. *
  12. * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  13. * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  14. * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  15. *
  16. * Sun RPC is provided with no support and without any obligation on the
  17. * part of Sun Microsystems, Inc. to assist in its use, correction,
  18. * modification or enhancement.
  19. *
  20. * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  21. * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  22. * OR ANY PART THEREOF.
  23. *
  24. * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  25. * or profits or other special, indirect and consequential damages, even if
  26. * Sun has been advised of the possibility of such damages.
  27. *
  28. * Sun Microsystems, Inc.
  29. * 2550 Garcia Avenue
  30. * Mountain View, California 94043
  31. */
  32. /*
  33. * svc_auth_nodes.c, Server-side rpc authenticator interface,
  34. * *WITHOUT* DES authentication.
  35. *
  36. * Copyright (C) 1984, Sun Microsystems, Inc.
  37. */
  38. #include <rpc/rpc.h>
  39. /*
  40. * svcauthsw is the bdevsw of server side authentication.
  41. *
  42. * Server side authenticators are called from authenticate by
  43. * using the client auth struct flavor field to index into svcauthsw.
  44. * The server auth flavors must implement a routine that looks
  45. * like:
  46. *
  47. * enum auth_stat
  48. * flavorx_auth(rqst, msg)
  49. * register struct svc_req *rqst;
  50. * register struct rpc_msg *msg;
  51. *
  52. */
  53. enum auth_stat _svcauth_null(); /* no authentication */
  54. enum auth_stat _svcauth_unix(); /* unix style (uid, gids) */
  55. enum auth_stat _svcauth_short(); /* short hand unix style */
  56. static struct {
  57. enum auth_stat (*authenticator)();
  58. } svcauthsw[] = {
  59. _svcauth_null, /* AUTH_NULL */
  60. _svcauth_unix, /* AUTH_UNIX */
  61. _svcauth_short, /* AUTH_SHORT */
  62. };
  63. #define AUTH_MAX 2 /* HIGHEST AUTH NUMBER */
  64. /*
  65. * The call rpc message, msg has been obtained from the wire. The msg contains
  66. * the raw form of credentials and verifiers. authenticate returns AUTH_OK
  67. * if the msg is successfully authenticated. If AUTH_OK then the routine also
  68. * does the following things:
  69. * set rqst->rq_xprt->verf to the appropriate response verifier;
  70. * sets rqst->rq_client_cred to the "cooked" form of the credentials.
  71. *
  72. * NB: rqst->rq_cxprt->verf must be pre-alloctaed;
  73. * its length is set appropriately.
  74. *
  75. * The caller still owns and is responsible for msg->u.cmb.cred and
  76. * msg->u.cmb.verf. The authentication system retains ownership of
  77. * rqst->rq_client_cred, the cooked credentials.
  78. *
  79. * There is an assumption that any flavour less than AUTH_NULL is
  80. * invalid.
  81. */
  82. enum auth_stat
  83. _authenticate(rqst, msg)
  84. register struct svc_req *rqst;
  85. struct rpc_msg *msg;
  86. {
  87. register int cred_flavor;
  88. rqst->rq_cred = msg->rm_call.cb_cred;
  89. rqst->rq_xprt->xp_verf.oa_flavor = _null_auth.oa_flavor;
  90. rqst->rq_xprt->xp_verf.oa_length = 0;
  91. cred_flavor = rqst->rq_cred.oa_flavor;
  92. if ((cred_flavor <= AUTH_MAX) && (cred_flavor >= AUTH_NULL)) {
  93. return ((*(svcauthsw[cred_flavor].authenticator))(rqst, msg));
  94. }
  95. return (AUTH_REJECTEDCRED);
  96. }
  97. enum auth_stat
  98. _svcauth_null(/*rqst, msg*/)
  99. /*struct svc_req *rqst;
  100. struct rpc_msg *msg;*/
  101. {
  102. return (AUTH_OK);
  103. }