1 /* $NetBSD: auth_none.c,v 1.13 2000/01/22 22:19:17 mycroft Exp $ */
4 * SPDX-License-Identifier: BSD-3-Clause
6 * Copyright (c) 2009, Sun Microsystems, Inc.
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.
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.
33 #if defined(LIBC_SCCS) && !defined(lint)
34 static char *sccsid2 = "@(#)auth_none.c 1.19 87/08/11 Copyr 1984 Sun Micro";
35 static char *sccsid = "@(#)auth_none.c 2.1 88/07/29 4.0 RPCSRC";
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
42 * Creates a client authentication handle for passing "null"
43 * credentials and verifiers to remote systems.
45 * Copyright (C) 1984, Sun Microsystems, Inc.
48 #include "namespace.h"
49 #include "reentrant.h"
52 #include <rpc/types.h>
55 #include "un-namespace.h"
58 #define MAX_MARSHAL_SIZE 20
61 * Authenticator operations routines
64 static bool_t authnone_marshal (AUTH *, XDR *);
65 static void authnone_verf (AUTH *);
66 static bool_t authnone_validate (AUTH *, struct opaque_auth *);
67 static bool_t authnone_refresh (AUTH *, void *);
68 static void authnone_destroy (AUTH *);
70 extern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *);
72 static struct auth_ops *authnone_ops(void);
74 static struct authnone_private {
76 char marshalled_client[MAX_MARSHAL_SIZE];
83 struct authnone_private *ap = authnone_private;
87 mutex_lock(&authnone_lock);
89 ap = calloc(1, sizeof (*ap));
91 mutex_unlock(&authnone_lock);
94 authnone_private = ap;
97 ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
98 ap->no_client.ah_ops = authnone_ops();
100 xdrmem_create(xdrs, ap->marshalled_client,
101 (u_int)MAX_MARSHAL_SIZE, XDR_ENCODE);
102 (void)xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
103 (void)xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
104 ap->mcnt = XDR_GETPOS(xdrs);
107 mutex_unlock(&authnone_lock);
108 return (&ap->no_client);
113 authnone_marshal(AUTH *client, XDR *xdrs)
115 struct authnone_private *ap;
118 assert(xdrs != NULL);
120 ap = authnone_private;
122 mutex_unlock(&authnone_lock);
125 dummy = (*xdrs->x_ops->x_putbytes)(xdrs,
126 ap->marshalled_client, ap->mcnt);
127 mutex_unlock(&authnone_lock);
131 /* All these unused parameters are required to keep ANSI-C from grumbling */
134 authnone_verf(AUTH *client)
140 authnone_validate(AUTH *client, struct opaque_auth *opaque)
148 authnone_refresh(AUTH *client, void *dummy)
156 authnone_destroy(AUTH *client)
160 static struct auth_ops *
163 static struct auth_ops ops;
165 /* VARIABLES PROTECTED BY ops_lock: ops */
167 mutex_lock(&ops_lock);
168 if (ops.ah_nextverf == NULL) {
169 ops.ah_nextverf = authnone_verf;
170 ops.ah_marshal = authnone_marshal;
171 ops.ah_validate = authnone_validate;
172 ops.ah_refresh = authnone_refresh;
173 ops.ah_destroy = authnone_destroy;
175 mutex_unlock(&ops_lock);