xref: /netbsd-src/lib/libc/rpc/svc_auth.c (revision 2a399c6883d870daece976daec6ffa7bb7f934ce)
1 /*	$NetBSD: svc_auth.c,v 1.3 1997/07/13 20:13:21 christos 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.3 1997/07/13 20:13:21 christos 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 <rpc/rpc.h>
50 
51 /*
52  * svcauthsw is the bdevsw of server side authentication.
53  *
54  * Server side authenticators are called from authenticate by
55  * using the client auth struct flavor field to index into svcauthsw.
56  * The server auth flavors must implement a routine that looks
57  * like:
58  *
59  *	enum auth_stat
60  *	flavorx_auth(rqst, msg)
61  *		register struct svc_req *rqst;
62  *		register struct rpc_msg *msg;
63  *
64  */
65 
66 static struct {
67 	enum auth_stat (*authenticator) __P((struct svc_req *,
68     struct rpc_msg *));
69 } svcauthsw[] = {
70 	{ _svcauth_null },		/* AUTH_NULL */
71 	{ _svcauth_unix },		/* AUTH_UNIX */
72 	{ _svcauth_short }		/* AUTH_SHORT */
73 };
74 #define	AUTH_MAX	2		/* HIGHEST AUTH NUMBER */
75 
76 
77 /*
78  * The call rpc message, msg has been obtained from the wire.  The msg contains
79  * the raw form of credentials and verifiers.  authenticate returns AUTH_OK
80  * if the msg is successfully authenticated.  If AUTH_OK then the routine also
81  * does the following things:
82  * set rqst->rq_xprt->verf to the appropriate response verifier;
83  * sets rqst->rq_client_cred to the "cooked" form of the credentials.
84  *
85  * NB: rqst->rq_cxprt->verf must be pre-alloctaed;
86  * its length is set appropriately.
87  *
88  * The caller still owns and is responsible for msg->u.cmb.cred and
89  * msg->u.cmb.verf.  The authentication system retains ownership of
90  * rqst->rq_client_cred, the cooked credentials.
91  *
92  * There is an assumption that any flavour less than AUTH_NULL is
93  * invalid.
94  */
95 enum auth_stat
96 _authenticate(rqst, msg)
97 	register struct svc_req *rqst;
98 	struct rpc_msg *msg;
99 {
100 	register int cred_flavor;
101 
102 	rqst->rq_cred = msg->rm_call.cb_cred;
103 	rqst->rq_xprt->xp_verf.oa_flavor = _null_auth.oa_flavor;
104 	rqst->rq_xprt->xp_verf.oa_length = 0;
105 	cred_flavor = rqst->rq_cred.oa_flavor;
106 	if ((cred_flavor <= AUTH_MAX) && (cred_flavor >= AUTH_NULL)) {
107 		return ((*(svcauthsw[cred_flavor].authenticator))(rqst, msg));
108 	}
109 
110 	return (AUTH_REJECTEDCRED);
111 }
112 
113 enum auth_stat
114 _svcauth_null(rqst, msg)
115 	struct svc_req *rqst;
116 	struct rpc_msg *msg;
117 {
118 
119 	return (AUTH_OK);
120 }
121