xref: /titanic_44/usr/src/lib/libnsl/rpc/auth_none.c (revision b1dd958f54f8bfa984d306bb8ca8264855761d7b)
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  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
26 /* All Rights Reserved */
27 /*
28  * Portions of this source code were derived from Berkeley
29  * 4.3 BSD under license from the Regents of the University of
30  * California.
31  */
32 
33 #pragma ident	"%Z%%M%	%I%	%E% SMI"
34 
35 /*
36  * auth_none.c
37  * Creates a client authentication handle for passing "null"
38  * credentials and verifiers to remote systems.
39  */
40 
41 #include "mt.h"
42 #include "rpc_mt.h"
43 #include <rpc/types.h>
44 #include <rpc/trace.h>
45 #include <rpc/xdr.h>
46 #include <rpc/auth.h>
47 #define	MAX_MARSHEL_SIZE 20
48 
49 
50 extern bool_t xdr_opaque_auth();
51 
52 static struct auth_ops *authnone_ops();
53 
54 static struct authnone_private {
55 	AUTH	no_client;
56 	char	marshalled_client[MAX_MARSHEL_SIZE];
57 	uint_t	mcnt;
58 } *authnone_private;
59 
60 char *calloc();
61 
62 AUTH *
63 authnone_create()
64 {
65 	struct authnone_private *ap;
66 	XDR xdr_stream;
67 	XDR *xdrs;
68 	extern mutex_t authnone_lock;
69 
70 	/* VARIABLES PROTECTED BY authnone_lock: ap */
71 
72 	trace1(TR_authnone_create, 0);
73 	mutex_lock(&authnone_lock);
74 	ap = authnone_private;
75 	if (ap == NULL) {
76 /* LINTED pointer alignment */
77 		ap = (struct authnone_private *)calloc(1, sizeof (*ap));
78 		if (ap == NULL) {
79 			mutex_unlock(&authnone_lock);
80 			trace1(TR_authnone_create, 1);
81 			return ((AUTH *)NULL);
82 		}
83 		authnone_private = ap;
84 	}
85 	if (!ap->mcnt) {
86 		ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
87 		ap->no_client.ah_ops = authnone_ops();
88 		xdrs = &xdr_stream;
89 		xdrmem_create(xdrs, ap->marshalled_client,
90 			(uint_t)MAX_MARSHEL_SIZE, XDR_ENCODE);
91 		(void) xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
92 		(void) xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
93 		ap->mcnt = XDR_GETPOS(xdrs);
94 		XDR_DESTROY(xdrs);
95 	}
96 	mutex_unlock(&authnone_lock);
97 	trace1(TR_authnone_create, 1);
98 	return (&ap->no_client);
99 }
100 
101 /*ARGSUSED*/
102 static bool_t
103 authnone_marshal(AUTH *client, XDR *xdrs)
104 {
105 	struct authnone_private *ap;
106 	bool_t dummy;
107 	extern mutex_t authnone_lock;
108 
109 	trace1(TR_authnone_marshal, 0);
110 	mutex_lock(&authnone_lock);
111 	ap = authnone_private;
112 	if (ap == NULL) {
113 		mutex_unlock(&authnone_lock);
114 		trace1(TR_authnone_marshal, 1);
115 		return (FALSE);
116 	}
117 	dummy = (*xdrs->x_ops->x_putbytes)(xdrs,
118 			ap->marshalled_client, ap->mcnt);
119 	mutex_unlock(&authnone_lock);
120 	trace1(TR_authnone_marshal, 1);
121 	return (dummy);
122 }
123 
124 /* All these unused parameters are required to keep ANSI-C from grumbling */
125 /*ARGSUSED*/
126 static void
127 authnone_verf(AUTH *client)
128 {
129 	trace1(TR_authnone_verf, 0);
130 	trace1(TR_authnone_verf, 1);
131 }
132 
133 /*ARGSUSED*/
134 static bool_t
135 authnone_validate(AUTH *client, struct opaque_auth *opaque)
136 {
137 	trace1(TR_authnone_validate, 0);
138 	trace1(TR_authnone_validate, 1);
139 	return (TRUE);
140 }
141 
142 /*ARGSUSED*/
143 static bool_t
144 authnone_refresh(AUTH *client, void *dummy)
145 {
146 	trace1(TR_authnone_refresh, 0);
147 	trace1(TR_authnone_refresh, 1);
148 	return (FALSE);
149 }
150 
151 /*ARGSUSED*/
152 static void
153 authnone_destroy(AUTH *client)
154 {
155 	trace1(TR_authnone_destroy, 0);
156 	trace1(TR_authnone_destroy, 1);
157 }
158 
159 static struct auth_ops *
160 authnone_ops()
161 {
162 	static struct auth_ops ops;
163 	extern mutex_t ops_lock;
164 
165 /* VARIABLES PROTECTED BY ops_lock: ops */
166 
167 	trace1(TR_authnone_ops, 0);
168 	mutex_lock(&ops_lock);
169 	if (ops.ah_nextverf == NULL) {
170 		ops.ah_nextverf = authnone_verf;
171 		ops.ah_marshal = authnone_marshal;
172 		ops.ah_validate = authnone_validate;
173 		ops.ah_refresh = authnone_refresh;
174 		ops.ah_destroy = authnone_destroy;
175 	}
176 	mutex_unlock(&ops_lock);
177 	trace1(TR_authnone_ops, 1);
178 	return (&ops);
179 }
180