/* $NetBSD: auth_none.c,v 1.13 2000/01/22 22:19:17 mycroft Exp $ */12/*-3* SPDX-License-Identifier: BSD-3-Clause4*5* Copyright (c) 2009, Sun Microsystems, Inc.6* All rights reserved.7*8* Redistribution and use in source and binary forms, with or without9* modification, are permitted provided that the following conditions are met:10* - Redistributions of source code must retain the above copyright notice,11* this list of conditions and the following disclaimer.12* - Redistributions in binary form must reproduce the above copyright notice,13* this list of conditions and the following disclaimer in the documentation14* and/or other materials provided with the distribution.15* - Neither the name of Sun Microsystems, Inc. nor the names of its16* contributors may be used to endorse or promote products derived17* from this software without specific prior written permission.18*19* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"20* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE21* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE22* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE23* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR24* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF25* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS26* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN27* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)28* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE29* POSSIBILITY OF SUCH DAMAGE.30*/3132/*33* auth_none.c34* Creates a client authentication handle for passing "null"35* credentials and verifiers to remote systems.36*37* Copyright (C) 1984, Sun Microsystems, Inc.38*/3940#include "namespace.h"41#include "reentrant.h"42#include <assert.h>43#include <stdlib.h>44#include <rpc/types.h>45#include <rpc/xdr.h>46#include <rpc/auth.h>47#include "un-namespace.h"48#include "mt_misc.h"4950#define MAX_MARSHAL_SIZE 205152/*53* Authenticator operations routines54*/5556static bool_t authnone_marshal (AUTH *, XDR *);57static void authnone_verf (AUTH *);58static bool_t authnone_validate (AUTH *, struct opaque_auth *);59static bool_t authnone_refresh (AUTH *, void *);60static void authnone_destroy (AUTH *);6162extern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *);6364static struct auth_ops *authnone_ops(void);6566static struct authnone_private {67AUTH no_client;68char marshalled_client[MAX_MARSHAL_SIZE];69u_int mcnt;70} *authnone_private;7172AUTH *73authnone_create(void)74{75struct authnone_private *ap = authnone_private;76XDR xdr_stream;77XDR *xdrs;7879mutex_lock(&authnone_lock);80if (ap == NULL) {81ap = calloc(1, sizeof (*ap));82if (ap == NULL) {83mutex_unlock(&authnone_lock);84return (0);85}86authnone_private = ap;87}88if (!ap->mcnt) {89ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;90ap->no_client.ah_ops = authnone_ops();91xdrs = &xdr_stream;92xdrmem_create(xdrs, ap->marshalled_client,93(u_int)MAX_MARSHAL_SIZE, XDR_ENCODE);94(void)xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);95(void)xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);96ap->mcnt = XDR_GETPOS(xdrs);97XDR_DESTROY(xdrs);98}99mutex_unlock(&authnone_lock);100return (&ap->no_client);101}102103/*ARGSUSED*/104static bool_t105authnone_marshal(AUTH *client, XDR *xdrs)106{107struct authnone_private *ap;108bool_t dummy;109110assert(xdrs != NULL);111112ap = authnone_private;113if (ap == NULL) {114mutex_unlock(&authnone_lock);115return (FALSE);116}117dummy = (*xdrs->x_ops->x_putbytes)(xdrs,118ap->marshalled_client, ap->mcnt);119mutex_unlock(&authnone_lock);120return (dummy);121}122123/* All these unused parameters are required to keep ANSI-C from grumbling */124/*ARGSUSED*/125static void126authnone_verf(AUTH *client)127{128}129130/*ARGSUSED*/131static bool_t132authnone_validate(AUTH *client, struct opaque_auth *opaque)133{134135return (TRUE);136}137138/*ARGSUSED*/139static bool_t140authnone_refresh(AUTH *client, void *dummy)141{142143return (FALSE);144}145146/*ARGSUSED*/147static void148authnone_destroy(AUTH *client)149{150}151152static struct auth_ops *153authnone_ops(void)154{155static struct auth_ops ops;156157/* VARIABLES PROTECTED BY ops_lock: ops */158159mutex_lock(&ops_lock);160if (ops.ah_nextverf == NULL) {161ops.ah_nextverf = authnone_verf;162ops.ah_marshal = authnone_marshal;163ops.ah_validate = authnone_validate;164ops.ah_refresh = authnone_refresh;165ops.ah_destroy = authnone_destroy;166}167mutex_unlock(&ops_lock);168return (&ops);169}170171172