1/*	$NetBSD: auth_none.c,v 1.13 2000/01/22 22:19:17 mycroft Exp $	*/
2
3/*-
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 * Copyright (c) 2009, Sun Microsystems, Inc.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 * - Redistributions of source code must retain the above copyright notice,
12 *   this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright notice,
14 *   this list of conditions and the following disclaimer in the documentation
15 *   and/or other materials provided with the distribution.
16 * - Neither the name of Sun Microsystems, 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 "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#include <sys/cdefs.h>
34/*
35 * auth_none.c
36 * Creates a client authentication handle for passing "null"
37 * credentials and verifiers to remote systems.
38 *
39 * Copyright (C) 1984, Sun Microsystems, Inc.
40 */
41
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/kernel.h>
45#include <sys/lock.h>
46#include <sys/malloc.h>
47#include <sys/mutex.h>
48
49#include <rpc/types.h>
50#include <rpc/xdr.h>
51#include <rpc/auth.h>
52#include <rpc/clnt.h>
53
54#define MAX_MARSHAL_SIZE 20
55
56/*
57 * Authenticator operations routines
58 */
59
60static bool_t authnone_marshal (AUTH *, uint32_t, XDR *, struct mbuf *);
61static void authnone_verf (AUTH *);
62static bool_t authnone_validate (AUTH *, uint32_t, struct opaque_auth *,
63    struct mbuf **);
64static bool_t authnone_refresh (AUTH *, void *);
65static void authnone_destroy (AUTH *);
66
67static const struct auth_ops authnone_ops = {
68	.ah_nextverf =		authnone_verf,
69	.ah_marshal =		authnone_marshal,
70	.ah_validate =		authnone_validate,
71	.ah_refresh =		authnone_refresh,
72	.ah_destroy =		authnone_destroy,
73};
74
75struct authnone_private {
76	AUTH	no_client;
77	char	mclient[MAX_MARSHAL_SIZE];
78	u_int	mcnt;
79};
80
81static struct authnone_private authnone_private;
82
83static void
84authnone_init(void *dummy)
85{
86	struct authnone_private *ap = &authnone_private;
87	XDR xdrs;
88
89	ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
90	ap->no_client.ah_ops = &authnone_ops;
91	xdrmem_create(&xdrs, ap->mclient, MAX_MARSHAL_SIZE, XDR_ENCODE);
92	xdr_opaque_auth(&xdrs, &ap->no_client.ah_cred);
93	xdr_opaque_auth(&xdrs, &ap->no_client.ah_verf);
94	ap->mcnt = XDR_GETPOS(&xdrs);
95	XDR_DESTROY(&xdrs);
96}
97SYSINIT(authnone_init, SI_SUB_KMEM, SI_ORDER_ANY, authnone_init, NULL);
98
99AUTH *
100authnone_create(void)
101{
102	struct authnone_private *ap = &authnone_private;
103
104	return (&ap->no_client);
105}
106
107/*ARGSUSED*/
108static bool_t
109authnone_marshal(AUTH *client, uint32_t xid, XDR *xdrs, struct mbuf *args)
110{
111	struct authnone_private *ap = &authnone_private;
112
113	KASSERT(xdrs != NULL, ("authnone_marshal: xdrs is null"));
114
115	if (!XDR_PUTBYTES(xdrs, ap->mclient, ap->mcnt))
116		return (FALSE);
117
118	xdrmbuf_append(xdrs, args);
119
120	return (TRUE);
121}
122
123/* All these unused parameters are required to keep ANSI-C from grumbling */
124/*ARGSUSED*/
125static void
126authnone_verf(AUTH *client)
127{
128}
129
130/*ARGSUSED*/
131static bool_t
132authnone_validate(AUTH *client, uint32_t xid, struct opaque_auth *opaque,
133    struct mbuf **mrepp)
134{
135
136	return (TRUE);
137}
138
139/*ARGSUSED*/
140static bool_t
141authnone_refresh(AUTH *client, void *dummy)
142{
143
144	return (FALSE);
145}
146
147/*ARGSUSED*/
148static void
149authnone_destroy(AUTH *client)
150{
151}
152