xref: /freebsd/lib/libc/rpc/auth_none.c (revision 7760154342d4361500e997477d3f0c683e084351)
18360efbdSAlfred Perlstein /*	$NetBSD: auth_none.c,v 1.13 2000/01/22 22:19:17 mycroft Exp $	*/
28360efbdSAlfred Perlstein 
32e322d37SHiroki Sato /*-
42e322d37SHiroki Sato  * Copyright (c) 2009, Sun Microsystems, Inc.
52e322d37SHiroki Sato  * All rights reserved.
699064799SGarrett Wollman  *
72e322d37SHiroki Sato  * Redistribution and use in source and binary forms, with or without
82e322d37SHiroki Sato  * modification, are permitted provided that the following conditions are met:
92e322d37SHiroki Sato  * - Redistributions of source code must retain the above copyright notice,
102e322d37SHiroki Sato  *   this list of conditions and the following disclaimer.
112e322d37SHiroki Sato  * - Redistributions in binary form must reproduce the above copyright notice,
122e322d37SHiroki Sato  *   this list of conditions and the following disclaimer in the documentation
132e322d37SHiroki Sato  *   and/or other materials provided with the distribution.
142e322d37SHiroki Sato  * - Neither the name of Sun Microsystems, Inc. nor the names of its
152e322d37SHiroki Sato  *   contributors may be used to endorse or promote products derived
162e322d37SHiroki Sato  *   from this software without specific prior written permission.
1799064799SGarrett Wollman  *
182e322d37SHiroki Sato  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
192e322d37SHiroki Sato  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
202e322d37SHiroki Sato  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
212e322d37SHiroki Sato  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
222e322d37SHiroki Sato  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
232e322d37SHiroki Sato  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
242e322d37SHiroki Sato  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
252e322d37SHiroki Sato  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
262e322d37SHiroki Sato  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
272e322d37SHiroki Sato  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
282e322d37SHiroki Sato  * POSSIBILITY OF SUCH DAMAGE.
2999064799SGarrett Wollman  */
3099064799SGarrett Wollman 
3199064799SGarrett Wollman #if defined(LIBC_SCCS) && !defined(lint)
32a986ef57SDavid E. O'Brien static char *sccsid2 = "@(#)auth_none.c 1.19 87/08/11 Copyr 1984 Sun Micro";
338360efbdSAlfred Perlstein static char *sccsid = "@(#)auth_none.c	2.1 88/07/29 4.0 RPCSRC";
3499064799SGarrett Wollman #endif
35d3d20c82SDavid E. O'Brien #include <sys/cdefs.h>
36d3d20c82SDavid E. O'Brien __FBSDID("$FreeBSD$");
3799064799SGarrett Wollman 
3899064799SGarrett Wollman /*
3999064799SGarrett Wollman  * auth_none.c
4099064799SGarrett Wollman  * Creates a client authentication handle for passing "null"
4199064799SGarrett Wollman  * credentials and verifiers to remote systems.
4299064799SGarrett Wollman  *
4399064799SGarrett Wollman  * Copyright (C) 1984, Sun Microsystems, Inc.
4499064799SGarrett Wollman  */
4599064799SGarrett Wollman 
468360efbdSAlfred Perlstein #include "namespace.h"
479f5afc13SIan Dowse #include "reentrant.h"
488360efbdSAlfred Perlstein #include <assert.h>
494c3af266SPoul-Henning Kamp #include <stdlib.h>
5099064799SGarrett Wollman #include <rpc/types.h>
5199064799SGarrett Wollman #include <rpc/xdr.h>
5299064799SGarrett Wollman #include <rpc/auth.h>
538360efbdSAlfred Perlstein #include "un-namespace.h"
54235baf26SDaniel Eischen #include "mt_misc.h"
558360efbdSAlfred Perlstein 
568360efbdSAlfred Perlstein #define MAX_MARSHAL_SIZE 20
5799064799SGarrett Wollman 
5899064799SGarrett Wollman /*
5999064799SGarrett Wollman  * Authenticator operations routines
6099064799SGarrett Wollman  */
6199064799SGarrett Wollman 
628360efbdSAlfred Perlstein static bool_t authnone_marshal (AUTH *, XDR *);
638360efbdSAlfred Perlstein static void authnone_verf (AUTH *);
648360efbdSAlfred Perlstein static bool_t authnone_validate (AUTH *, struct opaque_auth *);
658360efbdSAlfred Perlstein static bool_t authnone_refresh (AUTH *, void *);
668360efbdSAlfred Perlstein static void authnone_destroy (AUTH *);
678360efbdSAlfred Perlstein 
68*77601543SCraig Rodrigues extern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *);
698360efbdSAlfred Perlstein 
70*77601543SCraig Rodrigues static struct auth_ops *authnone_ops(void);
7199064799SGarrett Wollman 
7299064799SGarrett Wollman static struct authnone_private {
7399064799SGarrett Wollman 	AUTH	no_client;
748360efbdSAlfred Perlstein 	char	marshalled_client[MAX_MARSHAL_SIZE];
7599064799SGarrett Wollman 	u_int	mcnt;
7699064799SGarrett Wollman } *authnone_private;
7799064799SGarrett Wollman 
7899064799SGarrett Wollman AUTH *
79*77601543SCraig Rodrigues authnone_create(void)
8099064799SGarrett Wollman {
818360efbdSAlfred Perlstein 	struct authnone_private *ap = authnone_private;
8299064799SGarrett Wollman 	XDR xdr_stream;
838360efbdSAlfred Perlstein 	XDR *xdrs;
8499064799SGarrett Wollman 
858360efbdSAlfred Perlstein 	mutex_lock(&authnone_lock);
8699064799SGarrett Wollman 	if (ap == 0) {
8799064799SGarrett Wollman 		ap = (struct authnone_private *)calloc(1, sizeof (*ap));
888360efbdSAlfred Perlstein 		if (ap == 0) {
898360efbdSAlfred Perlstein 			mutex_unlock(&authnone_lock);
9099064799SGarrett Wollman 			return (0);
918360efbdSAlfred Perlstein 		}
9299064799SGarrett Wollman 		authnone_private = ap;
9399064799SGarrett Wollman 	}
9499064799SGarrett Wollman 	if (!ap->mcnt) {
9599064799SGarrett Wollman 		ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
968360efbdSAlfred Perlstein 		ap->no_client.ah_ops = authnone_ops();
9799064799SGarrett Wollman 		xdrs = &xdr_stream;
988360efbdSAlfred Perlstein 		xdrmem_create(xdrs, ap->marshalled_client,
998360efbdSAlfred Perlstein 		    (u_int)MAX_MARSHAL_SIZE, XDR_ENCODE);
10099064799SGarrett Wollman 		(void)xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
10199064799SGarrett Wollman 		(void)xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
10299064799SGarrett Wollman 		ap->mcnt = XDR_GETPOS(xdrs);
10399064799SGarrett Wollman 		XDR_DESTROY(xdrs);
10499064799SGarrett Wollman 	}
1058360efbdSAlfred Perlstein 	mutex_unlock(&authnone_lock);
10699064799SGarrett Wollman 	return (&ap->no_client);
10799064799SGarrett Wollman }
10899064799SGarrett Wollman 
10999064799SGarrett Wollman /*ARGSUSED*/
11099064799SGarrett Wollman static bool_t
1118360efbdSAlfred Perlstein authnone_marshal(AUTH *client, XDR *xdrs)
11299064799SGarrett Wollman {
1138360efbdSAlfred Perlstein 	struct authnone_private *ap;
1148360efbdSAlfred Perlstein 	bool_t dummy;
11599064799SGarrett Wollman 
1168360efbdSAlfred Perlstein 	assert(xdrs != NULL);
1178360efbdSAlfred Perlstein 
1188360efbdSAlfred Perlstein 	ap = authnone_private;
1198360efbdSAlfred Perlstein 	if (ap == NULL) {
1208360efbdSAlfred Perlstein 		mutex_unlock(&authnone_lock);
1218360efbdSAlfred Perlstein 		return (FALSE);
1228360efbdSAlfred Perlstein 	}
1238360efbdSAlfred Perlstein 	dummy = (*xdrs->x_ops->x_putbytes)(xdrs,
1248360efbdSAlfred Perlstein 	    ap->marshalled_client, ap->mcnt);
1258360efbdSAlfred Perlstein 	mutex_unlock(&authnone_lock);
1268360efbdSAlfred Perlstein 	return (dummy);
12799064799SGarrett Wollman }
12899064799SGarrett Wollman 
1298360efbdSAlfred Perlstein /* All these unused parameters are required to keep ANSI-C from grumbling */
1308360efbdSAlfred Perlstein /*ARGSUSED*/
13199064799SGarrett Wollman static void
1328360efbdSAlfred Perlstein authnone_verf(AUTH *client)
13399064799SGarrett Wollman {
13499064799SGarrett Wollman }
13599064799SGarrett Wollman 
1368360efbdSAlfred Perlstein /*ARGSUSED*/
13799064799SGarrett Wollman static bool_t
1388360efbdSAlfred Perlstein authnone_validate(AUTH *client, struct opaque_auth *opaque)
13999064799SGarrett Wollman {
14099064799SGarrett Wollman 
14199064799SGarrett Wollman 	return (TRUE);
14299064799SGarrett Wollman }
14399064799SGarrett Wollman 
1448360efbdSAlfred Perlstein /*ARGSUSED*/
14599064799SGarrett Wollman static bool_t
1468360efbdSAlfred Perlstein authnone_refresh(AUTH *client, void *dummy)
14799064799SGarrett Wollman {
14899064799SGarrett Wollman 
14999064799SGarrett Wollman 	return (FALSE);
15099064799SGarrett Wollman }
15199064799SGarrett Wollman 
1528360efbdSAlfred Perlstein /*ARGSUSED*/
15399064799SGarrett Wollman static void
1548360efbdSAlfred Perlstein authnone_destroy(AUTH *client)
15599064799SGarrett Wollman {
15699064799SGarrett Wollman }
1578360efbdSAlfred Perlstein 
1588360efbdSAlfred Perlstein static struct auth_ops *
159*77601543SCraig Rodrigues authnone_ops(void)
1608360efbdSAlfred Perlstein {
1618360efbdSAlfred Perlstein 	static struct auth_ops ops;
1628360efbdSAlfred Perlstein 
1638360efbdSAlfred Perlstein /* VARIABLES PROTECTED BY ops_lock: ops */
1648360efbdSAlfred Perlstein 
1658360efbdSAlfred Perlstein 	mutex_lock(&ops_lock);
1668360efbdSAlfred Perlstein 	if (ops.ah_nextverf == NULL) {
1678360efbdSAlfred Perlstein 		ops.ah_nextverf = authnone_verf;
1688360efbdSAlfred Perlstein 		ops.ah_marshal = authnone_marshal;
1698360efbdSAlfred Perlstein 		ops.ah_validate = authnone_validate;
1708360efbdSAlfred Perlstein 		ops.ah_refresh = authnone_refresh;
1718360efbdSAlfred Perlstein 		ops.ah_destroy = authnone_destroy;
1728360efbdSAlfred Perlstein 	}
1738360efbdSAlfred Perlstein 	mutex_unlock(&ops_lock);
1748360efbdSAlfred Perlstein 	return (&ops);
1758360efbdSAlfred Perlstein }
176