xref: /openbsd/lib/libc/rpc/svc_auth.c (revision 89ed967e)
1*89ed967eSguenther /*	$OpenBSD: svc_auth.c,v 1.10 2016/09/23 02:53:46 guenther Exp $ */
2cb7760d1Smillert 
3df930be7Sderaadt /*
4cb7760d1Smillert  * Copyright (c) 2010, Oracle America, Inc.
5df930be7Sderaadt  *
6cb7760d1Smillert  * Redistribution and use in source and binary forms, with or without
7cb7760d1Smillert  * modification, are permitted provided that the following conditions are
8cb7760d1Smillert  * met:
9df930be7Sderaadt  *
10cb7760d1Smillert  *     * Redistributions of source code must retain the above copyright
11cb7760d1Smillert  *       notice, this list of conditions and the following disclaimer.
12cb7760d1Smillert  *     * Redistributions in binary form must reproduce the above
13cb7760d1Smillert  *       copyright notice, this list of conditions and the following
14cb7760d1Smillert  *       disclaimer in the documentation and/or other materials
15cb7760d1Smillert  *       provided with the distribution.
16cb7760d1Smillert  *     * Neither the name of the "Oracle America, Inc." nor the names of its
17cb7760d1Smillert  *       contributors may be used to endorse or promote products derived
18cb7760d1Smillert  *       from this software without specific prior written permission.
19df930be7Sderaadt  *
20cb7760d1Smillert  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21cb7760d1Smillert  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22cb7760d1Smillert  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23cb7760d1Smillert  *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24cb7760d1Smillert  *   COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25cb7760d1Smillert  *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26cb7760d1Smillert  *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27cb7760d1Smillert  *   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28cb7760d1Smillert  *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29cb7760d1Smillert  *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30cb7760d1Smillert  *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31cb7760d1Smillert  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32df930be7Sderaadt  */
33df930be7Sderaadt 
34df930be7Sderaadt /*
35df930be7Sderaadt  * svc_auth_nodes.c, Server-side rpc authenticator interface,
36df930be7Sderaadt  * *WITHOUT* DES authentication.
37df930be7Sderaadt  */
38df930be7Sderaadt 
39df930be7Sderaadt #include <rpc/rpc.h>
40df930be7Sderaadt 
41df930be7Sderaadt /*
42df930be7Sderaadt  * svcauthsw is the bdevsw of server side authentication.
43df930be7Sderaadt  *
44df930be7Sderaadt  * Server side authenticators are called from authenticate by
45df930be7Sderaadt  * using the client auth struct flavor field to index into svcauthsw.
46df930be7Sderaadt  * The server auth flavors must implement a routine that looks
47df930be7Sderaadt  * like:
48df930be7Sderaadt  *
49df930be7Sderaadt  *	enum auth_stat
50df930be7Sderaadt  *	flavorx_auth(rqst, msg)
5141aa8645Sderaadt  *		struct svc_req *rqst;
5241aa8645Sderaadt  *		struct rpc_msg *msg;
53df930be7Sderaadt  *
54df930be7Sderaadt  */
55df930be7Sderaadt 
56384ec30aSotto /* no authentication */
57384ec30aSotto enum auth_stat _svcauth_null(void);
5885858ec2Sguenther PROTO_NORMAL(_svcauth_null);
59df930be7Sderaadt 
60df930be7Sderaadt static struct {
61df930be7Sderaadt 	enum auth_stat (*authenticator)();
62df930be7Sderaadt } svcauthsw[] = {
63a7c2f5b9Smillert 	{ _svcauth_null },		/* AUTH_NULL */
64a7c2f5b9Smillert 	{ _svcauth_unix },		/* AUTH_UNIX */
65a7c2f5b9Smillert 	{ _svcauth_short }		/* AUTH_SHORT */
66df930be7Sderaadt };
67df930be7Sderaadt #define	AUTH_MAX	2		/* HIGHEST AUTH NUMBER */
68df930be7Sderaadt 
69df930be7Sderaadt 
70df930be7Sderaadt /*
71df930be7Sderaadt  * The call rpc message, msg has been obtained from the wire.  The msg contains
72df930be7Sderaadt  * the raw form of credentials and verifiers.  authenticate returns AUTH_OK
73df930be7Sderaadt  * if the msg is successfully authenticated.  If AUTH_OK then the routine also
74df930be7Sderaadt  * does the following things:
75df930be7Sderaadt  * set rqst->rq_xprt->verf to the appropriate response verifier;
76df930be7Sderaadt  * sets rqst->rq_client_cred to the "cooked" form of the credentials.
77df930be7Sderaadt  *
78*89ed967eSguenther  * NB: rqst->rq_cxprt->verf must be pre-allocated;
79df930be7Sderaadt  * its length is set appropriately.
80df930be7Sderaadt  *
81df930be7Sderaadt  * The caller still owns and is responsible for msg->u.cmb.cred and
82df930be7Sderaadt  * msg->u.cmb.verf.  The authentication system retains ownership of
83df930be7Sderaadt  * rqst->rq_client_cred, the cooked credentials.
84df930be7Sderaadt  *
85df930be7Sderaadt  * There is an assumption that any flavour less than AUTH_NULL is
86df930be7Sderaadt  * invalid.
87df930be7Sderaadt  */
88df930be7Sderaadt enum auth_stat
_authenticate(struct svc_req * rqst,struct rpc_msg * msg)89384ec30aSotto _authenticate(struct svc_req *rqst, struct rpc_msg *msg)
90df930be7Sderaadt {
9141aa8645Sderaadt 	int cred_flavor;
92df930be7Sderaadt 
93df930be7Sderaadt 	rqst->rq_cred = msg->rm_call.cb_cred;
94df930be7Sderaadt 	rqst->rq_xprt->xp_verf.oa_flavor = _null_auth.oa_flavor;
95df930be7Sderaadt 	rqst->rq_xprt->xp_verf.oa_length = 0;
96df930be7Sderaadt 	cred_flavor = rqst->rq_cred.oa_flavor;
97df930be7Sderaadt 	if ((cred_flavor <= AUTH_MAX) && (cred_flavor >= AUTH_NULL)) {
98df930be7Sderaadt 		return ((*(svcauthsw[cred_flavor].authenticator))(rqst, msg));
99df930be7Sderaadt 	}
100df930be7Sderaadt 
101df930be7Sderaadt 	return (AUTH_REJECTEDCRED);
102df930be7Sderaadt }
103df930be7Sderaadt 
104df930be7Sderaadt enum auth_stat
_svcauth_null(void)105384ec30aSotto _svcauth_null(void)
106df930be7Sderaadt 	/*struct svc_req *rqst;
107df930be7Sderaadt 	struct rpc_msg *msg;*/
108df930be7Sderaadt {
109df930be7Sderaadt 
110df930be7Sderaadt 	return (AUTH_OK);
111df930be7Sderaadt }
11285858ec2Sguenther DEF_STRONG(_svcauth_null);
113