1 | #include <machine/rtems-bsd-user-space.h> |
---|
2 | |
---|
3 | /* $NetBSD: auth_none.c,v 1.13 2000/01/22 22:19:17 mycroft Exp $ */ |
---|
4 | |
---|
5 | /*- |
---|
6 | * SPDX-License-Identifier: BSD-3-Clause |
---|
7 | * |
---|
8 | * Copyright (c) 2009, Sun Microsystems, Inc. |
---|
9 | * All rights reserved. |
---|
10 | * |
---|
11 | * Redistribution and use in source and binary forms, with or without |
---|
12 | * modification, are permitted provided that the following conditions are met: |
---|
13 | * - Redistributions of source code must retain the above copyright notice, |
---|
14 | * this list of conditions and the following disclaimer. |
---|
15 | * - Redistributions in binary form must reproduce the above copyright notice, |
---|
16 | * this list of conditions and the following disclaimer in the documentation |
---|
17 | * and/or other materials provided with the distribution. |
---|
18 | * - Neither the name of Sun Microsystems, Inc. nor the names of its |
---|
19 | * contributors may be used to endorse or promote products derived |
---|
20 | * from this software without specific prior written permission. |
---|
21 | * |
---|
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
---|
26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
32 | * POSSIBILITY OF SUCH DAMAGE. |
---|
33 | */ |
---|
34 | |
---|
35 | #if defined(LIBC_SCCS) && !defined(lint) |
---|
36 | static char *sccsid2 = "@(#)auth_none.c 1.19 87/08/11 Copyr 1984 Sun Micro"; |
---|
37 | static char *sccsid = "@(#)auth_none.c 2.1 88/07/29 4.0 RPCSRC"; |
---|
38 | #endif |
---|
39 | #include <sys/cdefs.h> |
---|
40 | __FBSDID("$FreeBSD$"); |
---|
41 | |
---|
42 | /* |
---|
43 | * auth_none.c |
---|
44 | * Creates a client authentication handle for passing "null" |
---|
45 | * credentials and verifiers to remote systems. |
---|
46 | * |
---|
47 | * Copyright (C) 1984, Sun Microsystems, Inc. |
---|
48 | */ |
---|
49 | |
---|
50 | #include "namespace.h" |
---|
51 | #include "reentrant.h" |
---|
52 | #include <assert.h> |
---|
53 | #include <stdlib.h> |
---|
54 | #include <rpc/types.h> |
---|
55 | #include <rpc/xdr.h> |
---|
56 | #include <rpc/auth.h> |
---|
57 | #include "un-namespace.h" |
---|
58 | #include "mt_misc.h" |
---|
59 | |
---|
60 | #define MAX_MARSHAL_SIZE 20 |
---|
61 | |
---|
62 | /* |
---|
63 | * Authenticator operations routines |
---|
64 | */ |
---|
65 | |
---|
66 | static bool_t authnone_marshal (AUTH *, XDR *); |
---|
67 | static void authnone_verf (AUTH *); |
---|
68 | static bool_t authnone_validate (AUTH *, struct opaque_auth *); |
---|
69 | static bool_t authnone_refresh (AUTH *, void *); |
---|
70 | static void authnone_destroy (AUTH *); |
---|
71 | |
---|
72 | extern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *); |
---|
73 | |
---|
74 | static struct auth_ops *authnone_ops(void); |
---|
75 | |
---|
76 | static struct authnone_private { |
---|
77 | AUTH no_client; |
---|
78 | char marshalled_client[MAX_MARSHAL_SIZE]; |
---|
79 | u_int mcnt; |
---|
80 | } *authnone_private; |
---|
81 | |
---|
82 | AUTH * |
---|
83 | authnone_create(void) |
---|
84 | { |
---|
85 | struct authnone_private *ap = authnone_private; |
---|
86 | XDR xdr_stream; |
---|
87 | XDR *xdrs; |
---|
88 | |
---|
89 | mutex_lock(&authnone_lock); |
---|
90 | if (ap == NULL) { |
---|
91 | ap = calloc(1, sizeof (*ap)); |
---|
92 | if (ap == NULL) { |
---|
93 | mutex_unlock(&authnone_lock); |
---|
94 | return (0); |
---|
95 | } |
---|
96 | authnone_private = ap; |
---|
97 | } |
---|
98 | if (!ap->mcnt) { |
---|
99 | ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth; |
---|
100 | ap->no_client.ah_ops = authnone_ops(); |
---|
101 | xdrs = &xdr_stream; |
---|
102 | xdrmem_create(xdrs, ap->marshalled_client, |
---|
103 | (u_int)MAX_MARSHAL_SIZE, XDR_ENCODE); |
---|
104 | (void)xdr_opaque_auth(xdrs, &ap->no_client.ah_cred); |
---|
105 | (void)xdr_opaque_auth(xdrs, &ap->no_client.ah_verf); |
---|
106 | ap->mcnt = XDR_GETPOS(xdrs); |
---|
107 | XDR_DESTROY(xdrs); |
---|
108 | } |
---|
109 | mutex_unlock(&authnone_lock); |
---|
110 | return (&ap->no_client); |
---|
111 | } |
---|
112 | |
---|
113 | /*ARGSUSED*/ |
---|
114 | static bool_t |
---|
115 | authnone_marshal(AUTH *client, XDR *xdrs) |
---|
116 | { |
---|
117 | struct authnone_private *ap; |
---|
118 | bool_t dummy; |
---|
119 | |
---|
120 | assert(xdrs != NULL); |
---|
121 | |
---|
122 | ap = authnone_private; |
---|
123 | if (ap == NULL) { |
---|
124 | mutex_unlock(&authnone_lock); |
---|
125 | return (FALSE); |
---|
126 | } |
---|
127 | dummy = (*xdrs->x_ops->x_putbytes)(xdrs, |
---|
128 | ap->marshalled_client, ap->mcnt); |
---|
129 | mutex_unlock(&authnone_lock); |
---|
130 | return (dummy); |
---|
131 | } |
---|
132 | |
---|
133 | /* All these unused parameters are required to keep ANSI-C from grumbling */ |
---|
134 | /*ARGSUSED*/ |
---|
135 | static void |
---|
136 | authnone_verf(AUTH *client) |
---|
137 | { |
---|
138 | } |
---|
139 | |
---|
140 | /*ARGSUSED*/ |
---|
141 | static bool_t |
---|
142 | authnone_validate(AUTH *client, struct opaque_auth *opaque) |
---|
143 | { |
---|
144 | |
---|
145 | return (TRUE); |
---|
146 | } |
---|
147 | |
---|
148 | /*ARGSUSED*/ |
---|
149 | static bool_t |
---|
150 | authnone_refresh(AUTH *client, void *dummy) |
---|
151 | { |
---|
152 | |
---|
153 | return (FALSE); |
---|
154 | } |
---|
155 | |
---|
156 | /*ARGSUSED*/ |
---|
157 | static void |
---|
158 | authnone_destroy(AUTH *client) |
---|
159 | { |
---|
160 | } |
---|
161 | |
---|
162 | static struct auth_ops * |
---|
163 | authnone_ops(void) |
---|
164 | { |
---|
165 | static struct auth_ops ops; |
---|
166 | |
---|
167 | /* VARIABLES PROTECTED BY ops_lock: ops */ |
---|
168 | |
---|
169 | mutex_lock(&ops_lock); |
---|
170 | if (ops.ah_nextverf == NULL) { |
---|
171 | ops.ah_nextverf = authnone_verf; |
---|
172 | ops.ah_marshal = authnone_marshal; |
---|
173 | ops.ah_validate = authnone_validate; |
---|
174 | ops.ah_refresh = authnone_refresh; |
---|
175 | ops.ah_destroy = authnone_destroy; |
---|
176 | } |
---|
177 | mutex_unlock(&ops_lock); |
---|
178 | return (&ops); |
---|
179 | } |
---|