1 /*
2  * Copyright (c) 2006-2021, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  */
9 /* @(#)auth_none.c  2.1 88/07/29 4.0 RPCSRC */
10 /*
11  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
12  * unrestricted use provided that this legend is included on all tape
13  * media and as a part of the software program in whole or part.  Users
14  * may copy or modify Sun RPC without charge, but are not authorized
15  * to license or distribute it to anyone else except as part of a product or
16  * program developed by the user.
17  *
18  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
19  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
20  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
21  *
22  * Sun RPC is provided with no support and without any obligation on the
23  * part of Sun Microsystems, Inc. to assist in its use, correction,
24  * modification or enhancement.
25  *
26  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
27  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
28  * OR ANY PART THEREOF.
29  *
30  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
31  * or profits or other special, indirect and consequential damages, even if
32  * Sun has been advised of the possibility of such damages.
33  *
34  * Sun Microsystems, Inc.
35  * 2550 Garcia Avenue
36  * Mountain View, California  94043
37  */
38 #if !defined(lint) && defined(SCCSIDS)
39 static char sccsid[] =
40 
41     "@(#)auth_none.c 1.19 87/08/11 Copyr 1984 Sun Micro";
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 <rpc/types.h>
53 #include <rpc/xdr.h>
54 #include <rpc/auth.h>
55 #define MAX_MARSHEL_SIZE 20
56 
57 static void authnone_verf(AUTH *);
58 static bool_t authnone_validate(AUTH *, struct opaque_auth *);
59 static bool_t authnone_refresh(AUTH *);
60 static void authnone_destroy(AUTH *);
61 static bool_t authnone_marshal(AUTH *client, XDR *xdrs);
62 
63 struct opaque_auth _null_auth;
64 
65 static struct auth_ops ops = {
66     authnone_verf,
67     authnone_marshal,
68     authnone_validate,
69     authnone_refresh,
70     authnone_destroy
71 };
72 
73 static struct authnone_private {
74     AUTH no_client;
75     char marshalled_client[MAX_MARSHEL_SIZE];
76     unsigned int mcnt;
77 } *authnone_private;
78 
authnone_create()79 AUTH *authnone_create()
80 {
81     register struct authnone_private *ap = authnone_private;
82     XDR xdr_stream;
83     register XDR *xdrs;
84     extern bool_t xdr_opaque_auth(XDR *xdrs, struct opaque_auth *ap);
85 
86     if (ap == 0) {
87         ap = (struct authnone_private *) rt_malloc (sizeof(*ap));
88         if (ap == 0) return NULL;
89         memset(ap, 0, sizeof(*ap));
90         authnone_private = ap;
91     }
92     if (!ap->mcnt) {
93         ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
94         ap->no_client.ah_ops = &ops;
95         xdrs = &xdr_stream;
96         xdrmem_create(xdrs, ap->marshalled_client,
97                       (unsigned int) MAX_MARSHEL_SIZE, XDR_ENCODE);
98         (void) xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
99         (void) xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
100         ap->mcnt = XDR_GETPOS(xdrs);
101         XDR_DESTROY(xdrs);
102     }
103     return (&ap->no_client);
104 }
105 
106 /*ARGSUSED*/
authnone_marshal(AUTH * client,XDR * xdrs)107 static bool_t authnone_marshal(AUTH *client, XDR *xdrs)
108 {
109     register struct authnone_private *ap = authnone_private;
110 
111     if (ap == 0)
112         return (0);
113     return ((*xdrs->x_ops->x_putbytes) (xdrs,
114                                         ap->marshalled_client, ap->mcnt));
115 }
116 
authnone_verf(AUTH * x)117 static void authnone_verf(AUTH *x)
118 {
119 }
120 
authnone_validate(AUTH * x,struct opaque_auth * x1)121 static bool_t authnone_validate(AUTH *x, struct opaque_auth *x1)
122 {
123 
124     return (TRUE);
125 }
126 
authnone_refresh(AUTH * x)127 static bool_t authnone_refresh(AUTH *x)
128 {
129 
130     return (FALSE);
131 }
132 
authnone_destroy(AUTH * x)133 static void authnone_destroy(AUTH *x)
134 {
135 }
136