xref: /onnv-gate/usr/src/lib/libnsl/rpc/auth_none.c (revision 132:e3f7eaf7dde4)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
21*132Srobinson  */
22*132Srobinson 
23*132Srobinson /*
24*132Srobinson  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
250Sstevel@tonic-gate  * Use is subject to license terms.
260Sstevel@tonic-gate  */
270Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
280Sstevel@tonic-gate /* All Rights Reserved */
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate  * Portions of this source code were derived from Berkeley
310Sstevel@tonic-gate  * 4.3 BSD under license from the Regents of the University of
320Sstevel@tonic-gate  * California.
330Sstevel@tonic-gate  */
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
360Sstevel@tonic-gate 
370Sstevel@tonic-gate /*
380Sstevel@tonic-gate  * auth_none.c
390Sstevel@tonic-gate  * Creates a client authentication handle for passing "null"
400Sstevel@tonic-gate  * credentials and verifiers to remote systems.
410Sstevel@tonic-gate  */
420Sstevel@tonic-gate 
430Sstevel@tonic-gate #include "mt.h"
440Sstevel@tonic-gate #include "rpc_mt.h"
45*132Srobinson #include <stdlib.h>
460Sstevel@tonic-gate #include <rpc/types.h>
470Sstevel@tonic-gate #include <rpc/xdr.h>
480Sstevel@tonic-gate #include <rpc/auth.h>
490Sstevel@tonic-gate #define	MAX_MARSHEL_SIZE 20
500Sstevel@tonic-gate 
510Sstevel@tonic-gate 
52*132Srobinson extern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *);
530Sstevel@tonic-gate 
54*132Srobinson static struct auth_ops *authnone_ops(void);
550Sstevel@tonic-gate 
560Sstevel@tonic-gate static struct authnone_private {
570Sstevel@tonic-gate 	AUTH	no_client;
580Sstevel@tonic-gate 	char	marshalled_client[MAX_MARSHEL_SIZE];
590Sstevel@tonic-gate 	uint_t	mcnt;
600Sstevel@tonic-gate } *authnone_private;
610Sstevel@tonic-gate 
620Sstevel@tonic-gate 
630Sstevel@tonic-gate AUTH *
authnone_create(void)64*132Srobinson authnone_create(void)
650Sstevel@tonic-gate {
660Sstevel@tonic-gate 	struct authnone_private *ap;
670Sstevel@tonic-gate 	XDR xdr_stream;
680Sstevel@tonic-gate 	XDR *xdrs;
690Sstevel@tonic-gate 	extern mutex_t authnone_lock;
700Sstevel@tonic-gate 
710Sstevel@tonic-gate 	/* VARIABLES PROTECTED BY authnone_lock: ap */
720Sstevel@tonic-gate 
73*132Srobinson 	(void) mutex_lock(&authnone_lock);
740Sstevel@tonic-gate 	ap = authnone_private;
750Sstevel@tonic-gate 	if (ap == NULL) {
76*132Srobinson 		ap = calloc(1, sizeof (*ap));
770Sstevel@tonic-gate 		if (ap == NULL) {
78*132Srobinson 			(void) mutex_unlock(&authnone_lock);
79*132Srobinson 			return (NULL);
800Sstevel@tonic-gate 		}
810Sstevel@tonic-gate 		authnone_private = ap;
820Sstevel@tonic-gate 	}
830Sstevel@tonic-gate 	if (!ap->mcnt) {
840Sstevel@tonic-gate 		ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
850Sstevel@tonic-gate 		ap->no_client.ah_ops = authnone_ops();
860Sstevel@tonic-gate 		xdrs = &xdr_stream;
870Sstevel@tonic-gate 		xdrmem_create(xdrs, ap->marshalled_client,
880Sstevel@tonic-gate 			(uint_t)MAX_MARSHEL_SIZE, XDR_ENCODE);
890Sstevel@tonic-gate 		(void) xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
900Sstevel@tonic-gate 		(void) xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
910Sstevel@tonic-gate 		ap->mcnt = XDR_GETPOS(xdrs);
920Sstevel@tonic-gate 		XDR_DESTROY(xdrs);
930Sstevel@tonic-gate 	}
94*132Srobinson 	(void) mutex_unlock(&authnone_lock);
950Sstevel@tonic-gate 	return (&ap->no_client);
960Sstevel@tonic-gate }
970Sstevel@tonic-gate 
980Sstevel@tonic-gate /*ARGSUSED*/
990Sstevel@tonic-gate static bool_t
authnone_marshal(AUTH * client,XDR * xdrs)1000Sstevel@tonic-gate authnone_marshal(AUTH *client, XDR *xdrs)
1010Sstevel@tonic-gate {
1020Sstevel@tonic-gate 	struct authnone_private *ap;
103*132Srobinson 	bool_t res;
1040Sstevel@tonic-gate 	extern mutex_t authnone_lock;
1050Sstevel@tonic-gate 
106*132Srobinson 	(void) mutex_lock(&authnone_lock);
1070Sstevel@tonic-gate 	ap = authnone_private;
1080Sstevel@tonic-gate 	if (ap == NULL) {
109*132Srobinson 		(void) mutex_unlock(&authnone_lock);
1100Sstevel@tonic-gate 		return (FALSE);
1110Sstevel@tonic-gate 	}
112*132Srobinson 	res = (*xdrs->x_ops->x_putbytes)(xdrs,
1130Sstevel@tonic-gate 			ap->marshalled_client, ap->mcnt);
114*132Srobinson 	(void) mutex_unlock(&authnone_lock);
115*132Srobinson 	return (res);
1160Sstevel@tonic-gate }
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate /* All these unused parameters are required to keep ANSI-C from grumbling */
1190Sstevel@tonic-gate /*ARGSUSED*/
1200Sstevel@tonic-gate static void
authnone_verf(AUTH * client)1210Sstevel@tonic-gate authnone_verf(AUTH *client)
1220Sstevel@tonic-gate {
1230Sstevel@tonic-gate }
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate /*ARGSUSED*/
1260Sstevel@tonic-gate static bool_t
authnone_validate(AUTH * client,struct opaque_auth * opaque)1270Sstevel@tonic-gate authnone_validate(AUTH *client, struct opaque_auth *opaque)
1280Sstevel@tonic-gate {
1290Sstevel@tonic-gate 	return (TRUE);
1300Sstevel@tonic-gate }
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate /*ARGSUSED*/
1330Sstevel@tonic-gate static bool_t
authnone_refresh(AUTH * client,void * dummy)1340Sstevel@tonic-gate authnone_refresh(AUTH *client, void *dummy)
1350Sstevel@tonic-gate {
1360Sstevel@tonic-gate 	return (FALSE);
1370Sstevel@tonic-gate }
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate /*ARGSUSED*/
1400Sstevel@tonic-gate static void
authnone_destroy(AUTH * client)1410Sstevel@tonic-gate authnone_destroy(AUTH *client)
1420Sstevel@tonic-gate {
1430Sstevel@tonic-gate }
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate static struct auth_ops *
authnone_ops(void)146*132Srobinson authnone_ops(void)
1470Sstevel@tonic-gate {
1480Sstevel@tonic-gate 	static struct auth_ops ops;
1490Sstevel@tonic-gate 	extern mutex_t ops_lock;
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate /* VARIABLES PROTECTED BY ops_lock: ops */
1520Sstevel@tonic-gate 
153*132Srobinson 	(void) mutex_lock(&ops_lock);
1540Sstevel@tonic-gate 	if (ops.ah_nextverf == NULL) {
1550Sstevel@tonic-gate 		ops.ah_nextverf = authnone_verf;
1560Sstevel@tonic-gate 		ops.ah_marshal = authnone_marshal;
1570Sstevel@tonic-gate 		ops.ah_validate = authnone_validate;
1580Sstevel@tonic-gate 		ops.ah_refresh = authnone_refresh;
1590Sstevel@tonic-gate 		ops.ah_destroy = authnone_destroy;
1600Sstevel@tonic-gate 	}
161*132Srobinson 	(void) mutex_unlock(&ops_lock);
1620Sstevel@tonic-gate 	return (&ops);
1630Sstevel@tonic-gate }
164