174462Salfred/* $NetBSD: auth_none.c,v 1.13 2000/01/22 22:19:17 mycroft Exp $ */ 274462Salfred 3258578Shrs/*- 4258578Shrs * Copyright (c) 2009, Sun Microsystems, Inc. 5258578Shrs * All rights reserved. 68870Srgrimes * 7258578Shrs * Redistribution and use in source and binary forms, with or without 8258578Shrs * modification, are permitted provided that the following conditions are met: 9258578Shrs * - Redistributions of source code must retain the above copyright notice, 10258578Shrs * this list of conditions and the following disclaimer. 11258578Shrs * - Redistributions in binary form must reproduce the above copyright notice, 12258578Shrs * this list of conditions and the following disclaimer in the documentation 13258578Shrs * and/or other materials provided with the distribution. 14258578Shrs * - Neither the name of Sun Microsystems, Inc. nor the names of its 15258578Shrs * contributors may be used to endorse or promote products derived 16258578Shrs * from this software without specific prior written permission. 17258578Shrs * 18258578Shrs * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19258578Shrs * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20258578Shrs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21258578Shrs * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22258578Shrs * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23258578Shrs * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24258578Shrs * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25258578Shrs * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26258578Shrs * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27258578Shrs * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28258578Shrs * POSSIBILITY OF SUCH DAMAGE. 291901Swollman */ 301901Swollman 311901Swollman#if defined(LIBC_SCCS) && !defined(lint) 32136581Sobrienstatic char *sccsid2 = "@(#)auth_none.c 1.19 87/08/11 Copyr 1984 Sun Micro"; 3374462Salfredstatic char *sccsid = "@(#)auth_none.c 2.1 88/07/29 4.0 RPCSRC"; 341901Swollman#endif 3592990Sobrien#include <sys/cdefs.h> 3692990Sobrien__FBSDID("$FreeBSD$"); 371901Swollman 381901Swollman/* 391901Swollman * auth_none.c 408870Srgrimes * Creates a client authentication handle for passing "null" 418870Srgrimes * credentials and verifiers to remote systems. 428870Srgrimes * 438870Srgrimes * Copyright (C) 1984, Sun Microsystems, Inc. 441901Swollman */ 451901Swollman 4675094Siedowse#include "namespace.h" 4774462Salfred#include "reentrant.h" 4874462Salfred#include <assert.h> 4911666Sphk#include <stdlib.h> 501901Swollman#include <rpc/types.h> 511901Swollman#include <rpc/xdr.h> 521901Swollman#include <rpc/auth.h> 5374462Salfred#include "un-namespace.h" 54156090Sdeischen#include "mt_misc.h" 551901Swollman 5674462Salfred#define MAX_MARSHAL_SIZE 20 5774462Salfred 581901Swollman/* 591901Swollman * Authenticator operations routines 601901Swollman */ 611901Swollman 6274462Salfredstatic bool_t authnone_marshal (AUTH *, XDR *); 6374462Salfredstatic void authnone_verf (AUTH *); 6474462Salfredstatic bool_t authnone_validate (AUTH *, struct opaque_auth *); 6574462Salfredstatic bool_t authnone_refresh (AUTH *, void *); 6674462Salfredstatic void authnone_destroy (AUTH *); 671901Swollman 68287350Srodrigcextern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *); 6974462Salfred 70287350Srodrigcstatic struct auth_ops *authnone_ops(void); 7174462Salfred 721901Swollmanstatic struct authnone_private { 731901Swollman AUTH no_client; 7474462Salfred char marshalled_client[MAX_MARSHAL_SIZE]; 751901Swollman u_int mcnt; 761901Swollman} *authnone_private; 771901Swollman 781901SwollmanAUTH * 79287350Srodrigcauthnone_create(void) 801901Swollman{ 8174462Salfred struct authnone_private *ap = authnone_private; 821901Swollman XDR xdr_stream; 8374462Salfred XDR *xdrs; 841901Swollman 8574462Salfred mutex_lock(&authnone_lock); 86297790Spfg if (ap == NULL) { 87297790Spfg ap = calloc(1, sizeof (*ap)); 88297790Spfg if (ap == NULL) { 8974462Salfred mutex_unlock(&authnone_lock); 901901Swollman return (0); 9174462Salfred } 921901Swollman authnone_private = ap; 931901Swollman } 941901Swollman if (!ap->mcnt) { 951901Swollman ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth; 9674462Salfred ap->no_client.ah_ops = authnone_ops(); 971901Swollman xdrs = &xdr_stream; 9874462Salfred xdrmem_create(xdrs, ap->marshalled_client, 9974462Salfred (u_int)MAX_MARSHAL_SIZE, XDR_ENCODE); 1001901Swollman (void)xdr_opaque_auth(xdrs, &ap->no_client.ah_cred); 1011901Swollman (void)xdr_opaque_auth(xdrs, &ap->no_client.ah_verf); 1021901Swollman ap->mcnt = XDR_GETPOS(xdrs); 1031901Swollman XDR_DESTROY(xdrs); 1041901Swollman } 10574462Salfred mutex_unlock(&authnone_lock); 1061901Swollman return (&ap->no_client); 1071901Swollman} 1081901Swollman 1091901Swollman/*ARGSUSED*/ 1101901Swollmanstatic bool_t 11174462Salfredauthnone_marshal(AUTH *client, XDR *xdrs) 1121901Swollman{ 11374462Salfred struct authnone_private *ap; 11474462Salfred bool_t dummy; 1151901Swollman 11674462Salfred assert(xdrs != NULL); 11774462Salfred 11874462Salfred ap = authnone_private; 11974462Salfred if (ap == NULL) { 12074462Salfred mutex_unlock(&authnone_lock); 12174462Salfred return (FALSE); 12274462Salfred } 12374462Salfred dummy = (*xdrs->x_ops->x_putbytes)(xdrs, 12474462Salfred ap->marshalled_client, ap->mcnt); 12574462Salfred mutex_unlock(&authnone_lock); 12674462Salfred return (dummy); 1271901Swollman} 1281901Swollman 12974462Salfred/* All these unused parameters are required to keep ANSI-C from grumbling */ 13074462Salfred/*ARGSUSED*/ 1318870Srgrimesstatic void 13274462Salfredauthnone_verf(AUTH *client) 1331901Swollman{ 1341901Swollman} 1351901Swollman 13674462Salfred/*ARGSUSED*/ 1371901Swollmanstatic bool_t 13874462Salfredauthnone_validate(AUTH *client, struct opaque_auth *opaque) 1391901Swollman{ 1401901Swollman 1411901Swollman return (TRUE); 1421901Swollman} 1431901Swollman 14474462Salfred/*ARGSUSED*/ 1451901Swollmanstatic bool_t 14674462Salfredauthnone_refresh(AUTH *client, void *dummy) 1471901Swollman{ 1481901Swollman 1491901Swollman return (FALSE); 1501901Swollman} 1511901Swollman 15274462Salfred/*ARGSUSED*/ 1531901Swollmanstatic void 15474462Salfredauthnone_destroy(AUTH *client) 1551901Swollman{ 1561901Swollman} 15774462Salfred 15874462Salfredstatic struct auth_ops * 159287350Srodrigcauthnone_ops(void) 16074462Salfred{ 16174462Salfred static struct auth_ops ops; 16274462Salfred 16374462Salfred/* VARIABLES PROTECTED BY ops_lock: ops */ 16474462Salfred 16574462Salfred mutex_lock(&ops_lock); 16674462Salfred if (ops.ah_nextverf == NULL) { 16774462Salfred ops.ah_nextverf = authnone_verf; 16874462Salfred ops.ah_marshal = authnone_marshal; 16974462Salfred ops.ah_validate = authnone_validate; 17074462Salfred ops.ah_refresh = authnone_refresh; 17174462Salfred ops.ah_destroy = authnone_destroy; 17274462Salfred } 17374462Salfred mutex_unlock(&ops_lock); 17474462Salfred return (&ops); 17574462Salfred} 176