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