import less(1)
[unleashed/tickless.git] / usr / src / lib / libc / port / nsl / auth_none.c
blob893c4a96e37d6e520bf06ebdd7c1b87d3bd59432
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
24 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
30 * Portions of this source code were derived from Berkeley
31 * 4.3 BSD under license from the Regents of the University of
32 * California.
35 #pragma ident "%Z%%M% %I% %E% SMI"
38 * auth_none.c
39 * Creates a client authentication handle for passing "null"
40 * credentials and verifiers to remote systems.
43 #include "mt.h"
44 #include "rpc_mt.h"
45 #include <stdlib.h>
46 #include <rpc/types.h>
47 #include <rpc/xdr.h>
48 #include <rpc/auth.h>
49 #define MAX_MARSHEL_SIZE 20
52 extern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *);
54 static struct auth_ops *authnone_ops(void);
56 static struct authnone_private {
57 AUTH no_client;
58 char marshalled_client[MAX_MARSHEL_SIZE];
59 uint_t mcnt;
60 } *authnone_private;
63 AUTH *
64 authnone_create(void)
66 struct authnone_private *ap;
67 XDR xdr_stream;
68 XDR *xdrs;
69 extern mutex_t authnone_lock;
71 /* VARIABLES PROTECTED BY authnone_lock: ap */
73 (void) mutex_lock(&authnone_lock);
74 ap = authnone_private;
75 if (ap == NULL) {
76 ap = calloc(1, sizeof (*ap));
77 if (ap == NULL) {
78 (void) mutex_unlock(&authnone_lock);
79 return (NULL);
81 authnone_private = ap;
83 if (!ap->mcnt) {
84 ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
85 ap->no_client.ah_ops = authnone_ops();
86 xdrs = &xdr_stream;
87 xdrmem_create(xdrs, ap->marshalled_client,
88 (uint_t)MAX_MARSHEL_SIZE, XDR_ENCODE);
89 (void) xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
90 (void) xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
91 ap->mcnt = XDR_GETPOS(xdrs);
92 XDR_DESTROY(xdrs);
94 (void) mutex_unlock(&authnone_lock);
95 return (&ap->no_client);
98 /*ARGSUSED*/
99 static bool_t
100 authnone_marshal(AUTH *client, XDR *xdrs)
102 struct authnone_private *ap;
103 bool_t res;
104 extern mutex_t authnone_lock;
106 (void) mutex_lock(&authnone_lock);
107 ap = authnone_private;
108 if (ap == NULL) {
109 (void) mutex_unlock(&authnone_lock);
110 return (FALSE);
112 res = (*xdrs->x_ops->x_putbytes)(xdrs,
113 ap->marshalled_client, ap->mcnt);
114 (void) mutex_unlock(&authnone_lock);
115 return (res);
118 /* All these unused parameters are required to keep ANSI-C from grumbling */
119 /*ARGSUSED*/
120 static void
121 authnone_verf(AUTH *client)
125 /*ARGSUSED*/
126 static bool_t
127 authnone_validate(AUTH *client, struct opaque_auth *opaque)
129 return (TRUE);
132 /*ARGSUSED*/
133 static bool_t
134 authnone_refresh(AUTH *client, void *dummy)
136 return (FALSE);
139 /*ARGSUSED*/
140 static void
141 authnone_destroy(AUTH *client)
145 static struct auth_ops *
146 authnone_ops(void)
148 static struct auth_ops ops;
149 extern mutex_t ops_lock;
151 /* VARIABLES PROTECTED BY ops_lock: ops */
153 (void) mutex_lock(&ops_lock);
154 if (ops.ah_nextverf == NULL) {
155 ops.ah_nextverf = authnone_verf;
156 ops.ah_marshal = authnone_marshal;
157 ops.ah_validate = authnone_validate;
158 ops.ah_refresh = authnone_refresh;
159 ops.ah_destroy = authnone_destroy;
161 (void) mutex_unlock(&ops_lock);
162 return (&ops);