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