1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License").  You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22/*
23 * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27/* from SunOS 4.1 */
28#pragma ident	"%Z%%M%	%I%	%E% SMI"
29
30/*
31 * modified for use by the boot program.
32 *
33 * auth_none.c
34 * Creates a client authentication handle for passing "null"
35 * credentials and verifiers to remote systems.
36 */
37
38#include <rpc/types.h>
39#include <rpc/xdr.h>
40#include <rpc/auth.h>
41#include "clnt.h"
42
43#define	MAX_MARSHEL_SIZE 20
44
45static struct auth_ops *authnone_ops();
46
47static struct authnone_private {
48	AUTH	no_client;
49	char	marshalled_client[MAX_MARSHEL_SIZE];
50	uint_t	mcnt;
51} *authnone_private;
52
53static struct authnone_private authnone_local;
54
55AUTH *
56authnone_create(void)
57{
58	struct authnone_private *ap = authnone_private;
59	XDR xdr_stream;
60	XDR *xdrs;
61
62	if (ap == 0) {
63		ap = &authnone_local;
64		authnone_private = ap;
65	}
66	if (!ap->mcnt) {
67		ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
68		ap->no_client.ah_ops = authnone_ops();
69		xdrs = &xdr_stream;
70		xdrmem_create(xdrs, ap->marshalled_client,
71			(uint_t)MAX_MARSHEL_SIZE, XDR_ENCODE);
72		(void) xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
73		(void) xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
74		ap->mcnt = XDR_GETPOS(xdrs);
75		XDR_DESTROY(xdrs);
76	}
77	return (&ap->no_client);
78}
79
80/*ARGSUSED*/
81static bool_t
82authnone_marshal(AUTH *client, XDR *xdrs, struct cred *cr)
83{
84	struct authnone_private *ap = authnone_private;
85
86	if (ap == 0)
87		return (0);
88	return ((*xdrs->x_ops->x_putbytes)(xdrs,
89	    ap->marshalled_client, ap->mcnt));
90}
91
92/* ARGSUSED */
93static void
94authnone_verf(AUTH *foo)
95{
96}
97
98/* ARGSUSED */
99static bool_t
100authnone_validate(AUTH *foo, struct opaque_auth *bar)
101{
102	return (TRUE);
103}
104
105/* ARGSUSED */
106static bool_t
107authnone_refresh(AUTH *foo, struct rpc_msg *bar, cred_t *cr)
108{
109	return (FALSE);
110}
111
112/* ARGSUSED */
113static void
114authnone_destroy(AUTH *foo)
115{
116}
117
118static struct auth_ops *
119authnone_ops(void)
120{
121	static struct auth_ops ops;
122
123	if (ops.ah_nextverf == NULL) {
124		ops.ah_nextverf = authnone_verf;
125		ops.ah_marshal = authnone_marshal;
126		ops.ah_validate = authnone_validate;
127		ops.ah_refresh = authnone_refresh;
128		ops.ah_destroy = authnone_destroy;
129	}
130	return (&ops);
131}
132