18360efbdSAlfred Perlstein /* $NetBSD: auth_none.c,v 1.13 2000/01/22 22:19:17 mycroft Exp $ */
28360efbdSAlfred Perlstein
32e322d37SHiroki Sato /*-
4*8a16b7a1SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause
5*8a16b7a1SPedro F. Giffuni *
62e322d37SHiroki Sato * Copyright (c) 2009, Sun Microsystems, Inc.
72e322d37SHiroki Sato * All rights reserved.
899064799SGarrett Wollman *
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.
1999064799SGarrett Wollman *
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.
3199064799SGarrett Wollman */
3299064799SGarrett Wollman
3399064799SGarrett Wollman /*
3499064799SGarrett Wollman * auth_none.c
3599064799SGarrett Wollman * Creates a client authentication handle for passing "null"
3699064799SGarrett Wollman * credentials and verifiers to remote systems.
3799064799SGarrett Wollman *
3899064799SGarrett Wollman * Copyright (C) 1984, Sun Microsystems, Inc.
3999064799SGarrett Wollman */
4099064799SGarrett Wollman
418360efbdSAlfred Perlstein #include "namespace.h"
429f5afc13SIan Dowse #include "reentrant.h"
438360efbdSAlfred Perlstein #include <assert.h>
444c3af266SPoul-Henning Kamp #include <stdlib.h>
4599064799SGarrett Wollman #include <rpc/types.h>
4699064799SGarrett Wollman #include <rpc/xdr.h>
4799064799SGarrett Wollman #include <rpc/auth.h>
488360efbdSAlfred Perlstein #include "un-namespace.h"
49235baf26SDaniel Eischen #include "mt_misc.h"
508360efbdSAlfred Perlstein
518360efbdSAlfred Perlstein #define MAX_MARSHAL_SIZE 20
5299064799SGarrett Wollman
5399064799SGarrett Wollman /*
5499064799SGarrett Wollman * Authenticator operations routines
5599064799SGarrett Wollman */
5699064799SGarrett Wollman
578360efbdSAlfred Perlstein static bool_t authnone_marshal (AUTH *, XDR *);
588360efbdSAlfred Perlstein static void authnone_verf (AUTH *);
598360efbdSAlfred Perlstein static bool_t authnone_validate (AUTH *, struct opaque_auth *);
608360efbdSAlfred Perlstein static bool_t authnone_refresh (AUTH *, void *);
618360efbdSAlfred Perlstein static void authnone_destroy (AUTH *);
628360efbdSAlfred Perlstein
6377601543SCraig Rodrigues extern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *);
648360efbdSAlfred Perlstein
6577601543SCraig Rodrigues static struct auth_ops *authnone_ops(void);
6699064799SGarrett Wollman
6799064799SGarrett Wollman static struct authnone_private {
6899064799SGarrett Wollman AUTH no_client;
698360efbdSAlfred Perlstein char marshalled_client[MAX_MARSHAL_SIZE];
7099064799SGarrett Wollman u_int mcnt;
7199064799SGarrett Wollman } *authnone_private;
7299064799SGarrett Wollman
7399064799SGarrett Wollman AUTH *
authnone_create(void)7477601543SCraig Rodrigues authnone_create(void)
7599064799SGarrett Wollman {
768360efbdSAlfred Perlstein struct authnone_private *ap = authnone_private;
7799064799SGarrett Wollman XDR xdr_stream;
788360efbdSAlfred Perlstein XDR *xdrs;
7999064799SGarrett Wollman
808360efbdSAlfred Perlstein mutex_lock(&authnone_lock);
81513004a2SPedro F. Giffuni if (ap == NULL) {
82513004a2SPedro F. Giffuni ap = calloc(1, sizeof (*ap));
83513004a2SPedro F. Giffuni if (ap == NULL) {
848360efbdSAlfred Perlstein mutex_unlock(&authnone_lock);
8599064799SGarrett Wollman return (0);
868360efbdSAlfred Perlstein }
8799064799SGarrett Wollman authnone_private = ap;
8899064799SGarrett Wollman }
8999064799SGarrett Wollman if (!ap->mcnt) {
9099064799SGarrett Wollman ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
918360efbdSAlfred Perlstein ap->no_client.ah_ops = authnone_ops();
9299064799SGarrett Wollman xdrs = &xdr_stream;
938360efbdSAlfred Perlstein xdrmem_create(xdrs, ap->marshalled_client,
948360efbdSAlfred Perlstein (u_int)MAX_MARSHAL_SIZE, XDR_ENCODE);
9599064799SGarrett Wollman (void)xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
9699064799SGarrett Wollman (void)xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
9799064799SGarrett Wollman ap->mcnt = XDR_GETPOS(xdrs);
9899064799SGarrett Wollman XDR_DESTROY(xdrs);
9999064799SGarrett Wollman }
1008360efbdSAlfred Perlstein mutex_unlock(&authnone_lock);
10199064799SGarrett Wollman return (&ap->no_client);
10299064799SGarrett Wollman }
10399064799SGarrett Wollman
10499064799SGarrett Wollman /*ARGSUSED*/
10599064799SGarrett Wollman static bool_t
authnone_marshal(AUTH * client,XDR * xdrs)1068360efbdSAlfred Perlstein authnone_marshal(AUTH *client, XDR *xdrs)
10799064799SGarrett Wollman {
1088360efbdSAlfred Perlstein struct authnone_private *ap;
1098360efbdSAlfred Perlstein bool_t dummy;
11099064799SGarrett Wollman
1118360efbdSAlfred Perlstein assert(xdrs != NULL);
1128360efbdSAlfred Perlstein
1138360efbdSAlfred Perlstein ap = authnone_private;
1148360efbdSAlfred Perlstein if (ap == NULL) {
1158360efbdSAlfred Perlstein mutex_unlock(&authnone_lock);
1168360efbdSAlfred Perlstein return (FALSE);
1178360efbdSAlfred Perlstein }
1188360efbdSAlfred Perlstein dummy = (*xdrs->x_ops->x_putbytes)(xdrs,
1198360efbdSAlfred Perlstein ap->marshalled_client, ap->mcnt);
1208360efbdSAlfred Perlstein mutex_unlock(&authnone_lock);
1218360efbdSAlfred Perlstein return (dummy);
12299064799SGarrett Wollman }
12399064799SGarrett Wollman
1248360efbdSAlfred Perlstein /* All these unused parameters are required to keep ANSI-C from grumbling */
1258360efbdSAlfred Perlstein /*ARGSUSED*/
12699064799SGarrett Wollman static void
authnone_verf(AUTH * client)1278360efbdSAlfred Perlstein authnone_verf(AUTH *client)
12899064799SGarrett Wollman {
12999064799SGarrett Wollman }
13099064799SGarrett Wollman
1318360efbdSAlfred Perlstein /*ARGSUSED*/
13299064799SGarrett Wollman static bool_t
authnone_validate(AUTH * client,struct opaque_auth * opaque)1338360efbdSAlfred Perlstein authnone_validate(AUTH *client, struct opaque_auth *opaque)
13499064799SGarrett Wollman {
13599064799SGarrett Wollman
13699064799SGarrett Wollman return (TRUE);
13799064799SGarrett Wollman }
13899064799SGarrett Wollman
1398360efbdSAlfred Perlstein /*ARGSUSED*/
14099064799SGarrett Wollman static bool_t
authnone_refresh(AUTH * client,void * dummy)1418360efbdSAlfred Perlstein authnone_refresh(AUTH *client, void *dummy)
14299064799SGarrett Wollman {
14399064799SGarrett Wollman
14499064799SGarrett Wollman return (FALSE);
14599064799SGarrett Wollman }
14699064799SGarrett Wollman
1478360efbdSAlfred Perlstein /*ARGSUSED*/
14899064799SGarrett Wollman static void
authnone_destroy(AUTH * client)1498360efbdSAlfred Perlstein authnone_destroy(AUTH *client)
15099064799SGarrett Wollman {
15199064799SGarrett Wollman }
1528360efbdSAlfred Perlstein
1538360efbdSAlfred Perlstein static struct auth_ops *
authnone_ops(void)15477601543SCraig Rodrigues authnone_ops(void)
1558360efbdSAlfred Perlstein {
1568360efbdSAlfred Perlstein static struct auth_ops ops;
1578360efbdSAlfred Perlstein
1588360efbdSAlfred Perlstein /* VARIABLES PROTECTED BY ops_lock: ops */
1598360efbdSAlfred Perlstein
1608360efbdSAlfred Perlstein mutex_lock(&ops_lock);
1618360efbdSAlfred Perlstein if (ops.ah_nextverf == NULL) {
1628360efbdSAlfred Perlstein ops.ah_nextverf = authnone_verf;
1638360efbdSAlfred Perlstein ops.ah_marshal = authnone_marshal;
1648360efbdSAlfred Perlstein ops.ah_validate = authnone_validate;
1658360efbdSAlfred Perlstein ops.ah_refresh = authnone_refresh;
1668360efbdSAlfred Perlstein ops.ah_destroy = authnone_destroy;
1678360efbdSAlfred Perlstein }
1688360efbdSAlfred Perlstein mutex_unlock(&ops_lock);
1698360efbdSAlfred Perlstein return (&ops);
1708360efbdSAlfred Perlstein }
171