svc_auth.c 3.6 KB

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