Home | History | Annotate | Line # | Download | only in rpc
auth_none.c revision 1.14.62.1
      1 /*	$NetBSD: auth_none.c,v 1.14.62.1 2013/03/14 22:03:13 riz Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2010, Oracle America, Inc.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions are
      8  * met:
      9  *
     10  *     * Redistributions of source code must retain the above copyright
     11  *       notice, this list of conditions and the following disclaimer.
     12  *     * Redistributions in binary form must reproduce the above
     13  *       copyright notice, this list of conditions and the following
     14  *       disclaimer in the documentation and/or other materials
     15  *       provided with the distribution.
     16  *     * Neither the name of the "Oracle America, 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
     21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     23  *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     24  *   COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     25  *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     27  *   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28  *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     29  *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     30  *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 
     34 #include <sys/cdefs.h>
     35 #if defined(LIBC_SCCS) && !defined(lint)
     36 #if 0
     37 static char *sccsid = "@(#)auth_none.c 1.19 87/08/11 Copyr 1984 Sun Micro";
     38 static char *sccsid = "@(#)auth_none.c	2.1 88/07/29 4.0 RPCSRC";
     39 #else
     40 __RCSID("$NetBSD: auth_none.c,v 1.14.62.1 2013/03/14 22:03:13 riz Exp $");
     41 #endif
     42 #endif
     43 
     44 /*
     45  * auth_none.c
     46  * Creates a client authentication handle for passing "null"
     47  * credentials and verifiers to remote systems.
     48  *
     49  * Copyright (C) 1984, Sun Microsystems, Inc.
     50  */
     51 
     52 #include "namespace.h"
     53 
     54 #include <assert.h>
     55 #include <stdlib.h>
     56 
     57 #include <rpc/types.h>
     58 #include <rpc/xdr.h>
     59 #include <rpc/auth.h>
     60 
     61 #ifdef __weak_alias
     62 __weak_alias(authnone_create,_authnone_create)
     63 #endif
     64 
     65 #define MAX_MARSHAL_SIZE 20
     66 
     67 /*
     68  * Authenticator operations routines
     69  */
     70 
     71 static bool_t authnone_marshal __P((AUTH *, XDR *));
     72 static void authnone_verf __P((AUTH *));
     73 static bool_t authnone_validate __P((AUTH *, struct opaque_auth *));
     74 static bool_t authnone_refresh __P((AUTH *));
     75 static void authnone_destroy __P((AUTH *));
     76 
     77 static const struct auth_ops ops = {
     78 	authnone_verf,
     79 	authnone_marshal,
     80 	authnone_validate,
     81 	authnone_refresh,
     82 	authnone_destroy
     83 };
     84 
     85 static struct authnone_private {
     86 	AUTH	no_client;
     87 	char	marshalled_client[MAX_MARSHAL_SIZE];
     88 	u_int	mcnt;
     89 } *authnone_private;
     90 
     91 AUTH *
     92 authnone_create()
     93 {
     94 	struct authnone_private *ap = authnone_private;
     95 	XDR xdr_stream;
     96 	XDR *xdrs;
     97 
     98 	if (ap == 0) {
     99 		ap = (struct authnone_private *)calloc(1, sizeof (*ap));
    100 		if (ap == 0)
    101 			return (0);
    102 		authnone_private = ap;
    103 	}
    104 	if (!ap->mcnt) {
    105 		ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
    106 		ap->no_client.ah_ops = &ops;
    107 		xdrs = &xdr_stream;
    108 		xdrmem_create(xdrs, ap->marshalled_client,
    109 		    (u_int)MAX_MARSHAL_SIZE, XDR_ENCODE);
    110 		(void)xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
    111 		(void)xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
    112 		ap->mcnt = XDR_GETPOS(xdrs);
    113 		XDR_DESTROY(xdrs);
    114 	}
    115 	return (&ap->no_client);
    116 }
    117 
    118 /*ARGSUSED*/
    119 static bool_t
    120 authnone_marshal(client, xdrs)
    121 	AUTH *client;
    122 	XDR *xdrs;
    123 {
    124 	struct authnone_private *ap = authnone_private;
    125 
    126 	_DIAGASSERT(xdrs != NULL);
    127 
    128 	if (ap == 0)
    129 		return (0);
    130 	return ((*xdrs->x_ops->x_putbytes)(xdrs,
    131 	    ap->marshalled_client, ap->mcnt));
    132 }
    133 
    134 /*ARGSUSED*/
    135 static void
    136 authnone_verf(client)
    137 	AUTH *client;
    138 {
    139 }
    140 
    141 /*ARGSUSED*/
    142 static bool_t
    143 authnone_validate(client, auth)
    144 	AUTH *client;
    145 	struct opaque_auth *auth;
    146 {
    147 
    148 	return (TRUE);
    149 }
    150 
    151 /*ARGSUSED*/
    152 static bool_t
    153 authnone_refresh(client)
    154 	AUTH *client;
    155 {
    156 
    157 	return (FALSE);
    158 }
    159 
    160 /*ARGSUSED*/
    161 static void
    162 authnone_destroy(client)
    163 	AUTH *client;
    164 {
    165 }
    166