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