xref: /minix3/lib/libc/rpc/auth_none.c (revision 84d9c625bfea59e274550651111ae9edfdc40fbd)
1*84d9c625SLionel Sambuc /*	$NetBSD: auth_none.c,v 1.16 2013/03/11 20:19:28 tron Exp $	*/
22fe8fb19SBen Gras 
32fe8fb19SBen Gras /*
4*84d9c625SLionel Sambuc  * Copyright (c) 2010, Oracle America, Inc.
52fe8fb19SBen Gras  *
6*84d9c625SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
7*84d9c625SLionel Sambuc  * modification, are permitted provided that the following conditions are
8*84d9c625SLionel Sambuc  * met:
92fe8fb19SBen Gras  *
10*84d9c625SLionel Sambuc  *     * Redistributions of source code must retain the above copyright
11*84d9c625SLionel Sambuc  *       notice, this list of conditions and the following disclaimer.
12*84d9c625SLionel Sambuc  *     * Redistributions in binary form must reproduce the above
13*84d9c625SLionel Sambuc  *       copyright notice, this list of conditions and the following
14*84d9c625SLionel Sambuc  *       disclaimer in the documentation and/or other materials
15*84d9c625SLionel Sambuc  *       provided with the distribution.
16*84d9c625SLionel Sambuc  *     * Neither the name of the "Oracle America, Inc." nor the names of its
17*84d9c625SLionel Sambuc  *       contributors may be used to endorse or promote products derived
18*84d9c625SLionel Sambuc  *       from this software without specific prior written permission.
192fe8fb19SBen Gras  *
20*84d9c625SLionel Sambuc  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21*84d9c625SLionel Sambuc  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22*84d9c625SLionel Sambuc  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23*84d9c625SLionel Sambuc  *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24*84d9c625SLionel Sambuc  *   COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25*84d9c625SLionel Sambuc  *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26*84d9c625SLionel Sambuc  *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27*84d9c625SLionel Sambuc  *   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28*84d9c625SLionel Sambuc  *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29*84d9c625SLionel Sambuc  *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30*84d9c625SLionel Sambuc  *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31*84d9c625SLionel Sambuc  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
322fe8fb19SBen Gras  */
332fe8fb19SBen Gras 
342fe8fb19SBen Gras #include <sys/cdefs.h>
352fe8fb19SBen Gras #if defined(LIBC_SCCS) && !defined(lint)
362fe8fb19SBen Gras #if 0
372fe8fb19SBen Gras static char *sccsid = "@(#)auth_none.c 1.19 87/08/11 Copyr 1984 Sun Micro";
382fe8fb19SBen Gras static char *sccsid = "@(#)auth_none.c	2.1 88/07/29 4.0 RPCSRC";
392fe8fb19SBen Gras #else
40*84d9c625SLionel Sambuc __RCSID("$NetBSD: auth_none.c,v 1.16 2013/03/11 20:19:28 tron Exp $");
412fe8fb19SBen Gras #endif
422fe8fb19SBen Gras #endif
432fe8fb19SBen Gras 
442fe8fb19SBen Gras /*
452fe8fb19SBen Gras  * auth_none.c
462fe8fb19SBen Gras  * Creates a client authentication handle for passing "null"
472fe8fb19SBen Gras  * credentials and verifiers to remote systems.
482fe8fb19SBen Gras  *
492fe8fb19SBen Gras  * Copyright (C) 1984, Sun Microsystems, Inc.
502fe8fb19SBen Gras  */
512fe8fb19SBen Gras 
522fe8fb19SBen Gras #include "namespace.h"
532fe8fb19SBen Gras 
542fe8fb19SBen Gras #include <assert.h>
552fe8fb19SBen Gras #include <stdlib.h>
562fe8fb19SBen Gras 
572fe8fb19SBen Gras #include <rpc/types.h>
582fe8fb19SBen Gras #include <rpc/xdr.h>
592fe8fb19SBen Gras #include <rpc/auth.h>
602fe8fb19SBen Gras 
612fe8fb19SBen Gras #ifdef __weak_alias
622fe8fb19SBen Gras __weak_alias(authnone_create,_authnone_create)
632fe8fb19SBen Gras #endif
642fe8fb19SBen Gras 
652fe8fb19SBen Gras #define MAX_MARSHAL_SIZE 20
662fe8fb19SBen Gras 
672fe8fb19SBen Gras /*
682fe8fb19SBen Gras  * Authenticator operations routines
692fe8fb19SBen Gras  */
702fe8fb19SBen Gras 
71f14fb602SLionel Sambuc static bool_t authnone_marshal(AUTH *, XDR *);
72f14fb602SLionel Sambuc static void authnone_verf(AUTH *);
73f14fb602SLionel Sambuc static bool_t authnone_validate(AUTH *, struct opaque_auth *);
74f14fb602SLionel Sambuc static bool_t authnone_refresh(AUTH *);
75f14fb602SLionel Sambuc static void authnone_destroy(AUTH *);
762fe8fb19SBen Gras 
772fe8fb19SBen Gras static const struct auth_ops ops = {
782fe8fb19SBen Gras 	authnone_verf,
792fe8fb19SBen Gras 	authnone_marshal,
802fe8fb19SBen Gras 	authnone_validate,
812fe8fb19SBen Gras 	authnone_refresh,
822fe8fb19SBen Gras 	authnone_destroy
832fe8fb19SBen Gras };
842fe8fb19SBen Gras 
852fe8fb19SBen Gras static struct authnone_private {
862fe8fb19SBen Gras 	AUTH	no_client;
872fe8fb19SBen Gras 	char	marshalled_client[MAX_MARSHAL_SIZE];
882fe8fb19SBen Gras 	u_int	mcnt;
892fe8fb19SBen Gras } *authnone_private;
902fe8fb19SBen Gras 
912fe8fb19SBen Gras AUTH *
authnone_create(void)92f14fb602SLionel Sambuc authnone_create(void)
932fe8fb19SBen Gras {
942fe8fb19SBen Gras 	struct authnone_private *ap = authnone_private;
952fe8fb19SBen Gras 	XDR xdr_stream;
962fe8fb19SBen Gras 	XDR *xdrs;
972fe8fb19SBen Gras 
982fe8fb19SBen Gras 	if (ap == 0) {
992fe8fb19SBen Gras 		ap = (struct authnone_private *)calloc(1, sizeof (*ap));
1002fe8fb19SBen Gras 		if (ap == 0)
1012fe8fb19SBen Gras 			return (0);
1022fe8fb19SBen Gras 		authnone_private = ap;
1032fe8fb19SBen Gras 	}
1042fe8fb19SBen Gras 	if (!ap->mcnt) {
1052fe8fb19SBen Gras 		ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
1062fe8fb19SBen Gras 		ap->no_client.ah_ops = &ops;
1072fe8fb19SBen Gras 		xdrs = &xdr_stream;
1082fe8fb19SBen Gras 		xdrmem_create(xdrs, ap->marshalled_client,
1092fe8fb19SBen Gras 		    (u_int)MAX_MARSHAL_SIZE, XDR_ENCODE);
1102fe8fb19SBen Gras 		(void)xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
1112fe8fb19SBen Gras 		(void)xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
1122fe8fb19SBen Gras 		ap->mcnt = XDR_GETPOS(xdrs);
1132fe8fb19SBen Gras 		XDR_DESTROY(xdrs);
1142fe8fb19SBen Gras 	}
1152fe8fb19SBen Gras 	return (&ap->no_client);
1162fe8fb19SBen Gras }
1172fe8fb19SBen Gras 
1182fe8fb19SBen Gras /*ARGSUSED*/
1192fe8fb19SBen Gras static bool_t
authnone_marshal(AUTH * client,XDR * xdrs)120f14fb602SLionel Sambuc authnone_marshal(AUTH *client, XDR *xdrs)
1212fe8fb19SBen Gras {
1222fe8fb19SBen Gras 	struct authnone_private *ap = authnone_private;
1232fe8fb19SBen Gras 
1242fe8fb19SBen Gras 	_DIAGASSERT(xdrs != NULL);
1252fe8fb19SBen Gras 
1262fe8fb19SBen Gras 	if (ap == 0)
1272fe8fb19SBen Gras 		return (0);
1282fe8fb19SBen Gras 	return ((*xdrs->x_ops->x_putbytes)(xdrs,
1292fe8fb19SBen Gras 	    ap->marshalled_client, ap->mcnt));
1302fe8fb19SBen Gras }
1312fe8fb19SBen Gras 
1322fe8fb19SBen Gras /*ARGSUSED*/
1332fe8fb19SBen Gras static void
authnone_verf(AUTH * client)134f14fb602SLionel Sambuc authnone_verf(AUTH *client)
1352fe8fb19SBen Gras {
1362fe8fb19SBen Gras }
1372fe8fb19SBen Gras 
1382fe8fb19SBen Gras /*ARGSUSED*/
1392fe8fb19SBen Gras static bool_t
authnone_validate(AUTH * client,struct opaque_auth * auth)140f14fb602SLionel Sambuc authnone_validate(AUTH *client, struct opaque_auth *auth)
1412fe8fb19SBen Gras {
1422fe8fb19SBen Gras 
1432fe8fb19SBen Gras 	return (TRUE);
1442fe8fb19SBen Gras }
1452fe8fb19SBen Gras 
1462fe8fb19SBen Gras /*ARGSUSED*/
1472fe8fb19SBen Gras static bool_t
authnone_refresh(AUTH * client)148f14fb602SLionel Sambuc authnone_refresh(AUTH *client)
1492fe8fb19SBen Gras {
1502fe8fb19SBen Gras 
1512fe8fb19SBen Gras 	return (FALSE);
1522fe8fb19SBen Gras }
1532fe8fb19SBen Gras 
1542fe8fb19SBen Gras /*ARGSUSED*/
1552fe8fb19SBen Gras static void
authnone_destroy(AUTH * client)156f14fb602SLionel Sambuc authnone_destroy(AUTH *client)
1572fe8fb19SBen Gras {
1582fe8fb19SBen Gras }
159