17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*61961e0fSrobinson */
22*61961e0fSrobinson
23*61961e0fSrobinson /*
24*61961e0fSrobinson * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
257c478bd9Sstevel@tonic-gate * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate */
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate * Portions of this source code were derived from Berkeley
317c478bd9Sstevel@tonic-gate * 4.3 BSD under license from the Regents of the University of
327c478bd9Sstevel@tonic-gate * California.
337c478bd9Sstevel@tonic-gate */
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
367c478bd9Sstevel@tonic-gate
377c478bd9Sstevel@tonic-gate /*
387c478bd9Sstevel@tonic-gate * auth_none.c
397c478bd9Sstevel@tonic-gate * Creates a client authentication handle for passing "null"
407c478bd9Sstevel@tonic-gate * credentials and verifiers to remote systems.
417c478bd9Sstevel@tonic-gate */
427c478bd9Sstevel@tonic-gate
437c478bd9Sstevel@tonic-gate #include "mt.h"
447c478bd9Sstevel@tonic-gate #include "rpc_mt.h"
45*61961e0fSrobinson #include <stdlib.h>
467c478bd9Sstevel@tonic-gate #include <rpc/types.h>
477c478bd9Sstevel@tonic-gate #include <rpc/xdr.h>
487c478bd9Sstevel@tonic-gate #include <rpc/auth.h>
497c478bd9Sstevel@tonic-gate #define MAX_MARSHEL_SIZE 20
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate
52*61961e0fSrobinson extern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *);
537c478bd9Sstevel@tonic-gate
54*61961e0fSrobinson static struct auth_ops *authnone_ops(void);
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate static struct authnone_private {
577c478bd9Sstevel@tonic-gate AUTH no_client;
587c478bd9Sstevel@tonic-gate char marshalled_client[MAX_MARSHEL_SIZE];
597c478bd9Sstevel@tonic-gate uint_t mcnt;
607c478bd9Sstevel@tonic-gate } *authnone_private;
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate
637c478bd9Sstevel@tonic-gate AUTH *
authnone_create(void)64*61961e0fSrobinson authnone_create(void)
657c478bd9Sstevel@tonic-gate {
667c478bd9Sstevel@tonic-gate struct authnone_private *ap;
677c478bd9Sstevel@tonic-gate XDR xdr_stream;
687c478bd9Sstevel@tonic-gate XDR *xdrs;
697c478bd9Sstevel@tonic-gate extern mutex_t authnone_lock;
707c478bd9Sstevel@tonic-gate
717c478bd9Sstevel@tonic-gate /* VARIABLES PROTECTED BY authnone_lock: ap */
727c478bd9Sstevel@tonic-gate
73*61961e0fSrobinson (void) mutex_lock(&authnone_lock);
747c478bd9Sstevel@tonic-gate ap = authnone_private;
757c478bd9Sstevel@tonic-gate if (ap == NULL) {
76*61961e0fSrobinson ap = calloc(1, sizeof (*ap));
777c478bd9Sstevel@tonic-gate if (ap == NULL) {
78*61961e0fSrobinson (void) mutex_unlock(&authnone_lock);
79*61961e0fSrobinson return (NULL);
807c478bd9Sstevel@tonic-gate }
817c478bd9Sstevel@tonic-gate authnone_private = ap;
827c478bd9Sstevel@tonic-gate }
837c478bd9Sstevel@tonic-gate if (!ap->mcnt) {
847c478bd9Sstevel@tonic-gate ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
857c478bd9Sstevel@tonic-gate ap->no_client.ah_ops = authnone_ops();
867c478bd9Sstevel@tonic-gate xdrs = &xdr_stream;
877c478bd9Sstevel@tonic-gate xdrmem_create(xdrs, ap->marshalled_client,
887c478bd9Sstevel@tonic-gate (uint_t)MAX_MARSHEL_SIZE, XDR_ENCODE);
897c478bd9Sstevel@tonic-gate (void) xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
907c478bd9Sstevel@tonic-gate (void) xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
917c478bd9Sstevel@tonic-gate ap->mcnt = XDR_GETPOS(xdrs);
927c478bd9Sstevel@tonic-gate XDR_DESTROY(xdrs);
937c478bd9Sstevel@tonic-gate }
94*61961e0fSrobinson (void) mutex_unlock(&authnone_lock);
957c478bd9Sstevel@tonic-gate return (&ap->no_client);
967c478bd9Sstevel@tonic-gate }
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate /*ARGSUSED*/
997c478bd9Sstevel@tonic-gate static bool_t
authnone_marshal(AUTH * client,XDR * xdrs)1007c478bd9Sstevel@tonic-gate authnone_marshal(AUTH *client, XDR *xdrs)
1017c478bd9Sstevel@tonic-gate {
1027c478bd9Sstevel@tonic-gate struct authnone_private *ap;
103*61961e0fSrobinson bool_t res;
1047c478bd9Sstevel@tonic-gate extern mutex_t authnone_lock;
1057c478bd9Sstevel@tonic-gate
106*61961e0fSrobinson (void) mutex_lock(&authnone_lock);
1077c478bd9Sstevel@tonic-gate ap = authnone_private;
1087c478bd9Sstevel@tonic-gate if (ap == NULL) {
109*61961e0fSrobinson (void) mutex_unlock(&authnone_lock);
1107c478bd9Sstevel@tonic-gate return (FALSE);
1117c478bd9Sstevel@tonic-gate }
112*61961e0fSrobinson res = (*xdrs->x_ops->x_putbytes)(xdrs,
1137c478bd9Sstevel@tonic-gate ap->marshalled_client, ap->mcnt);
114*61961e0fSrobinson (void) mutex_unlock(&authnone_lock);
115*61961e0fSrobinson return (res);
1167c478bd9Sstevel@tonic-gate }
1177c478bd9Sstevel@tonic-gate
1187c478bd9Sstevel@tonic-gate /* All these unused parameters are required to keep ANSI-C from grumbling */
1197c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1207c478bd9Sstevel@tonic-gate static void
authnone_verf(AUTH * client)1217c478bd9Sstevel@tonic-gate authnone_verf(AUTH *client)
1227c478bd9Sstevel@tonic-gate {
1237c478bd9Sstevel@tonic-gate }
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1267c478bd9Sstevel@tonic-gate static bool_t
authnone_validate(AUTH * client,struct opaque_auth * opaque)1277c478bd9Sstevel@tonic-gate authnone_validate(AUTH *client, struct opaque_auth *opaque)
1287c478bd9Sstevel@tonic-gate {
1297c478bd9Sstevel@tonic-gate return (TRUE);
1307c478bd9Sstevel@tonic-gate }
1317c478bd9Sstevel@tonic-gate
1327c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1337c478bd9Sstevel@tonic-gate static bool_t
authnone_refresh(AUTH * client,void * dummy)1347c478bd9Sstevel@tonic-gate authnone_refresh(AUTH *client, void *dummy)
1357c478bd9Sstevel@tonic-gate {
1367c478bd9Sstevel@tonic-gate return (FALSE);
1377c478bd9Sstevel@tonic-gate }
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1407c478bd9Sstevel@tonic-gate static void
authnone_destroy(AUTH * client)1417c478bd9Sstevel@tonic-gate authnone_destroy(AUTH *client)
1427c478bd9Sstevel@tonic-gate {
1437c478bd9Sstevel@tonic-gate }
1447c478bd9Sstevel@tonic-gate
1457c478bd9Sstevel@tonic-gate static struct auth_ops *
authnone_ops(void)146*61961e0fSrobinson authnone_ops(void)
1477c478bd9Sstevel@tonic-gate {
1487c478bd9Sstevel@tonic-gate static struct auth_ops ops;
1497c478bd9Sstevel@tonic-gate extern mutex_t ops_lock;
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate /* VARIABLES PROTECTED BY ops_lock: ops */
1527c478bd9Sstevel@tonic-gate
153*61961e0fSrobinson (void) mutex_lock(&ops_lock);
1547c478bd9Sstevel@tonic-gate if (ops.ah_nextverf == NULL) {
1557c478bd9Sstevel@tonic-gate ops.ah_nextverf = authnone_verf;
1567c478bd9Sstevel@tonic-gate ops.ah_marshal = authnone_marshal;
1577c478bd9Sstevel@tonic-gate ops.ah_validate = authnone_validate;
1587c478bd9Sstevel@tonic-gate ops.ah_refresh = authnone_refresh;
1597c478bd9Sstevel@tonic-gate ops.ah_destroy = authnone_destroy;
1607c478bd9Sstevel@tonic-gate }
161*61961e0fSrobinson (void) mutex_unlock(&ops_lock);
1627c478bd9Sstevel@tonic-gate return (&ops);
1637c478bd9Sstevel@tonic-gate }
164