home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / comm / tcp / amitcp-sdk / src / rpclib / svc_auth.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-29  |  2.7 KB  |  92 lines

  1. /*
  2.  *      $Id: svc_auth.c,v 4.2 1994/09/29 23:48:50 jraja Exp $
  3.  *
  4.  *      Server-side rpc authenticator interface, *WITHOUT* DES authentication.
  5.  *
  6.  *      Copyright © 1994 AmiTCP/IP Group,
  7.  *                       Network Solutions Development Inc.
  8.  *                       All rights reserved. 
  9.  */
  10.  
  11. #if !defined(lint) && defined(SCCSIDS)
  12. static char sccsid[] = "@(#)svc_auth.c    2.1 88/08/07 4.0 RPCSRC; from 1.19 87/08/11 Copyr 1984 Sun Micro";
  13. #endif
  14.  
  15. /*
  16.  * Copyright (C) 1984, Sun Microsystems, Inc.
  17.  */
  18.  
  19. #include <sys/param.h>
  20. #include <rpc/rpc.h>
  21.  
  22. /*
  23.  * svcauthsw is the bdevsw of server side authentication. 
  24.  * 
  25.  * Server side authenticators are called from authenticate by
  26.  * using the client auth struct flavor field to index into svcauthsw.
  27.  * The server auth flavors must implement a routine that looks  
  28.  * like: 
  29.  * 
  30.  *    enum auth_stat
  31.  *    flavorx_auth(rqst, msg)
  32.  *        register struct svc_req *rqst; 
  33.  *        register struct rpc_msg *msg;
  34.  *
  35.  */
  36.  
  37. enum auth_stat _svcauth_null();        /* no authentication */
  38. enum auth_stat _svcauth_unix();        /* unix style (uid, gids) */
  39. enum auth_stat _svcauth_short();    /* short hand unix style */
  40.  
  41. static struct {
  42.     enum auth_stat (*authenticator)(struct svc_req *, struct rpc_msg *);
  43. } svcauthsw[] = {
  44.     _svcauth_null,            /* AUTH_NULL */
  45.     _svcauth_unix,            /* AUTH_UNIX */
  46.     _svcauth_short,            /* AUTH_SHORT */
  47. };
  48. #define    AUTH_MAX    2        /* HIGHEST AUTH NUMBER */
  49.  
  50.  
  51. /*
  52.  * The call rpc message, msg has been obtained from the wire.  The msg contains
  53.  * the raw form of credentials and verifiers.  authenticate returns AUTH_OK
  54.  * if the msg is successfully authenticated.  If AUTH_OK then the routine also
  55.  * does the following things:
  56.  * set rqst->rq_xprt->verf to the appropriate response verifier;
  57.  * sets rqst->rq_client_cred to the "cooked" form of the credentials.
  58.  *
  59.  * NB: rqst->rq_cxprt->verf must be pre-alloctaed;
  60.  * its length is set appropriately.
  61.  *
  62.  * The caller still owns and is responsible for msg->u.cmb.cred and
  63.  * msg->u.cmb.verf.  The authentication system retains ownership of
  64.  * rqst->rq_client_cred, the cooked credentials.
  65.  *
  66.  * There is an assumption that any flavour less than AUTH_NULL is
  67.  * invalid.
  68.  */
  69. enum auth_stat
  70. _authenticate(rqst, msg)
  71.     register struct svc_req *rqst;
  72.     struct rpc_msg *msg;
  73. {
  74.     register int cred_flavor;
  75.  
  76.     rqst->rq_cred = msg->rm_call.cb_cred;
  77.     rqst->rq_xprt->xp_verf.oa_flavor = _null_auth.oa_flavor;
  78.     rqst->rq_xprt->xp_verf.oa_length = 0;
  79.     cred_flavor = rqst->rq_cred.oa_flavor;
  80.     if ((cred_flavor <= AUTH_MAX) && (cred_flavor >= AUTH_NULL)) {
  81.         return ((*(svcauthsw[cred_flavor].authenticator))(rqst, msg));
  82.     }
  83.  
  84.     return (AUTH_REJECTEDCRED);
  85. }
  86.  
  87. enum auth_stat
  88. _svcauth_null(struct svc_req *rqst, struct rpc_msg *msg)
  89. {
  90.     return (AUTH_OK);
  91. }
  92.