auth_none.c revision 136581
174462Salfred/*	$NetBSD: auth_none.c,v 1.13 2000/01/22 22:19:17 mycroft Exp $	*/
274462Salfred
31901Swollman/*
41901Swollman * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
51901Swollman * unrestricted use provided that this legend is included on all tape
61901Swollman * media and as a part of the software program in whole or part.  Users
71901Swollman * may copy or modify Sun RPC without charge, but are not authorized
81901Swollman * to license or distribute it to anyone else except as part of a product or
91901Swollman * program developed by the user.
108870Srgrimes *
111901Swollman * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
121901Swollman * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
131901Swollman * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
148870Srgrimes *
151901Swollman * Sun RPC is provided with no support and without any obligation on the
161901Swollman * part of Sun Microsystems, Inc. to assist in its use, correction,
171901Swollman * modification or enhancement.
188870Srgrimes *
191901Swollman * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
201901Swollman * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
211901Swollman * OR ANY PART THEREOF.
228870Srgrimes *
231901Swollman * In no event will Sun Microsystems, Inc. be liable for any lost revenue
241901Swollman * or profits or other special, indirect and consequential damages, even if
251901Swollman * Sun has been advised of the possibility of such damages.
268870Srgrimes *
271901Swollman * Sun Microsystems, Inc.
281901Swollman * 2550 Garcia Avenue
291901Swollman * Mountain View, California  94043
301901Swollman */
311901Swollman
321901Swollman#if defined(LIBC_SCCS) && !defined(lint)
33136581Sobrienstatic char *sccsid2 = "@(#)auth_none.c 1.19 87/08/11 Copyr 1984 Sun Micro";
3474462Salfredstatic char *sccsid = "@(#)auth_none.c	2.1 88/07/29 4.0 RPCSRC";
351901Swollman#endif
3692990Sobrien#include <sys/cdefs.h>
3792990Sobrien__FBSDID("$FreeBSD: head/lib/libc/rpc/auth_none.c 136581 2004-10-16 06:11:35Z obrien $");
381901Swollman
391901Swollman/*
401901Swollman * auth_none.c
418870Srgrimes * Creates a client authentication handle for passing "null"
428870Srgrimes * credentials and verifiers to remote systems.
438870Srgrimes *
448870Srgrimes * Copyright (C) 1984, Sun Microsystems, Inc.
451901Swollman */
461901Swollman
4775094Siedowse#include "namespace.h"
4874462Salfred#include "reentrant.h"
4974462Salfred#include <assert.h>
5011666Sphk#include <stdlib.h>
511901Swollman#include <rpc/types.h>
521901Swollman#include <rpc/xdr.h>
531901Swollman#include <rpc/auth.h>
5474462Salfred#include "un-namespace.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
6874462Salfredextern bool_t xdr_opaque_auth();
6974462Salfred
7074462Salfredstatic struct auth_ops *authnone_ops();
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 *
791901Swollmanauthnone_create()
801901Swollman{
8174462Salfred	struct authnone_private *ap = authnone_private;
821901Swollman	XDR xdr_stream;
8374462Salfred	XDR *xdrs;
8474462Salfred	extern mutex_t authnone_lock;
851901Swollman
8674462Salfred	mutex_lock(&authnone_lock);
871901Swollman	if (ap == 0) {
881901Swollman		ap = (struct authnone_private *)calloc(1, sizeof (*ap));
8974462Salfred		if (ap == 0) {
9074462Salfred			mutex_unlock(&authnone_lock);
911901Swollman			return (0);
9274462Salfred		}
931901Swollman		authnone_private = ap;
941901Swollman	}
951901Swollman	if (!ap->mcnt) {
961901Swollman		ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
9774462Salfred		ap->no_client.ah_ops = authnone_ops();
981901Swollman		xdrs = &xdr_stream;
9974462Salfred		xdrmem_create(xdrs, ap->marshalled_client,
10074462Salfred		    (u_int)MAX_MARSHAL_SIZE, XDR_ENCODE);
1011901Swollman		(void)xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
1021901Swollman		(void)xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
1031901Swollman		ap->mcnt = XDR_GETPOS(xdrs);
1041901Swollman		XDR_DESTROY(xdrs);
1051901Swollman	}
10674462Salfred	mutex_unlock(&authnone_lock);
1071901Swollman	return (&ap->no_client);
1081901Swollman}
1091901Swollman
1101901Swollman/*ARGSUSED*/
1111901Swollmanstatic bool_t
11274462Salfredauthnone_marshal(AUTH *client, XDR *xdrs)
1131901Swollman{
11474462Salfred	struct authnone_private *ap;
11574462Salfred	bool_t dummy;
11674462Salfred	extern mutex_t authnone_lock;
1171901Swollman
11874462Salfred	assert(xdrs != NULL);
11974462Salfred
12074462Salfred	ap = authnone_private;
12174462Salfred	if (ap == NULL) {
12274462Salfred		mutex_unlock(&authnone_lock);
12374462Salfred		return (FALSE);
12474462Salfred	}
12574462Salfred	dummy = (*xdrs->x_ops->x_putbytes)(xdrs,
12674462Salfred	    ap->marshalled_client, ap->mcnt);
12774462Salfred	mutex_unlock(&authnone_lock);
12874462Salfred	return (dummy);
1291901Swollman}
1301901Swollman
13174462Salfred/* All these unused parameters are required to keep ANSI-C from grumbling */
13274462Salfred/*ARGSUSED*/
1338870Srgrimesstatic void
13474462Salfredauthnone_verf(AUTH *client)
1351901Swollman{
1361901Swollman}
1371901Swollman
13874462Salfred/*ARGSUSED*/
1391901Swollmanstatic bool_t
14074462Salfredauthnone_validate(AUTH *client, struct opaque_auth *opaque)
1411901Swollman{
1421901Swollman
1431901Swollman	return (TRUE);
1441901Swollman}
1451901Swollman
14674462Salfred/*ARGSUSED*/
1471901Swollmanstatic bool_t
14874462Salfredauthnone_refresh(AUTH *client, void *dummy)
1491901Swollman{
1501901Swollman
1511901Swollman	return (FALSE);
1521901Swollman}
1531901Swollman
15474462Salfred/*ARGSUSED*/
1551901Swollmanstatic void
15674462Salfredauthnone_destroy(AUTH *client)
1571901Swollman{
1581901Swollman}
15974462Salfred
16074462Salfredstatic struct auth_ops *
16174462Salfredauthnone_ops()
16274462Salfred{
16374462Salfred	static struct auth_ops ops;
16474462Salfred	extern mutex_t ops_lock;
16574462Salfred
16674462Salfred/* VARIABLES PROTECTED BY ops_lock: ops */
16774462Salfred
16874462Salfred	mutex_lock(&ops_lock);
16974462Salfred	if (ops.ah_nextverf == NULL) {
17074462Salfred		ops.ah_nextverf = authnone_verf;
17174462Salfred		ops.ah_marshal = authnone_marshal;
17274462Salfred		ops.ah_validate = authnone_validate;
17374462Salfred		ops.ah_refresh = authnone_refresh;
17474462Salfred		ops.ah_destroy = authnone_destroy;
17574462Salfred	}
17674462Salfred	mutex_unlock(&ops_lock);
17774462Salfred	return (&ops);
17874462Salfred}
179