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