Home | History | Annotate | Line # | Download | only in rpc
      1 /*	$NetBSD: auth_none.c,v 1.16 2013/03/11 20:19:28 tron 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.16 2013/03/11 20:19:28 tron 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(AUTH *, XDR *);
     72 static void authnone_verf(AUTH *);
     73 static bool_t authnone_validate(AUTH *, struct opaque_auth *);
     74 static bool_t authnone_refresh(AUTH *);
     75 static void authnone_destroy(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(void)
     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(AUTH *client, XDR *xdrs)
    121 {
    122 	struct authnone_private *ap = authnone_private;
    123 
    124 	_DIAGASSERT(xdrs != NULL);
    125 
    126 	if (ap == 0)
    127 		return (0);
    128 	return ((*xdrs->x_ops->x_putbytes)(xdrs,
    129 	    ap->marshalled_client, ap->mcnt));
    130 }
    131 
    132 /*ARGSUSED*/
    133 static void
    134 authnone_verf(AUTH *client)
    135 {
    136 }
    137 
    138 /*ARGSUSED*/
    139 static bool_t
    140 authnone_validate(AUTH *client, struct opaque_auth *auth)
    141 {
    142 
    143 	return (TRUE);
    144 }
    145 
    146 /*ARGSUSED*/
    147 static bool_t
    148 authnone_refresh(AUTH *client)
    149 {
    150 
    151 	return (FALSE);
    152 }
    153 
    154 /*ARGSUSED*/
    155 static void
    156 authnone_destroy(AUTH *client)
    157 {
    158 }
    159