Home | History | Annotate | Line # | Download | only in rpc
svc_auth.c revision 1.10
      1 /*	$NetBSD: svc_auth.c,v 1.10 1999/09/20 04:39:24 lukem Exp $	*/
      2 
      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 #include <sys/cdefs.h>
     33 #if defined(LIBC_SCCS) && !defined(lint)
     34 #if 0
     35 static char *sccsid = "@(#)svc_auth.c 1.19 87/08/11 Copyr 1984 Sun Micro";
     36 static char *sccsid = "@(#)svc_auth.c	2.1 88/08/07 4.0 RPCSRC";
     37 #else
     38 __RCSID("$NetBSD: svc_auth.c,v 1.10 1999/09/20 04:39:24 lukem Exp $");
     39 #endif
     40 #endif
     41 
     42 /*
     43  * svc_auth_nodes.c, Server-side rpc authenticator interface,
     44  * *WITHOUT* DES authentication.
     45  *
     46  * Copyright (C) 1984, Sun Microsystems, Inc.
     47  */
     48 
     49 #include <assert.h>
     50 
     51 #include <rpc/rpc.h>
     52 
     53 /*
     54  * svcauthsw is the bdevsw of server side authentication.
     55  *
     56  * Server side authenticators are called from authenticate by
     57  * using the client auth struct flavor field to index into svcauthsw.
     58  * The server auth flavors must implement a routine that looks
     59  * like:
     60  *
     61  *	enum auth_stat
     62  *	flavorx_auth(rqst, msg)
     63  *		struct svc_req *rqst;
     64  *		struct rpc_msg *msg;
     65  *
     66  */
     67 
     68 static const struct {
     69 	enum auth_stat (*authenticator) __P((struct svc_req *,
     70     struct rpc_msg *));
     71 } svcauthsw[] = {
     72 	{ _svcauth_null },		/* AUTH_NULL */
     73 	{ _svcauth_unix },		/* AUTH_UNIX */
     74 	{ _svcauth_short }		/* AUTH_SHORT */
     75 };
     76 #define	AUTH_MAX	2		/* HIGHEST AUTH NUMBER */
     77 
     78 
     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-alloctaed;
     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(rqst, msg)
     99 	struct svc_req *rqst;
    100 	struct rpc_msg *msg;
    101 {
    102 	int cred_flavor;
    103 
    104 	_DIAGASSERT(rqst != NULL);
    105 	_DIAGASSERT(msg != NULL);
    106 
    107 	rqst->rq_cred = msg->rm_call.cb_cred;
    108 	rqst->rq_xprt->xp_verf.oa_flavor = _null_auth.oa_flavor;
    109 	rqst->rq_xprt->xp_verf.oa_length = 0;
    110 	cred_flavor = rqst->rq_cred.oa_flavor;
    111 	if ((cred_flavor <= AUTH_MAX) && (cred_flavor >= AUTH_NULL)) {
    112 		return ((*(svcauthsw[cred_flavor].authenticator))(rqst, msg));
    113 	}
    114 
    115 	return (AUTH_REJECTEDCRED);
    116 }
    117 
    118 /* ARGSUSED */
    119 enum auth_stat
    120 _svcauth_null(rqst, msg)
    121 	struct svc_req *rqst;
    122 	struct rpc_msg *msg;
    123 {
    124 
    125 	return (AUTH_OK);
    126 }
    127