GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lib/libc/rpc/svc_auth.c Lines: 0 8 0.0 %
Date: 2017-11-07 Branches: 0 2 0.0 %

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