xref: /illumos-gate/usr/src/uts/common/rpc/sec/auth_none.c (revision c9eab9d4e096bb9b983e9b007577edfa73c32eff)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * auth_none.c implements routines used to pass "null" credentials
29  * and "null" verifiers in kernel RPC.
30  */
31 
32 #include <rpc/auth.h>
33 
34 /*
35  * Null authenticator operations vector
36  */
37 static void	authnone_nextverf(AUTH *);
38 static bool_t	authnone_marshal(AUTH *, XDR *, struct cred *);
39 static bool_t	authnone_validate(AUTH *, struct opaque_auth *);
40 static bool_t	authnone_refresh(AUTH *, struct rpc_msg *, cred_t *);
41 static void	authnone_destroy(AUTH *);
42 
43 static struct auth_ops auth_none_ops = {
44 	authnone_nextverf,
45 	authnone_marshal,
46 	authnone_validate,
47 	authnone_refresh,
48 	authnone_destroy,
49 	authany_wrap,
50 	authany_unwrap
51 };
52 
53 /*
54  * Create a kernel null style authenticator.
55  * Returns an auth handle.
56  */
57 AUTH *
58 authnone_create(void)
59 {
60 	/*
61 	 * Allocate and set up auth handle
62 	 */
63 	return (kmem_cache_alloc(authnone_cache, KM_SLEEP));
64 }
65 
66 /*
67  *  The constructor of the authnone_cache.
68  */
69 /* ARGSUSED */
70 int
71 authnone_init(void *buf, void *cdrarg, int kmflags)
72 {
73 	AUTH *auth = (AUTH *)buf;
74 
75 	auth->ah_ops = &auth_none_ops;
76 
77 	/*
78 	 * Flavor of RPC message's credential and verifier should be set to
79 	 * AUTH_NONE. Opaque data associated with AUTH_NONE is undefined.
80 	 * The length of the opaque data should be zero.
81 	 *	oa_flavor = AUTH_NONE
82 	 *	oa_base = NULL
83 	 *	oa_length = 0
84 	 */
85 	auth->ah_cred = auth->ah_verf = _null_auth;
86 
87 	return (0);
88 }
89 
90 /*
91  * authnone operations
92  */
93 /* ARGSUSED */
94 static void
95 authnone_nextverf(AUTH *auth)
96 {
97 	/* no action necessary */
98 }
99 
100 /* ARGSUSED */
101 static bool_t
102 authnone_marshal(AUTH *auth, XDR *xdrs, struct cred *cr)
103 {
104 	int32_t	*ptr;
105 
106 	/*
107 	 * auth_none has no opaque data. Encode auth_none
108 	 * value with 0 len data for both cred and verf.
109 	 * We first try a fast path to complete this operation.
110 	 */
111 	ptr = XDR_INLINE(xdrs, 4 + 4 + 4 + 4);
112 	if (ptr) {
113 		IXDR_PUT_INT32(ptr, AUTH_NONE);
114 		IXDR_PUT_INT32(ptr, 0);
115 		IXDR_PUT_INT32(ptr, AUTH_NONE);
116 		IXDR_PUT_INT32(ptr, 0);
117 		return (TRUE);
118 	}
119 
120 	/*
121 	 * serialize AUTH_NONE credential and AUTH_NONE verifier
122 	 */
123 	if ((xdr_opaque_auth(xdrs, &(auth->ah_cred))) &&
124 	    (xdr_opaque_auth(xdrs, &(auth->ah_verf))))
125 		return (TRUE);
126 	else
127 		return (FALSE);
128 }
129 
130 /* ARGSUSED */
131 static bool_t
132 authnone_validate(AUTH *auth, struct opaque_auth *verf)
133 {
134 	return (TRUE);
135 }
136 
137 /* ARGSUSED */
138 static bool_t
139 authnone_refresh(AUTH *auth, struct rpc_msg *msg, cred_t *cr)
140 {
141 	return (FALSE);
142 }
143 
144 static void
145 authnone_destroy(AUTH *auth)
146 {
147 	kmem_cache_free(authnone_cache, auth);
148 }
149