home *** CD-ROM | disk | FTP | other *** search
/ Serving the Web / ServingTheWeb1995.disc1of1.iso / linux / slacksrce / d / libc / libc-4.6 / libc-4 / libc-linux / rpc / svc_auth.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-15  |  3.7 KB  |  117 lines

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