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