xref: /openbsd/lib/libc/rpc/auth_none.c (revision 8d4335cb)
1*8d4335cbSguenther /*	$OpenBSD: auth_none.c,v 1.15 2022/02/14 03:38:59 guenther Exp $ */
2cb7760d1Smillert 
3df930be7Sderaadt /*
4cb7760d1Smillert  * Copyright (c) 2010, Oracle America, Inc.
5df930be7Sderaadt  *
6cb7760d1Smillert  * Redistribution and use in source and binary forms, with or without
7cb7760d1Smillert  * modification, are permitted provided that the following conditions are
8cb7760d1Smillert  * met:
9df930be7Sderaadt  *
10cb7760d1Smillert  *     * Redistributions of source code must retain the above copyright
11cb7760d1Smillert  *       notice, this list of conditions and the following disclaimer.
12cb7760d1Smillert  *     * Redistributions in binary form must reproduce the above
13cb7760d1Smillert  *       copyright notice, this list of conditions and the following
14cb7760d1Smillert  *       disclaimer in the documentation and/or other materials
15cb7760d1Smillert  *       provided with the distribution.
16cb7760d1Smillert  *     * Neither the name of the "Oracle America, Inc." nor the names of its
17cb7760d1Smillert  *       contributors may be used to endorse or promote products derived
18cb7760d1Smillert  *       from this software without specific prior written permission.
19df930be7Sderaadt  *
20cb7760d1Smillert  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21cb7760d1Smillert  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22cb7760d1Smillert  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23cb7760d1Smillert  *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24cb7760d1Smillert  *   COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25cb7760d1Smillert  *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26cb7760d1Smillert  *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27cb7760d1Smillert  *   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28cb7760d1Smillert  *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29cb7760d1Smillert  *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30cb7760d1Smillert  *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31cb7760d1Smillert  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32df930be7Sderaadt  */
33df930be7Sderaadt 
34df930be7Sderaadt /*
35df930be7Sderaadt  * auth_none.c
36df930be7Sderaadt  * Creates a client authentication handle for passing "null"
37df930be7Sderaadt  * credentials and verifiers to remote systems.
38df930be7Sderaadt  */
39df930be7Sderaadt 
40df930be7Sderaadt #include <stdlib.h>
41df930be7Sderaadt #include <rpc/types.h>
42e0476b6aSderaadt #include <rpc/rpc.h>
43df930be7Sderaadt #include <rpc/xdr.h>
44df930be7Sderaadt #include <rpc/auth.h>
45df930be7Sderaadt #define MAX_MARSHEL_SIZE 20
46df930be7Sderaadt 
47df930be7Sderaadt /*
48df930be7Sderaadt  * Authenticator operations routines
49df930be7Sderaadt  */
5041aa8645Sderaadt static void	authnone_destroy(struct __rpc_auth *);
5141aa8645Sderaadt static void	authnone_verf(struct __rpc_auth *);
5241aa8645Sderaadt static bool_t	authnone_validate(struct __rpc_auth *, struct opaque_auth *);
5341aa8645Sderaadt static bool_t	authnone_marshal(struct __rpc_auth *, XDR *);
5441aa8645Sderaadt static bool_t	authnone_refresh(struct __rpc_auth *);
55df930be7Sderaadt 
56*8d4335cbSguenther static const struct auth_ops ops = {
57df930be7Sderaadt 	authnone_verf,
58df930be7Sderaadt 	authnone_marshal,
59df930be7Sderaadt 	authnone_validate,
60df930be7Sderaadt 	authnone_refresh,
61df930be7Sderaadt 	authnone_destroy
62df930be7Sderaadt };
63df930be7Sderaadt 
64df930be7Sderaadt static struct authnone_private {
65df930be7Sderaadt 	AUTH	no_client;
66df930be7Sderaadt 	char	marshalled_client[MAX_MARSHEL_SIZE];
67df930be7Sderaadt 	u_int	mcnt;
68df930be7Sderaadt } *authnone_private;
69df930be7Sderaadt 
70df930be7Sderaadt AUTH *
authnone_create(void)71384ec30aSotto authnone_create(void)
72df930be7Sderaadt {
7341aa8645Sderaadt 	struct authnone_private *ap = authnone_private;
74df930be7Sderaadt 	XDR xdr_stream;
7541aa8645Sderaadt 	XDR *xdrs;
76df930be7Sderaadt 
77f590e579Sderaadt 	if (ap == NULL) {
78fa713987Sderaadt 		ap = calloc(1, sizeof (*ap));
79f590e579Sderaadt 		if (ap == NULL)
80f590e579Sderaadt 			return (NULL);
81df930be7Sderaadt 		authnone_private = ap;
82df930be7Sderaadt 	}
83df930be7Sderaadt 	if (!ap->mcnt) {
84df930be7Sderaadt 		ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
85df930be7Sderaadt 		ap->no_client.ah_ops = &ops;
86df930be7Sderaadt 		xdrs = &xdr_stream;
87df930be7Sderaadt 		xdrmem_create(xdrs, ap->marshalled_client, (u_int)MAX_MARSHEL_SIZE,
88df930be7Sderaadt 		    XDR_ENCODE);
89df930be7Sderaadt 		(void)xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
90df930be7Sderaadt 		(void)xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
91df930be7Sderaadt 		ap->mcnt = XDR_GETPOS(xdrs);
92df930be7Sderaadt 		XDR_DESTROY(xdrs);
93df930be7Sderaadt 	}
94df930be7Sderaadt 	return (&ap->no_client);
95df930be7Sderaadt }
9685858ec2Sguenther DEF_WEAK(authnone_create);
97df930be7Sderaadt 
98df930be7Sderaadt static bool_t
authnone_marshal(AUTH * client,XDR * xdrs)99384ec30aSotto authnone_marshal(AUTH *client, XDR *xdrs)
100df930be7Sderaadt {
10141aa8645Sderaadt 	struct authnone_private *ap = authnone_private;
102df930be7Sderaadt 
103f590e579Sderaadt 	if (ap == NULL)
104df930be7Sderaadt 		return (0);
105df930be7Sderaadt 	return ((*xdrs->x_ops->x_putbytes)(xdrs,
106df930be7Sderaadt 	    ap->marshalled_client, ap->mcnt));
107df930be7Sderaadt }
108df930be7Sderaadt 
109df930be7Sderaadt static void
authnone_verf(struct __rpc_auth * none)11041aa8645Sderaadt authnone_verf(struct __rpc_auth *none)
111df930be7Sderaadt {
112df930be7Sderaadt }
113df930be7Sderaadt 
114df930be7Sderaadt static bool_t
authnone_validate(struct __rpc_auth * none,struct opaque_auth * noauth)11541aa8645Sderaadt authnone_validate(struct __rpc_auth *none, struct opaque_auth *noauth)
116df930be7Sderaadt {
117df930be7Sderaadt 
118df930be7Sderaadt 	return (TRUE);
119df930be7Sderaadt }
120df930be7Sderaadt 
121df930be7Sderaadt static bool_t
authnone_refresh(struct __rpc_auth * none)12241aa8645Sderaadt authnone_refresh(struct __rpc_auth *none)
123df930be7Sderaadt {
124df930be7Sderaadt 
125df930be7Sderaadt 	return (FALSE);
126df930be7Sderaadt }
127df930be7Sderaadt 
128df930be7Sderaadt static void
authnone_destroy(struct __rpc_auth * none)12941aa8645Sderaadt authnone_destroy(struct __rpc_auth *none)
130df930be7Sderaadt {
131df930be7Sderaadt }
132