1177633Sdfr/*	$NetBSD: auth_none.c,v 1.13 2000/01/22 22:19:17 mycroft Exp $	*/
2177633Sdfr
3261046Smav/*-
4261046Smav * Copyright (c) 2009, Sun Microsystems, Inc.
5261046Smav * All rights reserved.
6177633Sdfr *
7261046Smav * Redistribution and use in source and binary forms, with or without
8261046Smav * modification, are permitted provided that the following conditions are met:
9261046Smav * - Redistributions of source code must retain the above copyright notice,
10261046Smav *   this list of conditions and the following disclaimer.
11261046Smav * - Redistributions in binary form must reproduce the above copyright notice,
12261046Smav *   this list of conditions and the following disclaimer in the documentation
13261046Smav *   and/or other materials provided with the distribution.
14261046Smav * - Neither the name of Sun Microsystems, Inc. nor the names of its
15261046Smav *   contributors may be used to endorse or promote products derived
16261046Smav *   from this software without specific prior written permission.
17261046Smav *
18261046Smav * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19261046Smav * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20261046Smav * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21261046Smav * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22261046Smav * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23261046Smav * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24261046Smav * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25261046Smav * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26261046Smav * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27261046Smav * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28261046Smav * POSSIBILITY OF SUCH DAMAGE.
29177633Sdfr */
30177633Sdfr
31177633Sdfr#if defined(LIBC_SCCS) && !defined(lint)
32177633Sdfrstatic char *sccsid2 = "@(#)auth_none.c 1.19 87/08/11 Copyr 1984 Sun Micro";
33177633Sdfrstatic char *sccsid = "@(#)auth_none.c	2.1 88/07/29 4.0 RPCSRC";
34177633Sdfr#endif
35177633Sdfr#include <sys/cdefs.h>
36177633Sdfr__FBSDID("$FreeBSD: releng/10.3/sys/rpc/auth_none.c 261046 2014-01-22 23:45:27Z mav $");
37177633Sdfr
38177633Sdfr/*
39177633Sdfr * auth_none.c
40177633Sdfr * Creates a client authentication handle for passing "null"
41177633Sdfr * credentials and verifiers to remote systems.
42177633Sdfr *
43177633Sdfr * Copyright (C) 1984, Sun Microsystems, Inc.
44177633Sdfr */
45177633Sdfr
46177633Sdfr#include <sys/param.h>
47177633Sdfr#include <sys/systm.h>
48177633Sdfr#include <sys/kernel.h>
49177633Sdfr#include <sys/lock.h>
50177633Sdfr#include <sys/malloc.h>
51177633Sdfr#include <sys/mutex.h>
52177633Sdfr
53177633Sdfr#include <rpc/types.h>
54177633Sdfr#include <rpc/xdr.h>
55177633Sdfr#include <rpc/auth.h>
56184588Sdfr#include <rpc/clnt.h>
57177633Sdfr
58177633Sdfr#define MAX_MARSHAL_SIZE 20
59177633Sdfr
60177633Sdfr/*
61177633Sdfr * Authenticator operations routines
62177633Sdfr */
63177633Sdfr
64184588Sdfrstatic bool_t authnone_marshal (AUTH *, uint32_t, XDR *, struct mbuf *);
65177633Sdfrstatic void authnone_verf (AUTH *);
66184588Sdfrstatic bool_t authnone_validate (AUTH *, uint32_t, struct opaque_auth *,
67184588Sdfr    struct mbuf **);
68177633Sdfrstatic bool_t authnone_refresh (AUTH *, void *);
69177633Sdfrstatic void authnone_destroy (AUTH *);
70177633Sdfr
71177633Sdfrstatic struct auth_ops authnone_ops = {
72177633Sdfr	.ah_nextverf =		authnone_verf,
73177633Sdfr	.ah_marshal =		authnone_marshal,
74177633Sdfr	.ah_validate =		authnone_validate,
75177633Sdfr	.ah_refresh =		authnone_refresh,
76184588Sdfr	.ah_destroy =		authnone_destroy,
77177633Sdfr};
78177633Sdfr
79177633Sdfrstruct authnone_private {
80177633Sdfr	AUTH	no_client;
81177633Sdfr	char	mclient[MAX_MARSHAL_SIZE];
82177633Sdfr	u_int	mcnt;
83177633Sdfr};
84177633Sdfr
85177633Sdfrstatic struct authnone_private authnone_private;
86177633Sdfr
87177633Sdfrstatic void
88177633Sdfrauthnone_init(void *dummy)
89177633Sdfr{
90177633Sdfr	struct authnone_private *ap = &authnone_private;
91177633Sdfr	XDR xdrs;
92177633Sdfr
93177633Sdfr	ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
94177633Sdfr	ap->no_client.ah_ops = &authnone_ops;
95177633Sdfr	xdrmem_create(&xdrs, ap->mclient, MAX_MARSHAL_SIZE, XDR_ENCODE);
96177633Sdfr	xdr_opaque_auth(&xdrs, &ap->no_client.ah_cred);
97177633Sdfr	xdr_opaque_auth(&xdrs, &ap->no_client.ah_verf);
98177633Sdfr	ap->mcnt = XDR_GETPOS(&xdrs);
99177633Sdfr	XDR_DESTROY(&xdrs);
100177633Sdfr}
101177633SdfrSYSINIT(authnone_init, SI_SUB_KMEM, SI_ORDER_ANY, authnone_init, NULL);
102177633Sdfr
103177633SdfrAUTH *
104177633Sdfrauthnone_create()
105177633Sdfr{
106177633Sdfr	struct authnone_private *ap = &authnone_private;
107177633Sdfr
108177633Sdfr	return (&ap->no_client);
109177633Sdfr}
110177633Sdfr
111177633Sdfr/*ARGSUSED*/
112177633Sdfrstatic bool_t
113184588Sdfrauthnone_marshal(AUTH *client, uint32_t xid, XDR *xdrs, struct mbuf *args)
114177633Sdfr{
115177633Sdfr	struct authnone_private *ap = &authnone_private;
116177633Sdfr
117177633Sdfr	KASSERT(xdrs != NULL, ("authnone_marshal: xdrs is null"));
118177633Sdfr
119184588Sdfr	if (!XDR_PUTBYTES(xdrs, ap->mclient, ap->mcnt))
120184588Sdfr		return (FALSE);
121184588Sdfr
122184588Sdfr	xdrmbuf_append(xdrs, args);
123184588Sdfr
124184588Sdfr	return (TRUE);
125177633Sdfr}
126177633Sdfr
127177633Sdfr/* All these unused parameters are required to keep ANSI-C from grumbling */
128177633Sdfr/*ARGSUSED*/
129177633Sdfrstatic void
130177633Sdfrauthnone_verf(AUTH *client)
131177633Sdfr{
132177633Sdfr}
133177633Sdfr
134177633Sdfr/*ARGSUSED*/
135177633Sdfrstatic bool_t
136184588Sdfrauthnone_validate(AUTH *client, uint32_t xid, struct opaque_auth *opaque,
137184588Sdfr    struct mbuf **mrepp)
138177633Sdfr{
139177633Sdfr
140177633Sdfr	return (TRUE);
141177633Sdfr}
142177633Sdfr
143177633Sdfr/*ARGSUSED*/
144177633Sdfrstatic bool_t
145177633Sdfrauthnone_refresh(AUTH *client, void *dummy)
146177633Sdfr{
147177633Sdfr
148177633Sdfr	return (FALSE);
149177633Sdfr}
150177633Sdfr
151177633Sdfr/*ARGSUSED*/
152177633Sdfrstatic void
153177633Sdfrauthnone_destroy(AUTH *client)
154177633Sdfr{
155177633Sdfr}
156